//Basic Ajax Routine- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Last updated: Jan 15th, 06'
function createAjaxObj(){
var httprequest=false
if (window.XMLHttpRequest){ // if Mozilla, Safari etc
httprequest=new XMLHttpRequest()
if (httprequest.overrideMimeType)
httprequest.overrideMimeType('text/xml')
}
else if (window.ActiveXObject){ // if IE
try {
httprequest=new ActiveXObject("Msxml2.XMLHTTP");
} 
catch (e){
try{
httprequest=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
return httprequest
}

var ajaxpack=new Object()
ajaxpack.basedomain="http://"+window.location.hostname
ajaxpack.ajaxobj=createAjaxObj()
ajaxpack.filetype="txt"
ajaxpack.addrandomnumber=0 //Set to 1 or 0. See documentation.

ajaxpack.getAjaxRequest=function(url, parameters, callbackfunc, filetype){
ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
if (ajaxpack.addrandomnumber==1) //Further defeat caching problem in IE?
var parameters=parameters+"&ajaxcachebust="+new Date().getTime()
if (this.ajaxobj){
this.filetype=filetype
this.ajaxobj.onreadystatechange=callbackfunc
this.ajaxobj.open('GET', url+"?"+parameters, true)
this.ajaxobj.send(null)
}
}

ajaxpack.postAjaxRequest=function(url, parameters, callbackfunc, filetype){
ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
if (this.ajaxobj){
this.filetype=filetype
this.ajaxobj.onreadystatechange = callbackfunc;
this.ajaxobj.open('POST', url, true);
this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
this.ajaxobj.setRequestHeader("Content-length", parameters.length);
this.ajaxobj.setRequestHeader("Connection", "close");
this.ajaxobj.send(parameters);
}
}

function processGetPost() {
	var strMsg = "Your estimated shipping cost is: &nbsp;&nbsp;$";
	var myajax=ajaxpack.ajaxobj
	var myfiletype=ajaxpack.filetype
	if (myajax.readyState == 4) {
		if (myajax.status==200) { 
			document.getElementById('spanShipEstimate').innerHTML = strMsg + myajax.responseText;
			MinimumCheckShipping = myajax.responseText;
		}
	}
}
function ShippingLookup() {
	var strParms = "";
	if (document.ShipEstimateForm.EstimateZipCode.value == "") {
		alert("A ZipCode is required.");
		document.ShipEstimateForm.EstimateZipCode.focus(); 
		return false
	}	
	if (!checkZipCode(document.ShipEstimateForm.EstimateZipCode)) {
		alert("A valid Zip Code is required.");
		document.ShipEstimateForm.EstimateZipCode.focus(); 
		return false
	}	
	if ((document.ShipEstimateForm.rdoEstimateAddressType[0].checked || document.ShipEstimateForm.rdoEstimateAddressType[1].checked)== false) {
		alert("An Address Type is required.");
		document.ShipEstimateForm.rdoEstimateAddressType[0].focus(); 
		return false
	}
	strParms = strParms + "z=" + document.ShipEstimateForm.EstimateZipCode.value;
	strParms = strParms + "&w=" + document.ShipEstimateForm.EstimateWeight.value;
	if (document.ShipEstimateForm.rdoEstimateAddressType[1].checked == true) {
		strParms = strParms + "&a=C";
	} else {
		strParms = strParms + "&a=R";
	}
	document.getElementById('spanShipEstimate').innerHTML = "working...";
	ajaxpack.getAjaxRequest("ajaxlookup.asp", strParms, processGetPost, "txt");
}
var MinimumCheckItems = 0;
var MinimumCheckShipping = 0;
function MinimumCheck() {
	if ((parseFloat(MinimumCheckItems) + parseFloat(MinimumCheckShipping) ) > 50) {
		location.href = 'https://www.bfwebexpress.com/cart_checkout_1.asp';
	} else {
		//alert(MinimumCheckItems);
		//alert(MinimumCheckShipping);
		if ( parseFloat(MinimumCheckShipping) == 0 ) {
			alert('Minimum order amount (products plus shipping) is $50.00. You can estimate your shipping costs below.');
		} else {
			alert('The minimum order amount (products plus shipping) is $50.00.');
		}
	}
}
