function validate(field)
{
	var valid = "0123456789"
	var ok = "yes";
	var temp; 
	for (var i=0; i<field.value.length; i++) {
	temp = "" + field.value.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") ok = "no";
	}
	
	if (ok == "no") {
		return (false); 
	   }
	return (true); 
}


function isEmpty(theEntry) 
{ 
	var whitespace = " \b\t\n\r"; 

	theInput = theEntry.value ; 
	theLength = theEntry.value.length; 


	if((theInput == null) || (theLength == 0)) 
	{ 
		return (true); 
	} 


	for (var i = 0; i < theLength ; i++) 
	{ 
		var theChar = theInput.charAt(i); 

		if (whitespace.indexOf(theChar) == -1) 
		{ 
		 	return (false); 
		} 
	}
	return (true); 
}

function pageSubmit()
{
	if ((isEmpty(document.frmFLMD.txtZipCode)==true) && (isEmpty(document.frmFLMD.txtDealerName, 100)==true) && ((isEmpty(document.frmFLMD.txtCity)==true)||document.frmFLMD.selState.selectedIndex==0)) 
	{
		alert("Please enter one of the search criteria: \n dealer name or zipcode or city and state");
		return;
	}
			
	if (validate(document.frmFLMD.txtZipCode)==false) 
	{
		alert("Please enter a valid zipcode!!");
		return;
	}
	
	if (isEmpty(document.frmFLMD.txtZipCode)==false)
	{
	   if (document.frmFLMD.txtZipCode.value.length != 5) 
	   {
		   alert ("Zipcode should be 5 digits");
		   return;  
	   }
	}
	document.frmFLMD.submit();
}

function pageFADSubmit()
{
	var PTFlag = "off";
	if ((isEmpty(document.frmFAD.txtZipCode)==true) && (isEmpty(document.frmFAD.txtDealerName, 100)==true) && ((isEmpty(document.frmFAD.txtCity)==true)||document.frmFAD.selState.selectedIndex==0)) 
	{
		alert("Please enter one of the search criteria: \n dealer name or zipcode or city and state");
		return;
	}
			
	if (validate(document.frmFAD.txtZipCode)==false) 
	{
		alert("Please enter a valid zipcode!!");
		return;
	}

	if (isEmpty(document.frmFAD.txtZipCode)==false)
	{
	   if (document.frmFAD.txtZipCode.value.length != 5) 
	   {  
	   		alert ("Zipcode should be 5 digits");
	   		return;
	 	}
	}
	
	if (document.frmFAD.chkPTSearch.checked==true)
		PTFlag = "on";
			
	document.frmFAD.searchFlag.value= PTFlag;
	document.frmFAD.submit();
}

function inputKeyPress()
{
    if (window.event.keyCode == 13)
       pageSubmit();
}
function inputKeyPressfad()
{
    if (window.event.keyCode == 13)
       pageFADSubmit();
}


function openWindow(name, url, height, width) {
	window.open(url, name, 'height='+height+',width='+width+',resizable,scrollbars,')
}


function getCacheResult(action)
{
   	var oForm = window.document.frmMain;
	if (action == "next"){
		oForm.cacheUrl1.value = oForm.nextPageURL1.value;
		//alert(oForm.cacheUrl1.value);
		oForm.cacheUrl2.value = oForm.nextPageURL2.value;
		oForm.dealerType.value = oForm.sDType.value;
	}
	else
	{
		oForm.cacheUrl1.value = oForm.prevPageURL1.value;
		oForm.cacheUrl2.value = oForm.prevPageURL2.value;
		oForm.dealerType.value = oForm.sDType.value;
	}
		
	oForm.submit();
}

function openLocalMap(name,url){
	var client_multimapAddr = window.document.frmMain.client_multimapAddress.value;
	var absolute_url = client_multimapAddr + url;
	
	window.open(absolute_url ,name,"toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=yes,height=550,width=650,left=100,top=100");
}

function getDirections(name, url) {
	
	window.document.frmMain.cacheUrl.value = url;
	window.open( url ,name,"toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=yes,height=550,width=650,left=100,top=100");
}


function gotopage(val)
{
	if (val == 1) 
		window.location.href = "dealercontent.do"
	else 
		window.location.href = "FLM-dealercontent.do"

}

function checkAddr(theForm)
{
	
	if (isEmpty(theForm.startAddress)) 
	{
		alert("Please enter start address!!");
		return false;
	}
	
	if (isEmpty(theForm.startCSZ))
	{
	   	   alert("Please enter City/State or Zip!!");
		   return false;  
	}
	
	return true;

}

function openNewWin(name,url){
		window.open( url ,name,"toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=yes,height=550,width=650,left=100,top=100");
}
