//File    : lc_common.js
//Purpose : Generic Javascript functions that are applicable for most of the pages
var giDecimalPos = 0;
var n, p, p1, goFieldName;
var ssField, ssHandler, handlerInterval = 100, mcValue = ""
/* ========================================================================= */
/* trims leading/trailing spaces from a string                               */
/* ========================================================================= */
String.prototype.trim = function(){
	return this.replace(/^\s+/,"").replace(/\s+$/,"");
}

//checks if the input value is numeric or not
String.prototype.isNumeric = function isNum() {
	var arg = isNum.arguments;

	if (arg==null || arg.length==0) {
		regE = /^\s*[-+]{0,1}\d*\.{0,1}\d*\s*$/g
	} else {
		regE = new RegExp(arg[0], arg[1])
	}
	var larrVal = new Array();
	larrVal = this.match(regE);
	if (larrVal==null) {
		return false;
	} else {
		return true;
	}
}

//Checks if the date is valid or not (format must be MM/DD/YYYY only)
/***
function ufIsDate(asDate){
  var indate      =       asDate
  var strDate   =   indate.split("/");
  //format must be (yyyy,mm,dd)
  var dtchkDate   =       new Date(((strDate[2] * 1)),((strDate[0] * 1)-1),(strDate[1] * 1));
  var lintYear  = dtchkDate.getFullYear();
  var strcmpDate  =       ((dtchkDate.getMonth()+1)+"/"+dtchkDate.getDate())+"/"+(lintYear);
  var strindate2  =       (Math.abs(strDate[0]))+"/"+(Math.abs(strDate[1]))+"/"+(Math.abs(strDate[2]));
  if (strindate2!=strcmpDate){ return false;}
  else {
    if (strcmpDate=="NaN/NaN/NaN"){
      return false;
    }
	}
    return true;
}
***/

//Checks if the date is valid or not (format must be MM/DD/YYYY only)
function ufIsDate(asDate) {
	// regular expression to match "MM/DD/YYYY" where
	//	MM   = (1, 2, ... 9), (01, 02, ...09), (10, 11, 12)
	//	DD   = (1, 2, ... 9), (01, 02, ...09), (10, 11, ... 19), (20, 21, ... 29), (30, 31)
	//	YYYY = any 4 digit year
	var exp = /^((1[0-2])|(0*[1-9]))\/(([12][0-9])|([3][01])|(0*[1-9]))\/\d{4}$/
	asDate = asDate.trim()
	if (!exp.test(asDate)) {
		return false
	} else {
		arr = asDate.split("/")
		dateObj = new Date( arr[2], arr[0] - 1, arr[1] )
		if ( dateObj.getMonth()!=(arr[0] - 1) ||  arr[2] < 1900) {
			return false
		}
	}
	return true
}

//JMAGNO #33882 07.27.2007 -- START
//Checks if entered date is valid (format = MM/DD/YYYY) and within acceptable date range (01/01/1753-12/31/2050).
function isValidDate(asObj, asLabel, asTab, asReturnMsg) {
	// regular expression to match "MM/DD/YYYY" where
	//	MM   = (1, 2, ... 9), (01, 02, ...09), (10, 11, 12)
	//	DD   = (1, 2, ... 9), (01, 02, ...09), (10, 11, ... 19), (20, 21, ... 29), (30, 31)
	//	YYYY = any 4 digit year
    if (asObj) {
        var lbError = false;
        var lsErrorMsg = '';
	    var exp = /^((1[0-2])|(0*[1-9]))\/(([12][0-9])|([3][01])|(0*[1-9]))\/\d{4}$/;
	    var lsDate = asObj.value.trim();
	    if (!exp.test(lsDate)) {
            if (asReturnMsg == 1) {
                lsErrorMsg = 'Invalid ' + asLabel + ', please enter in format MM/DD/YYYY.';
            } else {
		        alert('Invalid ' + asLabel + ', please enter in format MM/DD/YYYY.');
            }
			lbError = true;
	    } else {
		    arr = lsDate.split("/");
		    if (arr[2] < 1753) {
                if (asReturnMsg == 1) {
                    lsErrorMsg = asLabel + ' cannot be prior to 01/01/1753.';
                } else {
                    alert(asLabel + ' cannot be prior to 01/01/1753.');
                }
                lbError = true;
            } else if (arr[2] > 2050) {
                if (asReturnMsg == 1) {
                    lsErrorMsg = asLabel + ' cannot be later than 12/31/2050.';
                } else {
                    alert(asLabel + ' cannot be later than 12/31/2050.');
                }
                lbError = true;
            }

			//---------------
			month = arr[0]
			day = arr[1]
			year = arr[2]

			if (month == 02) { // check for february 29th
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
				if (day > 29 || (day==29 && !isleap)) {
                    if (asReturnMsg == 1) {
                        lsErrorMsg = 'Invalid ' + asLabel + ', please enter in format MM/DD/YYYY.';
                    } else {
				        alert('Invalid ' + asLabel + ', please enter in format MM/DD/YYYY.')
                    }
				    lbError = true;
				}
			}
            //---------------

	    }
	    if (lbError) {
            if (asTab > 0) { uf_tab_select(asTab); }
		    asObj.focus();
            if (asReturnMsg == 1) {
                return lsErrorMsg;
            } else {
                return false;
            }
        }
    }
    if (asReturnMsg == 1) {
        return '';
    } else {
        return true;
    }
}

//Checks if entered date range is valid
function ufValidDateRange(asDateFrom, asDateTo, asLabelFrom, asLabelTo, asTab, asReturnMsg) {
    var lsDateFrom = asDateFrom.value.trim();
    var lsDateTo = asDateTo.value.trim();
    var lsErrorMsg = '';
	if (!(lsDateFrom == "") || !(lsDateTo == "" )) {
		if (lsDateFrom == "") {
            if (asReturnMsg == 1) {
                lsErrorMsg = asLabelFrom + ' is required.';
            } else {
			    alert(asLabelFrom + ' is required.');
            }
            if (asTab > 0) { uf_tab_select(asTab); }
			asDateFrom.focus();
            if (asReturnMsg == 1) {
                return lsErrorMsg;
            } else {
			    return false;
            }
		}
		if (lsDateFrom != "") {
            if (asReturnMsg == 1) {
                lsErrorMsg = isValidDate(asDateFrom, asLabelFrom, asTab, asReturnMsg);
                if (lsErrorMsg != '') {
                    return lsErrorMsg;
                }
            } else if (!isValidDate(asDateFrom, asLabelFrom, asTab)) {
                return false;
            }
		}
		if (lsDateTo == "") {
            if (asReturnMsg == 1) {
                lsErrorMsg = asLabelTo + ' is required.';
            } else {
			    alert(asLabelTo + ' is required.') ;
            }
			if (asTab > 0) { uf_tab_select(asTab); }
			asDateTo.focus();
            if (asReturnMsg == 1) {
                return lsErrorMsg;
            } else {
			    return false;
            }
		}
		if (lsDateTo != "") {
            if (asReturnMsg == 1) {
                lsErrorMsg = isValidDate(asDateTo, asLabelTo, asTab, asReturnMsg);
                if (lsErrorMsg != '') {
                    return lsErrorMsg;
                }
            } else if (!isValidDate(asDateTo, asLabelTo, asTab)) {
                return false;
            }
		}
		if (!isValidDateRange(lsDateFrom, lsDateTo)){
            if (asReturnMsg == 1) {
                lsErrorMsg = asLabelTo + ' cannot be prior to ' + asLabelFrom + '.';
            } else {
                alert(asLabelTo + ' cannot be prior to ' + asLabelFrom + '.') ;
            }
			if (asTab > 0) { uf_tab_select(asTab); }
			asDateTo.focus();
            if (asReturnMsg == 1) {
                return lsErrorMsg;
            } else {
			    return false;
            }
		}

	}
    if (asReturnMsg == 1) {
        return '';
    } else {
        return true;
    }
}

//Checks if entered year is valid (format = YYYY) and within acceptable year range (1753-2050).
function isValidYear(asObj, asLabel, asTab, asReturnMsg) {
    var lsErrorMsg = '';
	// regular expression to match "YYYY" where
	//	YYYY = any 4 digit year
    if (asObj) {
        var lbError = false;
	    var exp = /^\d{4}$/;
	    var lsYear = asObj.value.trim();
	    if (!exp.test(lsYear)) {
            if (asReturnMsg == 1) {
                lsErrorMsg = 'Invalid ' + asLabel + ', please enter in format YYYY.';
            } else {
		        alert('Invalid ' + asLabel + ', please enter in format YYYY.');
            }
            lbError = true;
	    } else {
		    if (lsYear < 1753) {
                if (asReturnMsg == 1) {
                    lsErrorMsg = asLabel + ' cannot be prior to 1753.';
                } else {
                    alert(asLabel + ' cannot be prior to 1753.');
                }
                lbError = true;
            } else if (lsYear > 2050) {
                if (asReturnMsg == 1) {
                    lsErrorMsg = asLabel + ' cannot be later than 2050.';
                } else {
                    alert(asLabel + ' cannot be later than 2050.');
                }
                lbError = true;
            }
	    }
	    if (lbError) {
            if (asTab > 0) { uf_tab_select(asTab); }
		    asObj.focus();
            if (asReturnMsg == 1) {
                return lsErrorMsg;
            } else {
                return false;
            }
        }
    }
    if (asReturnMsg == 1) {
        return '';
    } else {
        return true;
    }
}

//Checks if entered year range is valid.
function isValidYearRange(asYearFrom, asYearTo, asLabelFrom, asLabelTo, asTab, asReturnMsg) {
    var lsYearFrom = asYearFrom.value.trim();
    var lsYearTo = asYearTo.value.trim();
    var lsErrorMsg = '';
	if (!(lsYearFrom == "") || !(lsYearTo == "" )) {
		if (lsYearFrom == "") {
            if (asReturnMsg == 1) {
                lsErrorMsg = asLabelFrom + ' is required.';
            } else {
			    alert(asLabelFrom + ' is required.') ;
            }
            if (asTab > 0) { uf_tab_select(asTab); }
			asYearFrom.focus();
            if (asReturnMsg == 1) {
                return lsErrorMsg;
            } else {
			    return false;
            }
		}
        if(lsYearFrom != "") {
            if (asReturnMsg == 1) {
                lsErrorMsg = isValidYear(asYearFrom, asLabelFrom, asTab, asReturnMsg);
                if (lsErrorMsg != '') {
                    return lsErrorMsg;
                }
            } else if (!isValidYear(asYearFrom, asLabelFrom, asTab)) {
                return false;
            }
        }
		if (lsYearTo == "") {
            if (asReturnMsg == 1) {
                lsErrorMsg = asLabelTo + ' is required.';
            } else {
			    alert(asLabelTo + ' is required.') ;
            }
			if (asTab > 0) { uf_tab_select(asTab); }
			asYearTo.focus();
            if (asReturnMsg == 1) {
                return lsErrorMsg;
            } else {
			    return false;
            }
		}
        if(lsYearTo != "") {
            if (asReturnMsg == 1) {
                lsErrorMsg = isValidYear(asYearTo, asLabelTo, asTab, asReturnMsg);
                if (lsErrorMsg != '') {
                    return lsErrorMsg;
                }
            } else if (!isValidYear(asYearTo, asLabelTo, asTab)) {
                return false;
            }
        }
		if (lsYearTo < lsYearFrom){
            if (asReturnMsg == 1) {
                lsErrorMsg = asLabelTo + ' cannot be prior to ' + asLabelFrom + '.';
            } else {
                alert(asLabelTo + ' cannot be prior to ' + asLabelFrom + '.') ;
            }
			if (asTab > 0) { uf_tab_select(asTab); }
			asYearTo.focus();
            if (asReturnMsg == 1) {
                return lsErrorMsg;
            } else {
			    return false;
            }
		}
	}
    if (asReturnMsg == 1) {
        return '';
    } else {
        return true;
    }
}

//Validates date entries.
function ufValidateDate(asObjFrom, asObjTo, asLabelFrom, asLabelTo, asTab, asReturnMsg) {
    var lsErrorMsg = '';
	if (asObjFrom && asObjTo) {
        if (asReturnMsg == 1) {
            lsErrorMsg = ufValidDateRange(asObjFrom, asObjTo, asLabelFrom, asLabelTo, asTab, asReturnMsg);
            if (lsErrorMsg != '') {
                return lsErrorMsg;
            }
        } else if (!ufValidDateRange(asObjFrom, asObjTo, asLabelFrom, asLabelTo, asTab)) {
            return false;
        }
	}
	if (asObjFrom) {
		if (asObjFrom.value.trim() != "") {
            if (asReturnMsg == 1) {
                lsErrorMsg = isValidDate(asObjFrom, asLabelFrom, asTab, asReturnMsg);
                if (lsErrorMsg != '') {
                    return lsErrorMsg;
                }
            } else if (!isValidDate(asObjFrom, asLabelFrom, asTab)) {
                return false;
            }
		}
	}
	if (asObjTo) {
		if (asObjTo.value.trim() != "") {
            if (asReturnMsg == 1) {
                lsErrorMsg = isValidDate(asObjTo, asLabelTo, asTab, asReturnMsg);
                if (lsErrorMsg != '') {
                    return lsErrorMsg;
                }
            } else if (!isValidDate(asObjTo, asLabelTo, asTab)) {
                return false;
            }
		}
	}
    if (asReturnMsg == 1) {
        return '';
    } else {
        return true;
    }
}

//Validates year entries.
function ufValidYear(asObjFrom, asObjTo, asLabelFrom, asLabelTo, asTab, asReturnMsg) {
    var lsErrorMsg = '';
	if (asObjFrom && asObjTo) {
        if (asReturnMsg == 1) {
            lsErrorMsg = isValidYearRange(asObjFrom, asObjTo, asLabelFrom, asLabelTo, asTab, asReturnMsg);
            if (lsErrorMsg != '') {
                return lsErrorMsg;
            }
        } else if (!isValidYearRange(asObjFrom, asObjTo, asLabelFrom, asLabelTo, asTab)) {
            return false;
        }
	}
    if (asObjFrom) {
        if(asObjFrom.value.trim() != "") {
            if (asReturnMsg == 1) {
                lsErrorMsg = isValidYear(asObjFrom, asLabelFrom, asTab, asReturnMsg);
                if (lsErrorMsg != '') {
                    return lsErrorMsg;
                }
            } else if (!isValidYear(asObjFrom, asLabelFrom, asTab)) {
                return false;
            }
        }
    }
    if (asObjTo) {
        if(asObjTo.value.trim() != "") {
            if (asReturnMsg == 1) {
                lsErrorMsg = isValidYear(asObjTo, asLabelTo, asTab, asReturnMsg);
                if (lsErrorMsg != '') {
                    return lsErrorMsg;
                }
            } else if (!isValidYear(asObjTo, asLabelTo, asTab)) {
                return false;
            }
        }
    }
    if (asReturnMsg == 1) {
        return '';
    } else {
        return true;
    }
}
//JMAGNO #33882 07.27.2007 -- END

//Checks if the date is valid or not (format must be MM/DD/YYYY only)
function ufIsTime(asTime){

  var inTime      =       asTime
  var strTime   =   inTime.split(":");
     if (strTime.length) {
    } else {
        return false;
    }

    if (strTime[0].length != 2) {
        return false;
    }

    if (!ufIsNumber(strTime[0])) {
        return false;
    }

    if (eval(strTime[0]) <= 0 || eval(strTime[0]) > 12) {
        return false;
    }


    var strTime2   =   strTime[1].trim().split(" ");
    if (strTime2.length)  {
    } else {
        return false;
    }
    if (strTime2[0].length != 2) {
        return false;
    }

    if (!ufIsNumber(strTime2[0])) {
        return false;
    }
    if (eval(strTime2[0]) < 0 || eval(strTime2[0]) > 59) {
        return false;
    }


    if (strTime2[1]) {
        if (strTime2[1].toUpperCase() != "AM" && strTime2[1].toUpperCase() != "PM") {
            return false;
        }
    }else{
        return false;
    }


    return true;
}

/* ========================================================================= */
/* Roll Over Images function                                                 */
/* ========================================================================= */
function ufImgRollOver(astrImg) {
	var lobjSource = event.srcElement;
	lobjSource.src = astrImg;
}

// displays error message from CLIENT SIDE validations
function ufShowMessage(asLayer, asMsg) {
                var loLyr = document.all[asLayer];
                loLyr.innerHTML = "<CENTER CLASS='message'>" + asMsg + "</CENTER>"
                loLyr.style.display = "block";
}
// Hides the message
function ufHideMessage(asLayer, abDisplay) {
	var loLyr = document.all[asLayer];
	loLyr.innerHTML = "&nbsp;"
	if (!abDisplay)	loLyr.style.display = "none";
}

//
function ufDisable(asChk) {
 if (asChk.checked) {
	asChk.checked = false;
 }
 else {
   asChk.checked = true ;
 }
}

function ufChkValidate(asChk) {
 if (asChk.checked) {
   asChk.value = 1 ;
 }
 else {
   asChk.value = 0 ;
 }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function ufToUpper( asString ){
  if ( asString == null ) return "" ;
  if ( asString.length = 0 ) return "" ;
  return asString.trim().toUpperCase();
}

function isValidDateRange( asFrom,asTo ){
  dtFrom = new Date(asFrom)
  dtTo = new Date(asTo)
  if (dtFrom > dtTo) return false;
  return true;
}

function isFutureDate(asDateEntry){
  dtDateEntry = new Date(asDateEntry)
  dtDateToday = new Date()
  if (dtDateEntry > dtDateToday) return false;
  return true;
}

function getHTMLEncode( asString ) {

  if ( asString == null ) return "";
  if ( asString.length <= 0 ) return "";
  var lsTemp = "";
  var lbMultiSpace = false ;

  for( liX = 0; liX < asString.length ; liX++ ) {
    var lcChar = asString.charAt( liX ) ;
    var lbMultiSpace = (lbMultiSpace && lcChar == ' ' )
    switch( lcChar ) {
      case '<' :
        lsTemp = lsTemp + "&lt;" ;
        break ;
      case '>' :
        lsTemp =  lsTemp +"&gt;" ;
        break ;
      case '&' :
        lsTemp =  lsTemp +"&amp;" ;
        break ;
      case '"' :
        lsTemp =  lsTemp +"&quot;" ;
        break ;
      case '\n' :
        break ;
      case '\t' :
        lsTemp =  lsTemp +"&nbsp;&nbsp;&nbsp;" ;
        break ;
      case ' ' :
        lsTemp =  lsTemp +" " ;
        if ( lbMultiSpace ) {
          lsTemp =  lsTemp +"&nbsp; " ;
        }
        lbMultiSpace = true ;
        break ;
      default:
        lsTemp =  lsTemp + lcChar
    }
  }

  if( lbMultiSpace ) {
    lsTemp =  lsTemp +"&nbsp; " ;
  }
  return lsTemp ;

}

function ufGetTime() {
     var ldate    = new Date()
     var lampm    = ((ldate.getHours() >= 12) ? "pm" : "am");
     var lhours   = ldate.getHours();
     var lhours   = ((lhours > 12) ? (lhours - 12) : lhours);
     var lminutes = ((ldate.getMinutes() < 10) ? ".0" : ".") + ldate.getMinutes();
     var lseconds = ((ldate.getSeconds() < 10) ? ".0" : ".") + ldate.getSeconds();
     var ltime    = (lhours + lminutes + lseconds + lampm)
     return (ltime);
}

// dreamweaver systems generated functions //

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

// print displayed page
function ufPrintMeNow() {
       var ns = (navigator.appName == "Netscape");
       if (ns) {
          var version = parseInt(navigator.appVersion);
       } else {
          var version = navigator.userAgent;
              version = parseInt(version.substring(version.indexOf('MSIE') + 5));
       }
       window.focus();
       this.focus();
       if ((ns) || (version > 4)) {
           window.print();
       } else {
           //alert("test2");
           var webBrowser = '<OBJECT ID="webBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
           document.body.insertAdjacentHTML('BeforeEnd', webBrowser);
           window.alert("Make sure the printer is ready.");
           webBrowser1.ExecWB(6, 1); //use 1(for prompting dialog box in IE4) or 2(for direct print in IE4)
           webBrowser1.outerHTML = "";
       }
}

function ufCheckForDecimal(asVal){
   var liPos = asVal.indexOf(".");
   if (liPos > 0){
        var lsDecimal = asVal.substring(liPos+1);
        if (lsDecimal.length > 2){  //two decimals found
                return true;
        }
   }
return false;
}

//Use this function instead of the above isNumeric(). This works with ie 5.5. AEEJR 11/06/2001
function ufIsNumeric(asValue,asText) {
       var lsVal = asValue.toString();
       var lsMessage = "";

        if(isNaN(asValue.trim())){
             lsMessage = asText +" should be a valid numeric entry.";
             return lsMessage;
        } else {
                var ldTmp = (lsVal.trim() == "")?0: eval(lsVal);
                if (lsVal.trim()!="" && ldTmp<0) {
                        lsMessage = asText +" should be a positive numeric value.";
                        return lsMessage;
                }
                liPos = lsVal.indexOf(".");
                if (liPos >= 0){
                        lsDecimal = lsVal.substring(liPos+1);
                        if (lsDecimal.length > 2){
                                lsMessage = asText +" can not have more than two decimal places.";
                                return lsMessage;
                        }
                }
                if(eval(lsVal) > 999999.99) {
                        lsMessage = asText +" should be in 999999.99 format.";
                        return lsMessage;
                }
        }
        return "";
}

function getDate() {
	var today = new Date();
	var today_day = new Array( "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
		"Friday", "Saturday" );
	var today_month = new Array( "January", "February", "March", "April", "May", "June",
		"July", "August", "September", "October", "November", "December" );

	var today_date = today.getDate();

	var today_year = today.getYear();
	if (today_year < 1000) {
		today_year = today_year + 1900
	}
    var lsdate = (today_day[today.getDay()] + " " + today_month[today.getMonth()] + " " + today_date + ", " + today_year);
    return lsdate;
}

//Use this function instead of the above isNumeric(). This works with ie 5.5. AEEJR 11/06/2001
function ufIsNumber(asValue) {
       var lsVal = asValue.toString();
       var lsMessage = "";

        if(isNaN(asValue.trim())){
             return false;
        } else {
                var ldTmp = (lsVal.trim() == "")?0: eval(lsVal);
                if (lsVal.trim()!="" && ldTmp<0) {
                        return false;
                }
                liPos = lsVal.indexOf(".");
                if (liPos >= 0){
			return false;
                }

        }
        return true;
}

//this method allow negative values -gvs02182002
function ufIsNum(asValue,asText) {
       var lsVal = asValue.toString();
       var lsMessage = "";

        if(isNaN(asValue.trim())){
             lsMessage = asText +" should be a valid numeric entry.";
             return lsMessage;
        } else {
                var ldTmp = (lsVal.trim() == "")?0: eval(lsVal);
                //if (lsVal.trim()!="" && ldTmp<0) {
                //        lsMessage = asText +" should be a positive numeric value.";
                //        return lsMessage;
                //}
                liPos = lsVal.indexOf(".");
                if (liPos >= 0){
                        lsDecimal = lsVal.substring(liPos+1);
                        if (lsDecimal.length > 2){
                                lsMessage = asText +" can not have more than two decimal places.";
                                return lsMessage;
                        }
                }

               if(eval(lsVal) > 999999.99) {
                        lsMessage = asText +" should be in 999999.99 format.";
                       return lsMessage;
                }

        }
        return "";
}


//validates Minimum and Maximum range
function ufValidate_Range(asMin,asMax,asMinField,asMaxField){
  if (eval(asMin) > eval(asMax)){
    lsMessage = asMinField +" can not be greater than "+ asMaxField +"."
    return lsMessage;
  }
  return "";
}

function ufMaxValue(aiLen) {
var lsVal = "";
        for (i=0;i<aiLen;i++){
           lsVal += "9";
        }
return lsVal+".99";

}

//add trailing zero to numeric entries
function ufPadElement(objField){
        var liDecCtr = 0;
        var lsPrefix = "",lsVal="";
        var lsTempVal = objField.value
        if (objField.value.charAt(0)=="") return

        lsVal = objField.value.substring(0,objField.value.indexOf("."));
//        if (lsVal.length > objField.maxLength ){
//                objField.value = "0.00";
//                return
//        }
        if (objField.value.length >= objField.maxLength ){
                return;
        }
        if(lsTempVal.indexOf(".") <= 0) {
               lsTempVal = lsTempVal + ".00";
        } else {
                if (lsTempVal.charAt(lsTempVal.length-2)=="."){
                        lsTempVal=lsTempVal+"0"
                } else if(lsTempVal.charAt(lsTempVal.length-1)=="."){
                        lsTempVal=lsTempVal+"00"
                }
        }

        if (lsTempVal.length > objField.maxLength ){
                return;
        }

        var lsTempnum = objField.value
        for (i=0;i<lsTempnum.length;i++){
                if (lsTempnum.charAt(i)=="."){
                        liDecCtr++;
                }
        }


        if(liDecCtr <= 1) {
                if (objField.value.trim() == ".") {
                        objField.value = "0.00";
                        return;
                }

                lsVal = objField.value;
                var lsStartChars = lsVal.substring(0,lsVal.indexOf("."));
                for (i=0;i<lsVal.indexOf(".");i++) {
                        if (lsVal.charAt(i)=="0" && lsStartChars.length > 1){
                                 objField.value = lsVal.substring(i+1, lsVal.length);
                        } else {
                                break;
                        }
                }
                //start check
                lsVal = objField.value;
                var lsChar = lsVal.substring(0,1);
                if(lsChar == "."){
                        objField.value = "0"+lsVal;
                }
                lsVal = objField.value;
                if(eval(lsVal) < 0.01) {
                        objField.value = "0.00";
                        return;
                }


                if (eval(objField.value+" > "+ufMaxValue(objField.maxLength))) {
                        objField.value = "0.00";
                        return
                }
                if (liDecCtr == 0)
                        objField.value=lsPrefix+lsTempnum+".00"
                else if(liDecCtr == 1) {
                    if (lsTempnum.charAt(lsTempnum.length-2)=="."){
                        objField.value=lsPrefix+lsTempnum+"0"
                    } else if(lsTempnum.charAt(lsTempnum.length-1)=="."){
                          objField.value=lsPrefix+lsTempnum+"00"
                    }
                }

                //we need to redo this again. since there are other scenario not considered.
                lsVal = objField.value;
                var lsStartChars = lsVal.substring(0,lsVal.indexOf("."));
                for (i=0;i<lsVal.indexOf(".");i++) {
                        if (lsVal.charAt(i)=="0" && lsStartChars.length > 1){
                                 objField.value = lsVal.substring(i+1, lsVal.length);
                        } else {
                                break;
                        }
                }
                //final check
                lsVal = objField.value;
                var lsChar = lsVal.substring(0,1);
                if(lsChar == ".") objField.value = "0"+lsVal;
                lsVal = objField.value;
                if(eval(lsVal) < 0.01) objField.value = "0.00";

        }
}

function ufPadElem(objField){
        var liDecCtr = 0;
        var lsPrefix = "",lsVal="";
        var lsTempVal = objField.value
        if (objField.value.charAt(0)=="") return

        lsVal = objField.value.substring(0,objField.value.indexOf("."));
//        if (lsVal.length > objField.maxLength ){
//                objField.value = "0.00";
//                return
//        }
        if (objField.value.length >= objField.maxLength ){
                return;
        }
        if(lsTempVal.indexOf(".") <= 0) {
               lsTempVal = lsTempVal + ".00";
        } else {
                if (lsTempVal.charAt(lsTempVal.length-2)=="."){
                        lsTempVal=lsTempVal+"0"
                } else if(lsTempVal.charAt(lsTempVal.length-1)=="."){
                        lsTempVal=lsTempVal+"00"
                }
        }

        if (lsTempVal.length > objField.maxLength ){
                return;
        }

        var lsTempnum = objField.value
        for (i=0;i<lsTempnum.length;i++){
                if (lsTempnum.charAt(i)=="."){
                        liDecCtr++;
                }
        }


        if(liDecCtr <= 1) {
                if (objField.value.trim() == ".") {
                        objField.value = "0.00";
                        return;
                }

                lsVal = objField.value;
                var lsStartChars = lsVal.substring(0,lsVal.indexOf("."));
                for (i=0;i<lsVal.indexOf(".");i++) {
                        if (lsVal.charAt(i)=="0" && lsStartChars.length > 1){
                                 objField.value = lsVal.substring(i+1, lsVal.length);
                        } else {
                                break;
                        }
                }
                //start check
                lsVal = objField.value;
                var lsChar = lsVal.substring(0,1);
                if(lsChar == "."){
                        objField.value = "0"+lsVal;
                }
                lsVal = objField.value;
                //if(eval(lsVal) < 0.01) {
                //        objField.value = "0.00";
                //        return;
                //}


                if (eval(objField.value+" > "+ufMaxValue(objField.maxLength))) {
                        objField.value = "0.00";
                        return
                }
                if (liDecCtr == 0)
                        objField.value=lsPrefix+lsTempnum+".00"
                else if(liDecCtr == 1) {
                    if (lsTempnum.charAt(lsTempnum.length-2)=="."){
                        objField.value=lsPrefix+lsTempnum+"0"
                    } else if(lsTempnum.charAt(lsTempnum.length-1)=="."){
                          objField.value=lsPrefix+lsTempnum+"00"
                    }
                }

                //we need to redo this again. since there are other scenario not considered.
                lsVal = objField.value;
                var lsStartChars = lsVal.substring(0,lsVal.indexOf("."));
                for (i=0;i<lsVal.indexOf(".");i++) {
                        if (lsVal.charAt(i)=="0" && lsStartChars.length > 1){
                                 objField.value = lsVal.substring(i+1, lsVal.length);
                        } else {
                                break;
                        }
                }
                //final check
                lsVal = objField.value;
                var lsChar = lsVal.substring(0,1);
                if(lsChar == ".") objField.value = "0"+lsVal;
                lsVal = objField.value;
                //if(eval(lsVal) < 0.01) objField.value = "0.00";

        }
}

//accepts comma and semicolon as separator for multiple email addresses
function uf_IsEmail(asEmail) {
    //MaricelTalens issue27255 08.07.2006 [start]
    //var exp=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
    var exp=/^(\w+([_\'\.-]\w+)*@\w+([_\.-]\w+)*\.([A-Za-z]{2,4}))(([,;]\s*\w+([_\'\.-]\w+)*@\w+([_\.-]\w+)*\.([A-Za-z]{2,4}))*)*$/i;
    //MaricelTalens issue27255 08.07.2006 [start]

	//var exp = (/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.o rg)|(\..{2,2}))$)\b/gi);
	asEmail = asEmail.trim()
	if(asEmail != ""){
		if (!exp.test(asEmail)) {
		return false
		}
		return true
	}else{
		return true
	}
}

//only comma is accepted as separator for multiple email addresses
function uf_IsEmail2(asEmail) {
    //MaricelTalens issue27255 08.07.2006 [start]
    //var exp=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
    var exp=/^(\w+([_\'\.-]\w+)*@\w+([_\.-]\w+)*\.([A-Za-z]{2,4}))(([,]\s*\w+([_\'\.-]\w+)*@\w+([_\.-]\w+)*\.([A-Za-z]{2,4}))*)*$/i;
    //MaricelTalens issue27255 08.07.2006 [start]

	//var exp = (/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.o rg)|(\..{2,2}))$)\b/gi);
	asEmail = asEmail.trim()
	if(asEmail != ""){
		if (!exp.test(asEmail)) {
		return false
		}
		return true
	}else{
		return true
	}
}

/* ====================================================================================
*  Description: Add new line in table
*  Arguments:
*	aobjDiv (object) = document referencing to DIV name (e.g. document.all.divAttendance)
*       astrIdentifier (string) = will serve as a basis on what action to take.
*       asString (string) = the string or value to display on field.
======================================================================================== */
function ufAddLine(aobjDiv,asIdentifier, asString) {
    var lsStart = "",
        lsEnd = "",
        lsHTML = aobjDiv.innerHTML,
        lsSearch="<tbody>",
        liPos = 0;

    liPos = lsHTML.indexOf(lsSearch.toUpperCase());
        if (liPos >= 0) {
	    lsStart = lsHTML.substring(0, liPos);
            lsEnd = lsHTML.substring(liPos, lsHTML.length);
		//handles which action to be taken, depending on the Identifier passed
		switch (asIdentifier) {
		    case 'ContActivity':
                                lsHTML  = lsStart + asString + lsEnd;
			break;
		}
            aobjDiv.innerHTML = lsHTML
        }
}

function ufRoundOff(asResult) {
  liDecPt=2;
  var lsResult = asResult + " ";
  if (lsResult.charAt(0) == ".") {lsResult = "0" + lsResult};
  var liResultLen = lsResult.length - 1;
  ufGetPos(lsResult);

  if (liResultLen > 16) {
    if (liDecPt == -1) {liDecPt = 14};
    lsResult = ufDecPt(lsResult.substring(0,liResultLen)) + " ";
    liResultLen = lsResult.length - 1;
    ufGetPos(lsResult)
  }

  if (giDecimalPos > 0) {
       var lsRetVal = ufDecPt(lsResult.substring(0,liResultLen))
  }

  if (lsRetVal.charAt(0) == ".") {lsRetVal = "0" + lsRetVal};
  return(lsRetVal);
}

function ufGetPos(asParam) {
  giDecimalPos = 0;
  giDecimalPos = asParam.indexOf(".");
}

function ufDecPt(asParam) {
with (Math) {
    var liDecPos = giDecimalPos;
    if (liDecPos == -1) {liDecPos = asParam.length};
    if (liDecPos > 16) {
        var lsRoundNo = round(asParam*pow(10, 18)) + " ";
        var lsEpos = lsRoundNo.indexOf("e");
        var lsRetNo = (lsRoundNo.substring(0,lsEpos));
        lsRetNo = round(lsRetNo*pow(10, 15))/pow(10, 15) + " ";
        lsSpace = (lsRoundNo.substring(lsEpos+2,lsRoundNo.length-1));
        lsSpace = "e+" + (lsSpace-18)
     } else {
        var lsRetNo = round(asParam*pow(10, liDecPt))/pow(10, liDecPt) + " "
     }

        lsRetNo = lsRetNo.substring(0,lsRetNo.length - 1);
        if (lsRetNo.charAt(0) == ".") {lsRetNo = "0" + lsRetNo};
        if (liDecPt < 14) {
                if (lsRetNo.indexOf(".") == -1 && liDecPt != 0)
                        {lsRetNo += "."};
                var liTemp = (giDecimalPos + liDecPt) - (lsRetNo.length - 1);
                if (liTemp > 0 && liDecPt > 0) {
                        for (var n = 0; n < liTemp; n++) {
                                lsRetNo += "0"
			}
                }
        }
  return (lsRetNo)
}
}

function ValidatePhone(){
p=p1.value
if(p.length==3){
	pp=p;
	d4=p.indexOf('(')
	d5=p.indexOf(')')
	if(d4==-1){
		pp="("+pp;
	}
	if(d5==-1){
		pp=pp+")";
	}
    goFieldName.value="";
    goFieldName.value=pp;
}
if(p.length>3){
	d1=p.indexOf('(')
	d2=p.indexOf(')')
	if (d2==-1){
		l30=p.length;
		p30=p.substring(0,4);
		p30=p30+")"
		p31=p.substring(4,l30);
		pp=p30+p31;
        goFieldName.value="";
        goFieldName.value=pp;
	}
	}
if(p.length>5){
	p11=p.substring(d1+1,d2);
	if(p11.length>3){
	p12=p11;
	l12=p12.length;
	l15=p.length
	p13=p11.substring(0,3);
	p14=p11.substring(3,l12);
	p15=p.substring(d2+1,l15);
    goFieldName.value="";
	pp="("+p13+")"+p14+p15;
    goFieldName.value=pp;
	}
	l16=p.length;
	p16=p.substring(d2+1,l16);
	l17=p16.length;
	if(l17>3&&p16.indexOf('-')==-1){
		p17=p.substring(d2+1,d2+4);
		p18=p.substring(d2+4,l16);
		p19=p.substring(0,d2+1);
	pp=p19+p17+"-"+p18;
    goFieldName.value="";
    goFieldName.value=pp;
	}
}
    setTimeout(ValidatePhone,100)
}
function getIt(aoField){
    n=aoField.name;
    p1=aoField
    goFieldName = aoField;
    ValidatePhone();
}

//function checks if the passed string is found in the string list separated by ,.
function ufFindString(asStringList, asStringParm) {
  var lsString_arr = asStringList.split(",");
  var lbFound = 0;
  for(var x = 0; x < lsString_arr.length; x++) {
        //alert(lsString_arr[x].trim().toUpperCase())       //MaricelTalens issue27255 08.01.2006 [start]
        if(asStringParm.trim().toUpperCase() == lsString_arr[x].trim().toUpperCase()) {
            lbFound = x + 1;
            break;
        }
  }
 return lbFound;
}

// alex 08.04.2004 - for issue #15108 - testing start
//function checks if the passed string is found in the string list separated by |.
function ufFindString2(asStringList, asStringParm) {
  var lsString_arr = asStringList.split("|");
  var lbFound = 0;
  for(var x = 0; x < lsString_arr.length; x++) {
        if(asStringParm.trim().toUpperCase() == lsString_arr[x].trim().toUpperCase()) {
            lbFound = x + 1;
            break;
        }
  }
 return lbFound;
}
// alex 08.04.2004 - testing stop

function formatSSNo() {
	// format: 999-99-9999
	var ssNo
	if (ssField) {
		ssNo = ssField.value

		ssNo = ssNo.replace(/-+/g, "").replace(/\D/g, "")
		if (ssNo.length>5) {
			ssNo = ssNo.substr(0, 5) + '-' + ssNo.substr(5, ssNo.length - 4)
		}
		if (ssNo.length>3) {
			ssNo = ssNo.substr(0, 3) + '-' + ssNo.substr(3, ssNo.length - 2)
		}
		ssField.value = ssNo
	}
}

function getSSNo(aoField){
	ssField = aoField
	ssHandler = setInterval("formatSSNo()", handlerInterval)
}

function stopFormatter(handler) {
	clearInterval(handler)
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}


function formatMixedCase() {
        var sValue, nValue, tValue
        if (mcField) {
                var liCurrentPos = doGetCaretPosition(mcField)
                nValue  = "";
                sValue  = mcField.value;
                if (sValue==mcValue) {
                        return
                }

                //results = sValue.match(/\S+\s*/g);
/*
                if (results) {
                       for (var i =0; i < results.length; i++) {
                                if (results[i].length>1) {
                                        tValue = results[i].substr(0,1).toUpperCase() + results[i].substring(1, results[i].length);
                                } else {
                                        tValue = results[i].toUpperCase();
                                }
                                nValue = nValue + tValue;
                        }

               } else {
                        nValue = sValue;
               }
*/
                tValue = Right(sValue,2);

				if (tValue.length == 1)
				{
				tValue = tValue.toUpperCase();
				nValue = tValue;
				}
				else
				{
					if (tValue.substr(0,1) == " ")
					{
					tValue = tValue.substr(0,1) + tValue.substr(1,1).toUpperCase();
					}
					nValue = sValue.substr(0,sValue.length-2) + tValue;
				}

                mcField.value  = "";
                mcField.value  = nValue;
                setCaretPosition(mcField,liCurrentPos)
                mcValue = nValue
        }
}




function formatUpperCase() {
        var sValue, nValue, tValue
        if (mcField) {
                var liCurrentPos = doGetCaretPosition(mcField)
                nValue  = "";
                sValue  = mcField.value;
                if (sValue==mcValue) {
                        return
                }
                sValue  = sValue.toUpperCase()
                mcField.value  = "";
                mcField.value  = sValue;
                setCaretPosition(mcField,liCurrentPos)
                mcValue = sValue
        }
}

function formatLowerCase() {
        var sValue, nValue, tValue
        if (mcField) {
                var liCurrentPos = doGetCaretPosition(mcField)
                nValue  = "";
                sValue  = mcField.value;
                if (sValue==mcValue) {
                        return
                }
                sValue  = sValue.toLowerCase()
                mcField.value  = "";
                mcField.value  = sValue;
                setCaretPosition(mcField,liCurrentPos)
                mcValue = sValue
        }
}

function getMixedCase(aoField) {
        // dynamic arguments:
        //      arg[0] = field object
        //      arg[1] = format type (optional): 1 = mixed case (default), 2 = all uppercase, 3 = all lowercase
        args = getMixedCase.arguments
        if (args) {
                if (args.length>0) {
                        mcField = args[0];
                        mcValue = mcField.value
                        if (args.length>1) {
                                formatType = args[1]
                        } else {
                                formatType = 0
                        }
                        switch (args[1]) {
                                case 1:
                                        mcHandler = setInterval("formatMixedCase()", handlerInterval)
                                        break;
                                case 2:
                                        mcHandler = setInterval("formatUpperCase()", handlerInterval)
                                        break;
                                case 3:
                                        mcHandler = setInterval("formatLowerCase()", handlerInterval)
                                        break;
                                default:
                                        mcHandler = setInterval("formatMixedCase()", handlerInterval)
                                        break;
                        }
                }
        }

}


// alex 06.29.2004 : issue #14215 - removing radio button selection
function ufClearRadio(lsName){
  var loForm = document.evaluation_form;
  if (lsName == "all")
  {
    for (var liCtr=0;liCtr < loForm.elements.length;liCtr++){
        var loElem = loForm.elements[liCtr];
        if (loElem.type == "radio")
            loElem.checked = false;
        if (loElem.type == "text")
            loElem.value = "";
    }
  }
  else
  {
    for (var liCtr=0;liCtr < loForm.elements.length;liCtr++){
        var loElem = loForm.elements[liCtr];
        if (loElem.type == "radio" && loElem.name == lsName)
        loElem.checked = false;
    }
  }
}

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getRadioCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setRadioCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

//Mariceld issue20978 07.12.2005 [start]
function formatDate(DateField) {
  // format: 99/99/9999
  var asDate
  var loForm = document.evaluation_form
  if (DateField) {
    asDate = DateField.value

    asDate = asDate.replace(/[/]+/g, "").replace(/\D/g, "")
    if (asDate.length>4) {
      asDate = asDate.substr(0, 4) + '/' + asDate.substr(4, asDate.length - 4)
		}
    if (asDate.length>2) {
      asDate = asDate.substr(0, 2) + '/' + asDate.substr(2, asDate.length - 1)
		}
    DateField.value = asDate
	}
}
//Mariceld issue20978 07.12.2005 [end]

//Mariceld issue20978 07.20.2005 [start]
//codes inherited from mask.js
var lbMod = "false";
function _MaskAPI(){
	this.version = "0.4a";
	this.instances = 0;
	this.objects = {};
}
MaskAPI = new _MaskAPI();

function Mask(m, t){
	this.mask = m;
	this.type = (typeof t == "string") ? t : "string";
	this.error = [];
	this.errorCodes = [];
	this.value = "";
	this.strippedValue = "";
	this.allowPartial = false;
	this.id = MaskAPI.instances++;
	this.ref = "MaskAPI.objects['" + this.id + "']";
	MaskAPI.objects[this.id] = this;
}

// define the attach(oElement) function
// define the attach(oElement) function
Mask.prototype.attach = function (o){
	if (navigator.userAgent.toLowerCase().indexOf("safari") != -1) {
		//browser is safari
		$addEvent(o, "onkeydown", "return " + this.ref + ".isAllowKeyPress(event, this);", true);
		this.allowPartial = true;
		$addEvent(o, "onblur", "this.value = " + this.ref + ".format(this.value, this);", true);
	} else {
		//browser is IE
		$addEvent(o, "onkeydown", "return " + this.ref + ".isAllowKeyPress(event, this);", true);
		$addEvent(o, "onkeyup", "return " + this.ref + ".getKeyPress(event, this);", true);
		$addEvent(o, "onblur", "this.value = " + this.ref + ".format(this.value, this);", true);
	}
}

Mask.prototype.isAllowKeyPress = function (e, o){
	if( this.type != "string" ) return true;
	var xe = new qEvent(e);

	if( ((xe.keyCode > 47) && (o.value.length >= this.mask.length)) && !xe.ctrlKey ) return false;
	return true;
}

Mask.prototype.getKeyPress = function (e, o, _u){
    if (o.readOnly || o.disabled) return false;  //-- new code: Mark David Gan - Issue #17887 - 01/04/2005 --//

	this.allowPartial = true;
	var xe = new qEvent(e);

	if( (xe.keyCode > 47) || (_u == true) || (xe.keyCode == 8 || xe.keyCode == 46) ){
        var liCurrentPos = doGetCaretPosition (o)
		var v = o.value, d;
		if( xe.keyCode == 8 || xe.keyCode == 46 ) d = true;
		else d = false

		if( this.type == "number" ) this.value = this.setNumber(v, d);
		else if( this.type == "date" ) this.value = this.setDateKeyPress(v, d);
		else this.value = this.setGeneric(v, d);

		lbMod = "true"; //ante:09/01/2004 issie#15742

		o.value = this.value;
        if( this.type == "date" ){
            if (o.value.substr(liCurrentPos,1) == '/') {
                liCurrentPos = liCurrentPos + 1;
            }
            if( o.value.substr(o.value.length - 1, 1) != '/'){
                setCaretPosition(o, liCurrentPos)
            }
        }
        else{
            setCaretPosition(o, liCurrentPos)
        }

	}

	this.allowPartial = false;
	return true;
}

Mask.prototype.format = function (s, o){  //-- new code: Mark David Gan - Issue #14974 - 12/29/2004 --//
	if( this.type == "number" ) this.value = this.setNumber(s);
	else if( this.type == "date" ) this.value = this.setDate(s);
	else this.value = this.setGeneric(s);

	//ante:08/31/2004 issue#15742 - start - set hfmodified value to true.
	//if (this.value != "") {
	if (this.value != "" && lbMod == "true") {
		if (document.getElementById('hfModified')) {
            //-- new code (begin): Mark David Gan - Issue #14974 - 12/29/2004 --//
            if (o) {
                if (o.getAttribute("excludeonConfirmDiscard") != "true") {
			        document.getElementById('hfModified').value = "true";
			    }
			} else
            //-- new code (end): Mark David Gan - Issue #14974 - 12/29/2004 --//
                document.getElementById('hfModified').value = "true";
		}
	}
	//ante:08/31/2004 issue#15742 - end
	return this.value;
}

Mask.prototype.throwError = function (c, e, v){
	this.error[this.error.length] = e;
	this.errorCodes[this.errorCodes.length] = c;
	if( typeof v == "string" ) return v;
	return true;
}

Mask.prototype.setGeneric = function (_v, _d){
	var v = _v, m = this.mask;
	var r = "x#*", rt = [], nv = "", t, x, a = [], j=0, rx = {"x": "A-Za-z", "#": "0-9", "*": "A-Za-z0-9" };

	// strip out invalid characters
	v = v.replace(new RegExp("[^" + rx["*"] + "]", "gi"), "");
	if( (_d == true) && (v.length == this.strippedValue.length) ) v = v.substring(0, v.length-1);
	this.strippedValue = v;
	var b=[];
	for( var i=0; i < m.length; i++ ){
		// grab the current character
		x = m.charAt(i);
		// check to see if current character is a mask, escape commands are not a mask character
		t = (r.indexOf(x) > -1);
		// if the current character is an escape command, then grab the next character
		if( x == "!" ) x = m.charAt(i++);
		// build a regex to test against
		if( (t && !this.allowPartial) || (t && this.allowPartial && (rt.length < v.length)) ) rt[rt.length] = "[" + rx[x] + "]";
		// build mask definition table
		a[a.length] = { "chr": x, "mask": t };
	}

	var hasOneValidChar = false;
	// if the regex fails, return an error
	if( !this.allowPartial && !(new RegExp(rt.join(""))).test(v) ) return this.throwError(1, "The value \"" + _v + "\" must be in the format " + this.mask + ".", _v);
	// loop through the mask definition, and build the formatted string
	else if( (this.allowPartial && (v.length > 0)) || !this.allowPartial ){
		for( i=0; i < a.length; i++ ){
			if( a[i].mask ){
				while( v.length > 0 && !(new RegExp(rt[j])).test(v.charAt(j)) ) v = (v.length == 1) ? "" : v.substring(1);
				if( v.length > 0 ){
					nv += v.charAt(j);
					hasOneValidChar = true;
				}
				j++;
			} else nv += a[i].chr;
			if( this.allowPartial && (j > v.length) ) break;
		}
	}

	if( this.allowPartial && !hasOneValidChar ) nv = "";
	if( this.allowPartial ){
		if( nv.length < a.length ) this.nextValidChar = rx[a[nv.length].chr];
		else this.nextValidChar = null;
	}

	return nv;
}

Mask.prototype.setNumber = function(_v, _d){
	var v = String(_v).replace(/[^\d.-]*/gi, ""), m = this.mask;
	// make sure there's only one decimal point
	v = v.replace(/\./, "d").replace(/\./g, "").replace(/d/, ".");

	//-- new code (begin): Mark David Gan - Issue #17887 - 12/21/2004 --//
	v = v.replace(/^\-/, "d").replace(/\-/g, "").replace(/d/, "-");
	//-- new code (end): Mark David Gan - Issue #17887 - 12/21/2004 --//

	// check to see if an invalid mask operation has been entered
	if( !/^[\$]?((\$?[\+-]?([0#]{1,3},)*[0#]*(\.[0#]*)?)|([\+-]?\([\+-]?([0#]{1,3},)?[0#]*(\.[0#]*)?\)))$/.test(m) )
		return this.throwError(1, "An invalid mask was specified for the \nMask constructor.", _v);

	if( (_d == true) && (v.length == this.strippedValue.length) ) v = v.substring(0, v.length-1);

	if( this.allowPartial && (v.replace(/[^0-9]/, "").length == 0) ) return v;
	this.strippedValue = v;

	if( v.length == 0 ) v = NaN;
	var vn = Number(v);
	if( isNaN(vn) ) return this.throwError(2, "The value entered was not a number.", _v);

	// if no mask, stop processing
	if( m.length == 0 ) return v;

	// get the value before the decimal point
	var vi = String(Math.abs((v.indexOf(".") > -1 ) ? v.split(".")[0] : v));

	// get the value after the decimal point
	var vd = (v.indexOf(".") > -1) ? v.split(".")[1] : "";

    //-- new code (begin): Mark David Gan - Issue #17887 - 12/21/2004 --//
    var p = (m.replace(/[^#0.]*/gi, "").indexOf(".") > -1 ) ? m.replace(/[^#0.]*/gi, "").indexOf(".") : m.length;
    if (vi.replace(/[d.]*/gi, "").length > p) {
        vd = vi.replace(/[d.]*/gi, "").substring(p, vi.replace(/[d.]*/gi, "").length).concat(vd);
        vi = vi.replace(/[d.]*/gi, "").substr(0, p);
        v = vi + "." + vd;
    }
    //-- new code (end): Mark David Gan - Issue #17887 - 12/21/2004 --//

	var _vd = vd;
	//-- (Begin): Sherwin Sebarrotin - Issue #26293 - 06/21/2006 --//
	//Flag if negative sign is entered
	var lbFlag = true;

	if(v.substring(0,1) == "-"){
		lbFlag = true;
	}
	else{
		lbFlag = false;
	}



	if (vn != 0){
		// check for masking operations
		var isNegative = (Math.abs(vn)*-1 == vn);

		var show = {
			"$" : /^[\$]/.test(m),
			"(": (isNegative && (m.indexOf("(") > -1)),
			"+" : ( (m.indexOf("+") != -1) && !isNegative )
		}
		show["-"] = (isNegative && (!show["("] || (m.indexOf("-") != -1)));

	}

	else if (lbFlag){
		// check for masking operations
		var isNegative = (Math.abs(vn)*-1 == vn);

		var show = {
			"$" : /^[\$]/.test(m),
			"(": (isNegative && (m.indexOf("(") > -1)),
			"+" : ( (m.indexOf("+") != -1) && !isNegative )
		}
		show["-"] = (isNegative && (!show["("] || (m.indexOf("-") != -1)));
	}

	else if (vn == 0 && !lbFlag){
		// check for masking operations
		var isNegative = (Math.abs(vn)*-1 == vn);

		var show = {
			"$" : /^[\$]/.test(m),
			"(": (isNegative && (m.indexOf("(") > -1)),
			"+" : ( (m.indexOf("+") != -1) && !isNegative )
		}
		show[""] = (isNegative && (!show["("] || (m.indexOf("-") != -1)));
	}

	/*var isNegative = (vn != 0 && Math.abs(vn)*-1 == vn);

	// check for masking operations
	var show = {
		"$" : /^[\$]/.test(m),
		"(": (isNegative && (m.indexOf("(") > -1)),
		"+" : ( (m.indexOf("+") != -1) && !isNegative )
	}
	show["-"] = (isNegative && (!show["("] || (m.indexOf("-") != -1)));
	*/
	//-- (End): Sherwin Sebarrotin - Issue #26293 - 06/21/2006 --//


	// replace all non-place holders from the mask
	m = m.replace(/[^#0.,]*/gi, "");

	/*
		make sure there are the correct number of decimal places
	*/
	// get number of digits after decimal point in mask
	var dm = (m.indexOf(".") > -1 ) ? m.split(".")[1] : "";
	if( dm.length == 0 ){
		vi = String(Math.round(Number(vi)));
		vd = "";
	} else {
		// find the last zero, which indicates the minimum number
		// of decimal places to show
		var md = dm.lastIndexOf("0")+1;
		// if the number of decimal places is greater than the mask, then round off

		//-- old code (begin): Mark David Gan - Issue #17887 - 12/21/2004 --//
		//if( vd.length > dm.length ) vd = String(Math.round(Number(vd.substring(0, dm.length + 1))/10));
		//-- old code (end): Mark David Gan - Issue #17887 - 12/21/2004 --//

		//-- new code (begin): Mark David Gan - Issue #17887 - 12/21/2004 --//
		if( vd.length > dm.length ) vd = vd.substring(0, dm.length);
		//-- new code (end): Mark David Gan - Issue #17887 - 12/21/2004 --//

		// otherwise, pad the string w/the required zeros
		else while( vd.length < md ) vd += "0";
	}

	/*
		pad the int with any necessary zeros
	*/
	// get number of digits before decimal point in mask
	var im = (m.indexOf(".") > -1 ) ? m.split(".")[0] : m;
	im = im.replace(/[^0#]+/gi, "");
	// find the first zero, which indicates the minimum length
	// that the value must be padded w/zeros
	var mv = im.indexOf("0")+1;
	// if there is a zero found, make sure it's padded
	if( mv > 0 ){
		mv = im.length - mv + 1;
		while( vi.length < mv ) vi = "0" + vi;
	}


	/*
		check to see if we need commas in the thousands place holder
	*/
	if( /[#0]+,[#0]{3}/.test(m) ){
		// add the commas as the place holder
		var x = [], i=0, n=Number(vi);
		while( n > 999 ){
			x[i] = "00" + String(n%1000);
			x[i] = x[i].substring(x[i].length - 3);
			n = Math.floor(n/1000);
			i++;
		}
		x[i] = String(n%1000);
		vi = x.reverse().join(",");
	}


	/*
		combine the new value together
	*/
	/*if(isNaN(vi.replace(",", ""))){
		vi = 0;
	}*/
	//-- Sherwin Sebarrotin - Issue #26293 - 06/21/2006 --//
	if(vi == "NaN"){
		vi = 0;
	}

	if( (vd.length > 0 && !this.allowPartial) || ((dm.length > 0) && this.allowPartial && (v.indexOf(".") > -1) && (_vd.length >= vd.length)) ){
		v = vi + "." + vd;
	} else if( (dm.length > 0) && this.allowPartial && (v.indexOf(".") > -1) && (_vd.length < vd.length) ){
		v = vi + "." + _vd;
	} else {
		v = vi;
	}

	if( show["$"] ) v = this.mask.replace(/(^[\$])(.+)/gi, "$") + v;
	if( show["+"] ) v = "+" + v;
	if( show["-"] ) v = "-" + v;
	if( show["("] ) v = "(" + v + ")";

	return v;
}

Mask.prototype.setDate = function (_v){
	var v = _v, m = this.mask;
	var a, e, mm, dd, yy, x, s;
	// split mask into array, to see position of each day, month & year
	a = m.split(/[^mdy]+/);
	// split mask into array, to get delimiters
	s = m.split(/[mdy]+/);
	// convert the string into an array in which digits are together
	e = v.split(/[^0-9]/);

	if( s[0].length == 0 ) s.splice(0, 1);

	for( var i=0; i < a.length; i++ ){
		x = a[i].charAt(0).toLowerCase();
		if( x == "m" ) mm = parseInt(e[i], 10)-1;
		else if( x == "d" ) dd = parseInt(e[i], 10);
		else if( x == "y" ) yy = parseInt(e[i], 10);
	}

	// if year is abbreviated, guess at the year
	if( String(yy).length < 3 ){
		yy = 2000 + yy;
		if( (new Date()).getFullYear()+20 < yy ) yy = yy - 100;
	}

	// create date object
	var d = new Date(yy, mm, dd);

	if( d.getDate() != dd ) return this.throwError(1, "An invalid day was entered.", _v);
	else if( d.getMonth() != mm ) return this.throwError(2, "An invalid month was entered.", _v);

	var nv = "";

	for( i=0; i < a.length; i++ ){
		x = a[i].charAt(0).toLowerCase();
		if( x == "m" ){
			mm++;
			if( a[i].length == 2 ){
				mm = "0" + mm;
				mm = mm.substring(mm.length-2);
			}
			nv += mm;
		} else if( x == "d" ){
			if( a[i].length == 2 ){
				dd = "0" + dd;
				dd = dd.substring(dd.length-2);
			}
			nv += dd;
		} else if( x == "y" ){
			if( a[i].length == 2 ) nv += d.getYear();
			else nv += d.getFullYear();
		}

		if( i < a.length-1 ) nv += s[i];
	}

	return nv;
}

Mask.prototype.setDateKeyPress = function (_v, _d){
	var v = _v, m = this.mask, k = v.charAt(v.length-1);
	var a, e, c, ml, vl, mm = "", dd = "", yy = "", x, p, z;

	if( _d == true ){
		while( (/[^0-9]/gi).test(v.charAt(v.length-1)) ) v = v.substring(0, v.length-1);
		if( (/[^0-9]/gi).test(this.strippedValue.charAt(this.strippedValue.length-1)) ) v = v.substring(0, v.length-1);
		if( v.length == 0 ) return "";
	}

	// split mask into array, to see position of each day, month & year
	a = m.split(/[^mdy]/);
	// split mask into array, to get delimiters
	s = m.split(/[mdy]+/);
	// mozilla wants to add an empty array element which needs removed
	if( s[0].length == 0 ) {
		s.splice(0,1);
	}

	// convert the string into an array in which digits are together
	e = v.split(/[^0-9]/);
	//if (e[e.length-1] == "") e.splice(e.length-1,1)

	if (e.length == 0) return ""
	e = (e[e.length-1].length == 0) ? e.splice(0,e.length-1) : e;

	// position in mask

	//alert(e.length)
	p = (e.length > 0) ? (e[e.length-1].length == 0 ? e.length-1 : e.length-1 ) : 0;

	// determine what mask value the user is currently entering
	c = a[p].charAt(0);

	// determine the length of the current mask value
	ml = a[p].length;

	for( var i=0; i < e.length; i++ ){
		x = a[i].charAt(0).toLowerCase();
		if( x == "m" ) mm = parseInt(e[i], 10)-1;
		else if( x == "d" ) dd = parseInt(e[i], 10);
		else if( x == "y" ) yy = parseInt(e[i], 10);
	}

	var nv = "";
	var j=0;

	for( i=0; i < e.length; i++ ){
		x = a[i].charAt(0).toLowerCase();
		if( x == "m" ){
			z = ((/[^0-9]/).test(k) && c == "m");
			mm++;

			if( (e[i].length == 2 && mm < 10) || (a[i].length == 2 && c != "m") || (mm > 1 && c == "m") || (z && a[i].length == 2) ){
				mm = "0" + mm;
				mm = mm.substring(mm.length-2);
			}
			vl = String(mm).length;
			ml = 2;
			nv += mm;
		} else if( x == "d" ){
			z = ((/[^0-9]/).test(k) && c == "d");
			if( (e[i].length == 2 && dd < 10) || (a[i].length == 2 && c != "d") || (dd > 3 && c == "d") || (z && a[i].length == 2) ){
				if (dd != "NaN") {
					dd = "0" + dd;
					dd = dd.substring(dd.length-2);
				}
			}

			vl = String(dd).length;
			ml = 2;

			nv += dd;
		} else if( x == "y" ){
			z = ((/[^0-9]/).test(k) && c == "y");
			if( c == "y" ) yy = String(yy);
			else {
				if( a[i].length == 2 ) yy = d.getYear();
				else yy = d.getFullYear();
			}
			if( (e[i].length == 2 && yy < 10) || (a[i].length == 2 && c != "y") || (z && a[i].length == 2) ){
				yy = "0" + yy;
				yy = yy.substring(yy.length-2);
			}
			ml = a[i].length;
			vl = String(yy).length;
			nv += yy;
		}

		if( ((ml == vl || z) && (x == c) && (i < s.length)) || (i < s.length && x != c ) ) nv += s[i];
	}

	//alert("nv =    "+ nv)

	if( nv.length > m.length ) nv = nv.substring(0, m.length);
	this.strippedValue = (nv == "NaN") ? "" : nv;
	this.strippedValue = (nv == "aN") ? "" : nv;
	this.strippedValue = ((this.strippedValue).indexOf("NaN") >= 0) ? this.strippedValue.substring(0,(this.strippedValue).indexOf("NaN")) : this.strippedValue;

	this.strippedValue = ((this.strippedValue).indexOf("aN") >= 0) ? this.strippedValue.substring(0,(this.strippedValue).indexOf("aN")) : this.strippedValue;
	return this.strippedValue;
}

function qEvent(e){
	// routine for NS, Opera, etc DOM browsers
	if( window.Event ){
		var isKeyPress = (e.type.substring(0,3) == "key");

		this.keyCode = (isKeyPress) ? parseInt(e.which, 10) : 0;
		this.button = (!isKeyPress) ? parseInt(e.which, 10) : 0;
		this.srcElement = e.target;
		this.type = e.type;
		this.x = e.pageX;
		this.y = e.pageY;
		this.screenX = e.screenX;
		this.screenY = e.screenY;
		if( document.layers ){
			this.altKey = ((e.modifiers & Event.ALT_MASK) > 0);
			this.ctrlKey = ((e.modifiers & Event.CONTROL_MASK) > 0);
			this.shiftKey = ((e.modifiers & Event.SHIFT_MASK) > 0);
			this.keyCode = this.translateKeyCode(this.keyCode);
		} else {
			this.altKey = e.altKey;
			this.ctrlKey = e.ctrlKey;
			this.shiftKey = e.shiftKey;
		}
	// routine for Internet Explorer DOM browsers
	} else {
		e = window.event;
		this.keyCode = parseInt(e.keyCode, 10);
		this.button = e.button;
		this.srcElement = e.srcElement;
		this.type = e.type;
		if( document.all ){
			this.x = e.clientX + document.body.scrollLeft;
			this.y = e.clientY + document.body.scrollTop;
		} else {
			this.x = e.clientX;
			this.y = e.clientY;
		}
		this.screenX = e.screenX;
		this.screenY = e.screenY;
		this.altKey = e.altKey;
		this.ctrlKey = e.ctrlKey;
		this.shiftKey = e.shiftKey;
	}
	if( this.button == 0 ){
		this.setKeyPressed(this.keyCode);
		this.keyChar = String.fromCharCode(this.keyCode);
	}
}

// this method will try to remap the keycodes so the keycode value
// returned will be consistent. this doesn't work for all cases,
// since some browsers don't always return a unique value for a
// key press.
qEvent.prototype.translateKeyCode = function (i){
	var l = {};
	// remap NS4 keycodes to IE/W3C keycodes
	if( !!document.layers ){
		if( this.keyCode > 96 && this.keyCode < 123 ) return this.keyCode - 32;
		l = {
			96:192,126:192,33:49,64:50,35:51,36:52,37:53,94:54,38:55,42:56,40:57,41:48,92:220,124:220,125:221,
			93:221,91:219,123:219,39:222,34:222,47:191,63:191,46:190,62:190,44:188,60:188,45:189,95:189,43:187,
			61:187,59:186,58:186,
			"null": null
		}
	}
	return (!!l[i]) ? l[i] : i;
}

// try to determine the actual value of the key pressed
qEvent.prototype.setKP = function (i, s){
	this.keyPressedCode = i;
	this.keyNonChar = (typeof s == "string");
	this.keyPressed = (this.keyNonChar) ? s : String.fromCharCode(i);
	this.isNumeric = (parseInt(this.keyPressed, 10) == this.keyPressed);
	this.isAlpha = ((this.keyCode > 64 && this.keyCode < 91) && !this.altKey && !this.ctrlKey);
	return true;
}

// try to determine the actual value of the key pressed
qEvent.prototype.setKeyPressed = function (i){
	var b = this.shiftKey;
	if( !b && (i > 64 && i < 91) ) return this.setKP(i + 32);
	if( i > 95 && i < 106 ) return this.setKP(i - 48);

	switch( i ){
		case 49: case 51: case 52: case 53: if( b ) i = i - 16; break;
		case 50: if( b ) i = 64; break;
		case 54: if( b ) i = 94; break;
		case 55: if( b ) i = 38; break;
		case 56: if( b ) i = 42; break;
		case 57: if( b ) i = 40; break;
		case 48: if( b ) i = 41; break;
		case 192: if( b ) i = 126; else i = 96; break;
		case 189: if( b ) i = 95; else i = 45; break;
		case 187: if( b ) i = 43; else i = 61; break;
		case 220: if( b ) i = 124; else i = 92; break;
		case 221: if( b ) i = 125; else i = 93; break;
		case 219: if( b ) i = 123; else i = 91; break;
		case 222: if( b ) i = 34; else i = 39; break;
		case 186: if( b ) i = 58; else i = 59; break;
		case 191: if( b ) i = 63; else i = 47; break;
		case 190: if( b ) i = 62; else i = 46; break;
		case 188: if( b ) i = 60; else i = 44; break;

		case 106: case 57379: i = 42; break;
		case 107: case 57380: i = 43; break;
		case 109: case 57381: i = 45; break;
		case 110: i = 46; break;
		case 111: case 57378: i = 47; break;

		case 8: return this.setKP(i, "[backspace]");
		case 9: return this.setKP(i, "[tab]");
		case 13: return this.setKP(i, "[enter]");
		case 16: case 57389: return this.setKP(i, "[shift]");
		case 17: case 57390: return this.setKP(i, "[ctrl]");
		case 18: case 57388: return this.setKP(i, "[alt]");
		case 19: case 57402: return this.setKP(i, "[break]");
		case 20: return this.setKP(i, "[capslock]");
		case 32: return this.setKP(i, "[space]");
		case 91: return this.setKP(i, "[windows]");
		case 93: return this.setKP(i, "[properties]");

		case 33: case 57371: return this.setKP(i*-1, "[pgup]");
		case 34: case 57372: return this.setKP(i*-1, "[pgdown]");
		case 35: case 57370: return this.setKP(i*-1, "[end]");
		case 36: case 57369: return this.setKP(i*-1, "[home]");
		case 37: case 57375: return this.setKP(i*-1, "[left]");
		case 38: case 57373: return this.setKP(i*-1, "[up]");
		case 39: case 57376: return this.setKP(i*-1, "[right]");
		case 40: case 57374: return this.setKP(i*-1, "[down]");
		case 45: case 57382: return this.setKP(i*-1, "[insert]");
		case 46: case 57383: return this.setKP(i*-1, "[delete]");
		case 144: case 57400: return this.setKP(i*-1, "[numlock]");
	}

	if( i > 111 && i < 124 ) return this.setKP(i*-1, "[f" + (i-111) + "]");

	return this.setKP(i);
}

// define the addEvent(oElement, sEvent, sCmd, bAppend) function
function $addEvent(o, _e, c, _b){
	var e = _e.toLowerCase(), b = (typeof _b == "boolean") ? _b : true, x = (o[e]) ? o[e].toString() : "";
	// strip out the body of the function
	x = x.substring(x.indexOf("{")+1, x.lastIndexOf("}"));
	x = ((b) ? (x + c) : (c + x)) + "\n";
	return o[e] = (!!window.Event) ? new Function("event", x) : new Function(x);
}
//Mariceld issue20978 07.20.2005 [end]

//rfigueroa set caret position [start]
function setCaretPosition(ctrl, pos)
{

    if(ctrl.setSelectionRange)
    {
        ctrl.focus();
        ctrl.setSelectionRange(pos,pos);
    }
    else if (ctrl.createTextRange) {
        var range = ctrl.createTextRange();
        range.collapse(true);
        range.moveEnd('character', pos);
        range.moveStart('character', pos);
        range.select();
    }
}

function doGetCaretPosition (ctrl) {

    var CaretPos = 0;
    // IE Support
    if (document.selection) {

        ctrl.focus ();
        var Sel = document.selection.createRange ();

        Sel.moveStart ('character', -ctrl.value.length);

        CaretPos = Sel.text.length;
    }
    // Firefox support
    else if (ctrl.selectionStart || ctrl.selectionStart == '0')
        CaretPos = ctrl.selectionStart;

    return (CaretPos);

}
//rfigueroa set caret position [end]

function ufGenRepSessionID(){
    var reportid = Math.floor(Math.random()*100000000);

    if (reportid < 1){
        reportid = ufGenRepSessionID();
    }

    return reportid;
}

