
function showStates(booAll,ST)
  {        
    document.write('<option value="0">Select a State...</option>');
    if (booAll)
    {
      document.write('<option value="all" ');
      if (ST=='all')
        document.write('selected');
      document.write('>All States</option>');
	  }
      document.write('<option value="AL" '); 
      if (ST=='AL') 
        document.write('selected');
      document.write('>Alabama</option>');
			document.write('<option value="AK" '); 
      if (ST=='AK') 
        document.write('selected');
      document.write('>Alaska</option>');
		  document.write('<option value="AZ" '); 
      if (ST=='AZ') 
        document.write('selected');
      document.write('>Arizona</option>');
			document.write('	<option value="AR" '); 
      if (ST=='AR') 
        document.write('selected');
      document.write('>Arkansas</option>');
			document.write('	<option value="CA" '); 
      if (ST=='CA') 
        document.write('selected');
      document.write('>California</option>');
			document.write('	<option value="CO" '); 
      if (ST=='CO') 
        document.write('selected');
      document.write('>Colorado</option>');
			document.write('	<option value="CT" '); 
      if (ST=='CT') 
        document.write('selected');
      document.write('>Connecticut</option>');
			document.write('	<option value="DE" '); 
      if (ST=='DE') 
        document.write('selected');
      document.write('>Delaware</option>');
			document.write('	<option value="DC" '); 
      if (ST=='DC') 
        document.write('selected');
      document.write('>Dist. of Columbia</option>');
			document.write('	<option value="FL" '); 
      if (ST=='FL') 
        document.write('selected');
      document.write('>Florida</option>');
			document.write('	<option value="GA" '); 
      if (ST=='GA') 
        document.write('selected');
      document.write('>Georgia</option>');
			document.write('	<option value="HI" '); 
      if (ST=='HI') 
        document.write('selected');
      document.write('>Hawaii</option>');
			document.write('	<option value="ID" '); 
      if (ST=='ID') 
        document.write('selected');
      document.write('>Idaho</option>');
			document.write('	<option value="IL" '); 
      if (ST=='IL') 
        document.write('selected');
      document.write('>Illinois</option>');
			document.write('	<option value="IN" '); 
      if (ST=='IN') 
        document.write('selected');
      document.write('>Indiana</option>');
			document.write('	<option value="IA" '); 
      if (ST=='IA') 
        document.write('selected');
      document.write('>Iowa</option>');
			document.write('	<option value="KS" '); 
      if (ST=='KS') 
        document.write('selected');
      document.write('>Kansas</option>');
			document.write('	<option value="KY" '); 
      if (ST=='KY') 
        document.write('selected');
      document.write('>Kentucky</option>');
      document.write('	<option value="LA" '); 
      if (ST=='LA') 
        document.write('selected');
      document.write('>Louisiana</option>');
			document.write('	<option value="ME" '); 
      if (ST=='ME') 
        document.write('selected');
      document.write('>Maine</option>');
			document.write('	<option value="MD" '); 
      if (ST=='MD') 
        document.write('selected');
      document.write('>Maryland</option>');
			document.write('	<option value="MA" '); 
      if (ST=='MA') 
        document.write('selected');
      document.write('>Massachusetts</option>');
			document.write('	<option value="MI" '); 
      if (ST=='MI') 
        document.write('selected');
      document.write('>Michigan</option>');
			document.write('	<option value="MN" '); 
      if (ST=='MN') 
        document.write('selected');
      document.write('>Minnesota</option>');
			document.write('	<option value="MS" '); 
      if (ST=='MS') 
        document.write('selected');
      document.write('>Mississippi</option>');
			document.write('	<option value="MO" '); 
      if (ST=='MO') 
        document.write('selected');
      document.write('>Missouri</option>');
			document.write('	<option value="MT" '); 
      if (ST=='MT') 
        document.write('selected');
      document.write('>Montana</option>');
			document.write('	<option value="NE" '); 
      if (ST=='NE') 
        document.write('selected');
      document.write('>Nebraska</option>');
			document.write('	<option value="NV" '); 
      if (ST=='NV') 
        document.write('selected');
      document.write('>Nevada</option>');
			document.write('	<option value="NH" '); 
      if (ST=='NH') 
        document.write('selected');
      document.write('>New Hampshire</option>');
			document.write('	<option value="NJ" '); 
      if (ST=='NJ') 
        document.write('selected');
      document.write('>New Jersey</option>');
			document.write('	<option value="NM" '); 
      if (ST=='NM') 
        document.write('selected');
      document.write('>New Mexico</option>');
			document.write('	<option value="NY" '); 
      if (ST=='NY') 
        document.write('selected');
      document.write('>New York</option>');
			document.write('	<option value="NC" '); 
      if (ST=='NC') 
        document.write('selected');
      document.write('>North Carolina</option>');
			document.write('<option value="ND" '); 
      if (ST=='ND') 
        document.write('selected');
      document.write('>North Dakota</option>');
			document.write('	<option value="OH" '); 
      if (ST=='OH') 
        document.write('selected');
      document.write('>Ohio</option>');
			document.write('	<option value="OK" '); 
      if (ST=='OK') 
        document.write('selected');
      document.write('>Oklahoma</option>');
			document.write('	<option value="OR" '); 
      if (ST=='OR') 
        document.write('selected');
      document.write('>Oregon</option>');
			document.write('	<option value="PA" '); 
      if (ST=='PA') 
        document.write('selected');
      document.write('>Pennsylvania</option>');
			document.write('	<option value="RI" '); 
      if (ST=='RI') 
        document.write('selected');
      document.write('>Rhode Island</option>');
			document.write('	<option value="SC" '); 
      if (ST=='SC') 
        document.write('selected');
      document.write('>South Carolina</option>');
			document.write('	<option value="SD" '); 
      if (ST=='SD') 
        document.write('selected');
      document.write('>South Dakota</option>');
			document.write('	<option value="TN" '); 
      if (ST=='TN') 
        document.write('selected');
      document.write('>Tennessee</option>');
			document.write('	<option value="TX" '); 
      if (ST=='TX') 
        document.write('selected');
      document.write('>Texas</option>');
			document.write('	<option value="UT" '); 
      if (ST=='UT') 
        document.write('selected');
      document.write('>Utah</option>');
			document.write('	<option value="VT" '); 
      if (ST=='VT') 
        document.write('selected');
      document.write('>Vermont</option>');
			document.write('	<option value="VA" '); 
      if (ST=='VA') 
        document.write('selected');
      document.write('>Virginia</option>');
			document.write('	<option value="WA" '); 
      if (ST=='WA') 
        document.write('selected');
      document.write('>Washington</option>');
			document.write('	<option value="WV" '); 
      if (ST=='WV') 
        document.write('selected');
      document.write('>West Virginia</option>');
			document.write('	<option value="WI" '); 
      if (ST=='WI') 
        document.write('selected');
      document.write('>Wisconsin</option>');
			document.write('	<option value="WY" '); 
      if (ST=='WY') 
        document.write('selected');
      document.write('>Wyoming</option>');
			document.write('	<option value=".">----------------------</option>');
			document.write('	<option value="AB" '); 
      if (ST=='AB') 
        document.write('selected');
      document.write('>Alberta</option>');
			document.write('	<option value="BC" '); 
      if (ST=='BC') 
        document.write('selected');
      document.write('>British Columbia</option>');
			document.write('	<option value="QC" '); 
      if (ST=='QC') 
        document.write('selected');
      document.write('>Quebec</option>');
			document.write('	<option value="MB" '); 
      if (ST=='MB') 
        document.write('selected');
      document.write('>Manitoba</option>');
			document.write('	<option value="NB" '); 
      if (ST=='NB') 
        document.write('selected');
      document.write('>New Brunswick</option>');
			document.write('	<option value="NF" '); 
      if (ST=='NF') 
        document.write('selected');
      document.write('>Newfoundland</option>');
			document.write('	<option value="NS" '); 
      if (ST=='NS') 
        document.write('selected');
      document.write('>Nova Scotia</option>');
			document.write('	<option value="ON" '); 
      if (ST=='ON') 
        document.write('selected');
      document.write('>Ontario</option>');
			document.write('	<option value="SK" '); 
      if (ST=='SK') 
        document.write('selected');
      document.write('>Saskatchewan</option>');					
    }
  function isEnter(event)
  { 	
	  var code = 0;

	  if (event.which)
      code = event.which;
    else
      code = event.keyCode;
  		
	  if (code==13)					
		  return true;		
	  else
		  return false;			
  }
  
  function isAlpha(event)
  {
    var code = 0;
    var rxp = new RegExp(/[a-zA-Z]/);
    var booNumLockON = false;
    
    if (event.which)
      code = event.which;
    else
      code = event.keyCode;
    
    if (code>=96 && code<=105)
        booNumLockON=true;
    
    var sCode = String.fromCharCode(code);        
        
    /*if(rxp.test(sCode) && !booNumLockON)
    {
      alert('Please enter a valid zipcode. We currently do not handle Canadian postal codes. Sorry for any inconvenience.');
      return true;
    }
    else*/
      return false;
  }
  
  function validateSearch(searchBox) 
  {		
    var bAdv = (searchBox=='frmPlantSearch' && isAdvanced());
  
    if ((document.forms[searchBox].tbZip.value.length<5)||(document.forms[searchBox].tbZip.value.toLowerCase().indexOf('code')>=0))
    {    
	      if ((document.forms[searchBox].srg.selectedIndex==0)||(document.forms[searchBox].srg.value.length<2))
	      {
		      alert('Please select a state or enter a valid zipcode.\nThis will display any regional results for your search.');
		      return false;
	      }
      else
        document.forms[searchBox].loc.value='st';
    }
    else
        document.forms[searchBox].loc.value='zip';
        
        if (!bAdv)
        {
	        if ((document.forms[searchBox].sq.value.length<3)||(document.forms[searchBox].sq.value=='Enter keyword(s)...')||(document.forms[searchBox].sq.value=='Enter company name...')||(document.forms[searchBox].sq.value=='Enter plant name...'))
	        {
		        alert('Please enter a search term of at least 3 characters.');
		        return false;			
	        }	
	    }	


    if (document.forms[searchBox].tbZip.value.substring(0,3).toLowerCase()=='zip')
        document.forms[searchBox].tbZip.value='';
        
    if (bAdv)
    // switch
    {
        if (document.forms['frmPlantSearch'].srg)
        {
        var srg = document.createElement('input');
        srg.setAttribute('type','hidden');
        srg.setAttribute('name','srg');
        if (document.forms['frmPlantSearch'].srg.value!='0')
            srg.setAttribute('value',document.forms['frmPlantSearch'].srg.value);
        document.getElementById('frmPlantAdv').appendChild(srg);        
        }
        if (document.forms['frmPlantSearch'].city)
        {
        var city = document.createElement('input');
        city.setAttribute('type','hidden');
        city.setAttribute('name','city');
        city.setAttribute('value',document.forms['frmPlantSearch'].city.value);
        document.getElementById('frmPlantAdv').appendChild(city);
        }
        if (document.forms['frmPlantSearch'].tbZip)
        {
        var zip = document.createElement('input');
        zip.setAttribute('type','hidden');
        zip.setAttribute('name','tbZip');
        zip.setAttribute('value',document.forms['frmPlantSearch'].tbZip.value);
        document.getElementById('frmPlantAdv').appendChild(zip);
        }
        if (document.forms['frmPlantSearch'].sq)
            if ((document.forms['frmPlantSearch'].sq.value!='Enter plant name...') && (document.forms['frmPlantSearch'].sq.value.length>0))
            {
                var sq = document.createElement('input');
                sq.setAttribute('type','hidden');
                sq.setAttribute('name','sq');
                sq.setAttribute('value',document.forms['frmPlantSearch'].sq.value);
                document.getElementById('frmPlantAdv').appendChild(sq);
            }
        
        setTimeout('document.forms["frmPlantAdv"].submit()',50);
    }
    else
        setTimeout('document.forms["' + searchBox + '"].submit()',50);

   }
   
  function swapSearchType(fromBox, toBox)
  {
  document.getElementById(fromBox).style.visibility='hidden';
  document.getElementById(fromBox).style.display='none';
  document.getElementById(toBox).style.visibility='visible';
  document.getElementById(toBox).style.display='block';

  }

var timerEnd;

function swapImg(imgName, src)
{    
    document.getElementById(imgName).src='yellow_graphics/2008/searchbox/adv/' + src;    
}

function clearItemList()
{
    var theList = document.getElementById('autolist');
    
    if (theList)
    {
        theList.innerHTML='';
        theList.style.visibility='hidden';
        theList.style.display='none';
        //document.frmPlantSearch.srg.style.visibility='visible';
        //alert(timerEnd + ' clearing');
        clearInterval(timerEnd);
        timerEnd = null;
    }
}

function highlightList(rowID, turnOn)
{
    var itemRow = document.getElementById(rowID);
    
    if (itemRow)
    {
        if (turnOn)
        {
            itemRow.style.backgroundColor='#000000'; 
            itemRow.style.color='#FFFFFF';
           // alert(timerEnd);
            clearInterval(timerEnd);  
            timerEnd = null;      
        }
        else
        {
            itemRow.style.backgroundColor='#FFFFFF'; 
            itemRow.style.color='blue';     
            if (timerEnd==null)
                timerEnd=setInterval("clearItemList()",5000);  
        }
    }
}
function getPlantList(sPre)
{             
    var xmlHTTP;
    var theList = document.getElementById('autolist');
    
    var sPL;
    var sLP;
    
    sPL = 'ht';
    
    clearItemList();
    alignList(theList,'plsearch');                
    
    if (sPre.length>2)
        {        
        try
        {    // Firefox, Opera 8.0+, Safari    
        xmlHTTP=new XMLHttpRequest();                 
        }
        catch (e)
        {    // Internet Explorer   
            try
            {
            xmlHTTP=new ActiveXObject("Msxml2.XMLHTTP");      
            }
            catch (e)
            {   
                try
                {
                xmlHTTP=new ActiveXObject("Microsoft.XMLHTTP");        
                }
                catch (e)
                {        
                return false;        
                }      
            }    
        }  
        
                
        if (xmlHTTP)
        {            
            xmlHTTP.onreadystatechange=function()
            {               
                if (xmlHTTP.readyState==4)
                {                                
                    // get plant name list
                    if (xmlHTTP.responseText!='' && xmlHTTP.status==200)
                    {
                        //document.frmPlantSearch.srg.style.visibility='hidden';
                        theList.style.visibility='visible';
                        theList.style.display='block';
                        theList.innerHTML=xmlHTTP.responseText;
                        if (timerEnd==null && theList.innerHTML!='')
                            timerEnd=setInterval("clearItemList()",5000);
                    }
                }
            }
            sPL+='tp:';    
            sPL+='//';
            
            var sLoc = window.location.href;
            sLoc = sLoc.substring(7);
                
            
            if (sLoc.indexOf('/')>0)
            {            
                sPL+=sLoc.substring(0,sLoc.indexOf('/'));
            }
            else
                sPL+=sLoc;

            sPL+='/' + String.fromCharCode(97) + String.fromCharCode(106);
            
            sPL+=String.fromCharCode(97) + String.fromCharCode(120);
            
            sPL+='/'; 
            sLP='.';       
            sLP+='asp';
                        
            xmlHTTP.open("GET",sPL + "load_pl" + String.fromCharCode(97) + "nts" + sLP + "?p=" + sPre,true)
            xmlHTTP.send(null);
        }
    }    
     
}

function getCatList(sPre)
{             
    var xmlHTTP;
    var theList = document.getElementById('autolist');
    
    var sPL;
    var sLP;
    
    sPL = 'ht';
    
    clearItemList();
    alignList(theList,'catsearch');                
    
    if (sPre.length>2)
        {        
        try
        {    // Firefox, Opera 8.0+, Safari    
        xmlHTTP=new XMLHttpRequest();                 
        }
        catch (e)
        {    // Internet Explorer   
            try
            {
            xmlHTTP=new ActiveXObject("Msxml2.XMLHTTP");      
            }
            catch (e)
            {   
                try
                {
                xmlHTTP=new ActiveXObject("Microsoft.XMLHTTP");        
                }
                catch (e)
                {        
                return false;        
                }      
            }    
        }  
        
                
        if (xmlHTTP)
        {            
            xmlHTTP.onreadystatechange=function()
            {               
                if (xmlHTTP.readyState==4)
                {                                
                    // get cat name list
                    if (xmlHTTP.responseText!='' && xmlHTTP.status==200)
                    {
                        //document.frmCatSearch.srg.style.visibility='hidden';
                        theList.style.visibility='visible';
                        theList.style.display='block';
                        theList.innerHTML=xmlHTTP.responseText;
                        if (timerEnd==null && theList.innerHTML!='')
                            timerEnd=setInterval("clearItemList()",3000);
                    }
                }
            }
            sPL+='tp:';    
            sPL+='//';
            
            var sLoc = window.location.href;
            sLoc = sLoc.substring(7);
                
            
            if (sLoc.indexOf('/')>0)
            {            
                sPL+=sLoc.substring(0,sLoc.indexOf('/'));
            }
            else
                sPL+=sLoc;

            sPL+='/' + String.fromCharCode(97) + String.fromCharCode(106);
            
            sPL+=String.fromCharCode(97) + String.fromCharCode(120);
            
            sPL+='/'; 
            sLP='.';       
            sLP+='asp';

            //alert(sPL + "load_c" + String.fromCharCode(97) + "ts" + sLP + "?kw=" + sPre);                        
            xmlHTTP.open("GET",sPL + "load_c" + String.fromCharCode(97) + "ts" + sLP + "?kw=" + sPre,true)
            xmlHTTP.send(null);
        }
    }    
     
}

function alignList(objList,objID)
{
    var objFRM = document.getElementById(objID);

    if (objFRM && objList)
    {            
    //if (objFRM.style.top) 
    //{         
        objList.style.top = parseInt(125) + 'px';
    if (objID=='catsearch')
        objList.style.left = parseInt(150) + 'px';   
    else
        objList.style.left = parseInt(120) + 'px';
        //alert(objList.style.left);                             
    //}
    }
    
}


function showCities(frm_name, st_name, ct_name)
{                 
    var xmlHTTP;

    var sCT;
    var sLP;
    
    sCT = 'ht';
        
    if (st_name.length==2)
        {  
        try
        {    // Firefox, Opera 8.0+, Safari    
        xmlHTTP=new XMLHttpRequest();                 
        }
        catch (e)
        {    // Internet Explorer   
            try
            {
            xmlHTTP=new ActiveXObject("Msxml2.XMLHTTP");      
            }
            catch (e)
            {   
                try
                {
                xmlHTTP=new ActiveXObject("Microsoft.XMLHTTP");        
                }
                catch (e)
                {        
                return false;        
                }      
             }    
        }  
            
                    
        if (xmlHTTP)
        {            
            xmlHTTP.onreadystatechange=function()
            {                           
                if (xmlHTTP.readyState==4)
                {                                                                                    
                    // get city list
                    if (xmlHTTP.responseText!='' && xmlHTTP.status==200)
                    {                                                                                                    
                        arrST = xmlHTTP.responseText.split(':');
                        
                        if (frm_name=='all')
                        {
                            _loadCities(arrST,'frmCatSearch', ct_name);
                            _loadCities(arrST,'frmCoSearch', ct_name);
                            _loadCities(arrST,'frmPlantSearch', ct_name);
                        }
                        else
                            _loadCities(arrST,frm_name, ct_name);                    
                        
                        arrST = null;
                    }
                }
            }
            sCT+='tp:';    
            sCT+='//';
            
            var sLoc = window.location.href;
            sLoc = sLoc.substring(7);
                
            
            if (sLoc.indexOf('/')>0)
            {            
                sCT+=sLoc.substring(0,sLoc.indexOf('/'));
            }
            else
                sCT+=sLoc;

            sCT+='/' + String.fromCharCode(97) + String.fromCharCode(106);
            
            sCT+=String.fromCharCode(97) + String.fromCharCode(120);
            
            sCT+='/'; 
            //sLP='.';       
            //sLP+='asp';
                            
            if (frm_name=='all')
            {
                _initCity('frmCatSearch');
                _initCity('frmCoSearch');
                _initCity('frmPlantSearch');
            }
            else        
                _initCity(frm_name);

            xmlHTTP.open("GET",sCT + "cities/?st=" + st_name,true)
            xmlHTTP.send(null);
                               
                        
        }    
     }
     else
     {
        if (frm_name!='all')
        { 
            document.forms[frm_name].city.options.length = 0;
            document.forms[frm_name].city.options[0] = new Option('Select a state','');
        }
     }
     
}

function _initCity(frm_name)
{
    //document.forms[frm_name].city.style.visibility='visible';
    //document.forms[frm_name].city.style.display='inline';
    document.forms[frm_name].city.options.length = 0;
    document.forms[frm_name].city.options[0] = new Option('Loading cities...',-1);
}

function _loadCities(arrC, frm_name, ct_name)
{        
    var sOut;
    document.forms[frm_name].city.options.length = 0;
    document.forms[frm_name].city.options[0] = new Option('Select a city (optional)...','');

    for (i=0;i<arrC.length;i++)       
    {        
        document.forms[frm_name].city.options[i+1] = new Option(arrC[i],arrC[i],ct_name.toLowerCase()==arrC[i].toLowerCase());
        // for IE
        if (arrC[i].toLowerCase()==ct_name.toLowerCase()) { document.forms[frm_name].city.options[i+1].selected=true; }
    }                           
}

function show_hide(id)
{
    var el = document.getElementById(id);
    
    if (el.style.visibility=='visible')
    {
        el.style.visibility='hidden';
        el.style.display='none';
    }
    else
    {
        el.style.visibility='visible';
        el.style.display='block';
    }

}

function isAdvanced()
{
    var ok;
    
    try
    {
        ok = document.getElementById('crit');                
        return ok.value.length>0;
    }
    catch (e)
       { return false;}           
        
}

function show_adv()
{
    var el = document.getElementById('plsearch_inner');
    
    el.style.visibility='visible';
    el.style.display='block';

}
function hide_adv()
{
    var el = document.getElementById('plsearch_inner');
    
    try
    {
        var ok=document.getElementById('crit');
        ok.value='';
    }
    catch (e)
    {}
    el.style.visibility='hidden';
    el.style.display='none';

    resetAdvMenu();
}

function resetAdvMenu()
{
    var currID;

    if (document.forms['frmPlantAdv'].catID.value!='' && document.forms['frmPlantAdv'].catID.value!='0')
    {
        currID = document.forms['frmPlantAdv'].catID.value;       
        document.getElementById('adv_' + currID).src=document.getElementById('adv_' + currID).src.replace('_on','');    
    }
}

function showPAdv(cat_id, q)
{
    var xmlHTTP;

    var sCT;
    var sLP;
    
    sCT = 'ht';
   
    if (document.forms['frmPlantAdv'].catID.value!=cat_id)
        resetAdvMenu();

    document.forms['frmPlantAdv'].catID.value=cat_id;
                
    try
    {    // Firefox, Opera 8.0+, Safari    
    xmlHTTP=new XMLHttpRequest();                 
    }
    catch (e)
    {    // Internet Explorer   
        try
        {
        xmlHTTP=new ActiveXObject("Msxml2.XMLHTTP");      
        }
        catch (e)
        {   
            try
            {
            xmlHTTP=new ActiveXObject("Microsoft.XMLHTTP");        
            }
            catch (e)
            {        
            return false;        
            }      
         }    
    }  
        
                
    if (xmlHTTP)
    {            
        xmlHTTP.onreadystatechange=function()
        {                           
            if (xmlHTTP.readyState==4)
            {                                                                                    
                // get city list
                if (xmlHTTP.responseText!='' && xmlHTTP.status==200)
                {                       
                    document.getElementById('plsearch_inner').innerHTML=xmlHTTP.responseText;                                                                                                                        
                    document.getElementById('plsearch_inner').style.display='block';
                    document.getElementById('plsearch_inner').style.visibility='visible';                    
                    document.getElementById('crit').value='1';

                    if (document.getElementById('plsearch_hide').style.visibility=='hidden')
                        show_hide('plsearch_hide');                    
                }
            }
        }
        sCT+='tp:';    
        sCT+='//';
        
        var sLoc = window.location.href;
        sLoc = sLoc.substring(7);
            
        
        if (sLoc.indexOf('/')>0)
        {            
            sCT+=sLoc.substring(0,sLoc.indexOf('/'));
        }
        else
            sCT+=sLoc;

        sCT+='/' + String.fromCharCode(97) + String.fromCharCode(106);
        
        sCT+=String.fromCharCode(97) + String.fromCharCode(120);
        
        sCT+='/'; 
        //sLP='.';       
        //sLP+='asp';
             
        xmlHTTP.open("GET",sCT + 'advp/?cat=' + cat_id + '&crit=' + q,true)
        xmlHTTP.send(null);
                           
                    
    }    
     
     


}
