var mstrMyAnnotation;

var STR_PAD_LEFT = 1;
var STR_PAD_RIGHT = 2;
var STR_PAD_BOTH = 3;

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
String.prototype.pad = function(len, pad, dir) {
	var str = this;
	
	if (typeof(len) == "undefined") { var len = 0; }
	if (typeof(pad) == "undefined") { var pad = ' '; }
	if (typeof(dir) == "undefined") { var dir = STR_PAD_RIGHT; }
 
	if (len + 1 >= str.length) { 
		switch (dir){
			case STR_PAD_LEFT:
				str = Array(len + 1 - str.length).join(pad) + str;
			break;
 
			case STR_PAD_BOTH:
				var right = Math.ceil((padlen = len - str.length) / 2);
				var left = padlen - right;
				str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
			break;
 
			default:
				str = str + Array(len + 1 - str.length).join(pad);
			break; 
		} // switch
	}
	return str;
}
function formatCurrency(num, nocents) {
	if (typeof(nocents) == "undefined") { var nocents = false; }

	num = num.toString().replace(/\$|\,/g,'');
	
	if(isNaN(num))
		num = "0";

	sign = (num == (num = Math.abs(num)));
	
	num = Math.floor(num*100+0.50000000001);
	
	cents = num%100;
	
	num = Math.floor(num/100).toString();
	
	if(cents<10)
		cents = "0" + cents;
		
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+

	num.substring(num.length-(4*i+3));

	if (nocents == true)
		return (((sign)?'':'-') + '$' + num);
	
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}
function getRadioIndex(objRadio) {
	for (var intIndex = 0; intIndex < objRadio.length; intIndex++) {
		if (objRadio[intIndex].checked)
			return intIndex;
	}
	return null;
}
function getRadioValue(objRadio) {
	if (typeof objRadio.value != 'undefined')
		return objRadio.value;
		
	for (var intCounter = 0; intCounter < objRadio.length; intCounter++) {
		if (objRadio[intCounter].checked)
			return objRadio[intCounter].value;
	}
	return null;
}
function isNumeric(InString) {
	RefString     = "-1234567890.";
	DecimalPoints = 0;
	
	for (i=0; i<InString.length; i++) {
		TempChar = InString.substring ( i, i+1 );
		
		/* Can only have zero or one decimal points in a number */
		if (  TempChar == "." )
			DecimalPoints++;

		/* Minus Sign must be first character */
		if (( TempChar == "-" ) && ( i != 0 ))
			return ( false );
		
		/* Check if current character is valid */
		if ( RefString.indexOf (TempChar,0) == -1)
			return (false);
	}

	if ( DecimalPoints > 1 ) 
		return ( false );

	return(true);
}
function payment(PV, IR, NP) {
	/************************************************************************************ 
	Payment() function
	
	http://www.informit.com/isapi/product_id~{098DC7D4-2000-4E4C-A41E-1B862CB3C4F9}/st~{5A2F85EB-56A8-4246-AAA7-5EB25B72F02B}/content/index.asp
	FV  - The future value of an investment
	IR  - The interest rate for an investment or loan
	NP  - The number of periods in an investment or loan
	PMT - The regular payment into an investment or loan
	PV  - The present value of an investment or loan
	************************************************************************************/
 	var PMT = (PV * IR) / (1 - Math.pow(1 + IR, -NP));
  	return roundDecimals(PMT, 2);
}
function solveToTerm(PV, IR, PMT) {
	return Term = -Math.log((-(PV * IR ) / PMT) + 1) / Math.log(1 + IR);
}
function roundDecimals(original_number, decimals) {
  	var result1 = original_number * Math.pow(10, decimals)
  	var result2 = Math.round(result1)
  	var result3 = result2 / Math.pow(10, decimals)

  	return (result3)
}
function dateAdd( start, interval, number ) {
	/************************************************************************************ 
	DateAdd() function
	
	http://www.flws.com.au/showusyourcode/codeLib/code/js_dateAdd.asp?catID=2
	************************************************************************************/

    // Create 3 error messages, 1 for each argument. 
    var startMsg = "Sorry the start parameter of the dateAdd function\n"
        startMsg += "must be a valid date format.\n\n"
        startMsg += "Please try again." ;
		
    var intervalMsg = "Sorry the dateAdd function only accepts\n"
        intervalMsg += "d, h, m OR s intervals.\n\n"
        intervalMsg += "Please try again." ;

    var numberMsg = "Sorry the number parameter of the dateAdd function\n"
        numberMsg += "must be numeric.\n\n"
        numberMsg += "Please try again." ;
		
    // get the milliseconds for this Date object. 
    var buffer = Date.parse( start ) ;
	
    // check that the start parameter is a valid Date. 
    if ( isNaN (buffer) ) {
        alert( startMsg ) ;
        return null ;
    }
	
    // check that an interval parameter was not numeric. 
    if ( interval.charAt == 'undefined' ) {
        // the user specified an incorrect interval, handle the error. 
        alert( intervalMsg ) ;
        return null ;
    }

    // check that the number parameter is numeric. 
    if ( isNaN ( number ) )	{
        alert( numberMsg ) ;
        return null ;
    }

    // so far, so good...
    // what kind of add to do? 
    switch (interval.charAt(0))
    {
        case 'd': case 'D': 
            number *= 24 ; // days to hours 
            // fall through! 
        case 'h': case 'H':
            number *= 60 ; // hours to minutes
            // fall through! 
        case 'm': case 'M':
            number *= 60 ; // minutes to seconds
            // fall through! 
        case 's': case 'S':
            number *= 1000 ; // seconds to milliseconds
            break ;
        default:
        // If we get to here then the interval parameter
        // didn't meet the d,h,m,s criteria.  Handle
        // the error. 		
        alert(intervalMsg) ;
        return null ;
    }
    return new Date( buffer + number ) ;
}
function dateDiff( start, end, interval, wholedays ) {
	/************************************************************************************ 
	DateDiff() function
	
	http://www.flws.com.au/showusyourcode/codeLib/code/js_dateDiff.asp?catID=2
	************************************************************************************/

    var iOut = 0;
    
    // Create 2 error messages, 1 for each argument. 
    var startMsg = "Check the Start Date and End Date\n"
        startMsg += "must be a valid date format.\n\n"
        startMsg += "Please try again." ;
		
    var intervalMsg = "Sorry the dateAdd function only accepts\n"
        intervalMsg += "d, h, m OR s intervals.\n\n"
        intervalMsg += "Please try again." ;

    var bufferA = Date.parse( start ) ;
    var bufferB = Date.parse( end ) ;
    	
    // check that the start parameter is a valid Date. 
    if ( isNaN (bufferA) || isNaN (bufferB) ) {
        alert( startMsg ) ;
        return null ;
    }
	
    // check that an interval parameter was not numeric. 
    if ( interval.charAt == 'undefined' ) {
        // the user specified an incorrect interval, handle the error. 
        alert( intervalMsg ) ;
        return null ;
    }
    
    var number = bufferB-bufferA ;
    
    // what kind of add to do? 
    switch (interval.charAt(0))
    {
        case 'd': case 'D': 
            iOut = parseInt(number / 86400000) ;
            if(wholedays) iOut += parseInt((number % 86400000)/43200001) ;
            break ;
        case 'h': case 'H':
            iOut = parseInt(number / 3600000 ) ;
            if(wholedays) iOut += parseInt((number % 3600000)/1800001) ;
            break ;
        case 'm': case 'M':
            iOut = parseInt(number / 60000 ) ;
            if(wholedays) iOut += parseInt((number % 60000)/30001) ;
            break ;
        case 's': case 'S':
            iOut = parseInt(number / 1000 ) ;
            if(wholedays) iOut += parseInt((number % 1000)/501) ;
            break ;
        default:
        // If we get to here then the interval parameter
        // didn't meet the d,h,m,s criteria.  Handle
        // the error. 		
        alert(intervalMsg) ;
        return null ;
    }
    
    return iOut ;
}

function getEventObject(evt) {
	evt = getEvent(evt);
	if (evt)
		return (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
}
function getEvent(evt) {
	return (evt) ? evt : ((event) ? event : null);
}
function getElement(ID) {
	if (document.getElementById)
		return document.getElementById(ID);
	else if (document.all)
		return document.all(ID);
}
function getObjectLeft(obj) {
	var result = 0;
	
	if (document.defaultView) {
		var style = document.defaultView;
		var cssDec1 = style.getComputedStyle(obj, '');
		result = cssDec1.getPropertyValue('left');
	} else if (obj.currentStyle) {
		result = obj.currentStyle.left;
	} else if (obj.style) {
		result = obj.style.left;
	} 
	return parseInt(result);
}
function getObjectTop(obj) {
	var result = 0;
	if (document.defaultView) {
		var style = document.defaultView;
		var cssDec1 = style.getComputedStyle(obj, '');
		result = cssDec1.getPropertyValue('top');
	} else if (obj.currentStyle) {
		result = obj.currentStyle.top;
	} else if (obj.style) {
		result = obj.style.top;
	}
	return parseInt(result);
}
function getObjectWidth(obj) {
	var result = 0;
	if (obj.offsetWidth) {
		if (obj.scrollWidth && (obj.offsetWidth != obj.scrollWidth)) {
			result = obj.scrollWidth;
		} else {
			result = obj.offsetWidth;
		}
	} else if (obj.clip && obj.clip.width) {
		result = obj.clip.width;
	} else if (obj.style && obj.style.pixelWidth) {
		result = obj.style.pixelWidth;
	}
	return parseInt(result);
}
function getObjectHeight(obj) {
	var result = 0;
	if (obj.offsetHeight) {
		result = obj.offsetHeight;
	} else if (obj.clip && obj.clip.height) {
		result = obj.clip.height;
	} else if (obj.style && obj.style.pixelHeight) {
		result = obj.style.pixelHeight;
	}
	return parseInt(result);
}

function validateField(field, type, doalert, autoplace, minval, maxval, mandatory) {
	/*
	validateField obtained from NL...
	
	Possible values for 'type'...
    type =="url"
	type == "currency" || type == "currency2" || type == "poscurrency"
    type == "date"
    type == "mmyydate"
    type == "ccexpdate"
    type == "ccnumber"
    type == "rate"
    type == "integer" || type == "posinteger" || type == "float" || type == "posfloat" || type == "pct"
    type == "address"
    type == "time" || type == "timetrack"
    type == "timeofday"
    type == "visiblepassword"
    type == "email"
    type == "emails"
    type == "printerOffset"
    type == "metricPrinterOffset"
    type == "phone"  || type == "fullphone"
    type == "color"
    type == "identifier"
	*/
	type = type.toLowerCase();
    if (field.value == null || field.value.length == 0) {
		if (mandatory == true) {
		    if (doalert) alert("Field must contain a value.");
		    field.focus();
		    field.select();
			window.isvalid = false;
			return false;
		}
		else {
		    window.isvalid = true;
		    return true;
		}
    }
    var validflag = true;
    if (type =="url") {
		var val = field.value;
		if ( val.indexOf('http://') == -1 && val.indexOf('https://') == -1)	{
            if (doalert)
				alert("Invalid url. Url must start with http:// or https://");
            validflag = false;
		}
	}
	else if (type == "currency" || type == "currency2" || type == "poscurrency") {
		if (maxval == null)
			maxval = 1.0e+10;
			
        var val = field.value.replace(/\$/g,"");
        val = val.replace(/\ /g,"");
		val = val.replace(/,/g,"");
        val = val.toLowerCase();
        if(val.charAt(0) == '=') val = val.substr(1);
        if (val.substr(1).search(/[\+\-\*\/]/g) != -1) {
            var c = val.charAt(0);
            if(val.charAt(0) >='a' && val.charAt(0) <='z') {
                value = "error";
            }
            else {
		        try {
		        	val = eval(val);
		        } 
				catch (e) { val = "error"; }
                autoplace = false;
            }
        }
        numval = parseFloat(val);
        if (isNaN(numval) || Math.abs(numval)>maxval) {
            if (doalert) 
				alert("Invalid currency value. Values must be numbers up to " + maxval);
            validflag = false;
        }
        else if (type == "poscurrency" && numval < 0) {
            if (doalert) alert("Invalid currency value. Value can not be negative.");
            validflag = false;
        }
        else {
            if(autoplace && val.indexOf(".") == -1) numval/=100;
            if(type == "currency" || type == "poscurrency")
                field.value = formatCurrency2(numval);
            else
                field.value = formatCurrency2(numval, true);
           validflag = true;
        }
    }
    else if (type == "date") {
        validflag = true;
        var m=0,d=0,y=0,val=field.value;
        var fmterr;
        var year="";
        var custrange=false;
		if (! (isNaN(Date.parse(minval)) || isNaN(Date.parse(maxval)))) {
          custrange=true;
		  var d1 = new Date(Date.parse(minval));
		  var d2 = new Date(Date.parse(maxval));
		}
        if(!window.dateformat)
            window.dateformat = "MM/DD/YYYY";   

        if(window.dateformat == "MM/DD/YYYY") {
            if (val.indexOf("/") != -1) {
                var c = val.split("/");
                if(onlydigits(c[0])) m = parseInt(c[0],10);
                if(onlydigits(c[1])) d = parseInt(c[1],10);
                if(onlydigits(c[2])) y = parseInt(c[2],10);
                year=c[2];
            }
            else {
                var l = val.length, str;
                str = val.substr(0,2-l%2); if(onlydigits(str)) m = parseInt(str,10);
                str = val.substr(2-l%2,2); if(onlydigits(str)) d = parseInt(str,10);
                str = val.substr(4-l%2);   if(onlydigits(str)) y = parseInt(str,10);
                year=str;
            }
            fmterr = "MM/DD/YY, MM/DD/YYYY, MMDDYY or MMDDYYYY";
        }
        else if(window.dateformat == "DD.MM.YYYY") {
            if (val.indexOf(".") != -1) {
                var c = val.split(".");
                if(onlydigits(c[0])) d = parseInt(c[0],10);
                if(onlydigits(c[1])) m = parseInt(c[1],10);
                if(onlydigits(c[2])) y = parseInt(c[2],10);
                year=c[2];
            }
            else {
                var l = val.length, str;
                str = val.substr(0,2-l%2); if(onlydigits(str)) d = parseInt(str,10);
                str = val.substr(2-l%2,2); if(onlydigits(str)) m = parseInt(str,10);
                str = val.substr(4-l%2);   if(onlydigits(str)) y = parseInt(str,10);
                year=parseInt(str,10);
            }
            fmterr = "DD.MM.YY, DD.MM.YYYY, DDMMYY or DDMMYYYY";
        }
        else if(window.dateformat == "DD-Mon-YYYY") {
            var ms = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";
            if (val.indexOf("-") != -1) {
                var c = val.split("-");
                if(onlydigits(c[0])) d = parseInt(c[0],10);
                m = (ms.indexOf(c[1].toUpperCase())+3)/3;
                if(onlydigits(c[2])) y = parseInt(c[2],10);
                year=c[2];
            }
            else {
                var l = val.length, str;
                str = val.substr(0,1+l%2); if(onlydigits(str)) d = parseInt(str,10);
                str = val.substr(1+l%2,3); if (ms.indexOf(str.toUpperCase()) >= 0) m = (ms.indexOf(str.toUpperCase())+3)/3;
                str = val.substr(4+l%2);   if(onlydigits(str)) y = parseInt(str,10);
                year=str;
            }
            fmterr = "DD-Mon-YY, DD-Mon-YYYY, DDMonYY or DDMonYYYY";
        }

        if(m==0 || d==0) {
            if (doalert) alert("Invalid date value (must be "+fmterr+")");
            validflag = false;
        }
        else {
			if (y==0 && !onlydigits(year)) y = (new Date()).getYear();  
			if(m<1) m=1; else if(m>12) m=12;
			if(d<1) d=1; else if(d>31) d=31;
			if(y<100) y+=((y>=70)?1900:2000);
			if(y<1000) y*=10;
			if (y > 9999) y = (new Date()).getYear();

			var dt = new Date(y, m-1, d);
			
	        if (custrange && (dt < d1 || dt > d2)) {
				if (doalert) alert("Date must be between " + minval + " and " + maxval); 
	            validflag = false;
			}
			else field.value = getdatestring(dt);
		}
    }
    else if (type == "mmyydate") {
        var month;
        var day = 0;
        var year;
        var fmterr = "MMYY, MMYYYY, MM/DD/YY, MM/DD/YYYY";

        if(window.dateformat == "DD-Mon-YYYY" && field.value.indexOf("/") == -1 && !onlydigits(field.value)) {
            var ms = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";
            var val = field.value;
            if (val.indexOf("-") != -1) {
                var c = val.split("-");
                month = (ms.indexOf(c[0].toUpperCase())+3)/3;
                year=parseInt(c[1],10);
            }
            else {
                var l = val.length, str;
                str = val.substr(0,3); if (ms.indexOf(str.toUpperCase()) >= 0) month = (ms.indexOf(str.toUpperCase())+3)/3;
                str = val.substr(3);
                year=parseInt(str,10);
            }
            fmterr = "Mon-YY, Mon-YYYY, MonYY or MonYYYY";
        }
        else {
			if (field.value.indexOf("/") == -1) {
				var l = field.value.length;
				month = parseInt(field.value.substr(0,2-l%2),10);
				year = parseInt(field.value.substr(2-l%2),10);
			}
			else {
				var comps = field.value.split("/");
				month = parseInt(comps[0],10);
				if (comps[2] != null) {
					day  = parseInt(comps[1],10);
					year = parseInt(comps[2],10);
				}
				else
					year = parseInt(comps[1],10);
			}
		}
        if (month >= 1 && month <= 12 && ((year >= 0 && year < 100) || (year > 1900 && year <2100))) {
            if (year < 50)
                year += 2000;
            else if (year < 100)
                year += 1900;
            if (day == 0 || day > 31) {
                if (month == 2) {
                    if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
                        day = 29;
                    else
                        day = 28;
                }
                else if (month == 4 || month == 6 || month == 9 || month == 11)
                    day = 30;
                else
                    day = 31;
            }
            field.value = getmmyydatestring(new Date(year, month-1, day));
            validflag = true;
        }
        else {
            if (doalert) alert("Invalid date value (must be "+fmterr+")");
            validflag = false;
        }
    }
    else if (type == "ccexpdate") {
        validflag = true;
        var m=0, y=0;
        if(field.value.indexOf('/') != -1) {
            var dToday = new Date();
            var Y = dToday.getYear();
            var M = dToday.getMonth() + 1;
            if(Y <= 999) Y += 1900;         

            var c = field.value.split('/');
            if(onlydigits(c[0])) m = parseInt(c[0],10);
            if(onlydigits(c[1])) y = parseInt(c[1],10);

            if(m<1) m=1; else if(m>12) m=12;
            if(y<100) y+=((y>=70)?1900:2000);

            if(y<Y || (y==Y && m<M)) {
                if (doalert) alert("Notice: The credit card appears to be incorrect");
            }
            field.value = (m<10?'0':'')+m+'/'+y;
        }
        else {
            if (doalert) alert("Please enter an expiration date int MM/YYYY format");
            validflag = false;
        }
    }
    else if (type == "ccnumber")  {
        validflag = checkccnumber(field);
    }
    else if (type == "rate") {
        var numval;
        var minclip=-10000000;
        var maxclip=10000000;

        var val = field.value;
        val = val.replace(/,/g,"");
        var pctidx = val.lastIndexOf("%");
        if (pctidx!=-1)
            val = val.substr(0,pctidx);

        numval = parseFloat(val);
        if (isNaN(numval)) {
            if (doalert) alert("Invalid number or percentage");
            validflag = false;
        }
        else if  (numval >= maxclip) {
            if (doalert) alert("Number exceeds maximum value");
            validflag = false;
        }
        else if  (numval <= minclip) {
            if (doalert) alert("Number is less than minimum value");
            validflag = false;
        }
        else {
            field.value = format_rate(numval,pctidx!=-1);
            validflag = true;
        }
    }
    else if (type == "integer" || type == "posinteger" || type == "float" || type == "posfloat" || type == "pct") {
        var numval;
        var custrange=false;
        if ((minval != null && maxval != null) || type == "pct")
          custrange=true;
        var minclip= minval == null ? (type == "pct" ? 0 : -Math.pow(2,32)) : minval;
        var maxclip = maxval == null ?(type == "pct" ? 100 : Math.pow(2,64)) : maxval;
        var val = field.value;
        val = val.replace(/,/g,"");
        val = val.replace(/%/g,"");

        if (type == "integer")
            numval = parseInt(val,10);
        else if (type == "posinteger") {
            numval = parseInt(val,10);
            minclip=0;
        }
        else if (type == "posfloat") {
            numval = parseFloat(val);
            minclip=0;
        }
        else
            numval = parseFloat(val);
		
        if (isNaN(numval) || (custrange && (numval > maxclip || numval < minclip)) || (!custrange && (numval >= maxclip || numval <= minclip))) {
			if (doalert) {
			  	if (type == "pct") {
					alert("Invalid percentage (must be between 0 and 100)");
			  	}
			    else if (custrange == true) {
		        	if (minval == null)
						alert("Invalid number (must be less than "+maxclip+")");
			  		else if (maxval == null)
		        		alert("Invalid number (must be greater than "+minclip+")");
		      		else
		      			alert("Invalid number (must be between "+minclip+" and "+maxclip+")");
		    	}
		    	else if (type=="posinteger" || type=="posfloat")
		        	alert("Invalid number (must be positive)");
		    	else if (type=="integer" || type=="float") {
		        	if (isNaN(numval))
		            	alert('You may only enter numbers into this field');
		        	else
		            	alert("Illegal number: " + numval);
		    	}
		    	else
		        	alert("Invalid number (must be greater than -4.29B");
		  	}
			validflag = false;
		}
		else {
			if (type == "pct") {
	            if (numval == Math.floor(numval))
	                field.value = numval + ".0%";
	            else
	                field.value = numval + "%";
	        }
	    else
	    	field.value = numval;
	    	validflag = true;
		}
    }
    else if (type == "address")
    {
        var err = '';
        if (field.value.length>999) {
            err = "Address too long (truncated at 1000 characters)";
            newval = field.value.substr(0,999);
        }
        if (err != '') {
            if (doalert) alert(err);
            field.value = newval;
        }
    }
    else if (type == "time" || type == "timetrack") {
        var hours;
        var minutes;

        var re = /([0-9][0-9]?)?(:[0-5][0-9])?/
        var result = re.exec(field.value)
        if (result==null || result.index > 0 || result[0].length != field.value.length) {
            timeval = parseFloat(field.value);
            if (isNaN(timeval))
                hours = -1;
            else {
                hours = Math.floor(timeval);
                minutes = Math.floor((timeval-hours)*60+0.5);
            }
        }
        else {
            if (RegExp.$1.length > 0)
                hours = parseInt(RegExp.$1,10);
            else
                hours = 0;
            if (typeof(RegExp.$2) != "undefined" && RegExp.$2.length > 0)
                minutes = parseInt(RegExp.$2.substr(1),10);
            else
                minutes = 0;
        }
        if (hours >= 0 && minutes >= 0 && minutes < 60) {
            field.value = hours + ":" + (minutes < 10 ? "0" : "") + minutes;
            validflag = true;
        }
        else {
            if (doalert) alert("Invalid time value (must be HH:MI)");
            validflag = false;
        }
    }
    else if (type == "timeofday") {
        var hours;
        var minutes;
        var amorpm;

        var re;
        var re = /([0-9][0-9]?)(:[0-5][0-9])\s?([AaPp])?[Mm]?/
        var result = re.exec(field.value)
        if (result==null || result.index > 0 || result[0].length != field.value.length)
            hours = -1;
        else {
            if (RegExp.$1.length > 0)
                hours = parseInt(RegExp.$1,10);
            else
                hours = -1;
            if (typeof(RegExp.$2) != "undefined" && RegExp.$2.length > 0)
                minutes = parseInt(RegExp.$2.substr(1),10);
            else
                minutes = -1;
            amorpm = (RegExp.$3.length == 0 || RegExp.$3 == 'a' || RegExp.$3 == 'A') ? "" : "pm";
        }
        if (hours > 0 && hours <=12 && minutes >= 0 && minutes < 60) {
			if (amorpm == "") amorpm = "am";
            field.value = hours + ":" + (minutes < 10 ? "0" : "") + minutes + " " + amorpm;
            validflag = true;
        }
        else if (hours > 12 && hours <= 25 && minutes >= 0 && minutes < 60 && amorpm == "") {
			amorpm = "pm";
			hours -= 12;
            field.value = hours + ":" + (minutes < 10 ? "0" : "") + minutes + " " + amorpm;
        }
        else {
            if (doalert) alert("Enter the time of day as HH:MI or HH:MI AM/PM. You can enter hours from 1 to 12 and minutes from 0 to 59.");
            validflag = false;
        }
    }
    else if (type == "visiblepassword") {
        if (checkpassword(field, field, doalert))
            validflag = true;
        else
            validflag = false;
    }
    else if (type == "email") {
        if (checkemail(field, true, doalert))
            validflag = true;
        else
            validflag = false;
    }
    else if (type == "emails") {
        var bademail;
        var emails1 = field.value.split(',');
        for (var i=0; i<emails1.length; i++)
        {
            if (validflag && !isValEmpty(emails1[i]))
            {
				var emails = emails1[i].split(';');
				for (var j=0; j<emails.length; j++)
				{
					if (validflag && !isValEmpty(emails[j]))
					{
						var semail = emails[j].replace(/ /gi,'');
						validflag = checkemailvalue(semail, false);
						if (!validflag)
							 bademail = emails[j];
					}
				}
            }
        }
        if (!validflag)
            if (doalert) alert("Invalid email found:"+bademail);
    }
    else if (type == "printerOffset") {
        var maxclip =  2.0;
        var minclip = -2.0;
        var val = field.value;
        val = val.replace(/,/g,"");

        numval = parseFloat(val);
        if (isNaN(numval) || numval >= maxclip || numval <= minclip) {
			if (doalert) {
				if (numval >= maxclip)
					alert("Invalid number (must be lower than " + maxclip + ").");
				else if (numval <= minclip)
					alert("Invalid number (must be greater than " + minclip + ").");
				else
					alert("Illegal number: " + numval);
				}
			validflag = false;
		}
		else {
			validflag = true;
		}
    }
    else if (type == "metricPrinterOffset") {
        var maxclip =  50.0;
        var minclip = -50.0;
        var val = field.value;
        val = val.replace(/,/g,"");

        numval = parseFloat(val);
        if (isNaN(numval) || numval >= maxclip || numval <= minclip) {
			if (doalert) {
				if (numval >= maxclip)
					alert("Invalid number (must be lower than " + maxclip + ").");
				else if (numval <= minclip)
					alert("Invalid number (must be greater than " + minclip + ").");
				else
					alert("Illegal number: " + numval);
				}
			validflag = false;
			}
		else {
			validflag = true;
		}
    }
    else if (type == "phone"  || type == "fullphone") {
        var val = field.value;
        var re = /^[0-9()\- .\/]{7,}$/;
		
        if (!re.test(val)) {
            if (doalert) alert("Invalid phone number: " + val);
            validflag = false;
        }

        if (validflag && type == "fullphone") {
            var val = field.value;
            var re = /^[0-9()\- .\/]{10,}$/;

            if (!re.test(val)) {
                if (doalert) alert("Please include the area code for phone number: " + val);
                validflag = false;
            }
        }
    }
    else if (type == "color") {
		var val = field.value;
		if (val.substring(0,1) == "#")
			val = val.substring(1);
		
		var re = /^[0-9ABCDEFabcdef]{6,}$/;
		if (val.length > 6 || !re.test(val)) {
			if (doalert) alert("Color value must be 6 hexadecimal digits of the form: #RRGGBB.  Example: #FF0000 for red.");
				validflag = false;
		}
		else
			field.value = "#"+val;
    }
    else if (type == "identifier") {
        var val = field.value;
        var re = /^[0-9A-Za-z_]+$/;
        if (!re.test(val)) {
            if (doalert) alert("Identifiers can contain only digits, alphabetic characters, or \"_\" with no spaces");
			validflag = false;
		}
	    else
	      field.value = val.toLowerCase();
    }
    if (mandatory == true) {
		if (field.value.length == 0) {
            if (doalert) alert("Field must contain a value.");
            validflag = false;
		}
	}
    if (!validflag) {
        field.focus();
        field.select();
    }
    window.isvalid = validflag;
    return validflag;
}
function formatCurrency2(a, bDoNotRound) {
	var returnMe;
	if(isNaN(a))
		return "";
	else if( !(bDoNotRound == true))
		returnMe = roundCurrency(a);
	else
		returnMe = a;
	
	returnMe = padCurrency(returnMe);
	
	return returnMe;
}
function roundCurrency(a) {
	var b = Math.abs(a);
	
	b = Math.round(b * 10000000.0) / 100000.0;
	b = Math.round(b) / 100.0;
	
	b = b * (a >= 0.0 ? 1.0 : -1.0);
	if( b == 0.0 )
		return 0.0;
	return b;
}
function padCurrency(a) {
	//was formerly pad_to_atleast_two_decimal_places
	var s;
	if(a == null)
		s = "";
	else {
		s = a.toString();
		var n = s.indexOf(".");
		if(n == -1)
			s = s + ".00";
		else if(n == s.length-1)
			s = s + "00";
		else if(n == s.length-2)
			s = s + "0";
		if (n == 0)
			s = "0" + s;
	}
	return s;
}
function onlydigitsandchars(str) {
    var re = new RegExp("([A-Za-z0-9]+)");
    return (re.exec(str)!=null && RegExp.$1==str);
}
function onlydigits(str) {
    var re = new RegExp("([0-9]+)");
    return (re.exec(str)!=null && RegExp.$1==str);
}
function getdatestring(d) {
    if (window.dateformat == "DD-Mon-YYYY") {
        var m = "JanFebMarAprMayJunJulAugSepOctNovDec";
        return d.getDate()+"-"+m.substring(d.getMonth()*3,d.getMonth()*3+3)+"-"+nlGetFullYear(d);
    }
    else if (window.dateformat == "DD.MM.YYYY")
        return d.getDate()+"."+(d.getMonth()+1)+"."+nlGetFullYear(d);
    else
        return (d.getMonth()+1)+"/"+d.getDate()+"/"+nlGetFullYear(d);
}
function nlGetFullYear(d) {
    if (navigator.appName == "Netscape") {
        if (d.getFullYear=="undefined")
            return d.getYear();
    }
    return d.getFullYear();
}
function nlSetFullYear(d,val) {
    if (navigator.appName == "Netscape") {
        if (d.setFullYear=="undefined")
            d.setYear(val);
    }
    d.setFullYear(val);
}
function stringToDate(arg)
{
    var comps;
	var month, day, year;
    var datetime = arg.split(" ");
    var d = datetime[0];
    if (d.indexOf("/") != -1)
    {
        comps = d.split("/");
        if (comps.length == 2) 
        {
        	month = parseInt(comps[0],10)-1;
	        day = 1;
	        year = parseInt(comps[1],10);
        }
        else
        {
	        month = parseInt(comps[0],10)-1;
	        day = parseInt(comps[1],10);
	        year = parseInt(comps[2],10);
	    }
    }
    else if (d.indexOf(".") != -1)
    {
        comps = d.split(".");
        if (comps.length == 2) 
        {
	        day = 1;
	        month = parseInt(comps[0],10);
	        year = parseInt(comps[1],10)-1;
	    }
	    else
	    {
	    	day = parseInt(comps[0],10);
	        month = parseInt(comps[1],10)-1;
	        year = parseInt(comps[2],10);
	    }
    }
    else if (d.indexOf("-") != -1)
    {
        comps = d.split("-");
        var ms = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";
        if (comps.length == 2) 
        {
	        day = 1;
	        month = parseInt(comps[0],10);
	        year = ms.indexOf(comps[1].toUpperCase())/3;
	    }
	    else
	    {
	     	day = parseInt(comps[0],10);
	        month = ms.indexOf(comps[1].toUpperCase())/3;
	        year = parseInt(comps[2],10);
	    }
    }
    var result;
    var t = datetime[1];
    if (t != null)
    {
        comps = t.split(":");
	    var hour = parseInt(comps[0],10);
	    var min  = parseInt(comps[1],10);
        var sec  = (comps[2] != null ? parseInt(comps[2],10) : 0);
        if (datetime[2].toLowerCase() == "pm")
            hour += 12;
        result = new Date(year,month,day,hour,min,sec);
    }
    else
        result = new Date(year,month,day);
    if (year < 50)
        nlSetFullYear(r, year+2000);
    else if (year < 100)
        nlSetFullYear(r, year+1900);
    return result;
}
function selectAll(Form) {
	var objElements = Form.getElementsByTagName('INPUT');
	var objElement;
	
	if (typeof Form.checked == 'undefined')
		Form.checked = false;

	Form.checked = !Form.checked;
		
	for (var intElement = 0; intElement < objElements.length; intElement++) {
	    objElement = objElements[intElement];
		
		if (objElement.type == 'checkbox')
			objElement.checked = Form.checked;
	}
}
function switchToLive(URL) {
	if (confirm('You have requested to switch to the Live Site. Applications issued on the Live Site WILL be processed.\n\nDo you wish to continue?') == true)
		document.location = URL;
}
function switchToDemo(URL) {
	if (confirm('You have requested to switch to the Training Site. Applications issued on the Demo Site WILL NOT be processed.\n\nDo you wish to continue?') == true)
		document.location = URL;
}
function getFAQText(Database, ProductGroupID, FAQID) {
	jsrsExecute("/ThirdParty/JSRS/Server/GetFAQText.asp", cbWriteFAQText, "getFAQText", Array(Database, ProductGroupID, FAQID));
}
function cbWriteFAQText(Text) {
	getElement("FAQText").innerHTML = Text;
}

/*******************************************************************************************************************/


function BrowserInfo() {
	var agt=navigator.userAgent.toLowerCase();

	this.ie = this.ie4 = this.ie5 = this.ie6 = false;
	this.op5 = this.op6 = this.op7 = false;
	this.ns4 = this.ns6 = this.ns7 = false;
	this.mz7 = false;
	this.win = this.mac = false;

	if(agt.indexOf('win')!=-1)
		this.win = true;
	if(agt.indexOf('mac')!=-1)
		this.mac = true;

	if(typeof window.opera!="undefined"){
		if(agt.indexOf("opera/5")!=-1||agt.indexOf("opera 5")!=-1) this.op5 = true;
		if(agt.indexOf("opera/6")!=-1||agt.indexOf("opera 6")!=-1) this.op6 = true;
		if(agt.indexOf("opera/7")!=-1||agt.indexOf("opera 7")!=-1) this.op7 = true;
	}
	else if(typeof document.all!="undefined"){
		this.ie = true;
		if(typeof document.getElementById!="undefined"){
			this.ie5 = true;
			if(agt.indexOf("msie 6")!=-1)
				this.ie6 = true;
			}
		else this.ie4 = true;
	}
	else if(typeof document.getElementById!="undefined"){
		if(agt.indexOf("netscape/6")!=-1||agt.indexOf("netscape6")!=-1)
			this.ns6 = true;
		else if(agt.indexOf("netscape/7")!=-1||agt.indexOf("netscape7")!=-1){
			this.ns6 = true;
			this.ns7 = true;
		}
		else if(agt.indexOf("gecko")!=-1){
			this.ns6 = true;
			this.mz7 = true;
		}
	}
	else if((agt.indexOf('mozilla')!=-1)&&(parseInt(navigator.appVersion)>=4)){
		this.ns4 = true;
		if(typeof navigator.mimeTypes['*']=="undefined")
			this.ns4 = false;
		if(agt.indexOf('escape')!=-1)
			this.ns4 = false;
	}
}



/*******************************************************************************************************************/

/* Client-side access to querystring name=value pairs
	Version 1.2.3
	22 Jun 2005
	Adam Vandenberg
	http://adamv.com/dev/javascript/querystring
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object();
	this.get=Querystring_get;
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length);

	if (qs.length == 0) return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=');
		var name = unescape(pair[0]);

		if (pair.length == 2)
			value = unescape(pair[1]);
		else
			value = name;
		
		this.params[name] = value;
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value;
}

/*******************************************************************************************************************/
function addAnnotation(TargetURL, Optional) {
	getAnnotation('MyMemo', 'Add Memo', 
		'mstrMyAnnotation = document.getElementById("MyMemoPrompt").value; ' +
		'processAddAnnotation("' + TargetURL + '", ' + Optional + ');', Optional);
}	
function getAnnotation(WindowName, WindowTitle, OnClick, Optional) {
	var strMsg = '';

	if (Optional == true)
		var strMsg = 'You may add a memo to this event...';
	else
		var strMsg = 'Please enter the desired memo...';
	
	newPrompt(WindowName, WindowTitle, strMsg, '<add memo here>', OnClick, 50, 50, 400, 85, true);
}
function processAddAnnotation(TargetURL, Optional) {
	if (mstrMyAnnotation == '<add memo here>') 
		mstrMyAnnotation = '';
		
	if (Optional == true)
		document.location = TargetURL + '&Annotation=' + escape(mstrMyAnnotation);
	else if (Optional == false) {
		if (mstrMyAnnotation == '') {
			alert('A memo is required');
			addAnnotation(TargetURL, Optional);
			return;
		}
		else
		    document.location = TargetURL + '&Annotation=' + escape(mstrMyAnnotation);
	}
}



