/*

  File : validation.js

  Date        Author        	Changes

  Jan, 1998   Joe Dickman		Created

  Jun, 2001   Swarn Dhaliwal	Cleaned up code and made the code more 

  								general and reusable.

  Oct, 2002   Nichole Bui       Cleaned up code to use pattern matching	and

  			  Eric Smallwood	added additional functions							

*/



var isNav = (navigator.appName.indexOf("Netscape") != -1);

var isIE = (navigator.appName.indexOf("Microsoft") != -1);



/* variable for keeping track of errors on form */

var errors = "";



/* array of names of all the fields on the form */

var names = new Array();



/* array of lengths for fields in the names array */

var strlens = new Array();



var returnAndSpaces = "\n           ";

var NUMERIC = 1;

var ALPHA = 2;

var ALPHA_NUMERIC = 3;

var FLOAT = 4;

var CURRENCY = 5;

var DATE = 6;

var EMAIL = 7;

var CREDIT_CARD = 8;

var NUMERIC_RANGE = 9;

var PERCENT = 10;

var RETURN_KEY_CODE = 13;

var US_ZIP_CODE = 15;

var NO_SPECIAL = 16;

var SAME_PASSWORD = 17;

var SAME_VALUE = 18;

var VALID_RANGE = 19;

var PHONE = 20;

var DEPENDENT = 21;

var SCREEN_NAME = 22;

var ALPHA_NAME = 23;

var CC_EXPIRATION_DATE = 24;

var NOT_EMAIL = 25;

var STREET_ADDRESS = 26;



// VARIABLE DECLARATIONS



// whitespace characters														

var whitespace = " \t\n\r";



// prohibited characters

var prohibitedLetters = "['\"%]"



// decimal point character differs by language and culture

var decimalPointDelimiter = "."



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;



/* Determine if the current key pressed is return key */

function returnKeyPressed(e) {

	if (isNav) {

		return e.which == RETURN_KEY_CODE;

	}

		else {

		//starts added by anjali nalapure on 15/1/2003 to remove enter=submit functionality inside textarea
	
		if (window.event.srcElement.type != "textarea") {

			return window.event.keyCode == RETURN_KEY_CODE;

		}

		//ends added by anjali nalapure on 15/1/2003 to remove enter=submit functionality inside textarea
	}

}



/* Check whether string s is empty. */

function isEmpty(s) { 

	return isBlank(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;

    }



	if (s.search(/[^ \t\n\r]/g) > -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;

}







/* 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;

}







/* Removes all whitespace characters from s.

	Global variable whitespace (see above)

	defines which characters are considered whitespace.

*/



function stripWhitespace (s) {   

	return stripCharsInBag (s, whitespace);

}



// WORKAROUND FUNCTION FOR NAVIGATOR 2.0.2 COMPATIBILITY.

//

// The below function *should* be unnecessary.  In general,

// avoid using it.  Use the standard method indexOf instead.

//

// However, because of an apparent bug in indexOf on 

// Navigator 2.0.2, the below loop does not work as the

// body of stripInitialWhitespace:

//

// while ((i < s.length) && (whitespace.indexOf(s.charAt(i)) != -1))

//   i++;

//

// ... so we provide this workaround function charInString

// instead.

//

// 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

}





/* 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);

}



// 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);

		}	

    }

	

	if (s.search(/\D/g) > -1) {

		return false;

	}



    // All characters are numbers.

    return true;

}



// isSignedInteger (STRING s [, BOOLEAN emptyOK])

// 

// Returns true if all characters are numbers; 

// first character is allowed to be + or - as well.

//

// Does not accept floating point, exponential notation, etc.

//

// We don't use parseInt because that would accept a string

// with trailing non-numeric characters.

//

// 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));

    }

}



// 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, 10) > 0) ) );

}



// 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, 10) >= 0) ) );

}



// isNegativeInteger (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 isNegativeInteger (s) {   

	var secondArg = defaultEmptyOK;



    if (isNegativeInteger.arguments.length > 1) {

        secondArg = isNegativeInteger.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 negative, not positive, number



    return (isSignedInteger(s, secondArg)

         && ( (isEmpty(s) && secondArg)  || (parseInt (s, 10) < 0) ) );

}



// isNonpositiveInteger (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 isNonpositiveInteger (s) {   

	var secondArg = defaultEmptyOK;



    if (isNonpositiveInteger.arguments.length > 1) {

        secondArg = isNonpositiveInteger.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, 10) <= 0) ) );

}



// isFloat (STRING s [, BOOLEAN emptyOK])

// 

// True if string s is an unsigned floating point (real) number. 

//

// Also returns true for unsigned integers. If you wish

// to distinguish between integers and floating point numbers,

// first call isInteger, then call isFloat.

//

// Does not accept exponential notation.

//

// For explanation of optional argument emptyOK,

// see comments of function isInteger.

/*

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;

}

*/



// currency should be in the format "nnnnn.nn", "nn,nnn.nn", "nn.n", and "nn.".

// - basically with or without properly spaced comments, and with any number of

// decimal places, also with or without the decimal point.

function isFloat(s)

{

	s = trimString(s);



	if (s == "")

		return true;



	var rxPattern1 = /^(\d{0,3})?(,\d{3})*(\.\d{0,2})?$/;

	var arrPatternMatch1 = s.match(rxPattern1, "g");



	var rxPattern2 = /^\d*(\.\d{0,2})?$/;

	var arrPatternMatch2 = s.match(rxPattern2, "g");



	if ((arrPatternMatch1 == null) && (arrPatternMatch2 == null))

	{

		return false;

	}

	s = s + "";

	return true;

}



/* trimString - takes a string and returns a string with all leading and trailing spaces removed. */

function trimString(s)

{

	if (s == null) {

		return "";

	}

	else {

		s = "" + s;

		return s.replace(/^\s+|\s+$/g,"");

	}

}







// isSignedFloat (STRING s [, BOOLEAN emptyOK])

// 

// True if string s is a signed or unsigned floating point 

// (real) number. First character is allowed to be + or -.

//

// Also returns true for unsigned integers. If you wish

// to distinguish between integers and floating point numbers,

// first call isSignedInteger, then call isSignedFloat.

//

// Does not accept exponential notation.

//

// For explanation of optional argument emptyOK,

// see comments of function isInteger.



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));

    }

}



// isAlphabetic (STRING s, BOOLEAN spaceOK [, BOOLEAN emptyOK])

// 

// Returns true if string s is English letters 

// (A .. Z, a..z) only.

//

// Argument spaceOK determines if empty space is allowed

//

// For explanation of optional argument emptyOK,

// see comments of function isInteger.

//

// NOTE: Need i18n version to support European characters.

// This could be tricky due to different character

// sets and orderings for various languages and platforms.



function isAlphabetic (s, b) {   

	var i;



	if (isEmpty(s)) { 

	   if (isAlphabetic.arguments.length == 2) {

	   		return defaultEmptyOK;

	   }

	   else {

	   		return (isAlphabetic.arguments[2] == true);

	   }

	}



	if (b) {	

		sPattern = /[^a-zA-Z ]/g;

	}

	else {	

		sPattern = /[^a-zA-Z]/g;

	}

		

	if (s.search(sPattern) > -1) {

		return false;

	}

	

    // All characters are letters.

    return true;

}



// isAlphanumeric (STRING s, BOOLEAN spaceOK [, BOOLEAN emptyOK])

// 

// Returns true if string s is English letters 

// (A .. Z, a..z) and numbers only.

//

// Argument spaceOK determines if empty space is allowed

//

// For explanation of optional argument emptyOK,

// see comments of function isInteger.

//

// NOTE: Need i18n version to support European characters.

// This could be tricky due to different character

// sets and orderings for various languages and platforms.



function isAlphanumeric (s, b) {   

	var i;



    if (isBlank(s)) {

       if (isAlphanumeric.arguments.length == 2) {

	   		return defaultEmptyOK;

       }

       else {

	   		return (isAlphanumeric.arguments[2] == true);

       }

    }



	var sPattern;

	if (b) {	

		sPattern = /[^a-zA-Z0-9 ]/g;

	}

	else {	

		sPattern = /[^a-zA-Z0-9]/g;

	}

		

	if (s.search(sPattern) > -1) {

		return false;

	}



    // All characters are numbers or letters.

    return true;

}



// isEmail (STRING s [, BOOLEAN emptyOK])

// 

// Email address must be of form a@b.c -- in other words:

// * there must be at least one character before the @

// * there must be at least one character before and after the .

// * the characters @ and . are both required

//

// For explanation of optional argument emptyOK,

// see comments of function isInteger.



function isValidEmail (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;

     
    //alert("Reaching here"+document.forms[0].email+"after");
    // 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;

	*/

        if ((s.search(/^.+@.+\..+$/g) < 0) || (s.search(/\.\@|\@\.|\.\./g) != -1)) {

		return false;

	}

        if (s.search(/\ \+\c/g) != -1) {
            
            return false;
            }

        /*if (s.search(/_|\-|~|#//cg) >= 1) {
            return false;
            }*/
         
            var i = 1;
        var sLength = s.length;
        while ((i < sLength) && (s.charAt(i) != " "))
        { i++

        }
        if ((i >= sLength)) return true;
	else
            return false;

	return true;

}



// 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.

//

// And yes, this function is not Year 10000 compliant, but 

// because I am giving you 8003 years of advance notice,

// I don't feel very guilty about this ...

//

// For B.C. compliance, write your own function. ;->

//

// 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 == 2) || (s.length == 4));

}







// 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 isValidDate (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;

}



/* Map used to store data on which the changes are to be tracked */

var changeDataMap = new Array();

var changeFieldMap = new Array();



/* This function determines whether the values stored in an array are the same

    as the values of options array of a select element

*/

function compareSelect(values, s) {

    if (values.length != s.length) {

        return false;

    }

    

    for (k = 0; k < values.length; k++) {

        //alert(s.name + " old value = " +values[k] + " new value = " +  s.options[k].selected);

        if (values[k] != s.options[k].selected) {

            return false;

        }

    }

    return true;

}



function setChangeField(obj) {

	if (obj == null) {

		return;

	}

	obj.checkForChange = true;

}



function ignoreChangeField(obj) {

	if (obj == null) {

		return;

	}

	obj.checkForChange = false;

}

/* Save the values of elements of form (obj) to be later on compared with the

    changed values

*/

    

function setChangeData(obj) {    

	if (obj == null) {

		return;

	}

    for (i = 0; i < obj.length; i++) {

        var element = obj.elements[i];

		var elementType = getType (element);

        if ((elementType == "submit" || elementType == "hidden") 

        		&& element.checkForChange == null) {

        	element.checkForChange = false;

        }

        else if (element.checkForChange == null) {

        	element.checkForChange = true;

        }

        

        if (element.checkForChange) {	

        //if (elementType != "hidden" && elementType != "submit" && !element.checkForChange) {

            if (elementType == "checkbox" || elementType == "radio") { 

                changeDataMap[element.name + element.value] = element.checked;

            }

            else if (elementType == "select-one") {

                changeDataMap[element.name] = element.selectedIndex;

            }

            else if (elementType == "select-multiple") {

                changeDataMap[element.name] = new Array();

                var sArray = changeDataMap[element.name];

                for (j = 0; j < element.length; j++) {

                    sArray[j] = element.options[j].selected;

                }

            }

            else {

                changeDataMap[element.name] = element.value;

            }

        }

    }

}



/* Compare the saved values with current values to determine whether the data has changed*/

    

function isDataChanged(obj) {

	if (obj == null) {

		return;

	}

	

    for (i = 0; i < obj.length; i++) {

        var element = obj.elements[i];

		var elementType = getType (element);

        

        if (!element.checkForChange) {

        	continue;

        }

        //alert(element.name + " old value = " +changeDataMap[element.value] + " new value = " +  element.checked);

        if (elementType == "checkbox" || elementType == "radio") {

            if (changeDataMap[element.name + element.value] != element.checked) {

                return true;

            }

        }

        else if (elementType == "select-one") {

            //alert(element.name + " old value = " +changeDataMap[element.name] + " new value = " +  element.selectedIndex);

            if (changeDataMap[element.name] != element.selectedIndex) {

                return true;

            }

        }

        else if (elementType == "select-multiple") {

            if (!compareSelect(changeDataMap[element.name], element)) {

                return true;

            }

        }

        else {

            //alert(element.name + " old value = " +changeDataMap[element.name] + " new value = " +  element.value);

            if (changeDataMap[element.name] != element.value) {

                return true;

            }

        }

    }

    return false;

}



/* check if a window is valid */

function isValidWindow(obj) {

	if (obj != null && !obj.closed) {

		return true;

	}

	else {

		return false;

	}

}



function isBlank(str) {

	str = trimString (str);

	return (str == null || str.length == 0);

}



/* Sets the size attribute of the passed object to the value in size */

function setSize(e, size) {

	var elementType = getType (e);

	if (((elementType == "text") || (elementType == "textarea"))) {

		strlens[e.name] = size; 

 	}

}



/* Get the value of the size attribute of the passed object */

function getSize(e) {

	var slen = strlens[e.name]; 

	

	if (slen) {

    	return slen;

	}

   	else {

    	return 0;

   	}

}



/* Creates an alias for the specified element */

function setTitle(obj, str) {

	names[getName (obj)] = str;

}



/* Gets the alias for the specified element */

function getTitle(obj) {

	var aName;

  

 	aName = names[getName(obj)]; 

  

  	return aName; 

}



/* mark an element as numeric */

function setNumeric(obj, bool) {

	setValidationType(obj, NUMERIC);

	obj.spaceOk = bool;

}



/* Remove Numeric validation */

function removeNumeric(obj) {

   	removeValidationType(obj, NUMERIC);

   	obj.spaceOk = false;

}





/* Function to make an input element numeric only (with a max and minimum value). */

function setNumericRange(obj, min_num, max_num) {

	setValidationType(obj, NUMERIC_RANGE);

  	setRange(obj, min_num, max_num);

}



/* Remove NumericRange validation */

function removeNumericRange(obj) {

   removeValidationType(obj, NUMERIC_RANGE);

   obj.spaceOk = false;

}



function isValidNumericRange(obj) {

	var value = trimString (obj.value);

	return (value >= obj.min && value <= obj.max);

}



  

/* Check if the given object is numeric */

function isNumeric(obj) {

	var s = trimString(obj.value);

	

	var b = obj.spaceOk;



	if (s == "")

		return true;

	

	var sPattern;

	if (b) {	

		sPattern = /[^0-9 ]/g;

	}

	else {	

		sPattern = /[^0-9]/g;

	}

		

	if (s.search(sPattern) > -1) {

		return false;

	}	



	return true;  

}



/* Check if the given object represents an integer */

function isInteger(obj) {

    var v = parseInt(obj, 10);

    if(isNaN(v)) {

        return false;

    }

    return true;    

}





function setRange(obj, min_num, max_num) {

   obj.min = min_num;

   obj.max = max_num;

}



/* mark an object to be alphaNumeric only */

function setAlphaNumeric(obj, bool) {

   setValidationType(obj, ALPHA_NUMERIC);

   obj.spaceOk = bool;

}



function removeAlphaNumeric(obj) {

   removeValidationType(obj, ALPHA_NUMERIC);

   obj.spaceOk = false;

}



/* check if an object is alphaNumeric */

function isAlphaNumeric(obj) {

	return isAlphanumeric(trimString (obj.value), obj.spaceOk);

}



/* mark an object to be alpha only */

function setAlpha(obj, bool) {

   	setValidationType(obj, ALPHA);

	obj.spaceOk = bool;

}



/* Check if an object is alpha */

function isAlpha(obj) {

	return isAlphabetic(trimString (obj.value), obj.spaceOk);

}



/* mark an object to be text containing no special chars only 

   bool is an optional argument to specify if blanks are allowed

   bool is set to true if not specified

*/

function setNoSpecialChars(obj, bool) {

   setValidationType(obj, NO_SPECIAL);

   if (setNoSpecialChars.arguments.length == 1) {

   		obj.spaceOk = true;

   }

   else {

   		obj.spaceOk = bool;

   }

}



/* Check if an object contains special chars  */

function isNoSpecialChars(obj)

{

	var s = trimString (obj.value);

	var b = obj.spaceOk;

	

	var sPattern;

	if (b) {	

		sPattern = /['\"%<>]/g;

	}

	else {	

		sPattern = /['\"%<> ]/g;

	}

	

	if (s.search(sPattern) > -1) {

		return false;

	}



    // string does not contain special characters ', ", %, <, or >

    return true;

}





/* Remove validation for NoSpecialChars */

function removeNoSpecialChars(obj) {

   removeValidationType(obj, NO_SPECIAL);

   obj.spaceOk = false;

}

/* mark an object to be street address not allowing certain characters

   bool is an optional argument to specify if blanks are allowed

   bool is set to true if not specified

*/

function setStreetAddress(obj, bool) {

   setValidationType(obj, STREET_ADDRESS);

   if (setStreetAddress.arguments.length == 1) {

   		obj.spaceOk = true;

   }

   else {

   		obj.spaceOk = bool;

   }

}



/* Check if an object contains special chars  */

function isStreetAddress(obj)

{

	var s = trimString (obj.value);

	var b = obj.spaceOk;



	var sPattern;

	if (b) {

		sPattern = /[\"%<>]/g;

	}

	else {

		sPattern = /[\"%<> ]/g;

	}



	if (s.search(sPattern) > -1) {

		return false;

	}



    // string does not contain special characters ", %, <, or >

    return true;

}





/* Remove validation for StreetAddress */

function removeStreetAddress(obj) {

   removeValidationType(obj, STREET_ADDRESS);

   obj.spaceOk = false;

}



/* set minimum length */

function setMinLength (obj, min) {

	obj.minLength = min;

}



/* set minimum length */

function removeMinLength (obj) {

	obj.minLength = null;

}





/* mark an object to be password */

function setSamePassword(obj1, obj2) {

   setValidationType(obj1, SAME_PASSWORD);

   obj1.retypePassword = obj2;

}



/* Check if the passwords are the same  */

function isSamePassword(obj)

{

	var s1 = trimString (obj.value);

	var s2 = trimString (obj.retypePassword.value);

	

	if (s1 != s2) {

		return false;

	}



    // strings are equal

    return true;

}



/* mark an object to share the same value */

function setSameValue(obj1, obj2, bool) {

   setValidationType(obj1, SAME_VALUE);

   obj1.object2 = obj2;

   obj1.share = bool;

}



/* Check if the values are the same  */

function isSameValue(obj)

{

	var s1 = trimString (obj.value);

	var s2 = trimString (obj.object2.value);

	

	if (s1 == s2) {

		return true;

	}



    // strings are not equal

    return false;

}



/* mark an object to be of type currency */

function setCurrency(obj) {

	setValidationType(obj, CURRENCY);

}



/* Check if an object is US zip code */

function isUSZipCode(obj) {

	var s = trimString(obj.value);

	if (s.search(/^(\d{5})$/g) >= 0)

	{

		return true;

	}

	else if (s.search(/^(\d{5}\-\d{4})$/g)  >= 0)

	{

		return true;

	}

	else

	{

		return false;

	}

}



/* mark an object to be of type US zip code */

function setUSZipCode(obj) {

	setValidationType(obj, US_ZIP_CODE);

}



function removeUSZipCode(obj) {

	removeValidationType(obj, US_ZIP_CODE);

}



/* Check if an object has a valid phone number format 

   Phone numbers can include space, period and hyphen

*/

function isPhone(obj) 

{

	var s = trimString(obj.value);



	if (isBlank(s))

		return true;

	

	var sPattern;

	sPattern = /[^0-9 .-]/g;

		

	if (s.search(sPattern) > -1) {

		return false;

	}	



	return true;  



}



function setPhone(obj) {

	setValidationType(obj, PHONE);

}



/* Check if an object has a valid screen name format 

   ScreenName can include hyphen and underscore

*/

function isScreenName(obj) 

{

	var s = trimString(obj.value);



	if (isBlank(s))

		return true;

	

	var sPattern;

	sPattern = /[^a-zA-Z0-9_-]/g;

		

	if (s.search(sPattern) > -1) {

		return false;

	}	



	return true;  



}



function setScreenName(obj) {

	setValidationType(obj, SCREEN_NAME);

}



/* Check if an object has a valid name format 

   names can include -, ', space, .

   However, it cannot begin with -, period, or '

   or end with - or '.

*/

function isAlphaName(obj) 

{

	var s = trimString(obj.value);



	if (isBlank(s))

		return true;

	

	var sPattern;

	sPattern = /[^a-zA-Z- .']/g;

	

	var firstChar = s.charAt(0);

	var lastChar = s.charAt(s.length-1);

		

	if (s.search(sPattern) > -1) {

		return false;

	}	

	else if (firstChar.search(/[-.']/g) > -1) {

		return false;

	}

	else if (lastChar.search(/[-']/g) > -1) {

		return false;

	}



	return true;  



}



function setAlphaName(obj) {

	setValidationType(obj, ALPHA_NAME);

}



/* Check if an object that is dependent on another object is not blank

*/

function isDependent(obj) 

{

	var s = trimString(obj.object2.value);



	if (isBlank(s)) 

	{

		return false;

	}

		

	return true;  



}



function setDependent(obj1, obj2) {

	setValidationType(obj1, DEPENDENT);

	obj1.object2 = obj2;

}



function removeDependent(obj) {

	obj.validationType = null;

	obj.object2 = null;

}



/* Check if the credit card expiration date has expired

*/

function isCCExpired(obj) 

{

	var month = trimString(obj.value);

	var year = trimString(obj.object2.value);



	var currDate = new Date();

	var currYear = currDate.getFullYear();

	var currMonth = currDate.getMonth() + 1;



	var flag = true;



	if (year > currYear) {

		flag = false;

	}

	else if (year < currYear) {

		flag = true;

	}

	else if (year == currYear) {

		if (month >= currMonth) {

			flag = false;

		}

		else {

			flag = true;

		}

	}

		

	return flag;  



}





/*	Sets the credit card expiration date where:

	obj1 is the month and

	obj2 is the year

*/

function setCCExpirationDate(obj1, obj2) {

	setValidationType(obj1, CC_EXPIRATION_DATE);

	obj1.object2 = obj2;

}





function isCurrency(obj) {

	return isFloat(trimString (obj.value));

}



/* mark an object to be of type percent */

function setPercent(obj) {

	setValidationType(obj, PERCENT);

}



function isPercent(obj) {

	return isFloat(trimString (obj.value));

}



function setEmail(obj) {

	setValidationType(obj, EMAIL);

}


function setNoOfChildtrenParent(obj) {

	setValidationType(obj, NOCP);

}


function setNotEmail(obj) {

	setValidationType(obj, NOT_EMAIL);

}





function setDate(obj) {

	setValidationType(obj, DATE);

}



function setDate (obj, obj2, obj3) {

	setValidationType(obj, DATE);

}



function isEmail(obj) {

	return isValidEmail(trimString (obj.value));

}





function isDate(obj) {

	var dateStr = trimString(obj.value);

	if (isBlank(dateStr)) {

		return false;

	}



	var index = dateStr.indexOf('/');

	var month = dateStr.substring(0, index);

	dateStr = dateStr.substring(index+1);

	index = dateStr.indexOf('/');

	var day = dateStr.substring(0, index);

	var year = dateStr.substring(index+1);

	

	return isValidDate(year, month, day);

}







/* Function to allow the field to remain optionally blank */

function setOptional(obj) {

   obj.optional = true;

}



/* Function to allow the field to remain optionally blank. */

function ignore(obj) {   

	if (obj != null) {      

   		obj.optional = true; 

		var atype = getType (obj);   

		if ( (atype == "radio" || atype == "checkbox") && typeof obj.length != "undefined") 

		{

			for (var i = 0; i < obj.length; i++) {

  				obj[i].optional = true;

   			}

  		}

	}

}



/* Function to force a field to be validated */

function unignore(obj) {   

	if (obj != null) {

   		obj.optional = false;

		var atype = getType (obj);   

		if ( (atype == "radio" || atype == "checkbox") && typeof obj.length != "undefined") 

		{

			for (var i = 0; i < obj.length; i++) {

  				obj[i].optional = false;

   			}

  		}

   	}

}



/* Basic validation function. This should always be the 

	last function called from the validation object.

*/ 

function validate(f) {

    var msg = "";

    var foc;

    var empty_fields = "";

    var error;

	var errors = "";

	var warnings = "";

    for (var i = 0; i < f.length; i++) {

        var error = false;

        var e = f.elements[i];

		var elementType = getType (e);

        var eTitle = getTitle(e);

		if (!e.optional) {

	        if (elementType == "select-one" || elementType == "select-multiple") {

	            if ((e.selectedIndex < 0) || 

						isBlank(e.options[e.selectedIndex].value)) {	

	                empty_fields += returnAndSpaces + eTitle;

	                error = true;

	            }

	        }

	        

	        else if (((elementType == "checkbox") || (elementType == "radio"))) {

		        var alreadyChecked = false;                        

		       // alert(i);

		        for (k = 0; k < i; k++) {

		            if (f.elements[k].name == e.name) {

		                alreadyChecked = true;

		                break;

		            }   

		        }



	            if (!alreadyChecked) {

	                var checked = false;

	                if (e.checked) {

	                    checked = true;

	                } 

					else {

		            	var name = e.name;

		               // alert(e.value);

		                for (j = 0; j < f.length; j++) {

		                	if (f.elements[j].name == name) {

		                    	if (f.elements[j].checked) {

		                        	checked = true;

		                             //alert(f.elements[j].value);

		                            break;

		                        }

		                    }   

		                }

					}   



                    if (!checked) {

                         empty_fields += returnAndSpaces + eTitle;       

                         error = true;

                    }   

	          	}   

	     	}

				

     		else if((elementType == "text") || (elementType == "textarea") 

					|| (elementType == "password")) {

        		//*** check if empty ***

        		if (isBlank(trimString(e.value))) {

					empty_fields += returnAndSpaces + eTitle;

					error = true;

          			if (!foc) { 

            			foc = f.elements[i];

        			}

        		}

			}

		}

		

		/* Check for special validation requirements */

		if ((e.validationType != null) 

				&& (elementType == "text" || elementType == "password" 

				|| elementType == "textarea" || elementType == "select-one") 

				&& !isBlank(getSelectedValue(e))) {



			//loop thru all the validation requirements

			for (var vcnt=0; vcnt<e.validationType.length; vcnt++) {

			

				var valType = e.validationType[vcnt];


				switch(valType) {

				

				case 1: //NUMERIC

					if (!isNumeric(e)) {

		        		errors += eTitle + " must contain Numeric values.\n\n";

						error = true;

					}

					break;

				case 2: //ALPHA

					if (!isAlpha(e)) {

						errors += eTitle + " must contain only Alphabetic characters.\n\n";

						error = true;

					}

					break;

				case 3: //ALPHA_NUMERIC

					if (!isAlphaNumeric(e)) {

						errors += eTitle + " can only contain Alphanumeric characters.\n\n";

						error = true;

					}

					break;

				case 4: //FLOAT

					break;

				case 5: //CURRENCY

					if (!isCurrency(e)) {

						errors += eTitle + " must contain a Currency value (i.e. 2,300.00).\n\n";

						error = true;

					}

					break;

				case 6: //DATE

					if (!isDate(e)) {

						errors += eTitle + " must be a valid date in mm/dd/yyyy format.\n\n";

						error = true;

					}

					break;

				case 7: //EMAIL

					if (!isEmail(e)) {

						errors += eTitle + " must be a valid Email address in 'user@somedomain.com' format.   \n\n";

						error = true;

					}

					break;

				case 8: //CREDIT_CARD

					break;

				case 9: //NUMERIC_RANGE

					if (!isValidNumericRange(e)) {

						errors += "The field " + eTitle + " should have a value" 

							+ " between " + e.min + " and " + e.max + ".\n\n";

						error = true;

					}

		            break;

				case 10: //PERCENT

					if (!isPercent(e)) {

						errors += "The field " + eTitle + " should be of type 'Percent'.\n\n";

						error = true;

					}

					break;	

				case 15: //US_ZIP_CODE

					if (!isUSZipCode(e)) {

						errors += eTitle + " is not a valid US Zip Code format.  Please use the format of 12345 or 12345-6789.\n\n";

						error = true;

					}

					break;		

				case 16: //NO_SPECIAL

					if (!isNoSpecialChars(e)) {

						errors += "The field " + eTitle + " should not contain any special characters, for example: ', \", %, <, or >.\n\n";

						error = true;

					}

					break;	

				case 17: //SAME_PASSWORD

					if (!isSamePassword(e)) {

						errors += "The field " + getTitle(e.retypePassword) + " should be the same as the " + eTitle + ".\n\n";

						error = true;

					}

					break;	

				case 18: //SAME_VALUE

					if (isSameValue(e)) {

						//if sharing is allowed, then only throw warning

						if (e.share)  {

							if (!e.warned)  {

								warnings += "WARNING: The field " + eTitle + " is the same as the " + getTitle(e.object2) + ".\n\n";

								e.warned = true;

							}

						}

						else  {

							errors += "The field " + eTitle + " should NOT be the same as the " + getTitle(e.object2) + ".\n\n";

							error = true;

						}	

					}

					break;		VALID_RANGE

				case 19: //VALID_RANGE

					if (!isValidRange(e)) {

						errors += "The field " + eTitle + " should be greater than the " + getTitle (e.minObj) + ".\n\n";

						error = true;

					}

					break;	

				case 20: //PHONE

					if (!isPhone(e)) {

						errors += eTitle + " is not a valid Phone Number format.  Please use only spaces, periods, or hyphens in the phone number.\n\n";

						error = true;

					}

					break;	

				case 21: //DEPENDENT

					if (!isDependent(e)) {

						errors += "The selected option for the field " + eTitle + " cannot be chosen since the " + getTitle(e.object2) + " has not been provided.\n\n";

						error = true;

					}

					break;

				case 22: //SCREEN_NAME

					if (!isScreenName(e)) {

						errors += "The field " + eTitle + " should be of type 'Screen Name'; alphanumeric and only hyphens and underscores can be used.\n\n";

						error = true;

					}

					break;	

				case 23: //ALPHA_NAME

					if (!isAlphaName(e)) {

						errors += "The field " + eTitle + " should be of type 'Name'.\n\n";

						error = true;

					}

					break;		

				case 24: //CC_EXPIRATION_DATE

					if (isCCExpired(e)) {

						errors += "The field Expiration Date has expired.\n\n";

						error = true;

					}

					break;

				case 25: //NOT_EMAIL

					if (isEmail(e)) {

						errors += "The field " + eTitle + " should not be of type 'Email'.\n\n";

						error = true;

					}

					break;
			    case 26: //STREET_ADDRESS

					if (!isStreetAddress(e)) {

						errors += "The Street Address field " + eTitle + " should not contain any special characters, for example: \", %, <, or >.\n\n";

						error = true;

					}

					break;

				default:

					alert("Unknown validation type = " + valType + ".");

					break;

				}

			}

		}	

		

		//check for minimum length requirements

		//alert("e.minLength="+e.minLength);

		if ((e.minLength != null) 

				&& (elementType == "text" || elementType == "password" 

				|| elementType == "textarea") 

				&& !isBlank(trimString(e.value))) {	

			if (trimString(e.value).length < e.minLength) {			

				errors += "The field " + eTitle + " should have a minimum length of " + e.minLength + " characters.\n\n";

				error = true;

			}	

		}

		

    }

	

          

	if (!empty_fields && !errors && !warnings) {

		return true;

	}


	if (!foc) {

		foc = f.elements[i];

	}



	msg = "__________________________________________________\n\n"

	msg += "The form was not submitted because of the following error(s).\n";

	msg += "Please correct these error(s) and re-submit.\n";

	msg += "__________________________________________________\n\n"



	if (empty_fields) {

		if(!foc) {

			foc = f.elements[i];

		}

		msg += "The following required field(s) are empty:" + empty_fields + "\n";

		if (errors) {

			msg += "\n";

		}

	}

	msg += errors + "\n" + warnings;

	alert(msg);
	
	if(foc) {

		foc.focus();

	}

	foc = null;

	errors = "";

	warnings = "";
	
	msg = "";

	return false;

}



function submitForm(f) {
	if (validate(f)) {

		f.submit();

	}

}



function submitFormAndClose (f) {

	//only close the window if the validate was successful

	if (validate(f)) 

	{

		f.submit();

		window.close();

	}	

}



function doCommand(f, cmdName) {

	f.command.value=cmdName;

	submitForm(f);

}



function clearForm(f) {

	for (var i = 0; i < f.length; i++) {

		var e = f.elements[i];

		var elementType = getType (e);



	    if (elementType == "select-one" || elementType == "select-multiple") {

	        e.selectedIndex = -1;

	    }

	    

	    else if ((elementType == "checkbox") || (elementType == "radio")) {

			e.checked = false;

		}



	    else if((elementType == "text") || (elementType == "textarea") 

				|| (elementType == "password")) {

			e.value = "";

		}

		

	}

}



function closeWindow() {

	window.close('_self');

}



function gotoURL(url) {

	if (navigator.appName=="Netscape") {

    	window.location = url; 

    }

    else {

   		window.location.replace(url);

    }

}

	

function itemSelected(selectObj, destURI) {

	var selectedIndex=selectObj.selectedIndex;



    if (selectedIndex == 0) {

    	return;

	}



	var selectedValue=selectObj.options[selectedIndex].value;

	var url = destURI + "?id=" + selectedValue;  

	

	gotoURL(url);

    

}



function checkButtonClicked(radioObj, destURI) {



	var selectedValue=radioObj.value;

	var url = destURI + "?id=" + selectedValue;  



    gotoURL(url);

}



function popup(popupSrc) {

  	var thePopup =

    window.open(popupSrc, "Details", "scrollbars,width=550,height=580");

  	thePopup.focus();

}



//this returns the first selected value of the selected object

/*

function getSelectedName (obj) 

{	

	//do not use this function...it will be removed once all the

	//reference to it has been removed

	return getSelectedValue (obj);

}

*/



function getSelectedValue(obj) 

{

	var s = "";	

	

	var type = getType (obj);		



	if (type == "radio" || type=="checkbox") 

	{

		if (typeof obj.length != "undefined") 

		{

			for (var i=0; i<obj.length; i++) 

			{

				if (obj[i].checked) 	

				{

					s = obj[i].value;

					break;

				}

			}		

		}

		else 

		{

			if (obj.checked) 	

			{	

				s = obj.value;

			}

		}

	}	

	else if (type == "select-one" || type == "select-multiple") 

	{

		if (obj.selectedIndex > -1)

			s = obj.options[obj.selectedIndex].value;

	}	

	else 

	{ 		

		s = obj.value;

	}	



	return trimString (s);

}



function setValidationType (obj, vtype) {

	if (obj.validationType != null) {

		obj.validationType[obj.validationType.length] = vtype;

	}

	else {

		//put validation type into array

		var vArray = new Array;

		vArray[0] = vtype;

		obj.validationType = vArray;

	}

}



function removeValidationType (obj, vtype) {

	//alert("removeValidationType, obj:"+obj +", and vtype:"+vtype);

	if (obj != null) {

		if (obj.validationType != null) {

			if (obj.validationType.length == 1) {

				obj.validationType = null;

			}

			else {

				//remove from array

				var vArray = new Array;

				var index = 0;

				for (var i=0; i<obj.validationType.length; i++) {

					if (obj.validationType[i] != vtype) {

						vArray [index] = obj.validationType[i];

						index++;

					}

				}

				obj.validationType = vArray;

			}		

		}

	}

	

}





/* getType gets the type of the object */

function getType(obj) {

	var atype;



  	if (obj == "[object InputArray]") {

  		atype = obj[0].type;

  	}

	else if (obj.type)  

	{ 	

		atype = obj.type;

	}

	else 

	{	if (typeof obj.length != "undefined")  

		{ 	

			atype = obj[0].type;

		}

		else 

		{

			atype = obj.type;

		}

	}



	return atype; 

}



/* getName gets the name of the object */

function getName(obj) {

	var aName;

	/*

	if (getType(obj) == "radio") {

		if (typeof obj.length != "undefined")  

		{ 	

			aName = obj[0].name;

		}

		else 

		{

			aName = obj.name;

		}

	}

	else {

		aName = obj.name;

	}

	*/

	

	if (obj == "[object InputArray]") {

  		aName = obj[0].name;

  	}

        else if (obj.name)  

  	{ 	

  		aName = obj.name;

  	}

  	else 

	{	if (typeof obj.length != "undefined")  

		{ 	

			aName = obj[0].name;

		}

		else 

		{

			aName = obj.name;

		}

	}



  	return aName; 

}







/*  selectedCount (obj) returns the # of checked items

	an object array is expected

*/

function selectedCount (obj) 

{	var cnt = 0;



	//check that obj exists

	if (obj) 

	{

		if (obj.name)  

		{ 	

			if (obj.checked) 

			{

				cnt++;

			}

		}

		else 

		{

			for (var i=0; i<obj.length; i++) 

			{

				if (obj[i].checked) 

				{

					cnt++;

				}

			}

		}

	}

	return cnt;

}	



/* determines whether the state is required or should be ignored

   based on the value of the selected country; 

   also determines if the zip code should be validated for correct format

   obj is the country object

   sobj is the corresponding state object

   zobj is the corresponding zip code object

*/

function validateCountryAndState(obj, sobj, zobj) {

	//if country = US or Canada, then state/province is required

	var selectedCountryName = getSelectedValue(obj);

	

	if (selectedCountryName == "us") { 

		unignore(sobj);

		if (zobj != null) {				

			removeAlphaNumeric(zobj);

			setUSZipCode(zobj);	

		}

		unignore(zobj);	

	}

	else if (selectedCountryName == "ca") {

		unignore(sobj);

		if (zobj != null) {

			removeUSZipCode(zobj);

			setAlphaNumeric(zobj, true); 

		}

		unignore(zobj);

	}

	else {

		ignore(sobj);

		if (zobj != null) {		

			removeUSZipCode(zobj);

			setAlphaNumeric(zobj, true); 	 

		}

		ignore(zobj);

	}

}



/* disableFields (obj, farray [, values]) disables the fields

   obj is the value object (checkbox expected) to determine if 

     the objects in the farray should be disabled

   farray is the array of objects to disable

   values is an optional argument that contains the original values

   this works in IE only and is used only to take advantage of the disable tag;      for a nicer UI display; works in conjunction with disableObject function

disableFields(addressFields.rootField, addressFields, sameAddrValues);

*/

function disableFields(obj, farray, values) {

	if (obj.checked) {

        for (var i=0; i<farray.length; i++) {

			farray[i].value = values[i];   

		    if (isIE) {

                farray[i].disabled = true;

            }

        }

	}

	/*else {	

		for (var i=0; i<farray.length; i++) {

			//reset to original value

			if (isIE) {

				farray[i].disabled = false;

			} 

			if (disableFields.arguments.length > 2) {

	   			farray[i].value = values[i];

				//farray[i].value="";

    		}

        }

    }*/
    //Modified by Amit Goyal to reset the fields of the form block when the user unchecks the "Same As" checkbox
	else  {

		if (isIE)  {

			for (var i=0; i<farray.length; i++) {

				//farray[i].value = values[i];
                                farray[i].value="";
                                farray[i].disabled = false;				

			}			

        }

    }



}     



/* disableObject (obj, sobj) keeps a field from getting focus

   obj is the object to prevent from getting focus

   vobj is the value object (checkbox expected) to determine if 

     obj should receive focus

   e.g. <input type="text" name="billZip" onfocus="keepFocus(this, )"/>

*/

function disableObject(obj, sobj)

{

	if (sobj.checked)

    {

        obj.blur();

	}

}





/* confirmDelete(f, obj) confirms if a user wants to delete the 

   selected records where:

     f is the form

     obj is the object (array expected) that has the value(s) 

	     marked for deletion

 */

function confirmDelete(f, obj)

{

	var deleteCnt = selectedCount (obj);

	

	if (deleteCnt == 0)  

	{

		alert ("Please select at least one record to delete.");

	} 

	else 

	{

		if (deleteCnt == 1)

			var confirmMsg = "Please confirm that you would like to delete this record by clicking the OK button below.  You will not be able to access the deleted record once it has been removed."

		else

			var confirmMsg = "Please confirm that you would like to delete these records by clicking the OK button below.  You will not be able to access the deleted records once they have been removed."

			

		if (confirm (confirmMsg)){

			f.privoCommand.value="delete";

			f.submit();

		}

	}

}



/* confirmCopy (f, obj) confirms that only one record is selected where:

	 f is the form

     obj is the object (array expected) that has the selected value(s)

 */

function confirmCopy(f, obj){



	var cnt = selectedCount (obj);

	

	if (cnt == 0){

		alert ("Please select one record.");

	} 

	else if (cnt == 1) {

		f.privoCommand.value="copy";

		f.submit();

	}

	else if (cnt > 1) {

		alert ("Only one record can be selected.");

	}

}



/* confirmRun (f, obj) confirms that only one record is selected where:

	 f is the form

     obj is the object (array expected) that has the selected value(s)

 */

function confirmRun(f, obj){



	var cnt = selectedCount (obj);

	

	if (cnt == 0){

		alert ("Please select one record.");

	} 

	else if (cnt == 1) {

		f.privoCommand.value="run";

		f.submit();

	}

	else if (cnt > 1) {

		alert ("Only one record can be selected.");

	}

}



/* confirmSelection (f, obj) confirms that only one record is selected where:

	 f is the form

     obj is the object (array expected) that has the selected value(s)

 */

function confirmSelection(f, obj)

{

	var cnt = selectedCount (obj);

	

	if (cnt == 0)  

	{

		alert ("Please select one record.");

	} 

	else if (cnt == 1)

                f.submit();

	else if (cnt > 1)

		alert ("Only one record can be selected.");

        
              
}





/*	hasSelectedCriteria (varray) determines if at least one of the 	

	object in varray has a value

*/

function hasSelectedCriteria (varray) 

{

	var rtn = false;

	for (var i=0; i<varray.length; i++) 

	{

	

		if (!isBlank (getSelectedValue(varray[i])))

		{

			rtn = true;

			break;

		}

	}



	return rtn;

}



/*	setValidRange (obj, minObj) sets the object to be of 

		type VALID_RANGE where:

		obj is the max object and

		minObj is the min object

*/

function setValidNumberRange (obj, minObj) 

{

	setValidationType (obj, VALID_RANGE);

	obj.minObj = minObj;

	obj.rangeType = NUMERIC;

}



/*	setValidRange (obj) determines if the object values

		form a valid range

*/

function isValidRange (obj) 

{

	var value = trimString (obj.value);

	var minValue = trimString (obj.minObj.value);

	if (!isBlank(value) && !isBlank(minValue)) {

		switch (obj.rangeType) 

		{

			case 1:	//NUMERIC

				return (parseInt(value) > parseInt(minValue));

				break;

			default:

				return (value > minValue);

				break;	

		}

	}			

	else

		return true;	

}

