var VatRate=.2;	// UK VAT rate 
	
function doTotals(form) {
	var Tax=0, GTot=0;
	if (form.VatAmtInd.checked) {
		Tax = VatRate*parseFloat(form.Cost.value);
		form.AmtOfVat.value = formatDec(Tax,2);
	}
	GTot = Tax + parseFloat(form.Cost.value);
	form.GrandTotal.value = formatDec(GTot,2);
}

function inspectOptions(btn,field,form) {
	field.value = formatDec(btn.value,2);
	doSalesTax(form.VatAmtInd,form);
	doTotals(form);
}

function doSalesTax(field,form) {
	if (field.checked) 
		form.AmtOfVat.value = formatDec(VatRate*form.Cost.value,2);
	else 
		form.AmtOfVat.value = formatDec(0,2);
	doTotals(form);
}

function reset_handler(){
	showImage("RegNameError", "images/cross.gif");
	showImage("Emailerror", "images/cross.gif");
	return true;
}

function formatDec(expr,decplaces) {
	var str = "" + Math.round (eval(expr) * Math.pow(10,decplaces));
	while (str.length <= decplaces) {
		str = "0" + str;
	}
	var decpoint = str.length - decplaces;
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}

function deflect_focus(curr_field){
	var curr_form=curr_field.form
	curr_form.Email.focus()
}

function printWindow(){
	bV = parseInt(navigator.appVersion)
	if (bV >= 4) window.print()
}

function trimLength(fld){
size = fld.length
while(fld.slice(size-1,size)== " ") //Strip trailing spaces
 {fld = fld.substr(0,size-1);size = fld.length}
return fld.length
}

function showImage(imagename, imageurl) {
	document[imagename].src = imageurl;
}

function validateField(fld) {
var imagename="RegNameError";
(trimLength(fld) < 1) 
	? showImage(imagename, "images/cross.gif")
	: showImage(imagename, "images/tick.gif");
}

function check_email(email_address) {
	var imagename="Emailerror";
	if (email_address.length < 5) {
		showImage(imagename, "images/cross.gif")}
	else	{at_location = email_address.indexOf("@")
			dot_location = email_address.lastIndexOf(".")
			if (at_location < 1 || dot_location == -1 || at_location > dot_location 
			|| (dot_location - at_location < 2) || (email_address.length - dot_location < 2) ) {
			showImage(imagename, "images/cross.gif")}
			else 	{showImage(imagename, "images/tick.gif")}}
}
