function divVisible(divId,visible) {
	//show or hide a division
	try {
		document.getElementById(divId).style.display = visible ? "block" : "none";
	}
	catch (e) {
		// alert(e+": "+divId );
	}
}

function divHide(divId) {
	divVisible(divId,false);
}
function divShow(divId) {
	divVisible(divId,true);
}

function divToggle(divId) {
	//toggle visibility of a div
	var elem;
	try {
		elem = document.getElementById(divId);
		elem.style.display = (elem.style.display=="none") ? "block" : "none";
	}
	catch (e) {
		// alert(e+": "+divId );
	}
}

function loadToggleDiv(divId,loadUrl) {
	var elem = document.getElementById(divId);
	if (elem.innerHTML == "") {
		loadDiv(divId,loadUrl);
		divShow(divId);
	}
	else
		divToggle(divId);
}

//load html into specified div, and show the div
function loadShowDiv(divId, url) {
	//alert(divId+": "+url);

	loadDiv(divId,url,false);
	//sendHttpRequest(url, "loadShowDivCb('"+divId+"');");
	divShow(divId);
}

function loadShowDivCb(divId) {
	divShow(divId);
	alert("mighta worked "+divId);
}

//load html into specified div, and show the div
function loadShowDiv_OLD(divId,loadUrl) {
	loadDiv(divId,loadUrl,false);
	divShow(divId);
}

function divIsVisible(divId) {
	return !(document.getElementById(divId).style.display == "none");
}

function loadDiv(divId,loadUrl,noCache) {
//
// This javascript function makes the connection
// to the server to execute a script
//
		var httpRequest;

		//document.write("divId="+divId+", loadUrl="+loadUrl);
		//return;

		document.getElementById(divId).innerHTML =
			'<img src="/images/waiting.gif" align="center" border="0" alt="" class="miniWait" />';

		if (window.XMLHttpRequest) {
				// alert("Create a new httpRequest for Mozilla");
				httpRequest = new XMLHttpRequest();
				if (httpRequest.overrideMimeType)
						httpRequest.overrideMimeType('text/xml');
		}
		else if (window.ActiveXObject) {
				// alert("Create a new httpRequest for IE");
				try { httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
				catch (e) {
						try {
							// alert("loadDiv error1: "+e);
							httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
						}
						catch (e) {
							// alert("loadDiv error2: "+e);
						}
				}
		}
		if (!httpRequest) {
				alert('Giving up: Cannot create an XMLHTTP instance');
				return false;
		}
		httpRequest.onreadystatechange = function() { alertContents(divId,httpRequest); };
		if (noCache == null || noCache == true) {
				var prm = loadUrl.indexOf("?") >= 0 ? "&" :"?";
				//alert("loadUrl: !ajax_get"+loadUrl+prm+"x="+Math.random());
				//httpRequest.open('GET', "!ajax_get"+loadUrl+prm+"x="+Math.random(), true);
				//alert(loadUrl+prm+"x="+Math.random());
				httpRequest.open('GET', loadUrl+prm+"x="+Math.random(), true);
		}
		else
				httpRequest.open('GET', loadUrl, true);

		httpRequest.send(null);
}

function alertContents(divId,httpRequest) {
//
// This function collects the response from the server
// and puts it into a form variable
//
		if (httpRequest.readyState == 4)
				if (httpRequest.status == 200) {
						try {
							//document.getElementById(divId).innerHTML = unescape(httpRequest.responseText);
							//document.getElementById(divId).innerHTML = "TEST123";
							document.getElementById(divId).innerHTML = httpRequest.responseText;
						}
						catch(e) {
							alert("loadDiv(3): "+e);
							// document.write (httpRequest.responseText);
						}
						// divVisible(divId,true);
				}
				//else
				//		alert('There was a problem with the request');
}


function getWindowHeight() {
	var winH = 460;

	if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
		// winW = window.innerWidth;
		winH = window.innerHeight;
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
		// winW = document.body.offsetWidth;
		winH = document.body.offsetHeight;
	 }
	}

	return winH;
}


/*
 * Date Format 1.2.2
 * (c) 2007-2008 Steven Levithan <stevenlevithan.com>
 * MIT license
 * Includes enhancements by Scott Trenda <scott.trenda.net> and Kris Kowal <cixar.com/~kris.kowal/>
 *
 * Accepts a date, a mask, or a date and a mask.
 * Returns a formatted version of the given date.
 * The date defaults to the current date/time.
 * The mask defaults to dateFormat.masks.default.
 */
var dateFormat = function () {
	var	token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
		timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (val, len) {
			val = String(val);
			len = len || 2;
			while (val.length < len) val = "0" + val;
			return val;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask, utc) {
		var dF = dateFormat;

		// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
		if (arguments.length == 1 && (typeof date == "string" || date instanceof String) && !/\d/.test(date)) {
			mask = date;
			date = undefined;
		}

		// Passing date through Date applies Date.parse, if necessary
		date = date ? new Date(date) : new Date();
		if (isNaN(date)) throw new SyntaxError("invalid date");

		mask = String(dF.masks[mask] || mask || dF.masks["default"]);

		// Allow setting the utc argument via the mask
		if (mask.slice(0, 4) == "UTC:") {
			mask = mask.slice(4);
			utc = true;
		}

		var	_ = utc ? "getUTC" : "get",
			d = date[_ + "Date"](),
			D = date[_ + "Day"](),
			m = date[_ + "Month"](),
			y = date[_ + "FullYear"](),
			H = date[_ + "Hours"](),
			M = date[_ + "Minutes"](),
			s = date[_ + "Seconds"](),
			L = date[_ + "Milliseconds"](),
			o = utc ? 0 : date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: y,
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
				S:    ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
			};

		return mask.replace(token, function ($0) {
			return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks = {
	"default":      "ddd mmm dd yyyy HH:MM:ss",
	shortDate:      "m/d/yy",
	mediumDate:     "mmm d, yyyy",
	longDate:       "mmmm d, yyyy",
	fullDate:       "dddd, mmmm d, yyyy",
	shortTime:      "h:MM TT",
	mediumTime:     "h:MM:ss TT",
	longTime:       "h:MM:ss TT Z",
	isoDate:        "yyyy-mm-dd",
	isoTime:        "HH:MM:ss",
	isoDateTime:    "yyyy-mm-dd'T'HH:MM:ss",
	isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
};

// Internationalization strings
dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask, utc) {
	return dateFormat(this, mask, utc);
};


// Date Validation Javascript
// http://javascript.about.com
function valDateFmt(datefmt) {myOption = -1;
for (i=0; i<datefmt.length; i++) {if (datefmt[i].checked) {myOption = i;}}
if (myOption == -1) {alert("You must select a date format");return ' ';}
return datefmt[myOption].value;}

function valDateRng(daterng) {myOption = -1;
for (i=0; i<daterng.length; i++) {if (daterng[i].checked) {myOption = i;}}
if (myOption == -1) {alert("You must select a date range");return ' ';}
return daterng[myOption].value;}

function stripBlanks(fld) {var result = "";var c=0;for (i=0; i<fld.length; i++) {
if (fld.charAt(i) != " " || c > 0) {result += fld.charAt(i);
if (fld.charAt(i) != " ") c = result.length;}}return result.substr(0,c);}
var numb = '0123456789';

function isValid(parm,val) {if (parm == "") return true;
for (i=0; i<parm.length; i++) {if (val.indexOf(parm.charAt(i),0) == -1)
return false;}return true;}
function isNumber(parm) {return isValid(parm,numb);}
var mth = new Array(' ','january','february','march','april','may','june','july','august','september','october','november','december');
var day = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

function validateDate(fld,fmt,rng) {
var dd, mm, yy;var today = new Date;var t = new Date;fld = stripBlanks(fld);
if (fld == '') return false;var d1 = fld.split('\/');
if (d1.length != 3) d1 = fld.split(' ');
if (d1.length != 3) return false;
if (fmt == 'u' || fmt == 'U') {
	dd = d1[1]; mm = d1[0]; yy = d1[2];}
else if (fmt == 'j' || fmt == 'J') {
	dd = d1[2]; mm = d1[1]; yy = d1[0];}
else if (fmt == 'w' || fmt == 'W'){
	dd = d1[0]; mm = d1[1]; yy = d1[2];}
else return false;
var n = dd.lastIndexOf('st');
if (n > -1) dd = dd.substr(0,n);
n = dd.lastIndexOf('nd');
if (n > -1) dd = dd.substr(0,n);
n = dd.lastIndexOf('rd');
if (n > -1) dd = dd.substr(0,n);
n = dd.lastIndexOf('th');
if (n > -1) dd = dd.substr(0,n);
n = dd.lastIndexOf(',');
if (n > -1) dd = dd.substr(0,n);
n = mm.lastIndexOf(',');
if (n > -1) mm = mm.substr(0,n);
if (!isNumber(dd)) return false;
if (!isNumber(yy)) return false;
if (!isNumber(mm)) {
	var nn = mm.toLowerCase();
	for (var i=1; i < 13; i++) {
		if (nn == mth[i] ||
				nn == mth[i].substr(0,3)) {mm = i; i = 13;}
	}
}
if (!isNumber(mm)) return false;
dd = parseFloat(dd); mm = parseFloat(mm); yy = parseFloat(yy);
if (yy < 100) yy += 2000;
if (yy < 1582 || yy > 4881) {alert("Invalid Year"); return false;}
if (mm == 2 && (yy%400 == 0 || (yy%4 == 0 && yy%100 != 0))) day[mm-1]++;
if (mm < 1 || mm > 12) {alert("Invalid Month"); return false;}
if (dd < 1 || dd > day[mm-1]) return false;
t.setDate(dd); t.setMonth(mm-1); t.setFullYear(yy);
if (rng == 'p' || rng == 'P') {
if (t > today) return false;
}
else if (rng == 'f' || rng == 'F') {
if (t < today) { alert("Date must be today or a future date"); return false; }
}
else if (rng != 'a' && rng != 'A') return false;
return true;
}
// Date Validation Javascript (END)



function roundToPlaces(numval,places) {
	var power = Math.pow(10,places);
	//alert(places+", "+power);

	return Math.round(numval * power)/power;
}


function tabSelect(tabSet,tabId) {
	var base = document.getElementById(tabSet);
	var tabCount = 0, sel;
	var eBase;

	if (base) {
		tabCount = (base.getElementsByTagName("li").length) / 3;
		//alert("tabs: "+tabCount);
		for (var t=0; t<tabCount; t++) {
			eBase = tabSet+t;
			sel = t == tabId;
			document.getElementById(eBase+"l").className = sel ? "tbsl" : "tbul";
			document.getElementById(eBase+"m").className = sel ? "tbsm" : "tbum";
			document.getElementById(eBase+"r").className = sel ? "tbsr" : "tbur";
		}
		divShow(tabSet+"l");
	}
	return tabCount;
}


function showLoading(status) {
	if (document.all||document.getElementById)
		if (status )
			document.body.style.background="url('images/loading.gif') white center no-repeat fixed";
		else
			document.body.style.background="";
}


function createElem(tag,text,attribs) {
	var i, retval = document.createElement(tag);

	if(text)
		retval.appendChild(document.createTextNode(text));

	for(i in attribs)
		retval.setAttribute(attribs[i][0],attribs[i][1]);

	return retval;
}


function dropElem(elm) {
	//alert("dropping: "+elm.id);
	if(elm)
		elm.parentNode.removeChild(elm);
}


function dropElemById(elmId) {
	dropElem(document.getElementById(elmId));
}


function logAppend(logText) {
	sendHttpRequest("lib/logger.asp?text="+logText);
}


function removeHTMLTags(htmlText) {
	var str1 =
		htmlText.replace(/&(lt|gt);/g,
			function (strMatch, p1) {
				return (p1 == "lt")? "<" : ">";
			}
		);

	return str1.replace(/<\/?[^>]+(>|$)/g, "");
}


function setCookie(c_name,value,expiredays) {
	fEntry("setCookie",c_name+"="+value);
	var exdate = new Date();

	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie = c_name + "=" + escape(value) +
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	fExit("setCookie");
}


function getCookie(c_name) {
	if (document.cookie.length > 0) {
		var c_start = document.cookie.indexOf(c_name + "=");

		if (c_start != -1) {
			c_start += c_name.length+1;
			c_end = document.cookie.indexOf(";",c_start);
			if (c_end == -1)
				c_end = document.cookie.length;

			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}


function valTime(txt) {
	var tFmt = /^(\d{1,2}):(\d{2})\s?([a|p]m)?$/i
	var parts, h, m, ap, ok = false;

	if(tFmt.test(txt)) {
		parts = txt.split(tFmt);
		h = parts[1]-0;
		m = parts[2]-0;
		ap = parts[3];

		//alert("h="+h+" m="+m+" ap="+ap);
		//alert("h="+parts[1]+" m="+parts[2]+" ap="+parts[3]);

		if(parts[1] == undefined)
			return true;  // IE

		if(m >= 0 && m <= 59)
			if((ap == "" && h <= 23) || (ap != "" && h >= 1 && h <= 12))
				ok = true;
	}

	return ok;
}

function valDate(txt) {
	var tFmt = /^(\d{1,2})[/|.](\d{1,2})[/|.]((\d{2})|(\d{4}))$/
	var parts, d, m, y, ok = false;

	if(tFmt.test(txt)) {
		parts = txt.split(tFmt);
		d = parts[1]-0;
		m = parts[2]-0;
		y = parts[3]-0;

		if(m >= 1 && m <= 12)
			if(d >= 1 && d <= 31)
				ok = true;
	}
	return ok;
}


function changecss(theClass,element,value) {
	//Last Updated on June 23, 2009
	//documentation for this script at
	//http://www.shawnolson.net/a/503/altering-css-class-attributes-with-javascript.html
	var cssRules;

	var added = false;
	for (var S = 0; S < document.styleSheets.length; S++) {
		if (document.styleSheets[S]['rules'])
			cssRules = 'rules';
		else if (document.styleSheets[S]['cssRules'])
			cssRules = 'cssRules';

		for (var R = 0; R < document.styleSheets[S][cssRules].length; R++)
			if (document.styleSheets[S][cssRules][R].selectorText == theClass)
				if(document.styleSheets[S][cssRules][R].style[element]) {
					document.styleSheets[S][cssRules][R].style[element] = value;
					added=true;
					break;
				}

		if(!added)
			if(document.styleSheets[S].insertRule)
				document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);
			else if (document.styleSheets[S].addRule)
				document.styleSheets[S].addRule(theClass,element+': '+value+';');
	}
}