function submitPostCode() {
	el = document.getElementById("PostCode");
	if (el.value)
	{
		window.location = 'https://secure.lessmess.ca/products.php?code=' + el.value;
//		window.location = 'http://preview.thebrandfactory.com/lessmess/secure/products.php?code=' + el.value;
	} else alert("Please enter your postal code");

}

var GST = 0.05;
var PST = 0.08;
function updateTotals() {
	total1 = 0;
	qt = 0;
	for (i=1; i<=6 ; i++ )
	{
		el = document.getElementById('Qty' + i);
		el2 = document.getElementById('Price' + i);
		el3 = document.getElementById('Total' + i);
		subt = parseInt(el.value) * parseInt(el2.value);
		if (!subt) {
			subt = 0;
			
		} else if (i<6) qt += parseInt(el.value);
		total1 = total1 + subt;
		el3.innerHTML = formatCurrency(subt);
	}
	var discount = 0;
	el = document.getElementById('Qty' + 6);
	if (parseInt(el.value) > 1)
	{
		discount = 25 * (parseInt(el.value) - 1);
	}
	discount += (qt-1) * 25;

	el = document.getElementById('subtotal'); 	el.innerHTML = formatCurrency(total1);
	el = document.getElementById('discount'); 	el.innerHTML = formatCurrency(discount);
	total1 = total1 - discount;
	el = document.getElementById('tax1'); 	el.innerHTML = formatCurrency(total1 * GST);
	el = document.getElementById('tax2'); 	el.innerHTML = formatCurrency(total1 * PST);
	el = document.getElementById('grandtotal'); 	el.innerHTML = formatCurrency(total1 * (1 + GST + PST));

}

function validateWasteQty() {
	total1 = 0;
	for (i=1; i<=5 ; i++ )
	{
		el = document.getElementById('Qty' + i);
		subt = parseInt(el.value);
		if (!subt) subt = 0;
		total1 = total1 + subt;
	}
	el = document.getElementById('Qty' + 6);
	if (parseInt(el.value) > total1)
	{
		alert("The number of bags of waste pick-up cannot exceed the number of bags of soil purchased, as the waste will be returned using the same bags!");
		el.focus();
		el.select();
		return false;
	}
	updateTotals();	 
	return true;

}



function updateOrderQty() {
	orderQty = "0";
	cnt = 0;
	for (i=1; i<=6 ; i++ )
	{
		el = document.getElementById('Qty' + i);
		orderQty += "," + el.value;
		if (parseInt(el.value)) cnt += parseInt(el.value);
	}
	if (cnt==0)
	{
		alert("Please select the products you want to purchase");
		return false;
	}
	window.location = "delivery.php?qty=" + orderQty;
}

function resetOrderQty() {
	for (i=1; i<=6 ; i++ )
	{
		el = document.getElementById('Qty' + i);
		el3 = document.getElementById('Total' + i);
		el3.innerHTML = "$0.00";
		el.value = 0;
	}
	el = document.getElementById('subtotal'); 	el.innerHTML = "$0.00";
	el = document.getElementById('discount'); 	el.innerHTML = "$0.00";
	el = document.getElementById('tax1'); 	el.innerHTML = "$0.00";
	el = document.getElementById('tax2'); 	el.innerHTML = "$0.00";
	el = document.getElementById('grandtotal'); 	el.innerHTML = "$0.00";

}


function toggleDate(x) {
	for (i=1; i<=4 ; i++ )
	{
		if (x == i) continue;
		el = document.getElementById('Date' + i);
		el.value = "0";
		el = document.getElementById('cbDate' + i);
		el.src="images/cb_off.jpg";
	}
	el = document.getElementById('Date' + x);
	el2 = document.getElementById('cbDate' + x);

	if (parseInt(el.value) == 1)
	{
		el.value = 0;
		el2.src="images/cb_off.jpg";
	} else {
		el.value = 1;
		el2.src="images/cb_on.jpg";
	}

}

function updateDelivery() {
	x = 0;
	for (i=1; i<=4 ; i++ )
	{
		el = document.getElementById('Date' + i);
		if (el.value == 1)
		{
			x = i;
			break;
		}
	}
	if (x)
	{
		el = document.getElementById('txtDate' + x);
		window.location = "payment.php?date=" + el.value;
	} else alert("Please select a delivery date!");

}

function placeOrder() {
	el = document.getElementById('FirstName'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('LastName'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('Address'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('City'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('Province'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('PostCode'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('Phone1'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('Phone2'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('Phone3'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('CCNumber'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('CCType'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('CCName'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('CCYear'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('CCMonth'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('Sources'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('Email'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el2 = document.getElementById('Email2'); if (!el2.value) { alert("Please fill all required fields!"); return false;}
	if (el.value != el2.value)
	{
		alert("Email address verification failed, please review!"); 
		return false;
	}
	el = document.getElementById('frmPayment');
	el.submit();
}

function reviewOrder() {
	el = document.getElementById('FirstName'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('LastName'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('Address'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('City'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('Province'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('PostCode'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('Phone1'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('Phone2'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('Phone3'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('CCNumber'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('CCType'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('CCName'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('CCYear'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('CCMonth'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('Sources'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el = document.getElementById('Email'); if (!el.value) { alert("Please fill all required fields!"); return false;}
	el2 = document.getElementById('Email2'); if (!el2.value) { alert("Please fill all required fields!"); return false;}
	if (el.value != el2.value)
	{
		alert("Email address verification failed, please review!"); 
		return false;
	}
	el = document.getElementById('frmPayment');
	el.target="_blank";
	el.action="review.php";
	el.submit();
	el.target="_self";
	el.action="order.php";
}

function showWasteHelp() {
	txt = "<div style='text-align: left; padding: 30px;'><b>Items Not Allowed: </b><ul><li>Tires	</li><li>Paints</li><li>Chemicals	</li><li>Solvents</li><li>Fluorescent tubes	</li><li>Light fixtures with ballasts</li><li>Batteries	</li><li>Other hazardous materials</li></ul></div>";
	message2(txt);
}

var products = [];
function showProductInfo(nm, productid) {
	txt = "<div style='text-align: left; padding: 30px; width: 400px; font-weight: normal;'><span class='greentxt'><b>"+nm + "</b></span><br>" + products[productid]+"</div>";
	
	message2(txt);
}

function showCubicInfo() {
	txt = '<div style="text-align: left; padding: 30px; font-weight: normal;"><b>Cubic Yard Coverage</b><br><br><span class="greentxt">1 Cubic Yard</span> Covers 324 square feet 1" deep<br><span class="greentxt">1 Cubic Yard</span> Covers 162 square feet 2" deep<br><span class="greentxt">1 Cubic Yard</span> Covers 108 square feet 3" deep<br><span class="greentxt">1 Cubic Yard</span> Covers   81 square feet 4" deep<br><span class="greentxt">1 Cubic Yard</span> Covers   54 square feet 5" deep</div>';
	message2(txt);

}




function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

