/*****************************************************************
* Name:
*	Validator
*
* Purpose:
*	A function which builds a custom javascript object with
*	properties that are used when validation occurs.
*	
* Parameters:
*
*	ControlName		- HTML element name to validate
*	FormIndex		- Form index reference in which the 
*					  ControlName can be found
*	DataType		- Type of data
*	Required		- true / false value indicating required
*					  element or not
*	MinValue		- Minimum value accepted (optional)
*	MaxValue		- Maximum value accepted (optional)
*	AlertMsg		- Message to be displayed in an alert box
*					  if validation fails
*	MinMaxMsg		- Message to be displayed in an alert box
*					  if min / max validation fails (optional)
*
* Created: 
*	SR 02/22/2002
*
* History:
*   ~ 1	KP  08/31/2007 - #69423  Added replaceMSWORDCharCodes (s) to replace msword macro character codes
*	~ 2	KP  09/04/2007 - #69731  Removed the following if block -  if ( document.forms[0].opgFeidType )...
*   ~ 3 KP  09/20/2007 - #69423  Updated replaceMSWORDCharCodes (s) with more non-readable character codes
*	~ 4 BH	10/32/2007 - #72225  Added logic to keep disabled fields being set to focus. This causes crashes.
*   ~ 5 TN  08/27/2008 - #88007  Modified email validate emailReg
*   ~ 6 DC  06/16/2009 - #103517 Account for nub users that enter more than one email into single email fields.
*   ~ 7 DC  09/11/2009 - #111421 Modified IsDigit function
*   ~ 7 JDM 06/21/2007 - #133254 JS Alert in Safari
*   ~ 8 JDM 07/08/2010 - #134823 page crash on employer save
*
* Output:
*	Object
*****************************************************************/
function Validator(ControlName, FormIndex, DataType, Required, 
				   MinValue, MaxValue, AlertMsg, MinMaxMsg)
{
	// Build custom validator object
	
	this.ControlName = ControlName;
	this.FormIndex = FormIndex;
	this.DataType = DataType;
	this.Required = Required;
	this.MinValue = MinValue;
	this.MaxValue = MaxValue;
	this.AlertMsg = AlertMsg;
	this.MinMaxMsg = MinMaxMsg;
	
}

/*****************************************************************
* Name:
*	ValidateIt
*
* Purpose:
*	Processes an array that contains Validator objects.
*	
* Parameters:
*
*	ary			- An array that contains validator objects
*	cumulative	- true / false indicating whether to group 
*				  all alert messages into 1 dialog or display
*				  messages 1 at a time (optional).
*
* Created: 
*	SR 02/22/2002
*
* History:
*	~ 1 SR 03/21/2002 - Performed check of element type to 
*						determine whether or not to set focus to.
*	~ 2 SS 04/15/2002 - Added AlphaNumericSpace to handle spaces within
*						strings
*	~ 3 SR 06/11/2002 - Function will now skip validating hidden 
*						elements.
*	~ 4 SR 11/07/2002 - Added support for a form name as well as form
*						index number for the FormIndex property.
*	~ 5 SR 10/10/2006 - Added support for a single radio button
*   ~ 6 KQ 07/14/2011 - #169222 Fixed safari issue removing "if typeof(obj) == "object"" and replaced with "if obj"
*
* Output:
*	Boolean
*****************************************************************/
function ValidateIt(ary, cumulative)
{
	// Declare local vars

	var counter = 0;		// loop counter
	var length = 0;			// array length var
	var result = false;		// flag var

	// Cumulative intro message
	var cumulativeIntroMsg = "The following items need attention:\r\n\r\n";
	var cumulativeMsg = "";
	
	// Object reference
	var obj = null;
	

	// Was an array passed?
	if (typeof(ary) == "undefined")
	{
		alert("Developer Error: No array has been passed to be validated!");
		return false;
	}

	// Determine length of array
	if (ary.length)	{ length = ary.length }
		
	
	// Loop through array and validate objects	
	for (counter=0; counter < length; counter++)
	{
		
		// Determine if form name or index has been supplied
		if (isNaN(parseInt(ary[counter].FormIndex)))
		{
			// Get an object reference to the HTML control
			obj = eval("document.forms." + ary[counter].FormIndex + "." + ary[counter].ControlName);
		}
		else
		{
			// Get an object reference to the HTML control
			obj = eval("document.forms[" + ary[counter].FormIndex + "]." + ary[counter].ControlName);
		}


         // uncomment for debugging
      // Did it eval?
      //if (typeof(obj) != "object") 
      //{ 
      //	alert("Developer Error: document.forms[" + ary[counter].FormIndex + "]." + ary[counter].ControlName + " did not evaluate to a valid object!");
      //	return false;
      //}
    

           // SR 06/11/2002
        // If object is a hidden element, skip validation
        // 134823
        //if (typeof (obj) == "object") //169222 commented out due to it is not working on safari browsers
        if (obj) 
        {
		    if (obj.type == "hidden") { continue; }
		}
		    else
        {
           // alert("Developer Error: document.forms[" + ary[counter].FormIndex + "]." + ary[counter].ControlName + " did not evaluate to a valid object!");
      
		      return true;
		}
		/*****************************************************************
		*
		* Determine validation function to run
		*
		*****************************************************************/
		
		if (ary[counter].DataType == "RE")
		{
			result = ValidateText(Trim(obj), ary[counter].Required)
			//MinMax is checked via ValidateRange and uses Regular Expressions passed via Min and Max value parameters :-)
			if (ary[counter].MaxValue.length == 0){ary[counter].MaxValue = ary[counter].MinValue;}
		}

		if (ary[counter].DataType == "TEXT")
		{
			result = ValidateText(Trim(obj), ary[counter].Required);
		}
		
		if (ary[counter].DataType == "DATE")
		{
			result = ValidateDate(obj, ary[counter].Required);
		}
		
		if (ary[counter].DataType == "SELECT")
		{
			result = ValidateSelect(obj, ary[counter].Required);
		}

		if (ary[counter].DataType == "RADIO")
		{
			result = ValidateRadio(obj, ary[counter].Required);
		}

		if (ary[counter].DataType == "CHECKBOX")
		{
			result = ValidateCheckbox(obj, ary[counter].Required);
			//Min and Max number of checkboxes can be required by passing them in using the Min/Max value parameters :-)
		}

		if (ary[counter].DataType == "ALPHA")
		{
			result = ValidateAlpha(Trim(obj), ary[counter].Required);
		}

		if (ary[counter].DataType == "ALPHANUMERIC")
		{
			result = ValidateAlphaNumeric(Trim(obj), ary[counter].Required);
		}

		if (ary[counter].DataType == "ALPHANUMERICSPACE")
		{
			result = ValidateAlphaNumericSpace(Trim(obj), ary[counter].Required);
		}

		if (ary[counter].DataType == "NUMERIC")
		{
			result = ValidateNumeric(Trim(obj), ary[counter].Required);
		}

		if (ary[counter].DataType == "CURRENCY")
		{
			result = ValidateCurrency(Trim(obj), ary[counter].Required);
		}

		if (ary[counter].DataType == "EMAIL")
		{
			result = ValidateEmail(Trim(obj), ary[counter].Required);
		}

		if (ary[counter].DataType == "ZIPCODE")
		{
			result = ValidateZipCode(Trim(obj), ary[counter].Required);
		}

		
		/***********************************************************
			Added By EC(02/28/2003)
		************************************************************/
		if (ary[counter].DataType == "DECIMAL")
		{
			result = ValidateDecimal(Trim(obj), ary[counter].Required);
		}
		/***************************************************************/
		
		/*****************************************************************
		*
		* Handle result of validation function and call range validation
		* if neccessary.
		*
		*****************************************************************/

		// Was the result true?
		if (result)
		{
			// Is there a min / max validation value?
			if (ary[counter].MinValue != "" && ary[counter].MaxValue != "")
			{
				// Validate min / max range
				result = ValidateRange(obj, ary[counter].Required, ary[counter].DataType, ary[counter].MinValue, ary[counter].MaxValue)
			}

			// Did range validation fail?
			if (!result)
			{
				// Is cumulative messaging turned on?
				if (cumulative)
				{
					// Add message to cumulative message var
					cumulativeMsg += "- " + ary[counter].MinMaxMsg + "\r\n";
				}
				else
				{
					// Display custom validation error message
					alert(ary[counter].MinMaxMsg);
					
					// Set focus to control that failed validation
					if (ary[counter].DataType != "RADIO")
					{
						if (ary[counter].DataType != "CHECKBOX")
						{
							// Check for element type of hidden
							if (obj.type != "hidden")
							{
								obj.focus();
							}
						}
						else
						{
							if (obj.length)
							{
								//BH #72225 - Do not set focus to a disabled field
								if(obj[0].disabled == false)
								{
									obj[0].focus();
								}
							}
							else
							{
								//BH #72225 - Do not set focus to a disabled field
								if(obj.disabled == false)
								{
									obj.focus();
								}
							}
						}
					}
					else
					{
						if (obj.length)
						{
							//BH #72225 - Do not set focus to a disabled field
							if(obj[0].disabled == false)
							{
								obj[0].focus();
							}
						}
						else
						{
							//BH #72225 - Do not set focus to a disabled field
							if(obj.disabled == false)
							{
								obj.focus();
							}
						}
					}
				
					
					return false;
				}
			}
		}
		else	// Validation failed
		{

			// Is cumulative messaging turned on?
			if (cumulative)
			{
				// Add message to cumulative message var
				cumulativeMsg += "- " + ary[counter].AlertMsg + "\r\n";
			}
			else
			{
				// Display custom validation error message
				alert(ary[counter].AlertMsg);
				
				// Set focus to control that failed validation
				if (ary[counter].DataType != "RADIO")
				{
					if (ary[counter].DataType != "CHECKBOX")
					{
						// Check for element type of hidden
						if (obj.type != "hidden")
						{
							try{obj.focus()}catch(e){};
						}
					}
					else
					{
						if (obj.length)
						{
							//BH #72225 - Do not set focus to a disabled field
							if(obj[0].disabled == false)
							{
								obj[0].focus();
							}
						}
						else
						{
							//BH #72225 - Do not set focus to a disabled field
							if(obj.disabled == false)
							{
								obj.focus();
							}
						}
					}
				}
				else
				{
					if (obj.length)
					{
						//BH #72225 - Do not set focus to a disabled field
						if(obj[0].disabled == false)
						{
							obj[0].focus();
						}
					}
					else
					{
						//BH #72225 - Do not set focus to a disabled field
						if(obj.disabled == false)
						{
							obj.focus();
						}
					}
				}
				
				return false;
			}
		}

	}	// End For Loop
	
	
	// Check length of cumulative message variable... do we have something to display?
	if (cumulative && cumulativeMsg.length > 0)
	{
		alert(cumulativeIntroMsg + cumulativeMsg);
		return false;
	}
	
	
	// If we have gotten here... all is good!
	return true;
	
}

/*****************************************************************
* Name:
*	ValidateText
*
* Purpose:
*	To validate a string or object and see if its value has been
*	populated.
*	
* Parameters:
*
*	obj			- A string or object reference
*	required	- true / false value indicating whether the value
*				  is required (optional).
*
* Created: 
*	SR 02/22/2002
*
* History:
*	~ 1 DC 07/06/2007 - #63891 - Added whitespace checking to validator
*
* Output:
*	Boolean
*****************************************************************/
function ValidateText(obj, required)
{
    var str
    var validchars
    
    // Regular expression for testing of valid data. \S+ means non-whitespace characters i.e. a-z or 0-9 or punctuation
    validchars = /\S+/
    
	// Process if obj parameter is of object type
	if (typeof(obj) == "object")
	{
        str = obj.value
        if (required && (obj.value.length == 0 || !validchars.test(str)))
		{
			return false;
		}
	}
	
	// Process if obj parameter is of string type
	if (typeof(obj) == "string")
	{
	    str = obj
		if (required && (obj.length == 0 || !validchars.test(str)))
		{
			return false;
		}
	}
	
	return true;
}

/*****************************************************************
* Name:
*	ValidateDate
*
* Purpose:
*	To validate a string or object and see if its value is a true
*	date.
*	
* Parameters:
*
*	obj			- A string or object reference
*	required	- true / false value indicating whether the value
*				  is required (optional).
*
* Created: 
*	SR 02/22/2002
*
* History:
*	~ 1 SR 08/07/2008 #86783 - Add low and high date range limits that are 
*           compatible with SQL server's smalldatetime data type.
*
* Output:
*	Boolean
*****************************************************************/
function ValidateDate(obj, required)
{

	var thedate;
	
	var mindate = new Date(Date.parse("01/01/1900"));
	var maxdate = new Date(Date.parse("06/06/2079"));
	
	// Store date value to var
	if (typeof(obj) == "object") { thedate = obj.value; }
	if (typeof(obj) == "string") { thedate = obj; }
	

	// If not required and value is empty, nothing to validate...
	if (!required && thedate.length == 0) { return true; }
	
    // regular expression to match required date format
    re = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
    
    if(regs = thedate.match(re)) 
    {
        if(regs[2] < 1 || regs[2] > 31) 
        {
            return false;
        } 
        else if(regs[1] < 1 || regs[1] > 12) 
        {
            return false;
        } 
        else if(regs[3] < mindate.getFullYear() || regs[3] > maxdate.getFullYear()) 
        {
            return false;
        }
    } 
    else 
    {
       return false;
    }

	// Populate array based on "/" as a delimiter
	// Use "123456789/" to initiate this error
	if (thedate.indexOf("/") != -1)
	{
		var sdate = thedate.split("/")
		
		// SR 05/31/2001
		// Check to make sure month is a length of 2
		if (isNaN(sdate[0]) || sdate[0] < 0)
		{
			return false;
		}
		
		// Check to make sure day is a length of 2
		if (isNaN(sdate[1]) || sdate[1] < 0)
		{
			return false;
		}

		// Check to make sure year is a length of 4
		if (isNaN(sdate[2]) || sdate[2] < 0)
		{
			return false;
		}

	}
	else // Use "1234567890" to initiate this error
	{
		return false;
	}

	// Attempt to construct a JavaScript date 
	var JSDate = new Date(Date.parse(thedate))

	// Store date pieces to separate variables
	var month = JSDate.getMonth()+1;
	var day = JSDate.getDate();
	var year = JSDate.getYear();

	// Do we have valid numbers for the date parts?
	// Use "aa/aa/aaaa" to initiate this error
	if (isNaN(month) || isNaN(day) || isNaN(year)) { return false; }

	// Fix for year 2000
	if (navigator.appVersion.indexOf("MSIE") > -1 || (navigator.appName == "Netscape" && parseInt(navigator.appVersion.charAt(0)) <= 3))
	{
		if (year < 100) year += 1900;
	}
	if (navigator.appName == "Netscape" && parseInt(navigator.appVersion.charAt(0)) >= 4)
	{
		year += 1900;
	}

	// Re-assemble date
	var theDate1 = (month) + "/" + (day) + "/" + (year);
	var theDate2 = (Math.abs(sdate[0])) + "/" + (Math.abs(sdate[1])) + "/" + (Math.abs(sdate[2]));
	// Use a valid date and uncomment next line to initiate this error
	// theDate2 = ""	

	if (theDate1 != theDate2) { return false; }

    if (JSDate < mindate || JSDate > maxdate) 
    {
        return false;
    }
    
	return true;
}

/*****************************************************************
* Name:
*	ValidateSelect
*
* Purpose:
*	To validate a select object and see if a valid item has been
*	selected.
*	
* Parameters:
*
*	obj			- A object reference
*	required	- true / false value indicating whether the value
*				  is required (optional).
*
* Created: 
*	SR 02/22/2002
*
* History:
*	~ 1 
*
* Output:
*	Boolean
*****************************************************************/
function ValidateSelect(obj, required) 
{

	// set index variable
	var index = -1;
	
	// loop through all items in the select list
	for (var i = 0; i < obj.length; i++) 
	{
		if (obj[i].selected && obj[i].value != "") 
		{
			index = i;
		}
	}

	// has an option been selected
	if (index == -1 && required) { return false; }

	return true;
}

/*****************************************************************
* Name:
*	ValidateRadio
*
* Purpose:
*	To validate a radio object and see if an option has been
*	selected.
*	
* Parameters:
*
*	obj			- A object reference
*	required	- true / false value indicating whether the value
*				  is required (optional).
*
* Created: 
*	SR 02/22/2002
*
* History:
*	~ 1 SR 10/10/2006 - Added support for a single radio button
*
* Output:
*	Boolean
*****************************************************************/
function ValidateRadio(obj, required) 
{

	// set index variable
	var index = -1;

	if (!obj.length)
	{
		if (obj.checked) {index = 0};
	}
	else
	{
		// loop through all items in the radio group
		for (var i = 0; i < obj.length; i++) 
		{
			if (obj[i].checked) { index = i; }
		}
	}
		
	// has a radio option been selected
	if (index == -1 && required) { return false; }
   
    
	return true;
}

/*****************************************************************
* Name:
*	ValidateCheckbox
*
* Purpose:
*	To validate a checkbox object and see if an option has been
*	selected.
*	
* Parameters:
*
*	obj			- A object reference
*	required	- true / false value indicating whether the value
*				  is required (optional).
*
* Created: 
*	BKB 04/15/2002 - Cloned ValidateRadio and added length check
*
* History:
*	~ 1 
*
* Output:
*	Boolean
*****************************************************************/
function ValidateCheckbox(obj, required) 
{

	if (obj.length)
	{
		// set index variable
		var index = -1;
		
		// loop through all items in the radio group
		for (var i = 0; i < obj.length; i++) 
		{
			if (obj[i].checked) { index = i; }
		}
		
		// has a radio option been selected
		if (index == -1 && required) { return false; }
	}
	else
	{
		if (!obj.checked && required)
		{
			return false;
		}
	}

	return true;
}

/*****************************************************************
* Name:
*	ValidateAlpha
*
* Purpose:
*	To validate a string or object and see if its value is made
*	up of alpha only characters.
*	
* Parameters:
*
*	obj			- A string or object reference
*	required	- true / false value indicating whether the value
*				  is required (optional).
*
* Created: 
*	SR 02/22/2002
*
* History:
*	~ 1 
*
* Output:
*	Boolean
*****************************************************************/
function ValidateAlpha(obj, required)
{

	// Declare local vars
	var curChar;
	var i;

	// Holds the numeric value
	var thevalue;
	
	// Holds the numeric values length
	var thelength;
	
	// set index variable
	var index = -1;
	
	// Process if obj parameter is of object type
	if (typeof(obj) == "object")
	{
		thevalue = obj.value;
		thelength = obj.value.length;
	}

	// Process if obj parameter is of string type
	if (typeof(obj) == "string")
	{
		thevalue = obj;
		thelength = obj.length;
	}
	
	for (var i = 0; i < thelength; i++)
	{
		index = i;
		var curChar = thevalue.charAt(i);
	    if (!IsLetter(curChar)) { return false; }
	}
	
	// If this was required, was there any character data?
	if (index == -1 && required) { return false; }
	
	return true;
}

/*****************************************************************
* Name:
*	ValidateNumeric
*
* Purpose:
*	To validate a string or object and see if its value is made
*	up of numeric only characters.
*	
* Parameters:
*
*	obj			- A string or object reference
*	required	- true / false value indicating whether the value
*				  is required (optional).
*
* Created: 
*	SR 02/22/2002
*
* History:
*	~ 1 
*
* Output:
*	Boolean
*****************************************************************/
function ValidateNumeric(obj, required)
{

	// Declare local vars
	var curChar;
	var i;

	// Holds the numeric value
	var thevalue;
	
	// Holds the numeric values length
	var thelength;
	
	// set index variable
	var index = -1;
	
	// Process if obj parameter is of object type
	if (typeof(obj) == "object")
	{
		thevalue = obj.value;
		thelength = obj.value.length;
	}

	// Process if obj parameter is of string type
	if (typeof(obj) == "string")
	{
		thevalue = obj;
		thelength = obj.length;
	}
	
	
	for (var i = 0; i < thelength; i++)
	{
		index = i;
		var curChar = thevalue.charAt(i);
	    if (!IsDigit(curChar)) { return false; }
	}
	
	// If this was required, was there any character data?
	if (index == -1 && required) { return false; }
	
	return true;
}

/*****************************************************************
* Name:
*	ValidateAlphaNumeric
*
* Purpose:
*	To validate a string or object and see if its value is made
*	up of alpha-numeric only characters.
*	
* Parameters:
*
*	obj			- A string or object reference
*	required	- true / false value indicating whether the value
*				  is required (optional).
*
* Created: 
*	SR 02/22/2002
*
* History:
*	~ 1 
*
* Output:
*	Boolean
*****************************************************************/
function ValidateAlphaNumeric(obj, required)
{
	
	var curChar;
	var i;
	
	// set index variable
	var index = -1;

	// Holds the alphanumeric value
	var thevalue;
	
	// Holds the alphanumeric values length
	var thelength;
	
	// Process if obj parameter is of object type
	if (typeof(obj) == "object")
	{
		thevalue = obj.value;
		thelength = obj.value.length;
	}

	// Process if obj parameter is of string type
	if (typeof(obj) == "string")
	{
		thevalue = obj;
		thelength = obj.length;
	}
	
	for (var i = 0; i < thelength; i++)
	{
		index = i;
		var curChar = thevalue.charAt(i);
	    if (! (IsLetter(curChar) || IsDigit(curChar)) )
		{
			return false;
		}
	}
		
	// If this was required, was there any character data?
	if (index == -1 && required) { return false; }

	return true;
}
/*****************************************************************
* Name:
*	ValidateAlphaNumericSpace
*
* Purpose:
*	To validate a string or object and see if its value is made
*	up of alpha-numeric only characters. This is the same as 
*	ValidateAlphaNumeric except this will allow a space in the
*	string
*	
* Parameters:
*
*	obj			- A string or object reference
*	required	- true / false value indicating whether the value
*				  is required (optional).
*
* Created: SS 04/15/2002
*
* History: ~ 1 
*
* Output: Boolean
*****************************************************************/
function ValidateAlphaNumericSpace(obj, required)
{
	
	var curChar;
	var i;
	
	// set index variable
	var index = -1;

	// Holds the alphanumeric value
	var thevalue;
	
	// Holds the alphanumeric values length
	var thelength;
	
	// Process if obj parameter is of object type
	if (typeof(obj) == "object")
	{
		thevalue = obj.value;
		thelength = obj.value.length;
	}

	// Process if obj parameter is of string type
	if (typeof(obj) == "string")
	{
		thevalue = obj;
		thelength = obj.length;
	}
	
	for (var i = 0; i < thelength; i++)
	{
		index = i;
		var curChar = thevalue.charAt(i);
	    if (! (IsLetter(curChar) || IsDigit(curChar) || ! curChar == " ") )
		{
			return false;
		}
	}
		
	// If this was required, was there any character data?
	if (index == -1 && required) { return false; }

	return true;
}

/*****************************************************************
* Name:
*	ValidateCurrency
*
* Purpose:
*	To validate a string or object and see if its value is a true
*	currency data type.
*	
* Parameters:				  
*
*	obj			- A string or object reference
*	required	- true / false value indicating whether the value
*				  is required (optional).
*
* Created: 
*	SR 02/22/2002
*
* History:
*
* Output:
*	Boolean
*****************************************************************/
function ValidateCurrency(obj, required)
{
	var i;
	var cntDec = 0;
	var curChar;
	var index = -1;
    
    //Removes dollar sign and spaces.
    obj.value = obj.value.toString().replace("$","").replace(" ","").replace(",","");
    
	// Holds the currency value
	var thevalue;
	
	// Holds the currency length
	var thelength;
    
    // Process if obj parameter is of object type
	if (typeof(obj) == "object")
	{
		thevalue = obj.value;
		thelength = obj.value.length;
	}
	
	// Process if obj parameter is of string type
	if (typeof(obj) == "string")
	{
		thevalue = obj;
		thelength = obj.length;
	}
	
	// Check length... must be at least 4 (0.00)
	if (thelength < 4 && thelength > 0) { return false; }

	// Is 3rd to last position a decimal?
	if (thevalue.substring(thelength - 3, thelength - 2) != "." && thelength > 0) { return false; }

	// Get float value
	if (isNaN(parseFloat(thevalue)) && thelength > 0) { return false; }

	for (var i = 0; i < thelength; i++)
	{
		index = i
				
		var curChar = thevalue.charAt(i);

		if (i == 0 && curChar == "-")
		{
			continue;
		}
		if (curChar == ".")
		{
			if (cntDec >= 1)
			{
				return false;
			}
			cntDec += 1;
			continue;
		}
		if (curChar < "0" || curChar > "9")
		{
			return false;
		}
	}
	
	// Check for a decimal place
	if ((cntDec == 0 && thelength > 0) || (cntDec == 0 && required)) { return false; }
	
	// If this was required, was there any character data?
	if ((index == -1 && thelength > 0) || (index == -1 && required)) {  return false; }
	

	return true;
}

/*****************************************************************
* Name:
*	ValidateEmail
*
* Purpose:
*	To validate a string or object and see if its value is a
*	valid email address.
*	
* Parameters:
*
*	obj			- A string or object reference
*	required	- true / false value indicating whether the value
*				  is required (optional).
*
* Created: 
*	SR 03/06/2002
*
* History:
*	~ 1 
*
* Output:
*	Boolean
*****************************************************************/
function ValidateEmail(obj, required)
{

	// Declare local vars
	var curChar;
	var i;
	var emailReg;
	var regex;
	var result = false;
	
	// Holds the numeric value
	var thevalue;
	
	// Holds the numeric values length
	var thelength;
	
	// set index variable
	var index = -1;
	
	// Process if obj parameter is of object type
	if (typeof(obj) == "object")
	{
		thevalue = obj.value;
		thelength = obj.value.length;
	}

	// Process if obj parameter is of string type
	if (typeof(obj) == "string")
	{
		thevalue = obj;
		thelength = obj.length;
	}

	// Thanks to Scott from 4guysfromrolla.com
	//emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
    emailReg = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,10}|[0-9]{1,10})(\\]?)$";
	regex = new RegExp(emailReg);
	result = regex.test(thevalue);
     
	
	// Determine result
	if (!result && thelength > 0) { return false; }
	
	// If this was required, was there an email address provided?
	if (thelength == 0 && required) { return false; }

	// Count the number of times the @ symbol occurs in the email string
	// This will account for user nubness - #103517
	var email_ary = thevalue.split('');
	var check_char = '@';
	var counter = 0;

	for (i = 0; i < email_ary.length; i++)
	{
	    if (email_ary[i] == check_char)
	    {
	        counter++;
	    }
	}
    // If we found more than 1 @ symbol then it's not a valid email address
	if (counter > 1)
    {
        return false;
    }
	
	return true;
}

/*****************************************************************
* Name:
*	ValidateZipCode
*
* Purpose:
*	To validate a string or object and see if its value is a
*	valid zip code.
*	
* Parameters:
*
*	obj			- A string or object reference
*	required	- true / false value indicating whether the value
*				  is required (optional).
*
* Created: 
*	SR 03/06/2002
*
* History:
*	~ 1 
*
* Output:
*	Boolean
*****************************************************************/
function ValidateZipCode(field, required) {
    // Holds the value
    var theValue;

    // Holds the values length
    var theLength;

    // Result variable
    var result = true;

    // Process if obj parameter is of object type
    if (typeof(field) == "object") {
        theValue = field.value;
    }

    // Process if field parameter is of string type
    if (typeof(field) == "string") {
        theValue = field;
    }

    // Remove leading/trailing spaces
    theValue = theValue.replace(/^\s+|\s+$/g,"");
    theLength = theValue.length;

    // Check to see if this is a zip code with:
    //    -- standard 5 digits
    //    -- or the 5 + 4 separated by dash
    //    -- or Canadian, format "A0A 0A0" where A is any letter and 0 is any number
    switch(theLength) {
        case 0:
            if (required) {
                result = false;
            }
            break;
        case 5:
            if (isNaN(theValue)) {
                result = false;
            }
            break;
        case 7:
            var re = new RegExp("[A-Za-z][0-9][A-Za-z][ ][0-9][A-Za-z][0-9]");
            if (!(theValue.match(re))) {
                result = false;
            }
            break;
        case 10:
            var re = new RegExp("[0-9][0-9][0-9][0-9][0-9][-][0-9][0-9][0-9][0-9]");
            if (!(theValue.match(re))) {
                result = false;
            }
            break;
        default:
            result = false;
    }

    return result;
}

/*****************************************************************
* Name:
*	ValidateRange
*
* Purpose:
*	To validate a string or object and see if its value falls
*	between the min and max values specified.  Warning:  The min
*	and max values should be validated by the developer.
*	
* Parameters:
*
*	obj			- A string or object reference
*	required	- true / false value indicating whether the value
*				  is required (optional).
*	datatype	- Type of data
*	minvalue	- Minimum value
*	maxvalue	- Maximum value
*
* Created: 
*	SR 02/22/2002
*
* History:
*	~ 1 BKB 04/15/2002 - Added RE and CHECKBOX field type validation
*	~ 1 JR  06/11/2006 - Added TEXT field type validation
*
* Output:
*	Boolean
*****************************************************************/
function ValidateRange(obj, required, datatype, minvalue, maxvalue)
{
	var curChar;
	var i;

	var thevalue;

	// Process if obj parameter is of object type
	if (typeof(obj) == "object")
	{
		thevalue = obj.value;
	}

	// Process if obj parameter is of string type
	if (typeof(obj) == "string")
	{
		thevalue = obj;
	}

	if (datatype == "TEXT")
	{
		if (required && (thevalue.length > 0))
		{
			if (thevalue.length < parseFloat(minvalue) ||
				thevalue.length > parseFloat(maxvalue))
			{
				return false;
			}
		}
	}
	
	if (datatype == "RE")
	{
		if ((obj.value.length > 0) && required)
		{
			if (minvalue.length > 0)
			{
				var MinRE = new RegExp(minvalue);
				
				if (!MinRE.test(obj.value))
				{
					 return false;
				}
			}
		}

		if (obj.value.length > 0)
		{
			if (maxvalue.length > 0)
			{
				var MaxRE = new RegExp(maxvalue);

				if (!MaxRE.test(obj.value))
				{
					 return false;
				}
			}
		}

	}
	
	if (datatype == "CHECKBOX")
	{
		if (obj.length)
		{
			// set index variable
			var index = 0;
			
			// loop through all items in the radio group
			for (var i = 0; i < obj.length; i++) 
			{
				if (obj[i].checked) { index = index + 1; }
			}
			
			//Check Min Number of Checkboxes Required
			if ((index < minvalue) | (index > maxvalue))
			{
				return false;
			}
		}
	   else
		{
			if (!obj.checked && required)
			{
				return false;
			}
		}
	}

	if (datatype == "NUMERIC" || datatype == "CURRENCY")
	{
		if ((obj.value.length > 0) && required)
		{
			if (parseFloat(thevalue) < parseFloat(minvalue) ||
				parseFloat(thevalue) > parseFloat(maxvalue))
			{
				return false;
			}
		}
	}

	if (datatype == "DATE")
	{
		if ((obj.value.length > 0) && required)
		{
			// Create date objects from string values
			var newDate = new Date(thevalue);
			var newMinDate = new Date(minvalue);		
			var newMaxDate = new Date(maxvalue);		
				
			if (newDate < newMinDate ||
				newDate > newMaxDate)
			{
				return false;
			}
		}
	}
	
	return true;
}


/******************************************************************************
' Name:	IsValidElement(src,elementRE)
'
' Shared: No
'
' Application: VOS 
'
' Purpose: Handles validation based on Regular Expression
'
' Linked From:
'
' Requires: intelligence to operate :-)	 
'
' Linked To:   
'
' Created: BKB 04/15/2002
'
' Examples:	SSN w/Dashes Required: ^[0-9]{3}\-[0-9]{2}\-[0-9]{3}$
'			SSN wo/Dashed Required: ^[0-9]{9}$
'			Phone Number (...-...-....): ^[0-9]{3}\-[0-9]{3}\-[0-9]{4}$
'			Phone Area Code/Prefix: ^[0-9]{3}$
'			Phone Suffix: ^[0-9]{4}$
'			
'
' History: ~1 
'******************************************************************************/
function ValidateElement(obj,required,elementRE)
{
	var regex = new RegExp(elementRE);
	return regex.test(obj.value);

}


/*****************************************************************
* Name:
*	IsLetter
*
* Purpose:
*	To verify a value as being an alpha character.
*	
* Parameters:
*
*	c			- A character
*
* Created: 
*	SR 02/22/2002
*
* History:
*	~ 1 
*
* Output:
*	Boolean
*****************************************************************/
function IsLetter (c)
{
   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

/*****************************************************************
* Name:
*	IsDigit
*
* Purpose:
*	To verify a value as being a numeric value.
*	
* Parameters:
*
*	c			- A character
*
* Created: 
*	SR 02/22/2002
*
* History:
*	~ 1 DC  09/11/2009 #111421 Check for isNaN.
*
* Output:
*	Boolean
*****************************************************************/
function IsDigit(c)
{
    //return ((c >= "0") && (c <= "9"))
    return !isNaN(c);
}


/*****************************************************************
* Name:
*	DateCompare
*
* Purpose:
*	To compare 2 date values to see if one is greater than the
*	other.
*	
* Parameters:
*	Date1		- a date value
*	Compairson	- a comparison operator
*	Date2		- a date value
*
* Output:
*	A boolean value indicating if compairson of the 2 date values
*	are true or false.
*
* Created:
*	SR 01/31/2001
*
*****************************************************************/
function DateCompare(Date1, Comparison, Date2)
{

	// Is Date1 and Date2 valid?
	if (ValidateDate(Date1) && ValidateDate(Date2))
	{
		// Create date objects from string values
		var newDate1 = new Date(Date1);
		var newDate2 = new Date(Date2);
	
		if (Comparison == "==")
		{
			if (newDate1 == newDate2) { return true; }
		}
		
		if (Comparison == ">=")
		{
			if (newDate1 >= newDate2) { return true; }
		}

		if (Comparison == ">")
		{
			if (newDate1 > newDate2) { return true; }
		}

		if (Comparison == "<=")
		{
			if (newDate1 <= newDate2) { return true; }
		}

		if (Comparison == "<")
		{
			if (newDate1 < newDate2) { return true; }
		}

		if (Comparison == "!=")
		{
			if (newDate1 != newDate2) { return true; }
		}
	}

	return false;
}

/*****************************************************************
* Name:
*	GetSelList
*
* Purpose:
*	To return the selected VALUE in a HTML select object.
*	
* Parameters:
*	list - a reference to an HTML select object.
*
* Output:
*	The selected VALUE in an HTML select object.
*
* Created:
*	SR 01/31/2001
*
*****************************************************************/
function GetSelList(list) 
{
	// Get the selected list item's value

	var value = "";

	for (var i = 0; i < list.length; i++) 
	{
		if (list[i].selected) 
		{
			value = list[i].value;
		}
	}
	return value;
}

/*****************************************************************
* Name:
*	GetSelListText
*
* Purpose:
*	To return the selected TEXT in a HTML select object.
*	
* Parameters:
*	list - a reference to an HTML select object.
*
* Output:
*	The selected TEXT in an HTML select object.
*
* Created:
*	SR 01/31/2001
*
*****************************************************************/
function GetSelListText(list) 
{
	// Get the selected list item's value
	var value = "";
	
	for (var i = 0; i < list.length; i++) 
	{
		if (list[i].selected) 
		{
			value = list[i].text;
		}
	}
	return value;
}


/*****************************************************************
* Name:
*	replaceMSWORDCharCodes
*
* Purpose:
*	Replaces all modified (ms word) dashes (codes 8211,8212) with regular dashes
*   09/20/2007 'other' non-printable chars (160,161,162,166,172,194,197,195,198,226,339,353,382,402,8364,8220,8218,8222,8230,8224,8482,8217)
*	
* Parameters:
*	s - a string value
*
* Output:
*	The value of s without any ms word modified dashes.
*
* Created:
*	KP 08/31/2007 #69423
*	BH 11/05/2007 #72411 Added new character to clean 61472
*	BH 11/19/2007 #72411 Added new character to clean 9830
*	BH 01/28/2008 #75509 Added flower bullet to a rounded bullet logic
*****************************************************************/
function replaceMSWORDCharCodes (s)
{
	var i;
    var returnString = "";
    // (these codes are modified dashes from ms word documents pasted into text fields).
    
    for (i = 0; i < s.length; i++)
    {   
        // get current character code
        var c = s.charCodeAt(i);
        
		//		
		// this can help find the character code of an item being added to this logic
		//alert("Code: " + c + "\n Position: " + i);
		//

        //if a microsoft dash replace with regular dash
        if (c == '8211' || c == '8212') 
            {
                returnString += "-";
            }
        //'other' non-readable characters to omit found in sample saved data
        else if (c == '160' || c == '161' || c == '162' || c == '166' || c == '172' || c == '194' || 
            c == '197' || c == '195' || c == '198' || c == '226' || c == '339' || c == '353' || 
            c == '382' || c == '402' || c == '8364' || c == '8220' || c == '8218'|| c == '8222' || 
            c == '8230'|| c == '8224' || c == '8482' || c == '8217' || c == '61472' || c == '9830') 
            {
                returnString += "";
            }
	
		//flower bullet to a rounded bullet
		else if (c == '61558')
		{
			// replace with rounded bullet
			returnString += String.fromCharCode(8226);
		}
        else
        {
			returnString += s.charAt(i);
        }
    }
    return returnString;
}


/*****************************************************************
* Name:
*	stripCharsInBag
*
* Purpose:
*	Removes all characters which appear in string bag from 
*	string s.
*	
* Parameters:
*	s - a string value
*	bag - a string value of unwanted characters
*
* Output:
*	The value of s without any characters contained in bag.
*
* Created:
*	SR 01/31/2001
*
*****************************************************************/
function stripCharsInBag (s, bag)
{
	var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}


/*****************************************************************
* Name:
*	stripCharsNotInBag
*
* Purpose:
*	Removes all characters which do NOT appear in string bag 
*	from string s.
*
* Parameters:
*	s - a string value
*	bag - a string value of wanted characters
*
* Output:
*	The value of s with any characters contained in bag.
*
* Created:
*	SR 01/31/2001
*
*****************************************************************/
function stripCharsNotInBag (s, bag)
{
	var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }

    return returnString;
}

/*****************************************************************
* Name:
*	Trim
*
* Purpose:
*	Strips excess spaces from a field. Users sometimes enter " " 
*	in required fields to trick most validation that only checks 
*	for "" length fields. This script takes a string and removes 
*	the leading and trailing spaces and also any extra spaces in 
*	the string.
*	
* Parameters:
*	obj			- A string or object reference
*
* Output:
*	If a string then a trimmed version of that string.  If object,
*	object's value becomes trimmed.
*
* Created:
*	SR 03/06/2002
*****************************************************************/
function Trim(obj)
{

	// Declare vars
	var thevalue;
	var thelength;
	var thelength_minus_1	
	var tmp = "";
	var index;

	// Process if obj parameter is of object type
	if (typeof(obj) == "object")
	{
		thevalue = obj.value;
		thelength = obj.value.length;
	}

	// Process if obj parameter is of string type
	if (typeof(obj) == "string")
	{
		thevalue = obj;
		thelength = obj.length;
	}

	var thelength_minus_1 = thelength - 1;

	for (index = 0; index < thelength; index++)
	{
		if (thevalue.charAt(index) != ' ')
		{
			tmp += thevalue.charAt(index);
		}
		else
		{
			if (tmp.length > 0)
			{
				if (thevalue.charAt(index+1) != ' ' && index != thelength_minus_1)
				{
					tmp += thevalue.charAt(index);
				}
			}
		}
	}

	// Process if obj parameter is of object type
	if (typeof(obj) == "object")
	{
		obj.value = tmp;
		return obj;
	}

	// Process if obj parameter is of string type
	if (typeof(obj) == "string")
	{
		return tmp;
	}

}

/*****************************************************************
* Name:
*	ValidateDecimalNumber
*
* Purpose:
*	To validate a string or object and see if its value is made
*	up of numeric only characters disregarding the decimal
*	
* Parameters:
*
*	obj			- A string or object reference
*	required	- true / false value indicating whether the value
*				  is required (optional).
*
* Created: 
*	EC(02/28/2003)
*
* History:
*	~ 1 
*
* Output:
*	Boolean
*****************************************************************/
function ValidateDecimal(obj, required)
{

	// Declare local vars
	var curChar;
	var i;

	// Holds the numeric value
	var thevalue;
	
	// Holds the numeric values length
	var thelength;
	
	// set index variable
	var index = -1;
	
	// Process if obj parameter is of object type
	if (typeof(obj) == "object")
	{
		thevalue = obj.value;
		thelength = obj.value.length;
	}

	// Process if obj parameter is of string type
	if (typeof(obj) == "string")
	{
		thevalue = obj;
		thelength = obj.length;
	}
	
	
	for (var i = 0; i < thelength; i++)
	{
		index = i;
		var curChar = thevalue.charAt(i);
		if( curChar != '.')
		{
			if (!IsDigit(curChar)) { return false;} 
		}
	   
	}
	
	// If this was required, was there any character data?
	if (index == -1 && required) { return false; }
	
	return true;
}

/*****************************************************************
* Name: 		CheckBoxPosByValue
*
* Shared: 		No
*
* Application: 	VOS 
*
* Purpose:		Return the position(s) of the check box(es) that matches 
*				the value contained in strValue.
*	
* Parameters:	
*	objCheckBoxArray	- An array of check boxes
*	strValue			- the value to find.
*
* Linked From: 
*
* Requires:		objCheckBoxArray, strValue, and requires that the strValue 
*				doesn't contain the '|' character.
*
* Linked To:  
*
* Created:	AA 08/06/2003
*
* History:	~1 
'******************************************************************************/
function CheckBoxPosByValue(objCheckBoxArray, strValue)
{
	var strPos = ""
	if (objCheckBoxArray)
	{
		for (var i=0; i < objCheckBoxArray.length;i++)
		{
			if (objCheckBoxArray[i].value == strValue)
			{
				if (strPos == "")
					strPos = i;
				else
					strPos = strPos + '|' + i;
			}				
		}
	}
	return strPos;
}

/*****************************************************************
* Name:
*	GetRadioList
*
* Purpose:
*	To return the selected VALUE in a HTML radio object.
*	
* Parameters:
*	list - a reference to an HTML radio object.
*
* Output:
*	The selected VALUE in an HTML radio object.
*
* Created:
*	SR 03/30/2005
*
*****************************************************************/
function GetRadioList(list) 
{
	// Get the selected list item's value

	var value = "";

	for (var i = 0; i < list.length; i++) 
	{
		if (list[i].checked) 
		{
			value = list[i].value;
		}
	}
	return value;
}

/*****************************************************************
* Name:
*	GetRadioListText
*
* Purpose:
*	To return the selected TEXT in a HTML radio object.
*	
* Parameters:
*	list - a reference to an HTML radio object.
*
* Output:
*	The selected TEXT in an HTML radio object.
*
* Created:
*	SR 03/30/2005
*
*****************************************************************/
function GetRadioListText(list) 
{
	// Get the selected list item's value
	var value = "";
	
	for (var i = 0; i < list.length; i++) 
	{
		if (list[i].checked) 
		{
			value = list[i].text;
		}
	}
	return value;
}


var newWindow;
/*********************************************************************************
' Name:		selectNAICS()
'
' Purpose:	to call the naics popup screen
'
' History: 
'	#	initials	incident	date		description
'	----------------------------------------------------------------------------------------------------
'	1	REM						01/27/2002	Created
'	2	REM						02/20/2004	A new Naics box was impleneted by someone so we modified the 
'											width,height
'   3   AA                      04/07/2005  #33121 Moved the selectNAICS() function to merged all versions into one.
***********************************************************************************/
function selectNAICS(url)
{

	// Find left and top coordinates to center window
	if (navigator.appVersion.indexOf("MSIE") > -1 || (navigator.appName == "Netscape" && parseInt(navigator.appVersion.charAt(0)) >= 4))
	{
		var h = (screen.availHeight - 680) / 2;
		var w = (screen.availWidth - 635) / 2;
		var center = ",top=" + h + ",left=" + w;
	}
	
	if (!newWindow || newWindow.closed)
	{
		newWindow = window.open(url,"newNaicsWindow","resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=yes,menubar=no,height=680,width=635" + center)
		if (!newWindow.opener)
		{
			newWindow.opener = window
		}
	}
	else
	{
		newWindow = window.open(url,"newNaicsWindow","resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=yes,menubar=no,height=680,width=635" + center)
		if (!newWindow.opener)
		{
			newWindow.opener = window
		}
		// window's already open; bring to front
		newWindow.focus()
	}
}

/*****************************************************************
* Name: 		DateCompareWithOptions
*
* Shared: 		Yes
*
* Application: 	VOS 
*
* Purpose:		Evaluate if the passed date is Greater Than System Date
*	
* Linked From:
*
* Requires:		
*
* Linked To:  
*
* Created:  AA  06/15/2005 
*
* History:	~1 AA  06/15/2005 
'******************************************************************************/
//Global Variable to override focus setting, helpful for save mode, auto-resets to false after first use.
var blnOverrideDateCompareWithOptionsFocus = false;
function DateCompareWithOptions(strformname, strdatename, strdate, strcompareoption, strdate2, strerrormessage, blnfocus) 
{
    //strcompareoption "==", ">", "<", etc
    if (DateCompare(FormatDate(strdate, "MM/DD/YYYY"), strcompareoption, FormatDate(strdate2, "MM/DD/YYYY")))
	{
	    if (strerrormessage != '') 
        {
	        alert(strerrormessage);
	    }
        if (blnOverrideDateCompareWithOptionsFocus || blnfocus)
        {   
            blnOverrideDateCompareWithOptionsFocus = false;
	        SetFocusHtmlElement(strformname, strdatename);
	    }
	    return true;
	}
	else
	{
		return false;
	}
}

/******************************************************************************
' Name:	SetFocusHtmlElement()
'
' Shared: No
'
' Application: VOS 
'
' Purpose: It sets the focus to the html element otherwise catch the errors.
'
' Linked From: 
'
' Requires:
'
' Linked To:  
'
' Created: AA 08/02/2004
'
' History: ~1 
'******************************************************************************/
function SetFocusHtmlElement(strFormName, strElementName)
{
	try 
	{
		eval(strFormName + '.' + strElementName + '.' + 'focus()')
	}
	catch(strerror)
	{
	}
	return true;
}


/******************************************************************************
' Name:	FormatDate()
'
' Shared: No
'
' Application: VOS 
'
' Purpose: To format dates.
'
' Linked From: 
'
' Requires:
'
' Linked To:  
'
' Created: AA 08/02/2004
'
' History: ~1 
'******************************************************************************/
function FormatDate(datdatetime, strformattype)
{	
	var myDate = new Date(datdatetime);
	var strday = myDate.getDate()  	//Returns the date of a Date object (from 1-31)	
	var strmonth = myDate.getMonth() 	//Returns the month of a Date object (from 0-11. 0=January, 1=February, etc.)
	var stryear = myDate.getFullYear() 	//Returns the year of a Date object (four digits) 
	var strformatteddate;
	var strformattedday;
	var strformattedmonth;
	var strformattedyear;

	strformattype.toUpperCase();
	switch(strformattype)
	{
	case 'MM/DD/YYYY':
		strmonth = parseInt(strmonth) + 1;
		switch(strmonth.toString().length)
		{
		case 1:
			strformattedmonth = '0' + strmonth.toString();
			break;
		case 2:
			strformattedmonth = strmonth.toString();
			break;
		default:
			strformattedmonth = 'NaN';
		}

		switch(strday.toString().length)
		{
		case 1:
			strformattedday = '0' + strday.toString();
			break;
		case 2:
			strformattedday = strday.toString();
			break;
		default:
			strformattedday = 'NaN';
		}

		switch(stryear.toString().length)
		{
		case 4:
			strformattedyear = stryear.toString();
			break;
		default:
			strformattedyear = 'NaN';
		}
		
		strformatteddate = strformattedmonth.toString() + '/' + strformattedday.toString() + '/' + strformattedyear.toString();

	}
	
	return strformatteddate;
	
}

/******************************************************************************
' Name:	DisableHtmlElement()
'
' Shared: No
'
' Application: VOS 
'
' Purpose: It disables the html element otherwise catch the errors.
'
' Linked From: 
'
' Requires:
'
' Linked To:  
'
' Created: AA 07/13/2004
'
' History: ~1 
'******************************************************************************/
function DisableHtmlElement(strFormName, strElementName)
{
	try 
	{
		eval(strFormName + '.' + strElementName + '.' + 'disabled = true')
	}
	catch(strerror)
	{
	}
	return true;
}
/******************************************************************************
' Name:	DisableHtmlElement()
'
' Shared: No
'
' Application: VOS 
'
' Purpose: It disables the html element otherwise catch the errors.
'
' Linked From: 
'
' Requires:
'
' Linked To:  
'
' Created: mgb 07/28/2004
'
' History: ~1 
'******************************************************************************/
function EnableHtmlElement(strFormName, strElementName)
{
	try 
	{
		eval(strFormName + '.' + strElementName + '.' + 'disabled = false')
	}
	catch(strerror)
	{
	}
	return true;
}

/*****************************************************************
* Name:
*	FixDecimals
*
* Purpose:
*	Fix Decimals in JavaScript
*
* Parameters:
*	dblNumber - a float number
*	intDecimalCount - the number of decimals
*
* Output:
*	0 (Zero) for any invalid input, otherwise a fixed number.
*
* Created:
*	AA 02/10/2005
*
*****************************************************************/
function FixDecimals(dblNumber, intDecimalCount)
{
    var dbltempNumber = parseFloat(dblNumber);
    if (isNaN(dbltempNumber))
    {
        return 0;
    }
    var dbltempDecimalCount = parseInt(intDecimalCount);
    if (isNaN(dbltempDecimalCount))
    {
        return 0;
    }    
	var dblFixedNumber = new Number(dbltempNumber);
	dblFixedNumber = (+dblFixedNumber.toFixed(dbltempDecimalCount));
    return dblFixedNumber;
}	




/*****************************************************************
* Name:
*	ValidatewildChar
*
* Purpose:
*	Specially created to allow certain symbols/characters as part of the company's name
*
* Parameters:
*	obj - text box 
*	err - error message to be displaye
*
* Output:
*	Accepts alpha numeric characters and spaces .
*
* Created:
*	MLT 4/14/2011 - #160031 Created to check company's name.  
*                           Allowed character are: 
*                           allphanumeric entries, hyphens, asterick, ampersand, 
*                           underscore, apostrophes, comma and spaces.
*
*****************************************************************/
function ValidatewildChar(obj,err)
{

   
    // Declare local vars
    var i;

    // Holds the numeric value
    var thevalue;

    // Holds the numeric values length
    var thelength;

    // set index variable
    var index = -1;


    thevalue = obj.value;
    thelength = obj.value.length;

    var iChars = "|\"~!@#$%^()+=[]{}:;?/<>";  

    for (var i = 0; i < thelength; i++) {

          if (iChars.indexOf(thevalue.charAt(i)) != -1) {
                alert(err);
                obj.focus();
                return false;
          }

     }

    
}	



