if (navigator.appName == 'Microsoft Internet Explorer')
	var IE = true;
else
	var NN = true;
	
var curcentury = '20';
var precentury = '19';


//Auto Skip in SSN
function SSN1Key()
{
var ssn1 = document.frmMain.txtSSN1.value;
if (ssn1.length == 3)  
{
	document.frmMain.txtSSN2.focus();
}
}



function SSN2Key()
{
var ssn2 = document.frmMain.txtSSN2.value;
if (ssn2.length == 2)  
{
   document.frmMain.txtSSN3.focus();
}
}
//end AutoSkip


function Trim(value) {
	while(''+value.charAt(value.length-1)==' ') // Trim trailing spaces
		value=value.substring(0,value.length-1);
		
	var i = 0; // Trim leading spaces
	while(''+value.charAt(i)==' ') {
		value=value.substring(i + 1,value.length);
		i = i + 1;
	}
		return value;
}

function isSSN(ssn) {
	var error;
	var snumber = ssn.value;
	if (isNumeric(snumber)) {
		if ((snumber.length == 3) || (snumber.length == 6) || (snumber.length==9)) {
		// success
		}
		else {
			error = "Enter 3/6/9 digits for Social Security Number.";
		}
	}
	else {
		error = "Social Security Number should be numeric.";
	}

	if (error != null) {
		alert(error);
		ssn.focus();
		return(false);
	}
	return(true);
}

// begin of date functions
function isdate(date)
{
	var aDate = date.value;
	
	if (aDate.length != 0)
	{
		var err = validate_Date(aDate,0,1);
	
		if (err != null)
		{
			alert(err);
			date.focus();
			return(false);
		}
		else
		{
			mm = aDate.substring( 0,2 );
			aDate=aDate.substring(2,aDate.length);
			dd=aDate.substring( 0,2 );
			aDate=aDate.substring(2,aDate.length);
			yy=aDate;
			
			if (isNumeric(mm) && isNumeric(dd))
				var formatdate = mm + "/" + dd + "/" + yy;
			else
				var formatdate = date.value;
			
			date.value = formatdate;
			mm = formatdate.substring(0,formatdate.indexOf("/"));
			dd = formatdate.substring(formatdate.indexOf("/")+1,formatdate.indexOf("/",formatdate.indexOf("/")+1));
			yy = formatdate.substring(formatdate.indexOf("/",formatdate.indexOf("/")+1)+1,formatdate.length);
			
			
			if (yy.length == 2)
			{
				if (yy < 30)
					birthyear = curcentury + yy;
				else
					birthyear = precentury + yy;
			}
			else
				birthyear = yy;
			
			formatdate = mm+"/"+dd+"/"+birthyear;
			var today = new Date();
			if (IE || (!document.all&&document.getElementById))
				today = new Date(today.getYear(),today.getMonth(),today.getDate());
			else
				today = new Date(today.getYear() + 1900,today.getMonth(),today.getDate());
			if (date.name == "txtFilter")  {
				return(true);
			}
			if (date.name == "txtDOB")
			{
				var currentdate=new Date();
				var curyy=currentdate.getFullYear();
				var curmm = currentdate.getMonth() + 1;
				var curdd = currentdate.getDate();
						
				if ((curyy - birthyear) < 15)
				{
					alert('DOB cannot be less than 15');
					date.value = "";
					date.focus();
				}
				else
				{
					if ((curyy - birthyear) == 15)
					{
						if (curmm < mm)
						{
							alert('DOB cannot be less than 15');
							date.value = "";
							date.focus();
						}
						else
						{
							if (curmm == mm)
							{
								if (curdd <= dd)
								{
									alert('DOB cannot be less than 15');
									date.value = "";
									date.focus();
								}
							}
						}
					}
				}
			}
			if (date.name == 'txtSince')
			{
				var sincedate = new Date(formatdate);
				if (sincedate.getTime() >= today.getTime())
				{
					alert('Date Should be Less than Today');
					date.value = "";
					date.focus();
				}	
			}
			if (date.name == 'txtRUAppDate')
			{
				var appdate = new Date(formatdate);
				if (appdate.getTime() > today.getTime())
				{
					alert('Date Should be Less than or Equal to Today');
					date.value = "";
					date.focus();
				}
			}
			if (date.name == 'txtRUMoveinDate')
			{
				var movedate = new Date(formatdate);
				if (movedate.getTime() < today.getTime())
				{
					alert('Date Should be Greater than or Equal to Today');
					date.value = "";
					date.focus();
				}
			}
			
			if (date.name == 'txtEmploymentDate')
			{
				var empdate = new Date(formatdate);
				if (empdate.getTime() > today.getTime())
				{
					alert('Date Should be Less than or Equal to Today');
					date.value = "";
					date.focus();
				}
			}
		}
	}

}

function validate_Date(date,mandatory,AlertsOK)
{
//	*********************************************
//	* Purpose:  general routine for validating dates .
//	*
//	* Format:	 mm/dd/yyyy, mm/dd/yy
//	* Inputs:	 date - date
//	*			 mandatory - there mustbe a date
//	*			 AlertsOK  - invalid dates will draw user attention
//	*			 FutureOK  - future dates are OK
//	*********************************************
    tDate = myTrim(date);
    if (( tDate.length == 0 ) && (mandatory))
    {
		if (AlertsOK)
			return "Please specify a valid date in either mm/dd/yyyy or mm/dd/yy." + "\n";
			 
    }  
    if (( tDate.length == 0 ) && ( !mandatory))	              
		return ;

	temp = tDate.indexOf("/",0);
	if (temp!= -1)	
	{
		if (( tDate.length > 10 )|| (tDate.length < 6)) 
		{
			if (AlertsOK)
				return "Date you've entered is unrecognizable." + "\n";
		} 
		mm = tDate.substring( 0,temp );
		dd = tDate.substring( temp+1, tDate.indexOf("/",temp+1) );
		yy = tDate.substring( tDate.indexOf("/",temp+1)+1, tDate.length );
						
		if( !isNumeric( mm ) || !isNumeric( dd ) || !isNumeric( yy ) )
		{
			if (AlertsOK)
				return "Invalid date entry." + "\n" ;
		}
		else if( (mm <= 0) || (mm > 12) )
		{
			if (AlertsOK)
				return "Invalid month entry." + "\n";
		}
		else if( (dd <= 0) || (dd > getDaysPerMonth( mm, yy ) ))
		{
			if (AlertsOK)
				return "Invalid day entry." + "\n";
		}

		if ((yy.length != 4)) 
		{
			if ((yy.length != 2)) 
			{
				if (AlertsOK)
					return "Invalid year entry." + "\n";
			}
		}

	}
//	***** absence of '/' ******** 
	else {						 
			if((tDate.length > 8 )|| (tDate.length < 6 ))
			{
				if (AlertsOK)
					return "Date you've entered is unrecognizable." + "\n";
				
			} 
			mm = tDate.substring( 0,2 );
			tDate=tDate.substring(2,tDate.length);
			dd=tDate.substring( 0,2 );

			tDate=tDate.substring(2,tDate.length);
			yy=tDate;

			if( !isNumeric( mm ) || !isNumeric( dd ) || !isNumeric( yy ) )
			{
				if (AlertsOK)
					return "Invalid date entry." + "\n";
			}
			else if( (mm <= 0 )|| (mm > 12 ))
			{
				if (AlertsOK)
		     		return "Invalid month entry." + "\n";
			}
			else if( (dd <= 0) || (dd > getDaysPerMonth( mm, yy )) )
			{
				if (AlertsOK)
					return "Invalid day entry." + "\n";
			}
			
			if ((yy.length != 2) && (yy.length != 4) ) 
			{
				if (AlertsOK)
					return "Invalid year entry." + "\n";
			}
			
        }

	if (yy.length == 4) {
		if (yy < 1900) {
			if(AlertsOK) 
				return "Check year entry." + "\n";
		}
	}

//    Following code can be removed!		
		dateobj=new Date(yy,mm,dd);
//		alert(dateobj); <%'  this is buggy %>
		currentdate=new Date();
//		getYear returns 2 digt for 1900-1999, and 4 digit for 2000+ %>
		var curyy=currentdate.getYear();
		var tempcuryy=new String(curyy);
		if (tempcuryy.length==2)
			tempcuryy=precentury+ tempcuryy; 
//		getMonth returns number 0-11 %>
		var curmm=currentdate.getMonth();
		var curdd=currentdate.getDate();


		dateobj=null;
		currentdate=null;
		// ' if its reached here it must be O.K %>
		
	return null;		
}

function myTrim(sinput) 	{
//	'*********************************************
//	'* general routine for trimming input data.
//	'*********************************************
	var stemp='';
	var counter = 0;
	for( var i=0; i<sinput.length; i++ ){
		  if( sinput.substring( i,i+1 ) !=" ") {
				stemp=stemp + sinput.substring( i,i+1 );
		  }
	}
	return(stemp);
}

function isNumeric( data )	{
	//	'*********************************************
	//	'* general routine for validating numeric data.
	//	'*********************************************
    var numString = "0123456789";
    var thisChar;
    var counter = 0;
    for( var i=0; i<data.length; i++ ){
	  thisChar = data.substring( i,i+1 );
		if(numString.indexOf(thisChar,0)!=-1)
		  counter++;						
    }
	if(counter == data.length)	{
			   return(true);  // 'validateNumber(data); %>
	}
	else
		   return(false);	
}

function getDaysPerMonth(month, year) 	{
//	'*********************************************
//	'* Purpose:  general routine for getting Days Per Month.
//	'*
//	'*
//	'* Desc:	 creates an array to hold number of days in each month,
//	'*			 then returns value based on month, year passed in
//	'*
//	'* Inputs:	 month, year
//	'*********************************************


	var daysPerMonth = new Array(12);
    daysPerMonth[0] = 31;           // January
    daysPerMonth[1] = (isLeapYear(year)) ? 29 : 28;    // ' February
    daysPerMonth[2] = 31;           // March
    daysPerMonth[3] = 30;           // April
    daysPerMonth[4] = 31;           // May
    daysPerMonth[5] = 30;           // June
    daysPerMonth[6] = 31;           // July
    daysPerMonth[7] = 31;           // August
    daysPerMonth[8] = 30;           // September
    daysPerMonth[9] = 31;           // October
    daysPerMonth[10] = 30;          // November
    daysPerMonth[11] = 31;          // December

    return daysPerMonth[ month-1 ]
}

function isLeapYear(year) 
{
//	'*********************************************
//	'* Purpose:  To find leap year definition
//	'*
//	'* Desc:	 uses mod to determine if divisible by 4
//	'*
//	'*********************************************
//
   
    if( year % 400 == 0 || (year % 4 == 0 && year % 100 != 0) )
                     return true;
    return false;
}

//dob date applet


//Show Date Applet
function ShowDate(div)
{
if (IE)  
{
	eval("document.all."+div+".style.visibility = 'visible'");
} 
else 
{
	eval("document."+div+".visibility = 'show'");
}
}
//end show date

function SeeDate()
{
  if (IE) 
  {
	document.all.divDOB.style.visibility = "hidden";
  	document.frmMain.txtDOB.value = appDOB.getSelectedMonth() + '/' + appDOB.getSelectedDate() + '/' + appDOB.getSelectedYear();
  }	
  else
  {
	document.divDOB.visibility = "hidden";
	document.frmMain.txtDOB.value = document.layers["divDOB"].document.applets["appDOB"].getSelectedMonth()+ '/' + document.layers["divDOB"].document.applets["appDOB"].getSelectedDate() + '/' + document.layers["divDOB"].document.applets["appDOB"].getSelectedYear();
  }	
  isdate(document.frmMain.txtDOB);
  return;
}

function setDateAny(divName, appletName, txtName) {
    if (IE) {
        document.all[divName].style.visibility = "hidden";
        document.frmMain[txtName].value = document.all[appletName].getSelectedMonth() + '/' + document.all[appletName].getSelectedDate() + '/' + document.all[appletName].getSelectedYear();
    } else {
        document[divName].visibility = "hidden";
        document.frmMain[txtName].value = document.layers[divName].document.applets[appletName].getSelectedMonth()+ '/' + document.layers[divName].document.applets[appletName].getSelectedDate() + '/' + document.layers[divName].document.applets[appletName].getSelectedYear();
    }

    isdate(document.frmMain[txtName]);
    return;
}


//
function selColumn_onchange() {
		if (window.document.frmMain.selColumn.value == 'sSSNum') {
			window.document.frmMain.txtFilter.maxLength = 9;
			window.document.frmMain.txtFilter.size = 20;
			window.document.frmMain.txtFilter.value = '';
		} else  {
		if (window.document.frmMain.selColumn.value == 'tTimeStamp') {
			window.document.frmMain.txtFilter.maxLength = 8;
			window.document.frmMain.txtFilter.size = 20;
			window.document.frmMain.txtFilter.value = '';
		}
		else {
			window.document.frmMain.txtFilter.maxLength = 20;
			window.document.frmMain.txtFilter.size = 20;
			window.document.frmMain.txtFilter.value = '';
		}
		};
}

function setColor(obj, col){
	if(document.all){
		obj.style.color=col;
	}
}

