var avFields = new Array();
var sections = new Array();
var dateToFill;

function openCal(v)
{	//eval("temp=findDoc('BodySpan',document)." + v)
  var intWidth=320;
  var intHeight=205;
  var intWidthOffset=240;
  var intHeightOffset=150;
  var strAgent=navigator.userAgent;
  var xCoord;
  var yCoord;
  if (strAgent.indexOf('Mozilla/3')==-1 && strAgent.indexOf('MSIE 3')==-1)
  { 
	 xCoord=screen.width/2 - intWidthOffset;
	 yCoord=(screen.height/2) - intHeightOffset;
  }

  eval("temp=document." + v)
  window.input = temp;
  dateToFill = temp;

  tmp=window.open('DatePicker2.asp?Date='+ temp.value,'Calendar','top='+ yCoord +',left=' + xCoord +',directories=no,menubar=no,scrollbars=no,resizable=no,location=no,toolbar=no,width=' + intWidth +',height=' + intHeight +'');
  if (strAgent.indexOf('MSIE 3')==-1) {
  tmp.focus();
  }
}

function openTime(v)
{	//eval("temp=findDoc('BodySpan',document)." + v)
  var intWidth=155;
  var intHeight=85;
  var intWidthOffset=240;
  var intHeightOffset=150;
  var strAgent=navigator.userAgent;
  var xCoord;
  var yCoord;
  if (strAgent.indexOf('Mozilla/3')==-1 && strAgent.indexOf('MSIE 3')==-1)
  { 
	 xCoord=screen.width/2 - intWidthOffset;
	 yCoord=(screen.height/2) - intHeightOffset;
  }

  eval("temp=document." + v)
  window.input = temp;
  timeToFill = temp;

  tmp=window.open('DatePicker3.asp?Time='+ temp.value,'Calendar','top='+ yCoord +',left=' + xCoord +',directories=no,menubar=no,scrollbars=no,resizable=no,location=no,toolbar=no,width=' + intWidth +',height=' + intHeight +'');
  if (strAgent.indexOf('MSIE 3')==-1) {
  tmp.focus();
  }
}

function fillDate(ReturnDate) 
{
	if (dateToFill.type == "text")
	{
		dateToFill.focus();
	}
	dateToFill.value=ReturnDate.Month + '/' + ReturnDate.Day + '/' + ReturnDate.Year;
}

function fillTime(ReturnTime) 
{
	if (timeToFill.type == "text")
	{
		timeToFill.focus();
	}
	timeToFill.value=ReturnTime;
}

function getForm(span,frm)
{
	if (document.all || navigator.version >= 6) //IE or Netscape 6+
	{
		return document[frm]
	}
	else
	{
		frms = findDoc(span,document)
		for(j=0;j<frms.forms.length;j++)
		{
			if(frms.forms[j].name==frm)
			{
				doc = frms.forms[j];
			}
		}
		return doc
	}
}

function getMonthString(num)
{
 var month;
 switch(num)
 {
   case 0:
     month='January';
     break;
   case 1:
     month='February';
     break;
   case 2:
     month='March';
     break;
   case 3:
     month='April';
     break;
   case 4:
     month='May';
     break;
   case 5:
     month='June';
     break;
   case 6:
     month='July';
     break;
   case 7:
     month='August';
     break;
   case 8:
     month='September';
     break;
   case 9:
     month='October';
     break;
   case 10:
     month='November';
     break;
   case 11:
     month='December';
     break;
 }
 return month;
}

function today() 
{
    var Today = new Date();
    var MonthToday = getMonthString(Today.getMonth());
    var DateToday = Today.getDate();
    var YearToday = Today.getFullYear();
    var Weekday = Today.getDay();
    var x = new Array("Sunday", "Monday", "Tuesday");
    var x = x.concat("Wednesday","Thursday", "Friday");
    var x = x.concat("Saturday");

    var FullDate = x[Weekday]+'<br/><img src="img/spacer.gif" width="5" border="0" />' + MonthToday + ' ' + DateToday + ', ' + YearToday;
    return FullDate;
}

function findDoc(name, doc)
{
	var i, layer;

	if (document.all || navigator.version >= 6) //IE or Netscape 6+
	{
		return (document);
	}
	else
	{
		for (i = 0; i < doc.layers.length; i++)
		{
			layer = doc.layers[i];
			if (layer.name == name)
				return layer.document;
			if (layer.document.layers.length > 0)
			{
				layer = findDoc(name, layer.document);
				if (layer != null)
					return layer.document;
			}
		}
		return null;
	}
}

function SetFormHref()
{
	var href = arguments[0];
	var frmName = arguments[1];
	var bValidate = '';
	var sConfirmation = '';

	if (arguments.length >= 3)
		bValidate = arguments[2];

	if (arguments.length == 4)
		sConfirmation = arguments[3];

	var doc = findDoc("BodySpan", document);

	eval("var frmForm = doc.forms." + frmName);
	if (bValidate)
	{
		if (validateForm(frmForm))
		{
			if (sConfirmation.length > 0) {
				if (!confirm(sConfirmation)) return;
			}	
			frmForm.action = href;
			frmForm.submit();
		}
	}
	else
	{
		if (sConfirmation.length > 0) {
			if (!confirm(sConfirmation)) return;
		}	
		frmForm.action = href;
		frmForm.submit();
	}
}

function tabClick(sDest, sFormName)
{
	var doc = findDoc("BodySpan", document);
	var frmToSubmit = eval("doc.forms." + sFormName);
	
	alert(sDest)
	
	frmToSubmit.Destination.value = sDest;
	frmToSubmit.submit();
}

function NextPage(frmName)
{
	eval("var frm = findDoc('BodySpan', document).forms." + frmName);

	frm.PageNumber.value=frm.NextPage.value;
	frm.submit();

}

function PreviousPage(frmName)
{
	eval("var frm = findDoc('BodySpan', document).forms." + frmName);

	frm.PageNumber.value=frm.PreviousPage.value;
	frm.submit();
}

function LaunchWBT(Href)
{
	window.open(Href);
}

/***********************************************************************************/
/************************** Validation Functions ***********************************/
/***********************************************************************************/


/********************************************
Function: validateForm
Purpose:  Validate all form fields.
Inputs:   Form Object
Returns:  boolean
********************************************/
// Create new event handlers
function validateForm(frm)
{
/*
	// Execute onbeforevalidate processing
	if(typeof this.onbeforevalidate=="function" && this.onbeforevalidate()==false)
		return false;
*/
	var i, oElement, iElements=frm.elements.length;
	// Validate individual elements
	for(i=0;i<iElements;i++)
	{
		oElement=frm.elements[i];
		// Perform default validation for element
		if (!elmValid(oElement))
		{
			return false;
		}
	}
/*
	// Execute onaftervalidate processing
	if(typeof this.onaftervalidate=="function" && this.onaftervalidate()==false)
		return false;

	// Perform original onsubmit event handler
	if (fnSubmit && fnSubmit()==false)
		return false;
*/
	return true;
}

/**********************************************
Method:   elmValid
Purpose:  Validate an element based on the
	  attributes provided in the HTML text
Inputs:   Form Element Object
Returns:  boolean
**********************************************/
function elmValid(oElement)
{
	// Trim leading and trailing spaces
	if(oElement.value)
		oElement.value = trimAll(oElement.value);
	var sValue = getValueOf(oElement);
	// REQUIRED
	if(oElement.REQUIRED && !sValue)
	{
		validationErr(oElement, "Please enter a value");
		return false;
	}
	// FLOAT
	var bSigned=oElement.SIGNED;
	if (oElement.FLOAT && sValue)
	{
		var re=new RegExp("^"+((bSigned)?"-?":"")+"(\\d*(,?\\d{3})*\\.?\\d+|\\d+(,?\\d{3})*\\.?\\d*)$");
		if (!re.test(sValue))
		{
			validationErr(oElement, "Please enter a number");
			return false;
		}
		// MIN
		var iMin = oElement.MIN;
		if(iMin==parseFloat(iMin) && sValue.replace(/,/,"")<iMin)
		{
			validationErr(oElement, "Please enter a value greater than or equal to "+formatNumber(iMin));
			return false;
		}
		// MAX
		var iMax = oElement.MAX;
		if(iMax==parseFloat(iMax) && sValue.replace(/,/,"")>iMax)
		{
			validationErr(oElement, "Please enter a value less than or equal to "+formatNumber(iMax));
			return false;
		}
	}
	// AMOUNT
	if (oElement.AMOUNT && sValue)
	{
		var sSigned = "(\\$?-?|-?\\$?)";
		var re = new RegExp("^"+((bSigned)?sSigned:"\\$?")+"((\\d{1,3})*(,?\\d{3})*\\.?\\d{2}|\\d{1,3}(,?\\d{3})*\\.?(\\d{2})?)$");
		if(!re.test(sValue))
		{
			validationErr(oElement, "Please enter a dollar amount");
			return false;
		}
		// MIN
		var iMin = oElement.MIN;
		if(iMin==parseFloat(iMin) && sValue.replace(/[\$,]/,"")<iMin)
		{
			validationErr(oElement, "Please enter a value greater than or equal to $"+formatNumber(iMin));
			return false;
		}
		// MAX
		var iMax = oElement.MAX;
		if(iMax==parseFloat(iMax) && sValue.replace(/[\$,]/,"")>iMax)
		{
			validationErr(oElement, "Please enter a value less than or equal to $"+formatNumber(iMax));
			return false;
		}
	}
	// INTEGER
	if (oElement.INTEGER && sValue)
	{
		var re=new RegExp("^"+((bSigned)?"-?":"")+"\\d{1,3}(,?\\d{3})*$");
		if (!re.test(sValue))
		{
			validationErr(oElement, "Please enter an whole number (no decimals or other characters)");
			return false;
		}
		// MIN
		var iMin = oElement.MIN;
		if(iMin==parseInt(iMin) && sValue.replace(/,/,"")<iMin)
		{
			validationErr(oElement, "Please enter a value greater than or equal to "+formatNumber(iMin));
			return false;
		}
		// MAX
		var iMax = oElement.MAX;
		if(iMax==parseInt(iMax) && sValue.replace(/,/,"")>iMax)
		{
			validationErr(oElement, "Please enter a value less than or equal to "+formatNumber(iMax));
			return false;
		}
	}
	// ALPHA
	if (oElement.ALPHA && sValue)
	{
		var re=new RegExp("[^a-zA-Z]");
		if (re.test(sValue)) 
		{
			validationErr(oElement, "Please enter only alpha characters (upper or lower case A-Z)");
			return false;
		}
	}
	// DATE
	if (oElement.DATE && sValue)
	{
		// Set default date format
		var sFormat = "DD/MMM/YYYY";
		if (!isDate(sValue,sFormat))
		{
			validationErr(oElement, "Please enter a date as MM/DD/YYYY");
			return false;
		}
	}
	// TIME
	if (oElement.TIME && sValue)
	{
		var re=new RegExp("^(0{0,1}[1-9]|1[0-2]):[0-5][0-9] *[aApP]\.{0,1}[mM]\.{0,1}$");
		if (!re.test(sValue)) 
		{
			validationErr(oElement, "Please enter a time as HH:MM am or HH:MM pm");
			return false;
		}
	}
	// REGEXP
	var oRegexp=oElement.REGEXP;
	if(oRegexp && oRegexp.constructor==RegExp && sValue)
	{
		if(!oRegexp.test(sValue))
		{
			validationErr(oElement, "Please enter a valid value");
			return false;
		}
	}
	// EQUALS
	var oEqualValue=oElement.EQUALS;
	if(typeof(oEqualValue) != 'undefined')
	{
		var sEqualValue = getValueOf(oEqualValue);
		if (sValue || sEqualValue)
		{
			if(String(sEqualValue) != String(sValue))
			{
				validationErr(oElement, "Values must be the same in both fields.");
				return false;
			}
		}
	}
	// LESSEQUAL
	var oCompValue=oElement.LESSEQUAL;	
	if(typeof(oCompValue) != 'undefined')
	{
		var sCompValue = getValueOf(oCompValue);
		    		
		if (sValue && sCompValue) 	// both values are non blank
		{
			sLeftValue = parseValue(oElement);
			sRightValue = parseValue(oCompValue);

			if(sLeftValue > sRightValue)
			{
				validationErr(oElement, "Value must be less or equal than " + sCompValue + ".");
				return false;
			}

		}
	}	
	
	// LESSTHAN
	var oCompValue=oElement.LESSTHAN;	
	if(typeof(oCompValue) != 'undefined')
	{
		var sCompValue = getValueOf(oCompValue);
		    		
		if (sValue && sCompValue) 	// both values are non blank
		{
			sLeftValue = parseValue(oElement);
			sRightValue = parseValue(oCompValue);

			if(sLeftValue >= sRightValue)
			{
				validationErr(oElement, "Value must be less than " + sCompValue + ".");
				return false;
			}

		}
	}	

	// GREATEREQUAL
	var oCompValue=oElement.GREATEREQUAL;	
	if(typeof(oCompValue) != 'undefined')
	{
		var sCompValue = getValueOf(oCompValue);
		    		
		if (sValue && sCompValue) 	// both values are non blank
		{
			sLeftValue = parseValue(oElement);
			sRightValue = parseValue(oCompValue);

			if(sLeftValue < sRightValue)
			{
				validationErr(oElement, "Value must be greater or equal than " + sCompValue + ".");
				return false;
			}

		}
	}	
	
	// GREATERTHAN
	var oCompValue=oElement.GREATERTHAN;	
	if(typeof(oCompValue) != 'undefined')
	{
		var sCompValue = getValueOf(oCompValue);
		    		
		if (sValue && sCompValue) 	// both values are non blank
		{
			sLeftValue = parseValue(oElement);
			sRightValue = parseValue(oCompValue);

			if(sLeftValue <= sRightValue)
			{
				validationErr(oElement, "Value must be greater than " + sCompValue + ".");
				return false;
			}

		}
	}	
	
	// PHONE
	if(oElement.PHONE && sValue)
	{
		var sPhone  = sValue.replace(/\D/g,"");
		var iDigits = sPhone.length;
		if( !(iDigits==10 || iDigits==11 && /^1/.test(sPhone)) )
		{
			validationErr(oElement, "Please enter a valid phone number");
			return false;
		}
	}
	// MAXLEN
	if(sValue && oElement.MAXLEN && isNum(oElement.MAXLEN) && sValue.length>oElement.MAXLEN)
	{
		validationErr(oElement, "Please enter a value with no more than " + formatNumber(oElement.MAXLEN) + " characters");
		return false;
	}
	// MINLEN
	if(sValue && oElement.MINLEN && isNum(oElement.MINLEN) && sValue.length<oElement.MINLEN)
	{
		validationErr(oElement, "Please enter a value with at least " + formatNumber(oElement.MINLEN) + " characters");
		return false;
	}
	// EMAIL
	if(oElement.EMAIL && sValue)
	{
		if(!/^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i.test(sValue))
		{
			validationErr(oElement, "Please enter a valid email address");
			return false;
		}
	}
	// ZIP Code
	if(oElement.ZIP && sValue)
	{
		if(!/^\d{5}(-?\d{4})?$/.test(sValue))
		{
			validationErr(oElement, "Please enter a valid ZIP code");
			return false;
		}
	}
	// AND
	var vAnd=typeof oElement.AND=="object";;
	if(vAnd && sValue)
	{
		vAnd = oElement.AND["fields"];
		if (vAnd)
		{
			// If not an array, create one
			if(vAnd.constructor!=Array)
				vAnd = vAnd.toString().split(/,/);
			// Require each element in the list
			var i, iFields=vAnd.length;
			for(i=0; i<iFields; i++)
			{
				var oNewElement =
					(vAnd[i].form)
					? vAnd[i]
					: oElement.form.elements[trimAll(vAnd[i])];
				if(oNewElement)
				{
					if(!getValueOf(oNewElement))
					{
						validationErr(oElement, oElement.AND["MSG"]?oElement.AND["MSG"]:"Please enter a value");
						return false;
					}
				}
			}
		}
	}
	// OR
	var vOr=typeof oElement.OR=="object";
	if(vOr && !sValue)
	{
		vOr = oElement.OR["fields"];
		if(vOr)
		{
			// If not an array, create one
			if(vOr.constructor!=Array)
				vOr = vOr.toString().split(/,/);
			// Require each element in the list
			var i, iFields=vOr.length;
			var bValue=false;
			for(i=0; i<iFields; i++)
			{
				var oNewElement =
					(vOr[i].form)
					? vOr[i]
					: oElement.form.elements[trimAll(vOr[i])];
				if(oNewElement)
					bValue |= !!getValueOf(oNewElement);
			}
			if(!bValue)
			{
				validationErr(oElement, oElement.OR["MSG"]?oElement.OR["MSG"]:"Please enter a value");
				return false;
			}
		}
	}
	// XOR
	var vXor=typeof oElement.XOR=="object";
	if(vXor)
	{
		vXor = oElement.XOR["fields"];
		if(vXor)
		{
			// If not an array, create one
			if(vXor.constructor!=Array)
				vXor = vXor.toString().split(/,/);
			// Require each element in the list
			var i, iFields=vXor.length;
			var bValue=!!sValue;
			var found = bValue;
			for(i=0; i<iFields; i++)
			{
				var oNewElement =
					(vXor[i].form)
					? vXor[i]
					: oElement.form.elements[trimAll(vXor[i])];
				if(oNewElement)
					bValue ^= !!getValueOf(oNewElement);
				if (found && !bValue)
					break;
			}
			if(!bValue)
			{
				validationErr(oElement, oElement.XOR["MSG"]?oElement.XOR["MSG"]:"Please enter a value");
				return false;
			}
		}
	}
	// NOSPACE
	if (oElement.NOSPACE && oElement.value)
		oElement.value=oElement.value.replace(/\s/g,"");
	// UPPERCASE
	if (oElement.UPPERCASE && oElement.value)
		oElement.value=oElement.value.toUpperCase();
	// LOWERCASE
	if (oElement.LOWERCASE && oElement.value)
		oElement.value=oElement.value.toLowerCase();

	// Perform onvalidate event handler
	if(typeof oElement.onvalidate=="function" && oElement.onvalidate()==false)
		return false;

	return true;
}
/********************************************
Function: getValueOf
Purpose:  Return the value of a form field as seen at server
Inputs:   oElement - form field
Returns:  boolean
********************************************/
function getValueOf(oElement)
{

	var sReturnValue = null;
	switch (oElement.type)
	{
		case "text" : case "textarea" : case "file" : case "password" : case "hidden" :
			sReturnValue = oElement.value;
			break;
		case "select-one" :
			if (oElement.selectedIndex > -1)
				sReturnValue = oElement.options[oElement.selectedIndex].value;
			else
				sReturnValue = false;
			break;
		case "select-multiple" :
			var i, iOptions = oElement.options.length;
			for(i=0; i<iOptions; i++)
				if(trimAll(oElement.options[i].selected && String(oElement.options[i].value)))
				{
					sReturnValue = true;
					break;
				}
			break;
		case "radio" : case "checkbox" :
			if(oElement.checked)
				sReturnValue = oElement.value ? oElement.value : true;
			break;
	}
	return sReturnValue;
}

/*====================================================================
Function: Err
Purpose:  Custom object constructor
Inputs:   None
Returns:  undefined
====================================================================*/
function validationErr()
{
	var oSource  = arguments[0];
	var sMessage = arguments[1];

	var sName = oSource.NAME;
	var sMsg  = oSource.MSG;
	
	// Alert appropriate error message
	sMsg = sMsg ? sMsg : sMessage + (sName ? " in the "+sName+" field" : "");

	popErrAlert(sMsg);
	
	if(oSource.NOFOCUS) 
		return false;
	if(oSource.type == "hidden") 
		return false;
		
	// Give invalid field focus
	if(oSource.focus)
		oSource.focus();
	if(oSource.select)
		oSource.select();
}

function popErrAlert(msgErr)
{
	var lenErr = String(msgErr).length;
	var strLen = 20;

	if (lenErr > 0)
	{
		if (lenErr > strLen) {
			var tMsg = '';
			var len = Math.floor(lenErr/strLen);
			var sep = ' ';
			var sep2 = ' ';
			var startCnt = 0;
			var endCnt = 0;

			for (var i = 0; i < len + 1;i++)
			{
				if (i == 0)
				{
					sep = '';
					startCnt = 0;
				}
				else
				{
					sep = ' ';
					startCnt = msgErr.indexOf(sep,strLen*i) + 1;
				}

				endCnt = msgErr.indexOf(sep2,strLen*(i+1)) - startCnt;

				if (((i + 1) * strLen) < lenErr)
				{
					if (msgErr.indexOf(sep,strLen*(i+1)) > -1)
					{
						if (msgErr.indexOf(sep,strLen*(i+1)) != startCnt)
							tMsg += "   " + msgErr.substr(startCnt,endCnt)
								 + "\n";
					}
					else
					{
						tMsg += "   " + msgErr.substr(startCnt)
						break;
					}
				}
				else
				{
					tMsg += "   " + msgErr.substr(tMsg.length - (3 * i))
				}
			}
			msgErr = tMsg;
		}

		var msg = "________________________\nThe following error occurred:\n\n\n";
		msg += msgErr;
		msg += "\n\n\n________________________\nPlease correct.";
		alert(msg);
	}

}


function isDate( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only 
    valid dates with 2 digit month, 2 digit day, 
    4 digit year. Date separator can be ., -, or /.
    Parses a date, and then validates it.
    Ex. mm/dd/yyyy or mm-dd-yyyy 
    
PARAMETERS:
   strValue - String to be tested for validity
   
RETURNS:
   True if valid, otherwise false.
   
REMARKS:
   Avoids some of the limitations of the Date.parse()
   method such as the date separator character.
*************************************************/

	var sParsedDate = parseDate(strValue);
        
        // extract day, month and year
	intDay = sParsedDate % 100;
	sParsedDate = (sParsedDate - intDay) / 100; 
	intMonth = sParsedDate % 100;
	sParsedDate = (sParsedDate - intMonth) / 100; 
	intYear = sParsedDate;
	
	
	if(intMonth > 12 || intMonth < 1) {
		return false;
	}
	
	if(intYear > 9999 || intYear < 1753) {
		return false;
	}
	
	//create a lookup for months not equal to Feb.
	var arrayLookup = { '1' : 31,'3' : 31, '4' : 30,'5' : 31,'6' : 30,'7' : 31,
			    '8' : 31,'9' : 30,'10' : 31,'11' : 30,'12' : 31}

		//check if month value and day value agree
		if(arrayLookup[intMonth] != null) {
			if(intDay <= arrayLookup[intMonth] && intDay != 0)
				return true; //found in lookup table, good date
		}

		//check for February
		var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
		if( ((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <=28)) && intDay !=0)
			return true; //Feb. had valid number of days
  		return false; //any other values, bad date
  		
}

/********************************************
Function: isNum
Purpose:  Check that parameter is a number
Inputs:   v - string value
Returns:  boolean
********************************************/
function isNum(v)
{
	return (typeof v!="undefined" && v.toString() && !/\D/.test(v));
}
/********************************************
Function: formatNumber
Purpose:  Format an integer for display
Inputs:   i - integer value (as string)
Returns:  string
********************************************/
function formatNumber(i)
{
	var sEnd="$";
	i = i.toString();
	if (/\./.test(i))
		sEnd="\\.";
	var re = new RegExp("(\\d)(\\d{3})(,|"+sEnd+")");
	if(re.test(i))
		i = formatNumber(i.replace(re, "$1,$2$3"));
	return i;
}

/************************************************
DESCRIPTION: Removes leading and trailing spaces.

PARAMETERS: Source string from which spaces will
  be removed;

RETURNS: Source string with whitespaces removed.
*************************************************/ 
function trimAll( strValue ) {

 var objRegExp = /^(\s*)$/;

   //check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = String(strValue).replace(objRegExp, '$2');
    }
  return strValue;
}

/************************************************
DESCRIPTION: Returns a reformated value of the field
             that is usable for comparason.

PARAMETERS: form field;

RETURNS: For numbers string with whitespaces, leading zeros, and commas removed.
         For amount string with $,whitespaces, leading zeros, and commas removed.
         For date, date in YYYYMMDD format. Did not use number of seconds since 
         beginning of time since it doesn't support dates before 01/01/1970
*************************************************/ 
function parseValue( oElement ) {
	var sReturnValue;
	if(typeof(oElement) != 'undefined') {
		
		sReturnValue = getValueOf(oElement);
		
		if (oElement.DATE) {    // convert to number of seconds since beginning of time
                        sReturnValue = parseDate(sReturnValue);
		}
		
		if (oElement.AMOUNT) {  // remove $ and then treat as numeric
			sReturnValue = sReturnValue.replace(/[\$,]/,"");
		}
		
		if (oElement.AMOUNT || oElement.INTEGER || oElement.FLOAT) {				
			sReturnValue = sReturnValue.replace(/,/,"");
			sReturnValue = parseFloat(sReturnValue);  
		}
		
	}

	return sReturnValue;
}

/************************************************
DESCRIPTION: Parses and returns a date in YYYYMMDD format.

PARAMETERS: String value representing a date;

RETURNS: Integer as YYYYMMDD, zero if invalid
*************************************************/ 
function parseDate(strValue) {
	if (strValue.indexOf("-") != -1) { 	// MM-DD-YYYY format
 		sections = strValue.split("-")
 	}	
 	else if (strValue.indexOf("/") != -1) { 	// MM/DD/YYYY format
		sections = strValue.split("/")
	}
 	else if (strValue.indexOf(".") != -1) { 	// MM.DD.YYYY format
		sections = strValue.split(".")
	}
	else {
		return (20020000);
	}
	
	if (sections.length != 3) {
		return 0;
	}	
 	
	//Day
	intMonth = sections[0];	
	intDay = sections[1];

	if (intDay.length == 3) {       // dd-mmm format
		intDay = sections[0];	// switch day and month
		intMonth = sections[1];	// and look up the month
		
		//Month 	
		args = ",JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC".split(",")
		m = new Object()
		for(i=1;i<13;i++) {
			m[args[i]] = i;
		}
		intMonth = m[sections[1].toUpperCase()];

		if (intMonth == "undefined") {
			return 0;
		}
	}

	//Year
	intYear = sections[2];
	if (intYear.length > 4) {
		return 0;
	}
	if (intYear.length != 4 ) { 
	
	        // if year is not 4 digit, 
	        // assume that it is in +/-50 years time frame
	        
		var Today = new Date();
    		var YearToday = Today.getFullYear();
    		
    		var iShortYear = YearToday % 100;
    		var iCent = (YearToday - iShortYear) / 100;
		
		if (Math.abs(iShortYear - intYear) <= 50)  { 
			intYear = iCent * 100 + parseInt(intYear,10); // same century
		}
		else {
			intYear = (iCent - 1) * 100 + parseInt(intYear,10); // previous cent
		}
		
	}


	return (10000 * intYear + 100 * intMonth + parseInt(intDay,10));
}
/***********************************************************************************/
/**********************   End of Validation Functions  *****************************/
/***********************************************************************************/