function fixNum(n) {
zs=new String(n);
z=eval(zs.replace(/[^0-9^\.]/g, ""));
if(isNaN(z)) z=0;
return z;
}

function fixNum2(n) {
zs=new String(n);
z=eval(zs.replace(/[^0-9^\.\-]/g, ""));
if(isNaN(z)) z=0;
return z;
}

function Dollars(amtin) {
	amt = fixNum2(amtin);
	if (amt == 0) {
			return"$0.00";
	}
	neg=0;
	if(eval(amt) < 0) {
		neg=1;
		amt=-eval(amt);
		}
	var temp = eval(amt) + 0.005;
	var cents = "" + (100 + Math.floor((temp - Math.floor(temp)) * 100));
	var dollars = "" + Math.floor(temp);
	dollars = dollars.replace(/([0-9]{1,3})([0-9]{3,3})([0-9]{3,3})([0-9]{3,3})/g,"$1,$2,$3,$4");
	dollars = dollars.replace(/([0-9]{1,3})([0-9]{3,3})([0-9]{3,3})/g,"$1,$2,$3");
	dollars = dollars.replace(/([0-9]{1,3})([0-9]{3,3})/g,"$1,$2");
	
	out = (neg==1?"-":"") + "$" + dollars + "." + cents.substring(1,3);
	return out;
}

function Dollars2(amt) {
	ret = Dollars(amt);
	if(ret=="$0.00") {
		return "";
		}
	else {
		return ret;
		}
	}

function fixPct(val) {
z=new String(val);
z.replace(/[^0-9^\.]/g, "");
if(isNaN(z)) {
	z=0;
	}
d1=Math.floor(Math.round(z * 1000) / 1000);
d2="" + (1000 + (Math.round(z * 1000)));
d3= d1 + "." + d2.substring(d2.length-3,d2.length);
return d3;
}



function Pct(inp) {
	z=inp.value.replace(/[^0-9^\.]/g, "");
	if(isNaN(z)) {
		z=0;
		}
	d1=Math.floor(Math.round(z * 1000) / 1000);

	d2="" + (1000 + (Math.round(z * 1000)));
	d3= d1 + "." + d2.substring(d2.length-3,d2.length);
	inp.value=d3;
	return z
	}


function checkVal(inp,lb,ub,gtlb,ltub,pct) {
	zs=inp.value;
	z=eval(zs.replace(/[^0-9^\.]/g, ""));
	if(z==null) {
		return 1;
		}
	if(isNaN(z)) {
		alert("Please Enter a Numeric Value");
		return 0;
		}
	if((gtlb==0 && z < eval(lb)) || (gtlb==1 && z<=eval(lb))) {
		lbs = pct==1?(fixPct(lb) + " %"):Dollars(lb);
		if(gtlb) {
			alert("Please enter a value greater than " + lbs);
			}
		else {
			alert("Please enter a value greater than or equal to " + lbs);
			}
		return 0;
		}

	if((ltub==0 && z > eval(ub)) || (ltub==1 && z>=eval(ub))) {
		ubs = pct==1?(fixPct(ub) + " %"):Dollars(ub);
		if(ltub) {
			alert("Please enter a value less than " + ubs);
			}
		else {
			alert("Please enter a value less than or equal to " + ubs);
			}
		return 0;
		}
	return 1;
}

function checkVal2(inp,lb,ub) {
	zs=inp.value;
	z=eval(zs.replace(/[^0-9^\.]/g, ""));
	if(isNaN(z) || z < eval(lb) || z > eval(ub)) {
		inp.focus();
		}
}

function checkVal3(inp,lb,ub,gtlb,ltub,pct) {
	zs=inp.value;
	zs=zs.replace(/ /g,"");
	if(zs=="") {
		inp.value="";
		return 1;
		}
	z=eval(zs.replace(/[^0-9^\.^\-]/g, ""));
	if(isNaN(z)) {
		alert("Please Enter a Numeric Value");
		return 0;
		}
	if((gtlb==0 && z < eval(lb)) || (gtlb==1 && z<=eval(lb))) {
		lbs = pct==1?(fixPct(lb) + " %"):lb;
		if(gtlb) {
			alert("Please enter a value greater than " + lbs);
			}
		else {
			alert("Please enter a value greater than or equal to " + lbs);
			}
		return 0;
		}

	if((ltub==0 && z > eval(ub)) || (ltub==1 && z>=eval(ub))) {
		ubs = pct==1?(fixPct(ub) + " %"):ub;
		if(ltub) {
			alert("Please enter a value less than " + ubs);
			}
		else {
			alert("Please enter a value less than or equal to " + ubs);
			}
		return 0;
		}
	inp.value=z;
	return 1;
}

function checkVal4(inp,lb,ub,gtlb,ltub,pct) {
	zs=inp.value;
	z=eval(zs.replace(/[^0-9^\.]/g, ""));
	if(z==null) {
		return 1;
		}
	if(isNaN(z)) {
		alert("Please Enter a Numeric Value");
		return 0;
		}
	if((gtlb==0 && z < eval(lb)) || (gtlb==1 && z<=eval(lb))) {
		lbs = pct==1?(fixPct(lb) + " %"):Dollars2(lb);
		if(gtlb) {
			alert("Please enter a value greater than " + lbs);
			}
		else {
			alert("Please enter a value greater than or equal to " + lbs);
			}
		return 0;
		}

	if((ltub==0 && z > eval(ub)) || (ltub==1 && z>=eval(ub))) {
		ubs = pct==1?(fixPct(ub) + " %"):Dollars2(ub);
		if(ltub) {
			alert("Please enter a value less than " + ubs);
			}
		else {
			alert("Please enter a value less than or equal to " + ubs);
			}
		return 0;
		}
	return 1;
}
function fixVal(inp) {
z=inp.value.replace(/[^0-9^\.]/g, "");
if(z == "") z = 0;
else if(isNaN(z)) {
	alert("Please Enter a Valid Dollar Amount");
	inp.focus();
	return 0;
	}
if(z<0 || z >10000000000) {
	alert("Please Enter a Valid Dollar Amount");
	inp.focus();
	return 0;
	}
inp.value = Dollars(z);
return z;
}

function fixVal2(inp) {
z=inp.value.replace(/[^0-9^\.]/g, "");
if(z == "") z = 0;
else if(isNaN(z)) {
	alert("Please Enter a Valid Dollar Amount");
	inp.focus();
	return 0;
	}
if(z<0 || z >10000000000) {
	alert("Please Enter a Valid Dollar Amount");
	inp.focus();
	return 0;
	}
inp.value = Dollars2(z);
return z;
}

function CommaFormat(amtin) {
	amt = fixNum2(amtin);
	if (amt == 0) {
			return"";
	}
	neg=0;
	if(eval(amt) < 0) {
		neg=1;
		amt=-eval(amt);
		}
	var temp = eval(amt) + 0.005;
	var dec = "" + (100 + Math.floor((temp - Math.floor(temp)) * 100));
	var i = "" + Math.floor(temp);
	i = i.replace(/([0-9]{1,3})([0-9]{3,3})([0-9]{3,3})([0-9]{3,3})/g,"$1,$2,$3,$4");
	i = i.replace(/([0-9]{1,3})([0-9]{3,3})([0-9]{3,3})/g,"$1,$2,$3");
	i = i.replace(/([0-9]{1,3})([0-9]{3,3})/g,"$1,$2");
	
	out = (neg==1?"-":"") + i + (dec.substring(1,3)=="00"?(""):("." + dec.substring(1,3)));
	return out;
}


function chkPhone(inp) {
	fixPhone(inp);
	ph1=inp.value;
	if(ph1.length == 0) {
		return;
		}
	ph1=ph1.replace(/[^0-9]/g,"");
	ph1=ph1.replace(/^1/,"");
	if(ph1.length < 10) {
		alert("Please Enter at least 10 digits");
		inp.focus();
		}
	else if(ph1.length > 15) {
		alert("Please Enter at most 15 digits");
		inp.focus();
		}
	
	}

function chkPhone2(inp) {
	fixPhone(inp);
	ph1=inp.value;
	if(ph1.length == 0) {
		return false;
		}
	ph1=ph1.replace(/[^0-9]/g,"");
	ph1=ph1.replace(/^1/,"");
	if(ph1.length < 10) {
		return false
		}
	return true;	
	}

function fixPhone(inp) {
	ph1=inp.value;
	ph1=ph1.replace(/[^0-9a-z\+]/gi,"");
	ph1=ph1.replace(/^1/,"");
	if(ph1.length < 10 || ph1.match(/^\+/)) {
		return;
		}
	ph1=ph1.replace(/(\w\w\w)(\w\w\w)(\w\w\w\w)x?(\d*)/g, "($1) $2-$3 x$4");
	ph1=ph1.replace(/x$/g, "");

	if(ph1.length > 21) {
		ph1 = ph1.substr(0,21);
		}
	inp.value=ph1;
}

function fixPhone2(ph) {
	ph1=ph.replace(/[^0-9a-z\+]/gi,"");
	ph1=ph1.replace(/^1/,"");
	if(ph1.length < 10 || ph1.match(/^\+/)) {
		return ph;
		}
	ph1=ph1.replace(/(\w\w\w)(\w\w\w)(\w\w\w\w)x?(\d*)/g, "($1) $2-$3 x$4");
	ph1=ph1.replace(/x$/g, "");

	if(ph1.length > 21) {
		ph1 = ph1.substr(0,21);
		}
	return ph1;
	}

function fixDate(inp) {
	sdt2 = inp.value;
	if(sdt2.match(/^[0-9]+[\-\/][0-9]+$/)) {
		sdt2 = sdt2.replace(/\/|\-/, "/1/", "g");
		inp.value=sdt2;
		}
	if(sdt2.match(/[\-\/][0-9][0-9]$/)) {
		yr1 = sdt2.replace(/.*[\-\/]([0-9][0-9])$/g,"$1");
		if(yr1 < 20) {
			yr1 = "" + 20 + yr1;
			}
		sdt2 = sdt2.replace(/([\-\/])[0-9][0-9]$/g, "$1" + yr1);
		}
	if(!Date.parse(sdt2)) {
		if(sdt2 != '') {
			alert('Please enter a date in the form of m/d/yyyy');
			return false;
			}
		}
	else {
		dt2=new Date(sdt2);
		if(dt2.getFullYear() < 1900 || dt2.getFullYear() > 2050) {
			alert('Please enter a current year');
			return false;
			}
		inp.value = eval(dt2.getMonth()+1) + "/" + dt2.getDate() + "/" + dt2.getFullYear();
		}
	return true;
}

function fixDate2(inp) {
	sdt2 = inp.value;
	if(sdt2.match(/^[0-9]+[\-\/][0-9]+$/)) {
		sdt2 = sdt2.replace(/\/|\-/, "/1/", "g");
		inp.value=sdt2;
		}
	if(sdt2.match(/[\-\/][0-9][0-9]$/)) {
		yr1 = sdt2.replace(/.*[\-\/]([0-9][0-9])$/g,"$1");
		if(yr1 < 20) {
			yr1 = "" + 20 + yr1;
			}
		sdt2 = sdt2.replace(/([\-\/])[0-9][0-9]$/g, "$1" + yr1);
		}
	if(!Date.parse(sdt2)) {
		if(sdt2 != '') {
			alert('Please enter a date in the form of m/yyyy');
			return false;
			}
		}
	else {
		dt2=new Date(sdt2);
		if(dt2.getFullYear() < 1900 || dt2.getFullYear() > 2050) {
			alert('Please enter a current year');
			return false;
			}
		inp.value = eval(dt2.getMonth()+1) + "/" + dt2.getFullYear();
		}
	return true;
}

function fixSSN(inp) {
	ph1=inp.value;
	ph1=ph1.replace(/[^0-9]/gi,"");
	if(ph1.length != 9 && ph1.length > 0) {
		alert('Please enter 9 digit SSN');
		return false;
		}
	ph1=ph1.replace(/(\w\w\w)(\w\w)(\w\w\w\w)/g, "$1-$2-$3");
	inp.value=ph1;
	return true;
	}

function lTop(divid) {
	dv=document.getElementById(divid);

	if(!dv) return 0;
	if((navigator.appName.lastIndexOf('Microsoft') != -1 && parseInt(navigator.appVersion) < 5.5) || navigator.userAgent.lastIndexOf('Firefox')>0) {
		layer=dv;
		y=0;
		while (layer.offsetParent != null) { y += eval(layer.offsetTop); layer = layer.offsetParent; }
		y += layer.offsetTop;
		return y;
		}
	return dv.offsetTop;
}

function lLeft(divid) {
	dv=document.getElementById(divid);

	if(!dv) return 0;
	if((navigator.appName.lastIndexOf('Microsoft') != -1 && parseInt(navigator.appVersion) < 5.5) || navigator.userAgent.lastIndexOf('Firefox')>0) {
		layer=dv;
		y=0;
		while (layer.offsetParent != null) {  y += eval(layer.offsetLeft); layer = layer.offsetParent; }
		y += layer.offsetLeft;
		return y;
		}
	return dv.offsetTop;
}

function setBlk(dvs)
{
if(document.getElementById) {
dv=eval("document.getElementById('" + dvs + "')");
dv.style.color='000000';
}
}

function fixZip(inp) {
	zip1=inp.value;
	zip1=zip1.replace(/[^0-9]/g,"");
	if(zip1.length != 5 && zip1.length != 9 && zip1.length != 0) {
		alert("Please enter a 5 or 9 digit zip code");
		return false;
		}
	zip1=zip1.replace(/(\d\d\d\d\d)(\d\d\d\d)/g,"$1-$2");
	inp.value=zip1;
	return true;
}

function Array_Find(v) {
	if(this.length==0) return -1;
	for(array_find_x=0; array_find_x<this.length; array_find_x++) {
		if(this[array_find_x]==v) return array_find_x;
		}
	return -1;
	}

Array.prototype.find = Array_Find;

function getCookieVal (offset){
 var endstr =  document.cookie.indexOf(";", offset);
 if (endstr == -1)
   endstr =  document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
  }

 function GetCookie (name) {
 var arg = name + "=";
 var arg2 = " " + name + "=";
 if(document.cookie.indexOf(arg) == 0) {
	return getCookieVal(arg.length);
	}
else 
 if(document.cookie.indexOf(arg2) != -1) {
	return getCookieVal(document.cookie.indexOf(arg2) + arg2.length);
	}
 else {
	return null;
	}
}

function SetCookie(name, value) {

var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? "; expires=" + argv[2].toGMTString() : "";
var path = (argc > 3) ? "; path=" + argv[3] : "; path=/";
var domain = (argc > 4) ? "; domain=" + argv[4] : "";
var secure = (argc > 5) ? "; " + argv[5] : "";
document.cookie = name + "=" + escape (value) + expires + path + domain + secure;

}

function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function checkChanged(frm) {
	chg=0;
	for(x=0;x<frm.elements.length;x++) {
		el=frm.elements[x];
		if(el.type=="text" || el.type=="password") {
			if(el.value!=el.defaultValue) {
				chg=1;
				break;
				}
			}
		else if(el.type=="radio"||el.type=="checkbox") {
			if(el.checked!=el.defaultChecked) {
				chg=1;
				break;
				}
			}
		else if(el.tagName=="SELECT") {
			for(y=0;y<el.options.length;y++) {
				if(el.options[y].defaultSelected!=el.options[y].selected) {
					chg=1;
					break;
					}
				}
			}
		}
	return chg;
	}

function setFormDefaults(frm) {
	for(x=0;x<frm.elements.length;x++) {
		el=frm.elements[x];
		if(el.type=="text" || el.type=="password") {
			if(el.value!=el.defaultValue) {
				el.defaultValue=el.value;
				}
			}
		else if(el.type=="radio"||el.type=="checkbox") {
			if(el.checked!=el.defaultChecked) {
				el.defaultChecked=el.checked;
				}
			}
		else if(el.type=="select") {
			for(y=0;y<el.options.length;y++) {
				if(el.options[y].defaultSelected!=el.options[y].selected) {
					el.defaultSelected=el.selected;
					}
				}
			}
		}
	}

function jt_isHoliday() {
	day=this.getDay();
	if(this.getMonth()==0 && this.getDate()==1) { 
		return true;
		}
	else if(this.getMonth()==0 && day==1 && this.getDate()<22 && this.getDate()>14) { 
		return true;
		}
	else if(this.getMonth()==1 && day==1 && this.getDate()<22 && this.getDate()>14) { 
		return true;
		}
	else if(this.getMonth()==4 && this.getDate()>24 && day==1) { 
		return true;
		}
	else if(this.getMonth()==6 && this.getDate()==4) {
		return true;
		}
	else if(this.getMonth()==8 && this.getDate()<8 && day==1) {
		return true;
		}
	else if(this.getMonth()==9 && day==1 && this.getDate()>7 && this.getDate()<15) { 
		return true;
		}
	else if(this.getMonth()==10 && this.getDate()==11) {
		return true;
		}
	else if(this.getMonth()==10 && this.getDate()>23 && day==4) {
		return true;
		}
	else if(this.getMonth()==11 && this.getDate()==25) {
		return true;
		}
	return false;
	}

function jt_daysDiff(d) {
	return Math.floor((this.valueOf2()-d.valueOf2())/86400000);
	}
function jt_businessDaysDiff(d) {
	td=this.valueOf2();
	cd=d.valueOf2();
	xdate=new Date();
	out=0;
	if(td<cd) {
		xdate.setTime(td);
		while(xdate.valueOf2()<cd) {
			xdate.addDays(2);
			if(xdate.getDay()!=0 && xdate.getDay()!=6 && !xdate.isHoliday()) {
				out--;
				}
			}
		}
	else {
		xdate.setTime(cd);
		
		while(xdate.valueOf2()<td) {
			xdate.addDays(2);
			if(xdate.getDay()!=0 && xdate.getDay()!=6 && !xdate.isHoliday()) {
				out++;
				}
			}
		}
	return out;
	}

function jt_valueOf2() {
	return this.valueOf() + this.getTimezoneOffset() * 3600 + 43200000;
	}

function jt_ticksInDay() {
	if(this.getMonth()==3 && this.getDate()<8 && day==0) {
		return 90000000;
		}
	else if(this.getMonth()==9 && this.getDate()>24 && day==0) {
		return 82800000;
		}
	else {
		return 86400000;
		}
	}

function jt_addDays(d) {
	if(d>0) {
		for(x=1;x<d;x++) {
			this.setTime(this.valueOf()+this.ticksInDay());
			}
		}
	else if(d<0) {
		for(x=1;x<Math.abs(d);x++) {
			this.setTime(this.valueOf()-this.ticksInDay());
			}
		}
	}
				
Date.prototype.isHoliday=jt_isHoliday;
Date.prototype.daysDiff=jt_daysDiff;
Date.prototype.businessDaysDiff=jt_businessDaysDiff;
Date.prototype.addDays=jt_addDays;
Date.prototype.ticksInDay=jt_ticksInDay;
Date.prototype.valueOf2=jt_valueOf2;


