 
 function resetvalue()
 {
 	var mCountry = document.getElementById("selCountry").value;
 	var mState = document.getElementById("selStates").value;
 	var mBrand = document.getElementById("selBrands").value;
 	
	loadData("C", mCountry); 
	if(mCountry == "US" && ( mBrand == "KMT" || mBrand == "WID") )
	{
		document.getElementById("selCounties").disabled = false;
		//loadData("S", mState); cannot call loadData 2 time in a roll
	}
}
 
 function GetXmlHttpObject()
 {
 	var xmlHttp=null;
 	try
 	{
 		 // Firefox, Opera 8.0+, Safari
 		 xmlHttp=new XMLHttpRequest();
 	}
 	catch (e)
 	{
 		// Internet Explorer
 		try
 		{
 			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
 		}
 		catch (e)
 		{
 			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
 		}
 	}
 	return xmlHttp;
 }
 
 var selType;
 
 function loadData(dType, dValue)
 {
 	selType = dType;
 	var mCountry = document.getElementById("selCountry").value;
 	var mBrand = document.getElementById("selBrands").value;
 	
 	
	if(dType =="C")
	{
		
	 
		document.getElementById("selStates").disabled = false;
		if(mCountry == "US" && ( mBrand == "KMT" ||  mBrand == "WID" ||  mBrand == "MAN" ||  mBrand == "CIR" ||  mBrand == "CLP" ||  mBrand == "HAN" ||  mBrand == "MR" ||  mBrand == "MET" ||  mBrand == "RBG" ||  mBrand == "GTD") )
		{
			document.getElementById("selCounties").style.display = 'inline';
			 document.getElementById("lblCounties").style.display = 'inline'; 
			document.getElementById("selCounties").disabled = false;
		}
		else
		{
				document.getElementById("selCounties").style.display = 'none'; 
				 document.getElementById("lblCounties").style.display = 'none'; 
			document.getElementById("selCounties").disabled = true;
		}
	}

	if(dType =="S")
	{
		if( mCountry == "US" && (mBrand == "KMT" ||  mBrand == "WID" ||  mBrand == "MAN" ||  mBrand == "CIR" ||  mBrand == "CLP" ||  mBrand == "HAN" ||  mBrand == "MR" ||  mBrand == "MET" ||  mBrand == "RBG" ||  mBrand == "GTD"))
		{
				document.getElementById("selCounties").style.display = 'inline';
				document.getElementById("lblCounties").style.display = 'inline';
			document.getElementById("selCounties").options.length=1;
			document.getElementById("selCounties").options[0]=new Option("Loading ...", " ", false, false);
		}
		else
		{
			return;
		}
	}
	 
 	xmlHttp=GetXmlHttpObject();
 
 	if (xmlHttp==null)
 	{
 		alert ("Your browser does not support AJAX!");
 		return;
 	}
 
 	var url="/distfinderdata.dyn";
 	url=url+"?t="+ dType + "&v=" + dValue;
 	xmlHttp.onreadystatechange = stateChanged;
 	xmlHttp.open("GET",url,true);
 	xmlHttp.send(null);
 }
 
 
 function stateChanged()
 {
 	if (xmlHttp.readyState==4)
 	{
 		var resText = xmlHttp.responseText;
 		var mySplitResult = resText.split("|");
 		if(selType =="C")
 		{
			if(document.getElementById("selStates").options!=null) 
			{
				document.getElementById("selStates").options.length=1;
			}

			if(mySplitResult.length==1)
			{
				document.getElementById("selStates").disabled = true;
			}
			else
			{
				var i;
				for(i= 0; i<mySplitResult.length; i++)
				{
					document.getElementById("selStates").options[i+1]=new Option(mySplitResult[i], mySplitResult[i], false, false);
				}
			}
		}
		else if (selType =="S")
		{
 			//document.getElementById("txtHint").innerHTML= xmlHttp.responseText;
 			
			var mCountry = document.getElementById("selCountry").value;
			var mBrand = document.getElementById("selBrands").value;
		
			if(mCountry == "US" && ( mBrand == "KMT" ||mBrand == "WID") )
			{
				if(document.getElementById("selCounties").options!=null) 
				{
					document.getElementById("selCounties").options.length=1;
					document.getElementById("selCounties").options[0]=new Option("Choose a County", "ALL", false, false);
				}

				var i;
				for(i= 0; i<mySplitResult.length; i++)
				{
					document.getElementById("selCounties").options[i+1]=new Option(mySplitResult[i], mySplitResult[i], false, false);
				}				
			}
		}
				
 	}
 }


function checkCounty()
{
 	var mCountry = document.getElementById("selCountry").value;
 	var mBrand = document.getElementById("selBrands").value;
 	var mState = document.getElementById("selStates").value;

 	
	if(mCountry == "US" && (mBrand == "KMT" ||  mBrand == "WID" ||  mBrand == "MAN" ||  mBrand == "CIR" ||  mBrand == "CLP" ||  mBrand == "HAN" ||  mBrand == "MR" ||  mBrand == "MET" ||  mBrand == "RBG" ||  mBrand == "GTD") )
	{
		document.getElementById("selCounties").disabled = false;
		loadData("S", mState);
	}
	else
	{
		document.getElementById("selCounties").disabled = true;
	}
}



function isInteger(evt, val)
{		
	var charcode = (evt.which) ? evt.which : evt.keyCode;
	
	if (charcode > 31 && (charcode < 48 || charcode > 57) )
	{
		return false;
	}

	return true;
}

//for Paste
function ispInteger(val)
{		
	var text = window.clipboardData.getData("Text");

	if ((text != 0) && ((text / text) != 1)) 
		return false;
			
	if( text.indexOf(".") != -1 )
		return false;
		
	return true;
}

