 //The Auto Tab Function

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
	return true;
}

function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
	if(arr[index] == ele)
		found = true;
	else
		index++;
	return found;
}
function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
	if (input.form[i] == input)index = i;
	else i++;
	return index;
}


//End of The Auto Tab Function


// New Auto Tab Function added by Gopal on 1/8/04

function isNumeric()
{
	if (navigator.appName.indexOf("Netscape")<0)
	{
		get=event.keyCode;

		if((get>47&&get<58)||(get==8)||(get==9)) 
		{
			return true;
		}
		else
		{
			event.returnValue=false;
		}
	}
}

function AutoTab( hItem, maxLength, linkItem )
{
	
	isNumeric();
	if (navigator.appVersion.indexOf('Mac') != -1)
	{
		return;
	}
	else
	{
		var vKeyCode,oItem;
		oItem = eval(linkItem);
	
		vKeyCode = window.event.keyCode
		if(vKeyCode==9 && window.event.shiftKey){ return; }
		switch(window.event.keyCode)
		{
			case 37 : return;
			case 39 : return;
			case 16 : return;
			case 46 : return;
		}
		if (window.event.keyCode != 9 )
		{
			if( typeof(oItem) == "object" )
			{
					
					if(bAutotab && (String(oItem.value).length ==0) && (String(hItem.value).length == maxLength) && (window.event.keyCode != 8))
					{
						oItem.focus();
					}
			}
		}
	}
	bAutotab = true;
}

bAutotab = true;
function stopAutoTab()
{
	bAutotab = false;
}

// End of the New Auto Tab Function






//Main Function for validating the lengths.
function validate_length(vlength, maxlength, fieldname)
{
   	err_statlength = false;
    errheaderlength = " ";
	if (vlength <= maxlength)
		donothing = 1
	else
	{
		errmsglength = "The " + fieldname + " cannot exceed " + maxlength + " digits in length.\n"
        err_statlength = true
    }

	if (err_statlength == true)
		errmsglength = errheader + errmsglength
	else
		errmsglength = "" 
	return errmsglength

}



//vstring is the string and vtype is the validation type, fieldname is the name of the field.
function validate_form(vstring, vtype, fieldname)
{
	err_stat = false;
    errheader = " ";
	smonth = ""
	sday = ""
	syear = ""
    
    //for userid checks
    if (vtype == "Password") 
	{
		
		vstring = Trim(vstring)
		status = isPassword(vstring)
		if (status == "false")
		{
			errmsg = "The " + fieldname + " must be alphanumeric and can have a maximum number of three repeating characters. Ex: sbg12345, vvv52345sd.\n"
            err_stat = true
		}
		else errmsg = ""
	}
	//    
    
    //for Alphanumeric checks
    if (vtype == "Alphanumeric") 
	{
		
		vstring = Trim(vstring)
		status = isAlphanumeric(vstring)
		if (status == "false")
		{
			errmsg = "The " + fieldname + " should be alphanumeric. Ex: 123ABC, ABC, 123.\n"
            err_stat = true
		}
		else errmsg = ""
	}
	//
	    if (vtype == "AlphanumericEmpty") 
	{
		
		vstring = Trim(vstring);
		if(isEmpty(vstring))
		{
			err_stat=false;
			errmsg="";
		}
		else
		{
			status = isAlphanumeric(vstring);
			if (status == "false")
			{
				errmsg = "The " + fieldname + " should be alphanumeric. Ex: 123ABC, ABC, 123.\n";
				err_stat = true;
			}
			else errmsg = "";
		}
	}

	//Listing Nmae
	if (vtype == "CompanyName") 
	{
		
		vstring = Trim(vstring)
		status = isCompanyName(vstring)
		if (status == "false")
		{
			errmsg = "The " + fieldname + " should be alphanumeric. Ex: 123ABC, ABC, 123, 123-45.\n"
            err_stat = true
		}
		else errmsg = ""
	}
	
	//for Street Number checks
    if (vtype == "StreetNumber") 
	{
		
		vstring = Trim(vstring)
		status = isStreetNumber(vstring)
		if (status == "false")
		{
			errmsg = "The " + fieldname + " should be alphanumeric. Ex: 123ABC, ABC, 123, 123-45.\n"
            err_stat = true
		}
		else errmsg = ""
	}
	//
	
	//for Alphabetic checks
	if (vtype == "Alphabetic") 
	{
		vstring = Trim(vstring)
		vstring = remove_delimiter(vstring, "'")
		status = isAlphabetic(vstring)
		if(vstring.length==0)
		{
			errmsg = "The " + fieldname + " should not be empty.\n"
			err_stat = true
		}
		else 
		{
			if (status == "false")
			{
				errmsg = "The " + fieldname + " should not contain numeric value. Ex: ABC.\n";
				err_stat = true;
			}
			else errmsg = "";
		}
	}
	
	
	
	//checks if Empty, if not contents must be Alphabetic
	if (vtype == "AlphabeticEmpty") 
	{
		vstring = Trim(vstring)
		if(isEmpty(vstring))
		{
			err_stat=false;
			errmsg="";
		}
		else
		{
			status = isAlphabetic2(vstring);
			if (status == "false")
			{
				errmsg = "The " + fieldname + " should be alphabetic. Ex: ABC.\n";
				err_stat = true;
			}
			else errmsg = "";
		}
	}

	
	//for Alphabetic checks with comma e.g jay'o
	if (vtype == "Alphabetic2") 
	{
		vstring = Trim(vstring)
		status = isAlphabetic2(vstring)
		if (status == "false")
		{
			errmsg = "The " + fieldname + " should be alphabetic. Ex: ABC.\n"
            err_stat = true
		}
		else errmsg = ""
	}
	//
	//for numeric checks
	if (vtype == "Number") 
	{
		vstring = Trim(vstring)
		status = isInteger(vstring)
		if (status == "false")
		{
			errmsg = "The " + fieldname + " should be an integer. Ex.123 \n"
            err_stat = true
		}
		else errmsg = ""
	}
	//
	
	//for empty checks or null checks
	if (vtype == "Empty") 
	{
		vstring = Trim(vstring)
		status = isEmpty(vstring)
		if (status == "true")
		{
			errmsg = "The " + fieldname + " should not be empty. \n"
            err_stat = true
		}
		else errmsg = ""
	}
	//
	
	//for email check
	if (vtype == "Email") 
	{
		vstring = Trim(vstring)
		status = isEmail(vstring)
		if (status == "false")
		{
			errmsg = "The " + fieldname + " must be a valid email address (Ex. yourname@yourbusiness.com).\n";
            err_stat = true
		}
		else errmsg = ""
	}	
	//
	
	//for zip code validation
	if (vtype == "Zip") 
	{
		vstring = Trim(vstring)
	 	status = isZIPCode(vstring)
		if (status == "false")
		{
			errmsg = "The " + fieldname + " must be a 5 or 9 digit U.S. ZIP Code. Ex: 94043, 11111-2222.\n"
            err_stat = true
		}
		else errmsg = ""
	}
	//
	
	//for credit card validation
	if (vtype == "CreditCard") 
	{
		vstring = Trim(vstring)
		status = isCreditCard(vstring)
		if (status == "false")
		{
			errmsg = "The " + fieldname + " must be a 16 digit valid credit card number\n"
            err_stat = true
		}
		else errmsg = ""
	}
	//
	//Introduced By Sasanka for 18836
	if (vtype == "CreditCardSecurity") 
	{
		vstring = Trim(vstring)
		status = isCreditCardSecurity(vstring)
		if (status == "false")
		{
			errmsg = "The " + fieldname + " must be a 3 digit valid credit card Security number\n"
            err_stat = true
		}
		else errmsg = ""
	}

	//for credit card validation American Express
	if (vtype == "CreditCardAmex") 
	{
		vstring = Trim(vstring)
		status = isCreditCardAmex(vstring)
		if (status == "false")
		{
			errmsg = "The " + fieldname + " must be a 15 digit valid credit card number\n"
            err_stat = true
		}
		else errmsg = ""
	}
	//
	
	//for state check
	if (vtype == "State")
	{
		if (vstring.selectedIndex < 1) 
			status = "false"
		else
			status = "true"
			
		if (status == "false")
		{
			errmsg = "The " + fieldname + " should not be empty. \n"
            err_stat = true
		}
		else errmsg = ""
	}
	//
	
	//for select box
	if (vtype == "Select")
	{
		if (vstring.selectedIndex < 1) 
			status = "false"
		else
			status = "true"
			
		if (status == "false")
		{
			errmsg = "The " + fieldname + " must be selected. \n"
            err_stat = true
		}
		else errmsg = ""
	}
	//
	
	
	//for US telephone number check
	if (vtype == "Telephone")
	{
		status = isUSPhoneNumber(vstring)
		if (status == "false")
		{	//errmsg ="Please fill in your phone number."
			errmsg = "The " + fieldname + " must be a valid 10 digit U.S. Phone Number. Ex: 972 777 7777.\n"
            err_stat = true
		}
		else errmsg = ""
	}
	//	
	
	//for US SSN check
	if (vtype == "SSN")
	{
		status = isSSN(vstring)
		//alert(status);
		if (status == "false")
		{
			errmsg = "The " + fieldname + " must be a valid 9 digit U.S. Social Security Number. Ex: 123 456 789.\n"
            //err_stat = true
		}
		else errmsg = ""
	}
	//
	
	//for date check
	err_date = false
	//for day check
	if (vtype == "Day")
	{
		vstring = Trim(vstring)
        sday = vstring
		status = isDay(sday)
		if (status == "false")
		{
			errmsg = "The " + fieldname + " must be a valid Day. Ex: 1-31.\n"
            err_stat = true
            err_date = true
		}
		else errmsg = ""
	}
	//
	
	//for month check
	if (vtype == "Month")
	{
		vstring = Trim(vstring)
		smonth = vstring
		status = isMonth(smonth)
		if (status == "false")
		{
			errmsg = "The " + fieldname + " must be a valid Month. Ex: 1-12.\n"
            err_stat = true
            err_date = true
		}
		else errmsg = ""
	}
	//
	
	//for year check
	if (vtype == "Year")
	{
		vstring = Trim(vstring)
		status = isYear(vstring)
        syear = vstring
		if (status == "false")
		{
			errmsg = "The " + fieldname + " must be a valid year. Ex: 2001.\n"
            err_stat = true
            err_date = true
		}
		else errmsg = ""
	}
	//

	//finally date check
	if (vtype == "Date")
	{	
		vstring = Trim(vstring)
		splitDate(vstring)
		if (syear == "" || smonth == "" || sday == "")
			donothing = 1
		else
		{
			 status = isDate(syear, smonth, sday)
			if (status == "false")
			{
				errmsg = "The " + fieldname + " must be a valid date. Ex: 02-28-2000 not 02-31-200.\n"
			    err_stat = true
			}
			else errmsg = ""
		}
	}
	
	
	
	//end of date check
	
	//isRadio
	//check Radio button
	if (vtype == "Radio")
	{
		status = isRadio(vstring)
		if (status == "false")
		{
			errmsg = "One radio button must be selected in " + fieldname + " .\n"
            err_stat = true
		}
		else errmsg = ""
	}
	
	
	//end isRadio

	if (err_stat == true)
		errmsg = errheader + errmsg
	else
		errmsg = "" 
	return errmsg
}

//End of the main function for validation.

//global variables

function makeArray(n) {
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}



var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;



var whitespace = " \t\n\r";

// U.S. phone numbers have 10 digits.
// They are formatted as 123 456 7890 or (123) 456-7890.
var digitsInUSPhoneNumber = 10;

// U.S. Social Security Numbers have 9 digits.
// They are formatted as 123-45-6789.
var digitsInSocialSecurityNumber = 9;

// Valid number of zip code digits
var digitsInZIPCode1 = 5
var digitsInZIPCode2 = 9
var digitsInCreditCardAmex = 15
var digitsInCreditCard = 16
//Introduced By Sasanka for CreditCard Security for 18836
var CardSecurity = 3

// Valid U.S. Postal Codes for states, territories, armed forces, etc.
var USStateCodeDelimiter = "|";
var USStateCodes = "AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY|AE|AA|AE|AE|AP"


// isPassword returns true if password is a valid password or returns false.
// The password must be alphanumeric and it should not have more than 3 repeating characters.

function isPassword (s)
{   
	if (isEmpty(s)) 
      return false;
      
	var secondchar;
	var thirdchar;
	var fourthchar;
	var letter_status = false;
	var digit_status = false;
	    
    //check for repeating characters  
    for (i = 0; i < s.length; i++)
    {   
        // Check whether characters are repeating more than 3 times.
        var c = s.charAt(i);
        if ( letter_status == false )
			letter_status = isLetter(c)
		if ( digit_status == false )
			digit_status = isDigit(c)
        if ( i < (s.length - 3) )
        {
			secondchar = s.charAt(i+1) 
			thirdchar = s.charAt(i+2)
			fourthchar = s.charAt(i+3)
			if (c == secondchar && c == thirdchar && c == fourthchar)
				return false;
			else
				donothing = 1;

		}
    }
    //check for "must" alphanumeric
    return (letter_status && digit_status);
}


// Removes initial (leading) whitespace characters from s.
// Global variable whitespace (see above)
// defines which characters are considered whitespace.

function stripInitialWhitespace (s)

{   var i = 0;
    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;
    
    return s.substring (i, s.length);
}

// charInString (CHARACTER c, STRING s)
//
// Returns true if single character c (actually a string)
// is contained within string s.

function charInString (c, s)
{   for (i = 0; i < s.length; i++)
    {   if (s.charAt(i) == c) return true;
    }
    return false
}

// isIntegerInRange returns true if string s is an integer 
// within the range of integer arguments a and b, inclusive.

function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
     return false;
       
    if (!isInteger(s, false)) return false;

    //if string s begins with '0' then it assumes octal values. 
    //pass the radix value as 10 meaning decimal.
    var num = parseInt (s, 10);

    return ((num >= a) && (num <= b));
}


// isMonth returns true if string s is a valid 
// month number between 1 and 12.

function isMonth (s)
{   if (isEmpty(s)) 
      return false;
    return isIntegerInRange (s, 1, 12);
}

// isDay returns true if string s is a valid 
// day number between 1 and 31.
 
function isDay (s)
{   if (isEmpty(s)) 
      return false;
    return isIntegerInRange (s, 1, 31);
}

// daysInFebruary
// Given integer argument year,
// returns number of days in February of that year.

function daysInFebruary (year)
{   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

// isYear returns true if string s is a valid 
// Year number.  Must be 4 digits only.
// For Year 2000 compliance, you are advised
// to use 4-digit year numbers everywhere.
//

function isYear (s)
{
	if (isInteger (s)) 
	{
		if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
		    return false;
		    else
		    return (s.length == 4);
	}
	return false;
}




// Returns true if string s is an integer >= 0.

function isNonnegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    // 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(s)
         && (isEmpty(s) || parseInt (s, 10) >= 0)  );
}

// 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.
//
// EXAMPLE FUNCTION CALL:          RESULT:
// isSignedInteger ("5")           true 
// isSignedInteger ("")            defaultEmptyOK
// isSignedInteger ("-5")          true
// isSignedInteger ("+5")          true
// isSignedInteger ("", false)     false
// isSignedInteger ("", true)      true

function isSignedInteger (s)

{   if (isEmpty(s)) 
         return false; 

    else {
        var startPos = 0;

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
			return true;
        else
			return false;
    }
}

// End of isSignedInteger


// splitDate gets the day, month and year from a date string
function splitDate(s)
{
	arrayofdate = s.split("-")
    smonth = arrayofdate[0]
    sday = arrayofdate[1]
    syear = arrayofdate[2]
}


//

// isDate returns true if string arguments year, month, and day 
// form a valid date.

function isDate (year, month, day)
{   
	// catch invalid years (not 2- or 4-digit) and invalid months and days.
    if (! (isYear(year) && isMonth(month) && isDay(day))) return false;
    
    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
    var intYear = parseInt(year, 10);
    var intMonth = parseInt(month, 10);
    var intDay = parseInt(day, 10);

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

// isUSPhoneNumber returns true if string s is a valid U.S. Phone
// Number.  Must be 10 digits.
//
// NOTE: Strip out any delimiters (spaces, hyphens, parentheses, etc.)
// from string s before calling this function.
function isUSPhoneNumber (s)
{   if (isEmpty(s)) 
      return false;
    return (isInteger(s) && s.length == digitsInUSPhoneNumber)
}

//isRadio
//isRadio checks whether the user selects atleast one radio button
//If only one radio button is present in the radio button group then
//s.checked will return the checked status
//otherwise for more radio buttons use length.
function isRadio (s)
{   
	var i=s.length;
	for (var x=0;x<i;x++) 
	{
		if (s[x].checked==true)
		{
				return true;
		}
	}

	return false;
}
//end of isRadio

// isSSN returns true if string s is a valid U.S. Social
// Security Number.  Must be 9 digits.
//
// NOTE: Strip out any delimiters (spaces, hyphens, etc.)
// from string s before calling this function.
//

// Modified by Vijay

/**
function isSSN (s)
{   if (isEmpty(s)) 
		return false;
    return (isInteger(s) && s.length == digitsInSocialSecurityNumber)
}
*/

function isSSN (s)
{   if (s == "000000000") 
		return false;
	else
		return true;
    //return (isInteger(s) && s.length == digitsInSocialSecurityNumber)
}

function isEmpty(s)
// Check whether string s is empty.
{   
	s = Trim(s)
	if ((s == null) || (s.length == 0))
	return true;
    // Check whether all characters are spaces.
	emptyc = 0
	for (j = 0; j < s.length; j++)
    {   
        var c = s.charAt(j);
        if (c == ' ') 
			emptyc = emptyc + 1 
   }
   if (emptyc == s.length) 
	return true;
   return false;
}

function isAlphabetic (s)

{   var i;

    if (isEmpty(s)) 
       return false;

    // 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 < s.length; i++)
    {   
        // Check that current character is letter.
        var c = s.charAt(i);
        if (c == ' ') 
			donothing = 1
        else {
			if (!isLetter(c))
			return false;}
    }

    // All characters are letters.
    return true;
}
function isAlphabetic2 (s)

{   var i;

    if (isEmpty(s)) 
       return false;

    // 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 < s.length; i++)
    {   
        // Check that current character is letter.
        var c = s.charAt(i);
        if (c == ' ') 
			donothing = 1
        else {
			if ( c != "'" ) 
			{
				if (!isLetter(c))
				return false;}
			}
    }

    // All characters are letters.
    return true;
}

// 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;
}

// 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

/*
function isEmail (s)
{   
if (isEmpty(s)) 
        return false;
   
    // 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 isEmail (s) {
//this function validates the email address and returns true for valid email.
//created by Sajjad and Rizaullah
	
	if (isEmpty(s)) 
        return false;
   
	/* The following pattern is used to check if the entered e-mail address
   	fits the user@domain format.  It also is used to separate the username
   	from the domain. */
	var emailPat=/^(.+)@(.+)$/
	/* The following string represents the pattern for matching all special
	   characters.  We don't want to allow special characters in the address. 
	   These characters include ( ) < > @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	/* The following string represents the range of characters allowed in a 
	   username or domainname.  It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]"
	/* The following pattern applies if the "user" is a quoted string (in
	   which case, there are no rules about which characters are allowed
	   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	   is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")"
	/* The following pattern applies for domains that are IP addresses,
	   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	   e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	/* The following string represents an atom (basically a series of
	   non-special characters.) */
	var atom=validChars + '+'
	/* The following string represents one word in the typical username.
	   For example, in john.doe@somewhere.com, john and doe are words.
	   Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	/* The following pattern describes the structure of a normal symbolic
	   domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


	/* Finally, let's start trying to figure out if the supplied address is
	   valid. */	

	/* Begin with the coarse pattern to simply break up user@domain into
	   different pieces that are easy to analyze. */
	var matchArray=s.match(emailPat)
	if (matchArray==null) {
	  /* Too many/few @'s or something; basically, this address doesn't
	     even fit the general mould of a valid e-mail address. */		
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	
	// See if "user" is valid 
	if (user.match(userPat)==null) {
	    // user is not valid		
    		return false
	}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {		
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {	
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length

/***********  Modified  *****************/

if ((domArr[domArr.length-1].length>=3))
{
   	switch (domArr[domArr.length-1].toLowerCase())
	{
		case "info":
		case "aero":
		case "biz":
		case "coop":
		case "museum":
		case "name":
		case "pro":
		case "com":
		case "edu":
		case "gov":
		case "net":
			return true;
		default:
			return false;
	}		
}

if ((domArr[domArr.length-1].length<2) || (domArr[domArr.length-1].length>6 && domArr[domArr.length-1].toLowerCase() != 'info')) {
   // the address must end in a two letter or three letter word except .info.	
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {	
   	return false
}

// If we've gotten this far, everything's valid!
return true;
}

function isStreetNumber(s)
{   var i;
    
    if (isEmpty(s)) 
	    return false;

    // Search through string's characters one by one
    // until we find a non-alphanumeric 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 or letter.
        var c = s.charAt(i);
        if (c == ' ') 
			donothing = 1
        else {
			if (!(isLetter(c) || isDigit(c) || isHypon(c)) )
			return false; 
			}
    }
    // All characters are numbers or letters.
    return true;
}

function isHypon(c){
   return (c == "-");
}

function isAlphanumeric (s)

{   var i;
    
    if (isEmpty(s)) 
	    return false;

    // Search through string's characters one by one
    // until we find a non-alphanumeric 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 or letter.
        var c = s.charAt(i);
        if (c == ' ') 
			donothing = 1
        else {
			if (! (isLetter(c) || isDigit(c) ) )
			return false; }
    }
    // All characters are numbers or letters.
    return true;
}
// Returns true if character c is an English letter 
// (A .. Z, a..z).
//

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}



// Returns true if character c is a digit 
// (0 .. 9).

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isCompanyName(s){
	var i;
    
    if (isEmpty(s)) 
	    return false;

    // Search through string's characters one by one
    // until we find a non-alphanumeric 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 or letter.
        var c = s.charAt(i);
        //if (c=='!') alert(isSpecialChar(c))
        
		//alert(c)
        if (c == ' ') 
			donothing = 1
        else {
			if ((!(isLetter(c) || isDigit(c)) || isSpecialChar(c))) 
			return false; }
    }
    // All characters are numbers or letters.
    return true;

}

function isSpecialChar(c)
{
var arySC=new Array("(","@","#","$","_","+","[","]","\\","\"",".","~","?","!","-","'","/","&",":","*","(",")");
	for (i=0;i<=arySC.length;i++){
		if (c==arySC[i]){
			return true;
		}
	}
return false;	
}

// Returns true if character c is a letter or digit.

function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}

function isInteger (s)

{   var i;

    if (isEmpty(s)) 
	    return false;


    // 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;
}


// isZIPCode (STRING s [, BOOLEAN emptyOK])
// 
// isZIPCode returns true if string s is a valid 
// U.S. ZIP code.  Must be 5 or 9 digits only.
//

function isZIPCode (s)
{  
   var temp1 = ""
   if (isEmpty(s)) 
	   return false;

   temp1 = s
   if ( ! isInteger( remove_delimiter(temp1, '-') ) )
		return false;
   else
   {	
		delimit_nos = checkDelimiter(s, '-')
		if ( delimit_nos > 0 )
		{ 
		 if ( (delimit_nos == 5) && (s.length == 10) )
				return true;
		 else 
				return false;	
		}
		else
		{
		  return ( isInteger(s) && 
		         ( (s.length == digitsInZIPCode1) ||
		           (s.length == digitsInZIPCode2) ) )
		}
   }
}

// isCreditCard returns true if string s is a valid 
// credit card.  Must be 16 digits only.
//
// NOTE: Strip out any delimiters (spaces, hyphens, etc.)
// from string s before calling this function.  
//

function isCreditCard (s)
{  
   if (isEmpty(s)) 
	return false;
   return ( isInteger(s) && (s.length == digitsInCreditCard) )
   
}
//Introduced By Sasanka for 18836
function isCreditCardSecurity (s)
{  
   if (isEmpty(s)) 
	return false;
   return ( isInteger(s) && (s.length == CardSecurity) )

}
// isCreditCardAmex returns true if string s is a valid 
// credit card.  Must be 15 digits only.
//
// NOTE: Strip out any delimiters (spaces, hyphens, etc.)
// from string s before calling this function.  
//

function isCreditCardAmex (s)
{  
   if (isEmpty(s)) 
	return false;
   return ( isInteger(s) && (s.length == digitsInCreditCardAmex) )
   
}

// isStateCode (STRING s [, BOOLEAN emptyOK])
// 
// Return true if s is a valid U.S. Postal Code 
// (abbreviation for state).

function isStateCode(s)
{   if (isEmpty(s)) 
	    return ("empty_field");

    return ( (USStateCodes.indexOf(s) != -1) &&
             (s.indexOf(USStateCodeDelimiter) == -1) )
}

//check_period
//This function removes period "." from a string to facilitate proper alphanumeric checks

function check_period(s)
{
	var i
	var temp = ""
    if (isEmpty(s)) 
		return s;
		
    // Search through string's characters one by one
    // until we find a period character.
    // When we do, remove period.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (c == '.')
        {
			temp = temp + ' '
        }
        else
			temp = temp + c;
			
    }
    s = temp;
    return s;
    
}

//check_hash
//This function removes hash "#" from a string to facilitate proper alphanumeric checks

function check_hash(s)
{
	var i
	var temp = ""
    if (isEmpty(s)) 
		return s;
		
    // Search through string's characters one by one
    // until we find a period character.
    // When we do, remove period.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (c == '#')
        {
			temp = temp + ' '
        }
        else
			temp = temp + c;
			
    }
    s = temp;
    return s;
    
}

// Removes all whitespace characters which appear in string s.

function stripWhiteSpace (s)
{   
	var i;
    var returnString = "";

    if (isEmpty(s)) 
		return s;
    
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != ' ') returnString += c;
    }
    return returnString;
}

//remove_delimiter
//This function removes delimiter from a string to facilitate proper checks

function remove_delimiter(s, delimiter)
{
	var i
	var temp = ""
    if (isEmpty(s)) 
		return temp;
		
    // Search through string's characters one by one
    // until we find the delimiter character.
    // When we do, remove delimiter.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is delimiter.
        var c = s.charAt(i);
        if (c == delimiter)
        {
			temp = temp
        }
        else
			temp = temp + c;
			
    }
    return temp;
    
}

//This function takes the delimiter and a string as input and 
//checks where the delimiter is positioned.
function checkDelimiter(s, delimiter)
{
	var i, countd = 0
	var posd = 0
    if (isEmpty(s)) 
		return s;
		
    // Search through string's characters one by one
    // until we find the delimiter character.
    // When we do, note the position.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (c == delimiter)
        {
			posd = posd + i
			countd = countd + 1
        }
        else
			donothing = 1;
    }
    
    if (countd > 1)
		posd = 0
		
		return posd;
		
}

/*
** This function will trim leading
** and trailing spaces from the
** passed string with the
** result returned as the return value.
*/

function Trim(xstrValue){
	// Trim leading characters
	if (xstrValue !=""){
	xstrValue = xstrValue.replace(/^\s+/, "");

	// Trim trailing characters
	xstrValue = xstrValue.replace(/\s+$/, "");
	}
	return xstrValue;
	
}
/*
** This function will check the Credit Card Expr. Date
*/

function Check_Expr_Date()
{



}

//This function checks for invalid Characters and displays them
function check_invalid_characters(s, bag)
{
   invalid_char = getCharsInBag(s, bag) 
   if (invalid_char != "")
	invalid_msg = " These are the invalid characters you entered " + invalid_char ;
   else
    invalid_msg = ""
   return invalid_msg;	
}

// Removes all characters which appear in string bag from string s.

function getCharsInBag (s, bag)
{   
	var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += " '" + c + "' ";
    }

    return returnString;
}


//This Function tackles the Room/Suite and Room/Suite Number issue
function check_condition(roomnumber, roomtype, setmsg1, setmsg2, roomtypename, roomnumbername  )
{
  var msg1, msg2, retmsg;
  retmsg = "";
  msg1 = validate_form(roomnumber, "Alphanumeric", roomnumbername)
  msg2 = validate_form(roomtype, "Select", roomtypename)
  
  if (msg1 == "")
  {
	msg2 = validate_form(roomtype, "Select", roomtypename)
	if (msg2 != "")
		retmsg = setmsg1; 
  } 
  else
  {
	if (roomnumber != "")
		retmsg = msg1;
  }

  
  
  if (msg2 == "")
  {
	msg1 = validate_form(roomnumber, "Alphanumeric", roomnumbername)
	if (msg1 != "")
		retmsg = setmsg2 + msg1; 
  } 
  
  return retmsg;

}




//SSN check

function ValidateSSN(SSN)
{
		var msg = "";
		if (SSN !="")
		{
			if (SSN == "000000000")
				{	
					msg = msg + " Please Enter Valid Social Security Number.\n";
					return false;
				}
			else 
			 {
				//SSN should not be 111-11-1111 or 22-22-2222 means all char should not be same.
				var firstChar, t
				var iLength = SSN.length
				firstChar = SSN.substring(0,1);
				var lflag = false
				for (t=1; t<iLength; t++)
					{	
					
			 			if (SSN.charAt(t)!=firstChar)
				 			{
								lflag = true
				 			}
					
					}
						 
				if (lflag == false)
					{	 
						return false;
					}
				
					//---------------------------ends here-----------------------	
					
							/*
									var ssn1 = SSN.substring(0,3);
									var con1 = SSN.charAt(3,3);
									var ssn2 = SSN.substring(4,6);
									var con2 = SSN.charAt(6,6);
									var ssn3 = SSN.substring(7,11);
				
					
										if (ssn1.length!=3 || ssn2.length!=2 || ssn3.length!=4 || con1!='-' || con2!='-' || isInteger(ssn1+ssn2+ssn3)!=true)
									{
											return false;
									}
							*/
					return true;		
				}
		}
						
	}
// end here	