// JavaScript Document

function loadDIV(lyr,data) {
	
	if(lyr == "giftwrapAdd") {
		var lyr = "giftwrapOptions";
		var url = "/secure2/checkoutGW.php?gwi=" + data;
	}
	if(lyr == "giftwrapRemove") {
		var lyr = "giftwrapOptions";
		var url = "/secure2/checkoutGW.php?gwr=" + data;
	}
	if(lyr == "giftwrapLoad") {
		var lyr = "giftwrapOptions";
		var url = "/secure2/checkoutGW.php";
	}
	if(lyr == "giftwrapCancelAll") {
		var lyr = "giftwrapOptions";
		var url = "/secure2/checkoutGW.php?gwcancel=1";
	}
	if(lyr == "shippingOptions") {
		var url = "/secure2/checkoutShipping.php?shipvalue=" + data + "&st=" + document.form1.ShipState.value;
	}
	if(lyr == "shippingOptionsLoad") {
		var lyr = "shippingOptions";
		var url = "/secure2/checkoutShipping.php?st=" + document.form1.ShipState.value;
	}
	if(lyr == "cartCoupon") {
		var ccode = document.getElementById('CouponCode').value;
		var url = "/scripts/php/components/cartCoupon.php?ccode=" + ccode + "&apply=" + data;
	}
	if(lyr == "cartTotal") {
		var url = "/scripts/php/components/cartTotal.php";
	}
	if(lyr == "cartTotalShipType") {
		var lyr = "cartTotal";
		var url = "/scripts/php/components/cartTotal.php?shipvalue=" + data + "&st=" + document.form2.ShipState.value;
	}
	if(lyr == "cartTotalState") {
		var lyr = "cartTotal";
		var url = "/scripts/php/components/cartTotal.php?st=" + data;
	}
	if(lyr == "orderCalculation") {
		var url = "/secure2/checkoutCalculation.php";
	}
	if(lyr == "stockAlert") {
		var url = "/scripts/php/components/stockalert.php?em=" + document.frmDetails.Email.value + "&sapid=" + data;
	}
	if(lyr == "reg1") {
		var url="/scripts/php/components/registration_popup.php?em="+document.formSubscribe.BillEmail.value+"&fn="+document.formSubscribe.BillFirstName.value+"&ln="+document.formSubscribe.BillLastName.value+"&submit=true";
	}
	if(lyr == "reg2") {
		var url="/scripts/php/components/registration_popup_fs.php?em="+document.formSubscribe2.BillEmail.value+"&fn="+document.formSubscribe2.BillFirstName.value+"&ln="+document.formSubscribe2.BillLastName.value+"&submit=true";
	}

	
	if (document.all) {
		// loading image
		//document.getElementById(lyr).innerHTML = '<div id="loading"><img src="/images/loading.gif" alt="loading..."><\/div>';
		// IE version
		try {
			// Use the XMLHTTP Object
			var xml = new ActiveXObject("Microsoft.XMLHTTP");
			xml.onreadystatechange = triggered; //check the state and status of the file
			xml.Open( "GET", url, false ); //get the file
			xml.Send(null);
			document.getElementById(lyr).innerHTML = xml.responseText; // give the content of a container the response text
			}
		// if we catch an error on the XMLHTTP Object, try 4.0
		catch (e) {
			var xml = new ActiveXObject("MSXML2.XMLHTTP.4.0");
			xml.onreadystatechange = triggered; //check the state and status of the file
			xml.Open( "GET", url, false ); //get the file
			xml.Send(null);
			document.getElementById(lyr).innerHTML = xml.responseText; // give the content of a container the response text
			}
		} else {
			// loading image
			//document.getElementById(lyr).innerHTML = '<div id="loading"><img src="/images/loading.gif" alt="loading..."><\/div>';
			// Mozilla/Netscrap 6+ version
			// Use the XMLHttpRequest Object
			var xml = new XMLHttpRequest();
			xml.onreadystatechange = triggered; //check the state and status of the file
			xml.open("GET",url,false); //get the file
			xml.send(null);
			document.getElementById(lyr).innerHTML = xml.responseText; // give the content of a container the response text
		}
	}
function triggered() {
	if (document.all) {
		try {
			// try XMLHTTP
			var xml = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e) {
			// try XMLHTTP 4.0
			var xml = new ActiveXObject("MSXML2.XMLHTTP.4.0");
		}
	} else {
		// try XMLHttpRequest
		var xml = new XMLHttpRequest();
	}
	if ((xml.readyState == 4) && (xml.status == 200)) { //if there is a 4 return state, and return status 200
		var txt = xml.responseText; //set txt to the response
		var txtNod = document.createTextNode(txt);
		document.getElementById(lyr).style.display = '';
		document.getElementById(lyr).innerHTML = txt; // give the content of a container the response text
	}
}


