var msg = "____________________________________________\n\n";
    msg += "Your entry cannot be submitted without\nthe following information:\n";
    msg += "____________________________________________\n\n";
    
function trimAll( strValue ) {
 var objRegExp = /^(\s*)$/;

    //check for all spaces
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }
    
   //check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}
function validateNotEmpty( strValue ) {
   var strTemp = strValue;
   strTemp = trimAll(strTemp);
   if(strTemp.length > 0){
     return true;
   }  
   return false;
}
function validateEmail(strValue) {
var objRegExp  = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})$/;
  //check for valid email
  return objRegExp.test(strValue);
}

//Function to check form is filled in correctly before submitting
function CheckForm (form) {
	
	var FieldToFocus = null;
	var FieldType = null;
	var errorMsg = "";

	//No EmailAddress and no Phone
	if(!validateNotEmpty(form.Email.value) && !validateNotEmpty(form.Phone.value)){
		errorMsg += "\nEnter Email Address or Phone Number";
		if(FieldToFocus == null)
			FieldToFocus = 	"Email";
	}
	else if(validateNotEmpty(form.Email.value) && !validateNotEmpty(form.Phone.value)){
		//Check for an EmailAddress
		if(!validateEmail(form.Email.value)){
			errorMsg += "\nEnter a valid Email Address";
			if(FieldToFocus == null)
				FieldToFocus = 	"Email";
		}					
	}
	//Check for Questions
	if(!validateNotEmpty(form.Questions.value)){
		errorMsg += "\nEnter your Questions";
		if(FieldToFocus == null)
			FieldToFocus = 	"Questions";					
	}
	
	//If there is a problem with the form then display an error
	if (errorMsg != ""){
		errorMsg += alert(msg + errorMsg + "\n\n");
		if(FieldType == null)
			form[FieldToFocus].focus();
		else
			form[FieldToFocus][0].focus();
		return false;
	}

	return true;
}