// JavaScript Document
//checkWholeForm
/*function checkWholeForm(theForm) {
    var errormsg = "";
    errormsg += checkEmail(theForm.email.value);
    errormsg += checkPhone(theForm.phone.value);
    errormsg += checkPassword(theForm.password.value);
    errormsg += checkUsername(theForm.username.value);
    errormsg += isEmpty(theForm.notempty.value);
    errormsg += isDifferent(theForm.different.value);
    if (errormsg != "") {
    alert(errormsg);
    return false;
    }
return true;
}*/
//checkUsername
function checkTextFields (strng,name) {
 if (strng == "") {
    alert("You didn't enter a corrert value for "+name+"\n");
	return false;
 }
 
 if (strng.length < 3) {
    alert("The "+name+" must be more than 3 characters.\n");
	return false;
}

var illegalChars = /\W[ ]/;
  // allow only letters, numbers, and underscores
    if (illegalChars.test(strng)) {
       alert("The "+name+" contains illegal characters.\n");
		 return false;
    } 
	 return true;
}
//checkPassword
function checkPassword(strng) {
  if (strng =="") {
    alert("You didn't enter a password.\n");
	return false;
 }
    var illegalChars = /[\W_]/; // allow only letters and numbers
    if (strng.length < 3 || strng.length > 15) {
       alert("The password must be more than 3 characters.\n");
	   return false;
    }
    else if (illegalChars.test(strng)) {
      error="The password contains illegal characters.\n";
	  return false;
    }
	
	/*else if (!((strng.search(/(a-z)+/))
  && (strng.search(/(A-Z)+/))
  && (strng.search(/(0-9)+/)))) {
  error="The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
	return error;
  }*/
	return true;
} 
//checkEmail
function checkEmail(strng){
if (strng=="") {
   alert("The E-mail Address can't be empty.\n");
   return false;
}
var emailFilter=/^.+@.+\..{2,3}$/;
if (!(emailFilter.test(strng))) { 
       alert("Please enter a valid email address.\n");
	   return false;
}

var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
if (strng.match(illegalChars)) {
   alert("The email address contains illegal characters.\n");
   return false;
}
	return true;
}
//checkPhone
function checkPhone(strng){
if (strng=="") {
   alert("The phone number can't be empty.");
   return false;
}
var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
if (isNaN(parseInt(stripped))) {
   alert("The phone number contains illegal characters.");
   return false;
}

if ((stripped.length<5)) {
	alert("The phone number is of the wrong length.\n");
	  return false;
}
	return true;
}
//isDifferent

function isDifferent(strng1,strng2) {
  if (strng1 != strng2) {
     alert("The password does not match each other.\n");
	 return false;
  }
	return true;
}
function isEmpty(strng) {
  if (strng=="") {
     alert("The Field can't be Empty.\n");
	 return false;
  }
	return true;
}

  
//checkRadio
/*  
  for (i=0, n=theForm.radios.length; i<n; i++) {
   if (theForm.radios[i].checked) {
      var checkvalue = theForm.radios[i].value;
      break;
   }
}
errormsg += checkRadio(checkvalue);
 */
function checkRadio(checkvalue) {
   if (!(checkvalue)) {
       alert("Please check a radio button.\n");
    }
return true;    
}

//check Dropdown

function checkDropdown(choice) {
    if (choice == 'Select Country') {
       alert("You didn't choose an option from the drop-down list for country.\n");
	   return false;
    }    
return true;
}