//for contact form - the functions called within this next function 
//MUST match the form fields exactly

//declare  this function in the actual page
//function validateFormOnSubmit(theForm) {
//var reason = "";

 // reason += validateUsername(theForm.username);

 // reason += validateEmail(theForm.email);
  //reason += validatePhone(theForm.phone); //only use this if there is a field name="phone"
 
  //reason += validateEmpty(theForm.comments);
	 
  //if (reason != "") {
  //  alert("Some fields need correction:\n" + reason);
 //   return false;
 // }

  //return true;
//}

function validate_required(field,fieldtxt){ var error = '';
   var x=document.getElementById(field);
   if (x.value.length == 0) {
	 error = fieldtxt +' required \n' ;
	 x.style.background = 'Yellow';
   }else{
	 x.style.background = 'White';
	 }
return error; } 



function validate_email(field,fieldtxt){ 

  var error = '';
   var x=document.getElementById(field);
	 var tfld = trim(x.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
		
		if (x.value == "") {
        x.style.background = 'Yellow';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        x.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (x.value.match(illegalChars)) {
        x.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        x.style.background = 'White';
    }		
 return error; 
 } 



function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}


//Advanced Email Check credit-
//By JavaScript Kit (http://www.javascriptkit.com)
//Over 200+ free scripts here!

var testresults
function checkemail(){
var str=document.fregister.email.value
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{
alert("Please input a valid email address!")
testresults=false
}
return (testresults)
}


