/*
Supports all the Ajax calls for the location pages

following arguments are used:
loc

*/
 function loadall(){
	loadData(1,0);
  	loadPreSelected();
  //
 }
 function loadParent(parentID){
  loadData(parentID, 1) }
 function narrowLoc(){
  var f = document.forms[0];
  var selectBox = f.elements['locSelect'];
  var selectBox = document.getElementById( 'locSelect' );
  var sLoc = selectBox.selectedIndex;
  loadData(selectBox.options[sLoc].value, 1);
  return true;
  }
 function loadPreSelected(){
  //var f = document.forms[0];
  var hiddenLoc = document.getElementById( 'PreSelectedLoc' );
  //alert('you chose ' + selectBox.options[sLoc].text );
  //if (sLoc = ''){loadData(0,0); return;}
  loadData(parseInt(hiddenLoc.value), 0);
  setSelected(parseInt(hiddenLoc.value));
  return true;
  } 
 function loadData(locID, narrow){
	 // locID is the current selected location, web will return this and it's children
	 // narrowLoc is a bitswitch, if 1 then children  are in drop down, if 0 then location and its siblings are in drop down.
  if (locID == null){locID = '0';}
  if (narrow == null){narrow = '0';}
  // Check for DOM and js functions on browser
  if(!document.getElementById || !document.createTextNode){return;}
  // Find element
  var ld=document.getElementById('LocationJDiv');
  ld.innerHTML = 'location info loading';
  loadURL = "../LocationTools/Location_Options_Ajax.asp";
  if(!(locID == '0')){
   loadURL = loadURL +'?locationId='+locID+'&narrow='+narrow;}
// debug line alert(loadURL);
  var objXMLHTTP;
  try{
	  objXMLHTTP = new XMLHttpRequest();
  } catch ( error ){
	  try {
		  objXMLHTTP = new ActiveXObject( "Microsoft.XMLHTTP");
	  } catch ( error ) {
		  return true;
	  }
  }
  
   //var objXMLHTTP = new ActiveXObject("Msxml2.XMLHTTP.3.0");
  objXMLHTTP.open("GET", loadURL, false);
  objXMLHTTP.setRequestHeader('If-Modified-Since', 'Thu, 06 Apr 2006 00:00:00 GMT');
  objXMLHTTP.send( null );
  
  var txtdata = objXMLHTTP.responseText;
  //txtdata = txtdata.replace(/rtn/, "return");
  ld.innerHTML = txtdata;
  return true;
  }
  function setSelected(val){
 // Check for DOM and js functions on browser
  if(!document.getElementById || !document.createTextNode){return;}	  
 // var f = document.forms[0];
var selectBox = document.getElementById( 'locSelect' );
  //var selectBox = f.elements['locSelect'];
  var opt = selectBox.options;
  for( i = 0; i < opt.length; i++){
	  if(opt[i].value == val){opt[i].selected = true;}
  		}
  }
  
window.onload=loadPreSelected;