// Order form functions

function selectPlan(selected) {
	form = document.mainForm;
	for(var i = 0; i < 6; ++i)
		form.plan[i].checked = (form.plan[i].value == selected);
	for(var i = 1; i <= 6; ++i) document.getElementById("plan" + i).className = "notselectedplan";
	document.getElementById("plan" + selected).className = "selectedplan";
}

function calcPaymentAmount(setup, months, monthly, saving, form) {
	var domaincost = (form.action[0].checked ? 0 : 50);
	document.getElementById("payment_setup").innerHTML = "&nbsp;$" + setup;
	document.getElementById("payment_months").innerHTML = months + " months:";
	document.getElementById("payment_monthly").innerHTML = "&nbsp;$" + (months * monthly);
	if(saving == 0)
		document.getElementById("payment_savings").innerHTML = "&nbsp;$0";
	else
		document.getElementById("payment_savings").innerHTML = '&nbsp;<b><font color="#0033FF">$' + saving + "</font></b>";
	document.getElementById("payment_amountex").innerHTML = "&nbsp;$" + (Math.round((setup + months * monthly - saving + domaincost) / 11 * 1000) / 100) + " + $" + (Math.round((setup + months * monthly - saving + domaincost) / 11 * 100) / 100) + " GST";
	document.getElementById("payment_amount").innerHTML = "&nbsp;$" + (setup + months * monthly - saving + domaincost);
}

function creditcardjump(form, box) {
	// force numeric only
	var clean = "", v = eval("form.cardnumber" + box + ".value");
	for(var i = 0; i < v.length; ++i)
		switch(v.charAt(i)) {
			case '1': case '2': case '3': case '4': case '5':
			case '6': case '7': case '8': case '9': case '0':
			clean += v.charAt(i);
		}
	eval("form.cardnumber" + box + ".value = '" + clean + "'");
	
	// jump box
	if(box == 4) return;
	if(clean.length >= 4) eval("form.cardnumber" + (box + 1) + ".focus()");
}

function changeDomainAction(form) {
	document.getElementById("domainnamecost").innerHTML = "&nbsp;$" + (form.action[0].checked ? "0" : "50");
	for(var i = 1; i <= 4; ++i)
		if(document.getElementById("save" +i).checked)
			document.getElementById("save" +i).click();
}

function confirmNext(form) {
	var next = confirm("Are your sure your details are correct? Click OK to proceed with the payment, cancel to go back and check your details.");
	if(next) form.submit();
}

function loadBillingAddress(form) {
	form.cardaddress.value = form.address.value;
	form.cardcity.value = form.city.value;
	form.cardstate.value = form.state.value;
	form.cardpostcode.value = form.postcode.value;
	form.cardcountry.value = form.country.value;
}
