String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}


function validate_form(theform) {
	var errString    = "The following fields are required to submit this form:";
	var orgErrString = errString;
	if  ( 
			( theform.FirstName.value == null || theform.FirstName.value.trim() == "" )
			&&
			( theform.LastName.value == null || theform.LastName.value.trim() == "" ) 
		) {
		errString += "\nYour name is required"
	}
	
	if  ( theform.Email.value == null || theform.Email.value.trim() == "" ) {
		errString += "\nYour email is required";
	} else if ( ! echeck(theform.Email.value) ) {
		errString += "\nA valid email address is required";
	}
	
	if ( errString != orgErrString ) {
		alert(errString);
		return false;
	} else {
		return true;
	}
}


function validate_required(field,alerttxt)
	{
		with (field)
		{
		if (value==null||value=="")
		  {alert(alerttxt);return false}
		else if ( echeck(value) == false ) {
			return false;
		}
		else {return true}
	}
}
function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if 
	(str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	   return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	   return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    return false
	 }

	return true;					
}