// JavaScript Document

if (window.ActiveXObject) {
	var storeConnect=new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
	var storeConnect=new XMLHttpRequest();
}

function getTotal(obj){
	obj.action='';
	var sendStr='';
	for (i=0; i<obj.elements.length; i++){
		with (obj.elements[i]){
			if ((type=='radio' && checked==true) || type!='radio'){
				sendStr=sendStr+name+'='+escape(value)+'&';
			}
		}
	}
	storeConnect.open('post','store/_getPrice.cfm',0);
	storeConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	storeConnect.send(sendStr);
	document.getElementById('totalPrice').innerHTML=storeConnect.responseText;
	if (document.getElementById('addCart')) document.getElementById('addCart').focus();
	window.scrollTo(0,999999);
}

function valImages(){
	if (document.getElementById('artSmall').value=='' && document.getElementById('prevArtSmall').value=='none'){
		alert('You must upload an image for the small application before you can save this item to your cart.');
		return false;
	}
	if (document.getElementById('artLarge').value=='' && document.getElementById('prevArtLarge').value=='none'){
		alert('You must upload an image for the large application before you can save this item to your cart.');
		return false;
	}
}

function fillBilling(objStat){
	if (objStat){
		document.getElementById('BillAddress').value=document.getElementById('ShipAddress').value;
		document.getElementById('BillCity').value=document.getElementById('ShipCity').value;
		document.getElementById('BillState').value=document.getElementById('ShipState').value;
		document.getElementById('BillZip').value=document.getElementById('ShipZip').value;
		var billOpts=document.getElementById('BillCountry').options;
		for (i=0;i<billOpts.length;i++){
			if (billOpts[i].value==document.getElementById('ShipCountry').value) billOpts[i].selected=true;
		}
	} else {
		document.getElementById('BillAddress').value='';
		document.getElementById('BillCity').value='';
		document.getElementById('BillState').value='';
		document.getElementById('BillZip').value='';
	}
}
function updateTaxShip(obj){
	if (obj.name=='shipCountry'){
		str='act=2&loc='+obj.value+'&amt='+document.goCheckout.sumPrice.value;
	} else if (obj.name=='ShipZip'){
		str='act=3&zip='+obj.value+'&amt='+document.goCheckout.sumPrice.value;
	}

	var resp=getXML(str,'store/_doStoreAjax.cfm');
	var chk=resp.getElementsByTagName('success')[0].firstChild.data;
	if (chk!='true'){
		document.getElementById('response').innerHTML=resp.getElementsByTagName('message')[0].firstChild.data;
		if (confirm("An error occurred while attempting to retrieve tax and shipping information. To try again, click 'OK'. If this problem persists, please click 'Cancel' and  contact EFV8.org for assistance.")) obj.focus();
	} else if (resp.getElementsByTagName('taxChg')[0]!=null){
		var tax=parseFloat(resp.getElementsByTagName('taxChg')[0].firstChild.data).toFixed(2);
		document.getElementById('taxChrgs').innerHTML='$'+tax;
		document.goCheckout.tax.value=tax;
		if (tax==0) {
			document.getElementById('taxRow').style.display='none';
		} else {
			document.getElementById('taxRow').style.display='block';
		}
	} else if (resp.getElementsByTagName('shipChg')[0]!=null){
		var shipping=parseFloat(resp.getElementsByTagName('shipChg')[0].firstChild.data).toFixed(2);
		document.getElementById('shipChrgs').innerHTML='$'+shipping;
		document.goCheckout.shipCharge.value=shipping;
	}
	document.goCheckout.ordTotal.value=parseFloat(document.goCheckout.sumPrice.value)+parseFloat(document.goCheckout.tax.value)+parseFloat(document.goCheckout.shipCharge.value);
	document.getElementById('ordTotal').innerHTML='$'+parseFloat(document.goCheckout.ordTotal.value).toFixed(2);
}

<!-----------------------AJAX -------------------------------->

function getXML(sendStr,template){
	srvrConnect.open('post',template,0);
	srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	srvrConnect.send(sendStr);
	//alert(srvrConnect.responseText);
	var resp=srvrConnect.responseXML;
	var notWhitespace = /\S/
	var xmlData=resp.getElementsByTagName('data')[0];
	//REMOVE white spaces in XML file. Intended mainly for NS6/Mozilla
	try {
		for (i=0;i<xmlData.childNodes.length;i++){
			if ((xmlData.childNodes[i].nodeType == 3)&&(!notWhitespace.test(xmlData.childNodes[i].nodeValue))) {
				// that is, if it's a whitespace text node
				xmlData.removeChild(xmlData.childNodes[i])
				i--
			}
		}
		return xmlData;
	} catch(err) {
		document.getElementById('response').innerHTML=srvrConnect.responseText;
		var xml=document.createDocumentFragment();
		var node=xml.createElement('success');
		xml.appendChild(node);
		var contents=xml.createTextNode('false');
		node.appendChild(contents);
		var node2=xml.createElement('message');
		var contents2=xml.createTextNode(srvrConnect.responseText);
		node2.appendChild(contents2);
		xml.appendChild(node2);
	 	return xml;
	}
}
