//**************************************************************************
// validate.js
//
// Purpose: contains client side validation scripts used by various library 
//          requestline applications
//
// Revision History
// Date       Author       Description
// XX-XX-199X  ???        >Initial Creation
// 06-05-2000  AMK        >added function "CheckEmailFormat"
//**************************************************************************


var defaultEmptyOK = false;
var decimalPointDelimiter = "."
var objWindow 


//********************************************************************************
// Name: isblank
// Parameters: str
// Returns: boolean
// Description: checks to see if string contains a blank space
//
// Note - used in function verify
// 
// Modification History: 
// Person   Date          Activity
// XX-XX-199X  ???        >Initial Creation
// 07-03-2000  AMK        >modified due to errors in Netscape 3.0 (does not handle 
//                         regular expressions)
//********************************************************************************

//checks for white space
function isblank(str) {
	for (var i = 0; i < str.length; i++) {
		var c = str.charAt(i);
//		if ((c!= /\s/) && (c != '\n') && (c != '\t')) return false;
		if ((c!= " ") && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}

//********************************************************************************
// Name: CheckEmailFormat
// Parameters: objTxtInput (text input field object), strSource
// Returns: boolean
// Description: checks for a properly formatted email address
//
// Note - used in customize and formslogin asp.  For customize, it will trigger
//        a form submit event
// 
// Modification History: 
// Person   Date          Activity
// AMK      06/05/2000   >Initial creation
// AMK      06/07/2000   >Added validation for no email address being entered, check
//                        for presence periods and for periods after the ampersand 
//                        and set it up to work with both formslogin and customize.
//********************************************************************************

function CheckEmailFormat(strValue,strSource)
    {
      var AmpersandIndex = strValue.indexOf("@");        
      var SpaceIndex = strValue.indexOf(" ");
      var LastPeriodIndex = strValue.lastIndexOf(".");

      if ((LastPeriodIndex == -1)||(AmpersandIndex == -1)||(LastPeriodIndex < AmpersandIndex)||(SpaceIndex > 0)||strValue == "")
        {
         alert("Please Enter a valid e-mail Address.\nGenerally, first name.last name @genzyme.com with no spaces    ");
         return (false);
        }
      if (strSource == "customize")
         {
          document.frmEmailSearch.submit();
         }
      return(true);
    }

//********************************************************************************
// Name: formCheck
// Parameters: none
// Returns: boolean
// Description: Formerly used in formslogin to determine whether email address was 
//              properly formatted
//
// Note - Replaced by CheckEmailFormat function - kept here for reference just in case
// 
// Modification History: 
// Person   Date          Activity
// XXX      XX/XX/199x   >Initial creation
//********************************************************************************

function formCheck() 
{ 
if (document.formslogin.Username.value.indexOf("@") == -1 || document.formslogin.Username.value == "" || document.formslogin.Username.value.indexOf(".com") == -1 ) 
  { 
  alert("Please enter a valid email address <Firstname>.<Lastname>@Genzyme.com "); 
  return false; 
  } 
}

//********************************************************************************
// Name: verify
// Parameters: frm (form object)
// Returns: boolean
// Description: checks all required fields on a requestline form to make sure they have
//              values
//
// Note - 
// 
// Modification History: 
// Person      Date          Activity
// XX-XX-199X  ???        >Initial Creation
// 06-06-2000  AMK        >Changed message text per JW/DR instructions
// 07-03-2000  AMK        >Changed "|| !e.optional" to" && !e.optional" in checking 
//                         for nulls
//********************************************************************************


//form verification. Invoked from the onSubmit() handler.
function verify(frm) {
	var msg;
	var empty_fields = "";
	var errors="";
	
	//loop through all the fields on the form, checking text and textarea fields for content.
	//also looks for fields that are "optional".
	for (var i = 0; i < frm.length; i++) {
		var e = frm.elements[i];
		if (((e.type == "text") || (e.type == "textarea")) && !e.optional) {
			//check to see if the field is empty
			if ((e.value == null) || (e.value == "") || isblank(e.value)) {
				empty_fields += "\n             " + e.name;
				continue;
			}
			//now check for fields that are supposed to be numeric.
			if (e.numeric || (e.min != null) || (e.max != null)) {
				if (isNaN(v) ||
					((e.min != null ) && (v < e.min)) ||
					((e.max != null) && (v > e.max))) {
						errors += "-  the field " + e.name + " must be a number";
						if (e.min != null)
							errors += " that is greater than " + e.min;
						if (e.max != null && e.min != null)
							errors += " and less than " + e.max;
						else if (e.max != null)
							errors += " that is less than " + e.max;
						errors += ".\n";
				}
			}
		}
	}
	//if there were any errors, display them.
	if (!empty_fields && !errors) return true;
	
	msg =  "______________________________________________________\n\n"
	msg += "You need to complete all of the required fields before\n";
	msg += "your order can be submitted. Please fill in the following\n";
	msg += "missing information or note 'NA' if not applicable.\n";
	msg += "______________________________________________________\n\n"
	
	if (empty_fields) {
		msg += "- The following required field(s) are empty:"
			+ empty_fields + "\n";
		if (errors) msg += "\n";
	}
	msg += errors;
	alert(msg);
	return false;
}

//********************************************************************************
// Name: CheckRado
// Parameters: objRadio (Radio button object)
// Returns: boolean
// Description: Checks that a value has been selected with radio button field elements.
// Modification History: 
// Person		Date          Activity
// Rupesh		08-24-2000    Initial Creation
//********************************************************************************
function CheckRadio(objRadio)	{
	if (objRadio.length > 1) {
		for(var n = 0; n < objRadio.length; n++) {
			if(objRadio[n].checked) {
				return true;
			}
		}
	}
	else	{
		if (objRadio.checked) {
			return true;
		}
	}
	return false;
}

//********************************************************************************
// Name: CheckList
// Parameters: objList (Dropdown/Listbox object)
// Returns: boolean
// Description: Checks that a value has been selected with dropdown list field elements.	
// Modification History: 
// Person		Date          Activity
// Rupesh		08-24-2000    Initial Creation
//********************************************************************************
function CheckList(objList) {
	if (objList.selectedIndex != -1) {
		//alert(objList.options[objList.selectedIndex].value)
		if (objList.options[objList.selectedIndex].value != -1) {
			return true;
		}
	}
	return false;
}

//********************************************************************************
// Name: isEmpty
// Parameters: strText 
// Returns: boolean
// Description: Checks that a value is empty/Blank
// Modification History: 
// Person		Date          Activity
// Rupesh		08-24-2000    Initial Creation
//********************************************************************************
function isEmpty(strText) {
		
		if ((strText == null) || (strText.length == 0)) return true

		//Check for Whitespace
		return (isWhitespace(strText))  
	}

//********************************************************************************
// Name: isWhitespace
// Parameters: strText 
// Returns: boolean
// Description: Checks whether the String value contains any white spaces 
// Modification History: 
// Person		Date          Activity
// Rupesh		08-24-2000    Initial Creation
//********************************************************************************
function isWhitespace(strText) {
		var intCount;
	    // Is s empty?
		//if (isEmpty(strText)) return true;
			
		// Search through string's characters one by one
		// until we find a non-whitespace character.
		// When we do, return false; if we don't, return true.
	    var whitespace = ' '; 
	    for (intCount = 0; intCount < strText.length; intCount++) {
			// Check that current character isn't whitespace.
			var strChar = strText.charAt(intCount);
			//if (whitespace.indexOf(strChar) == -1) return false;
			if (whitespace.indexOf(strChar) == -1 && strChar != '\n' && strChar != '\r' && strChar != "\t") return false;
		}
		// All characters are whitespace.
		return true;
	}

//********************************************************************************
// Name: isStrLength
// Parameters: strText 
// Returns: boolean = (True)- The length lies between min and max value. 
// Description: Checks whether the String value length with min and max 
// Modification History: 
// Person		Date          Activity
// Rupesh		08-24-2000    Initial Creation
//********************************************************************************
function isStrLength(strValue,iMin, iMax) {
		if (isEmpty(strValue)) return true;
		//Check the Minimum length of the string 
		if (iMin != null) {
		if (strValue.length <  iMin) return false;
		}
		//Check the Max length of the string 
		if (iMax != null) {
		if (strValue.length > iMax) return false;
		}
		
		return true ;
	}		

//********************************************************************************
// Name: isEmail
// Parameters: strText 
// Returns: boolean = (True)- Valid Email Address
// Description: Checks Valid Email Address
// Modification History: 
// Person		Date          Activity
// Rupesh		08-24-2000    Initial Creation
//********************************************************************************
function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}



//********************************************************************************
// Name: validText
// Parameters:  objElement (Form Element Text Box), 
//				strTitle   (Title to display on the Error Message
//				inMin, intMax - (Min and Max Lenght of the Value
//				blnRequired - Should be empty or not.
// Returns: boolean = True/False 
// Description: Valdates a Text String for empty and Length 
// Modification History: 
// Person		Date          Activity
// Rupesh		08-24-2000    Initial Creation
//********************************************************************************
function validText(objElement,strTitle, intMin, intMax,blnRequired) {

	if (blnRequired) {
		if (isEmpty(objElement.value)) {
			alert(strTitle + " cannot be blank");
			objElement.focus();
			return (false);
			}
	}
	// Check the Length of the string
	if (!isStrLength(objElement.value,intMin,intMax)) { 
		alert(strTitle + " requires at least " + intMin + " and  maximum " + intMax  + " characters.");	
		objElement.focus();
	return (false);
  }
   
  return (true); 		

}


//********************************************************************************
// Name: validEmail
// Parameters:  objElement (Form Element Text Box), 
//				strTitle   (Title to display on the Error Message
//				blnRequired - Should be empty or not.
// Returns: boolean = True/False 
// Description: Valdates a Text String for empty and Email Id
// Modification History: 
// Person		Date          Activity
// Rupesh		08-24-2000    Initial Creation
// Rupesh		10-15-2000    Included the required logic
//********************************************************************************
function validEmail(objElement,strTitle, blnRequired) {

	if (blnRequired) {
		if (isEmpty(objElement.value)) {
			alert(strTitle + " cannot be blank");
			objElement.focus();
			return (false);
			}
	}
	// Check the Length of the string
	if (!isEmpty(objElement.value)) {
	    if (!isEmail(objElement.value)) { 
		alert(strTitle + " is not a valid Email\nGenerally, first name.last name @genzyme.com with no spaces.")    
		objElement.select();
		objElement.focus();
		return (false);
             }	
        }
	
  return (true); 		
}


//********************************************************************************
// Name: validPosInteger
// Parameters:  objElement (Form Element Radio Button/Check Boxes), 
//		strTitle   Title to display on the Error Message
//		intMin	   Minimum Value	
//		intMax	   Maximum Value
//		blnRequired - Should be Selected 
// Returns: boolean = True/False 
// Description: Validate the Text Box value with Numeric values
// Modification History: 
// Person		Date          Activity
// Rupesh		08-24-2000    Initial Creation
//********************************************************************************
function validPosInteger(objElement,strTitle,intMin,intMax,blnRequired) {
	if (blnRequired) {
		if (isEmpty(objElement.value) == true)	{
			alert(strTitle + ' cannot be blank');
			objElement.select();
			objElement.focus();
			return (false);
		}
	}
	if (isEmpty(objElement.value) == false)	{
		if (isPositiveInteger(objElement.value) == false) {
			alert(strTitle + ' should be positive number');
			objElement.select();
			objElement.focus();
			return (false);
		}
		if (isValueInRange(objElement.value,intMin, intMax) == false){
			alert(strTitle + ' should be lie between ' + intMin + '-' + intMax);
			objElement.select();
			objElement.focus();
			return (false);
		}
	}
	    
	return true;
}


//********************************************************************************
// Name: validMoney
// Parameters:  objElement (Form Element Text Boxes), 
//		strTitle   Title to display on the Error Message
//		intMin	   Minimum Value	
//		intMax	   Maximum Value
//		blnRequired - Should be Selected 
// Returns: boolean = True/False 
// Description: Validate the Text Box value with Numeric values
// Modification History: 
// Person		Date          Activity
// Rupesh		08-24-2000    Initial Creation
//********************************************************************************
function validMoney(objElement,strTitle,intMin,intMax,blnRequired) {
	if (!isMoney(objElement.value, !blnRequired)) {	
		alert(strTitle + ' should be a money value');
		objElement.select();
		objElement.focus();
		return (false);
	}
	else {
	if (isEmpty(objElement.value) == false)	{
		if (isValueInRange(objElement.value,intMin, intMax) == false) {
			alert(strTitle + ' should be lie between ' + intMin + '-' + intMax);
			objElement.select();
			objElement.focus();
			return (false);
		}
	}
	}    
	return true;
}


//********************************************************************************
// Name: validList
// Parameters:  objElement (Form Element Dropdown/Listbox), 
//				strTitle   Title to display on the Error Message
//				blnRequired - Should be Selected 
// Returns: boolean = True/False 
// Description: Checks whether the dropdown has been selected or not. 
//				If also checks whether the value is not "-1" (<---- SELECT HERE ------>)
// Modification History: 
// Person		Date          Activity
// Rupesh		08-24-2000    Initial Creation
//********************************************************************************
function validList(objElement,strTitle, blnRequired) {
	if (blnRequired) {
		if (!CheckList(objElement)) {
			alert("Please select " + strTitle)
			objElement.focus();
			return (false);
		}
	}
	return (true);
}


//********************************************************************************
// Name: validRadio
// Parameters:  objElement (Form Element Radio Button/Check Boxes), 
//				strTitle   Title to display on the Error Message
//				blnRequired - Should be Selected 
// Returns: boolean = True/False 
// Description: Checks whether one of the item of radio button has been selected
// Modification History: 
// Person		Date          Activity
// Rupesh		08-24-2000    Initial Creation
//********************************************************************************
function validRadio(objElement,strTitle, blnRequired) {
	if (blnRequired) {
		if (!CheckRadio(objElement)) {
			alert("Please select " + strTitle)
			if (objElement.length > 1) {
				objElement[0].focus(); }
			else	{
				objElement.focus();
			}
			return (false);
		}
	}
	return (true);
}

//********************************************************************************
// Name: isPositiveInteger
// Parameters:  
// Returns: boolean = True/False 
// Description: 
// Modification History: 
// Person		Date          Activity
// RLP		08-24-2000    Initial Creation
//********************************************************************************
function isPositiveInteger (s)	{
		var secondArg = defaultEmptyOK;

		if (isPositiveInteger.arguments.length > 1)
			secondArg = isPositiveInteger.arguments[1];
		// The next line is a bit byzantine.  What it means is:
		// a) s must be a signed integer, AND
		// b) one of the following must be true:
		//    i)  s is empty and we are supposed to return true for
		//        empty strings
		//    ii) this is a positive, not negative, number
	
		return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
	}


//********************************************************************************
// Name: isSignedInteger
// Parameters:  
// Returns: boolean = True/False 
// Description: Check if the Value send is an signed Integer
// Modification History: 
// Person		Date          Activity
// RLP		08-24-2000    Initial Creation
//********************************************************************************
function isSignedInteger (s)	
	{   
		if (isEmpty(s)) 
		if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
		else return (isSignedInteger.arguments[1] == true);
		else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
		
        return (isInteger(s.substring(startPos, s.length), secondArg))
        
		}
	}

//********************************************************************************
// Name: isDigit
// Parameters:  
// Returns: boolean = True/False 
// Description: Returns true if character c is a digit 
// Modification History: 
// Person		Date          Activity
// RLP		08-24-2000    Initial Creation
//********************************************************************************
function isDigit(c)
{   
	
return ((c >= "0") && (c <= "9"))
	
}


//********************************************************************************
// Name: isInteger
// Parameters:  
// Returns: boolean = True/False 
// Description: 
// Modification History: 
// Person		Date          Activity
// RLP		08-24-2000    Initial Creation
//********************************************************************************
function isInteger(s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
        
    }


    // All characters are numbers.
    return true;
}

//********************************************************************************
// Name: isValueInRange
// Parameters:  
// Returns: boolean = True/False 
// Description: 
// Modification History: 
// Person		Date          Activity
// RLP		08-24-2000    Initial Creation
//********************************************************************************
function isValueInRange(sValue,min,max)
{
	var checkvalue = parseFloat(sValue);
	if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || sValue!=checkvalue )
	{	
		return false;
	}
}



//********************************************************************************'
//Name: DateSelect_onChange()
//Parameters: oSelMonth,oSelYear,oSelDay [objects representing each select field in
//                                        the new.asp]
//Returns: NOTHING
//Description: Function to dynamically repopulate the day select options list
//             if a user chooses a month different from the default month initially
//             displayed at intial page creation. 
//
//Modification History:
//Person			Date			Activity
//AMK                           02/05/2000              Initial creation
//AAA				00/00/200X		<insert description here>
//********************************************************************************'

function DateSelect_onChange(oSelMonth,oSelYear,oSelDay) {
    var iNewMonth;  //the new month just selected by the user
    var iLastDay;   //the last day of the new month
    var iYear;      //the currently selected year in the form
    var iYearIndex; //the select list index of the current year
    var iCount;     //counter variable
	var iDay;		//Day 	

    //Get the index from the PostMonth select field
    iNewMonth = oSelMonth.options[oSelMonth.selectedIndex].value;

	//Selected Day 
	iDay = oSelDay.options[oSelDay.selectedIndex].value
	
	oSelDay.options.length = 0
	CreateOption(oSelDay,"--day--",-1);    

    if (iNewMonth == -1)	{
		return; 
		}
	
    //get the value of the year from the PostYear select field
    iYearIndex = oSelYear.selectedIndex;
    //alert("The following line fails in Netscape 3.0")
    iYear = oSelYear.options[iYearIndex].value;

	
	

     //Determine the appropriate number of days in the month selected
     if (iNewMonth==1) {
            iLastDay = 31;
     }
     else if (iNewMonth==2) {
             if(iYear % 4==0) {
                 iLastDay = 29;
             }
             else {
                 iLastDay = 28;
             }
     }
     else if (iNewMonth==3) {
            iLastDay = 31;
            }
     else if (iNewMonth==4) {
            iLastDay = 30;
            }
     else if (iNewMonth==5) {
            iLastDay = 31;
            }
     else if (iNewMonth==6) {
            iLastDay = 30;
            }
     else if (iNewMonth==7) {
            iLastDay = 31;
            }
     else if (iNewMonth==8) {
            iLastDay = 31;
            }
     else if (iNewMonth==9) {
            iLastDay = 30;
            }
     else if (iNewMonth==10) {
            iLastDay = 31;
            }
     else if (iNewMonth==11) {
            iLastDay = 30;
            }
     else {                    //iNewMonth==11)
            iLastDay = 31;
          }
   
    //clear all the options in the PostDay list
    //oSelDay.options.length = 0

    //repopulate the options with the new list of days
    for(iCount = 1 ; iCount <= iLastDay ; iCount++)
        CreateOption(oSelDay,iCount,iCount,iDay);

    //set the default selection to the first day of the new month
    //oSelDay.options.selectedIndex = 0;

//end of function PostMonth_onChange()
}

//********************************************************************************'
//Name: CreateOption()
//Parameters: oObject,iCount
//Returns: NOTHING
//Description: 
//             This function does the actual instancing and creation of a new option.
//             Processing separated from the PostMonth_onChange function to prevent
//             overwriting the instantiated oNewOption variable, which leads to only
//             the last option created in the loop from appearing in the options list.
//
//Modification History:
//Person        Date           Activity
//AMK           02/05/2000     Initial creation
//AMK           02/08/2000     changed to make new Option arguments both iCount+1
//                             since neither argument is an index (they are "text" & "value".
//********************************************************************************'

function CreateOption(oObject,strText, intValue,intSelectedValue) {

        var oNewOption //New Option Object instance
	
		var blnSelected 
        //note, since index starts at 0, we have to offset iCount by +1
        oNewOption = new Option(strText, intValue);
        if (intSelectedValue == intValue) 
				oNewOption.selected = true;
		else
			oNewOption.selected = false;

        oObject.options[oObject.options.length] = oNewOption;
}


//********************************************************************************'
//Name: checkDate()
//Parameters: objName (String object/String Value)
//Returns: NOTHING
//Description:  Check whether the date string is a valid date 
//
//Modification History:
//Person        Date           Activity
//RLP           08/31/2000     Initial creation
//********************************************************************************'
function checkDate(objName) {
	var strDatestyle = "US"; //United States date style
	//var strDatestyle = "EU";  //European date style
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";
	strDate = datefield;
	if (strDate.length < 1) {
		return true;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) {
			err = 1;
			return false;
			}
			else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
		}
	}
	if (booFound == false) {
		if (strDate.length>5) {
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
	}
	if (strYear.length == 2) {
		strYear = '20' + strYear;
	}
	// US style
	if (strDatestyle == "US") {
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) {
		err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
		for (i = 0;i<12;i++) {
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}
		if (isNaN(intMonth)) {
			err = 3;
			return false;
		}
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) {
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1) {
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || 
		intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
		err = 7;
		return false;
	}
	if (intMonth == 2) {
		if (intday < 1) {
			err = 8;
			return false;
		}
		if (isLeapYear(intYear) == true) {
			if (intday > 29) {
				err = 9;
				return false;
			}
		}
		else {
			if (intday > 28) {
				err = 10;
				return false;
			}
		}
	}
	if (strDatestyle == "US") {
		datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
	}
	else {
		datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
	}
	return true;
}

//********************************************************************************'
//Name: isLeapYear()
//Parameters: intYear 
//Returns: True/False
//Description:  Check whether the year is a leap year
//
//Modification History:
//Person        Date           Activity
//RLP           08/31/2000     Initial creation
//********************************************************************************'
function isLeapYear(intYear) {
if (intYear % 100 == 0) {
	if (intYear % 400 == 0) { return true; }
}
else {
	if ((intYear % 4) == 0) { return true; }
}
return false;
}


//********************************************************************************'
//Name: stringSplit
//Parameters: string, delimeter
//Returns: Array of string
//Description:  
//
//Modification History:
//Person        Date           Activity
//RLP           09/05/2000     Initial creation
//********************************************************************************'
function stringSplit( string, delimiter )
{
	if ( string == null || string == "" )
	{
		return null;
	} else if ( string.split != null )
	{ 
		return string.split ( delimiter );
	} else
	{ 
		var ar = new Array();
		var i = 0;
		var start = 0;
		while( start >= 0 && start < string.length ) 
		{ 
			var end = string.indexOf ( delimiter, start ) ; 
			if( end >= 0 ) 
			{ 
				ar[i++] = string.substring ( start, end ); 
				start = end+1; 
			} else 
			{
				ar[i++] = string.substring ( start, string.length ); 
				start = -1; 
			} 
		}
		return ar;
	} 
} 


//********************************************************************************
// Name: validSocialSecurity
// Parameters:  objElement (Form Element Text Box), 
//				strTitle   Title to display on the Error Message
//				blnRequired - Should be Selected 
// Returns: boolean = True/False 
// Description: Validate the Text Box value with Numeric values
// Modification History: 
// Person		Date          Activity
// Rupesh		10-23-2000    Initial Creation
//********************************************************************************
function validSocialSecurity(objElement,strTitle,blnRequired) {
	if (blnRequired) {
		if (isEmpty(objElement.value) == true)	{
			alert(strTitle + ' cannot be blank');
			objElement.select();
			objElement.focus();
			return (false);
		}
	}
	
	if (isEmpty(objElement.value) == false)	{
		var strValue = objElement.value
		var i, c
		if ((strValue.length < 9) || (strValue.length > 9 && strValue.length < 11) || (strValue.length > 11)) {
			alert(strTitle + ' should be atleast 9 or 11 characters. \nGenerally, should be 123456789 or 123-45-6789.');
			objElement.select();
			objElement.focus();
			return (false);
		}		
		if (strValue.length == 9)  {
			for (i = 0; i < strValue.length; i++) {
				c = strValue.charAt(i);
				if (!isDigit(c)) {
					alert("Invalid " + strTitle + '. \nGenerally, should be 123456789 or 123-45-6789.');
					objElement.select();
					objElement.focus();
					return (false);
				}
			}
		}
		else if (strValue.length == 11) {
			for (i = 0; i < strValue.length; i++) {
				c = strValue.charAt(i);
				if (i == 3 || i == 6) {
					if (c != '-') {
						alert("Length")
						alert("Invalid " + strTitle + '. \nGenerally,  -  should be 123456789 or 123-45-6789.');
						objElement.select();
						objElement.focus();
						return (false);
						}
				}
				else if (!isDigit(c)) {
					alert("Invalid " + strTitle + '. \nGenerally, should be 123456789 or 123-45-6789.');
					objElement.select();
					objElement.focus();
					return (false);
				}
			}
		}				    						
	}
	    
	return true;
}

//********************************************************************************
// Name:OpenHelpWindow
// Parameters:  URL name
// Returns: boolean = N/A
// Description: Open new HELP window (Page)
// Modification History: 
// Person		Date          Activity
// Rupesh		11-10-2000    Initial Creation
//********************************************************************************
function OpenHelpWindow(sUrl) 
{	
	if (objWindow  != null) {
		if (!objWindow .closed) {
			objWindow .close()
		}
		objWindow = null
	}
	objWindow = window.open(sUrl,"HelpWindow","scrollbars=yes, width=560,height=300,menubar=no,location=no,alwaysRaised=yes");
	objWindow.focus()
}

//********************************************************************************
// Name:isFloat 
// Parameters:  strValue, the second argument is option (True - > should not be empty  False -> can be empty
// Returns: boolean = N/A
// Description: Check if the value is float 
// Modification History: 
// Person		Date          Activity
// Rupesh		11-30-2000    Initial Creation
//********************************************************************************
function isFloat (strValue)

{   var i;
    var seenDecimalPoint = false;
    
  
    if (isEmpty(strValue)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    if (strValue == decimalPointDelimiter) return false;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < strValue.length; i++)
    {   
        // Check that current character is number.
        var c = strValue.charAt(i);

	if  (c == ',') 
		return false;


        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

//********************************************************************************
// Name:isMoney 
// Parameters:  strValue, the second argument is option (True - > should not be empty  False -> can be empty
// Returns: boolean = N/A
// Description: Check if the value is a money value 
// Modification History: 
// Person		Date          Activity
// Rupesh		11-30-2000    Initial Creation
//********************************************************************************
function isMoney(strValue)
{   var i;
    var seenDecimalPoint = false;
    var iDecimalPointIndex = 0 
    var sStrAfterDecimal = ""		//String after decimal
  
    if (isEmpty(strValue)) 
       if (isMoney.arguments.length == 1) return defaultEmptyOK;
       else return (isMoney.arguments[1] == true);

    if (strValue == decimalPointDelimiter) return false;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < strValue.length; i++)
    {   
        // Check that current character is number.
        var c = strValue.charAt(i);

	if  (c == ',') 
		return false;


        if ((c == decimalPointDelimiter) && !seenDecimalPoint) {

		seenDecimalPoint = true;
	}
        else {
		if (!isDigit(c)) {
		    if ((i == 0 && (c == "-" || c == "+")) == false)  return false;  		
		}		
	}
    }
    
    iDecimalPointIndex = strValue.indexOf(".")
    
    if (iDecimalPointIndex != -1)
		{
		sStrAfterDecimal = strValue.substring(++iDecimalPointIndex,iDecimalPointIndex + 5);
		if (sStrAfterDecimal.length > 2) return false;
			
		}
		
    // All characters are numbers.
    return true;
}


