var invalids="/:,;!~$";			//lists the characters that shouldn't be included 

function isValid(string){
	for(var i=0; i<string.length; i++){
	  if(invalids.indexOf(string.charAt(i)) != -1)
		return false;
	}
	return true;
}
function validateMailFm(){

	var errmsg = "";
	
	// Check Name
	var tmpname = document.mailform.fname.value;
	if(tmpname=="") errmsg += "Please provide your name\n";
	if(!isValid(tmpname)) errmsg += "\"" + invalids + "\" characters are invalid for name";
	// Check email
	var tmpemail=document.mailform.femail.value;
	if (tmpemail=="") errmsg += "Please provide your email address\n";
	if(!isValid(tmpemail)) errmsg += "The email you provided is not in valid format\n";
	if(tmpemail.indexOf("@") == -1) errmsg += "The valid email format is name@domain.ext \n";
	if(tmpemail.indexOf(".") == -1) ;
	// Check Subject
	var tmpsub = document.mailform.fsubject.value;
	if(tmpsub=="") errmsg += "Please provide the subject of your inquiry\n";
	if(!isValid(tmpsub)) errmsg += "\"" + invalids + "\" characters are invalid in subject field";
	// Check message
	var tmpmsg = document.mailform.fmessage.value;
	if(tmpmsg=="") errmsg += "Please provide the message of your inquiry\n";
	//if(!isValid(tmpmsg)) errmsg += "Please remove \"" + invalids + "\" characters";
	
	// Display error message if any	
	if(errmsg!=""){
		alert(errmsg);
		return false;
	}else{
		document.mailform.submit();
	}
}
