/* Form Validation */
function checkForm()
{
firstName = document.getElementById("firstName").value;
surname = document.getElementById("surname").value;
email = document.getElementById("email").value;
address = document.getElementById("address").value;
postcode = document.getElementById("postcode").value;
country = document.getElementById("country").value;
telephone = document.getElementById("telephone").value;

hideAllErrors();

errors = false;

if (firstName.length < 3)
{
document.getElementById("firstNameError").style.display = "inline";
document.getElementById("firstName").select();
document.getElementById("firstName").focus();
errors = true;
}

if (surname.length < 3)
{
document.getElementById("surnameError").style.display = "inline";
if (!errors)
	{
	document.getElementById("surname").select();
	document.getElementById("surname").focus();
	}
errors = true;
}

var emailFilter=/^.+@.+\..{2,3}$/;

if (!(emailFilter.test(email)))
{
document.getElementById("emailError").style.display = "inline";
if (!errors)
	{
	document.getElementById("email").select();
	document.getElementById("email").focus();
	}
errors = true;
}

if (address.length < 5)
{
document.getElementById("addressError").style.display = "inline";
if (!errors)
	{
	document.getElementById("address").select();
	document.getElementById("address").focus();
	}
errors = true;
}

if ((postcode.length < 4) || (isNaN(postcode)))
{
document.getElementById("postcodeError").style.display = "inline";
if (!errors)
	{
	document.getElementById("postcode").select();
	document.getElementById("postcode").focus();
	}
errors = true;
}

if (country.length < 3)
{
document.getElementById("countryError").style.display = "inline";
if (!errors)
	{
	document.getElementById("country").select();
	document.getElementById("country").focus();
	}
errors = true;
}

if (telephone.length < 7)
{
document.getElementById("telephoneError").style.display = "inline";
if (!errors)
	{
	document.getElementById("telephone").select();
	document.getElementById("telephone").focus();
	}
errors = true;
}

return !errors;
}
 
function hideAllErrors()
{
document.getElementById("firstNameError").style.display = "none"
document.getElementById("surnameError").style.display = "none"
document.getElementById("emailError").style.display = "none"
document.getElementById("addressError").style.display = "none"
document.getElementById("postcodeError").style.display = "none"
document.getElementById("countryError").style.display = "none"
document.getElementById("telephoneError").style.display = "none"
}

/* Order Form */
function Total()
	{
    var q, i, orderTotal;
    orderTotal = 0;
    nitems = 9
    
	for (i=1; i<nitems+1; i++)
		{
        eval("document.santaVittoriaForm.Item" + i + "Total.value = '';");
        eval("q = document.santaVittoriaForm.Item" + i + "Quantity.value;");
        
		if (q)
			{
            eval("total=document.santaVittoriaForm.Item" + i + "Price.value * document.santaVittoriaForm.Item" + i + "Quantity.value;");
            eval("document.santaVittoriaForm.Item" + i + "Total.value=currency(total)");
            eval("orderTotal = orderTotal + total;");
            }
        }
	
	document.santaVittoriaForm.orderTotal.value = currency(orderTotal);
	
}

function currency(anynum)
	{
    anynum = "" + eval(anynum)
    intnum = parseInt(anynum)
    intnum = Math.abs(intnum)
    intstr = ""+intnum
		
    if (intnum >= 1000)
		{
        intlen = intstr.length
        temp1=parseInt(""+(intnum/1000))
        temp2=intstr.substring(intlen-3,intlen)
        intstr = temp1+","+temp2
        }
		
	if (intnum >= 1000000)
		{
        intlen = intstr.length
        temp1=parseInt(""+(intnum/1000000))
        temp2=intstr.substring(intlen-7,intlen)
        intstr = temp1+","+temp2
        }

	decnum = Math.abs(parseFloat(anynum)-parseInt(anynum))
	decnum = decnum * 100
	decstr = "" + Math.abs(Math.round(decnum))
	if (decstr.length>2) {decstr=decstr.substring(0,2)
	}

	while (decstr.length < 2) {decstr="0"+decstr}
	retval = intstr + "." + decstr 
	if (anynum < 0)
		{
		retval="("+retval+")"
		}
	return "$"+retval
}

function init()
{
document.santaVittoriaForm.reset();
}

window.onload=init;