// JavaScript Document

var img1 = new Image(16, 16);
img1.src="/lib/images/busy.gif";

function check_postcode() {
	
	pc = document.getElementById("postcode").value;

	document.getElementById("pc_go").disabled=true;
		
	document.getElementById("pc_image").src='/lib/images/busy.gif';
	
	var d = Date();
	
	_xmlHttp = getXMLHTTP();
	_xmlHttp.open("GET","/lib/ajax/postcode.php?postcode="+pc+"&time="+d,true);
    
	_xmlHttp.onreadystatechange=function() {
      if(_xmlHttp.readyState==4&&_xmlHttp.responseText) {
          // The response text gets executed as javascript... 
          var check = _xmlHttp.responseText;
		  
		  document.getElementById("pc_image").src='/lib/images/blank.gif';
 		  
		  document.getElementById("pc_go").disabled=false;

 		  document.getElementById("pc_results").style.visibility = 'visible';
		  
		  if(check=="OK") {
			
			 document.getElementById("pc_results").innerHTML = "We deliver to your area!";
		  
		  }else{
			  
			 document.getElementById("pc_results").innerHTML = "Sorry, we don't deliver to your area yet.";
			 
		  }
			  
		  
      }
    }
    ;
    _xmlHttp.send(null)


}
function check_postcode_for_delivery(f) {
	
	
	pc = document.getElementById("post_code").value;
	
	var d = Date();
	
	_xmlHttp = getXMLHTTP();
	_xmlHttp.open("GET","/lib/ajax/postcode.php?postcode="+pc+"&time="+d,true);
    
	_xmlHttp.onreadystatechange=function() {
      if(_xmlHttp.readyState==4&&_xmlHttp.responseText) {
          // The response text gets executed as javascript... 
          var check = _xmlHttp.responseText;
		  
		  if(check=="OK") {
			  
		  	  check_time(f);

		  }else{
			  
			  alert("Sorry, we do not delivery to your area, you may not checkout.");

		  }
		  
      }
    }
    ;
    _xmlHttp.send(null)


}

function check_time(f) {
	
	var d = Date();
	
	var dt = document.getElementById("delivery_date").value;
	var tm = document.getElementById("delivery_time").value;
	
	
	_xmlHttp = getXMLHTTP();
	_xmlHttp.open("GET","/lib/ajax/delivery_time.php?date="+dt+"&time="+tm+"&rand="+d,true);
    
	_xmlHttp.onreadystatechange=function() {
      if(_xmlHttp.readyState==4&&_xmlHttp.responseText) {
          // The response text gets executed as javascript... 
          var c2 = _xmlHttp.responseText;

		  if(c2=="OK") {
			  
			  eval(c2);
			  
		  }else{
			  eval(c2);
			  alert("Sorry we cannot delivery on that date/time because "+err);
			  
		  }
		  
      }
    }
    ;
    _xmlHttp.send(null)

}

function change_info() {

	if(document.getElementById("info_hidden")) {
	
		_xmlHttp = getXMLHTTP();
		_xmlHttp.open("GET","/lib/ajax/info.php?next="+document.getElementById("info_hidden").value,true);
		
		_xmlHttp.onreadystatechange=function() {
		  if(_xmlHttp.readyState==4&&_xmlHttp.responseText) {
			  // The response text gets executed as javascript... 
			  var check = _xmlHttp.responseText;
			  
	
	
			  eval(check);
			
			   
			  
			  
			  
		  }
		}
	
		_xmlHttp.send(null)
	}
	
}
