// VARIABLE DECLARATIONS
var fct_win =null;
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 = "."
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in US phone numbers
var validUSPhoneChars = digits + phoneNumberDelimiters;
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = digits + phoneNumberDelimiters + "+";


// CONSTANT STRING DECLARATIONS
// (grouped for ease of translation and localization)

// m is an abbreviation for "missing"

var mPrefix = "You did not enter a value into the "
var mSuffix = " field. This is a required field. Please enter it now."

// i is an abbreviation for "invalid"

var iUSPhone = "This field must be a 10 digit U.S. phone number (like 415 555 1212). Please reenter it now."
var iWorldPhone = "This field must be a valid international phone number. Please reenter it now."
var iEmail = "Email must be in a format like (foo@bar.com), Please reenter it now."
var iMileage = "Milage must be a positive integer, Please reenter it now."
var iPrice = "Estimated Price is positive integer and should not contain any '$' symbol, Please reenter it now."
var iCreditCardPrefix = "This is not a valid "
var iCreditCardSuffix = " credit card number. (Click the link on this form to see a list of sample numbers.) Please reenter it now."
var iDay = "Valid day range is from 1 to 31 . Please reenter it now."
var iMonth = "Valid day range is from 1 to 12 . Please reenter it now."
var iYear = "Valid year is a 4 digits positive integer > 1990 and < 2047. Please reenter it now."
var iDate = "Invalid Date Format. Please reenter it now."
var iDatePrefix = "The Year, Month or Day Values in"
var iDateSuffix = " will not make up a valid Date, Please reenter it now."
var iPassYear = "This field must be less than current year.  Please reenter it now."
var iYearValue = "Input Year exceed the current year.   Please reenter it now."

var pEntryPrompt = "Please enter  "
var pStateCode = "2 character code (like CA)."
var pZIPCode = "5 or 9 digit U.S. ZIP Code (like 94043)."
var pWorldPhone = "Internation phone format"
var pUSPhone = "10 digit U.S. phone number (like 415 555 1212)."
var pSSN = "9 digit U.S. social security number (like 123 45 6789)."
var pCreditCard = "valid credit card number."
var pEmail = "Valid Email format will be (foo@bar.com)"
var pDay = "an integer within 1 to 31"
var pMonth = "an integer within 1 to 12"
var pYear = "a 2-digit or a 2-digit integer within 1 to 13"
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;

    if (isEmpty(s)) 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 = "";

    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 stripCharsNotInBag (s, bag)

{   var i;
    var 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 charInString (c, s)
{   for (i = 0; i < s.length; i++)
    {   if (s.charAt(i) == c) return true;
    }
    return false
}


function stripInitialWhitespace (s)

{   var i = 0;

    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;
    
    return s.substring (i, s.length);
}

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function promptEntry (s)
{   window.status = pEntryPrompt + s
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}


function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}

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;
}

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(startPos) == "-") || (s.charAt(startPos) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}

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) ) );
}



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) ) );
}



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) ) );
}


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) ) );
}


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;

    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;
}

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(startPos) == "-") || (s.charAt(startPos) == "+") )
           startPos = 1;    
        return (isFloat(s.substring(startPos, s.length), secondArg))
    }
}

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;
}

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 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 isUSPhoneNumber (s)
{   if (isEmpty(s)) 
       if (isUSPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isUSPhoneNumber.arguments[1] == true);
    return (isInteger(s) && s.length == digitsInUSPhoneNumber)
}

function isInternationalPhoneNumber (s)
{   if (isEmpty(s)) 
       if (isInternationalPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isInternationalPhoneNumber.arguments[1] == true);
    return (isPositiveInteger(s))
}


function isEmail (emailStr) {
		if (isEmpty(emailStr)) 
		   if (isEmail.arguments.length == 1) return defaultEmptyOK;
		   else return (isEmail.arguments[1] == true);

		// is emailStr whitespace?
		if (isWhitespace(emailStr)) return false;

	/* The following pattern is used to check if the entered e-mail address
	   fits the user@domain format.  It also is used to separate the username
	   from the domain. */
	var emailPat=/^(.+)@(.+)$/
	/* The following string represents the pattern for matching all special
	   characters.  We don't want to allow special characters in the address. 
	   These characters include ( ) < > @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	/* The following string represents the range of characters allowed in a 
	   username or domainname.  It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]"
	/* The following pattern applies if the "user" is a quoted string (in
	   which case, there are no rules about which characters are allowed
	   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	   is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")"
	/* The following pattern applies for domains that are IP addresses,
	   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	   e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	/* The following string represents an atom (basically a series of
	   non-special characters.) */
	var atom=validChars + '+'
	/* The following string represents one word in the typical username.
	   For example, in john.doe@somewhere.com, john and doe are words.
	   Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	/* The following pattern describes the structure of a normal symbolic
	   domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


	/* Finally, let's start trying to figure out if the supplied address is
	   valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	   different pieces that are easy to analyze. */
	var matchArray=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. */
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	// See if "user" is valid 
	if (user.match(userPat)==null) {
		// user is not valid
		return false
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	   host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		// this is an IP address
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
			return false
			}
		}
		return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		return false
	}

	/* domain name seems valid, but now make sure that it ends in a
	   three-letter word (like com, edu, gov) or a two-letter word,
	   representing country (uk, nl), and that there's a hostname preceding 
	   the domain or country. */

	/* Now we need to break up the domain to get a count of how many atoms
	   it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	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.
	   return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   var errStr="This address is missing a hostname!"
	   return false
	}

	// If we've gotten this far, everything's valid!
	return true;
}

function isYear (s)
{   if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
    if (!isNonnegativeInteger(s)) return false;
	if (eval(s) < 1900 || eval(s) > 2047 ) return false;
    return ((s.length == 4));
}

function isPassYear(s)
{   
	if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);

	var cur_date = new Date()
	var cur_year = 1900 + parseInt(cur_date.getYear())
	var inp_year = (s.length == 2) ? 1900 + parseInt (s,10) : parseInt (s,10)
	if  (inp_year <= cur_year) 
		return true;
	else
    	return false;
}

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));
}

function isMonth (s)
{   if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}


function isDay (s)
{   if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 1, 31);
}

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 );
}


function isDate (year, month, day)
{   // catch invalid years (not 2- or 4-digit) and invalid months and days.
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;

    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}




function warnEmpty (theField, s)
{   
	if (theField.type == "text" && !theField.readOnly && !theField.disabled)
		theField.focus()
    alert(mPrefix + s + mSuffix)
    return false
}


function warnInvalid (theField, s)
{   	
	if (theField.type == "text" && !theField.readOnly && !theField.disabled){
		theField.focus()	
	    theField.select()
	}
    alert(s)
    return false
}

function tocomma_number(val, dpoint)
{   
	var tStr, s;
    var sPos = 0;
    var resultString = "";
	
	s = stripCharsInBag(val, ","); 
	sPos = s.indexOf(".")

	if (sPos > 0)
	{
		tStr = s.substring(0,sPos)
		if ((sPos - s.length) < 10)	s += "0000000000"
	}
	else
	{
		tStr = s
		s +=  ".0000000000000"
		sPos = s.indexOf(".")
	}

    resultString = tStr.substring(tStr.length-3, tStr.length);		
	tStr = tStr.substring(0, tStr.length-3);
    for (; tStr.length > 3;) {
    	resultString = tStr.substring(tStr.length-3, tStr.length) + "," + resultString
		tStr = tStr.substring(0, tStr.length-3);
    }

	if (tStr.length > 0)
    	resultString = tStr.substring(tStr.length-4, tStr.length) + "," + resultString

	
	resultString +=  s.substring(sPos, sPos + dpoint + 1)
    return resultString;
}


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;
}

// checkRetype (TEXTFIELD thePwd, TEXTFIELD theRetype, STRING s, [, BOOLEAN emptyOK==false])
function checkRetype (thePwd, theRetype, s, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (theRetype.value != thePwd.value)
         return warnInvalid (theRetype, s);
    else return true;
}

// checkAmount (TEXTFIELD thePwd, TEXTFIELD theRetype, STRING s, [, BOOLEAN emptyOK==false])
function checkAmount (theField, s, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.	
    if (checkAmount.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (isFloat(stripCharsInBag(theField.value, ","), emptyOK) == false ) 
           return warnInvalid (theField, s + " must be a number.");
    else return true;
}

// checkAmount (TEXTFIELD thePwd, TEXTFIELD theRetype, STRING s, [, BOOLEAN emptyOK==false])
function checkNonZeroAmount (theField, s, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
        var tmp_num
    if (checkNonZeroAmount.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
        tmp_num = parseFloat(stripCharsInBag(theField.value, ","))
    if (isFloat(stripCharsInBag(theField.value, ","), emptyOK) == false ) 
           return warnInvalid (theField, s);
        if (tmp_num <= 0.0) 
           return warnInvalid (theField, s);
    else return true;
}

// check100Percent (TEXTFIELD thePwd, TEXTFIELD theRetype, STRING s, [, BOOLEAN emptyOK==false])
function check100Percent (theField, s, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
        var tmp_num
    if (check100Percent.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
        tmp_num = parseFloat(stripCharsInBag(theField.value, ","))
    if (isFloat(stripCharsInBag(theField.value, ","), emptyOK) == false ) 
           return warnInvalid (theField, s);
    if (tmp_num < 0.0 || tmp_num > 100.0) 
           return warnInvalid (theField, s);
    else return true;
}


function checkInternationalPhone (theField, emptyOK)
{   if (checkInternationalPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  if (!isInternationalPhoneNumber(theField.value, false)) 
          return warnInvalid (theField, iWorldPhone);
       else return true;
    }
}

function checkEmail (theField, s, emptyOK)
{   if (checkEmail.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else if (!isEmail(theField.value)) 
       return warnInvalid (theField, s);
    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 checkPassYear (theField, emptyOK)
{   if (checkPassYear.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isYear(theField.value)) 
       return warnInvalid (theField, iYear);
    if (!isPassYear(theField.value)) 
       return warnInvalid (theField, iPassYear); 
    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 (yrField, mthField, dayField, emptyOK)
{   if (checkDate.arguments.length == 3) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(yrField.value) && isEmpty(mthField.value)&& isEmpty(dayField.value))) return true;
    if (!isDate(yrField.value, mthField.value, dayField.value, false)) 
       return warnInvalid (mthField, iDate);
    else return true;
}

function checkYMDDate (theField, s, emptyOK)
{   
	var datePat=/(\w+)-(\w+)-(\w+)/
	if (checkYMDDate.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && isEmpty(theField.value)) return true;
	var matchDateArray=theField.value.match(datePat);
	if (matchDateArray==null) 
		return warnInvalid (theField, s);
    if (!isDate(matchDateArray[1],matchDateArray[2],matchDateArray[3], false))
       return warnInvalid (theField, s);
    else return true;
}

function checkSelectList(theField, s)
{
	for(val = 999, j=0; j < theField.length; j++)
	{	
		if (theField.options[j].selected == true)
		{
			val = theField.options[j].value 
			break;
		}
	}

	if (val == 999) 
		return warnEmpty (theField, s)
	else 
		return true;
}

function GetFieldVal(theForm, theFieldname)
{
        var fld = null;
    if (theFieldname == null) return null;
    if (theForm == null) return null;

     for (i = 0; i < theForm.elements.length; i++)
     {
	   fld = theForm.elements[i];

		if (fld.name == theFieldname)
		{
			if (fld.type != null)
			{          
				if ((fld.type == "text") || (fld.type == "textarea") ||
					(fld.type == "hidden") || (fld.type == "password")) 
					{return fld.value;}
				else if (fld.type == "radio") 
					{if (fld.checked == true) return fld.value;}
				else if ((fld.type == "checkbox") && (fld.checked == true))
					{return fld.value;}
				else if (fld.type == "select-one")
					{						 
						 if (fld.options.length > 0)
						 {
								idx = fld.options.selectedIndex;
								return fld.options[idx].value;
						 }
					}
			}                        
		}
	}
	return null;     
}

function checkRequiredFields(input, requiredFields, fieldNames)
{       
    var fieldCheck   = true;
    var fieldsNeeded = "\nA value must be entered in the following field(s):\n\n\t";
        var Notpassed = 0;
    for(var fieldNum=0; fieldNum < requiredFields.length; fieldNum++) {
        valstr = GetFieldVal(input, input.elements[requiredFields[fieldNum]].name);             
        if ((valstr == "") || (valstr == " ")) {
            fieldsNeeded += fieldNames[fieldNum] + "\n\t";
            if (Notpassed == 0) Notpassed = fieldNum;
            fieldCheck = false;
        }
    }

    // ALL REQUIRED FIELDS HAVE BEEN ENTERED
    if (fieldCheck == true)
    {
        return true;
    }
    // SOME REQUIRED FIELDS ARE MISSING VALUES
    else
    {
		alert(fieldsNeeded);
		theField = input.elements[requiredFields[Notpassed]];
		if (theField.type == "text" && !theField.readOnly && !theField.disabled)
			input.elements[requiredFields[Notpassed]].focus();
        return false;
    }
}

function show_functionwin(nHeight,nWidth,url,win_id ){

var nXpos = (screen.availWidth - nWidth -10);
var nYpos = (screen.availHeight - nHeight) / 2;
var statusPopup =
	window.open(url, win_id,
                  'top=' + nYpos + ',left=' + nXpos +
                  ',screenY=' + nYpos + ',screenX=' + nXpos +
                  ',height=' + nHeight + ',width=' + nWidth +'status=no,toolbar=no,menubar=no,location=no');	 
	return 	statusPopup;
}


function show_popupwin(nHeight,nWidth,url,win_id ){

var nXpos = (screen.availWidth - nWidth)/2;
var nYpos = (screen.availHeight - nHeight) / 2;
var statusPopup =
		window.showModalDialog(url,win_id,
			"dialogHeight: "+ nHeight + "px; dialogWidth: " + nWidth + "px; dialogTop: " + nYpos + "px; dialogLeft: " + nXpos +"px; edge: Raised; center: Yes; help: No; resizable: Yes; status: Yes;");
			
}

