// Valdidate.js JavaScript Document


 
 //clear all highlighted elements
 function clearFields()
 {
	document.getElementById("info").childNodes[0].nodeValue=" ";
	document.getElementById("tb_service").style.backgroundColor="#FFFFFF";
	document.getElementById("tb_satisfied").style.backgroundColor="#FFFFFF";
	document.getElementById("tb_recommend").style.backgroundColor="#FFFFFF";
	document.getElementById("name").style.backgroundColor="#FFFFFF";
	document.getElementById("address").style.backgroundColor="#FFFFFF";
 }
 
/**
 * check if the form is valid
 validate the input and highlight missing fields
 */
 
function validateForm(form) {

clearFields();

var isValid=true;
var data_choice=false;

if  (!(document.Form1.Kitchen.checked || document.Form1.Bathroom.checked || document.Form1.Addition.checked || document.Form1.Painting.checked || document.Form1.Flooring.checked || document.Form1.Other.checked))
{
 isValid=false;
 document.getElementById("tb_service").style.backgroundColor="#FFC2A6";
}


if (document.Form1.categories.value=="")
{
 isValid=false;
document.getElementById("tb_satisfied").style.backgroundColor="#FFC2A6";
}


// Loop from zero to the one minus the number of radio button selections
for (counter = 0; counter < document.Form1.data.length; counter++)
{
// If a radio button has been selected it will return true

if (document.Form1.data[counter].checked)
data_choice = true; 
}
if (data_choice==false)
{
isValid=false;
document.getElementById("tb_recommend").style.backgroundColor="#FFC2A6";
}

if (document.Form1.name.value=="")
{
document.getElementById("name").style.backgroundColor="#FFC2A6";
isValid=false;
}


if (document.Form1.address.value=="" )
{
document.getElementById("address").style.backgroundColor="#FFC2A6";
isValid=false;
}
else if (!((document.Form1.address.value.indexOf(".") > 2) && (document.Form1.address.value.indexOf("@") > 0)))
{
document.getElementById("address").style.backgroundColor="#FFC2A6";
isValid=false;
}

if (isValid==false)
{
 document.getElementById("info").childNodes[0].nodeValue="Please enter information in the required fields";
 return false;
}

return true;
}
