<!--
/*  FUNCTIONS.JS  -  Javascript Functions Module
      insert the following code into the 'head' section of your html/asps page :	
 	       <script language="JavaScript" type="text/javascript" src="/includes/Functions.js"></script>
*/
//   Convert to currency 
// 		created by Rick Murray 3/30/2007
//		this function converts numeric string to currency string, including commas
//      if input has more than 2 decimal places, its rounded to 2 decimal places.       
//      As of 4/17/2007, this is used by :  /Employers/ereast/ereppr/RemitAdvice.aspx

	function ConvertToCurrency(strValue) {   
		strValue = strValue.replace(",","") ; 			// remove first comma
		strValue = strValue.replace(",","") ; 			// remove first comma
		strValue = strValue.replace(",","") ; 			// remove first comma
		strValue = strValue.replace(",","") ; 			// remove first comma
		if (isNaN(strValue)) { 							// if passed value is not all numeric 
			 strValue="not a number" ;	
			 return strValue;
		}
	    nbrValue=Number(strValue);							// convert string to number
		if ( nbrValue.toFixed(2) != nbrValue ) {            // if 3 or more decimal places ...
			 strValue="2 dec. places" ;	
			 return strValue;
		}
		var  nbrValue =  nbrValue.toFixed(2);			    // forces (and rounds to) 3 decimal places			
		strValue = String(nbrValue);  						// convert number back to string 
		var nbrTlen = strValue.length; 						// total length
		strCents = strValue.substring(nbrTlen-3, nbrTlen); 	// extract cents (including decimal)
		strValue = strValue + "";							// this is necessary, but not sure why
		strDollars = strValue.substring(0, nbrTlen-3); 		// extract dollars
		nbrDlen = strDollars.length;  						// dollars length
	    if (nbrDlen > 3) {
			arrDollars = strDollars.split(""); 			// convert dollars to array of single characters			
 	     	while (nbrDlen > 3) {  						// loop until past thousands position					
               nbrDlen-=3;  							// decrement length value
			   arrDollars.splice(nbrDlen,0,","); 		// insert comma character
           }
		    strDollars = arrDollars.join(""); 			// re-assemble dollars string from array
			strValue = strDollars + strCents;			// assemble currency string
			strValue = strValue.replace("-,","-") ;  	// remove "-," sequence, if found
		}
		return strValue;		 
	}
//           end of module

//   Date Validation code (assumes mm/dd/yyyy format) 
//     DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
//     As of 4/17/2007, this is used by :  /Employers/ereast/ereppr/RemitAdvice.aspx
/* 
Sample code to invoke this date validation  logic : 
		if (isDate(document.getElementById("DepositDate").value)==false){
			document.getElementById("DepositDate").focus();
			return false
		}
*/
var dtCh= "/";
var minYear=1900;
var maxYear=2100;
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
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++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}
		
//  Browser name and version 
//    This code has been tested for Windows XP and ...
//         - Netscape versions 6.x and 7.x
//         - Firefox Ver 1.x
//         - MSIE Ver 6.x			
/*    
      To insert the text value of browser name and version into your web page,
      insert the following code into the appropriate place in the 'body'
            <script> document.write(Browser()) </script>    
*/  													  
function Browser() { 
		var brwsrNm="unknown";
		var brwsrVer="?";
		var userAgent=navigator.userAgent; 
		if (userAgent.indexOf("MSIE")   != -1) {                   
				nbrIndex=userAgent.indexOf("MSIE");
				brwsrNm="Internet Explorer";
				brwsrVer=userAgent.charAt(nbrIndex+5);	
		}                                                
		if (userAgent.indexOf("Firefox")   != -1) {                   
				nbrIndex=userAgent.indexOf("Firefox");
				brwsrNm="Firefox";
				brwsrVer=userAgent.charAt(nbrIndex+8);
		} 
		if (userAgent.indexOf("Netscape")   != -1) {                   
				nbrIndex=userAgent.indexOf("Netscape");
				brwsrNm="Netscape";
				brwsrVer=userAgent.charAt(nbrIndex+9);
                if (userAgent.charAt(nbrIndex+8) == "6") { brwsrVer = "6";};   // needed for NS V6	
		}
		if (userAgent.indexOf("Safari")   != -1) {
				nbrIndex=userAgent.indexOf("Version");                  
				brwsrNm="Safari";  
				brwsrVer=userAgent.charAt(nbrIndex+8);	
		}		
		return brwsrNm + " v" + brwsrVer; 
} 
//  Operationg System name and version 
//    This code has been tested for Windows XP and ...
//         - Netscape versions 6.x and 7.x
//         - Firefox Ver 1.x
//         - MSIE Ver 6.x
//		   - Safari Ver 3.0.3			
/*    
      To insert the text value of Operationg System name and version into your web page,
      insert the following code into the appropriate place in the 'body'
            <script> document.write(System()) </script>    
*/  													  
function System() { 
		var OSNm="unknown";
		var OSVer="?";
		var userOS=navigator.appVersion; 
		if (userOS.indexOf("Windows") != -1) {                   
				OSNm="Windows";	
		}   
		if (userOS.indexOf("Mac OS X")   != -1) {               
				OSNm="Mac OS X";	
		}  
		if (userOS.indexOf("Linux")   != -1) {                
				OSNm="Linux";	
		}
		if (userOS.indexOf("LINUX")   != -1) {               
				OSNm="Linux";	
		}
		if (userOS.indexOf("Unix")   != -1) {               
				OSNm="Unix";	
		}
		if (userOS.indexOf("UNIX")   != -1) {                
				OSNm="Unix";	
		}                                            		
		return OSNm
}  

/*********************************************************************************************
	This script is based on the javascript code of Roman Feldblum (web.developer@programmer.net)
	Original script : http://javascript.internet.com/forms/format-phone-number.html
	Original script is revised by Eralper Yilmaz (http://www.eralper.com)
	Revised script : http://www.kodyaz.com
 *********************************************************************************************/

var zChar = new Array(' ', '(', ')', '-', '.');
var maxphonelength = 13;
var phonevalue1;
var phonevalue2;
var cursorposition;

function ParseForNumber1(object){
	phonevalue1 = ParseChar(object.value, zChar);
}

function ParseForNumber2(object){
	phonevalue2 = ParseChar(object.value, zChar);
}

function backspacerUP(object,e) { 
	if(e){ e = e } 
	else { e = window.event } 
	if(e.which){ var keycode = e.which } 
	else { var keycode = e.keyCode }
	ParseForNumber1(object)
	if(keycode >= 48){
		ValidatePhone(object)
	}
}

function backspacerDOWN(object,e) { 
	if(e){ e = e } 
	else { e = window.event } 
	if(e.which){ var keycode = e.which } 
	else { var keycode = e.keyCode }
	ParseForNumber2(object)
} 

function GetCursorPosition(){
	var t1 = phonevalue1;
	var t2 = phonevalue2;
	var bool = false
	for (i=0; i<t1.length; i++) {
		if (t1.substring(i,1) != t2.substring(i,1)) {
			if(!bool) {
				cursorposition=i
				bool=true
			}
		}
	}
}

function ValidatePhone(object){
	var p = phonevalue1

	p = p.replace(/[^\d]*/gi,"")

	if (p.length < 3) {
		object.value=p
	} 
	else if(p.length==3){
		pp=p;
		d4=p.indexOf('(')
		d5=p.indexOf(')')
		if(d4==-1){
			pp="("+pp;
		}
		if(d5==-1){
			pp=pp+")";
		}
	object.value = pp;
	} 
	else if(p.length>3 && p.length < 7){
		p ="(" + p; 
		l30=p.length;
		p30=p.substring(0,4);
		p30=p30+")"
	
		p31=p.substring(4,l30);
		pp=p30+p31;
	
		object.value = pp; 
	} 
	else if(p.length >= 7){
		p ="(" + p; 
		l30=p.length;
		p30=p.substring(0,4);
		p30=p30+")"
	
		p31=p.substring(4,l30);
		pp=p30+p31;
		
		l40 = pp.length;
		p40 = pp.substring(0,8);
		p40 = p40 + "-"
	
		p41 = pp.substring(8,l40);
		ppp = p40 + p41;
		
		object.value = ppp.substring(0, maxphonelength);
	}
	
	GetCursorPosition()

	if(cursorposition >= 0){
		if (cursorposition == 0) {
			cursorposition = 2
		} 
		else if (cursorposition <= 2) {
			cursorposition = cursorposition + 1
		} 
		else if (cursorposition <= 5) {
			cursorposition = cursorposition + 2
		} 
		else if (cursorposition == 6) {
			cursorposition = cursorposition + 2
		} 
		else if (cursorposition == 7) {
			cursorposition = cursorposition + 4
			e1=object.value.indexOf(')')
			e2=object.value.indexOf('-')
			if (e1>-1 && e2>-1){
				if (e2-e1 == 4) {
					cursorposition = cursorposition - 1
				}
			}
		} 
		else if (cursorposition < 11) {
			cursorposition = cursorposition + 3
		} 
		else if (cursorposition == 11) {
			cursorposition = cursorposition + 1
		} 
		else if (cursorposition >= 12) {
			cursorposition = cursorposition
		}
	
		var txtRange = object.createTextRange();
		txtRange.moveStart( "character", cursorposition);
		txtRange.moveEnd( "character", cursorposition - object.value.length);
		txtRange.select();
	}
}

function ParseChar(sStr, sChar) {
	if (sChar.length == null) {
		zChar = new Array(sChar);
	}
	else zChar = sChar;
	
	for (i=0; i<zChar.length; i++) {
		sNewStr = "";
	
		var iStart = 0;
		var iEnd = sStr.indexOf(sChar[i]);
	
		while (iEnd != -1) {
			sNewStr += sStr.substring(iStart, iEnd);
			iStart = iEnd + 1;
			iEnd = sStr.indexOf(sChar[i], iStart);
		}
		sNewStr += sStr.substring(sStr.lastIndexOf(sChar[i]) + 1, sStr.length);
		
		sStr = sNewStr;
	}
	
	return sNewStr;
}

/******************************************************
	Auto tabbing script- By JavaScriptKit.com
	http://www.javascriptkit.com
	This credit MUST stay intact for use
 ******************************************************/
function autotab(current,destination){
    if (current.getAttribute && 
      current.value.length==current.getAttribute("maxlength")) {
        destination.focus() 
        }
}
-->				