function ShowRef (fmt)
   {
   msgWindow = window.open("/formats/ref." + fmt + ".html",
                           "refwin",
                           "alwaysRaised=1,toolbar=1,scrollbars=1,resizable=1,width=750,height=300")
   msgWindow.focus()
   }

function ShowEval (id)
   {
   msgWindow = window.open("http://aipl.arsusda.gov/cgi-bin/general/Qpublic/proc.Q.cgi?qname=getbull&single&id=" + id ,
                           "evalwin",
                           "toolbar=1,scrollbars=1,resizable=1,width=767,height=700")
   msgWindow.focus()
   }

function ShowRefCFML (fmt)
   {
   msgWindow = window.open(fmt,
                           "refwin",
                           "alwaysRaised=1,toolbar=1,scrollbars=1,resizable=1,width=750,height=750")
   msgWindow.focus()
   }


function xShowRefCFML (fmt)
   {
   msgWindow = window.open("/formats/ref." + fmt + ".cfm",
                           "refwin",
                           "alwaysRaised=1,toolbar=1,scrollbars=1,resizable=1,width=750,height=750")
   msgWindow.focus()
   }


function ToggleDisplayById(ID2Toggle,ReqPos,Chld){
	if (Chld == 'Parent'){
		ToggleMe = document.getElementById(ID2Toggle).parentNode;
	}else{
		ToggleMe = document.getElementById(ID2Toggle);
	}
	if (ReqPos == null || ReqPos == ''){
		if (ToggleMe.style.display == 'none') {
			ToggleMe.style.display = 'block'
		} else {
			ToggleMe.style.display = 'none'
		}
	} else {
		ToggleMe.style.display = ReqPos;
	}
}

function HideDIVsByClass(ClassToHide){
	tagcollect=document.all? document.all.tags("DIV"): document.getElementsByTagName("DIV") //IE5 workaround
	filteredcollect=new Array()
	inc=0
	for (i=0;i<tagcollect.length;i++){
		if (tagcollect[i].className==ClassToHide)
		tagcollect[i].style.display = 'none'
	}
}

function SwitchDisplayedDiv(ClassToHide,ID2Show){
	HideDIVsByClass(ClassToHide)
	ToggleDisplayById(ID2Show)
}

function SetCurrentButton(DselClass,SelID){
	tagcollect=document.all? document.all.tags("LI"): document.getElementsByTagName("LI") //IE5 workaround
	filteredcollect=new Array()
	inc=0
	for (i=0;i<tagcollect.length;i++){
		if (tagcollect[i].className==DselClass)
		tagcollect[i].id = 'NULL'
	}
	document.getElementById(SelID).parentNode.id="current"
}
	function AIPL_Printable(content){
		NewPrintWindow=window.open();
		NewPrintWindow.document.write(content);
		point_PW = NewPrintWindow.document.getElementById('AIPL_NW_Anchor');
		point_PW.innerHTML='';
		NewPrintWindow.document.close();
	}


function AIPL_MakeNavDiv(){
	AIPL_DocTables = document.getElementsByTagName('table');
	ToggleControlDiv = '<div id="AIPL_ToggleNavDiv" style="position:absolute; margin:-32px 0px 0px 0px; padding:0px 0px 0px 0px; width:100px;"><a onClick="Toggle_ARS(1);" style="cursor:pointer; cursor:hand;" title="Click for LESS Navigation">&laquo;</a>|(2)|<a title="Currently at MAX Navigation">*</a></div>';
	elementToGetToggle = document.searchform.parentNode.parentNode.parentNode.parentNode.parentNode;
	elementToGetToggle.innerHTML = ToggleControlDiv + '<div id="ARS_RightNav">' + elementToGetToggle.innerHTML + '</div>';
}

function Toggle_ARS(NavLvl){
	if (AIPL_DocTables == null){
		AIPL_MakeNavDiv();
	}
	if (NavLvl == null){
		NavLvl = 2;
	}
	if (NavLvl > 0){
		document.getElementById('ARS_RightNav').style.display = 'block';
		AIPL_DocTables[0].style.width = '767px';
		AIPL_DocTables[2].style.display = AIPL_DocTables[0].style.display;
		AIPL_DocTables[4].style.display = AIPL_DocTables[0].style.display;
		AIPL_DocTables[6].style.display = AIPL_DocTables[0].style.display;
		AIPL_DocTables[12].style.display = AIPL_DocTables[0].style.display;
		AIPL_DocTables[13].style.display = AIPL_DocTables[0].style.display;
		AIPL_DocTables[20].style.display = AIPL_DocTables[0].style.display;
		document.getElementById('AIPL_ToggleNavDiv').innerHTML = '<a onClick="Toggle_ARS(0);" style="cursor:pointer; cursor:hand;" title="Click for LESS Navigation">&laquo;</a>|('+NavLvl+')|<a onClick="Toggle_ARS(2);" style="cursor:pointer; cursor:hand;" title="Click for MORE Navigation">&raquo;</a>';
	}
	if (NavLvl > 1){
		AIPL_DocTables[8].style.display = AIPL_DocTables[0].style.display;
		document.getElementById('AIPL_ToggleNavDiv').innerHTML = '<a onClick="Toggle_ARS(1);" style="cursor:pointer; cursor:hand;" title="Click for LESS Navigation">&laquo;</a>|('+NavLvl+')|<a title="Currently at MAX Navigation">*</a>';
	}
	if (NavLvl < 2){
		AIPL_DocTables[8].style.display = 'none';
		document.getElementById('AIPL_ToggleNavDiv').innerHTML = '<a onclick="Toggle_ARS(0);" style="cursor:pointer; cursor:hand;" title="Click for LESS Navigation">&laquo;</a>|(1)|<a onClick="Toggle_ARS(2);" style="cursor:pointer; cursor:hand;" title="Click for MORE navigation">&raquo;</a>';
	}
	if (NavLvl < 1){
		document.getElementById('ARS_RightNav').style.display = 'none';
		AIPL_DocTables[0].style.width = 'auto';
		AIPL_DocTables[2].style.display = 'none';
		AIPL_DocTables[4].style.display = 'none';
		AIPL_DocTables[6].style.display = 'none';
		AIPL_DocTables[12].style.display = 'none';
		AIPL_DocTables[13].style.display = 'none';
		AIPL_DocTables[20].style.display = 'none';
		document.getElementById('AIPL_ToggleNavDiv').innerHTML = '<a title="At Min. Navigation">*</a>|('+NavLvl+')|<a onclick="Toggle_ARS(1);" style="cursor:pointer; cursor:hand;" title="Increase amount of naviagion">&raquo;</a>';
	}
}





	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}

function Spinner(ThisSpinner){
	if(ThisSpinner.innerHTML == "Fetching Data | "){ThisSpinner.innerHTML="Fetching Data / ";}else if(ThisSpinner.innerHTML == "Fetching Data / "){ThisSpinner.innerHTML="Fetching Data - ";}else if(ThisSpinner.innerHTML == "Fetching Data - "){ThisSpinner.innerHTML="Fetching Data \\ ";}else if(ThisSpinner.innerHTML == "Fetching Data \\ "){ThisSpinner.innerHTML="Fetching Data | ";}else if(ThisSpinner.innerHTML == ""){ThisSpinner.innerHTML="Fetching Data | ";}
}


currentTime = new Date();
MyURLTime1Stamp = currentTime.getTime();

function XML_req_State(AlertMe){
   if ( xmlhttp.readyState != 0 && xmlhttp.readyState != 4 ){
// alert(xmlhttp.statusText);
//      if (xmlhttp.URL.indexOf('AIPL-Login') !=-1){
//		  alert('aborting');
//        xmlhttp.abort();
//	  }

      if ( xmlhttp.readyState != 0 && xmlhttp.readyState != 4 ){
         if ( AlertMe == true ){
            alert("Please wait for previous request to complete.");
	     }
         return false;
	  }
   }
}


function Load_URL(In_URL,Dest_area_Id){

if (Dest_area_Id == 'AIPL_Login_Box'){
   XMLstatus = XML_req_State(false);
}else{
   XMLstatus = XML_req_State(true);
}


if(XMLstatus != false){


   Dest_area = document.getElementById(Dest_area_Id);
   if (Dest_area_Id != 'AIPL_Login_Box' && Dest_area.innerHTML != ''){
	   return;
   }

Fetch_URL = In_URL + "&time=" + MyURLTime1Stamp;


xmlhttp.open("POST", Fetch_URL, true);

  var URL_PlWait = setInterval('Spinner(Dest_area);',200);

  xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4) {
      clearInterval(URL_PlWait);
      if( xmlhttp.status == 200 ){
        Dest_area.innerHTML = xmlhttp.responseText;

var x = Dest_area.getElementsByTagName("script");
for(var i=0;i<x.length;i++)
{
var y = x[i].text;
eval( y );
x[i].text = y;
}

      }else{
        Dest_area.innerHTML = "Could not load data";
        alert( "Error fetching Data : "+xmlhttp.statusText );
        clearInterval(URL_PlWait);
      }
    }
  }
  xmlhttp.send(null);
xmlhttp.close;

}
}

