// i is an abbreviation for "invalid"
var iEmail = "This field must be a valid email address (like abc@shangri-la.com). Please re-enter it now.";

// Global variable defaultEmptyOK defines default return value
// for many functions when they are passed the empty string.
// By default, they will return defaultEmptyOK.
//
// defaultEmptyOK is false, which means that by default,
// these functions will do "strict" validation.  Function
// isInteger, for example, will only return true if it is
// passed a string containing an integer; if it is passed
// the empty string, it will return false.
//
// You can change this default behavior globally (for all
// functions which use defaultEmptyOK) by changing the value
// of defaultEmptyOK.
//
// Most of these functions have an optional argument emptyOK
// which allows you to override the default behavior for
// the duration of a function call.
//
// This functionality is useful because it is possible to
// say "if the user puts anything in this field, it must
// be an integer (or a phone number, or a string, etc.),
// but it's OK to leave the field empty too."
// This is the case for fields which are optional but which
// must have a certain kind of content if filled in.
var defaultEmptyOK = false;

// whitespace characters
var whitespace = " \t\n\r";


function Check_Brithday(dobday,dobmonth,dobyear){

	if (dobmonth == "01"){ long_month = "January";}
	if (dobmonth == "02"){ long_month = "February";}
	if (dobmonth == "03"){ long_month = "March";}
	if (dobmonth == "04"){ long_month = "April";}
	if (dobmonth == "05"){ long_month = "May";}
	if (dobmonth == "06"){ long_month = "June";}
	if (dobmonth == "07"){ long_month = "July";}
	if (dobmonth == "08"){ long_month = "August";}
	if (dobmonth == "09"){ long_month = "September";}
	if (dobmonth == "10"){ long_month = "October";}
	if (dobmonth == "11"){ long_month = "November";}
	if (dobmonth == "12"){ long_month = "December";}
	birthTime = new Date(long_month + " " + dobday + ", " + dobyear);
	todaysTime = new Date();
	todaysYear = todaysTime.getYear();
	if (todaysYear < 2000) todaysYear += 1900;
	todaysMonth = todaysTime.getMonth();
	todaysDate = todaysTime.getDate();
	todaysHour = todaysTime.getHours();
	todaysMinute = todaysTime.getMinutes();
	todaysSecond = todaysTime.getSeconds();
	birthYear = birthTime.getYear();
	if (birthYear < 2000) birthYear += 1900;
	birthMonth = birthTime.getMonth();
	birthDate = birthTime.getDate();
	birthHour = birthTime.getHours();
	birthMinute = birthTime.getMinutes();
	birthSecond = birthTime.getSeconds();
	var monarr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	// check for leap year
	if (((todaysYear % 4 == 0) && (todaysYear % 100 != 0)) || (todaysYear % 400 == 0)) monarr[1] = "29";
	countMonth = monarr[todaysTime.getMonth()];
	<!-- Doing the subtactions
	if (todaysMinute > birthMinute) {
	diffMinute = todaysMinute - birthMinute;
	calcHour = 0;
	}
	else {
	diffMinute = todaysMinute + 60 - birthMinute;
	calcHour = -1;
	}
	if (todaysHour > birthHour) {
	diffHour = todaysHour - birthHour + calcHour;
	calcDate = 0;
	}
	else {
	diffHour = todaysHour + 24 - birthHour  + calcHour;
	calcDate = -1;
	}
	if (todaysDate > birthDate) {
	diffDate = todaysDate - birthDate + calcDate;
	calcMonth = 0;
	}
	else {
	diffDate = todaysDate + countMonth - birthDate  + calcDate;
	calcMonth = -1;
	}
	if (todaysMonth > birthMonth) {
	diffMonth = todaysMonth - birthMonth + calcMonth;
	calcYear = 0;
	}
	else {
	diffMonth = todaysMonth + 12 - birthMonth + calcMonth;
	calcYear = -1;
	}
	diffYear = todaysYear - birthYear + calcYear + (diffMonth + diffDate/countMonth)/12;
	age = diffYear;
	return age;
}

// Check whether string s is empty.
function isEmpty(s)
{   
	return ( (s==null) || (s.length==0) )
}


// Returns true if string s is empty or
// whitespace characters only.
function isWhitespace (s)
{  
	 var i;

    	// Is s empty?
    	if( isEmpty(s) ) {
    		return true;
    	}

    	// Search through string's characters one by one
    	// until we find a non-whitespace character.
    	// When we do, return false; if we don't, return true.
	for( i=0; i<s.length; i++)
    	{
        	// Check that current character isn't whitespace.
        	var c = s.charAt(i);

        	if( whitespace.indexOf(c)==-1 ) {
        		return false;
        	}
    	}

    	// All characters are whitespace.
    	return true;
}


// isEmail (STRING s [, BOOLEAN emptyOK])
//
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function isEmail (s)
{
	if( isEmpty(s) ) {
       		if( isEmail.arguments.length==1 ) {
       			return defaultEmptyOK;
       		}
       		else {
       			return ( isEmail.arguments[1]==true );
       		}
       	}

    		// is s whitespace?
    		if( isWhitespace(s) ) {
    			return false;
    		}

    		// there must be >= 1 character before @, so we
    		// start looking at character position 1
   		// (i.e. second character)
    		var i = 1;
    		var sLength = s.length;

    		// look for @
    		while( (i<sLength) && (s.charAt(i)!= "@") ) {
    			i++;
    		}

    		if( (i>=sLength) || (s.charAt(i)!="@") ) {
    			return false;
    		} else {
    			i += 2;
    		}

    		// look for .
    		while( (i<sLength) && (s.charAt(i)!= ".") ) {
    			i++;
    		}

    		// there must be at least one character after the .
    		if( (i>=sLength-1) || (s.charAt(i)!= ".") ) {
    			return false;
    		}
    		else {
    			return true;
    		}
}

function checkRadioButton (radio)
{   
	for( var i=0; i<radio.length; i++) {
		if( radio[i].checked ) { 
    			return true;
		}
    	}
    	return false;
}

// checkEmail (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid Email.
//
// By default, returns defaultEmptyOK if s is empty.
// There is an optional second argument called emptyOK.
// emptyOK is used to override for a single function call
//      the default behavior which is specified globally by
//      defaultEmptyOK.
// If emptyOK is false (or any value other than true),
//      the function will return false if s is empty.
// If emptyOK is true, the function will return true if s is empty.
function checkEmpty (theField, emptyOK)
{   
		if( checkEmpty.arguments.length==1 ) {
			emptyOK = defaultEmptyOK;
		}
    	
    	if( (emptyOK==false) && (isEmpty(theField.value)) ) {
    		return false;
    	}
    	
    	return true;
}

// checkEmail (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid Email.
//
// For explanation of optional argument emptyOK,
// see comments of function checkEmpty.
function checkEmail (theField, emptyOK)
{   
		if( checkEmail.arguments.length==1 ) {
			emptyOK = defaultEmptyOK;
		}
    	
    	if( (emptyOK==false) && (isEmpty(theField.value)) ) {
    		return false;
    	}
    	else if( !isEmail(theField.value, false) ) {
			theField.focus();
    		return false;
       	}
       	
       	return true;
}

// Returns true if character c is a digit
// (0 .. 9).
function isDigit (c)
{
	return ( (c>="0") && (c<="9") )
}

// isInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if all characters in string s are numbers.
//
// Accepts non-signed integers only. Does not accept floating
// point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.

// EXAMPLE FUNCTION CALL:     RESULT:
// isInteger ("5")            true
// isInteger ("-5")           false
function isInteger (s)
{
	var i;

    	// Search through string's characters one by one
    	// until we find a non-numeric character.
    	// When we do, return false; if we don't, return true.
    	for( i=0; i<s.length; i++)
    	{
        	// Check that current character is number.
        	var c = s.charAt(i);
        	if( !isDigit(c) ) {
        		return false;
        	}
    	}

    	// All characters are numbers.
    	return true;
}

// isSignedInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if all characters are numbers;
// first character is allowed to be + or - as well.
//
// Does not accept floating point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// EXAMPLE FUNCTION CALL:          RESULT:
// isSignedInteger ("5")           true
// isSignedInteger ("-5")          true
// isSignedInteger ("+5")          true
function isSignedInteger (s)
{   
	var startPos = 0;

        // skip leading + or -
        if ( (s.charAt(0)=="-") || (s.charAt(0)=="+") ) {
           	startPos = 1;
        }
	return ( isInteger(s.substring(startPos, s.length)) )
}

// isNonnegativeInteger (STRING s)
//
// Returns true if string s is an integer >= 0.
function isNonnegativeInteger(theField)
{
	if( isEmpty(theField.value) ) {
		return true;
	}
    	// The next line is a bit byzantine.  What it means is:
    	// a) s must be a signed integer, AND
    	// b) one of the following must be true:
    	//    i)  s is empty and we are supposed to return true for
    	//        empty strings
    	//    ii) this is a number >= 0

    	return ( isSignedInteger(theField.value) && (parseInt(theField.value)>=0) )
}

// checkNonnegativeInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if string s is an integer >= 0.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function checkNonnegativeInteger(theField, emptyOK)
{
		if( checkNonnegativeInteger.arguments.length==1 ) {
			emptyOK = defaultEmptyOK;
		}
    	
    	if( (emptyOK==false) && (isEmpty(theField.value)) ) {
    		return false;
    	}
    	else if( (emptyOK==true) && isEmpty(theField.value) ) {
    		return true;
    	}
    	else {
    		return isNonnegativeInteger(theField)
       	}
       	
       	return true;
}

// Returns true if character c is an English letter
// (A .. Z, a..z).
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.
function isLetter (c) {
	return (( (c>="a") && (c<="z") )||( (c>="A") && (c<="Z") ))
}

// isAlphabetic (STRING s [, BOOLEAN emptyOK])
//
// Returns true if string s is English letters
// (A .. Z, a..z) only.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.
function isAlphabetic (theField, emptyOK) {
    	// Search through string's characters one by one
    	// until we find a non-alphabetic character.
    	// When we do, return false; if we don't, return true.
    	for(i=0; i<theField.length; i++)
    	{
        	// Check that current character is letter.
        	var c = theField.charAt(i);

        	if( !isLetter(c) ) {
        		return false;
        	}
    	}

    	// All characters are letters.
    	return true;
}

// checkAlphabetic (STRING theField [, BOOLEAN emptyOK])
//
// Returns true if string theField.value is English letters
// (A .. Z, a..z) only.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.
function checkAlphabetic (theField, emptyOK)
{
	if( checkAlphabetic.arguments.length==1 ) {
		emptyOK = defaultEmptyOK;
	}
    	
    	if( (emptyOK==false) && (isEmpty(theField.value)) ) {
    		return false;
    	}
    	else if( (emptyOK==true) && isEmpty(theField.value) ) {
    		return true;
    	}
    	else {
    		return isAlphabetic(theField.value)
       	}
}


// Month 
function getMonth(){
	var month = ""
	for (i=0; i<document.forms[0].DOB_MONTH.length; i++) {		
		if (document.forms[0].DOB_MONTH[i].selected) {
			month = document.forms[0].DOB_MONTH[i].value
		}
	}
	return month
}

// Day 
function getDay(){
	var day = ""
	for (i=0; i<document.forms[0].DOB_DAY.length; i++){		
		if (document.forms[0].DOB_DAY[i].selected){
			day = document.forms[0].DOB_DAY[i].value
		}
	}
	return day
}

// Year 
function getYear(){
	return document.forms[0].DOB_YEAR.value
}

function y2k(number) {
	return (number < 1000) ? number + 1900 : number;
}

function isDate (day,month,year) {
     	var today = new Date();
     	year = ((!year) ? y2k(today.getYear()):year);
     	month = ((!month) ? today.getMonth():month-1);
     	if (!day) {
     		return false
     	}
     	
     	var test = new Date(year,month,day);
     	if (( y2k(test.getYear())==year )&&( month==test.getMonth() )&&( day==test.getDate() )) {
        	return true;
        }
     	else {
         	return false;
        }
}

function isChar(str){
	for(i=0; i<str.length; i++){
		cCode = str.charCodeAt(i);
		cChar = str.charAt(i);
		//alert("cChar= " + cChar + "cCode= " + cCode);
		if (( cCode>=97 && cCode<=122 )||( cCode>=65 && cCode<=90 )||( cCode==32 )) {
			//alert("cChar= " + cChar + "cCode= " + cCode);
			return true;
		}
	}
}

function Check_Brithday(dobday,dobmonth,dobyear) {
	
	todaysTime = new Date();
	todaysYear = todaysTime.getYear();
	if ( todaysYear<2000 ) {
		todaysYear += 1900;
	}
	todaysMonth = todaysTime.getMonth();
	todaysDate = todaysTime.getDate();
	todaysHour = todaysTime.getHours();
	todaysMinute = todaysTime.getMinutes();
	todaysSecond = todaysTime.getSeconds();
	
	
	if (dobmonth=="01") {
		long_month = "January";
	}
	if (dobmonth=="02") {
		long_month = "February";
	}
	if (dobmonth=="03") {
		long_month = "March";
	}
	if (dobmonth=="04") {
		long_month = "April";
	}
	if (dobmonth=="05") {
		long_month = "May";
	}
	if (dobmonth=="06") {
		long_month = "June";
	}
	if (dobmonth=="07") {
		long_month = "July";
	}
	if (dobmonth=="08") {
		long_month = "August";
	}
	if (dobmonth=="09") {
		long_month = "September";
	}
	if (dobmonth=="10") {
		long_month = "October";
	}
	if (dobmonth=="11") {
		long_month = "November";
	}
	if (dobmonth=="12") {
		long_month = "December";
	}
	birthTime = new Date(long_month + " " + dobday + ", " + dobyear);
	birthYear = birthTime.getYear();
	if ( birthYear<2000 ) {
		birthYear += 1900;
	}
	birthMonth = birthTime.getMonth();
	birthDate = birthTime.getDate();
	birthHour = birthTime.getHours();
	birthMinute = birthTime.getMinutes();
	birthSecond = birthTime.getSeconds();
	
	
	// check for leap year
	var monarr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	if (( (todaysYear%4==0) && (todaysYear%100!=0) )||( todaysYear%400==0 )) {
		monarr[1] = "29";
	}
	countMonth = monarr[todaysTime.getMonth()];
	//Doing the subtactions
	if ( todaysMinute>birthMinute ) {
		diffMinute = todaysMinute - birthMinute;
		calcHour = 0;
	} else {
		diffMinute = todaysMinute + 60 - birthMinute;
		calcHour = -1;
	}
	
	if ( todaysHour>birthHour) {
		diffHour = todaysHour - birthHour + calcHour;
		calcDate = 0;
	} else {
		diffHour = todaysHour + 24 - birthHour  + calcHour;
		calcDate = -1;
	}
	
	if ( todaysDate>birthDate ) {
		diffDate = todaysDate - birthDate + calcDate;
		calcMonth = 0;
	} else {
		diffDate = todaysDate + countMonth - birthDate  + calcDate;
		calcMonth = -1;
	}
	
	if ( todaysMonth>birthMonth ) {
		diffMonth = todaysMonth - birthMonth + calcMonth;
		calcYear = 0;
	}
	else {
		diffMonth = todaysMonth + 12 - birthMonth + calcMonth;
		calcYear = -1;
	}
	
	diffYear = todaysYear - birthYear + calcYear + (diffMonth + diffDate/countMonth)/12;
	age = diffYear;
	
	return age;
}

function isDigit(c){ 
	return ( (c>="0") && (c<="9") )
}


function ascii(c){
	for(i=0; i<c.length; i++){
		cCode = c.charCodeAt(i);
	}	
	return cCode	
}

function isSpecial(c){ 
	return ( (c==",")||(c==".")||(c=="~")||(c=="'")||(c=="`")||(c==":")||(c==";")||(c=="!")||(c=="?")||(c=="&")||(c=="@")||(c=="#")||(c=="$")||(c=="%")||(c=="^")||(c=="*")||(c=="(")||(c==")")||(c=="_")||(c=="-")||(c=="+")||(c=="=")||(c=="{")||(c=="}")||(c=="[")||(c=="]")||(c=="|")||(c=="<")||(c==">")||(c=="/")||(c=="\\")||(ascii(c)==34) )
}

function isAlphanumeric(s){  
	var i;
    	for (i=0; i<s.length; i++)
    	{   
        	// Check that current character is number or letter.
        	var c = s.charAt(i);
        	if ( !(isChar(c)||isDigit(c)||isSpecial(c)) ) {
        		return false;
        	}
    	}

    	// All characters are numbers or letters.
    	return true;
}