// VARIABLE DECLARATIONS

var digits = "0123456789";
// whitespace characters
var whitespace = " \t\n\r";

// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- +";


// characters which are allowed in US phone numbers
var validUSPhoneChars = digits + phoneNumberDelimiters;


// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = digits + phoneNumberDelimiters + "+";

// CONSTANT STRING DECLARATIONS
// (grouped for ease of translation and localization)

// m is an abbreviation for "missing"

//var mPrefix = "You did not enter a value into the "
//var mSuffix = " field. This is a required field. Please enter it now."

var mPrefix = "Please enter "
var mSuffix = ""

// s is an abbreviation for "string"

// begin changepwd.asp
var sPassword = "Password"
var sConfirmPassword = "Confirm Password"
var sMobilePassword = "Mobile Password"
var sConfirmMobilePassword = "Confirm Mobile Password"
// end changepwd.asp

var sUserId = "User Id"
var sMobileUserId = "Mobile User Id"
var sLastName = "Last Name"
var sFirstName = "First Name"
var sServiceProvider = "Service Provider"
var sSMSTelNo = "SMS Phone"
var sAlertEmail = "Alert Mail"
var sCompName = "Enterprise Name"
var sCompId = "Enterprise ID"
var sCompAccPwd = "Enterprise Key"
var sPhone = "Phone"
var sEmail = "Email"
var sValidFrom = "Valid From"
var sValidTo = "Valid To"
var sPwd = "Password"
var sId	= "Id"
var sNotSame = "The old and the new password values do not match. Please reenter them."
var sNotMobileSame = "The old and the new mobile password values do not match. Please reenter them."
var sError = "System error."
var sBackOffAdminPwd = "BackOffice Administrator Password"
var sEnterpriseAdminPwd = "Enterprise Administrator Password"
var sBackOffAdminId = "BackOffice Administrator ID"
var sEnterpriseAdminId = "Enterprise Administrator ID"
var sServerURL = "BackOffice connector URL"
var sScalaCompany = "Scala Company"
var sWareHouse = "Warehouse"


var sWorldLastName = "Family Name"
var sWorldFirstName = "Given Name"
var sTitle = "Title"
var sCompanyName = "Company Name"
var sUSAddress = "Street Address"
var sWorldAddress = "Address"
var sCity = "City"
var sStateCode = "State Code"
var sWorldState = "State, Province, or Prefecture"
var sCountry = "Country"
var sZIPCode = "ZIP Code"
var sWorldPostalCode = "Postal Code"
var sPhone = "Phone Number"
var sFax = "Fax Number"
var sDateOfBirth = "Date of Birth"
var sExpirationDate = "Expiration Date"
var sSSN = "Social Security Number"
var sCreditCardNumber = "Credit Card Number"
var sOtherInfo = "Other Information"
var sAdminIdsEqual = "Enterprise administrative Id should not be same as Backoffice administrative Id"
var sDuplicateCompanyId = "This Enterprise Id already exists"
var sDuplicateAdminId = "This Enterprise administrtor Id already exists"
var sDuplicateBackOfficeAdminId = "This Backoffice administrtor Id already exists"
var sSameAdminIds = "Enterprise administrtor's userId is same as Backoffice administrator's UserId"

// m is an abbreviation for "missing"

//var mPrefix = "You did not enter a value into the "
//var mSuffix = " field. This is a required field. Please enter it now."

// p is an abbreviation for "prompt"

var pEntryPrompt = "Please enter a "

var defaultEmptyOK = false

// i is an abbreviation for "invalid"
var iEmail = "Please enter valid e-mail address e.g. someone@somewhere.com "

//var iEmail = "This field must be a valid email address (like foo@bar.com). Please reenter it now."
//var iWorldPhone = "This field must be a valid international phone number. Please reenter it now."
var iWorldPhone = "Please enter your phone number properly."

var iWorldFax = "Please enter your Fax number properly."
//var iDay = "This field must be a day number between 1 and 31.  Please reenter it now."
var iDay = "Please enter day of date properly"
//var iMonth = "This field must be a month number between 1 and 12.  Please reenter it now."
var iMonth = "Please enter month of date properly"
//var iYear = "This field must be a 4 digit year number.  Please reenter it now."
var iYear = "Please enter year of date properly"
var iDatePrefix = "The Day, Month, and Year for "
var iDateSuffix = " do not form a valid date.  Please reenter them now."
var iPwd = "Invalid Password"
var iId = "Invalid Id" 
var iBackOffAdminPwd = "Invalid BackOffice Administrator Password"
var iEnterpriseAdminPwd = "Invalid Enterprise Administrator Password"
var iAccountingYear = "Invalid Accounting Year"


// Attempting to make this library run on Navigator 2.0,
// so I'm supplying this array creation routine as per
// JavaScript 1.0 documentation.  If you're using 
// Navigator 3.0 or later, you don't need to do this;
// you can use the Array constructor instead.

function makeArray(n) {
//*** BUG: If I put this line in, I get two error messages:
//(1) Window.length can't be set by assignment
//(2) daysInMonth has no property indexed by 4
//If I leave it out, the code works fine.
//   this.length = 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;





// 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;
}



// Returns true if string s is empty or 
// has even one whitespace character.

function isSingleWhitespace (s)

{   var i;
	var isfound ;
    // 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.
    isfound = 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) 
        {
			isfound = false ;
		}
		else
		{	
			isfound = true ;
			break ;
		}	
    }
	return isfound ;
    // All characters are whitespace.
  //  return true;
}

// Notify user that required field theField is empty.
// String s describes expected contents of theField.value.
// Put focus in theField and return false.

function warnEmpty (theField, s)
{   
    alert(mPrefix + s + mSuffix);
    theField.focus();    
    return false ;

}



/* FUNCTIONS TO INTERACTIVELY CHECK VARIOUS FIELDS. */

// checkIdPwd (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is not all whitespace or does not contain any space.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkIdPwd (theField, s, s1, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkIdPwd.arguments.length == 3) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (isWhitespace(theField.value)) 
    	 return warnEmpty (theField, s);
    if (isSingleWhitespace(theField.value)) 
       return alert(s1);
    else return true;
}


// checkString (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is not all whitespace.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkString (theField, s, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkString.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (isWhitespace(theField.value)) 
       return warnEmpty (theField, s);
    else 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 isInteger.

function checkEmail (theField, emptyOK)
{   if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
	if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else if (!isEmail(theField.value, false)) 
    {
       return warnInvalid (theField, iEmail);
    }   
    else return true;
}

// Notify user that contents of field theField are invalid.
// String s describes expected contents of theField.value.
// Put select theField, pu focus in it, and return false.

function warnInvalid (theField, s)
{   
      alert(s);
      theField.focus();
//      theField.select();
    return false
}


// 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;
	if (isSingleWhitespace(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;
	var x = 1;
	var no = 0;
	
	// look for @
    for ( x=0; x <= sLength; x++)
    { if (s.charAt(x) == "@")
		no++
    }
   
    if (no > 1 ) return false;
    
    // 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;
}


// checkInternationalPhone (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid International Phone.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkInternationalPhone (theField, emptyOK)
{   if (checkInternationalPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  
    var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters)
	//	if (!isInternationalPhoneNumber(theField.value, false)) 
	if (!isInternationalPhoneNumber(normalizedPhone, false)) 
	{
          return warnInvalid (theField, iWorldPhone);
			alert('invalid') ;	
    }      
       else return true;
    }
}


// Removes all characters which appear in string bag from string s.

function stripCharsInBag (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;
}



// isInternationalPhoneNumber (STRING s [, BOOLEAN emptyOK])
// 
// isInternationalPhoneNumber returns true if string s is a valid 
// international phone number.  Must be digits only; any length OK.
// May be prefixed by + character.
//
// NOTE: A phone number of all zeros would not be accepted.
// I don't think that is a valid phone number anyway.
//
// NOTE: Strip out any delimiters (spaces, hyphens, parentheses, etc.)
// from string s before calling this function.  You may leave in 
// leading + character if you wish.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isInternationalPhoneNumber (s)
{   if (isEmpty(s)) 
       if (isInternationalPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isInternationalPhoneNumber.arguments[1] == true);
    return (isPositiveInteger(s))
}

// isPositiveInteger (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 isPositiveInteger (s)
{   var secondArg = defaultEmptyOK;
    if (isPositiveInteger.arguments.length > 1)
        secondArg = isPositiveInteger.arguments[1];

    // 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 positive, not negative, number

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) > 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.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// 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)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}


// 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.
//
// 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.
//
// EXAMPLE FUNCTION CALL:     RESULT:
// isInteger ("5")            true 
// isInteger ("")             defaultEmptyOK
// isInteger ("-5")           false
// isInteger ("", true)       true
// isInteger ("", false)      false
// isInteger ("5", false)     true

function isInteger (s)

{   var i;
	if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
	// 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)) 
	{ //alert("This field must be a number.  Please reenter it now.")
		return false;
	}
    }

    // All characters are numbers.
    return true;
}

// Returns true if character c is a digit 
// (0 .. 9).

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

// isYear (STRING s [, BOOLEAN emptyOK])
// 
// isYear returns true if string s is a valid 
// Year number.  Must be 2 or 4 digits only.
// 
// For Year 2000 compliance, you are advised
// to use 4-digit year numbers everywhere.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isYear (s)
{   if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
    if (!isNonnegativeInteger(s)) return false;
    return ((s.length == 4));
}

// isNonnegativeInteger (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 isNonnegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];

    // 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(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
}


// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
// 
// isIntegerInRange returns true if string s is an integer 
// within the range of integer arguments a and b, inclusive.
// 
// For explanation of optional argument emptyOK,
// see comments of function isInteger.


function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);

    // Catch non-integer strings to avoid creating a NaN below,
    // which isn't available on JavaScript 1.0 for Windows.
    if (!isInteger(s, false)) return false;

    // Now, explicitly change the type to integer via parseInt
    // so that the comparison code below will work both on 
    // JavaScript 1.2 (which typechecks in equality comparisons)
    // and JavaScript 1.1 and before (which doesn't).
    var num = parseInt (s,10);
    return ((num >= a) && (num <= b));
}



// isMonth (STRING s [, BOOLEAN emptyOK])
// 
// isMonth returns true if string s is a valid 
// month number between 1 and 12.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isMonth (s)
{   if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}



// isDay (STRING s [, BOOLEAN emptyOK])
// 
// isDay returns true if string s is a valid 
// day number between 1 and 31.
// 
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isDay (s)
{   if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 1, 31);
}



// daysInFebruary (INTEGER year)
// 
// 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 );
}



// isDate (STRING year, STRING month, STRING day)
//
// 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, false) && isMonth(month, false) && isDay(day, false))) return false;

    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}


// Check that string theField.value is a valid Year.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkYear (theField, emptyOK)
{   if (checkYear.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isYear(theField.value, false)) 
       //return warnInvalid (theField, iYear);
       return false;
    else return true;
}


// Check that string theField.value is a valid Month.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkMonth (theField, emptyOK)
{   if (checkMonth.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isMonth(theField.value, false)) 
      // return warnInvalid (theField, iMonth);
      return false;
    else return true;
}


// Check that string theField.value is a valid Day.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkDay (theField, emptyOK)
{   if (checkDay.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isDay(theField.value, false)) 
      // return warnInvalid (theField, iDay);
      return false;
    else return true;
}



// checkDate (yearField, monthField, dayField, STRING labelString [, OKtoOmitDay==false])
//
// Check that yearField.value, monthField.value, and dayField.value 
// form a valid date.
//
// If they don't, labelString (the name of the date, like "Birth Date")
// is displayed to tell the user which date field is invalid.
//
// If it is OK for the day field to be empty, set optional argument
// OKtoOmitDay to true.  It defaults to false.

//function checkDate (yearField, monthField, dayField, labelString, OKtoOmitDay)
function checkDate (datefield, labelString, OKtoOmitDay)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    //if (checkDate.arguments.length == 4) OKtoOmitDay = false;
	
	//alert(datefield.value);
	if (checkDate.arguments.length == 2) OKtoOmitDay = false;
	
	if (datefield.value == "") return true;
		
	var sDate = datefield.value;
	var splitDate;
	splitDate = sDate.split("/");
	
if (sDate.indexOf("/",1) == -1) return false;

if (splitDate[2] < 1900){
//		alert("Year must be greater than 1900"); 
		return false;
	}	

//    if (!isYear(yearField.value)) return warnInvalid (yearField, iYear);

if (!isYear(splitDate[2])) 
//return warnInvalid (datefield, iYear);
return false;

//    if (!isMonth(monthField.value)) return warnInvalid (monthField, iMonth);


//    if ( (OKtoOmitDay == true) && isEmpty(dayField.value) ) return true;
 
    if ( (OKtoOmitDay == true) && isEmpty(splitDate[0])) return true;
//    else if (!isDay(dayField.value)) 

	else if (!isDay(splitDate[0]))
       //return warnInvalid (datefield, iDay);
       return false;

 if (!isMonth(splitDate[1])) 
	//return warnInvalid (datefield, iMonth);
	return false;

//    if (isDate (yearField.value, monthField.value, dayField.value))

	 if (isDate (splitDate[2], splitDate[1], splitDate[0]))
       return true;
    //alert (iDatePrefix + labelString + iDateSuffix)
    return false
}



//If other option is selected from the select box
// then display othtext field

function dispoth(selectfield , othfield)
{
  othfield.type = "Hidden" 
  if (selectfield.value == "others")
   {
         othfield.type = "Text"         
   }  
}

//check field is empty , if true display alert message

function warnEmptyField (theField, s)
{   if (theField.value == "" )
	{    alert(mPrefix + s + mSuffix);
	    theField.focus();    
	    return false ;
	}
   else  return true    
}


//
function chkInteger (theField,s)
{
if ( ! isInteger(theField.value, true))
	{
	alert ( "Please enter " + s +"as integer");
			theField.focus();
			return false
	}
else return true

}

function isDaysOfMonth (month, day)
{   // catch invalid years (not 2- or 4-digit) and invalid months and days.
    if (! isMonth(month, false) && isDay(day, false)) return false;

    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
  //  var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}


// checkInternationalFax (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid International Fax.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkInternationalFax (theField, emptyOK)
{   if (checkInternationalFax.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  
    var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters)
	//	if (!isInternationalPhoneNumber(theField.value, false)) 
	if (!isInternationalPhoneNumber(normalizedPhone, false)) 
	{
          return warnInvalid (theField, iWorldFax);
			alert('invalid') ;	
    }      
       else return true;
    }
}

function IsNumeric(str, s )
{
	var i;
	str = str.value;
	
	for(i=0;i<str.length;i++)
	{
		if(!(	((str.charAt(i) <= '9') && (str.charAt(i) >= '0')) ||
				(str.charAt(i) == ' ') || (str.charAt(i) == '.') || (str.charAt(i) == '-')))
			{
			alert("Please Enter " + s + " properly")	
			return(false);
			}
	}
	return(true);
}


function format(number,decimals) {
  var i,d;

  // set default values
  if(number=="") number=parseInt("0");
  if(decimals=="") decimals=parseInt("2");

  // round number to specified number of decimals
  number=""+Math.round(number*Math.pow(10,decimals))*Math.pow(10,-decimals);

  // find index of decimal point
  d=number.indexOf(".");

  // if no decimal point, number is an integer
  // pad number with trailing zeros
  if(d==-1) {
    number=number+".";
    for(i=0;i<decimals;i++)
      number=number+"0";
    return number;
  }

  // if decimal point is first index
  // pad number with leading zero
  if(d==0) {
    number="0"+number;
    d++;
  }

  // if first index is negative sign
  // pad number with leading zero
  if(d==1 && number.substring(0,1)=="-") {
    number="-0" + number.substring(1,number.length);
    d++;
  }

  // truncate number to desired length
  number=number.substring(0,d+decimals+1);

  // if number is shorter than desired length
  // pad number with trailing zeros
  while(number.length<=d+decimals)
    number=number+"0";
  return number;
}

