// Form Validation

function check_form(f) { // f is the form (passed using the this keyword)
if(f.name.value.length < 2){
alert("Please enter your full name");
f.name.focus(); // put the prompt in the name field 
// if the browser is Netscape 6 or IE
if(document.all || document.getElementByID){
// change the color of text field
f.name.style.background = "#FFDD9D";
}
// make sure the form is not submitted
return false;
}

if(f.company.value.length < 2){
alert("Please enter the name of the company you work for");
f.company.focus(); // put the prompt in the name field 
// if the browser is Netscape 6 or IE
if(document.all || document.getElementByID){
// change the color of text field
f.company.style.background = "#FFDD9D";
}
// make sure the form is not submitted
return false;
}

if(f.address1.value.length < 2){
alert("Please enter your address.");
f.address1.focus(); // put the prompt in the name field 
// if the browser is Netscape 6 or IE
if(document.all || document.getElementByID){
// change the color of text field
f.address1.style.background = "#FFDD9D";
}
// make sure the form is not submitted
return false;
}

if(f.province1.value.length < 2){
alert("Please enter your province");
f.province1.focus(); // put the prompt in the name field 
// if the browser is Netscape 6 or IE
if(document.all || document.getElementByID){
// change the color of text field
f.province1.style.background = "#FFDD9D";
}
// make sure the form is not submitted
return false;
}

if(f.phone.value.length < 10){
alert("Please the phone number you would like to be contacted at (including area code)");
f.phone.focus(); // put the prompt in the name field 
// if the browser is Netscape 6 or IE
if(document.all || document.getElementByID){
// change the color of text field
f.phone.style.background = "#FFDD9D";
}
// make sure the form is not submitted
return false;
}

//------------------------------------------------------//


// check the first email address ( the exclamation means "not" )
if(!check_email(f.email.value)){
alert("Invalid email detected.");
f.email.focus(); 
// if the browser is Netscape 6 or IE
if(document.all || document.getElementByID){
// change the color of text field
f.email.style.background = "#FFDD9D";
}
// make sure the form is not submitted
return false;
}

// check the second email address
if(!check_email(f.another_email.value)){
alert("Invalid email detected.");
f.another_email.focus(); 
if(document.all || document.getElementByID){
f.another_email.style.background = "#FFDD9D";
}
return false;
}
}