/*********************************************************************************************
 *    ensure the input is not empty or is not all space characters
 ************************************************************************************/   
function isValid(param){
/* check of the input is undefined */
	if(!param){
		return false;
	}
	var aString = param.toString();
/*check if the user input only spaces */
	var i = 0;
	var spc_cnt = 0;
	while(i < aString.length){
		if(aString.charAt(i) == " "){
			spc_cnt++;
		}
		i++;
	}
	if(spc_cnt == aString.length){
		return false;
	}
return true
}
/************************************************************************
 * strip leading and trailing spaces
 ********************************************************************/
function trim_spcs(param){
	var newStr;
	var i = 0;
	var j = param.length;
	//number of leading spaces
	while(param.charAt(i) == " "){
		i++;
	}
	//number of trailing spaces
	while(param.charAt(j) == " "){
		j--;
	}
 	newStr = param.substring(i, j);
return newStr;
}

/*****************************************************************************
 *
 ***************************************************************************/

function validate(theForm){
	
	var emailPat = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$"
  	var matchArray = theForm.email.value.match(emailPat);

	 if(!isValid(theForm.full_name.value)){
		alert("please enter your full name");
		theForm.full_name.value = "";
		theForm.full_name.focus();
		return false;
	}
	else{
		theForm.full_name.value = trim_spcs(theForm.full_name.value);
	}

	if (matchArray == null) {
		theForm.email.focus()
		alert("Email address missing or incorrect")
		return false
	}


	if(!isValid(theForm.company.value)){
		alert("please enter your company name");
		theForm.company.value = "";
		theForm.company.focus();
		return false;
	}
		else{
		theForm.company.value = trim_spcs(theForm.company.value);
	}

	if(!isValid(theForm.subject.value)){
		alert("please indicate your subject");
		theForm.subject.value = "";
		theForm.subject.focus();
		return false;
	}
		else{
		theForm.subject.value = trim_spcs(theForm.subject.value);
	}

}//end function
