
// VARIABLE DECLARATIONS

var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

// whitespace characters
var whitespace = " \t\n\r";

// decimal point character differs by language and culture
var decimalPointDelimiter = "."

var mPrefix = "You did not enter a value into the "
var mSuffix = " field. This is a required field. Please enter it now."

// i is an abbreviation for "invalid"

var iEmail = "This field must be a valid email address (like foo@bar.com). Please reenter it now."
var iDay = "This field must be a day number between 1 and 31.  Please reenter it now."
var iMonth = "This field must be a month number between 1 and 12.  Please reenter it now."
var iYear = "This field must be a 2 or 4 digit year number.  Please reenter it now."
var iDatePrefix = "The Day, Month, and Year for "
var iDateSuffix = " do not form a valid date.  Please reenter them now."

// p is an abbreviation for "prompt"

var pEntryPrompt = "Please enter a "
var pEmail = "valid email address (like foo@bar.com)."
var pCreditCard = "valid credit card number."
var defaultEmptyOK = false

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;


// 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;
}

// 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;
}

function replaceSpecialChars (s,replStr)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If special character found replace with replStr.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (isWhitespace(c)) {
	  returnString += replStr;
        }
	else {
	  returnString += c;
	}
    }

    return returnString;
}

// Removes all characters which do NOT appear in string bag from string s.

function stripCharsNotInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is 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;
}


function stripWhitespace (s)

{   return stripCharsInBag (s, whitespace)
}


function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || isGreekLetter(c) || isRussianLetter(c));
}

function isGreekLetter (greekChar)
{ var str=greekChar;
  var c=str.charCodeAt(0)
//alert(c);
return (c >= 940 && c <= 974) || (c >=902 && c <= 911) || (c>=945 && c<=969) || (c>=913 && c<=937);
 	
}

function isRussianLetter (rusChar)
{ var str=rusChar;
  var c=str.charCodeAt(0)
//alert(c);
return (c >= 1040 && c <= 1103) ;
 	
}

// Returns true if character c is a digit (0 .. 9).

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

// Returns true if character c is a letter or digit.

function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}

// Returns true if all characters in string s are numbers.

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)) return false;
    }

    // All characters are numbers.
    return true;
}

// Returns true if all characters are numbers;
// first character is allowed to be + or - as well.
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.

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))
    }
}

// Returns true if string s is an integer > 0.

function isPositiveInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isPositiveInteger.arguments.length > 1)
        secondArg = isPositiveInteger.arguments[1];

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s,10) > 0) ) );
}

// Returns true if string s is an integer >= 0.

function isNonnegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s,10) >= 0) ) );
}

// Returns true if string s is an integer < 0.

function isNegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNegativeInteger.arguments.length > 1)
        secondArg = isNegativeInteger.arguments[1];

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s,10) < 0) ) );
}

// Returns true if string s is an integer <= 0.

function isNonpositiveInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNonpositiveInteger.arguments.length > 1)
        secondArg = isNonpositiveInteger.arguments[1];

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s,10) <= 0) ) );
}

// True if string s is an unsigned floating point (real) number.

function isFloat (s)

{   var i;
    var seenDecimalPoint = false;

    if (isEmpty(s))
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    if (s == decimalPointDelimiter) 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 ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

// True if string s is a signed or unsigned floating point
// (real) number. First character is allowed to be + or -.

function isSignedFloat (s)

{   if (isEmpty(s))
       if (isSignedFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedFloat.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedFloat.arguments.length > 1)
            secondArg = isSignedFloat.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;
        return (isFloat(s.substring(startPos, s.length), secondArg))
    }
}

// Returns true if string s is English letters (A .. Z, a..z) only.

function isAlphabetic (s)

{   var i;

    if (isEmpty(s))
       if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphabetic.arguments[1] == true);

    // 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 (!isLetter(c))
        return false;
    }

    // All characters are letters.
    return true;
}

// Returns true if string s is English letters (A .. Z, a..z)

function isAlphabeticPlusOther (s,other)

{   var i;
    var tempRes;

    if (isEmpty(s))
       if (isAlphabeticPlusOther.arguments.length == 2) return defaultEmptyOK;
       else return (isAlphabeticPlusOther.arguments[2] == true);

    // 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++)
    {
	tempRes = false;

        // Check that current character is letter.
        var c = s.charAt(i);

	 	for (j=0;j < other.length; j++){

			if (c == other.charAt(j)){
				tempRes = true;
				break;
			}
		}

        if (!(isLetter(c) || tempRes))
        return false;
    }

    // All characters are letters.
    return true;
}


// Returns true if string s is English letters (A .. Z, a..z) and numbers only.

function isAlphanumeric (s)

{   var i;

    if (isEmpty(s))
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);


    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }

    // All characters are numbers or letters.
    return true;
}



function isAlphaNumericPlusOther (s,other)

{   var i;
    var tempRes;

    if (isEmpty(s))
       if (isAlphaNumericPlusOther.arguments.length == 2) return defaultEmptyOK;
       else return (isAlphaNumericPlusOther.arguments[2] == true);

    // 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++)
    {
	tempRes = false;

        // Check that current character is letter.
        var c = s.charAt(i);

	 	for (j=0;j < other.length; j++){

			if (c == other.charAt(j)){
				tempRes = true;
				break;
			}
		}

        if (!(isLetter(c) || tempRes ||isDigit(c)))
        return false;
    }

    // All characters are alphanumeric.
    return true;
}




function isNumericPlusOther (s,other)

{   var i;
    var tempRes;

    if (isEmpty(s))
       if (isNumericPlusOther.arguments.length == 2) return defaultEmptyOK;
       else return (isNumericPlusOther.arguments[2] == 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++)
    {
	tempRes = false;

        // Check that current character is letter.
        var c = s.charAt(i);

	 	for (j=0;j < other.length; j++){

			if (c == other.charAt(j)){
				tempRes = true;
				break;
			}
		}

        if (!(tempRes ||isDigit(c)))
        return false;
    }

    // All characters are numerico or one of the rest allowed
    return true;
}



function reformat (s)

{   var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}



function emailCheck (emailStr) {

       if (isEmpty(emailStr)) {

           if (emailCheck.arguments.length == 1) return defaultEmptyOK;
           else return (emailCheck.arguments[1] == true);
        }

/* 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=emailStr.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. */
	//alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    //alert("The username doesn't seem to be 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) {
	        //alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	//alert("The domain name doesn't seem to be valid.")
    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
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   //alert("The address must end in a three-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   //alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}



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) != "@"))
    {
       if (isWhitespace(s.substring(i,i+1))) return false;

       i++;
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { if (isWhitespace(s.substring(i,i+1))) return false;
      i++;
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else {
	while ((i < sLength)){
           if (isWhitespace(s.substring(i,i+1))) return false;
           i++;
       }

       return true;
    }
}

// isYear returns true if string s is a valid Year number.  Must be 2 or 4 digits only.

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 == 2) || (s.length == 4));
}

// 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))
       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 returns true if string s is a valid month 1-12

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 returns true if string s is a valid day number 1 - 31.

function isDay (s)
{   if (isEmpty(s))
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);
    return isIntegerInRange (s, 1, 31);
}

// 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 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,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;
}

/* FUNCTIONS TO NOTIFY USER OF INPUT REQUIREMENTS OR MISTAKES. */

// Display prompt string s in status bar.

function prompt (s)
{   window.status = s
}

// Display data entry prompt string s in status bar.

function promptEntry (s)
{   window.status = pEntryPrompt + s
}

// 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)
{   theField.focus()
    alert(mPrefix + s + mSuffix)
    return false
}

// 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)
{   theField.focus()
    theField.select()
    alert(s)
    return false
}

/* FUNCTIONS TO INTERACTIVELY CHECK VARIOUS FIELDS. */

// Check that string theField.value is not all whitespace.

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;
}



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;
}


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);
    else return true;
}

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);
    else return true;
}

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);
    else return true;
}

function checkDate (yearField, monthField, dayField, 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;
    if (!isYear(yearField.value)) return warnInvalid (yearField, iYear);
    if (!isMonth(monthField.value)) return warnInvalid (monthField, iMonth);
    if ( (OKtoOmitDay == true) && isEmpty(dayField.value) ) return true;
    else if (!isDay(dayField.value))
       return warnInvalid (dayField, iDay);
    if (isDate (yearField.value, monthField.value, dayField.value))
       return true;
    alert (iDatePrefix + labelString + iDateSuffix)
    return false
}

// Get checked value from radio button.
function getRadioButtonValue (radio)
{   for (var i = 0; i < radio.length; i++)
    {   if (radio[i].checked) { break }
    }
    return radio[i].value
}


// This function is to validate that text entered into a form field
// is in English,  i.e. they havent entered Arabic text.

function isEnglish (s)

{   var i;
    var tempRes;
    var other = " !?$%^&*()_-+={[}]:;@\"\\/'~#<,>.?";

    if (isEmpty(s))
       if (isEnglish.arguments.length == 1) return defaultEmptyOK;
       else return (isEnglish.arguments[1] == true);

    // 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++)
    {
	tempRes = false;

        // Check that current character is letter.
        var c = s.charAt(i);

	 	for (j=0;j < other.length; j++){

			if (c == other.charAt(j)){
				tempRes = true;
				break;
			}
		}

        if (!(isLetter(c) || tempRes ||isDigit(c)))
        return false;
    }

    // All characters are alphanumeric.
    return true;
}

function allTheSame(pwd){
//This method checks that the password is not consisting of an identical character
//e.g. that it is not 1111 or aaaa

    var pwdLen = pwd.length;
    var firstChar;

        if (pwdLen > 1){
            
            firstChar = pwd.charAt(0);
            
                for (var i=0;i<pwdLen-1;i++){
                   
                   
                    if (!(pwd.charAt(i) == firstChar)){
                        
                        return false;
                    }
                }
             
            return true;
        }
        else {
        //If string has only one character the no chane for duplicates
            
            return false;
        }

}

function isConsecutive(pwd){
    //This method returns true iff the given password is not empty and all of the characters (digits) contained in it
    //are not consecutive, i.e. passwd 1234 or 4321 are invalid
    //Pre: passwd is not null and consists only of numerical digits.
    
    var pwdLen = pwd.length;
    //var beforeChar,afterChar;
    var beforeCharIntValue,afterCharIntValue;
    var firstDiff;
	
	   if ( pwdLen > 1 ){  //if password is only character long we do not need to check 
                                //for consecutive characters

                   firstDiff = pwd.charCodeAt(1) - pwd.charCodeAt(0);                 
                   
                   
                   if (Math.abs(firstDiff) == 1){
                       for (var i=0;i<pwdLen-1;i++){ //We perform one less than the password length iterations to traverse
                                                    //the entire password.  
                            //beforeChar = pwd.charAt(i);	
                            //afterChar = pwd.charAt(i+1);

                            beforeCharIntValue = pwd.charCodeAt(i);
                            afterCharIntValue = pwd.charCodeAt(i+1);

                                    if ((afterCharIntValue - beforeCharIntValue  != firstDiff )){
                                       return false;
                                    }
                            
                            return true;        
                       }
                    }
                    else {
                        return false;
                    }
	   }
           else {
                return false;
            }
   }
   
   



function checkAlphabetic(formName){
//This function checks if alphabetic fields were  filled in correclty, i.e. with 
//capital or lower case arguments only. If some of the alphabetic fields were not it gives an
// error message and returns false otherwise it returns true.  The first argument is the form name
// on the document and the rest  of the arguments are alphabetic fields' names.  
//At least one alphabetic field should exist (otherwise there is no point to call this function).

//The n (n odd, so that n-1 is even) arguments to be passed are as follows:
//argument 0: form name
//arguments 1 to (n-1)/2: field names
//arguments (n-1)/2 + 1 to n-1: field labels

var errorFields = "";
var noFields  = (arguments.length  - 1)/2;



	for (var curFieldIndex = 1; curFieldIndex <= noFields;curFieldIndex++) {
		
		if (!isAlphabetic(document.forms[formName].elements[arguments[curFieldIndex]].value,true)) {
			changeTextColour(arguments[curFieldIndex],errColour);
			errorFields=errorFields + "\n   _ " + arguments[curFieldIndex + noFields];
		}
		else {
			changeTextColour(arguments[curFieldIndex],standardColour );
		}
	}


	if (errorFields != "") {
		//alert("The following fields should only contain alphabetic characters, i.e. not numerical digits or other characters, but they do so:" +errorFields + ".\n\nPlease correct before you can proceed.");
		alert(getI18NMsg("jsErrorCheckAlphabetic")+errorFields +getI18NMsg("jsErrorCorrect"));
		return false;
	}
	else {
		return true;
	}


}


function checkAlphabeticPlusOther(formName,otherValidChars){
//Works similar to checkAlphabetic with the addition of one argument

var errorFields = "";
var noFields  = (arguments.length  - 2)/2;



	for (var curFieldIndex = 2; curFieldIndex <= noFields+1;curFieldIndex++) {
		if (!isAlphabeticPlusOther(document.forms[formName].elements[arguments[curFieldIndex]].value,otherValidChars,true)) {
			changeTextColour(arguments[curFieldIndex],errColour);
			errorFields=errorFields + "\n   _ " + arguments[curFieldIndex + noFields];
		}
		else {
			changeTextColour(arguments[curFieldIndex],standardColour );
		}

	}


	if (errorFields != "") {
		//alert("The following fields contain non-valid characters:\n" +errorFields + ".\n\nPlease correct before you can proceed.");
		alert(getI18NMsg("jsErrorCheckAlphabeticPlusOther")+errorFields +getI18NMsg("jsErrorCorrect"));
		
	
		return false;
	}
	else {
		return true;
	}


}

function checkAlphanumericPlusOther(formName,otherValidChars){
//Works similar to checkAlphabetic with the addition of one argument

var errorFields = "";
var noFields  = (arguments.length  - 2)/2;



	for (var curFieldIndex = 2; curFieldIndex <= noFields+1;curFieldIndex++) {
		if (!isAlphaNumericPlusOther(document.forms[formName].elements[arguments[curFieldIndex]].value,otherValidChars,true)) {
			changeTextColour(arguments[curFieldIndex],errColour);
			errorFields=errorFields + "\n   _ " + arguments[curFieldIndex + noFields];
		}
		else {
			changeTextColour(arguments[curFieldIndex],standardColour );
		}

	}


	if (errorFields != "") {
		//alert("The following fields can only contain alphanumeric characters, comma (,), dot (.), dash (-), space ( ) and the And sign (&):" +errorFields + ".\n\nPlease correct before you can proceed.");
		alert(getI18NMsg("jsErrorCheckAlphaNumericPlusOther")+errorFields +getI18NMsg("jsErrorCorrect"));
		
		return false;
	}
	else {
		return true;
	}


}


function checkNumericPlusOther(formName,otherValidChars){
//Works similar to checkAlphabetic with the addition of one argument

var errorFields = "";
var noFields  = (arguments.length  - 2)/2;


	for (var curFieldIndex = 2; curFieldIndex <= noFields+1;curFieldIndex++) {
		if (!isNumericPlusOther(document.forms[formName].elements[arguments[curFieldIndex]].value,otherValidChars,true)) {
			changeTextColour(arguments[curFieldIndex],errColour);
			errorFields=errorFields + "\n   _ " + arguments[curFieldIndex + noFields];
		}
		else {
			changeTextColour(arguments[curFieldIndex],standardColour );
		}

	}


	if (errorFields != "") {
		//alert("The following fields can only contain numeric characters, the Plus sign (+) and dash (-):" +errorFields + ".\n\nPlease correct before you can proceed.");
		alert(getI18NMsg("jsErrorCheckNumericPlusOther")+errorFields +getI18NMsg("jsErrorCorrect"));
		
		return false;
	}
	else {
		return true;
	}


}

function checkAlphanumeric(formName){
//Works similar to checkAlphabetic

var errorFields = "";
var noFields  = (arguments.length  - 1)/2;



	for (var curFieldIndex = 1; curFieldIndex <= noFields;curFieldIndex++) {
		if (!isAlphanumeric(document.forms[formName].elements[arguments[curFieldIndex]].value,true)) {
			changeTextColour(arguments[curFieldIndex],errColour);
			errorFields=errorFields + "\n   _ " + arguments[curFieldIndex + noFields];
		}
		else {
			changeTextColour(arguments[curFieldIndex],standardColour );
		}

	}


	if (errorFields != "") {
		//alert("The following fields can only contain alphanumeric characters:" +errorFields + ".\n\nPlease correct before you can proceed.");
		alert(getI18NMsg("jsErrorCheckAlphaNumeric")+errorFields +getI18NMsg("jsErrorCorrect"));
		
		return false;
	}
	else {
		return true;
	}


}

