// Blue Buffalo Company

function menuZipHandler(){
	var FullZip = document.getElementById('zip').value;
	var menuzipTemp = document.getElementById('zip').value.charAt(0);
	var menuzipFirstChar=menuzipTemp.toLowerCase();
	zipPattern = /^([A-Za-z]\d[A-Za-z](?:[- ]?)\d[A-Za-z]\d)$/i;
	usaZipPattern = /^\d{5}$/i;
	if(!zipPattern.test(document.getElementById('zip').value)){
		if(!usaZipPattern.test(document.getElementById('zip').value)){
			alert('Please enter a 5-digit U.S. ZIP code or a\n6-character Canadian postal code.');
			return false;
		}
		//USA Zip OK, submit form
		return true;
	}else{
		//CA Postal OK, redirect with CA defined and radius in KMs
		location.href="/products/retailers_results.php?ca=1&radius=50&set=zip&do=zipcode&submit=submit&zip="+FullZip;
		return false;
	}

}

function calloutZipHandler(){
	var calloutFullZip = document.getElementById('callout_zip').value;
	var calloutzipTemp = document.getElementById('callout_zip').value.charAt(0);
	var calloutzipFirstChar=calloutzipTemp.toLowerCase();
	zipPattern = /^([A-Za-z]\d[A-Za-z](?:[- ]?)\d[A-Za-z]\d)$/i;
	usaZipPattern = /^\d{5}$/i;
	if(!zipPattern.test(document.getElementById('callout_zip').value)){
		if(!usaZipPattern.test(document.getElementById('callout_zip').value)){
			alert('Please enter a 5-digit U.S. ZIP code or a\n6-character Canadian postal code.');
			return false;
		}
		return true;
	}else{
		//CA Postal OK, redirect with CA defined and radius in KMs
		location.href="/products/retailers_results.php?ca=1&radius=50&set=zip&do=zipcode&submit=submit&zip="+calloutFullZip;
		return false;
	}

}

function calloutPSHandler(){
	var calloutFullZip = document.getElementById('callout_zip').value;
	var calloutzipTemp = document.getElementById('callout_zip').value.charAt(0);
	var calloutzipFirstChar=calloutzipTemp.toLowerCase();
	zipPattern = /^([A-Za-z]\d[A-Za-z](?:[- ]?)\d[A-Za-z]\d)$/i;
	usaZipPattern = /^\d{5}$/i;
	if(!zipPattern.test(document.getElementById('callout_zip').value)){
		if(!usaZipPattern.test(document.getElementById('callout_zip').value)){
			alert('Please enter a 5-digit U.S. ZIP code or a\n6-character Canadian postal code.');
			return false;
		}
		location.href="/products/retailers_results.php?radius=50&set=zip&do=zipcode&submit.x=0&submit.y=0&submit=submit&petsmart=1&zip="+calloutFullZip;
		return false;
	}else if(calloutzipFirstChar=='t'){
		location.href="/products/retailers_results.php?set=selstate&do=state&special=ab&petsmart=1";
		return false;
	}else if(calloutzipFirstChar=='v'){
		location.href="/products/retailers_results.php?set=selstate&do=state&special=bc&petsmart=1";
		return false;
	}else if(calloutzipFirstChar=='b'){
		location.href="/products/retailers_results.php?set=selstate&do=state&special=ns&petsmart=1";
		return false;
	}else if(calloutzipFirstChar=='p'||calloutzipFirstChar=='n'||calloutzipFirstChar=='l'||calloutzipFirstChar=='k'){
		location.href="/products/retailers_results.php?set=selstate&do=state&special=on&petsmart=1";
		return false;
	}else if(calloutzipFirstChar=='s'){
		location.href="/products/retailers_results.php?set=selstate&do=state&special=sk&petsmart=1";
		return false;
	}

}

function calloutLONGDHandler(){
	var calloutFullZip = document.getElementById('callout_zip').value;
	var calloutzipTemp = document.getElementById('callout_zip').value.charAt(0);
	var calloutzipFirstChar=calloutzipTemp.toLowerCase();
	zipPattern = /^([A-Za-z]\d[A-Za-z](?:[- ]?)\d[A-Za-z]\d)$/i;
	usaZipPattern = /^\d{5}$/i;
	if(!zipPattern.test(document.getElementById('callout_zip').value)){
		if(!usaZipPattern.test(document.getElementById('callout_zip').value)){
			alert('Please enter a 5-digit U.S. ZIP code or a\n6-character Canadian postal code.');
			return false;
		}
		location.href="/products/retailers_results.php?radius=50&set=zip&do=zipcode&longd=1&submit.x=0&submit.y=0&submit=submit&zip="+calloutFullZip;
		return false;
	}else if(calloutzipFirstChar=='t'){
		location.href="/products/retailers_results.php?set=selstate&do=state&special=ab&longd=1";
		return false;
	}else if(calloutzipFirstChar=='v'){
		location.href="/products/retailers_results.php?set=selstate&do=state&special=bc&longd=1";
		return false;
	}else if(calloutzipFirstChar=='b'){
		location.href="/products/retailers_results.php?set=selstate&do=state&special=ns&longd=1";
		return false;
	}else if(calloutzipFirstChar=='p'||calloutzipFirstChar=='n'||calloutzipFirstChar=='l'||calloutzipFirstChar=='k'){
		location.href="/products/retailers_results.php?set=selstate&do=state&special=on&longd=1";
		return false;
	}else if(calloutzipFirstChar=='s'){
		location.href="/products/retailers_results.php?set=selstate&do=state&special=sk&longd=1";
		return false;
	}

}

/*function calloutPSHandler(){
	var calloutFullZip = document.getElementById('callout_zip').value;
	var calloutzipTemp = document.getElementById('callout_zip').value.charAt(0);
	var calloutzipFirstChar=calloutzipTemp.toLowerCase();
	zipPattern = /^([A-Za-z]\d[A-Za-z](?:[- ]?)\d[A-Za-z]\d)$/i;
	usaZipPattern = /^\d{5}$/i;
	if(!zipPattern.test(document.getElementById('callout_zip').value)){
		if(!usaZipPattern.test(document.getElementById('callout_zip').value)){
			alert('Please enter a 5-digit U.S. ZIP code or a\n6-character Canadian postal code.');
			return false;
		}
		//US Postal Code OKd
		location.href="/products/retailers_results.php?radius=50&set=zip&do=zipcode&submit=submit&petsmart=1&zip="+calloutFullZip;
		return false;
	}else{
		//CA Postal OK, redirect with CA defined and radius in KMs
		location.href="/products/retailers_results.php?ca=1&radius=50&set=zip&do=zipcode&petsmart=1submit=submit&zip="+calloutFullZip;
		return false;
	}

}

function calloutLONGDHandler(){
	var calloutFullZip = document.getElementById('callout_zip').value;
	var calloutzipTemp = document.getElementById('callout_zip').value.charAt(0);
	var calloutzipFirstChar=calloutzipTemp.toLowerCase();
	zipPattern = /^([A-Za-z]\d[A-Za-z](?:[- ]?)\d[A-Za-z]\d)$/i;
	usaZipPattern = /^\d{5}$/i;
	if(!zipPattern.test(document.getElementById('callout_zip').value)){
		if(!usaZipPattern.test(document.getElementById('callout_zip').value)){
			alert('Please enter a 5-digit U.S. ZIP code or a\n6-character Canadian postal code.');
			return false;
		}
		location.href="/products/retailers_results.php?radius=50&set=zip&do=zipcode&longd=1&submit=submit&zip="+calloutFullZip;
		return false;
	}else{
		//CA Postal OK, redirect with CA defined and radius in KMs
		location.href="/products/retailers_results.php?ca=1&radius=50&set=zip&longd=1&do=zipcode&submit=submit&zip="+calloutFullZip;
		return false;
	}

}*/