
var acount = 1;
var alt = "";

function a(a){
	alt += acount + ": " + a + "\n";
	acount ++;
}

function validate_order(form){
	// Billing Name
	if(form.name.value == "")	
	a("Please enter your name");
	// Email Address
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(form.email.value))
	a("Please enter a valid email address");
	// Confirm Email
	if(form.email.value.toLowerCase() != form.email2.value.toLowerCase())
	a("Email addresses do not match");
	
	if(form.address1.value == "")
	a("Please enter the first line of your address");
	
	if(form.postal.value == "")
	a("Please enter your postal code");
	

  // how to use it in Javascript

  var regex =/^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$/;
	
	if(form.iptype.value == "static" && !regex.test(form.ipaddr.value))
	a("Please enter a valid IP address");
	
	if(alt != ""){
		alert("Your order is incomplete:\n" + alt);
		alt = "";
		acount = 1;
		return false;
	}
	
	return true;

}

function showhide(){
	var f = document.orderform;
	if(f["iptype"].value != "static"){
		f["ipaddr"].value = 'N/A';
		f["ipaddr"].disabled = true;
	}else{
		if(f["ipaddr"].value == "N/A") f["ipaddr"].value = "";
		f["ipaddr"].disabled = false;
	}
}

function order_information(){
	var f = document.orderform;
	// Define Prices
	var period = new Array();
	period["One Month"] = new Array(0,0,10,20,30,40);
	period["Three Months"] = new Array(0,0,24,51,78,105);
	period["Twelve Months"] = new Array(0,0,72,168,264,360);
	
	var total = 10;
	var GST = 0.05;
	var PST = 0.075;
	for(var i=0;i<5;i++){
		f["period"+i].value = f["period0"].value;
		f["price"+i].value = period[f["period"+i].value][f["channels"+i].value];
		total += (f["total"+i].value = f["quantity"+i].value * f["price"+i].value);
	}
	f["setupfee"].value = 10;
	f["subtotal"].value = total;
	
	if(f["country"].value != "Canada"){
		GST = 0;
		PST = 0;
	}
	if(f["province"].value != "Quebec"){
		PST = 0;
	}
	
	f["gst"].value = (100*GST) + "%";
	f["pst"].value = (100*PST) + "%";
	
	// Deal with taxes
	var tax = (total*(1+GST));
	tax += tax*PST;
	tax = tax - total;
	tax = Math.round(tax*100)/100;
	f["tax"].value = tax;
	
	f["total"].value = total + tax;
	
	return true;
}
var check = setInterval('order_information()',1000);
var dynamism = setInterval('showhide()', 1000);
