// JavaScript Document
//------------------------------------------------------------------------------------------

var check = '';
	function CheckZip() {
		//alert("checking zip ...");
		var myzip = document.getElementById('zipCode').value;
		//alert(myzip);return false;
		if (myzip != "") {
			checking_zip=true;
			//SetCookie("ShipZip", myzip);
			var url="check_zip.php?zip="+myzip;
			open_url(url, "zip_message2");
			if(!check)
			{
				return false;	
			}
			else
			{
				return true;
			}
			
		} else {
			document.getElementById("zip_message2").innerHTML = "<font color=red>Please enter a Zip Code.</font>";
			return false;
		}
	}
//------------------------------------------------------------------------------------------
function open_url(url, target) {
 	if ( ! document.getElementById) {
  		return false;
 	}
	//alert("open_url(): target='" + target + "'");
// 	if (please_wait != null) {
//  		document.getElementById(target).innerHTML = please_wait;
// 	}

 	if (window.ActiveXObject) {
  		link = new ActiveXObject("Microsoft.XMLHTTP");
 	} else if (window.XMLHttpRequest) {
  		link = new XMLHttpRequest();
 	}

 	if (link == undefined) {
  		return false;
 	}
 	link.onreadystatechange = function() { response(url, target); }
 	link.open("GET", url, true);
 	link.send(null);
}

//------------------------------------------------------------------------------------------
function response(url, target) {
	//alert("response: target='" + target + "', submitting="+submitting);
 	if (link.readyState == 4) {
		var text=link.responseText;
		//alert("response(): text='"+text+"', submitting='".submitting+"'");
		var mydiv=document.getElementById(target);
	 	//document.getElementById(target).innerHTML = (link.status == 200) ? link.responseText : "Ooops!! A broken link! Please contact the webmaster of this website ASAP and give him the following errorcode: " + link.status;
	 	mydiv.innerHTML = (link.status == 200) ? "("+link.responseText+")" : "Ooops!! A broken link! Please contact the webmaster of this website ASAP and give him the following errorcode: " + link.status;
		
		if (link.responseText == "") {
			//document.getElementById(target).innerHTML = "<font color=red>Invalid Zip Code, Please enter another.</font>";
			mydiv.innerHTML = "<font color=red>Invalid Zip Code, Please enter another.</font>";
			document.getElementById('valid_zip').value="";
			checking_zip=false;
			check = false;
		} else {
			document.getElementById('valid_zip').value = document.getElementById('zipCode').value;
			
				//document.products_store.submit();
			check = true;
			//return true;
			//checking_zip=false;
		}
	}
}