
function PopMe(url, name, features)
{
	var w = window.open(url, name, features);
	w.focus();
}
function ZipCode(zip) 
{	// Check that a US zip code is valid
var zip = removeSpaces(zip);

	if (!(zip.length == 5 || zip.length == 9 || zip.length == 10)) return false;
	if ((zip.length == 5 || zip.length == 9) && !isNumeric(zip)) return	false;
	if (zip.length == 10 && zip.search && zip.search(/^\d{5}-\d{4}$/) == -1) return false;
	return true;
	
}	
function PostalCode(zipcode) 
{	// Check that a Canadian postal code is valid
	var zip = removeSpaces(zipcode);					
		if (zip.length == 6 && zip.search(/^[a-zA-Z]\d[a-zA-Z]\d[a-zA-Z]\d$/)!= -1) return true;
		else
		if (zip.length == 7 &&
			zip.search(/^[a-zA-Z]\d[a-zA-Z]-\d[a-zA-Z]\d$/) != -1) return true;
		else return false;
	
	return true;
}
function validate(zip,city,send)
{
	if (zip != "" )
	{
		validCode(zip,send);
	}
	else
	{
		validCity(city,send);
	}
}
function validCity(city,send)
{	
	if(send == true)
	{
		//set screen center
		var height = 600;
		var width = 560;
		var screenx = 0;
		var screeny = 0;
		if(navigator.appName == "Microsoft Internet Explorer")
		{
			screenY = document.body.offsetHeight
			screenX = window.screen.availWidth
		}
		else
		{ 
				screenY = screen.height;
				screenX = screen.width;
		}
		screenX = (screen.availWidth - width)/2;
		screenY = (screen.availHeight - height)/2;
		document.DealerLocator.city.focus();
		PopMe('/DealerLocator/pop_dealer_listing.aspx?city='+ document.DealerLocator.city.value +'&state='+ document.DealerLocator.stateProvinceDropDownList.value +'&country='+ getCountry(),'DealerLocator','scrollbars=yes,resizable=yes,width='+ width +',height='+ height +',left='+ screenX +',top='+ screenY );
		
	}
	//document.DealerLocator.submit();
	
	return true;
 }
			
 function validCode(zip,send)
 {
	if (document.DealerLocator.country[0].checked )
	{
		if (ZipCode(zip)!= true)
		{
			alert('Please enter valid zip code (#####[-####])');
			document.DealerLocator.postalcode.focus();
			return false;
		}
	}
	else
	{
		if (PostalCode(zip)!= true)
		{
			alert('Please enter valid postal code (?#? #?#)');
			document.DealerLocator.postalcode.focus();
			return false;
			
		}
	}
	if(send == true)
	{
		//set screen center
		var height = 600;
		var width = 560;
		var screenx = 0;
		var screeny = 0;
		if(navigator.appName == "Microsoft Internet Explorer")
		{
			screenY = document.body.offsetHeight
			screenX = window.screen.availWidth
		}
		else
		{ 
				screenY = screen.height;
				screenX = screen.width;
		}
		screenX = (screen.availWidth - width)/2;
		screenY = (screen.availHeight - height)/2;
		document.DealerLocator.postalcode.focus();
		PopMe('/DealerLocator/pop_dealer_listing.aspx?zip='+ document.DealerLocator.postalcode.value +'&miles='+document.DealerLocator.Miles.value+'&country='+ getCountry(),'DealerLocator','scrollbars=yes,resizable=yes,width='+ width +',height='+ height +',left='+ screenX +',top='+ screenY );
		
	}
	//document.DealerLocator.submit();
	
	return true;
 }
 
 function MapUp(state)
{

		//set screen center
		var height = 600;
		var width = 560;
		var screenx = 0;
		var screeny = 0;
		if(navigator.appName == "Microsoft Internet Explorer")
		{
			screenY = document.body.offsetHeight
			screenX = window.screen.availWidth
		}
		else
		{ 
				screenY = screen.height;
				screenX = screen.width;
		}
		screenX = (screen.availWidth - width)/2;
		screenY = (screen.availHeight - height)/2;
		PopMe('/DealerLocator/pop_dealer_listing.aspx?state=' + state,'DealerLocator','scrollbars=yes,resizable=yes,width='+ width +',height='+ height +',left='+ screenX +',top='+ screenY );
	
	//setSelectedIndex(document.DealerLocator.stateprovince,state);
	//document.DealerLocator.submit();
	document.DealerLocator.city.focus();
	return true;
 }
 
 function validCodes(zip)
 {
  if ( ZipCode(zip)==true || PostalCode(zip)==true)
	{
		document.DealerLocator.submit();
		document.DealerLocator.postalcode.focus();
		return true;
	}
	else
	{		
		alert('Please enter valid postal code ');
		document.DealerLocator.postalcode.focus();
		return false;
	}
 }
 
  function clearOther(e)
 {
  if ( e == "zip" )
	{
		document.DealerLocator.city.value = "";
		document.DealerLocator.stateProvinceDropDownList.selectedIndex = 0;		
	}
	else
	{		
		document.DealerLocator.postalcode.value = "";
		document.DealerLocator.Miles.selectedIndex = 0;		
	}
 }
 function removeSpaces(string) {
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];	
	return tstring;
}

function isNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
function querySt(ji) 
{
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == ji) {
			return ft[1];
		}
	}
}
function setSelectedIndex(s, v) {
    for ( var i = 0; i < s.options.length; i++ ) {
        if ( s.options[i].value == v ) {
            s.options[i].selected = true;
            return;
        }
    }
}
function getCountry()
{
for (var i=0; i < document.DealerLocator.country.length; i++)
   {
   if (document.DealerLocator.country[i].checked)
      {
      return document.DealerLocator.country[i].value;
      }
   }
}
// ---> END