
function checkemail (strng) {
var error="";
if (strng=="") {
   error = "You didn't enter a <b>Email Address</b>.";
}else{

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid <b>Email Address</b>.";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.";
       }
    }}
return error;    
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a <b>Phone Number</b>.";
}else{
/*
var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.";
  
    }*/

stripped=filterNum(strng);

    if (!(stripped.length == 10)) {
	error = "The <b>Phone Number</b> is the wrong length.";
    } }
return error;
}


// password - between 6-8 chars, uppercase, lowercase, and numeral

function checkPassword (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a password.";
}

    var illegalChars = /[\W_]/; // allow only letters and numbers
    
    if ((strng.length < 6) || (strng.length > 8)) {
       error = "The password is the wrong length.";
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.";
    } 
    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;    
}    


// username - 4-10 chars, uc, lc, and underscore only.

function checkUsername (strng) {
var error = "";
if (strng.length=='0') {
   error = "You didn't enter a username.";
}else{


    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 4) || (strng.length > 10)) {
       error = "The username is the wrong length.";
    }
    else if (illegalChars.test(strng)) {
    error = "The username contains illegal characters.";
    }} 
return error;
}       


// non-empty textbox

function isEmpty(strng) {
var error = "";
  if (strng.length == 0) {
     error = "The mandatory text area has not been filled in."
  }
return error;	  
}

// was textbox altered

function isDifferent(strng) {
var error = ""; 
  if (strng != "Can\'t touch this!") {
     error = "You altered the inviolate text area.";
  }
return error;
}

// exactly one radio button is chosen

function checkRadio(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "Please check a radio button.";
    }
return error;
}

// valid selector from dropdown list

function checkDropdown(choice) {
var error = "";

    if (choice == 0 || choice=='none' || choice=='') {
    error = "You didn't choose an option from the drop-down list.";
    }    
return error;
} 

function checkisEmpty(str){
if(str.length=="0"){return 1;
}

}


function checkFax (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a fax number.";
}else{

/*var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The fax number contains illegal characters.";
  
    }
    if (!(stripped.length == 10)) {
	error = "The fax number is the wrong length.";
    }*/ }
return error;
}

function checkPostalCode(str){
	var error = "";
	if(str.length=="0")
		{
		error=" Please Enter Postal Code";
		}
	else{
		/*if(isNaN(str))
		{
		error='The Postal Code  contains illegal characters';
		}
		
		else if(!(str.length==10))
			{
				error = "Please Enter valid Postal Code .";
			}	*/
		
		
			str=filterNum(str);
			if(!(str.length==10))
			{
				error = "Please Enter valid Postal Code .";
			}	
	}
	return error;
	}

	
	
function checkMobile (strng) {

var error = "";
if (strng == "") 
{
   error = "You didn't enter a Mobile number.";
}
else
{
	stripped=filterNum(strng);

    if (!(stripped.length == 10)) 
    {
		error = "The mobile number is the wrong length.";
    }
} 
return error;
}	

function filterNum(str) {
         // re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\=|\[|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;
		re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;
          // remove special characters like "$" and "," etc...
          return str.replace(re, "");
     }

// Start javascript function will return false when the string passed contains charcter other then alphabetic.
// It returns true on correct validation that is for charecter only.
function alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if(!( (hh==32) || (hh > 64 && hh<91) || (hh > 96 && hh<123) ))
			 return true;
		}
 return false;
}
// End javascript function will return false when the string passed contains charcter other then alphabetic.
// It returns true on correct validation that is for charecter only.

