function roundNumber(num, dec) 
{
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function updateKitTotal()
{	
	var cost = 240;
	var s1 = Number(document.getElementById('s1').value);
	var s2 = Number(document.getElementById('s2').value);
	var s3 = Number(document.getElementById('s3').value);
	
	subtot = cost * (s1 + s2 + s3);
	subtot = roundNumber(subtot,2);
	subtot = subtot.toFixed(2);
	shipping = (subtot * .10);
	shipping = roundNumber(shipping,2);
	shipping = shipping.toFixed(2);
	tot = (Number(subtot) + Number(shipping));
	tot = roundNumber(tot,2);
	tot = tot.toFixed(2);
	
	document.getElementById('ellsubtotal').innerHTML = '$ ' + subtot;
	document.getElementById('ellshipping').innerHTML = '$ ' + shipping;
	document.getElementById('elltotalcost').innerHTML = '$ ' + tot;
}

function updateIndKitTotal()
{	
	var cost2 = 11;
	var s4 = Number(document.getElementById('s4').value);
	var s5 = Number(document.getElementById('s5').value);
	var s6 = Number(document.getElementById('s6').value);
	
	subtot = cost2 * (s4 + s5 + s6);
	subtot = roundNumber(subtot,2);
	subtot = subtot.toFixed(2);
	shipping = (subtot * .10);
	shipping = roundNumber(shipping,2);
	shipping = shipping.toFixed(2);
	tot = (Number(subtot) + Number(shipping));
	tot = roundNumber(tot,2);
	tot = tot.toFixed(2);
	
	document.getElementById('ellsubtotal').innerHTML = '$ ' + subtot;
	document.getElementById('ellshipping').innerHTML = '$ ' + shipping;
	document.getElementById('elltotalcost').innerHTML = '$ ' + tot;
}

function updateELLKitTotal()
{	
	var cost = 300;
	var s1 = Number(document.getElementById('ells1').value);
	var s2 = Number(document.getElementById('ells2').value);
	var s3 = Number(document.getElementById('ells3').value);
	
	subtot = cost * (s1 + s2 + s3);
	subtot = roundNumber(subtot,2);
	subtot = subtot.toFixed(2);
	shipping = (subtot * .10);
	shipping = roundNumber(shipping,2);
	shipping = shipping.toFixed(2);
	tot = (Number(subtot) + Number(shipping));
	tot = roundNumber(tot,2);
	tot = tot.toFixed(2);
	
	document.getElementById('ellsubtotal').innerHTML = '$ ' + subtot;
	document.getElementById('ellshipping').innerHTML = '$ ' + shipping;
	document.getElementById('elltotalcost').innerHTML = '$ ' + tot;
}

function updateIndELLKitTotal()
{	
	var cost2 = 13.60;
	var s4 = Number(document.getElementById('ells4').value);
	var s5 = Number(document.getElementById('ells5').value);
	var s6 = Number(document.getElementById('ells6').value);
	
	subtot = cost2 * (s4 + s5 + s6);
	subtot = roundNumber(subtot,2);
	subtot = subtot.toFixed(2);
	shipping = (subtot * .10);
	shipping = roundNumber(shipping,2);
	shipping = shipping.toFixed(2);
	tot = (Number(subtot) + Number(shipping));
	tot = roundNumber(tot,2);
	tot = tot.toFixed(2);
	
	document.getElementById('ellsubtotal').innerHTML = '$ ' + subtot;
	document.getElementById('ellshipping').innerHTML = '$ ' + shipping;
	document.getElementById('elltotalcost').innerHTML = '$ ' + tot;
}

function updateTotal()
{	
	var cost = 299;
	var s1 = Number(document.getElementById('s1').value);
	var s2 = Number(document.getElementById('s2').value);
	
	tot = cost * (s1 + s2);
	tot = roundNumber(tot,2);
	tot = tot.toFixed(2);	
	
	document.getElementById('x_amount').value = tot;
	document.getElementById('totalcost').innerHTML = '$ ' + tot;
}
function validateInfo()
{
	// Define Form Variables By ID
	var fname = document.getElementById("x_first_name");
	var lname = document.getElementById("x_last_name");
	var address = document.getElementById("x_address");
	var city = document.getElementById("x_city");
	var state = document.getElementById("x_state");
	var zip = document.getElementById("x_zip");
	var email = document.getElementById("x_email");
	var cc = document.getElementById("x_card_num");
	var expdate = document.getElementById("x_exp_date");
	var cvv = document.getElementById("cvv");
	var amount = document.getElementById("x_amount");
	var lot = document.getElementById("lot");
	var x_invoice_num = document.getElementById("x_invoice_num");
	var errordiv = document.getElementById("errors");
	var s1_num = document.getElementById("s1_num");
	var s2_num = document.getElementById("s2_num");
	var s3_num = document.getElementById("s3_num");
	var s4_num = document.getElementById("s4_num");
	var po_num = document.getElementById("po_num");
	
	// Set All Background Colors To Default
	fname.style.backgroundColor= "#FFFFFF";
	lname.style.backgroundColor= "#FFFFFF";
	address.style.backgroundColor= "#FFFFFF";
	city.style.backgroundColor= "#FFFFFF";
	state.style.backgroundColor= "#FFFFFF";
	zip.style.backgroundColor= "#FFFFFF";
	email.style.backgroundColor= "#FFFFFF";
	cc.style.backgroundColor= "#FFFFFF";
	expdate.style.backgroundColor= "#FFFFFF";
	cvv.style.backgroundColor= "#FFFFFF";
	amount.style.backgroundColor= "#FFFFFF";
	
	// Hide error container by default
	errordiv.style.display="none";											
	
	if(fname.value && fname.value != "")
	{
		if(lname.value && lname.value != "")
		{
			if(address.value && address.value != "")
			{
				if(city.value && city.value != "")
				{
					if(state.value && state.value != "")
					{
						if(zip.value && zip.value != "")
						{	
							if(email.value && email.value != "")
							{
								if(po_num.value == '')
								{
									if(cc.value && cc.value != "")
									{
										if(expdate.value && expdate.value != "")
										{
											if(cvv.value && cvv.value != "")
											{
												if(amount.value && amount.value != "")
												{												
													document.payform.submit();												
												}else{
													errordiv.style.display="block";
													errordiv.innerHTML="You must enter your payment amount to continue.";
													amount.focus();
													amount.style.backgroundColor= "#FFFFCC";
													return;
												}
											}else{
												errordiv.style.display="block";
												errordiv.innerHTML="You must enter your credit card CVV code to continue.";
												cvv.focus();
												cvv.style.backgroundColor= "#FFFFCC";
												return;
											}
										}else{
											errordiv.style.display="block";
											errordiv.innerHTML="You must enter your credit card expiration date to continue.";
											expdate.focus();
											expdate.style.backgroundColor= "#FFFFCC";
											return;
										}
									}else{
										errordiv.style.display="block";
										errordiv.innerHTML="You must enter your credit card number to continue.";
										cc.focus();
										cc.style.backgroundColor= "#FFFFCC";
										return;
									}
								}else{ /* This means they are using PO */
									document.payform.submit();
								}
							}else{
								errordiv.style.display="block";
								errordiv.innerHTML="You must enter an email address to continue.";
								email.focus();
								email.style.backgroundColor= "#FFFFCC";
								return;
							}
						}else{
							errordiv.style.display="block";
							errordiv.innerHTML="You must enter your billing zip code to continue.";
							zip.focus();
							zip.style.backgroundColor= "#FFFFCC";
							return;
						}
					}else{
						errordiv.style.display="block";
						errordiv.innerHTML="You must enter your billing state to continue.";
						state.focus();
						state.style.backgroundColor= "#FFFFCC";
						return;
					}
				}else{
					errordiv.style.display="block";
					errordiv.innerHTML="You must enter your billing city to continue.";
					city.focus();
					city.style.backgroundColor= "#FFFFCC";
					return;
				}
			}else{
				errordiv.style.display="block";
				errordiv.innerHTML="You must enter your billing address to continue.";
				address.focus();
				address.style.backgroundColor= "#FFFFCC";
				return;
			}
		}else{
			errordiv.style.display="block";
			errordiv.innerHTML="You must enter your last name to continue.";
			lname.focus();
			lname.style.backgroundColor= "#FFFFCC";
			return;
		}
	}else{
		errordiv.style.display="block";
		errordiv.innerHTML="You must enter your first name to continue.";
		fname.focus();
		fname.style.backgroundColor= "#FFFFCC";
		return;
	}
}
function show(id)
{
	document.getElementById(id).style.display = 'block';	
}
function hide(id)
{
	document.getElementById(id).style.display = 'none';	
}