function validateForm() {
	var clmNun = new String()
	clmNum = document.getElementById('txtClaimNbr').value
	if ( clmNum.length < 7 || clmNum.length > 8 ) {
		alert("You must enter a valid claim number");
		return false;
	}
	var monthDOL = new String()
	var dayDOL = new String()
	var yearDOL = new String()
	monthDOL = document.getElementById('txtDolmm').value
	dayDOL = document.getElementById('txtDoldd').value
	yearDOL = document.getElementById('txtDolyy').value

	if (monthDOL.length == 0 || dayDOL.length == 0 || yearDOL.length == 0 ) {
		alert("You must enter a Date of loss")
		return false
	}
	if (dateValidation(document.getElementById('txtDolmm'),document.getElementById('txtDoldd'),document.getElementById('txtDolyy'),this,false) ) {
		return true
	}
	return false
}



function removeSpaces(value)
{
	//remove spaces
	pattern = /\s+/gi;
	value = value.replace(pattern, "");
	return value;
}

function TempSSN(el)
{
	el.value = "888888888";	
}

function maxSizeValidation(el)
{
	var val = removeSpaces(el.value);
	el.value = val;
	
	//if nothing is in the field don't require max length
	if ( val.length == 0 )
		return true;
	
	if ( val.length == el.maxLength )
		return true;
					
	alert("**Validation Error**  "+el.ourTagName+" must be "+el.maxLength+" characters!");
	el.focus();
}

function listValidation(el,elList,showError)
{
	var numargs = listValidation.arguments.length;		
	if ( numargs != 3 )
		showError = true;
		
	var val = removeSpaces(el.value).toUpperCase();
	if ( val == "" )
		return true;
		
	el.value = val;		
	
	setOption(elList,val);
	if ( elList.selectedIndex > -1 )
		return true;
		

	if ( showError == true )		
		{
		alert("**Validation Error**  "+el.ourTagName+" is not valid!");
		el.value = "";
		el.focus();
		}
	return false;		
}

function dateToDateValidation(elMonth,elDay,elYear,orgFocus,allowFutureDate,elCmpMonth,elCmpDay,elCmpYear,after)
{
	var numargs = dateToDateValidation.arguments.length;
	if ( numargs != 9 )
		after = true;
		
	if ( dateValidation(elMonth,elDay,elYear,orgFocus,allowFutureDate) == true  )
		{
		var i = compareDates(elMonth,elDay,elYear,elCmpMonth,elCmpDay,elCmpYear);
		if ( after == true )
			{
			if ( i >= 0 )
				return true;
			else
				{
				alert("**Validation Error**  "+elMonth.ourTagName+" must be >= "+elCmpMonth.ourTagName+"!");
				elMonth.value = "";
				elDay.value = "";
				elYear.value = "";
				elMonth.focus();
				return false;
				}
			}
		else
			{
			if ( i <= 0 )
				return true;							
			else
				{
				alert("**Validation Error**  "+elMonth.ourTagName+" must be <= "+elCmpMonth.ourTagName+"!");
				elMonth.value = "";
				elDay.value = "";
				elYear.value = "";
				elMonth.focus();
				return false;
				}				
			}				
		}
				
	return false;						
	
		
}
function dateValidation(elMonth,elDay,elYear,orgFocus,allowFutureDate)
{

	var monthVal = removeSpaces(elMonth.value);
	var dayVal   = removeSpaces(elDay.value);
	var yearVal  = removeSpaces(elYear.value);
	var msgNotLaterToday = "**Validation Error**  "+elMonth.ourTagName+" can not be later than today!";
	var msg = "**Validation Error**  "+elMonth.ourTagName+" is not a valid date!";
	
	elMonth.value = monthVal;
	elDay.value = dayVal;
	elYear.value = yearVal;
	
	if ( monthVal.length == 0 &&
		 dayVal.length   == 0 &&
		 yearVal.length  == 0 )
		return true;
		
	//check for a valid month		
	if ( monthCheck(elMonth) )
		{
		if ( monthVal.length != 2 )
			elMonth.value = "0" + monthVal;
			
		if ( orgFocus == elMonth && (dayVal.length == 0 || yearVal == 0) )
			return true;
				
		//check for a valid day
		if ( dayCheck(elMonth,elDay) )
			{
			if ( dayVal.length != 2 )
				elDay.value = "0" + dayVal;
			
			if ( orgFocus == elDay && yearVal == 0 )
				return true;
				
			//check for a valid year
			if ( yearCheck(elYear) )
				{
				var ok = true;
				if ( allowFutureDate == false )
					{
					if ( futureDateCheck(elMonth,elDay,elYear) )
      					{
						msg = msgNotLaterToday;						
						ok = false;
						}
					}
				
				if ( ok )
					{	
					//future dates are allowed but need to check for leap year
					if ( monthVal == 2 && dayVal == 29 )
						{
						if (yearVal % 4 == 0 && yearVal % 100 != 0 || yearVal % 400 == 0)
							return true;
						}
					else
						return true;					
					}						
				} //year check
			} //day check
		} //month check
					
	alert(msg);
	if ( yearVal.length > 0 && yearVal.length < 4 )
		elYear.focus();
	else
		{	
		elMonth.value="";
		elDay.value="";
		elYear.value="";
		elMonth.focus();
		}
	return false;
}	

function monthCheck(elMonth)			
{
	var monthVal = elMonth.value;
	
	//check to see if the month is val and valid
	if ( numericCheck(monthVal) &&	( monthVal > 0 && monthVal <= 12 ) )
		return true;
	
	return false;				
}

function yearCheck(elYear)			
{
	
	var yearVal = elYear.value;
					
	//check to see if the year 4 digits in length and is numeric and later than 1760
	// if ( yearVal.length == elYear.maxLength &&  numericCheck(yearVal) && yearVal >= 1760)

   // Netscape does not seem to support the maxLength call, so I am hardcoding 4 
	if ( yearVal.length == 4 &&  numericCheck(yearVal) && yearVal >= 1760)
		return true;
	
	return false;				
}

function dayCheck(elMonth,elDay)			
{
	var dayVal = elDay.value;
	
	//check to see if the day is numeric
	if ( numericCheck(dayVal) == false)
		return false;

	//strip out the leading zero from the month to make checking it easier
	var monthVal = elMonth.value;
	
	if ( monthVal.length == 2 && monthVal.substring(0) == 0 )
		monthVal = monthVal.substring(1);

	//strip out the leading zero from the day to make checking it easier	
	if ( dayVal.length == 2 && dayVal.substring(0) == 0 )
		dayVal = dayVal.substring(1);
		
	//check to see if the month is 31 days long	
	if ( monthVal == 1 || monthVal == 3 || monthVal ==  5 || monthVal == 7 ||
		 monthVal == 8 || monthVal == 10 || monthVal == 12)
		{
		if ( dayVal <= 0 || dayVal > 31 )
			return false;
		else
			return true;			
		}			
	
	if ( monthVal == 4 || monthVal == 6 || monthVal ==  9 || monthVal == 11 )
		{
		if ( dayVal <= 0 || dayVal > 30 )
			return false;
		else
			return true;			
		}
		
	//month is Feb.  need to check for leap year later on in the year check
	if ( dayVal <= 0 || dayVal > 29 )
		return false;					
		
	return true;
}

function mustBeFutureDate(el, elMM, elDD, elYYYY)
{
	if (dateValidation(elMM,elDD,elYYYY,el,true) == true)
		{
      if ( removeSpaces(elMM.value) == "" ||
           removeSpaces(elDD.value) == "" ||
           removeSpaces(elYYYY.value) == "" )
        return true;

		var ret_cd = futureDateCheck(elMM, elDD, elYYYY, true);

		if (ret_cd == false)
            {
 			   alert("**Validation Error**  " + el.ourTagName + " must be >= the current date.");
            elMM.value = "";
            elDD.value = "";
            elYYYY.value = "";
            elMM.focus();
            return false;
            }

      return true;
		}	

   return false;
}

function futureDateCheck(elMonth,elDay,elYear,andToday)
{
	var numargs = futureDateCheck.arguments.length;		
   var andTodayInd = false;
	if ( numargs == 4 )
		andTodayInd = andToday;

	var today = new Date();
	var dateToChk = new Date(elYear.value,elMonth.value-1,elDay.value);

   if (andTodayInd == true )
      {
   	if ( dateToChk > today )
	   	return true;
      
      if ( dateToChk < today )
        	return false;		

      return true;
      }

   if ( dateToChk > today )
      return true;
   return false;		

}


function zip5Validation(elZip5)
{
	var zip5Val = removeSpaces(elZip5.value);
	elZip5.value = zip5Val;
	
	var msg = "**Validation Error**  "+elZip5.ourTagName+" must be either 5 or 9 numeric characters!";
	
	//if nothing is in the field don't require it to be all numeric
	if ( zip5Val.length == 0 )
		return true;
		
	//see if we have a valid zip5					
	if ( zip5Val.length == elZip5.maxLength && numericCheck(zip5Val) )
		return true;
		

	alert(msg);
	elZip5.value = "";
	elZip5.focus();
	return false;	
}

function zip4Validation(elZip4,elZip5)
{
	var zip5Val = removeSpaces(elZip5.value);
	var zip4Val = removeSpaces(elZip4.value);
	elZip5.value = zip5Val;
	elZip4.value = zip4Val;
	
	var msg = "**Validation Error**  "+elZip5.ourTagName+" must be either 5 or 9 numeric characters!";
	
	//if nothing is in the field don't require it to be all numeric
	if ( zip4Val.length == 0)
		return true;
		
	if ( zip5Val.length > 0 &&
		 zip4Val.length == elZip4.maxLength &&
		 numericCheck(zip4Val) )
		return true;
			
	alert(msg);
	elZip4.value = "";
	elZip4.focus();
	return false;
}

function maxNumericValidation(el)
{
	var val = removeSpaces(el.value);
	el.value = val;
	
	//if nothing is in the field don't require it to be all numeric
	if ( val.length == 0 )
		return true;
	
	if ( val.length == el.maxLength && numericCheck(val) )
		return true;
					
	alert("**Validation Error**  "+el.ourTagName+" is invalid!  Must be all numerics!");
	el.value = "";
	el.focus();
	return false;
}


function numericValidation(el)
{
	var val = removeSpaces(el.value);
	el.value = val;
	
	//if nothing is in the field don't require it to be all numeric
	if ( val.length == 0 )
		return true;
	
	if ( numericCheck(val) )
		return true;		
					
	alert("**Validation Error**  "+el.ourTagName+" is invalid!  Any characters inputted must be numeric!")
	el.value = "";
	el.focus();
	return false;
}

function numericValidationWithLimit(el,limit)
{
	//if nothing is in the field don't require it to be all numeric
	var val = removeSpaces(el.value);
	el.value = val;
	
	if ( val.length == 0 )
		return true;
	
	var msg = "**Validation Error**  "+el.ourTagName+" is invalid!  Any characters inputted must be numeric!";
	var msgMax = "**Validation Error**  "+el.ourTagName+" is greater than the maximum value limit!";
	
	if ( numericCheck(val) )
		{
		if ( val <= limit )
			{
			if ( val.length != el.maxLength )
				{
				var nbrZeros = el.maxLength - val.length;
				var zeroStr = "";
				for ( var i = 0; i < nbrZeros; i++ )
					{
					zeroStr = zeroStr + "0";
					}
				el.value = zeroStr + val;
				}
							
			return true;		
			}
		msg = msgMax;
		}	
		
	alert(msg);
	el.value = "";
	el.focus();
	return false;
}

function numericCheck(nbrToChk)
{

	flg=0;

	for (var i=0; i < nbrToChk.length;i++)
		{
		cmp="0123456789"
		tst=nbrToChk.substring(i,i+1)
		if (cmp.indexOf(tst)<0)
			{
			flg++;
			}
		}

	if (flg!=0)
		{
		return false;
		}

	return true;
}

function ssnValidation(el,tempInd)
{
	var tempSSNInd = true;
	var numargs = ssnValidation.arguments.length;
	if ( numargs == 2 )
		tempSSNInd = tempInd;
	else
		{
		if ( document.all.InternetVerStr.value == "D" )
			tempSSNInd = false;
		}
	var val = removeSpaces(el.value);
	el.value = val;
	
	if ( val.length == 0 )
		return true;
		
	//must be all numerics
	if ( !maxNumericValidation(el) )
		return false;
	
	if ( val == "000000000" ||
		 val == "111111111" ||			
		 val == "222222222" ||
		 val == "333333333" ||
		 val == "444444444" ||
		 val == "555555555" ||
		 val == "666666666" ||
		 val == "777777777" ||
		 val == "999999999" ||
		 val == "012345678" ||
		 val == "123456789" ||
		 (val == "888888888" && tempSSNInd == false) )
		;
	else
		return true;
	
						
	alert("**Validation Error**  "+el.ourTagName+" is invalid!")
	el.value = "";
	el.focus();
	return false;
}

function fieldPadLeadingZeros(el,always)
{
	var numargs = fieldPadLeadingZeros.arguments.length;
	if ( numargs != 2 )
		always = false;
	val = padLeadingZeros(el.value,el.maxLength,always);
	el.value = val;
	return val;
}

function padLeadingZeros(val,maxlength,always)
{
	var numargs = padLeadingZeros.arguments.length;
	if ( numargs != 3 )
		always = false;

	val = removeSpaces(val);
	if ( val.length == maxlength)
		return val;
	
	if ( val == "" && always == false )
		return val;
		
	var newval = "";
	var nbrZeros = maxlength - val.length;

	for ( var i = 0; i < nbrZeros; i++ )
		newval = newval + "0";
	val = newval + val;
	
	return val;
}

function padCollWithLeadingZeros(coll,always)
{		
	if (coll == null)
		return;
		
	var numargs = padCollWithLeadingZeros.arguments.length;
	if ( numargs != 2 )
		always = false;
		
	var nbrItems = coll.length;
	var value;
	var el;
	
	if ( nbrItems == null )
		{
		el = coll;
		fieldPadLeadingZeros(el,always);
		}			
	else
		{		
		for (i=0; i < nbrItems; i++)
			{
			el = coll.item(i);
			if ( isVisible(el))
				fieldPadLeadingZeros(el,always);
			}				
		}

}

function compareDates(elChkMonth,elChkDay,elChkYear,elCmpMonth,elCmpDay,elCmpYear,cmpOkIfNoCmpDt)
{
    var cmpOk = true;
    if ( compareDates.arguments.length == 7 )
       cmpOk = cmpOkIfNoCmpDt;

	var chkMonth = removeSpaces(elChkMonth.value);
	var chkDay   = removeSpaces(elChkDay.value);
	var chkYear  = removeSpaces(elChkYear.value);
	if ( chkMonth == "" || chkDay == "" || chkYear == "" )
		return 0; //compare them equal for now since the check date is not available		
		
	var cmpMonth = removeSpaces(elCmpMonth.value);
	var cmpDay   = removeSpaces(elCmpDay.value);
	var cmpYear  = removeSpaces(elCmpYear.value);
	if ( cmpMonth == "" || cmpDay == "" || cmpYear == "" )
        {
        if ( cmpOk == true)
    		return 0; //compare them equal for now since the compare date is not available
        else
            return 1; //compare them differenct since it was requested
        }

	var compareDate = new Date(cmpYear,cmpMonth-1,cmpDay);
	var dateToChk = new Date(chkYear,chkMonth-1,chkDay);
	if ( dateToChk > compareDate )
		return 1;
	
	if ( dateToChk < compareDate )
		return -1;

	return 0;				
	
}


function onfocusNextFocus(el,elNext)
{
	var value;
	if ( el.type == "select-one" )
		value = getOption(el);
	else
		value = el.value;		
		
	value = removeSpaces(value);	
   
	if ( keyJustPressed == TABKEY_VALUE &&
	     shiftKeyJustPressed == false &&
		 value != "" && 
        isVisible(elNext) == true )
		elNext.focus();		
	
	return true;		

}
	

function validatePhone(elAreaCode,elNbr3,elNbr4,elExt)
{
	var elExtToUse = null;
			
	if ( validatePhone.arguments.length == 4 )
		elExtToUse = elExt;

	var areaCode = removeSpaces(elAreaCode.value);
	var nbr3 = removeSpaces(elNbr3.value);
	var nbr4 = removeSpaces(elNbr4.value);
	var ext = "";
	
	if ( elExtToUse != null )
		ext = removeSpaces(elExt.value);
		
	var ok = true;
	
	if ( areaCode != "" && (nbr3 == "" || nbr4 == "" ) )
		ok = false;
		
	if ( ext != "" && ok == true && ( areaCode == "" || nbr3 == "" || nbr4 == "" ) )
		ok = false;
		
	if ( nbr3 != "" && ok == true && (areaCode == "" || nbr4 == "" ) )
		ok = false;
	
	if ( nbr4 != "" && ok == true && (areaCode == "" || nbr3 == "" ) )
		ok = false;
		
	if ( ok == false )
		{	
		alert("**Validation Error**  Invalid "+elAreaCode.ourTagName+" must be in the format (nnn)nnn-nnnn!");
		elAreaCode.focus();
		return false;
		}
	return true;			
}	

function dateValidateYearTo(elYear, bottomYear, nbrYearsTo)
{
	var curr_date  = new Date();
	var currDateYYYY  = curr_date.getFullYear();
	var futureYear = currDateYYYY + nbrYearsTo;
	var passedYear = removeSpaces(elYear.value);
	
	if ( passedYear == "" )
		return;
		
	var msg = "**Validation Error**  Invalid " + elYear.ourTagName + " must be a 4 numeric digit year >= 1900 and <= " + futureYear + "!";

	//check to see if the year a 4 digits in length and is numeric 
	if ( numericCheck(passedYear) == false )
		{
		alert(msg);
		elYear.value = "";
		elYear.focus();
		return false;
		}

	if ( passedYear.length != elYear.maxLength )
		{
		alert(msg);
		elYear.focus();
		return false;
		}
		
	if ( passedYear >= bottomYear && passedYear <= futureYear)    
		return true;
   else
      {
   	alert(msg);
   	elYear.value = "";
	   elYear.focus();
   	return false;
      }
}	

function makeThisLength(fldValue,makeLen)
{
   var sp = "";
   for (var i=0; i < makeLen; i++ )
      sp = sp + " ";
	var len = fldValue.length;
	var value = fldValue + sp.substr(0,makeLen-len);
   return value;
}


function formatSpecialOption(appendTo,value)
{
  appendTo = appendTo + removeSpecialClmtParticChars(value) + "^";
  return(appendTo);
}  

function removeSpecialClmtParticChars(value)
{
  var myValue = "";
  if ( removeSpaces(value) != "" )
     {
     var myLen = value.length;
     var myValue2 = "";
     for ( var i = 0; i < myLen; i++)
        {
        myValue2 = value.substr(i,1);
        if ( myValue2 != "," && myValue2 != ";" )
           {
            myValue = value.substr(i);
            i  = myLen;
           }
         }
     }
   return(myValue);
}  

//tab over from month to day
function AutoTab2(value)
{
	
var counter;
counter = 0;
for (var i=0; i<value.length; i++)
		{
                 
		  counter = counter + 1
//alert(counter);
			if ( counter == 2 )
				{
				document.getElementById('txtDoldd').focus();
                                return true;
				}
		}
	return false;
}

//tab over from day to year
function AutoTab3(value)
{
	
var counter;
counter = 0;
for (var i=0; i<value.length; i++)
		{
                 
		  counter = counter + 1
//alert(counter);
			if ( counter == 2 )
				{
				document.getElementById('txtDolyy').focus();
                                return true;
				}
		}
	return false;
}


//set focus from year text box to RSI 
function AutoTab4(value)
{
	
var counter;
counter = 0;
for (var i=0; i<value.length; i++)
		{
                 
		  counter = counter + 1
//alert(counter);
			if ( counter == 4 )
				{
				//document.getElementById('RSI').focus();
                                return true;
				}
		}
	return false;
}

//auto tab over from claim number text box to month text box
function AutoTab5(value)
{
	
var counter;
counter = 0;
for (var i=0; i<value.length; i++)
		{
                 
		  counter = counter + 1
//alert(counter);
			if ( counter == 7 )
				{
				document.getElementById('txtDolmm').focus();
                                return true;
				}
		}
	return false;
}

//function used to allow alphanumerics ONLY in txtClaimNbr
function editClaimNbr(el) {
   /* returns true if the field has all alphanumeric characters, false if not */ 
   var index;
   var myChar;

   /* add chars to the following string if you want punctuation or spaces allowed */
   var allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

   if (! el) {
      alert("**Validation Error** " + el.ourTagName + " must be alphanumeric"); 
      el.value = "";
      el.focus();
      return false;
   }
   else {
      var str = el.value;
   }

   for (index = 0; index < str.length; index ++) {
      myChar = str.charAt(index);
      if (allowedChars.indexOf(myChar) == -1) {
         alert("**Validation Error** " + el.ourTagName + " must be alphanumeric"); 
	 el.value = "";
	 el.focus();
	 return false;
      }
      if (index == 6) {
         document.getElementById('txtDolmm').focus();
      }
   }
   
   return true;
}   
