// Create boolean variable to check for a valid Internet Explorer instance.
var xmlhttp = false;
var xmlhttp2 = false;
var xmlhttp3 = false;

// Check if we are using IE
try {
	// If the javascript version is greater than 5.
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	xmlhttp2 = new ActiveXObject("Msxml2.XMLHTTP");
	xmlhttp3 = new ActiveXObject("Msxml2.XMLHTTP");
	//alert("You are using Microsoft Internet Explorer.");
} catch(e) {
	// if not, then use the older active x object.
	try {
		// if we are using IE
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
		xmlhttp3 = new ActiveXObject("Microsoft.XMLHTTP");
		//alert("You are using Microsoft Internet Explorer");
	} catch(e) {
		// else we must be using a non ie browser
		xmlhttp = false;
		xmlhttp2 = false;
		xmlhttp3 = false;
	}
}

// If we are using a non-ie browser, create a javascript instance of the object
if(!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	xmlhttp = new XMLHttpRequest();
	//alert("You are not using Microsoft Internet Explorer");
}
// If we are using a non-ie browser, create a javascript instance of the object
if(!xmlhttp2 && typeof XMLHttpRequest != 'undefined') {
	xmlhttp2 = new XMLHttpRequest();
	//alert("You are not using Microsoft Internet Explorer");
}
// If we are using a non-ie browser, create a javascript instance of the object
if(!xmlhttp3 && typeof XMLHttpRequest != 'undefined') {
	xmlhttp3 = new XMLHttpRequest();
	//alert("You are not using Microsoft Internet Explorer");
}

// Make page request
function makerequest(serverPage, objID, txtBoxname, what, pagepart) {
	this.oldValue = document.getElementById(objID).innerHTML;
	var obj = document.getElementById(objID);
	var whattodo = what;
	var pagepart = pagepart;
	if(whattodo != 2) {
		xmlhttp.open("GET", "includes/" + serverPage);
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				obj.innerHTML = xmlhttp.responseText;
			}
		}
	} else if(whattodo == 2) {
		var domainext = document.getElementById(txtBoxname).value;
		//alert(domainext);
		if(pagepart == 'homepage') {
			obj.innerHTML = '<p class="domaintxt">Loading...</p>';
		} else if(pagepart == 'rightside') {
			obj.innerHTML = '<p class="domaintxt2">Loading...</p>';
		}
		xmlhttp.open("GET", "includes/" + serverPage + "?domain=" + domainext);
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				obj.innerHTML = xmlhttp.responseText;
			}
		}
	}
	xmlhttp.send(null);
} 

function clearDomain2(targetDiv) {
	document.getElementById(targetDiv).innerHTML = this.oldValue;
}

function getMiniCart() {
	var obj = document.getElementById('minicart_cont');
	if(obj == null) {
		obj = '';
	}
	if(xmlhttp2) {
		xmlhttp2.open('GET','includes/minicart.inc.php');
		xmlhttp2.onreadystatechange = function() {
			if(xmlhttp2.readyState == 4 && xmlhttp2.status == 200) {
				obj.innerHTML = xmlhttp2.responseText;
			}
		}
		xmlhttp2.send(null);
	}
}

function getCheckoutList() {
	var obj = document.getElementById('checkOutList');
	if(obj == null) {
		obj = '';
	}
	if(xmlhttp) {
		xmlhttp.open('GET','includes/checkoutList.inc.php');
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				obj.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
}

function getViewCart(valueSet,prodNumber,payMeth,domainName) {
	var obj = document.getElementById('viewcart_cont');
	if(obj == null) {
		obj = '';
	}
	if(xmlhttp3) {
		if(valueSet == 1) {
			xmlhttp3.open('GET','includes/viewcart.inc.php?prodNum=' + prodNumber + '&payMeth=' + payMeth + '&domainName=' + domainName);
		} else if(valueSet == 0) {
			xmlhttp3.open('GET','includes/viewcart.inc.php');
		}
		xmlhttp3.onreadystatechange = function() {
			if(xmlhttp3.readyState == 4 && xmlhttp3.status == 200) {
				obj.innerHTML = xmlhttp3.responseText;
			}
		}
		xmlhttp3.send(null);
	}
}


function addProductToCart(prodNum,paymentMethod,targetDiv) {
	var objTarget = document.getElementById(targetDiv);
	var paymentMethod = document.getElementById(paymentMethod).value;
	if(xmlhttp) {
		xmlhttp.open('GET','includes/addtocart.inc.php?prodNum='+prodNum+'&paymentMethod='+paymentMethod);
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				objTarget.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
}

function addProductToCartDomain(prodNum,paymentMethod,targetDiv,domainName) {
	var objTarget = document.getElementById(targetDiv);
	if(xmlhttp) {
		xmlhttp.open('GET','includes/addtocart.inc.php?prodNum='+prodNum+'&paymentMethod='+paymentMethod+'&domainName='+domainName);
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				objTarget.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
}