//initialize the FieldInfoArray
FieldInfoArray = new Array();
iNumFields = 0;


/**
@Function boolean isBlank
	@Param String sName
	@Param String sType
	@Param Form formPanel
	Retruns true if the field named sName of type sType on form formPanel has a blank value.
		text/textarea - no characters in the value
		select list - no options selected or the item selected has no value
		checkbox || radio buttons - no options are checked
*/
function isBlank (sName, sType, formPanel)
{
	//alert ("Running isBlank for " + sName + " - " + sType);
	var bIsBlank = false;
	if (sType == null)
	{
		sType = getFieldType(sName);
	}
	
	if (sType == "text" || sType == "textarea" || sType == "password" || sType == "file")
	{
		if (formPanel.elements[sName].value == "")
		{
			bIsBlank = true;
		}
	}
	if (sType == "select-one" || sType == "select-multiple")
	{
		var iSel = formPanel.elements[sName].selectedIndex;
		if (iSel != -1)
		{
			if (formPanel.elements[sName].options[iSel].value == "")
			{
				bIsBlank = true;
			}
		}
		else
		{
			bIsBlank = true;
		}
	}
	if (sType=="checkbox" || sType == "radio")
	{
		var bIsChecked = false;
		
		if (formPanel.elements[sName].length == null)
		{
			if (formPanel.elements[sName].checked)
			{
				bIsChecked = true;
			}
		}
		else
		{
			for (var iNum = 0; iNum < formPanel.elements[sName].length; iNum++)
			{
				if (formPanel.elements[sName][iNum].checked)
				{
					bIsChecked = true;
					iNum = formPanel.elements[sName].length;
				}
			}
		}		
		
		//* 
		//  commented out by DMP 6/10/02 because of 
		//  performance problems with this implementation 
    	//*
		//var sCheckName;
		//for (var iNum = 0; iNum < formPanel.elements.length; iNum++)
		//{
		//	sCheckName = formPanel.elements[iNum].name;
			//alert ("checking " + sCheckName + " for blank value");
		//	while (sName == sCheckName)
		//	{
		//		if (formPanel.elements[iNum].checked)
		//		{
		//			var bIsChecked = true;
		//		}
		//		iNum++;
		//		if (iNum < formPanel.elements.length)
		//		{
		//			sCheckName = formPanel.elements[iNum].name;
		//		}
		//		else
		//		{
		//			sCheckName = "";
		//		}
		//	}
		//}
		
		if (!bIsChecked)
		{
			bIsBlank = true;
		}
		
	}
	return bIsBlank;
} /* end isBlank function */


/**
@Function boolean isInteger
	@Param String sString
	Retruns true if the string sString represents an integer value.
*/
function isInteger(sString)
{
	var iLimit = 0;
	if(isInteger.arguments.length == 2)
		{iLimit = parseInt(isInteger.arguments[1], 10);}

	if(regExpSupported())
	{
		//^[0-9]$
		var sExp = "^[0-9]";

		if(iLimit > 0)
			{ sExp += "{0," + iLimit + "}$"; }
		else
			{ sExp += "*$"; }

		var r1 = new RegExp(sExp);
		return(r1.test(sString));
	}
	else
	{
		if(sString == "")
			{return(true);}

		if((iLimit > 0) && (sString.length != iLimit))
			{return(false);}

		for(var i = 0; i < sString.length; i++)
		{
			if((sString.charAt(i) < '0') || (sString.charAt(i) > '9'))
				{return(false);}
		}
		return(true);
	}
} /* end isInteger function */


/**
@Function boolean isNumber
	@Param String sValue
	Retruns true if the string sValue represents an number value.
*/
function isNumber(sValue)
{	
	var sFormat = "";
	var bExact = false;
	var bAllowNegs = false;

	if(isNumber.arguments.length > 1)
		{sFormat = isNumber.arguments[1];}

	if(isNumber.arguments.length > 2)
		{bExact = isNumber.arguments[2];}
		
	if(isNumber.arguments.length > 3)
		{bAllowNegs = isNumber.arguments[3];}

	saFormat = split(sFormat, ".");

	if(regExpSupported())
	{
		//^[0-9\.]$
		var sExp;
		if (bAllowNegs)
		{
			sExp = "^-?";
		}
		else
		{
			sExp = "^";
		}
		if(sFormat != "")
		{
			for(var i = 0; i < saFormat.length; i++)
			{
				sExp += "[0-9]{" + (bExact? saFormat[i]: "0") + "," + saFormat[i] + "}\\.?";
			}
			sExp = sExp.substring(0, (sExp.length - 3)) + "$";
		}
		else
		{ 
			sExp += "[0-9\\.]*$"; 
		}
			
		//alert("evaluating regexp " + sExp);

		var r1 = new RegExp(sExp);
		return(r1.test(sValue));
	}
	else
	{
		var iDot;
		var iDigits;
		var iDecimals;

		if(sValue == "")
			{return(true);}

		if((saFormat != null) && (saFormat[0] != ""))
			{iDigits = parseInt(saFormat[0], 10);}
		else
			{iDigits = -1;}

		if((saFormat != null) && (saFormat[1] != ""))
			{iDecimals = parseInt(saFormat[1], 10);}
		else
			{iDecimals = -1;}

		saValue = split(sValue, ".");

		if(sValue.charAt((sValue.length - 1)) == '.')
			{return(false);}

		if(saValue.length > 2)
			{return(false);}

		if(bExact)
		{
			if(!(isInteger(saValue[0], iDigits)))
				{return(false);}
		}
		else
		{
			if(!(isInteger(saValue[0])))
				{return(false);}
		}

		if(saValue.length > 1)
		{
			if(bExact)
			{
				if(!(isInteger(saValue[1], iDecimals)))
					{return(false);}
			}
			else
			{
				if(!(isInteger(saValue[1])))
					{return(false);}
			}
		}

		if(!(bExact) && (iDigits != -1))
		{
			if(saValue[0].length > iDigits)
				{return(false);}
		}

		if(!(bExact) && (iDecimals != -1) && (saValue.length > 1))
		{
			if(saValue[1].length > iDecimals)
				{return(false);}
		}

		return(true);
	}
} /* end isNumber function */


/**
@Function boolean isCurrency
	@Param String sValue
	Retruns true if the string sValue represents a currency value.
	Currency values must have no more that 2 decimal places.
*/
function isCurrency(sValue)
{
	return isNumber(sValue, "9.2");
}/* end isCurrency function */


/**
@Function boolean isWithinRange
	@Param String sValue
	@Param Float fBottom
	@Param Float fTop
	Retruns true if the string sValue represents a number between fBottom and fTop.
*/
function isWithinRange(sValue, fBottom, fTop)
{
	return((sValue == null || sValue == "") ||(sValue >= fBottom && sValue <= fTop));
}

/**
@Function boolean isAlphaNum
	@Param String sString
	Retruns true if the string sString is comprised of only letters and numbers.
*/
function isAlphaNum(sString)
{
	if(regExpSupported())
	{
		//^[a-zA-Z0-9]*$
		var r1 = new RegExp("^[a-zA-Z0-9]*$");
		return(r1.test(sString));
	}
	else
	{
		var c;
		sString = sString.toUpperCase();

		for(var i = 0; i < sString.length; i++)
		{
			c = sString.charAt(i);
			if((c < '0') || ((c > '9') && (c < 'A')) || (c > 'Z'))
				{return(false);}
		}
		return(true);
	}
} /* end isAlphaNum function */


/**
@Function boolean isDate
	@Param String s
	Retruns true if the string s represents a valid date in mm/dd/yyyy format.
*/
function isDate(s)
{
	//alert('entering isDate');
	var iaDaysInMonth = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	if(s == "")
		{return(true);}

	saEls = split(s, "/");
	if(saEls == null)
		{return(true);}

	if(saEls.length != 3)
		{return(false);}

	if(!isInteger(saEls[0], 2) || (!isInteger(saEls[1], 2)) || (!isInteger(saEls[2], 4)))
		{return(false);}

	if(saEls[0].charAt(0) == '0')
		{saEls[0] = saEls[0].substring(1,2);}

	if((parseInt(saEls[0], 10) > 12) || (parseInt(saEls[1], 10) > parseInt(iaDaysInMonth[parseInt(saEls[0], 10)-1], 10)))
		{return(false);}

	var iYear = parseInt(saEls[2], 10);

	if((iYear < 1900) || (iYear > 2100))
		{return(false);}

	if(((iYear % 4) != 0) && (saEls[0] == "2") && (saEls[1] == "29"))
		{return(false);}

	return(true);
} /* end isDate function */



/**
@Function boolean isWeekEndingSunday(s)
	@Param String s
	Returns true if the string represents a date that is a Sunday
	
*/
function isWeekEndingSunday(s){
	
	//If s isn't a date its not a week ending sunday.
	if(isDate(s)){
		//Parse the date string into its day month and year.
		var sa = split(s, "/");
		var sMonth = sa[0];
		var sDay = sa[1];
		var sYear = sa[2];

		//subtract one from the month because the constructor for Date is 0 based on the month.
		var dtDate = new Date(sYear,--sMonth,sDay);

		//We have a sunday when getDay() is 0
		if(dtDate.getDay() == 0){
			return(true);
		}else{
			return(false);
		}
	}else{
		return(false);
	}
}

/**
@Function boolean isFutureDate
	@Param String s
	Retruns true if the string s represents a valid future date in mm/dd/yyyy format.
*/
function isFutureDate (s) 
{
	var mm;
	var dd;
	var yyyy;
	var today=new Date();	
	
	if(isFutureDate.arguments.length > 1)
	{
		mm = isFutureDate.arguments[0];
		dd = isFutureDate.arguments[1];
		yyyy = isFutureDate.arguments[2];
	}
	else
	{
		if (isDate (s)) 
		{
			var firstSlash = s.indexOf("/");
			var secondSlash = s.indexOf( "/", firstSlash + 1);
		  
			mm = s.substring(0, firstSlash);
			if (mm.substring(0,1) == "0") 
			{
				mm = mm.substring(1,2);
			}
			 mm = parseInt(mm, 10)-1;

			dd = s.substring(firstSlash + 1, secondSlash);
			yyyy = s.substring(secondSlash + 1);
		}
		else
		{
			return false;
		}
	}
    
    dateSub = new Date (yyyy, mm, dd);
    
    if  (Date.parse(dateSub.toGMTString()) < Date.parse(today.toGMTString())) 
    {
      return false;
    }

	return true;

}		//end function isFutureDate

function stringToDate (s)
{
	var mm;
	var dd;
	var yyyy;
	var today=new Date();	

	if (isDate (s)) 
	{
		var firstSlash = s.indexOf("/");
		var secondSlash = s.indexOf( "/", firstSlash + 1);

		mm = s.substring(0, firstSlash);
		if (mm.substring(0,1) == "0") 
		{
			mm = mm.substring(1,2);
		}
		 mm = parseInt(mm, 10)-1;

		dd = s.substring(firstSlash + 1, secondSlash);
		yyyy = s.substring(secondSlash + 1);
	}
	else
	{
		return null;
	}
	
	    
    dateSub = new Date (yyyy, mm, dd);
    return dateSub;
}
/**
@Function boolean isPastDate
	@Param String s
	Retruns true if the string s represents a valid past date in mm/dd/yyyy format.
*/
function isPastDate (s) 
{
	//alert('entering isPastDate');

	var mm;
	var dd;
	var yyyy;
	var today=new Date();	

	if(isPastDate.arguments.length > 1)
	{
		mm = isPastDate.arguments[0];
		dd = isPastDate.arguments[1];
		yyyy = isPastDate.arguments[2];
	}
	else
	{
		if (isDate (s)) 
		{
			var firstSlash = s.indexOf("/");
			var secondSlash = s.indexOf( "/", firstSlash + 1);

			mm = s.substring(0, firstSlash);
			if (mm.substring(0,1) == "0") 
			{
				mm = mm.substring(1,2);
			}
			 mm = parseInt(mm, 10)-1;

			dd = s.substring(firstSlash + 1, secondSlash);
			yyyy = s.substring(secondSlash + 1);
		}
		else
		{
			return false;
		}
	}
	    
    	dateSub = new Date (yyyy, mm, dd);

    	if  (Date.parse(dateSub.toGMTString())>Date.parse(today.toGMTString()))
    	{	
      		return false;
    	}
	
	return true;
	
}//end function isPastDate

/**
@Function boolean isPastDate
	@Param String s
	Retruns true if the string s represents a valid past date in mm/dd/yyyy format.
*/
function isValidBirthDate (s) 
{
	//alert("entering isValidBirthDate");
	
	if (isPastDate(s))
	{
	
	    	var firstSlash = s.indexOf("/");
		var secondSlash = s.indexOf( "/", firstSlash + 1);

		mm = s.substring(0, firstSlash);
		if (mm.substring(0,1) == "0") 
		{
			mm = mm.substring(1,2);
		}
		mm = parseInt(mm, 10)-1;
		
		dd = s.substring(firstSlash + 1, secondSlash);
		yyyy = s.substring(secondSlash + 1);
	   	
	    	var birthDateYear = new Date (yyyy, mm, dd).getYear();
	    	
	    	if (birthDateYear < 2000)
	    	{
	    		birthDateYear = birthDateYear + 1900;
	    	}
	    	
	   	 var theYear = new Date().getYear();
	   	
	   	if ((theYear - birthDateYear) < 14)
	   	{
			return false;
	    	}
	    	if ((theYear - birthDateYear) > 70)
	    	{
			return false;
	    	}
	  }
	  else
	  {
	  	return false;
	  }
	  return true;

}//end function isValidBirthDate


/**
@Function boolean isPercentage
	@Param String s
	Retruns true if the string s represents an integer between 0 and 100.
*/
function isPercentage(s)
{
	if(!(isInteger(s)))
		{return(false);}
	if(parseInt(s, 10) > 100)
		{return(false);}
	return(true);
} /* end isPercentage function */

/**
@Function boolean isTimeCardHours
	@Param String s
	Retruns true if the string s represents is a quarter integer.
*/
function isTimeCardHours(argHrs)
{
	if(argHrs == "")
		{return(true);}
	
	var saHrs = split(argHrs, ".");
	return((saHrs.length < 3) && ((parseInt(argHrs * 100, 10) % 25) == 0))
}/* end isTimeCardHours function */

/**
@Function boolean isMilitaryTime
	@Param String s
	Retruns true if the string s represents a time between 0:00 and 24:00.
*/
function isMilitaryTime(s)
{
	if(!(isInteger(s, 4)))
		{return(false);}
	if((parseInt(s) > 2400, 10) || (s.charAt(2) > '6'))
		{return(false);}
	return(true);
} /* end isMilitaryTime function */


/**
@Function boolean isTime
	@Param String s
	Retruns true if the string s represents a time between 1:00 and 12:59.
*/
function isTime(s)
{
	if(s == "")
		{return(true);}

	if(regExpSupported())
	{
		var r = new RegExp("^[0-9]{1,2}:[0-9]{2}$");
		if(!r.test(s))
			{return(false);}
		var sa = split(s, ":");
		return((parseInt(sa[0], 10) < 13) && (parseInt(sa[1], 10) < 60));
	}
	else //no regular expressions
	{
		var sa = split(s, ":");
		if(sa.lentgh != 2)
			{return(false);}
		if((!isInteger(sa[0], 2)) || (!isInteger(sa[1], 2)) || (sa[1].length != 2))
			{return(false);}		
		return((parseInt(sa[0], 10) < 13) && (parseInt(sa[1], 10) < 60));
	}
} /* end isTime function */


/**
@Function boolean isTimeCardTime
	@Param String s
	Retruns true if the string s represents a time on the quarter hour between 1:00 and 12:45.
*/
function isTimeCardTime(s)
{
	if(s == "")
		{return(true);}
		
	if(!isTime(s))
		{return(false);}
	var sa = split(s, ":");
	return((parseInt(sa[1], 10) % 15) == 0);
} /* end isTime function */


/**
@Function boolean isYear
	@Param String s
	Retruns true if the string s represents a date between 1900 and 2100.
*/
function isYear(s)
{
	if (s == "")
	{
		return true;
	}
	if(!(isInteger(s)))
		{return(false);}
	if((parseInt(s) > 2100, 10) || (parseInt(s, 10) < 1900))
		{return(false);}
	return(true);
} /* end isYear function */


/**
@Function boolean isURL
	@Param String str
	Retruns true if the string str matches the format for a URL.
*/
function isURL(str)
{
  // are regular expressions supported?
	if (!regExpSupported())
	{ 
		sPrefix = s.substring(0, 7);
		return(sPrefix.toLowerCase() == "http://" || sPrefix == "" || s.indexOf(" ") == -1);
	}	
	var re = /^(http:\/\/)?[a-z0-9_\-\.]+\.[a-z0-9_\-]{2,3}((\/.*$)|($))/i;
	return (str == "" || (re.test(str)));
}


/**
@Function boolean isEmail
	@Param String s
	Retruns true if the string s matches the format for an email address.
*/
function isEmail(s) {
  // are regular expressions supported?
	if (!regExpSupported())
		{ return((str.indexOf(".") > 2) && (str.indexOf("@") > 0) && (str.indexOf(" ") == -1)); }
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,6}|[0-9]{1,3})(\\]?)$");
	
	//alert("Regular expression 1 returns " + r1.test(s));
	//alert("Regular expression 2 returns " + r2.test(s));
	
	return ((!r1.test(s) && r2.test(s)) || s == "");	  

} /* end isEmail function */


/**
@Function boolean isStandardCharSet
	@Param String s
	Returns true if the string s is composed of standard ANSI characters
*/
function isStandardCharSet(s)
{
	for (i = 0; i < s.length; i++)
	{
		iCode = s.charCodeAt(i);
		//alert(iCode);
		if (iCode > 255)
		{
			return false;
		}
	}
	
	return true;
  
} /* end isStandardCharSet function */

/**Function isUSPhone
	Returns true if the number contains 10 numeric digits
 */
 function isUSPhone(s)
 {
	var sNewString = "";
	var sNumbers = "0123456789";
	if (s == null  || s == "")
	{
		return true;
	}
	for (i = 0; i < s.length; i++)
	{
		sChar = s.charAt(i);
		if (sNumbers.indexOf(sChar) != -1)
		{
			sNewString = sNewString + sChar;
		}
	}
	
	if (sNewString.length == 10)
	{
		return true;
	}
	
	return false;
}

function isUSPostalCode(s)
{
	var sNumbers = "0123456789";
	if (s == null  || s == "")
	{
		return true;
	}
	for (i = 0; i < s.length; i++)
	{
		sChar = s.charAt(i);
		if (sNumbers.indexOf(sChar) == -1)
		{
			return false;
		}
	}
	
	if (s.length != 5)
	{
		return false;
	}
	
	return true;
}

/**
@Function boolean checkLength
	@Param String sString
	@Param int iMaxLen
	Retruns true if the number of characters in string sString is less than iMaxLen.
*/
function checkLength(sString, iMaxLen)
{
	
	if(sString.length > iMaxLen)
	{
		return(false);
	}
	return(true);
} /* end checkLength function */


/**
@Function boolean checkMaxInput
	@Param input inputArea
	@Param int iMaxLen
	@Param input remLen
	Updates number of remaining characters for textarea fields and prohibits entry
	greater than iMaxLen
*/
function checkMaxInput(inputArea, iMaxLen, remLen ) {
// inputArea is the Text area to be checked.
// MAX NUMBER OF CHARACTERS ALLOWED IN THE TEXTAREA
// remLen displays the max lenght.
	//alert("start");
	if (inputArea.value.length > iMaxLen)
	{ 
		// IF TOO LONG IT WILL TRUNCATE TEXT		
		inputArea.value = inputArea.value.substring(0, iMaxLen);
		remLen.value = iMaxLen - inputArea.value.length;
		inputArea.focus();
		alert("Maximum limit of " + iMaxLen +" characters for this field is reached, Excess characters removed");		
		inputArea.focus();

		// IF LESS THAN MAXLENGTH UPDATE THE CHARACTER COUNTER 
		}
	else 
		remLen.value = iMaxLen - inputArea.value.length;
}


/**
@Function boolean checkMinLength
	@Param String sString
	@Param int iMinLen
	Returns true if the number of characters in string sString is greater than iMinLen.
*/
function checkMinLength(sString, iMinLen)
{
	//alert("Checking " + sString + " for length " + iMinLen);
	if(sString.length >= iMinLen)
	{
		return(true);
	}
	return(false);
} /* end checkMinLength function */


/**
@Function boolean regExpSupported
	Retruns true if the browser supports regular expressions.
*/
function regExpSupported()
{
	if (window.RegExp)
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr))
			{ return true; }
	}
	return false;
}/* end regExpSupported function*/


function checkRequired(fItem)
{
	var sType = getFieldType(fItem.name);
	var fForm = fItem.form;
	if(sType == null || fForm == null)
		{return(true);}
	else
		{return(!isBlank(fItem.name, sType, fForm));}
}

/**
Begin functions pulled from Wizard Validation scripts
*/


/**
@Function String getFieldValue
	@Param String sName
	@Param String sType
	@Param Form formPanel
	@Param boolean bTrim
	Returns the value of a field as a string, separates
	multiple values with semicolons, optionally trims 
	text type values and updates the field
*/
function getFieldValue (sName) {
  if (getFieldValue.arguments.length > 1) {
    sType = getFieldValue.arguments[1];
  }
  else {
    sType = getFieldType(sName);
  }
  if (getFieldValue.arguments.length > 2) {
    formPanel = getFieldValue.arguments[2];
  }
  else {
    formPanel = document.forms[0];
  }
  if (getFieldValue.arguments.length > 3) {
    bTrim = getFieldValue.arguments[3];
  }
  else {
    bTrim = true;
  }
  //alert("Type is " + sType);
  if (sType == "text" || sType == "textarea" || sType == "hidden" || sType == "password") {
	  if(bTrim)	{ formPanel.elements[sName].value = Trim(formPanel.elements[sName].value); }
	  return formPanel.elements[sName].value;
  }
  if (sType == "select-one") {
    var iSel = formPanel.elements[sName].selectedIndex;
    if (iSel != -1) {
      return formPanel.elements[sName].options[iSel].value;
    }
    else {
      return "";
    }
  }      
  if (sType == "select-multiple") {
    var sValues = "";
    for (var iOptions = 0; iOptions < formPanel.elements[sName].options.length; iOptions++) {
      if (formPanel.elements[sName].options[iOptions].selected) {
        sValues = sValues + formPanel.elements[sName].options[iOptions].value + ";";
      }
    }
    sValues = sValues.substring (0, (sValues.length - 1));
    return sValues;
  }
  if (sType=="checkbox" || sType == "radio") {
    var sValues = "";
    
    //* 
    //  commented out by DMP 6/10/02 because of 
    //  performance problems with this implementation 
    //*
    //var sCheckName;
    //for (var iNum = 0; iNum < formPanel.elements.length; iNum++) {
    //  sCheckName = formPanel.elements[iNum].name;
    //  while (sName == sCheckName) {
    //    if (formPanel.elements[iNum].checked) {
    //        sValues = sValues + formPanel.elements[iNum].value + ";";
    //    }
    //    iNum++;
    //    if (iNum < formPanel.elements.length) {
    //      sCheckName = formPanel.elements[iNum].name;
    //    }
    //    else {
    //      sCheckName = "";
    //    }
    //  }
    //}
    
    if (formPanel.elements[sName].length == null)
	{
		if (formPanel.elements[sName].checked)
		{
			sValues = sValues + formPanel.elements[sName].value;
        }		
	}
	else
	{
		for (var iNum = 0; iNum < formPanel.elements[sName].length; iNum++)
		{
			if (formPanel.elements[sName][iNum].checked)
			{
				sValues = sValues + formPanel.elements[sName][iNum].value + ";";
			}
		}
		sValues = sValues.substring (0, (sValues.length - 1));
	}
    
    
    return sValues;
  }
return "";
}

/**
@Function boolean fieldExists
	@Param String sName
	@Param Form formPanel
	Returns true if field exists, false otherwise
*/
function fieldExists(sName) {	
  if (fieldExists.arguments.length > 1) {
    formPanel = fieldExists.arguments[1];
  }
  else {
    formPanel = document.forms[0];
  }
  return(formPanel.elements[sName] != null);
}

/**
@Function String getFieldType
	@Param String sName		
	Returns the field type given the name of a field	
*/
function getFieldType (sName) {

  if (document.forms[0].elements[sName].type != null)
  	{
  		//alert("Only one field");
  		return document.forms[0].elements[sName].type;
  	}
  	else
  	{
		//alert("There are multiple fields for the field name to follow");
  		//alert(sName);
  		//alert("The type is " + document.forms[0].elements[sName][0].type);
  		return document.forms[0].elements[sName][0].type;
  	}  
}

/**
@Function String getErrorMessage
	@Param String sErrorKey
	@Param String sFieldName
	@Param Form formPanel
	@Param String sValidationFormula
	Gets the rror message for a particular error type
*/
function getErrorMessage (sErrorKey) {
  var sValidationFormula = "";
  var sFieldName = "";
  var formPanel = document.forms[0];
  var sStandardMsg = "";
  if (getErrorMessage.arguments.length > 1) {
    fieldInfo = getErrorMessage.arguments[1];
  }
  if (getErrorMessage.arguments.length > 2) {
    formPanel = getErrorMessage.arguments[2];
  }
  else {
    formPanel = document.forms[0];
  }
  if (getErrorMessage.arguments.length > 3) {
    sValidationFormula = getErrorMessage.arguments[3];
  }
  /*  
  //alert("Message by name is " + NamedErrorMsgArray[sErrorKey].message);
  sStandardMsg = NamedErrorMsgArray[sErrorKey].message;
  */
  for (iMsgs=0; iMsgs < ErrorMsgArray.length; iMsgs++) {
    if (ErrorMsgArray[iMsgs].key == sErrorKey) {
      sStandardMsg = ErrorMsgArray[iMsgs].message;
      iMsgs = ErrorMsgArray.length;
    }
  }

  if (sStandardMsg != "") {
    var saMessage = split (sStandardMsg, "*");
    for (iNum=0; iNum < saMessage.length; iNum++) {
      if (saMessage[iNum] == "ValidationFormula") {
        saMessage[iNum] = sValidationFormula;
      }
      else {
        saMessage[iNum] = getMessageVariable (fieldInfo, formPanel, saMessage[iNum]);
      }     
    }
    sStandardMsg = "";
    for (iNum=0; iNum < saMessage.length; iNum++) {
      sStandardMsg = sStandardMsg + saMessage[iNum];
    }
  }
  return sStandardMsg;
}/* end function getErrorMessage */ 


/**
@Function String getMessageVariable
	@Param String sFieldName
	@Param Form formPanel
	@Param String sVal
	Returns a variable value to be used in an error message
*/
function getMessageVariable (fieldInfo, formPanel, sVal) {
  if(getMessageVariable.arguments.length > 3) {
	saArgs = getMessageVariable.arguments[3];
  }

  sFieldName = fieldInfo.fieldName;	
  if (sVal == "FieldLabel") {
    return fieldInfo.label;
  }
  if (sVal == "FieldValue") {
    var sType = getFieldType (sFieldName);
    return getFieldValue (sFieldName, sType, formPanel);
  }
  if (sVal == "NL") {
    return "\n";
  }
  if (sVal == "CurrentDate") {
    var today = new Date();
    var sDate = "";
    var iMonth = today.getMonth() + 1;
    if (iMonth < 10) {
      sDate = "0" + iMonth + "/";
    }
    else {
      sDate = iMonth + "/";
    }
    if (today.getDate() < 10) {
      sDate = sDate + "0" + today.getDate() + "/";
    }
    else {
      sDate = sDate + today.getDate() + "/";
    }
    var sYear = today.getYear();
   	if (today.getFullYear == null)
	{ 
		sYear = today.getYear();
		if (today.getYear() < 2000)
                 	 sYear += 1900;             
	}
    else
	{
          sYear = today.getFullYear();
	}
    sDate = sDate + sYear;
    return sDate;
  }
  if(sVal > "" && isInteger(sVal)) {
	//insert the sVal-th argument to the validation function
	return(saArgs[sVal]);
  }
return sVal
}/*EndFunction*/

/**
@Function boolean evalCondition
	@Param String sCondition
	@Param Form formPanel
	Given a formula in the form FIELD:fieldname;=;VAL:value
	returns the value of the expression
*/
function evalCondition (sCondition, formPanel) {
  
  //alert("evaling condition " + sCondition);
  
  if (sCondition == null || sCondition == "")
  {
  	return true;
  }
  
  var sType;  
  var saCon = split(sCondition, ";"); 
  if (saCon.length != 3) {
    return false;
  }
  var sArg1 = saCon[0];
  var sComp = saCon[1];
  var sArg2 = saCon[2];
  sType = "";
  var saArg1 = split (sArg1,":");
  if (saArg1[0].toUpperCase() == "FIELD") {
    var sName = saArg1[1];
    sType = getFieldType(sName);
    if (sType == "") {
      return false;
    }
    else {
      var sVal1 = getFieldValue (sName, sType, formPanel);
    }
  }
  else {
    var sVal1 = saArg1[1];
  }
  sType = "";
  var saArg2 = split(sArg2,":");
  if (saArg2[0].toUpperCase() == "FIELD") {
    var sName = saArg2[1];
    sType = getFieldType(sName);
    if (sType == "") {
      return false;
    }
    else {
      var sVal2 = getFieldValue (sName, sType, formPanel);
    }
  }//end FIELD if
  else {
    if(saArg2.length < 2)
     {var sVal2 = "";}
    else
     {var sVal2 = saArg2[1];}
  }
  //alert("Returning evaluation of formula " + sVal1 + "=" + sVal2);
  if (sComp == "=") { 
    return(sVal1 == sVal2);
  }
  if (sComp == "<") {
    return(sVal1 < sVal2);
  }
  if (sComp == ">") {
    return(sVal1 > sVal2);
  }
  if (sComp == "!=") {
    return(sVal1 != sVal2);
  }
  if (sComp == "CONTAINS") {
	  return(sVal1.indexOf(sVal2) != -1);
  }
  return false;
}/*end function*/


/**
@Function void setFocus
	@Param String sFieldName
	@Param String sFieldType	
	Sets the focus to the field passed to the function
*/
function setFocus(sFieldName, sFieldType)
{
  var formPanel;
  if (sFieldType == null)
  {
  	sFieldType = getFieldType(sFieldName);
  }
  
  //include the tabid if supplied
  if (setFocus.arguments.length > 2) {
	sTabID = setFocus.arguments[2];
  }
  else {
	sTabID = null;
  }
  
  for (var iForms=0; iForms < document.forms.length; iForms++) {
    formPanel = document.forms[iForms];
    if (sFieldType=="checkbox" || sFieldType == "radio") {
      if (!isOldIE ()) {
      
        //* 
		//  commented out by DMP 6/10/02 because of 
		//  performance problems with this implementation 
    	//*
        //for (var iNum = 0; iNum < formPanel.elements.length; iNum++) {
        //  var sCheckName = formPanel.elements[iNum].name;
        //  if (sFieldName == sCheckName) {
        //  	//select the correct tab
        //  	if (sTabID != null)
        //  	{
        //  		tdNode = getTab(sTabID);
        //  		if (tdNode != null)
        //  		{
        //  			selectTab(tdNode);
        //  		}
        //  	}          
        //    formPanel.elements[iNum].focus();
        //  }
        
        //select the correct tab
		if (sTabID != null)
		{
			tdNode = getTab(sTabID);
			if (tdNode != null)
			{
				selectTab(tdNode);
			}
		}     
        if (formPanel.elements[sFieldName].length == null)
        {
        	//alert("Calling setFocus for checkbox/radio field with signle option " + sFieldName);
        	formPanel.elements[sFieldName].focus();
        	if (isMacOSX())
			{
				//alert("Calling scrollIntoView for regular field " + sFieldName);
				formPanel.elements[sFieldName].scrollIntoView();
			}
        }
        else
        {
        	//alert("Calling setFocus for checkbox/radio field with mult options " + sFieldName);
        	formPanel.elements[sFieldName][0].focus();
        	if (isMacOSX())
			{
				//alert("Calling scrollIntoView for regular field " + sFieldName);
				formPanel.elements[sFieldName][0].scrollIntoView();
			}
        }
      }
    }
    else {
      if(formPanel.elements[sFieldName])
      {
      	//select the correct tab
		if (sTabID != null)
		{
			tdNode = getTab(sTabID);
			if (tdNode != null)
			{
				selectTab(tdNode);
			}
		}
		//alert("Calling setFocus for regular field " + sFieldName);
		formPanel.elements[sFieldName].focus();	
		if (isMacOSX())
		{
			//alert("Calling scrollIntoView for regular field " + sFieldName);
			formPanel.elements[sFieldName].scrollIntoView();
		}
      }
    }
  }
}//end function


/**
@Function String[] split
	@Param String sString
	@Param String sSep
	Parses a string with the specified delimiter and returns an array
*/
function split(sString, sSep)
{ 
 if((sString == "") || (sSep == ""))
  {return(null);}

 var iToken = 0;
  for(var iSep = 0; ((iSep != -1) && (iSep != "")); iSep = sString.indexOf(sSep, (iSep += sSep.length)))
  {
    iToken++; 
    if(iSep == (sString.length - sSep.length))
     {iToken--;}
  }
  var saRet = new Array(iToken);

  iToken = 0;
  for(iStart = 0; iStart < sString.length; iStart = iEnd + sSep.length)
  {
    iEnd = sString.indexOf(sSep, iStart);
    if(iEnd == -1)
     {iEnd = sString.length;}
    saRet[iToken++] = sString.substring(iStart, iEnd);
  }
  if(saRet[0] == null)
   {saRet = null};
  return saRet;
}//end function

/**
@Function boolean isOldIE
	Returns true if browser is less than IE 3.x or lower
*/
function isOldIE()
{
  if((navigator.appName == "Microsoft Internet Explorer") && 
     (parseFloat(navigator.appVersion) < 4.0))
   {return(true);} 
  else
   {return(false);}
}//end function


/**
@Function String Trim
	@Param String s
	Removes leading and trailing spaces from the string
*/
function Trim(s)
{
  var sNew;
  var iLength = s.length;
  var i = 0;

  while(s.charAt(i) == " ")
   {i++;}

  sNew = s.substring(i,iLength);
  iLength = sNew.length;
  i = iLength - 1;

  while(sNew.charAt(i) == " ")
   {i--;}

  sNew = sNew.substring(0,++i);
  return sNew;
}


/**
@Function validateField
	Runs the validation specified in the fieldTypeInfo object
	
*/
function validateTypeInfo(fieldInfo)
{
		
	sValue = getFieldValue(fieldInfo.fieldName);
	//alert ("Running validateTypeInfo");
	//alert("validation function is: " + fieldInfo.validationFunction);
	
	if (fieldInfo.validationFunction != null && fieldInfo.validationFunction != "")
	{
		if (eval ("window." + fieldInfo.validationFunction + " != null;"))
		{
			//alert("Trying to run the validation function");
			//sFunction = "window." + fieldInfo.validationFunction + "(\"" + sValue + "\");";
			//alert(sFunction);
			
			//alert("Checking type info using function list: " + fieldInfo.validationFunction);
			
			//split the function list & insert the value as the first arg...
			saFunctions = split(fieldInfo.validationFunction,";");
			for(f = 0; f < saFunctions.length; f++)
			{
				//alert("Processing Function " + saFunctions[f]);
				if(saFunctions[f].indexOf("(") == -1)
				{
					//alert("adding default arg...");
					sFunName = saFunctions[f];
					saArgs = null;
					sFunction = "window." + saFunctions[f] + "(\"" + sValue + "\");";
				}
				else
				{
					//alert("inserting default arg to argument list " + saFunction[1]);
					var saFunction = split(saFunctions[f], "(");
					sFunName = saFunction[0];
					saArgs = split(saFunction[1].substring(0,saFunction[1].length - 1), ",")
					sFunction = "window." + saFunction[0] + "(\"" + sValue + "\"," + saFunction[1] + ";";
				}
				//alert("evaluating function " + sFunction);
				var ret = eval(sFunction);
				if(ret != true)
				{
					if(ret == false)
					{
						//alert("Getting error message for " + sFunName);
						ret = getErrorMessage(sFunName, fieldInfo, document.forms[0], "", saArgs);
					}
					alert(ret);
					setFocus (fieldInfo.fieldName, getFieldType(fieldInfo.fieldName), fieldInfo.tabid);
					return false;
				}
			}
		}//end data type validation if
		
	}//end validationFunction null if
		
	//alert("maxlength " + fieldInfo.maxlength);	
	if (fieldInfo.maxlength != null && fieldInfo.maxlength != 0)
	{
		//alert("Need to check the maxlength " + fieldInfo.maxlength);
		if (!(checkLength(sValue, fieldInfo.maxlength)))
		{
			alert(getErrorMessage("checkLength", fieldInfo, document.forms[0], fieldInfo.maxlength));
			setFocus (fieldInfo.fieldName, getFieldType(fieldInfo.fieldName), fieldInfo.tabid);
			return false;
		}
	}//end check length if
	
	return true;
	
}


/**
@Function fieldInfo
	Creates a fieldInformation object to store validation options for a given field
	
*/
function FieldInfo(sName, sLabel, bIsRequired, sConditionalFormula, sValidationFunction, iLength, sTabID, bSetFocus)
{
	
	this.fieldName = sName;
  	this.label = sLabel;
  	this.required = bIsRequired;
  	this.conditionalFormula = sConditionalFormula;
  	this.validationFunction = sValidationFunction;
  	this.maxlength = iLength;
  	this.tabid = sTabID;
  	this.getFocus = bSetFocus;

}

/**
* @Function setFieldInfo
* @param sName
* @param sLabel
* @param bIsRequired
* @param [sConditionallyRequiredFormula]
* @param [sValidationFunction]
* @param [iLength]
* @param [sTabId]
* @param [bSetFocus]
* 
* Sets validation meta-data for a field on the page.
*/

function setFieldInfo(sName, sLabel, bIsRequired)
{
	//alert("Running setFieldInfo");
	
	//include the conditional validation formula if supplied
	if (setFieldInfo.arguments.length > 3) {
	    sConditionalFormula = setFieldInfo.arguments[3];
  	}
  	else {
  		sConditionalFormula = null;
  	}
  	
  	//include the validation function if supplied
  	if (setFieldInfo.arguments.length > 4) {
	    sValidationFunction = setFieldInfo.arguments[4];
	}
	else {
		sValidationFunction = null;
  	}
  	
  	//include the length if supplied
	if (setFieldInfo.arguments.length > 5) {
		iLength = setFieldInfo.arguments[5];
	}
	else {
		iLength = 0;
  	}  	
  	
  	//include the tab ID if supplied
	if (setFieldInfo.arguments.length > 6) {
		sTabID = setFieldInfo.arguments[6];
	}
	else {
		sTabID = null;
  	}
  	
  	if(setFieldInfo.arguments.length > 7){
	  		bSetFocus = setFieldInfo.arguments[7];
	  	}
	  	else{
	  		bSetFocus = false;
  	}
  	/*
  	//we could just key off of field name...
  	if(FieldInfoArray[sName] == null) {
		iNumFields++;
	}
  	FieldInfoArray[sName] = new FieldInfo(sName, sLabel, bIsRequired, sConditionalFormula, sValidationFunction, iLength, sTabID, bSetFocus);
  	*/
  	
  	//check to see whether this field is already in the field info array
  	bIsNew = true;
  	for (i = 0; i < FieldInfoArray.length; i++)
  	{
  		if (FieldInfoArray[i].fieldName == sName)
  		{
  			FieldInfoArray[i] = new FieldInfo(sName, sLabel, bIsRequired, sConditionalFormula, sValidationFunction, iLength, sTabID, bSetFocus);
  			i = FieldInfoArray.length;
  			bIsNew = false;
  		}
  	}
  	
  	if (bIsNew)
  	{  	
		//add the fieldinfo to the field information array
		FieldInfoArray[iNumFields] = new FieldInfo(sName, sLabel, bIsRequired, sConditionalFormula, sValidationFunction, iLength, sTabID, bSetFocus);
		iNumFields++;
	}
	
  	
}


function removeFieldInfo(sName) 
{
  var newInfoArray = new Array();
  var iIndex = 0;
  for (var i=0; i < FieldInfoArray.length; i++) 
  {
  	  currentField = FieldInfoArray[i];
      if (currentField.fieldName != sName)
      {   
      	 newInfoArray[iIndex] = currentField;
      	 iIndex++;
      }
  }/*end FieldInfoArray loop*/
  
  FieldInfoArray = newInfoArray;
  iNumFields = iIndex;
}

/**
@Function setInitialFocus
	Sets the focus of the broswer to a selected field
*/
function setInitialFocus(){
	for(var i=0;i<FieldInfoArray.length;i++){
		currentField = FieldInfoArray[i];
		
		if(currentField.getFocus){
			setFocus(currentField.fieldName);
		}
	}
}


/**
@Function checkRequiredFields
	Checks all required fields as defined in the fieldInfo object	
*/
function checkRequiredFields() {
  var bAllowContinue = false;  
  if (checkRequiredFields.arguments.length > 0) {
    bAllowContinue = checkRequiredFields.arguments[0];
  }
  var sErrorMessage = "";
  var bIsComplete = true;
  var formPanel = document.forms[0];
  var firstField = null;
  
  for (var i=0; i < FieldInfoArray.length; i++) {
  	  currentField = FieldInfoArray[i];
  	  //alert(" number " + i + " field is " + currentField.fieldName);
      if (currentField.required)
      {   
      	  //alert(currentField.fieldName + " number " + i + "is required");
      	  if (evalCondition (currentField.conditionalFormula, formPanel))
      	  {
			  if (isBlank(currentField.fieldName, getFieldType(currentField.fieldName), formPanel)) {
				sErrorMessage = sErrorMessage + currentField.label + "\n";
				bIsComplete = false;
				if (firstField == null)
				{
					firstField = currentField;
				}
			  }//end isBlank if  
		   }//end evalCondition if
      }
  }/*end FieldInfoArray loop*/
  
  if (!bIsComplete) {
    var sStandardMsg = getErrorMessage ("checkRequired", firstField.fieldName, formPanel);
    if (sStandardMsg != "") {
      sErrorMessage = sStandardMsg + "\n\n" + sErrorMessage;
    }
    else {
      sErrorMessage = "You did not complete the following required fields: \n\n" + sErrorMessage;
    }    
    if (bAllowContinue) {
      var bContinue = confirm (sErrorMessage + "\n" + sOptionalMsg);
      if (bContinue) {
        return true;
      }
      else {
        setFocus (firstField.fieldName, getFieldType(firstField.fieldName), firstField.tabid);
        return false;
      }
    }
    else { 
      alert (sErrorMessage);
      setFocus (firstField.fieldName, getFieldType(firstField.fieldName), firstField.tabid);
      return false;
    }
  }
  else {
  	return true;
  }
}


/**
@Function validateFields
	Validates the data type and length of all fields
	as defined in the fieldInfo object	
*/
function validateFields() {

	formPanel = document.forms[0];
	
	for (var i=0; i < FieldInfoArray.length; i++)
	{
  		currentField = FieldInfoArray[i];
  		//alert("Validating " + currentField.fieldName);
  		if (!(validateTypeInfo(currentField)))
  		{
  			return false;
  		}
  	}//end for loop
  	
  	return true;
  	
}


/**
Begin navigation functions
**************************
*/

function goNext()
{

	bContinue = true;
	if (window.preValidationProcessing != null)
	{
		if (!(window.preValidationProcessing()))
		{			
			bContinue = false;
		}//end preValidation processing
	}//end preValidation if exists
	
	
	if (bContinue)
	{
		if (!(checkRequiredFields() && validateFields()))
		{
			bContinue = false;
		}//end checkFields if
	}

	
	if (bContinue)
	{
		if (window.postValidationProcessing != null)
		{
			if (!(window.postValidationProcessing()))
			{
				bContinue = false;
			}//end postValidation processing
		}//end postValidation if exists
	}
	

	if (bContinue)
	{
		document.forms[0].NavAction.value='next';
		document.forms[0].submit();
	}
					
}

function goPrevious()
{
	bContinue = true;
	
	if (window.preValidationProcessing != null)
	{
		if (!(window.preValidationProcessing()))
		{			
			bContinue = false;
		}
	}

	if (bContinue)
	{
		if (!(validateFields()))
		{
			bContinue = false;
		}
	}

	if (bContinue)
	{
		if (window.postValidationProcessing != null)
		{
			if (!(window.postValidationProcessing()))
			{
				bContinue = false;
			}
		}
	}

	if (bContinue)
	{
		document.forms[0].NavAction.value='previous';
		document.forms[0].submit();
	}
}

function goSaveForLater()
{
	bContinue = true;
	
	if (window.preValidationProcessing != null)
	{
		if (!(window.preValidationProcessing()))
		{			
			bContinue = false;
		}
	}

	if (bContinue)
	{
		if (!(validateFields()))
		{
			bContinue = false;
		}
	}
	
	if (bContinue)
	{
		if (window.postValidationProcessing != null)
		{
			if (!(window.postValidationProcessing()))
			{
				bContinue = false;
			}
		}
	}

	if (bContinue)
	{
		document.forms[0].NavAction.value='saveForLater';
		document.forms[0].submit();
	}
	
}


function goFinish()
{
	bContinue = true;
	if (window.preValidationProcessing != null)
	{
		if (!(window.preValidationProcessing()))
		{			
			bContinue = false;
		}//end preValidation processing
	}//end preValidation if exists

	if (bContinue)
	{
		if (!(checkRequiredFields() && validateFields()))
		{
			bContinue = false;
		}//end checkFields if
	}

	if (bContinue)
	{
		if (window.postValidationProcessing != null)
		{
			if (!(window.postValidationProcessing()))
			{
				bContinue = false;
			}//end postValidation processing
		}//end postValidation if exists
	}

	if (bContinue)
	{
		document.forms[0].NavAction.value='finish';
		document.forms[0].submit();
	}
}

function goSubmit()
{
	//alert("checking preValidationProcessing");
	bContinue = true;
	if (window.preValidationProcessing != null)
	{
		//alert("running preValidationProcessing");
		if (!(window.preValidationProcessing()))
		{			
			bContinue = false;
		}//end preValidation processing
	}//end preValidation if exists

	if (bContinue)
	{
		//alert("running checkRequiredFields() && validateFields()");
		if (!(checkRequiredFields() && validateFields()))
		{
			bContinue = false;
		}//end checkFields if
	}

	if (bContinue)
	{
		//alert("checking postValidationProcessing");
		if (window.postValidationProcessing != null)
		{
			//alert("running postValidationProcessing");
			if (!(window.postValidationProcessing()))
			{
				bContinue = false;
			}//end postValidation processing
		}//end postValidation if exists
	}
	
	//alert("returning " + bContinue);

	return(bContinue);
	
}//end goSubmit()
			
function goBack()
{
	history.back();
}

function trySubmit()
{
	if(goSubmit())
	{
		document.forms[0].submit();
		return true;
	}
}

function tryValidate()
{	
	alert("goSubmit() = " + goSubmit());
}


function requireState()
{
	//alert("entering requireState function");
	var sTabID = null;
	
  	//include the tabid if supplied
  	if (requireState.arguments.length > 0) 
  	{
  		//alert("there is an argument and setting it to: " + requireState.arguments[0]);
		sTabID = requireState.arguments[0];
  	}

	
	var countryValue = document.forms[0].country.value;
	var stateValue = document.forms[0].state.value;
	
	switch(countryValue) 
	{
		//US
		case '1':
		if (stateValue == null || stateValue == '')
		{
			alert("You must enter a state");
			setFocus('state', getFieldType('state'), sTabID);
			return false;
		}
		else
		{
			if (stateValue.length != 2)
			{
				alert("Please use the 2 letter state abbreviation");
				setFocus('state', getFieldType('state'), sTabID);
				return false;
			}
			else
			{
				return true;
			}
		}
		break;
		
		//CANADA
		case '2': 
		if (stateValue == null || stateValue == '')
		{
			alert("You must enter a state");
			setFocus('state', getFieldType('state'), sTabID);
			return false;
		}
		else
		{
			if (stateValue.length != 2)
			{
				alert("Please use the 2 letter state abbreviation");
				setFocus('state', getFieldType('state'), sTabID);
				return false;
			}
			else
			{
				return true;
			}
		}
		break;
		
		//AUSTRALIA
		case '8': 
		if (stateValue == null || stateValue == '')
		{
			alert("You must enter a state");
			setFocus('state', getFieldType('state'), sTabID);
			return false;
		}
		else
		{
			if (stateValue.length > 3 || stateValue.length < 2)
			{
				alert("Please use the 2-3 letter state abbreviation");
				setFocus('state', getFieldType('state'), sTabID);
				return false;
			}
			else
			{
				return true;
			}
		} 
		break;
		
		default: 
		return true;
		break;
	}
}

function requirePostalCode(sTabID)
{
	var countryValue = document.forms[0].country.value;
	var PCValue = document.forms[0].postalCode.value;
	
	switch(countryValue) 
	{
		//US
		case '1':
		if (PCValue == null || PCValue == '')
		{
			alert("You must enter a postal code");
			setFocus('postalCode', getFieldType('postalCode'), sTabID);
			return false;
		}
		else
		{
			//strip dash out of zip code
			var strippedPC = repSubstring(PCValue, "-", "");
			//alert("stripped PC is: " + strippedPC);
			
			if (strippedPC.length == 5 || strippedPC.length == 9)
			{
				if (isNumber(strippedPC))
				{
					return true;
				}
			}
			
			alert ("Please enter a postal code in either '#####' or '#####-####' format");
			setFocus("postalCode", getFieldType("postalCode"), sTabID);
			return false;
		}
		break;
		
		//CANADA
		case '2': 
		if (PCValue == null || PCValue == '')
		{
			alert("You must enter a postal code");
			setFocus('postalCode', getFieldType('postalCode'), sTabID);
			return false;
		}
		else
		{
			//strip out space or dash
			var strippedPC = repSubstring(PCValue, " ", "");
			strippedPC = repSubstring(strippedPC, "-", "");
			//alert("stripped PC is: " + strippedPC);
			
			if (strippedPC.length == 6)
			{
				return true;
			}
			
			alert("Please enter a postal code in 'xxx xxx' format");
			setFocus('postalCode', getFieldType('postalCode'), sTabID);
			return false;
			
		}
		break;
		
		//GERMANY
		case '4': 
		if (PCValue == null || PCValue == '')
		{
			alert("You must enter a postal code");
			setFocus('postalCode', getFieldType('postalCode'), sTabID);
			return false;
		}
		else
		{
			return true;
		}
		break;
		
		//FRANCE
		case '5': 
		if (PCValue == null || PCValue == '')
		{
			alert("You must enter a postal code");
			setFocus('postalCode', getFieldType('postalCode'), sTabID);
			return false;
		}
		else
		{
			return true;
		}
		break;
		
		//JAPAN
		case '6': 
		if (PCValue == null || PCValue == '')
		{
			alert("You must enter a postal code");
			setFocus('postalCode', getFieldType('postalCode'), sTabID);
			return false;
		}
		else
		{
			return true;
		}
		break;
		
		
		//AUSTRALIA
		case '8': 
		if (PCValue == null || PCValue == '')
		{
			alert("You must enter a postal code");
			setFocus('postalCode', getFieldType('postalCode'), sTabID);
			return false;
		}
		else
		{
			return true;
		}
		break;
		
		//UK
		case '9': 
		if (PCValue == null || PCValue == '')
		{
			alert("You must enter a postal code");
			setFocus('postalCode', getFieldType('postalCode'), sTabID);
			return false;
		}
		else
		{
			//strip out space or dash
			var strippedPC = repSubstring(PCValue, " ", "");
			strippedPC = repSubstring(strippedPC, "-", "");
			//alert("stripped PC is: " + strippedPC);
			
			if (strippedPC.length >=6 && strippedPC.length <= 8)
			{
				return true;
			}
			
			alert("Please enter a postal code in either 'xxxx xxxx' or 'xxxx xxx' or 'xxx xxx' format");
			setFocus('postalCode', getFieldType('postalCode'), sTabID);
			return false;	
		}
		break;
		
		//NETHERLANDS
		case '10': 
		if (PCValue == null || PCValue == '')
		{
			alert("You must enter a postal code");
			setFocus('postalCode', getFieldType('postalCode'), sTabID);
			return false;
		}
		else
		{
			//strip out space or dash
			var strippedPC = repSubstring(PCValue, " ", "");
			strippedPC = repSubstring(strippedPC, "-", "");
			//alert("stripped PC is: " + strippedPC);
			
			if (strippedPC.length == 6)
			{
				return true;
			}
			
			alert("Please enter a postal code in 'xxxx xx' format");
			setFocus('postalCode', getFieldType('postalCode'), sTabID);
			return false;
			
		}
		break;
		
		//SINGAPORE
		case '11': 
		if (PCValue == null || PCValue == '')
		{
			alert("You must enter a postal code");
			setFocus('postalCode', getFieldType('postalCode'), sTabID);
			return false;
		}
		else
		{
			return true;
		}
		break;
		
		//SWEDEN
		case '12': 
		if (PCValue == null || PCValue == '')
		{
			alert("You must enter a postal code");
			setFocus('postalCode', getFieldType('postalCode'), sTabID);
			return false;
		}
		else
		{
			return true;
		}
		break;
		
		default: 
		return true;
		break;
	}
}

function checkMinorSegments()
{
	var sTabID;
	 if (checkMinorSegments.arguments.length > 0) 
	 {
		sTabID = checkMinorSegments.arguments[0];
	 }
	 else
	 {
	  	sTabID = null;
  	 }
	
	iNumSelected = 0;
	iNumSelected += getNumSelected("creativeSegment");
	iNumSelected += getNumSelected("productionSegment");
	iNumSelected += getNumSelected("techSegment");
	iNumSelected += getNumSelected("webSegment");

	if (iNumSelected < 1)
	{
		alert("You must select at least one Profession");
		setFocus('creativeSegment', getFieldType('creativeSegment'), sTabID);
		return false;
	}

	if (iNumSelected > 5)
	{
		alert("You must select no more than five Professions");
		setFocus('creativeSegment', getFieldType('creativeSegment'), sTabID);
		return false;
	}

	return true;

}

function checkSkills()
{
	var sTabID;
	 if (checkSkills.arguments.length > 0) 
	 {
		sTabID = checkSkills.arguments[0];
	 }
	 else
	 {
	  	sTabID = null;
  	 }
	
	iNumSelected = 0;
	iNumSelected += getNumSelected("skills");
	
	if (iNumSelected < 1)
	{
		alert("You must select at least one skill");
		setFocus('skills', getFieldType('skills'), sTabID);
		return false;
	}

	return true;

}



function getNumSelected(sName)
{
	iNumSelected = 0;
	formPanel = document.forms[0];
    
    if (formPanel.elements[sName].length == null)
	{
		if (formPanel.elements[sName].checked)
		{
			iNumSelected++;
		}
	}
	else
	{
		for (var iNum = 0; iNum < formPanel.elements[sName].length; iNum++)
		{
			if (formPanel.elements[sName][iNum].checked)
			{
				iNumSelected++;
			}
		}
	}
    
    //var sCheckName;
    //for (var iNum = 0; iNum < formPanel.elements.length; iNum++) {
    //  sCheckName = formPanel.elements[iNum].name;
    //  while (sName == sCheckName) {
    //    if (formPanel.elements[iNum].checked) {
    //        iNumSelected++;
    //    }
    //    iNum++;
    //    if (iNum < formPanel.elements.length) {
    //      sCheckName = formPanel.elements[iNum].name;
    //    }
    //    else {
    //      sCheckName = "";
    //    }
    //  }
    //}
    
    
    return iNumSelected;

}

function validateMultipleEmails(sName)
{
	//alert("entering validateMultipleEmails on: " + sName);

	var emailAddresses = getFieldValue(sName);
	if (emailAddresses != null && emailAddresses != "")
	{
		var saEmailAddress = split(emailAddresses, ",");
		for (var i=0; i < saEmailAddress.length; i++)
		{
			if (!isEmail(saEmailAddress[i]))
			{
				setFocus(sName);
				return false;
			}
		}
		return true;
	}
	return true;

}

function validateSingleEmail(sName)
{
	var emailAddress = getFieldValue(sName);
	if (emailAddress != null && emailAddress != "")
	{
		var saEmailAddress = split(emailAddress, ",");

		if (saEmailAddress.length > 1)
		{
			alert("E-mail can only be FROM one person");
			setFocus(sName);
			return false;
		}
		else
		{
			if (!isEmail(saEmailAddress))
			{
				setFocus(sName);
				return false;
			}
			return true;
		}
	}
	return true;
}

function setRequired(fieldName, bRequired) {
	//currentField = FieldInfoArray[fieldName];
	var currentField;
	//alert("Setting required for " + fieldName + " to " + bRequired);
	for (var i=0; i < FieldInfoArray.length; i++) {
		currentField = FieldInfoArray[i];
		if(currentField.fieldName == fieldName) {
			//alert("Got it!");
			currentField.required = bRequired;
		}
		//alert(currentField.fieldName + ".required = " + currentField.required);
	}//end for loop
}
