﻿
//check for an existing farmname
function getCounty4State(StateCode) 
    {
        ajaxData.getCounty4State(StateCode, StateCodeComplete, OnError, OnTimeOut);
    }
    
function StateCodeComplete(arg)
    {
        //document.getElementById("ctl00_cphWorkSpace_fvFarmInfo_ddlCounties");
        var oSelect= document.getElementById("ctl00_cphWorkSpace_fvFarmInfo_ddlCounties");
        
        var cntys = arg.split("|")
                
        // clear dropdownlist
		for(var i=oSelect.length-1; i>=0; i--)
		{
			oSelect.options[i] = null;
		}

        opt = new Option("Select", "0");
		oSelect.options[oSelect.length] = opt;

		// populate dropdownlist from name-value object
		for(var i=0; i<cntys.length; i++)
		{
//			if (cntys[i].value == undefined)
//			{
//				oSelect.options[oSelect.length] = new Option(cntys[i]);
//			}
//			else
//			{
				if (cntys[i].length>0) {
				opt = new Option(cntys[i], cntys[i]);
				oSelect.options[oSelect.length] = opt;
				}
//			}
		}
    }


//check for an existing username
function checkUserName(UserName) 
    {
        ajaxData.check4UserName(UserName, UserNameComplete, OnError, OnTimeOut);
    }
    
function UserNameComplete(arg)
    {
        
        if(arg=="yes")
        {
            alert("That UserName is currently in use. Please choose another UserName\n or if you have already created an account go back and select\n'Sign in to your account'");
            var itm= document.getElementById("ctl00_cphInstructions_fvUserInfo_tbUserName");
            
            itm.value="";
            itm.select();
        }

    }

//check for an existing farmname
function checkFarmName(FarmName) 
    {
        ajaxData.check4FarmName(FarmName, FarmNameComplete, OnError, OnTimeOut);
    }
    
function FarmNameComplete(arg)
    {
        
        if(arg=="yes")
        {
            alert("That farm name is in use. Please choose another name");
            var itm= document.getElementById("ctl00_cphWorkSpace_fvFarmInfo_tbFarmName");
            
            itm.value="";
            itm.select();
        }

    }

//get the alternatives
function getAlternatives(resourceTypeID, tbID) 
    {
        ajaxData.getAlternatives(resourceTypeID,tbID, OnComplete, OnError, OnTimeOut);
    }
    
    function OnComplete(arg)
        {
            document.getElementById('results').style.display ='block';
            document.getElementById('results').innerHTML = arg;
            document.getElementById('shell').innerHTML = "Hide Alternatives";
            
        }


function OnTimeOut(arg)
        {
            alert("timeOut has occured");
        }
        
    function OnError(arg)
        {
        alert("error has occured: " + arg._message);
        }
      
      
function copyHTML(val,obj)
{
    
  var dtTA=obj;

  var valToAdd=val+",\n";
  
  var inthere = dtTA.value.indexOf(val);
   
   if(inthere<0)
   {   
    dtTA.value += valToAdd; 
   }
   else
   {
    alert("You have already added "+ val);
   } 

}
   
function displayDiv(item)
{ 
	var itm=document.getElementById(item);
	
	if (itm.style.display == 'none') {
		itm.style.display ='block';
		}
	else {
		itm.style.display ='none';
		}
}

function displayAltDiv(item)
{ 
	var itm=document.getElementById(item);
	
	if (itm.style.display == 'none') {
		itm.style.display ='block';
		document.getElementById('shell').innerHTML = "Hide Alternatives";
		}
	else {
		itm.style.display ='none';
		document.getElementById('shell').innerHTML = "Show Alternatives";
		}
}

function popIT(url, name)
{
    window.open (url,name,"location=1,status=1,scrollbars=1,width=800,height=600"); 

}


// Prevents session timeout
var timer = setTimeout('refresh()', 30000);

function refresh()
{
    var xmlHttp;
    if (window.ActiveXObject)
    {
        var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {
        var xmlHttp = new XMLHttpRequest();
    }

    xmlHttp.open("GET", "Refresh.aspx", false);
    xmlHttp.send(null);

    timer = setTimeout('refresh()', 30000);
}




