function calcTotal(){
//	var qtyFields = new Array('qtyChalkboard','qtyFish','qtyGrill','qtyFlatware','qtyPizza','qtyLemonade','qtyMargerita','qtyCosmo','qtyWine','qtyBeer','qtyCrab');
	var total = 0;
	
	items = document.getElementsByName('hew');	
	
	for (x in items) {
		if (items[x].value != undefined) {
			qty = document.getElementById(items[x].value).value;
			if(qty == parseInt(qty)){
	        	total += parseInt(qty);
			}
		}
	}

	document.getElementById('attachments').innerHTML = '<em>[' + total + ' selected ]</em>';  	  

}

function incrementQty(formId){
	if(document.getElementById(formId).value != parseInt(document.getElementById(formId).value)){
		return;
	}
	document.getElementById(formId).value = parseInt(document.getElementById(formId).value) + 4;
	calcTotal();
}

function decrementQty(formId){
	if(document.getElementById(formId).value != parseInt(document.getElementById(formId).value)){
		return;
	}
	document.getElementById(formId).value = (document.getElementById(formId).value > 3 ? parseInt(document.getElementById(formId).value) - 4 : 0);
	calcTotal();
}

function incrementPlateQty(formId){
	if(document.getElementById(formId).value != parseInt(document.getElementById(formId).value)){
		return;
	}
	document.getElementById(formId).value = parseInt(document.getElementById(formId).value) + 3;
}

function decrementPlateQty(formId){
	if(document.getElementById(formId).value != parseInt(document.getElementById(formId).value)){
		return;
	}
	document.getElementById(formId).value = (document.getElementById(formId).value > 2 ? parseInt(document.getElementById(formId).value) - 3 : 0);
}



function incrementQtyMini(formId,amount){
	if(document.getElementById(formId).value != parseInt(document.getElementById(formId).value)){
		return;
	}
	document.getElementById(formId).value = parseInt(document.getElementById(formId).value) + amount;
	calcTotal();
}

function decrementQtyMini(formId,amount){
	if(document.getElementById(formId).value != parseInt(document.getElementById(formId).value)){
		return;
	}
	document.getElementById(formId).value = (document.getElementById(formId).value > (amount - 1) ? parseInt(document.getElementById(formId).value) - amount : 0);
	calcTotal();
}





function incrementPlateQty(formId){
	if(document.getElementById(formId).value != parseInt(document.getElementById(formId).value)){
		return;
	}
	document.getElementById(formId).value = parseInt(document.getElementById(formId).value) + 3;
}

function decrementPlateQty(formId){
	if(document.getElementById(formId).value != parseInt(document.getElementById(formId).value)){
		return;
	}
	document.getElementById(formId).value = (document.getElementById(formId).value > 2 ? parseInt(document.getElementById(formId).value) - 3 : 0);
}

	function addwheeltocart() {
		total = 0;
		hap_ev = document.getElementById('HAP_EV').value;	
		items = document.getElementsByName('hew');	
		total += parseInt(hap_ev);
		
		idata = "";
		for (x in items) {
			if (items[x].value != undefined) {
				qty = document.getElementById(items[x].value).value;
				if (parseInt(qty) > 0) {
					idata += items[x].id + "|" + qty + "$";
					total += parseInt(qty);
				}
			}
		}
		inputString = hap_ev+"^"+idata;	
		document.getElementById('CARTRESULTS').innerHTML = total + " items added to your cart<br /><br /><a href='checkout.php'><img src='images/checkout.gif' alt='check out' /></a>";
		$.post("cart_ajax/addwheeltocart.php", {queryString: ""+inputString+""}, function(data){
			if (data != "") alert(data);
		});
	}
	
	function addminitocart() {
		total = 0;
		hap_ev = document.getElementById('HAPEV-9.25PL').value;	
		items = document.getElementsByName('hew');	
		total += parseInt(hap_ev);
		
		idata = "";
		for (x in items) {
			if (items[x].value != undefined) {
				qty = document.getElementById(items[x].value).value;
				if (parseInt(qty) > 0) {
					idata += items[x].id + "|" + qty + "$";
					total += parseInt(qty);
				}
			}
		}
		inputString = hap_ev+"^"+idata;	
		document.getElementById('CARTRESULTS').innerHTML = total + " items added to your cart<br /><br /><a href='checkout.php'><img src='images/checkout.gif' alt='check out' /></a>";
		$.post("cart_ajax/addwheeltocart.php", {queryStringMini: ""+inputString+""}, function(data){
			if (data != "") alert(data);
		});
	}


	function login() {
		uname = document.getElementById('login_name').value;	
		upass = document.getElementById('login_password').value;
		inputString = uname+"^"+upass;	
		$.post("cart_ajax/login.php", {queryString: ""+inputString+""}, function(data){
			var update = new Array();
			if (data.indexOf("|") >= 0) {
				update = data.split('|');
				document.getElementById('login_error').innerHTML = update[1];	
			}
			else {
				window.location = "index.php";
			}
		});
	}
	
	function getpasswordhint() {
		uname = document.getElementById('login_name').value;	
		fname = document.getElementById('first_name').value;
		inputString = uname+"^"+fname;	
		$.post("cart_ajax/gethint.php", {queryString: ""+inputString+""}, function(data){
			var update = new Array();
			if (data.indexOf("|") >= 0) {
				update = data.split('|');
				document.getElementById('login_error').innerHTML = update[1];	
				document.getElementById('hint').innerHTML = "";	
			}
			else {
				document.getElementById('login_error').innerHTML = "";	
				document.getElementById('hint').innerHTML = data;	
			}
		});
	}
	 
	function addtocart(pid, qty, options, personal, qtyfield) {
		if (qtyfield != "") {
			qty2 = document.getElementById(qtyfield).value;	
		}
		else {
			qty2 = qty;
		}
		inputString = pid+"^"+qty2+"^"+options+"^"+personal;	
		$.post("cart_ajax/addtocart.php", {queryString: ""+inputString+""}, function(data){
		});
	}
	
	function addqp(pid) {
		qty2 = 1;
		options = "";
		personal="";
		inputString = pid+"^"+qty2+"^"+options+"^"+personal;	
		$.post("cart_ajax/addtocart.php", {queryString: ""+inputString+""}, function(data){
			window.location = "checkout.php";
		});
	}

	function updateorder(pid, qty, options, personal) {
		itemcount = document.getElementById('itemcount').value;	
		crt = "";
		for (i = 1; i <= itemcount; i++) {
			pid = document.getElementById('ITEM'+i).value;	
			qty = document.getElementById('Q'+i).value;	
			shipwhen = document.getElementById('SH'+i).value;	
			options = document.getElementById('OPTION'+i).value;	
			personal = document.getElementById('PERSONAL'+i).value;	
			crt += pid+"^"+qty+"^"+shipwhen+"^"+options+"^"+personal+"|"
		}
		$.post("cart_ajax/updatecart.php", {queryString: ""+crt+""}, function(data){
		window.location = "checkout.php";
		});
	}

	function ccvalidate(ccnum) {
		$.post("cart_ajax/ccValidate.php", {ccnum: ""+ccnum+""}, function(data){
		if (data.length > 10) alert(data);
		});
	}

	function getorderemail(oid) {
		$.post("receipt-email.php", {id: ""+oid+""}, function(data){
			$.post("send-email.php", {id: ""+urlencode(data)+""}, function(data){
			});
		});
	}

function urlencode (str) {
    str = (str+'').toString();
    
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
                                                                    replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}

