function checkWholeForm(theForm) {
    var why = "";
	for (var i=0; i < document.theForm.gender.length; i++)
   {
   if (document.theForm.gender[i].checked)
      {
      var gender_value = document.theForm.gender[i].value;
      }
   }
       why += checkUsername(document.theForm.name.value);
       	 //why += checkPhonename(document.theForm.telephone.value);
		   why += checkEmail(document.theForm.email.value);
		 // why += checkPhone(document.theForm.telephone.value);
		  why += checkEmail2(document.theForm.email.value,document.theForm.email2.value);
		  why += checkEmailDomain(document.theForm.email.value);
		   why += checkPhone(document.theForm.telephone.value);
		   why += checkZip(document.theForm.zipcode.value);
		  why += checkGender(gender_value);
		  if (why != "") {
       alert(why);
       return false;
    }
return true;
}
function checkUsername (strng) {
 var error = "";
 if (strng == "") {
    error = "Please enter your name.\n";
    }
	return error;
 }
function checkPhonename (strng) {
 var error = "";
 if (strng == "") {
    error = "Please enter your phone number.\n";
    }
	return error;
 }
function checkEmail(strng) {
var error = "";
var emailFilter=/^.+@.+\..{2,3}$/;
if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
}
var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
if (strng.match(illegalChars)) {
   error = "The email address contains illegal characters.\n";
}
return error;
}
function checkEmail2(strng1,strng2) {
var error = "";
if (strng1!=strng2) { 
       error = "The email addresses do not match.\n";
}
return error;
}
function checkPhone(strng) {
var error = "";
var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
if (isNaN(parseInt(stripped))) {
   error = "The phone number contains illegal characters.";
}
if (!(stripped.length == 10)) {
	error = "The phone number is the wrong length.\n";
}
return error;
}
function checkGender (strng) {
 var error = "";
  if (strng!="male" && strng!="female") {
    error = "Please enter your gender.\n";
    }
	return error;
 }
function checkEmailDomain(nname){
var arr = new Array('.com','.net','.org','.biz','.info','.edu','.gov','.mil');
var mai = nname;
var val = true;
var error = "";
var dot = mai.lastIndexOf(".");
var dname = mai.substring(0,dot);
var ext = mai.substring(dot,mai.length);
//alert(ext);
if(dot>2 && dot<57){
	for(var i=0; i<arr.length; i++)	{
	  if(ext == arr[i])	  {
	 	val = true;
		break;
	  }else{
	 	val = false;
	  }
	}
	if(val == false){
	  	 error = "Your email domain "+ext+" is not correct.\n";
		 return error;
	}else{
		for(var j=0; j<dname.length; j++){
		  var dh = dname.charAt(j);
		  var hh = dh.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==45 || hh==46){
			 if((j==0 || j==dname.length-1) && hh == 45){
		 	  	 error = "Email domain name should not begin or end with '-'.\n";
			      return error;
		 	 }
		  }else{
		  	 error = "";
			 return error;
		  }
		}
	}
}else{
 error = "Your email domain name is too short/long.\n";
 return error;
}	
return error;
}
function checkZip(strng) {
 var error = "";
 if (strng == "") {
    error = "Please enter your zip code.\n";
    }
	return error;
 }
