<!--
function checkDigits (checkStr)
{
  var checkOK = "0123456789";
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j)){
        break;
        }
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  return allValid;

}

//zip US
function checkZipUS (strng) {
    var error = "";

    if (!(strng.length == 5 && checkDigits(strng)) ) {
	error = "US zip needs to be exactly 5 digits.\n";
        return error;
    }

return error;
}


//zip Canada
function checkZipCanada (strng) {
    var error = "";

    if (!(strng.length == 6) ) {
	error = "Canadian Post Code needs to be exactly 6 characters.\n";
        return error;
    }

    if (strng.indexOf(" ") > -1) {
	error = "No space allowed in the zip code field.\n";
        return error;
    }

    return error;
}


// email

//function checkEmail (strng) {
//var error="";
//if (strng == "") {
//   error = "You didn't enter an email address.\n";
//}
//
 //   var emailFilter=/^.+@.+\..{2,3}$/;
//    if (!(emailFilter.test(strng))) {
//       error = "Please enter a valid email address. Must be in the format of xxxx@xxx.xxx\n";
//   }
//    else {
//test email for illegal characters
//       var illegalChars= /[\+\ \(\)\<\>\,\;\:\\\"\[\]]/;
//         if (strng.match(illegalChars)) {
//          error = "The email address contains illegal characters.\n";
//       }
//    }
//return error;
//}

function checkEmail (strng) {
	if ( !isEmail(strng) ) {
		return "Please enter a valid email address";
	}  else {
		return "";
	}
}

function isEmail (objInputValue) {
        var email = objInputValue;

        if (email == "") return false;
        if (email.indexOf('@') == -1) return false; // no @ symbol (bob)
        if (email.indexOf('@') != email.lastIndexOf('@')) return false; // more than 1 @ symbol (bob@aol@aol)
        if (email.indexOf('.') == -1) return false; // no periods (bob@aol)
        if (email.lastIndexOf('.') < email.indexOf('@')) return false; // no periods after the @ symbol (aol.com@bob)
        if (email.indexOf('@') == 0) return false; // nothing before the @ symbol (@aol.com)
        if (email.indexOf('@') == email.length - 1) return false; // nothing after the @ symbol (bob@)
        if (email.indexOf('@.') != -1 || email.indexOf('.@') != -1) return false; // no characters between @ and period (bob@. or bob.@)
        if (email.lastIndexOf('.') == email.length - 1) return false; // nothing after the last period (bob@aol.)
        if (email.indexOf('..') != -1) return false; // no double periods (bob@aol..com)
        if (email.lastIndexOf('.') != email.length - 3 && email.lastIndexOf('.') != email.length - 4 && email.lastIndexOf('.') != email.length - 5) return false; // suffix 2,3 or 4 characters max
	
	// NEW 5/18/2005
	// make sure it ends with a acceptable character
	{
	var current = email.charAt(email.length - 1);
	var acceptableChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
	if (acceptableChars.indexOf(current) == -1) return false;
	}
	
        var username = email.substring(0, email.indexOf('@'));
        var domain = email.substring(email.indexOf('@') + 1, email.length);

        //check username for bad characters
        for (i = 0; i < username.length; i++) {
                var current = username.charAt(i);
                var acceptableChars = '!"#$%&\'()*+-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz';
                if (acceptableChars.indexOf(current) == -1) return false;
        }

        //check domain for bad characters
        for (j = 0; j < domain.length; j++) {
                var current = domain.charAt(j);
                var acceptableChars = '.-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
                if (acceptableChars.indexOf(current) == -1) return false;
                
        }
        
        

        return true; // if we get here, all's fine...
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a phone number.\n";
}

    var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (!(checkDigits(stripped))) {
       error = "The phone number contains illegal characters.\n";
       return error;
    }


    if (stripped.length < 10) {
	error = "The phone number is the wrong length. Make sure you included an area code.\n";
        return error;
    }
return error;
}

function checkPhoneUS (strng) {
var error = "";


    error = checkAreaCodeUS(strng);

    var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters

    if (!(stripped.length == 10)) {
	error = "You phone number needs to be exactly 10 digits.\n";
        return error;
    }

return error;
}

function checkPhoneNA (strng) {
var error = "";


    var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters

    if (!(stripped.length == 10)) {
	error = "You phone number needs to be exactly 10 digits.\n";
        return error;
    }
	
   error = checkAreaCodeNA(strng);
  
return error;
}


// last updated 10-7-04 ys data source http://www.mmiworld.com/codelist.htm
// Area code of US phone number - strip out delimiters and check for 3 digits

function checkAreaCodeUS (strng) {

var codesexist = "201,202,203,205,206,207,208,209,210,212,213,214,215,216,217,218,219,224,225,228,229,231,234,239,240,242,246,248,251,252,253,254,256,260,262,264,267,268,269,270,276,281,283,284,";
codesexist += "301,302,303,304,305,307,308,309,310,312,313,314,315,316,317,318,319,320,321,323,325,330,334,336,337,339,340,345,347,351,352,360,361,380,385,386,";
codesexist += "401,402,404,405,406,407,408,409,410,412,413,414,415,417,419,423,425,430,432,434,435,440,441,443,445,469,470,473,475,478,479,480,484,";
codesexist += "501,502,503,504,505,507,508,509,510,512,513,515,516,517,518,520,530,540,541,551,557,559,561,562,563,564,567,570,571,573,574,580,585,586,";
codesexist += "601,602,603,605,606,607,608,609,610,612,614,615,616,617,618,619,620,623,626,630,631,636,641,646,649,650,651,660,661,662,664,670,671,678,682,684,689,";
codesexist += "701,702,703,704,706,707,708,712,713,714,715,716,717,718,719,720,724,727,731,732,734,740,754,757,758,760,763,765,767,770,772,773,774,775,781,784,785,786,787,";
codesexist += "800,801,802,803,804,805,806,808,810,812,813,814,815,816,817,818,822,828,830,831,832,833,835,843,844,845,847,848,850,855,856,857,858,859,860,862,863,864,865,866,868,869,870,876,877,878,888,";
codesexist += "901,903,904,906,907,908,909,910,912,913,914,915,916,917,918,919,920,925,928,931,936,937,939,940,941,947,949,951,952,954,956,959,970,971,972,973,978,979,980,984,985,989";

var areacodes = codesexist.split(",");
    var error = "";
    if (strng == "")
    {
       error = "You didn't enter a phone number.\n";
       return error;
    }
    var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (!(checkDigits(stripped))) {
       error = "The phone number contains illegal characters.\n";
       return error;
    }

    var leaddigit = stripped.slice(0,1);

    if ((leaddigit == "0" || leaddigit == "1" )) {
	error = "Make sure you start with an area code for the phone.  Do not start with '0' or '1'.\n";
        return error;
    }

    var areacode = stripped.slice(0,3);
    for (i = 0;  i < areacodes.length;  i++)
    {
        if (areacode == areacodes[i])
        {
          break;
        }
    };
    if (i == areacodes.length){
	error = "The first 3 digits do not match a valid US area code.\n";
        return error;
    }
	
    //BK ADDED TEST TO FORTH DIGIT
    var digit4 = stripped.slice(3,4);
        if (digit4 == "0"){
           	error = "Make sure the prefix of your phone number does not start with '0'.";	
            	return error;
           }
   
    var nxxbad = "555,000";
    var nxxcodes = nxxbad.split(",");
    var nxxcode = stripped.slice(3,6);
    for (i = 0;  i < nxxcodes.length;  i++)
    {
        if (nxxcode == nxxcodes[i])
        {
          break;
        }
    }
    if (i < nxxcodes.length){
	error = "The 3 digits after area code in your phone number do not represent a valid exchange number.\n";
        return error;
    }


    return error;
}


// Area code of North America phone number - strip out delimiters and check for 3 digits

function checkAreaCodeNA (strng) {

var codesexist = "201,202,203,204,205,206,207,208,209,210,212,213,214,215,216,217,218,219,224,225,226,227,228,229,231,234,239,240,242,246,248,250,251,252,253,254,256,260,262,264,267,268,269,270,276,281,283,284,289,";
codesexist += "301,302,303,304,305,306,307,308,309,310,312,313,314,315,316,317,318,319,320,321,323,325,330,331,334,336,337,339,340,345,347,351,352,360,361,385,386,";
codesexist += "401,402,403,404,405,406,407,408,409,410,412,413,414,415,416,417,418,419,423,424,425,430,432,434,435,438,440,441,443,445,450,464,469,470,473,475,478,479,480,484,";
codesexist += "501,502,503,504,505,506,507,508,509,510,512,513,514,515,516,517,518,519,520,530,540,541,551,557,559,561,562,563,564,567,570,571,573,574,580,585,586,";
codesexist += "601,602,603,604,605,606,607,608,609,610,612,613,614,615,616,617,618,619,620,623,626,630,631,636,641,646,647,649,650,651,660,661,662,664,667,670,671,678,682,684,";
codesexist += "701,702,703,704,705,706,707,708,709,712,713,714,715,716,717,718,719,720,724,727,731,732,734,737,740,754,757,758,760,763,765,767,770,772,773,774,775,778,780,781,784,785,786,787,";
codesexist += "800,801,802,803,804,805,806,807,808,809,810,812,813,814,815,816,817,818,819,822,828,830,831,832,833,835,843,844,845,847,848,850,855,856,857,858,859,860,862,863,864,865,866,867,868,869,870,872,876,877,878,888,";
codesexist += "901,902,903,904,905,906,907,908,909,910,912,913,914,915,916,917,918,919,920,925,928,931,936,937,939,940,941,947,949,951,952,954,956,959,970,971,972,973,975,978,979,980,984,985,989";

var areacodes = codesexist.split(",");
    var error = "";
    if (strng == "")
    {
       error = "You didn't enter a phone number.\n";
       return error;
    }
    var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (!(checkDigits(stripped))) {
       error = "The phone number contains illegal characters.\n";
       return error;
    }

    var leaddigit = stripped.slice(0,1);

    if ((leaddigit == "0" || leaddigit == "1" )) {
	error = "Make sure you start with an area code for the phone.  Do not start with '0' or '1'.\n";
        return error;
    }


    var areacode = stripped.slice(0,3);
    for (i = 0;  i < areacodes.length;  i++)
    {
        if (areacode == areacodes[i])
        {
          break;
        }
    }
    if (i == areacodes.length){
	error = "The first 3 digits do not match a valid area code.\n";
        return error;
    } 
     //BK ADDED TEST TO FORTH DIGIT
        var digit4 = stripped.slice(3,4);
            if (digit4 == "0"){
               	error = "Make sure the prefix of your phone number does not start with '0'.";	
                	return error;
           }
    
    var nxxbad = "555,000";
    var nxxcodes = nxxbad.split(",");
    var nxxcode = stripped.slice(3,6);
    for (i = 0;  i < nxxcodes.length;  i++)
    {
        if (nxxcode == nxxcodes[i])
        {
          break;
        }
    }
    if (i < nxxcodes.length){
	error = "The 3 digits after area code in your phone number do not represent a valid exchange number.\n";
        return error;
    }


    return error;
}

function isBadPhoneNumber(thePhoneNumber){

	if ( thePhoneNumber.substr(3,7)=='0000000' ||
				thePhoneNumber.substr(3,7)=='1111111' ||
				thePhoneNumber.substr(3,7)=='2222222' ||
				thePhoneNumber.substr(3,7)=='3333333' ||
				thePhoneNumber.substr(3,7)=='4444444' ||
				thePhoneNumber.substr(3,7)=='5555555' ||
				thePhoneNumber.substr(3,7)=='6666666' ||
				thePhoneNumber.substr(3,7)=='7777777' ||
				thePhoneNumber.substr(3,7)=='8888888' ||
				thePhoneNumber.substr(3,7)=='9999999' ||
				thePhoneNumber=='1234567890' ||
				thePhoneNumber=='9876543210' ||
				thePhoneNumber.substr(0,4)=='1010') {

					return true;
	 }

	 return false;
}  // isBadPhoneNumber

function isShortDate(dateStr) {
	// ******************************************************************
	// This function accepts a string variable and verifies if it is a
	// proper date or not. It validates format matching either
	// mm/dd/yy. Then it checks to make sure the month
	// has the proper number of days, based on which month it is.

	// The function returns true if a valid date, false if not.
	// ******************************************************************

		var datePat = /^(\d{2})(\/)(\d{2})(\/)(\d{2})$/;
		var matchArray = dateStr.match(datePat); // is the format ok?

		if (matchArray == null) {
		alert("Please enter a date as mm/dd/yy.");
		return false;
		}

		month = matchArray[1]; // p@rse date into variables
		day = matchArray[3];
		year = matchArray[5];

		if (month < 1 || month > 12) { // check month range
		alert("Month must be between 1 and 12.");
		return false;
		}

		if (day < 1 || day > 31) {
		alert("Day must be between 1 and 31.");
		return false;
		}

		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Month "+month+" doesn`t have 31 days!")
		return false;
		}

		if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
		alert("February " + year + " doesn`t have " + day + " days!");
		return false;
		}
	}
	return true; // date is valid
}

function FourDigitsYear(number) {
      return (number < 1000) ? number + 1900 : number;
}

function isDateOfBirth(dateStr) {
	// ******************************************************************
	// This function accepts a string variable and verifies if it is a
	// proper date or not. It validates format matching either
	// mm/dd/yyyy. Then it checks to make sure the month
	// has the proper number of days, based on which month it is.

	// The function returns true if a valid date, false if not.
	// ******************************************************************
		var now = new Date();
		var datePat = /^(\d{2})(\/)(\d{2})(\/)(\d{4})$/;
		var matchArray = dateStr.match(datePat); // is the format ok?

		if (matchArray == null) {
		alert("Please enter a date as mm/dd/yyyy.");
		return false;
		}

		month = matchArray[1]; // p@rse date into variables
		day = matchArray[3];
		year = matchArray[5];
		yearnow = FourDigitsYear(now.getYear());

		if (year > yearnow || (yearnow - year) > 100 ) {
		alert("Please enter a valid year.")
		return false;
		}

		if (month < 1 || month > 12) { // check month range
		alert("Month must be between 1 and 12.");
		return false;
		}

		if (day < 1 || day > 31) {
		alert("Day must be between 1 and 31.");
		return false;
		}

		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Month "+month+" doesn`t have 31 days!")
		return false;
		}

		if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
		alert("February " + year + " doesn`t have " + day + " days!");
		return false;
		}

	}
	return true; // date is valid
}
//-->
