//function checks whether a text field is blank or not (textObj is an object of the form object)
function isBlank(textObj)
{
	if (textObj.value == "")
	{
		//if the text field (textObj) is blank then the function returns true.
		return true;
	}
	//otherwise it returns false.
	else return false;
}//end function isBlank

//Below is the Validate form function. 
//This function is called upon submiting the form. The onSubmit event returns the boolean return value from this function. If true is returned then the form is submitted, else it is not and the user can continue editing their details while their previous entry remains. The function returns true after a confirm box displaying the input details is approved. 
function validate(formObj)
{
//sErrMsg is a String variable that collects the applicable error statements for each text field element that has a missing value
var sErrMsg = '';
var sErrEmailMsg = '';
var bIsCorrect = false; 

//bIsCorrect stroes a boolean value of wether the form has passed validation or not. If all fields have been filled in the value is set to true.

if (isBlank(formObj.name_Req))
{
 document.getElementById("name_Req").style.border='2px solid #8ee41e';
 sErrMsg += 'No name.';
}
else { 
	document.getElementById("name_Req").style.border='solid 1px #b6b6b6';
	}
if (isBlank(formObj.contact_Req_Email))
{
 sErrMsg += 'No email 1.';
 document.getElementById("contact_Req_Email").style.border='2px solid #8ee41e';
}
else { 
	document.getElementById("contact_Req_Email").style.border='solid 1px #b6b6b6';
	}
if (isBlank(formObj.message_Req))
{
 sErrMsg += 'No email 2.';
 document.getElementById("message_Req").style.border='2px solid #8ee41e';
}
else
	{ 
	document.getElementById("message_Req").style.border='solid 1px #b6b6b6';	
	}

//Here we are checking a combo box. So instead of using the usBlank function we ask whether the value of the combo box is 0. If it is then no true value that we can use has been selected. Therefore we prompt the user to choose a value. 
//This same technique us used for the rest of the combo boxes in the form.


//The below if statement checks wether the sErrMsg string varible is more than 0. If the string length is more than 0 then this means there is a character stored. If there is then there must be an error in the form. Therefore the code continues to alert the user explaining that not all the fields have been filled in and then prints the relevant stored error messages. 
if (sErrMsg.length > 0)
{

	document.getElementById("errorMessage").innerHTML='*Please fill in the highlighted fields.' + sErrEmailMsg;
	
	return bIsCorrect;
}
else 
{
	sErrMsg = 'Thank you your message has been sent.';
	document.getElementById("errorMessage").innerHTML='';
}


}//end function validate()
