
function getXmlHttp () {
	var xmlhttp = false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest != "undefined") {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function updateActiveCart() {
	var xmlhttp = getXmlHttp();
	var obj = document.getElementById('cart');

	xmlhttp.open("GET", "/includes/ajax.php?task=itemcount");
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}


function addToCart(e) {
	//var xmlhttp = getXmlHttp();
	var obj = document.getElementById('c' + e.id);
	var qty = document.getElementById('quantity_' + e.id).value;
	var sku = document.getElementById('sku_' + e.id).value;

	// check for quanitity to be selected;
	if (qty == 0) {
		obj.innerHTML = 'Please select order quantity...';
		return false;
	}

//	xmlhttp.open("GET", "/includes/ajax.php?task=addtocart&sku=" + sku + "&quantity=" + qty);
//	xmlhttp.onreadystatechange = function() {
//		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
//			obj.innerHTML = xmlhttp.responseText;
//		}
//	}
//	xmlhttp.send(null);
	//updateActiveCart();
}

function checkForm(){
	var form = document.checkout_form;
	if(form.fname.value.length == 0){
		alert("Please enter your first name");
		form.fname.focus();
		return false;
	}
	if(form.lname.value.length == 0){
		alert("Please enter your last name");
		form.lname.focus();
		return false;
	}
	if(form.cname.value.length == 0){
		alert("Please enter your company name");
		form.cname.focus();
		return false;
	}
	if(form.address.value.length == 0){
		alert("Please enter your billing address");
		form.address.focus();
		return false;
	}
	if(form.city.value.length == 0){
		alert("Please enter your billing city");
		form.city.focus();
		return false;
	}
	if(form.zip.value.length == 0){
		alert("Please enter your billing Zip Code");
		form.zip.focus();
		return false;
	}
	if(form.phone.value.length == 0){
		alert("Please enter your billing phone");
		form.phone.focus();
		return false;
	}
	if(form.ship_fname.value.length == 0){
		alert("Please enter your shipping first name");
		form.ship_fname.focus();
		return false;
	}
	if(form.ship_lname.value.length == 0){
		alert("Please enter your shipping last name");
		form.ship_lname.focus();
		return false;
	}
	if(form.ship_cname.value.length == 0){
		alert("Please enter your shipping company name");
		form.ship_cname.focus();
		return false;
	}
	if(form.ship_address.value.length == 0){
		alert("Please enter your shipping address");
		form.ship_address.focus();
		return false;
	}
	if(form.ship_city.value.length == 0){
		alert("Please enter your shipping city");
		form.ship_city.focus();
		return false;
	}
	if(form.ship_zip.value.length == 0){
		alert("Please enter your Shipping Zip Code");
		form.ship_zip.focus();
		return false;
	}
	if(form.ship_phone.value.length == 0){
		alert("Please enter your shipping phone");
		form.ship_phone.focus();
		return false;
	}
	if(form.cname.value.indexOf(',') != -1){
		alert("Please remove any commas from the company name");
		form.cname.focus();
		return false;
	}
	if(form.ship_cname.value.indexOf(',') != -1){
		alert("Please remove any commas from the company name");
		form.ship_cname.focus();
		return false;
	}
	if(form.address.value.indexOf(',') != -1){
		alert("Please remove any commas from the address");
		form.address.focus();
		return false;
	}
	if(form.ship_address.value.indexOf(',') != -1){
		alert("Please remove any commas from the ship_address");
		form.ship_address.focus();
		return false;
	}
	if(form.cperson.value.length == 0){
		alert("Please enter the  Contact Person name");
		form.cperson.focus();
		return false;
	}
	if(form.cperson.value.indexOf(',') != -1){
		alert("Please remove any commas from the Contact Person");
		form.cperson.focus();
		return false;
	}
	if(form.email.value.length == 0){
		alert("Please enter the  Contact Person email address");
		form.email.focus();
		return false;
	}
	if(form.cnumber.value.length == 0){
		alert("Please enter valid cc number");
		form.cnumber.focus();
		return false;
	}
	if(form.cvvcode.value.length ==0){
		alert("Please enter Security Code");
		form.cvvcode.focus();
		return false;
	}
	return true;
}

function showShipAdd(){
	var form = document.checkout_form;

	if(form.isSameAddr.checked) {
		form.ship_address.value =  "";
		form.ship_city.value =  "";
		form.ship_zip.value =  "";
		form.ship_phone.value =  "";
		form.ship_address.focus();
	}
	else {
		form.ship_address.focus();
	}
	return;
}

function showResale(){
	var st = document.checkout_form.state.options[document.checkout_form.state.selectedIndex].text;
	if (st == 'TN'){
		document.all.resale1.style.visibility="visible";
	}
	if (st != 'TN'){
		document.all.resale1.style.visibility="hidden";
	}
	return;
}

function fillShipping() {
	if (document.getElementById("shipbill").checked) {
		document.registration_form.ship_address.value = document.registration_form.address.value;
		document.registration_form.ship_city.value = document.registration_form.city.value;
		document.registration_form.ship_state.value = document.registration_form.state.value;
		document.registration_form.ship_zip.value = document.registration_form.zip.value;
	}
	else {
		document.registration_form.ship_address.value = "";
		document.registration_form.ship_city.value = "";
		document.registration_form.ship_zip.value = "";
	}
	return;
}
