//Declare global variables
	  var stylesheet;
	  var change;
	  var whichString;
	  var root="snsdata/metadata[";
	  
	 function XMLhelp() { 
	 msgWindow=window.open("xml/XML_Help.html","Help",'height=300,width=700');
}

   // init takes of tasks that need to be performed the first time
   // the page is loaded.
 	function init() {
	snsXML.async = false;	
    // Load the XML document from the server
       msgWindow=window.open("xml/loaddata.html","Load",'height=25,width=150');
       snsXML.load("xml/snsall.xml");
       msgWindow.close();
	goDisplay() ;
}	
 
   // select is called when a user asks for a different view
   // of the XML document.
  	function goSelect(FindMe,dataNode) {   
  	var baseStr="contains(targetNode,'targetText')";
  	var transStr="contains(translate(targetNode,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),'targetText')";
     // Modify for case sensitivity
       if (SearchForm.C3.checked) {
		transStr=transStr.replace('targetNode',dataNode);
	      whichString= transStr.replace('targetText',FindMe.toUpperCase()); 
       } else{
	       baseStr=baseStr.replace('targetNode',dataNode);
	      whichString= baseStr.replace('targetText',FindMe); 
	}
return whichString;
}

// Take the search criteria from the input screen and make up the
//  boolean search string
  	function goDisplay() {   
	var booleanStr;
	var firstFind=goSelect(SearchForm.forWhat.value,SearchForm.inNode.options(SearchForm.inNode.selectedIndex).value);	
	var refineFind=goSelect(SearchForm.refineWith.value.substring(1),SearchForm.inNode2.options(SearchForm.inNode2.selectedIndex).value);	
//  Check which boolean search is to be used
if  (SearchForm.C2.checked) {
		booleanStr=' or ' 
	} else{
		booleanStr=' and '
	}
	if  (SearchForm.C1.checked) {
		refineFind=' not('+refineFind+')'; 
		}
   // Assign filenames
	document.SearchForm.recordChosen.value = 0;
if (SearchForm.refineWith.value.charCodeAt(0) == 43) {
	whichString= root+firstFind+booleanStr+refineFind+']';
	} else {	
	whichString= root+firstFind+']';
	}
	stylesheet = null;
	stylesheet = eval("fgdc_search"); 
	change=stylesheet.selectSingleNode("//xsl:variable/@select");
	change.nodeValue =whichString;
	showToScreen();
    }

// Here where the full data is displayed
       function full_display(view,which) {
	 var which;
	 var view;
	if (which > 0) {
	document.SearchForm.recordChosen.value = which;
	} else {
	which = document.SearchForm.recordChosen.value;
	} 
	whichString="snsdata/metadata["+which+"]";
	stylesheet = null;
 	stylesheet = eval(view);
	change=stylesheet.selectSingleNode("//xsl:apply-templates/@select");
	change.nodeValue = whichString;	 	
	showToScreen();
}
//Routine that generates the HTML to display
	function showToScreen() {
	       msgWindow=window.open("xml/finddata.html","Find",'height=25,width=150');

	displayDiv.innerHTML = snsXML.transformNode(stylesheet.documentElement); 
       msgWindow.close();

    }
