/*
The following functions are contained in this file:
    function resetTimer()
    function printTime(message)
    function startClock(message)
	function setActiveStyleSheet(title)
	function getActiveStyleSheet()
	function getPerferredStyleSheet()
    function createCookie(name,value,days)	
    function readCookie(name)
    
	function SubmitForm ()
	function DisplayUserManual ()
	function LearnAboutProject ()
	function DisplayPopupHelp (which)
	
	function setUnits(id,str,str2)
	function getObject(objectId)
	function chstyle(id)
	function show(id,name,base)
	function MM_preloadImages()
	function MM_swapImgRestore()
	function MM_findObj(n, d)
	function MM_swapImage()
	
*/

var cookie = readCookie("style");

//Global Request Object
var XmlHttp=null;

var selstate;

if (cookie == "null") {cookie = "Default"};

//This is the timeout functions for the session vars used by the tool/default.asp page
var minutes = 46;
var message = 'Session will expire in : minutes if not active';
var timeoutMsg = "startClock('" + message + "')";
var todayDate     = new Date();
var todayDay      = todayDate.getDate();
var todayMonth    = todayDate.getMonth() + 1;
var todayYear     = todayDate.getFullYear();

function safariGetRv()
{
  if (navigator.product != 'Safari')
  {
    return -1;
  }
  var rvValue = 0;
  var ua      = navigator.userAgent.toLowerCase();
  var rvStart = ua.indexOf('rv:');
  var rvEnd   = ua.indexOf(')', rvStart);
  var rv      = ua.substring(rvStart+3, rvEnd);
  var rvParts = rv.split('.');
  var exp     = 1;

  for (var i = 0; i < rvParts.length; i++)
  {
    var val = parseInt(rvParts[i]);
    rvValue += val / exp;
    exp *= 100;
  }

  return rvValue;
}

function geckoGetRv()
{
  if (navigator.product != 'Gecko')
  {
    return -1;
  }
  var rvValue = 0;
  var ua      = navigator.userAgent.toLowerCase();
  var rvStart = ua.indexOf('rv:');
  var rvEnd   = ua.indexOf(')', rvStart);
  var rv      = ua.substring(rvStart+3, rvEnd);
  var rvParts = rv.split('.');
  var exp     = 1;

  for (var i = 0; i < rvParts.length; i++)
  {
    var val = parseInt(rvParts[i]);
    rvValue += val / exp;
    exp *= 100;
  }

  return rvValue;
}


function scrollToSelect(name)
  {
  document.forms['vrggForm'][name].focus();
  }

function processState(state) {
  //alert(state);
  document.location.href= "default.asp?action=1&county=&state=" + state;
}


function changeCounty(state){
  //alert(state);
  
  var requestUrl = "getData.asp?action=0&state=" + state; 
  selstate = state;

  createXmlHttp();
  
  if(XmlHttp)
  {
    //alert("got xmlhttp");
    XmlHttp.onreadystatechange = handleResponse;  
    XmlHttp.open("GET",requestUrl, true);
    XmlHttp.send(null);
  }
else
  {
  document.location.href= "default.asp?action=1&state=" + state;
  }
}

function handleResponse() {
var obj = document.getElementById("county-select");
var obj2 = document.getElementById("comet-legend");
var obj3 = document.getElementById("statetd");
var obj4 = document.getElementById("countytd");
var obj5 = document.getElementById("fipstd");
var obj6 = document.getElementById("mlratd");
var obj7 = document.getElementById("lrrtd");

   
  if (XmlHttp.readyState == 4)
  {
    if(XmlHttp.status == 200)
    {
     if(obj){obj.innerHTML = XmlHttp.responseText;}
     if(obj2){obj2.innerHTML = "State/County Selection: " + selstate; }
     if(obj3){obj3.innerHTML = '<b>State: </b><font class="BodyTextBlackSmall">' + selstate + '</font>'; }
     if(obj4){obj4.innerHTML = '<b>County: </b><font class="BodyTextBlackSmall"></font>'; }
     if(obj5){obj5.innerHTML = '<b>Fips: </b><font class="BodyTextBlackSmall"></font>'; }
     if(obj6){obj6.innerHTML = '<b>MLRA: </b><font class="BodyTextBlackSmall"></font>'; }
     if(obj7){obj7.innerHTML = '<b>LRR: </b><font class="BodyTextBlackSmall"></font>'; }
    }
    else
    {
     alert("There was a problem retrieving data from the server.");
    }
  }
}

function selectCounty(county,state){
  //alert(county + " " + state);
  selstate = state;
  var requestUrl = "getData.asp?action=1&county=" + county; 
  createXmlHttp();
  
  if(XmlHttp)
  {
    XmlHttp.onreadystatechange = handleResponse2;  
    XmlHttp.open("GET",requestUrl, true);
    XmlHttp.send(null);
  }
else
  {
  document.location.href= "default.asp?action=1&county=" + county;
  }
   
}



function handleResponse2() {

var obj = document.getElementById("comet-legend");
var obj2 = document.getElementById("countytd");
var obj3 = document.getElementById("submit");

  if (XmlHttp.readyState == 4)
  {
    if(XmlHttp.status == 200)
    {
     if(obj){obj.innerHTML = "State/County Selection: " + selstate + ", " + XmlHttp.responseText;} 
     if(obj2){obj2.innerHTML = '<b>County: </b><font class="BodyTextBlackSmall">' + XmlHttp.responseText + '</font>'};
     if(obj3){obj3.disabled=false;}

    }
    else
    {
     alert("There was a problem retrieving data from the server.");
    }
  }
}


function createXmlHttp()
{

    // code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  XmlHttp =new XMLHttpRequest();
  //alert("got request for mozilla,safari");
  }
     // code for IE
else if (window.ActiveXObject)
  {
  //alert("got request for IE");
  try
  {
    XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch(e)
  {
     try
     {
      XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
     }
     catch(oc)
     {
      XmlHttp = null;
     }
     
  }
 }
  
}



function ws(w){window.status=w;return true;}

function startClock( message )
{
    minutes = minutes-1;
    
    if( !printTime(message) ){  
     return; 
    }
    
    setTimeout(timeoutMsg, 60000);  //60000 = 1 minute
    
    if( minutes == 0 ) {
      document.location.href = "default.asp?action=0&msg=Sorry Your Session Timed Out due to inactivity!";
    }

}

function printTime( message )
{
    var timeLeft = document.getElementById("timeLeft");
    
    if( timeLeft == null ){ return false;}

    var array = message.split(":");   
    var sTimeleft = array[0] + minutes + array[1];
       
	if (minutes < 5) {
			var msg = "<SPAN style='background-color:red; color:black;'>&nbsp;" + sTimeleft + "&nbsp;</SPAN>";
	} else {
			var msg = "<SPAN style='background-color:black; color:white;'>&nbsp;" + sTimeleft + "&nbsp;</SPAN>";
	}

    timeLeft.innerHTML = msg;

    return true;
}

function resetTimer(url)
{
    document.location.href = url + "?action=0&msg=Your Session is Reset to 45 minutes.";
}

// Style Switcher functions
// For details, refer to http://www.alistapart.com/stories/alternate/

//***************************************************************************************************
function setActiveStyleSheet(title) {
	var i, a, main;
	if (document.getElementsByTagName) {
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
				a.disabled = true;
				if(a.getAttribute("title") == title){
				   a.disabled = false;
				   //alert(a.getAttribute("title"));
				 }else{
				   //alert(a.getAttribute("title") + " and " + title + " dont match");
				 }
			}
		}
	}
	
}

//***************************************************************************************************
function getActiveStyleSheet() {
	var i, a;
	if (document.getElementsByTagName) {
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
		}
		return null;
	}
}

//***************************************************************************************************
function getPreferredStyleSheet() {
	var i, a;
	if (document.getElementsByTagName) {
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1
			&& a.getAttribute("rel").indexOf("alt") == -1
			&& a.getAttribute("title")
			) return a.getAttribute("title");
		}
		return null;
	}
}

//***************************************************************************************************
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

//***************************************************************************************************
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

//***************************************************************************************************
window.onload = function(e) {
	if (document.getElementsByTagName) {
		var cookie = readCookie("style");
		var title = cookie ? 'Default' : getPreferredStyleSheet();
		setActiveStyleSheet(title);
	}
}

//***************************************************************************************************
window.onunload = function(e) {
	if (document.getElementsByTagName) {
		var title = getActiveStyleSheet();
		createCookie("style", title, 1);
	}
}


	
//***************************************************************************************************
	function DisplayUserManual ()
	{
		window.open ("../UserGuide/UserGuide_TOC.htm")
	}

//***************************************************************************************************
	function LearnAboutProject ()
	{
		window.open ("http://www.nrel.colostate.edu/projects/agroeco/primer/primer.html")
	}
	
//***************************************************************************************************
	function DisplayPopupHelp (which)
	{
	
	//if ( window.helpWindow ) { window.helpWindow.Close;}
	
	var docFile = "../Help/Help-NoHelp.html"
		
		if (which == 0) /*Report Date*/
			docFile = "../Help/parcelInformation.asp?show=help#Date_info"
		else if (which == 1) /*Parcel Name*/
			docFile = "../Help/parcelInformation.asp?show=help#Parcel_info"
		else if (which == 2) /*Units*/
			docFile = "../Help/parcelInformation.asp?show=help#Units_info"
		else if (which == 3) /*Parcel Size*/
			docFile = "../Help/parcelInformation.asp?show=help#Size_info"
		else if (which == 4) /*State*/
			docFile = "../Help/locationInformation.asp?show=help#State_info"
		else if (which == 5)  /*County*/
			docFile = "../Help/locationInformation.asp?show=help#County_info"
		else if (which == 6) /*SoilTexture*/
			docFile = "../Help/soilInformation.asp?show=help#soiltexture"
		else if (which == 7) /*Hydric*/
			docFile = "../Help/soilInformation.asp?show=help#hydricsoil"
		else if (which == 8)  /*Mgmthistory*/
			docFile = "../Help/managementInformation.asp?show=help#management"
		else if (which == 9)  /*Rotation*/
			docFile = "../Help/managementInformation.asp?show=help#Rotation_info"
		else if (which == 9.1)  /*Rotation*/
			docFile = "../Help/managementInformation.asp?show=help#management_timeperiods"
		else if (which == 9.2)  /*Rotation*/
			docFile = "../Help/managementInformation.asp?show=help#1970s_through_mid-1990s"
		else if (which == 9.3)  /*Rotation*/
			docFile = "../Help/managementInformation.asp?show=help#Base"
		else if (which == 9.4)  /*Rotation*/
			docFile = "../Help/managementInformation.asp?show=help#Management_over_report_period"
		else if (which == 10)  /*Tillage*/
			docFile = "../Help/managementInformation.asp?show=help#Tillage_info"
		else if (which == 11)  /*FuelReport*/
			docFile = "../Help/fuelFertilizer.asp?show=help#Fuel_info"
		else if (which == 12) /*FFuserCalcs*/
			docFile = "../Help/fuelFertilizer.asp?show=help#actual_record"
		else if (which == 13)  /*Help*/
			docFile = "../Help/carbonReport.asp?show=help#Ascii_info"
		else if (which == 14)  /*Uncert*/
			docFile = "../Help/carbonReport.asp?show=help#Uncertainty_info"
		else if (which == 15)  /*Email Name*/
			docFile = "../Help/carbonReport.asp?show=help#Email_name"
		else if (which == 16)  /*Email*/
			docFile = "../Help/carbonReport.asp?show=help#Email_info"
		else if (which == 17)  /*Creport*/
			docFile = "../Help/carbonReport.asp?show=help#Carbon_info"
		else if (which == 18)  /*Ag or Forest*/
			docFile = "../Help/parcelInformation.asp?show=help#Ag_Forest"
		else if (which == 19)  /*Number of Parcels in Entity*/
			docFile = "../Help/parcelInformation.asp?show=help#Entity_Def"
		else if (which == 20)  /*Session Information*/
			docFile = "../Help/sessionInformation.asp?show=help#Session_info"
		    
		var helpWin = window.open ( docFile, "helpWindow",
			"status=no, location=no, directories=no, toolbar=no, width=620, height=400, scrollbars=yes, resizable=yes, dependent=yes" )
			
		helpWin.focus();
	}

//***************************************************************************************************
function setUnits(id, str, str2) {
  
    if (id.indexOf("CurYr") == -1) {
      var obj = getObject(id);
      var obj2 = getObject("Cur"+id);
    } else {
      var obj = getObject(id);
      var obj2 = getObject(id.replace("Cur",""));
    }
    
    //alert(obj.name + ' ' + obj.tagName + ' ' + obj.value);
    
    if (obj) {
      if (obj.innerText){
        obj.innerText = str;
        obj2.innerText = str;
      } else if (obj.value){
        if (obj.value == str) {
          obj.value = str2
          obj2.value = str2
        } else {
          obj.value = str
          obj2.value = str
        }
      } // end if obj.innerText
      
    }  // end if obj
} // end Function



//***************************************************************************************************
function Trim(TRIM_VALUE){
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

//***************************************************************************************************
function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

//***************************************************************************************************
function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function



//***************************************************************************************************
function selectType(id, str) {
 //alert (id + str);

 
//This is the sort routine for the management rotations page

    var obj;
    var objtmp;
    var objsort;
    var objinfo;
    var objtype;
    var objtitle;
    
switch(str) {
      //Agroforestry
      case "riparian buffers": objtype = "Riparian Buffer Managements";
                         break
      case "windbreaks": objtype = "Windbreak Managements";
                         break
      case "silvopasture": objtype = "Silvopasture Managements";
                         break
      case "multistory cropping": objtype = "Multistory Cropping Managements";
                         break
      case "alley cropping": objtype = "Alley Cropping Managements";
                         break

//A
      case "alfalfa","alfalfa hay": objtype = "Alfalfa Hay Managements";
                         break
//B
      case "barley": objtype = "Barley Managements";
                         break
                         
 //C                        
      case "corn": objtype = "Corn Managements";
                         break
      case "corn for silage": objtype = "Corn Silage Managements";
                         break
      case "cotton": objtype = "Cotton Managements";
                         break
      case "clover": objtype = "Clover Managements";
                         break
//D
      case "dry bean": objtype = "Dry Bean Managements";
                         break
                         break
//F
      case "fallow": objtype = "Fallow Managements";
                         break
      case "chemical fallow": objtype = "Fallow Managements";
                         break
      case "mechanical fallow": objtype = "Fallow Managements";
                         break
                         
//G
      case "grass": objtype = "Grass Managements";
                         break
      case "grass hay": objtype = "Grass Hay Managements";
                         break
      case "grass pasture": objtype = "Grass Pasture Managements";
                         break
      case "grass/legume hay": objtype = "Grass/Legume Managements";
                         break
      case "grass/legume hay/pasture mix": objtype = "Grass/Legume Hay/Pasture Managements";
                         break
      case "grass/legume mixture": objtype = "Grass/Legume Managements";
                         break
      case "grass/legume pasture": objtype = "Grass/Legume Pasture Managements";
                         break
      case "grain": objtype = "Grain Managements";
                         break
      case "spring grain": objtype = "Spring Grain Managements";
                         break
      case "small grain": objtype = "Small Grain Managements";
                         break
      case "other small grain": objtype = "Other Small Grain Managements";
                         break
//H
      case "hay": objtype = "Hay Managements";
                         break


//L
      case "legume": objtype = "Legume Managements";
                         break
      case "legume hay": objtype = "Legume Hay Managements";
                         break
      case "legume pasture": objtype = "Legume Pasture Managements";
                         break
//O
      case "oat": objtype = "Oat Managements";
                         break                         
      case "orchard/vineyard": objtype = "Orchard and Vineyard Managements";
                         break
      case "orchard": objtype = "Orchard Managements";
                         break
//P
      case "pasture": objtype = "Pasture Managements";
                        break
      case "grass pasture": objtype = "Grass Pasture Managements";
                        break
      case "pulse": objtype = "Pulse Managements";
                         break
      case "peanuts": objtype = "Peanut Managements";
                         break
      case "potatoes": objtype = "Potatoe Managements";
                         break
                         
//M                         
      case "milo": objtype = "Milo Managements";
//R                         
      case "rice": objtype = "Rice Managements";
                         break

//S
      case "soybean": objtype = "Soybean Managements";
                         break
      case "sorghum": objtype = "Sorghum Managements";
                         break
      case "sugarcane": objtype = "Sugarcane Managements";
                         break
      case "sunflower": objtype = "Sunflower Managements";
                         break
      case "sugar beet": objtype = "Sugar Beet Managements";
                         break                        
      case "spring wheat": objtype = "Spring Wheat Managements";
                         break
//T
      case "tobacco": objtype = "Tobacco Managements";
                         break
//W
      case "winter wheat": objtype = "Winter Wheat Managements";
                         break
                         
//V
      case "vineyard": objtype = "Vineyard Managements";
                         break
      case "vegetables": objtype = "Vegetable Managements";
                         break
//Special types                         
      case "|Irrigated": objtype = "Irrigated Managements";
                         break
                      
      case "|Non-Irrigated": objtype = "Non-Irrigated Managements";
                         break

                             
      case "|Grazing": objtype = "Grazing Managements";
                       break
                             
      case "|AGROFORESTRY": objtype = "AgroForestry Managements";
                       break
                             
      case "|CRP":  objtype = "CRP Managements";
                    break
                    
      case "|Other":  objtype = "OTHER Managements";
                    break
                    
      case "ALL":  objtype = "ALL Managements";
                    break
                    
      default : objtype = "Agricultural Managements";
}  

switch(id) {
      case 'base': obj = document.vrggForm.base; 
                   objsort = document.vrggForm.base_sort;
                   objtmp = document.vrggForm.base_tmp;
                   objinfo = document.getElementById("sortbasenote");
                   objtitle = document.getElementById("basetitle");
                   break
                   
      case 'rot1': obj = document.vrggForm.rot1;
                   objsort = document.vrggForm.rot1_sort;
                   objtmp = document.vrggForm.rot1_tmp;
                   objinfo = document.getElementById("sortrot1note");
                   objtitle = document.getElementById("rot1title");
                   break
                   
      case 'rot2': obj = document.vrggForm.rot2;
                   objsort = document.vrggForm.rot2_sort;
                   objtmp = document.vrggForm.rot2_tmp;
                   objinfo = document.getElementById("sortrot2note");
                   objtitle = document.getElementById("rot2title");
                   break

      case 'rot3': obj = document.vrggForm.rot3;
                   objsort = document.vrggForm.rot3_sort;
                   objtmp = document.vrggForm.rot3_tmp;
                   objinfo = document.getElementById("sortrot3note");
                   objtitle = document.getElementById("rot3title");
                   break
} 
   
   

   if (objtmp.options){
   
      //empty the tmp array and repopulate the selection
      if (objtmp.options.length > 0) {
      //add back to obj
      obj.options.length=0;
      for (i=0; i<objtmp.length; i++){
        if (i == 0) {
          obj.options[obj.options.length]=new Option(objtmp.options[i].text,objtmp.options[i].value,true,true)
        }else{
          obj.options[obj.options.length]=new Option(objtmp.options[i].text,objtmp.options[i].value,false,false)
        }
      }
      }
   }
    
if (str != 'ALL'){
 

    objtmp.options.length=0;
    objsort.options.length=0;
    
  if (obj) {
    
    for (i = 0; i < obj.options.length; i++)
    {
      var optval = obj.options[i].value;
      var textval = obj.options[i].text;
      
      //alert(optval.indexOf(str) + textval);
      
      var is_sort  = ((optval.indexOf(str)!=-1)); 
      //alert(is_sort + " " + optval +" " + textval);
      
      if ( is_sort ){
        objsort.options[objsort.options.length]=new Option(textval,optval,false,false)
        objtmp.options[objtmp.options.length]=new Option(textval,optval,false,false)
      }else {
        if (textval != ''){
          objtmp.options[objtmp.options.length]=new Option(textval,optval,false,false)
        }
      }
    }
    
    if (objsort.length != 0) {
    
      //empty the array and repopulate
      obj.options.length=0;
  
      //new Option(text, value, defaultSelected, selected)
      for (i=0; i < objsort.length; i++){
        if (i == 0 ){
        //alert("selected")
          obj.options[obj.options.length]=new Option(objsort.options[i].text,objsort.options[i].value,true,true)
        }else{
          obj.options[obj.options.length]=new Option(objsort.options[i].text,objsort.options[i].value,false,false)
        }
      }
      objinfo.innerHTML = "<b class='lgtext'>Number of Valid Records: " + objsort.length + "</b>";
      objtitle.innerHTML = objtype;
    } else {
        //give user a message
        //alert("none available");
        
        // empty the array 
        //comment this out to set back to show all managements
        obj.options.length=0;

        var nosel = "<span style='background-color:#FFFFCC ! important;font-size:130%padding:1px;margin:1px;'>Please select another category.</span>";
        objinfo.innerHTML = nosel;
        //change this text to reflect that no managements selected show all
        objtitle.innerHTML = "<span style='background-color:#FFFFCC ! important;font-size:110%;padding:1px;margin:1px;'>Invalid Search</span>";
        //set the seletions to none
        //comment this out to set back to show all managements
        obj.options[obj.options.length]=new Option("None Available","",false,false)
    } // end if objsort !=0
       
  } // end if object
 } else { 
       objinfo.innerHTML = "<b class='lgtext'>Number of Valid Records: " + obj.length + "</b>";
       objtitle.innerHTML = "All Managements";
       
 }  // end if not all  
} // end function


//***************************************************************************************************
function getObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	  // W3C DOM
	  return document.getElementById(objectId);
    } else if (document.all && document.all(objectId)) {
	  // MSIE 4 DOM
	  return document.all(objectId);
    } else if (document.layers && document.layers[objectId]) {
	  // NN 4 DOM.. note: this won't find nested layers
	  return document.layers[objectId];
    } else {
	  return false;
    }
} // getObject

//***************************************************************************************************
function chTextStyle(id,show) {
  // add  "_over" to the existing style
  //alert(document.getElementById([id]).className.indexOf('_over'));
  
  idArray=new Array('navSmallText','navMediumText','navLargeText');
  
  var i;
  
  for(i=0; i<idArray.length; i++) {
    if (show == "on" && id == idArray[i]) {
      chstyle(idArray[i],show);
    }else{
      chstyle(idArray[i],'off');
    }
  } // End for

}

//***************************************************************************************************
function chstyle(id,show) {
  // add  "_over" to the existing style
  //alert(document.getElementById([id]).className.indexOf('_over'));
  
  if (is_nav4) {
 
    
    if (show == 'on') {
         var name = document.layers[id].className + "_over";}
    else if (show == 'off') {
         var name = document.layers[id].className.replace('_over','');
    }else{
       if ( (document.layers[id].className.indexOf('_over')!=-1) ){ 
         var name = document.layers[id].className.replace('_over','');
       }else{
         var name = document.layers[id].className + "_over";
       }
    }

    document.layers[id].className = name;
  }
  else if (is_ie4) { 
     
    if (show == 'on') {
       var name = document.all[id].className + "_over"; }
    else if (show == 'off') {
         var name = document.all[id].className.replace('_over','');
    }else{
       if ( (document.all[id].className.indexOf('_over')!=-1) ){ 
         var name = document.all[id].className.replace('_over','');
       }else{
         var name = document.all[id].className + "_over";
       }
    }
   
    document.all[id].className = name;
  }
  else if (is_ie5up || is_nav6up) { 
    
    if (show == 'on') {
      var name = document.getElementById([id]).className + "_over";}
    else if (show == 'off') {
      var name = document.getElementById([id]).className.replace('_over','');
    }else{
       if ( (document.getElementById([id]).className.indexOf('_over')!=-1) ){ 
         var name = document.getElementById([id]).className.replace('_over','');
       }else{
         var name = document.getElementById([id]).className + "_over";
       }
    }
    
    document.getElementById([id]).className = name;
    }
}
//***************************************************************************************************
function hide(id) {
  
  if (is_nav4) {
  document.layers[id].visibility = 'hide'; 
  document.layers[id].display = 'none'; 
  }
  else if (is_ie4) {
  document.all[id].style.visibility = 'hidden'; 
  document.all[id].style.display = 'none'; 
  }
  else if (is_nav6up || is_ie5up) {
  document.getElementById([id]).style.visibility = 'hidden'; 
  document.getElementById([id]).style.display = 'none'; 
  }
}
//***************************************************************************************************
function show(id,name,base) {
  
  if (is_nav4) {
    if (document.layers[id].visibility == 'show'){vis='hide'; disp='none'}else{vis='show';disp='block';} 
    document.layers[id].visibility = vis; 
    document.layers[id].display = disp; 
  }
  else if (is_ie4) {
      if (document.all[id].style.visibility == 'visible'){vis='hidden'; disp='none'}else{vis='visible';disp='block';} 
      document.all[id].style.visibility = vis; 
      document.all[id].style.display = disp; 
  }
  else if (is_nav6up || is_ie5up) {
      if (document.getElementById([id]).style.visibility == 'visible'){vis='hidden'; disp='none'}else{vis='visible';disp='block';} 
      document.getElementById([id]).style.visibility = vis; 
      document.getElementById([id]).style.display = disp; 
  }
  
  if (name) {
  // need to switch the image
    //alert(name + "  " + name.indexOf('more') + " " + base + "images/carbon/more_button.GIF");
    if (name.indexOf('more')!=-1 && vis == 'visible' || vis == 'show' ){
      var newimg = base + 'images/carbon/less_button.GIF';
      //alert (newimg);
      MM_swapImage(name,'',newimg,4);
    } else {
       var newimg = base + 'images/carbon/more_button.GIF';
       //alert (newimg);
       MM_swapImage(name,'',newimg,4);
    }
  }

}
			
//***************************************************************************************************
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//***************************************************************************************************
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

//***************************************************************************************************
function MM_findObj(n, d) { //v4.0
  var p,i,x;
  if(!d) d=document; 

  if(!(x=d[n])&&d.all) x=d.all[n]; 
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

//***************************************************************************************************
function MM_swapImage() { //v3.0
    //MM_swapImage('l_c_nav1','','../images/usda/l_c_nav_majorContributors_on.gif',1)"
    //This expects a naming convention of blank_on.gif and blank_off.gif
    //The swap is extracted from the src image name and _on.gif is added to the string
    
  var i,j=0,x,a=MM_swapImage.arguments; 
  
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3)
   
   if ((x=MM_findObj(a[i]))!=null){
     document.MM_sr[j++]=x; 
     if(!x.oSrc) {x.oSrc=x.src;}
     var n = x.src;
     if (n.lastIndexOf('over') == -1 ){  //ok to change to over not found in scr
       var end = n.substring(n.lastIndexOf('.'),n.length);
       //alert (a[2]);
       //alert(a[2].lastIndexOf('over'));
     
       if (a[2].lastIndexOf('_over') > -1 ) {
         //alert("doing over");
         //alert(n.substring(0,n.lastIndexOf('.'))+'_over'+end);
         x.src=n.substring(0,n.lastIndexOf('.'))+'_over'+end;
       }
       else if (a[2].lastIndexOf('_on') > -1 ) {
         //alert("doing on");
         x.src=n.substring(0,n.lastIndexOf('_'))+'_on'+end;
       }
       else{
         //alert("doing else");
         x.src=a[2];
       }
       
       } //end n.lastindexof
         
     }
} // End function
