function trimchar(inputStr, needle){
	  if (needle.length){
	  while(''+inputStr.charAt(0)==needle){inputStr=inputStr.substring(1,inputStr.length);}
	  while(''+inputStr.charAt(inputStr.length-1)==needle){ inputStr=inputStr.substring(0,inputStr.length-1); }
	   }
	  return inputStr;
  }
  
//===================================================
function validEmail (fld) {
	 var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	 if(reg.test(fld.value) == false) {
		 alert("Invalid Email Address");
		 fld.focus();
		 return false;
		 }
	 else { return true; }
  }
  
//===================================================
function isEmpty(fld, Msge){
  fld.value=trimchar(fld.value,"\n");
  fld.value=trimchar(fld.value," ");
  if(fld.value==''){alert(Msge); fld.focus(); return true; } 
  else { return false; }  
  }
  
//=================================================== 
function validate(frm){
var fld, Msge;
if(isEmpty(frm.firstname, 'Please enter your first name')){return false; }
else if(isEmpty(frm.email, 'Please enter your email address')){return false; }
else if(!validEmail(frm.email)){return false; }
else {
alert("We are still fine-tuning the last chapter of guide.\n It should be ready within the next few days.\n We will send over a copy to your inbox as soon as it\'s ready");
}
return true;
}


//=================================================== 
function validcontact(frm){
var fld, Msge;
if(isEmpty(frm.firstname, 'Please enter your first name')){return false; }
else if(isEmpty(frm.email, 'Please enter your email address')){return false; }
else if(!validEmail(frm.email)){return false; }
else if(isEmpty(frm.questions, 'How may I help you?')){return false; }

return true;
}
