// Last modification:
var clib_version = 2008.0130;

//
// Javascript copyright 2003-2007 by Jeff Krause.  All rights reserved.
//
//  clib.js
//

var clib_fDebug=false;
var clib_fDebugInit = false;
var clib_fLocal;
var clib_website;
var clib_websiteUrl;
var clib_pageUrl,clib_subUrl,clib_pagePath;
var clib_host;
var clib_currentYear = null;
var clib_rgUrlParam = new Array();
var clib_homePrefix;
var clib_fNoCookies = true;
var clib_fCookieLog = false;
var clib_cookiePath = "/";
var clib_imageLoc = 'clibimages/';
var clib_urlCautionSuffix = "caution.gif";
var clib_urlCaution;
var clib_urlQuestionSuffix = "question.gif";
var clib_urlQuestion;
var clib_title="";
var clib_alertMsg2 = null;
var clib_alertImg2 = null;
var clib_fUseAlert = false;
var clib_alertx = 375;
var clib_alertx2 = 75;
var clib_rgPreLoad = new Array();
var clib_nrgPreLoad = 0;
var clib_alertDiv = 'div_clibAlert';
var clib_rgMonths = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var clibdb_members = '';

if (eval('typeof clib_fDumpData') == 'undefined') var clib_fDumpData = false;
if (clib_fDumpData) clibdb_register('clib_rgPreLoad');

function clib_isFunction(a) { return (typeof a == 'function'); }
function clib_isObject(a) { return (((a && (typeof a == 'object'))) || clib_isFunction(a)); }
function clib_isArray(a) { return (clib_isObject(a) && (a.constructor == Array)); }
function clib_isImage(a) { return (clib_isObject(a) && (typeof a.complete != 'undefined') && (typeof a.src != 'undefined')); }
function clib_isNumber(a) { return (typeof a == 'number'); }
function clib_isString(a) { return (typeof a == 'string'); }
function clib_isNonNullString(a) { return ((typeof a == 'string') && (a != '')); }
function clib_isNullString(a) { return ((typeof a == 'string') && (a == '')); }
function clib_isUndefined(a) { return (typeof a == 'undefined'); } 
function clib_isNull(a) { return ((typeof a == 'undefined') || (a == null)); } 

function clib_checkArg(a) { return (typeof a == 'undefined' ? null : a); } 
function clib_checkTopUrl() { if (window != top) top.location.href = location.href; }
function clib_gotoTopUrl(url) { top.location.href = url; }

function clib_closeWindows() {
	if (clib_fLocal) alert('clib_closeWindows()');
	}

function clib_decrypt(s) {
	var key = 5;
	var r = '';
	for (var i = 1; i < s.length; i += 2) r += String.fromCharCode(key ^ s.charCodeAt(i));
	return r;
	}

function clibdb_register() {
	for (var i = 0; i < clibdb_register.arguments.length; i++) clibdb_members = clibdb_register.arguments[i] + (clibdb_members == '' ? '' : ',' + clibdb_members); }

function clib_urlParamType(id,value) { this.members = 'id,value'; this.id = id; this.value = value; }
function clib_initClibLibrary(url) {
	clib_initWebSiteName();
	if (url == null) url = document.location;
	clib_pageUrl = clib_getUrlPrefix(url);
	clib_subUrl = clib_getUrlSuffix(url);
	if (clib_subUrl != null) {
		var rg = clib_subUrl.split('&');
		for (var i = 0; i < rg.length; i++) {
			var id,value;
			var rgp = rg[i].split('=');
			if (rgp.length > 2) for (var j = 2; j < rgp.length; j++) rgp[1] += '=' + rgp[j];
			if (rgp.length < 2) { id = rg[i]; value = ''; }
			else { id = rgp[0]; value = rgp[1]; }
			clib_rgUrlParam[clib_rgUrlParam.length] = new clib_urlParamType(id,value);
			}
		}
	var td = new Date();
	clib_currentYear = td.getFullYear();
	}

function clib_idCompare(a,b,fCase) {
	if ((a == null) || (b == null)) return false;
	if (fCase == null) fCase = false;
	if (!fCase) {
		a = a.toLowerCase();
		b = b.toLowerCase();
		}
	return (clib_insertText(a,"%20"," ") == clib_insertText(b,"%20"," "));
	}

function clib_getUrlParam(id) {
	for (var i = 0; i < clib_rgUrlParam.length; i++) if (clib_idCompare(clib_rgUrlParam[i].id,id)) return clib_rgUrlParam[i].value;
	return null;
	}

function clib_getUrlPrefix(url) {
	url = clib_cleanUrl(url);
	var rg = url.split('#');
	if (rg.length < 2) rg = url.split('?');
	if (rg.length > 1) url = rg[0];
	rg = url.split('/');
	if (rg.length > 1) return rg[rg.length-1];
	else return url;
	}

function clib_getUrlSuffix(url) {
	url = clib_cleanUrl(url);
	var ch = '#';
	var rg = url.split(ch);
	if (rg.length < 2) { ch = '?'; rg = url.split(ch); }
	if (rg.length > 1) {
		url = rg[1];
		for (var i = 2; i < rg.length; i++) url += ch + rg[i];
		return url;
		}
	else return null;
	}

function clib_cleanUrl(url) {
	if (url == null) return '';
	var x = url + ' ';
	url = x.substr(0,x.length-1);
	var len = url.length;
	var j = 0;
	var c = '';
	while (j < len) {
		var ch = url.charAt(j);
		var chLeft = len - j - 1;
		if (ch == '\\') ch = '/';
		else if ((ch == '%') && (chLeft >= 2)) if (url.substr(j,3) == '%20') {
			ch = ' ';
			j += 2;
			}
		c += ch;
		j++;
		}
	return c;
	}

function clib_unhideUrl(url) {
	if (typeof url == 'undefined') return null;
	if (typeof url == 'string') {
		if (url.indexOf('~') < 0) return url;
		url = clib_insertText(url,'~|~','\/');
		url = clib_insertText(url,'~j~','.jpg');
		url = clib_insertText(url,'~g~','.gif');
		url = clib_insertText(url,'~h~','.html');
		url = clib_insertText(url,'~c~','.com');
		if (url.indexOf('~') < 0) return url;
		url = clib_insertText(url,'~p~','.pdf');
		url = clib_insertText(url,'~n~','.net');
		url = clib_insertText(url,'~o~','.org');
		url = clib_insertText(url,'~e~','.edu');
		url = clib_insertText(url,'~a~','@');
		}
	return url;
	}

//
// Notes:
//	- urls are full spec from root such as /foo/bar.jpg
//	- If leading '/' is ommitted it is assumed (a/b.jpg == /a/b.jpg)
//	- If urlParent is blank or null then it is assumed to be (clib_pagePath + clib_pageUrl)
//
function clib_normalizeUrl(url,urlParent) {
    var urlRet = '';
	if ((typeof urlParent != 'string') || (urlParent == '')) urlParent = clib_pagePath + clib_pageUrl;
	if ((typeof url != 'string') || (url == '')) return null;
	url = clib_unhideUrl(url);
	if (url.charAt(0) == '/') url = url.substr(1,url.length-1);
	if (urlParent.charAt(0) == '/') urlParent = urlParent.substr(1,urlParent.length-1);
	var rg = url.split('/');
	var rgParent = urlParent.split('/');
	if (rgParent.length == 1) return url;
	var html = 'rg.length = ' + rg.length + ' (';
	for (var i = 0; i < rg.length; i++) html += (i == 0 ? '' : ', ') + rg[i];
	html += ')<br>';
	html += 'rgParent.length = ' + rgParent.length + ' (';
	for (i = 0; i < rgParent.length; i++) html += (i == 0 ? '' : ', ') + rgParent[i];
	html += ')<br><br>';
	if (rg.length == 1) {
		for (i = 0; i < rgParent.length - 1; i++) urlRet += '../';
		urlRet += rg[0];
		return urlRet;
		}
	else if (rg[0] == rgParent[0]) {
		url = rg[1]; for (i = 2; i < rg.length; i++) url += '/' + rg[i];
		urlParent = rgParent[1]; for (i = 2; i < rgParent.length; i++) urlParent += '/' + rgParent[i];
		return clib_normalizeUrl(url,urlParent);
		}
	else {
    	for (i = 0; i < rgParent.length-1; i++) urlRet += '../';
    	urlRet += url;
	    return urlRet;
	    }
	}

function clib_initWebSiteName() {
	var url = document.location;
	url = clib_cleanUrl(url);
	var rgWebSuffix = new Array('.com', '.org', '.net');
	var nrgWebSuffix = rgWebSuffix.length;
	var rgFolders = new Array();
	rgFolders = url.split('/');
	clib_website = '';
	clib_homePrefix = '';
	clib_websiteUrl= '';
	clib_pagePath = '';
	var urlLocal = 'file:';
	clib_fLocal = (url.substr(0,urlLocal.length) == urlLocal);		// force to be string and see if its "file:..."
	var n = 0;
	for (var i = rgFolders.length - 1; i >= 0; i--) {
//		clib_pagePath = rgFolders[i] + '/' + clib_pagePath;
		for (var j = 0; j < rgWebSuffix.length; j++) {
			var web = rgWebSuffix[j].toLowerCase();
			var local = rgFolders[i].toLowerCase();
			if (local.length >= web.length) {
				if (web == local.substr(local.length-web.length,web.length)) {
					for (var k = i + 1; k < rgFolders.length - 1; k++) clib_pagePath += rgFolders[k] + '/';
					clib_website = local;
					clib_websiteUrl="http://" + clib_website + "/";
					if (clib_fLocal) {
						clib_homePrefix = '';
						if (n > 0) for (var l = 1; l < n; l++) clib_homePrefix += "../";
						}
					else clib_homePrefix = clib_websiteUrl;
					if (clib_fLocal) clib_host='local';
					else {
						var rgsite = new Array();
						rgsite = clib_website.split('.');
						clib_host = rgsite[rgsite.length-2].toLowerCase();
						}
					return;
					}
				}
			}
		n++;
		}
	return;
	}

function clib_emailLink(user,dom,type,subj,cl) {
	return '<a ' + (cl == null ? '' : 'class=' + cl) + ' href="mailto:' + user + '@' + dom + '.' + type + (subj == null ? '' : '?subject=' + subj) + '">' + user + '@' + dom + '.' + type + '</a>';
	}

// clib_insertText("text~string", "~", "XXX")
// returns "textXXXstring"
//
function clib_insertText(t,s,p) {
	if (typeof t != 'string') return '';
	var rg = t.split(s);
	if (rg.length < 2) return t;
	var r = rg[0];
	for (var i = 1; i < rg.length; i++) r += p + rg[i];
	return r;
	}

// clib_insertParams('%3 %2 %1 %0 %1 %2 %3 %4 %5 %6','this','is','a','test')
// returns "test a is this is a test "
// t has up to 10 parameters [%0 .. %9]//
//
function clib_insertParams(t) {
	if ((t == null) || (t == '')) return t;
	var args = clib_insertParams.arguments;
	var nargs = args.length;
	var rgp = new Array();
	for (var i = 0; i < 10; i++) rgp[i] = '';
	for (i = 1; i < nargs; i++) if (args[i] != null) rgp[i-1] = args[i];
	var r = t;
	for (i = 0; i < 10; i++) {
		var s = '%' + i; 
		r = clib_insertText(r,s,rgp[i]);
		}	
	return r;
	}

function clib_imgPosX(objName) { return clib_objPosX(clib_getElementId(objName)); }
function clib_imgPosY(objName) { return clib_objPosY(clib_getElementId(objName)); }

function clib_objPosX(obj) {
	if ((obj == null) || (obj == '')) return null;
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
			}
		}
	else if (obj.x) curleft += obj.x;
	return curleft;
	}

function clib_objPosY(obj) {
	if ((obj == null) || (obj == '')) return null;
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
			}
		}
	else if (obj.y) curtop += obj.y;
	return curtop;
	}

function clib_wdType(xMin,xMax,yMin,yMax) { this.xMin = xMin; this.xMax = xMax; this.yMin = yMin; this.yMax = yMax; }
function clibx_newWindowDimType(x,y,w,h) { this.members = 'x,y,w,h'; this.x = x; this.y = y; this.w = w; this.h = h; }
function clib_screenDimType(w,h,st,sl,wx,wy,sx,sy) {
	this.members = 'x,y,w,h,scrollX,scrollY,windowX,windowY,screenX,screenY';
	this.x = w; this.y = h; this.w = w; this.h = h;
	this.scrollX = sl; this.scrollY = st;
	this.windowX = wx; this.windowY = wy;
	this.screenX = sx; this.screenY = sy;
	}

function clib_screenDimensions(id) {
	var w,h,st,sl,wx,wy,sx,sy = 0;
	var did = (id == null ? document : id.document);
	var wid = (id == null ? window : id.window);

	if (wid.innerWidth != null) w = wid.innerWidth;
	else if ((did.body != null) && (did.body.clientWidth != null)) w = did.body.clientWidth;
	if (wid.innerHeight != null) h = wid.innerHeight;
	else if ((did.body != null) && (did.body.clientHeight != null)) h = did.body.clientHeight;

	if (wid.pageXOffset != null) sl = wid.pageXOffset;
	else if ((did.body != null) && (did.body.scrollLeft != null)) sl = did.body.scrollLeft;
	if (wid.pageYOffset != null) st = wid.pageYOffset;
	else if ((did.body != null) && (did.body.scrollTop != null)) st = did.body.scrollTop;

	if (wid.outerWidth != null) wx = wid.outerWidth;
	else if ((did.body != null) && (did.body.offsetWidth != null)) wx = did.body.offsetWidth;
	if (wid.outerHeight != null) wy = wid.outerHeight;
	else if ((did.body != null) && (did.body.offsetHeight != null)) wy = did.body.offsetHeight;

	if (screen.availWidth != null) sx = screen.availWidth; else sx = wx;
	if (screen.availHeight != null) sy = screen.availHeight; else sy = wy;

	return new clib_screenDimType(w,h,st,sl,wx,wy, sx,sy);
	}

function clib_windowDimensions(id) {
	var xMin,xMax,yMin,yMax;
	if (window.innerWidth == null) {	// IE 4+
		var did = (id == null ? document : id.document);
		xMin = did.body.scrollLeft;
		xMax = xMin + did.body.clientWidth;
		yMin = did.body.scrollTop;
		yMax = yMin + did.body.clientHeight;
		}
	else {								// NS 4+
		var wid = (id == null ? window : id.window);
		xMin = wid.pageXOffset;
		xMax = xMin + wid.innerWidth;
		yMin = wid.pageYOffset;
		yMax = yMin + wid.innerHeight;
		}
	return new clib_wdType(xMin,xMax,yMin,yMax);
	}

function clib_innerWidth() {return clib_screenDimensions().w; }
function clib_innerHeight() {return clib_screenDimensions().h; }
function clib_clientWidth() {return clib_screenDimensions().w; }
function clib_clientHeight() {return clib_screenDimensions().h; }

function clib_screenScrollX() { return clib_screenDimensions().scrollX; }
function clib_screenScrollY() { return clib_screenDimensions().scrollY; }
function clib_pageXOffset() {return clib_screenDimensions().scrollX; }
function clib_pageYOffset() {return clib_screenDimensions().scrollY; }
function clib_scrollLeft() {return clib_screenDimensions().scrollX; }
function clib_scrollTop() {return clib_screenDimensions().scrollY; }

function clib_windowX(id) { return clib_screenDimensions(id).windowX; }
function clib_windowY(id) { return clib_screenDimensions(id).windowY; }
function clib_outerWidth(id) {return clib_screenDimensions(id).windowX; }
function clib_outerHeight(id) {return clib_screenDimensions(id).windowY; }
function clib_offsetWidth(id) {return clib_screenDimensions(id).windowX; }
function clib_offsetHeight(id) {return clib_screenDimensions(id).windowY; }

function clib_screenX(id) { return clib_screenDimensions(id).screenX; }
function clib_screenY(id) { return clib_screenDimensions(id).screenY; }
function clib_screenAvailWidth(id) { return clib_screenDimensions(id).screenX; }
function clib_screenAvailHeight(id) { return clib_screenDimensions(id).screenY; }

function clib_newWindowDim(w,h) {
	var xMax = clib_screenX();
	var yMax = clib_screenY();
	var x,y;
	if (w == "*") { w = xMax; x = 0; }
	else {
		if (w == null) w = clib_windowX();
		else w = Math.max(200,Math.min(w,xMax-70)) + 60;
		x = Math.floor((xMax - w)/2) + 20;
		}
	if (h == "*") { h = yMax; y = 0; }
	else {
		if (h == null) h = clib_windowY();
		else h = Math.max(200,Math.min(h,yMax-90)) + 80;
		y = Math.floor((yMax - h)/2);
		}
	return new clibx_newWindowDimType(x,y,w,h);
	}

function clib_centerWindow(id,w,h) {
	var s = clib_screenDimensions();
	mW = Math.max(0,Math.floor((s.screenX - w)/2)-5);
	mH = Math.max(0,Math.floor((s.screenY - h)/3));
	id.moveTo(mW,mH);
	}

function clib_objDimensions(obj) {
	function clib_objDimType(l,t,w,h) {
		this.members = 'left,top,width,height';
		this.left = l;
		this.top = t;
		this.width = w;
		this.height = h;
		}
	if ((obj == null) || (obj == '')) return null;
	var rgDim = new Array(null,null,obj.width,obj.height);
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			rgDim[0] += obj.offsetLeft;
			rgDim[1] += obj.offsetTop;
			if ((rgDim[2] == null) || (rgDim[2] == '')) rgDim[2] = obj.width;
			if ((rgDim[2] == null) || (rgDim[3] == '')) rgDim[3] = obj.height;
			obj = obj.offsetParent;
			}
		}
	else if (obj.x) {
		rgDim[0] += obj.x;
		rgDim[1] += obj.y;
		}
	var d = new clib_objDimType(rgDim[0],rgDim[1],rgDim[2],rgDim[3]);
	return d;
	}

function clib_changeClass(id,className) {
	if (typeof id == 'string') id = clib_getElementId(id);
	if (id) {
		if (id.className) id.className=className;
		else return -1;
		}
	else return -2;
	return 0;
	}

function clib_validateEmail(email) {
	if ((email == null) || (email == '') || (email.length < 6)) return false;
	var rg = email.split('<');
	if (rg.length > 1) {
		email = rg[rg.length-1];
		rg = email.split('>');
		if (rg.length != 2) return false;
		email = rg[0];
		}
	rg = email.split('@');
	if (rg.length != 2) return false;
	for (var i = 0; i < rg.length; i++) if (rg[i].length < 1) return false;
	rg = email.split('.');
	if (rg.length < 2) return false;
	for (i = 0; i < rg.length; i++) if (rg[i].length < 1) return false;
	return true;
	}

function clib_preLoadType(url,caller) {
	this.members = 'url,caller,img';
	this.url = url;
	this.caller = caller;
	this.img = new Image();
	this.img.src = url;
	}

function clibx_preLoadOneImage(url,caller) {
	for (var i = 0; i < clib_nrgPreLoad; i++) if (clib_rgPreLoad[i].url == url) return;
	clib_rgPreLoad[clib_nrgPreLoad++] = new clib_preLoadType(url,caller);
	}

function clibx_preLoadImageList(urlList,caller) {
	if (typeof urlList != 'string') {
		clib_debugFunction(clib_fLocal, ('Not a string: ' + typeof url));
		return;
		}
	var rgl = urlList.split(',');
	for (var i = 0; i < rgl.length; i++) {
		var url = rgl[i];
		var rg = url.split('.');
		if (rg.length < 2) clib_debugFunction(clib_fLocal,('not a valid file: ' + url));
		else clibx_preLoadOneImage(url,caller);
		}
	}

function clib_preLoadImages() {
	var rgArgs = clib_preLoadImages.arguments;
	var caller = null;
	var i;
	if (!clib_isNull(clib_preLoadImages.caller) && !clib_isNull(clib_preLoadImages.caller.arguments)) {
		caller += clib_preLoadImages.caller;
		rg = caller.split('(');
		caller = rg[0].substr(12,rg[0].length-12) + '(';
		for (i = 0; i < clib_preLoadImages.caller.arguments.length; i++) {
			if (i > 0) caller += ', ';
			caller += clib_preLoadImages.caller.arguments[i];
			}
		caller += ')';
		}
	for (i = 0; i < rgArgs.length; i++) {
		if (clib_isString(rgArgs[i])) clibx_preLoadImageList(rgArgs[i],caller);
		else if (clib_isArray(rgArgs[i])) for (var j = 0; j < rgArgs[i].length; j++) clibx_preLoadImageList(rgArgs[i][j],caller);
		else clib_debugFunction(clib_fLocal,'invalid argument: ' + (typeof rgArgs[i]));
		}
	}

function clib_preloadImageHandler(url,load,error,abort) {
	clib_debugFunction(clib_fLocal);
	var x = new clib_imageType(url,load,error,abort);
	x.image.src = url;
	return x;
	}

function clib_imageType(url,load,error,abort,w,h) {
	this.members = 'url,image,status,w,h';
	this.url = url;
	this.w = w;
	this.h = h;
	this.image = new Image();
	this.status = null;
	if (load != null) {
		eval("this.image.loadHandler = function () { " + load + " }" );
		this.image.onload = this.image.loadHandler;
		}
	if (error != null) {
		eval("this.image.errorHandler = function () { " + error + " }");
		this.image.onerror = this.image.errorHandler;
		}
	if (abort != null) {
		eval("this.image.errorHandler = function () { " + abort + " }");
		this.image.onabort = this.image.errorHandler;
		}
	if ((abort == null) && (error != null)) this.image.onabort = this.image.errorHandler;
	}

var clibx_rgPreLoadArray = new Array();
var clibx_nrgPreLoadArray = 0;
function clibx_preLoadType(rgUrl,nrgUrl) {
	this.members = 'rgUrl,nrgUrl,irgUrl,rgLoad,nrgLoad';
	this.rgUrl = rgUrl;
	this.nrgUrl = nrgUrl;
	this.irgUrl = 0;
	this.rgLoad = new Array();
	this.nrgLoad = 0;
	}

function clib_preLoadImageArray(rgUrl,nrgUrl,nUrlInit) {
	if (nUrlInit == null) nUrlInit = 3;
	var irg = clibx_nrgPreLoadArray;
	clibx_rgPreLoadArray[clibx_nrgPreLoadArray++] = new clibx_preLoadType(rgUrl,nrgUrl);
	var x = clibx_rgPreLoadArray[irg];
	var handler = 'clibx_nextPreLoadUrl(' + irg + ',' + ')';
	for (var i = 0; ((i < nUrlInit) && (i < nrgUrl)); i++) {
		var shandler = 'clibx_preLoadHandler(' + irg + ',' + x.nrgLoad + ',0)';
		var ehandler = 'clibx_preLoadHandler(' + irg + ',' + x.nrgLoad + ',1)';
		var ahandler = 'clibx_preLoadHandler(' + irg + ',' + x.nrgLoad + ',2)';
		x.rgLoad[x.nrgLoad] = new clib_imageType(x.rgUrl[x.irgUrl],shandler,ehandler,ahandler);
		x.rgLoad[x.nrgLoad++].image.src = x.rgUrl[x.irgUrl++];
		}
	}

function clibx_preLoadHandler(irg,irgLoad,status) {
	var x = clibx_rgPreLoadArray[irg];
	if (clib_fLocal) x.rgLoad[irgLoad].status = status;
	else x.rgLoad[irgLoad] = null;
	setTimeout('clibx_nextPreLoadUrl(' + irg + ')',20);
	}

function clibx_nextPreLoadUrl(irg) {
	var x = clibx_rgPreLoadArray[irg];
	if (x.nrgLoad < x.nrgUrl) {
		var shandler = 'clibx_preLoadHandler(' + irg + ',' + x.nrgLoad + ',0)';
		var ehandler = 'clibx_preLoadHandler(' + irg + ',' + x.nrgLoad + ',1)';
		var ahandler = 'clibx_preLoadHandler(' + irg + ',' + x.nrgLoad + ',2)';
		x.rgLoad[x.nrgLoad] = new clib_imageType(x.rgUrl[x.irgUrl],shandler,ehandler,ahandler);
		x.rgLoad[x.nrgLoad++].image.src = x.rgUrl[x.irgUrl++];
		}
	}

function clib_innerHTML(div,html) {
	clib_checkHTML(html);
	var id = clib_getElementId(div);
	if (id == null) return true;
	id.innerHTML = html;
	return false;
	}

function clib_writeln(html,div) {
	clib_checkHTML(html);
	if (div == null) document.writeln(html);
	else clib_innerHTML(div,html);
	}

function clib_checkHTML(html) {
	if ((!clib_fLocal) || (!clib_isString(html))) return;
	html = html.toLowerCase();
	var rgTest = new Array('table','tr','td','div');
	var rgTestResult = new Array(rgTest.length);
	var rg;
	var i;
	for (i = 0; i < rgTest.length; i++) {
		var begCode = '<' + rgTest[i] + ' ';
		rg = html.split(begCode);
		rgTestResult[i] = rg.length;
		begCode = '<' + rgTest[i] + '>';
		rg = html.split(begCode);
		rgTestResult[i] += rg.length - 1;
		var endCode = '<' + '/' + rgTest[i] + '>';
		rg = html.split(endCode);
		rgTestResult[i] -= rg.length;
		}
	rg = (clib_checkHTML.caller + ' ').split('(');
	var nErrors = 0;
	var msg = rg[0] + ': ';
	for (i = 0; i < rgTest.length; i++) {
		if (rgTestResult[i] != 0) { msg += rgTest[i] + ' error: ' + rgTestResult[i] + ' '; nErrors++; }
		}
	if (nErrors != 0) clib_debugFunction(true,msg);
	}

function clib_placeDiv(div, x, y, z, fVisible) {
	var id = clib_getElementId(div);
	if (id == null) return true;
	if (fVisible != null) id.style.visibility=(fVisible ? "visible" : "hidden");
	if (x != null) id.style.left = x;
	if (y != null) id.style.top = y;
	if (z != null) id.style.zIndex = z;
	return false;
	}

function clib_clipDiv(div,x,y,w,h) {
	var id = clib_getElementId(div);
	if ((id == null) || (x == null) || (y == null) || (w == null) || (h == null)) return; 
	else id.style.clip='rect(' + y + 'px ' + (x+w) + 'px ' + (y+h) + 'px ' + x + 'px)'
	}

// change HTML if function changes!

var clib_getId_html  = "function getId(name){ if ((name == null) || (name == '')) return null; var o = null;\n";
	clib_getId_html += "  if (document.getElementById) { o = eval('document.getElementById(" + '"' + "' + name + '" + '"' + ")'); if (o != null) return o; }\n";
	clib_getId_html += "  if (document.all) { o = eval('document.all.' + name); if (o != null) return o; }\n";
	clib_getId_html += "  if (document.images) { o = eval('document.images.' + name); if (o != null) return o; }\n";
	clib_getId_html += "  return null; }\n";

function clib_getElementId(name){
	if ((name == null) || (name == '')) return null;
	var o = null;
	if (document.getElementById) {
		o = eval('document.getElementById("' + name + '")');
		if (o != null) return o;
		}
	if (document.all) {
		o = eval('document.all.' + name);
		if (o != null) return o;
		}
	if (document.images) {
		o = eval('document.images.' + name);
		if (o != null) return o;
		}
	return null;
	}

function clib_xidType(name) { this.members = 'name,num'; this.name = name; this.num = 1000; }
var clib_rgxid = new Array();
clib_rgxid[0] = new clib_xidType('clib');
var clib_nrgxid = 1;
var clib_lastElementId = null;
function clib_newElementId(name) {	
	if (name == null) name = 'clib';
	for (var i = 0; i < clib_nrgxid; i++) if (clib_rgxid[i].name == name) break;
	if (i == clib_nrgxid) clib_rgxid[clib_nrgxid++] = new clib_xidType(name);
	clib_rgxid[i].num++;
	var id = 'id_' + name + '_' + clib_rgxid[i].num;
	clib_lastElementId = id;
	return id;
	}

function clib_fFadeObject(name) {
	var id = clib_getElementId(name);
	if ((id != null) && (id.filters) && (id.filters.blendTrans)) return true;
	return false;
	}

function clib_swapImage(name,file,nSec,w,h) {
	var id = clib_getElementId(name);
	if (id == null) return true;
	if (w != null) if (w != id.width) id.width = w;
	if (h != null) if (h != id.height) id.height = h;
	var fFade = false;
	if (nSec != null)
		if (nSec > 0)
			if (id.filters)
				if (id.filters.blendTrans) fFade = true;
	if (fFade) {
		if (id.filters.blendTrans)
		var status = id.filters.blendTrans.status;
		if (status != 0) fFade = false;
		else id.filters[0].apply();
		}
	if (file != null) id.src = file;
	if (fFade) {
		id.filters.blendTrans.duration = nSec;
		id.filters[0].play();
		}
	}

var clib_rgSlideShow = new Array();
var clib_nrgSlideShow = 0;

function clib_slideShowType(id,nrg,interval,fade,fRandom,fReverse,callback,wLast,hLast) {
	this.members = 'id,rgImg,nrg,irg,interval,fade,fRandom,fReverse,fLoading,nShown,idTimeout,fPause,callback,wLast,hLast,fShowingBlank,imgBlank';
	this.id = id;
	this.rgImg = new Array();
	this.nrg = nrg;
	this.irg = 0;
	this.interval = interval;
	this.fade = (fade == null ? 0 : fade);
	this.fRandom = fRandom;
	this.fReverse = fReverse;
	this.fLoading = false;
	this.nShown = 0;
	this.idTimeout = null;
	this.fPause = false;
	this.callback = callback;
	this.wLast = wLast;
	this.hLast = hLast;
	this.imgBlank = null;
	this.fShowingBlank = false;
	}

function clib_slideShowShuffle(is,fSkipFirst) {
	function swap(i,j) {
		var tempi = rg[i];
		var tempj = rg[j];
		rg[i] = tempj;
		rg[j] = tempi;
		}
	if (fSkipFirst == null) fSkipFirst = false;
	var rg = clib_rgSlideShow[is].rgImg;
	var i = rg.length;
	if ( i == 0 ) return;
	if (fSkipFirst) {
		swap(rg.length-1,0);
		i--;
		}
	while ( --i ) {
		var j = Math.floor( Math.random() * ( i + 1 ) );
		swap(i,j);
		}
	if (fSkipFirst) swap(rg.length-1,0);
	}

function clib_slideShow(id,rgUrl,nrgUrl,interval,fade,fRandom,fReverse,callback,wInit,hInit,imgBlank) {
	if (fRandom == null) fRandom = false;
	if (fReverse == null) fReverse = false;
	var hn = clib_nrgSlideShow++;
	clib_rgSlideShow[hn] = new clib_slideShowType(id,nrgUrl,interval,fade,fRandom,fReverse,callback,wInit,hInit,imgBlank);
	var s = clib_rgSlideShow[hn];
	if ((wInit == null) && clib_isObject(rgUrl[0])) wInit = rgUrl[0].w;
	if ((hInit == null) && clib_isObject(rgUrl[0])) hInit = rgUrl[0].h;
	s.wLast = wInit;
	s.hLast = hInit;
	if (clib_isString(imgBlank)) {
		s.imgBlank = new Image();
		s.imgBlank.src = imgBlank;
		}
	for (var i = 0; i < nrgUrl; i++) {
		var url = null;
		var w = null;
		var h = null;
		if (clib_isObject(rgUrl[i])) {
			url = rgUrl[i].url;
			w = rgUrl[i].w;
			h = rgUrl[i].h;
			}
		else url = rgUrl[i];
		var x = 'clib_rgSlideShow[' + hn + '].rgImg[' + i + '].status = ';
		s.rgImg[i] = new clib_imageType(url,x + 'true', x + 'false', x + 'false',w,h);
		s.rgImg[i].image.src = url;
		}
	if (fRandom) clib_slideShowShuffle(hn,true);
	s.idTimeout = setTimeout('clib_doSlideShow(' + hn + ')',interval);
	return hn;
	}

function clib_doSlideShow(hn,irg) {
	if ((hn == null) || (hn < 0) || (hn >= clib_rgSlideShow.length)) return false;
	var s = clib_rgSlideShow[hn];
	s.fLoading = true;
	if (s.idTimeout != null) { clearTimeout(s.idTimeout); s.idTimeout = null; }
	for (var j = 0; j < s.nrg; j++) {			// go through array looking for a loaded picture, skipping errors
		if (!clib_isNumber(irg)) {
			irg = s.irg + j + (s.fReverse ? -1 : 1);
			if (irg >= s.nrg) irg = 0;
			else if (irg < 0) irg = s.nrg-1;
			}
		var status = s.rgImg[irg].status;
		if (status == null) {
			if (s.rgImg[irg].image.complete) {
				status, s.rgImg[irg].status = true;
				}
			else if (!s.fRandom) {								// if not fRandom do nothing and wait for it to load
				s.idTimeout = setTimeout('clib_doSlideShow(' + hn + ')',100);
				if (s.callback != null) eval(s.callback);
				return;
				}
			}
		if (status == true) {					// image is ready
			var time = s.fade;
			var msNextPic = s.interval;
			if (s.fShowingBlank) {				// last image was blank
				irg = s.irg;
				time = time/2;
				s.wLast = s.rgImg[irg].w;
				s.hLast = s.rgImg[irg].h;
				s.fShowingBlank = false;
				}
			var url = s.rgImg[irg].url;
			var w = s.rgImg[irg].w;
			var h = s.rgImg[irg].h;
			if ((time > 0) && ((s.rgImg[irg].w != s.wLast) || (s.rgImg[irg].h != s.hLast))) {	// next image is a different size
				time = time/2;
				if (s.imgBlank != null) url = s.imgBlank.src;
				msNextPic = Math.floor(time * 1000 + 50);
				w = s.wLast;
				h = s.hLast;
				s.fShowingBlank = true;
				}
			clib_swapImage(s.id,url,time,w,h);
			s.wLast = w;
			s.hLast = h;		
			if (!s.fShowingBlank) s.nShown++;
			s.fLoading = false;
			s.irg = irg;
			if (s.fRandom) if (s.nShown % s.nrg == 0) clib_slideShowShuffle(hn);
			if (!s.fPause) {
				s.idTimeout = setTimeout('clib_doSlideShow(' + hn + ')',msNextPic);
				}
			if (s.callback != null) eval(s.callback);
			return;
			}
		// else if (status == false) {}			// try next pic because this had error or was not ready and fRandom is set
		}
	if (!s.fPause) {
		s.idTimeout = setTimeout('clib_doSlideShow(' + hn + ')',s.interval);
		}
	if (s.callback != null) eval(s.callback);
	return;
	}

function clib_slideShowControl(hn,fPause,interval,fade,fRandom,fReverse) {
	if ((hn == null) || (hn < 0) || (hn >= clib_rgSlideShow.length)) return false;
	var s = clib_rgSlideShow[hn];
	if (interval != null) s.interval = interval;
	if (fade != null) s.fade = fade;
	if (fRandom != null) s.fRandom = fRandom;
	if (fReverse != null) s.fReverse = fReverse;
	if ((fPause != null) && (fPause != s.fPause)) {
		s.fPause = fPause;
		if (fPause) if (s.idTimeout!= null) { clearTimeout(s.idTimeout); s.idTimeout = null; return;}
		clib_doSlideShow(hn);
		}
	}

function clibx_sirType(name) {
	this.members = 'name,url';
	this.name = name;
	this.url = null;
	}
var clibx_rgSir = new Array();
var clibx_nrgSir = 0;

function clib_swapImageRandom(nameList,fileList,nSec) {
	function irgSir(name) {
		for (var i = 0; i < clibx_nrgSir; i++) if (clibx_rgSir[i].name == name) return i;
		clibx_rgSir[clibx_nrgSir++] = new clibx_sirType(name);
		return (clibx_nrgSir - 1);
		}
	var rgn = nameList.split(",");
	var rgf = fileList.split(",");
	if ((rgn.length <= 1) && (rgf.length <= 1)) return clib_swapImage(nameList,fileList,nSec);
	var iname = Math.floor(Math.random()*rgn.length);
	var name = rgn[iname];
	var iurl = Math.floor(Math.random()*rgf.length);
	var url = rgf[iurl];
	var last = clibx_rgSir[irgSir(name)];
	if ((rgf.length > 1) && (last.url == url)) {
		iurl++;
		if (iurl >= rgf.length) iurl = 0;
		url = rgf[iurl];
		}
	last.url = url;
	clib_swapImage(name,url,nSec);
	}

function clib_mouseoverLinkHTML(name,url,classN,classHL) {
	url = clib_unhideUrl(url);
	var id = clib_newElementId();
	var html = '<a onmouseover="' + "clib_changeClass('" + id + "','" + classHL + "')" + '" ';
	html += 'onmouseout="' + "clib_changeClass('" + id + "','" + classN + "')" + '" ';
	html += 'href="' + url + '"><p id=' + id + ' class=' + classN + '>' + name + '</p></a>';
	return html;
	}

function clib_mouseoverImageHTML(url, imgN,imgHL, align, w,h, classN,classHL,onclick,onover,onout,alt,target) {
	url = clib_unhideUrl(url);
	imgN = clib_unhideUrl(imgN);
	imgHL = clib_unhideUrl(imgHL);
	var fLink = (url != null);
	var fClass = ((classN != null) && (classN != ''));
	var fSwapClass = (fClass && ((classHL != null) && (classHL != '')));
	var id = clib_newElementId();
	var html = ( fLink ? '<a ' : '<img id=' + id + ( fClass ? ' class=' + classN  : '' )) + ' onmouseover="';
	if (onover != null) html += onover + ';';
	if (fSwapClass) html += "clib_changeClass('" + id + "','" + classHL + "');";
	html += "clib_swapImageRandom('" + id + "','" + imgHL + "')" + '" onmouseout="';
	if (onout != null) html += onout + ';';
	if (fSwapClass) html += "clib_changeClass('" + id + "','" + classN + "');";
	html += "clib_swapImage('" + id + "','" + imgN + "')" + '" ';
	html += (target == null ? '' : 'target="' + target + '" ');
	if (fLink) html += 'href="' + url + '"><img id=' + id + (fClass ? ' class=' + classN + ' ' : ' ' );
	html += 'src="' + imgN + '"' + ( w!= null ? ' width=' + w : '' ) + ( h!= null ? ' height=' + h : '' );
	html += (onclick != null ? ' onclick="' + onclick + '"' : '' ) + (align != null ? ' align=' + align : '') + ' border=0';
	html += (alt == null ? '' : ' alt="' + alt + '"');
	html += '>' + (fLink ? '</a>' : '' );
	return html;
	}

function clib_openWin(url,windowName,params) {
	url = clib_unhideUrl(url);
	if (clib_fLocal) debugFunction(true);
	return clib_newWindow(url,windowName,params);
	}

function clib_newWindow(url,windowName,params) {
	url = clib_unhideUrl(url);
	var id;
	if (windowName == null) windowName = "_new";
	var openString = 'id=wind' + 'ow.op' + 'en(';
	if (params==null) openString += 'url,windowName)';
	else openString += 'url,windowName,params)';
	eval(openString);
	id.focus();
	return id;
	}

// popup magic ***************************************************************************************************
//

var clibx_rgWindowId = new Array();
var clibx_nrgWindowId = 0;
var clibx_iWindowName = 0;

function clib_popupImage(url,urlz,wWin,hWin,title,bgColor) {
	url = clib_unhideUrl(url);
	urlz = clib_unhideUrl(urlz);
	if (clib_isNull(title)) title = url;
	if (clib_isNull(bgColor)) bgColor = "white";
	var s = clibx_getPopupWindowInfo(wWin,hWin);
	var html = '<table border=0 cellpadding=0 cellspacing=0 width="100%" height="80%"><tr><td align=center valign=middle>';
	if (urlz != null) html += '<a href="' + urlz + '" target=_blank>';
	html += '<img src="' + url + '" alt="' + title + '" border=0>';
	if (urlz != null) html += '</a><br>(click on image to zoom)';
	html += '</td></tr></table>';
	html = clibx_getPopupHtml(title,null,' bgcolor=' + bgColor,html,s.fFullScreen);
	var id = clib_newWindow("",s.name,s.params);
	clibx_rgWindowId[clibx_nrgWindowId++] = id;
	if (s.fNeedResize) {
		id.moveTo(s.wLoc,s.hLoc);
		id.resizeTo(s.wWin,s.hWin);
		id.document.write(html);
		id.moveTo(s.wLoc,s.hLoc);
		}
	else id.document.write(html);
	id.focus();
	return id;
	}

function clib_popupPage(url,wWin,hWin,title) {
	url = clib_unhideUrl(url);
	if (clib_isNull(title)) title = url;
	var s = clibx_getPopupWindowInfo(wWin,hWin);
	var id = clib_newWindow(url,s.name,s.params);
	clibx_rgWindowId[clibx_nrgWindowId++] = id;
	if (s.fNeedResize) {
		id.moveTo(s.wLoc,s.hLoc);
		id.resizeTo(s.wWin,s.hWin);
		id.moveTo(s.wLoc,s.hLoc);
		}
	id.focus();
	return id;
	}

function clib_popupHtml(html,wWin,hWin,params) {
	if (clib_isNull(html)) html = '<html><body><h1>no html</h1></body></html>';
	var s = clibx_getPopupWindowInfo(wWin,hWin);
	if (params == null) params = s.params;
	var id = clib_newWindow("",s.name,params);
	clibx_rgWindowId[clibx_nrgWindowId++] = id;
	if (s.fNeedResize) {
		id.moveTo(s.wLoc,s.hLoc);
		id.resizeTo(s.wWin,s.hWin);
		id.document.write(html);
		id.moveTo(s.wLoc,s.hLoc);
		}
	else id.document.write(html);
	id.focus();
	return id;
	}

function clibx_getPopupHtml(title,head,bodyP,bodyH,fFullScreen) {
	var html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">\n';
	html += '<html>\n<head>\n<title>' + title + '</title>\n';
	html += '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\n';
	html += '<meta name="Author" content="' + clibx_getFunctionName(clibx_getPopupHtml.caller) + '()">\n';
	if (head != null) html += head + '\n';
	if (fFullScreen) {
		html += '<sty' + 'le>\n';
		html += '.closeButton { cursor:pointer; font-size:10px; color:black; background-color:white; border-type:inset; border-width:3px; border-color:gray; margin:0px; }\n';
		html += '</style>\n';
		}
	html += '</head>\n<body' + (bodyP == null ? '' : ' ' + bodyP) + '>\n';
	if (fFullScreen) {
		html += '<table border=0 cellpadding=0 cellspacing=0 width="100%">';
		html += '<tr><td align=right><button class=closeButton onclick="window.close()">CLOSE</button></td></tr></table>';
		}
	if (bodyH != null) html += bodyH;
	html += '\n</body>\n</html>\n';
	return html;
	}

function clibx_popupWindowInfoType(wWin,hWin,wLoc,hLoc,fFullScreen,fNeedResize,name,params) {
	this.members = 'wWin,hWin,wLoc,hLoc,fFullScreen,fNeedResize,name,params';
	this.wWin = wWin;
	this.hWin = hWin;
	this.wLoc = wLoc;
	this.hLoc = hLoc;
	this.fFullScreen = fFullScreen;
	this.fNeedResize = fNeedResize;
	this.name = name;
	this.params = params;
	}

function clibx_getPopupWindowInfo(wWin,hWin,fFullScreenOK) {
	if (fFullScreenOK == null) fFullScreenOK=false;
	var xMax = clib_screenX();
	var yMax = clib_screenY();
	var wLoc,hLoc;
	if (wWin == "*") { wWin = xMax; wLoc = 0; }
	else {
		if (wWin == null) wWin = clib_windowX();
		else wWin = Math.max(200,Math.min(wWin,xMax-70)) + 60;
		wLoc = Math.floor((xMax - wWin)/2) + 20;
		}
	if (hWin == "*") { hWin = yMax; hLoc = 0; }
	else {
		if (hWin == null) hWin = clib_windowY();
		else hWin = Math.max(200,Math.min(hWin,yMax-90)) + 80;
		hLoc = Math.floor((yMax - hWin)/2);
		}
	var fFullScreen = (fFullScreenOK && (wWin == xMax) && (hWin == yMax));
	var fNeedResize = (!fFullScreen && (wWin == xMax) && (hWin == yMax));
	var params = '';
	if (fFullScreen) params += 'fullscreen=yes';
	else {
		params += 'width=' + wWin + ', height=' + hWin + ', top=' + hLoc + ', left=' + wLoc;
		params += ', titlebar=no, status=no, location=no, menu=yes, toolbar=no, dependent=yes, scrollbars=yes, resizable=yes';
		}
	var windowName = '_new_' + clibx_iWindowName++;
	return new clibx_popupWindowInfoType(wWin,hWin,wLoc,hLoc,fFullScreen,fNeedResize,windowName,params);
	}

function clib_closeAllPopups() {
	for (var i = 0; i < clibx_nrgWindowId; i++) clibx_rgWindowId[i].close();
	}

function clib_showConfirm(msg,callback) {
	if (callback == null) return window.confirm(msg);
	else if (!clib_fUseAlert) eval(callback + '(' + confirm(msg) + ')');
	else clib_showAlert(msg,null, null,null, true, callback);
	}

function clib_focus(name) {
	var id=clib_getElementId(name);
	if (id != null) id.focus();
	}

function clib_showPicWithLink(t,w,h,link,fCenter) {
	if (fCenter == null) fCenter = false;
	var xid;
	var s = clib_newWindowDim(w,h);
	var params = 'width=' + s.w + ',height=' + s.h + ',scrollbars=yes,resizable=yes';
	if (link == null) {
		xid=clib_newWindow(t,'_pic',params);
		if (fCenter) xid.moveTo(s.x,s.y);
		xid.resizeTo(s.w,s.h);
		}
	else {
		xid=clib_newWindow("",'_pic',"replace," + params);
		if (fCenter) xid.moveTo(s.x,s.y);
		xid.resizeTo(s.w,s.h);
		var html = '<HTML><HEAD><TITLE>' + t + '</TITLE></HEAD><BODY>\n';
		html += '<center><a href="' + link + '"><img src="' + t + '" border=0></a></center>\n';
		html += '</BODY></HTML>\n';
		xid.document.write(html);
		}
	xid.focus();
	return xid;
	}

function clib_openWinWithHtml(name,w,h,html) {
	var xid;
	var s = clib_newWindowDim(w,h);
	var params = 'width=' + s.w + ',height=' + s.h + ',scrollbars=yes,resizable=yes';
	xid=clib_newWindow("",name,"replace," + params);
	xid.document.write(html);
	xid.moveTo(s.x,s.y);
	xid.resizeTo(s.w,s.h);
	xid.focus();
	return xid;
	}

var clib_spUrl = null;
var clib_spW = null;
var clib_spH = null;

function clib_showPicUrl() {
	if (clib_spUrl == null) return;
	clib_showPicWithLink(clib_spUrl,clib_spW,clib_spH,null,true);
	clib_spUrl = null;
	clib_spW = null;
	clib_spH = null;
	}

function clib_showPic(img,msg,wImg,hImg,url,wUrl,hUrl,onClose,tableClass,onPrev,urlPrev,onNext,urlNext,onUrl) {
	img = clib_unhideUrl(img);
	if (img == null) return;
	if (!clib_fUseAlert) return clib_showPicWithLink(img,wImg,hImg);
	if (msg == null) msg = '&nbsp;';
	if (wImg == null) wImg = 600;
	if (hImg == null) hImg = 400;
	var fPrevNext = ((onNext != null) || (onPrev != null));
	var fgDismiss = (!fPrevNext && (url == null));
	clib_spUrl = url;
	clib_spW = wUrl;
	clib_spH = hUrl;
	var html = '';
	if (fgDismiss) html += '<a onClick="clib_hideAlert()" href="javascript:clib_hideAlert()" style="cursor:pointer; text-decoration:none">';
	html += '<table align="center"';
	if (clib_isString(tableClass)) html += ' class=' + tableClass;
	else html += ' style="border-style:double; border-color:#CCCCCC; border-width:6px; background-color:#CCCCCC"';
	html += ' border=0 width=' + wImg + '>';
	html += '<tr><th width="5%">&nbsp;</th><th width="10%">';
	if (onPrev != null) {
		if (urlPrev != null) html += '<img src="' + urlPrev + '" onclick="' + onPrev + '" border=0 style="cursor:pointer;">';
		else html += '<button onclick="' + onPrev + '" style="cursor:pointer;font-size:10px;font-weight:normal;">prev</button>';
		}
	html += '</th><th width="70%" align=center><font color="#000000">' + msg + '</font></th><th width="10%">';
	if (onNext != null) {
		if (urlNext != null) html += '<img src="' + urlNext + '" onclick="' + onNext + '" border=0 style="cursor:pointer;">';
		else html += '<button onclick="' + onNext + '" style="cursor:pointer;font-size:10px;font-weight:normal;">next</button>';
		}
	html += '</th><th align="center" width="5%">';
	if (!fgDismiss) html += '<a onClick="clib_hideAlert()" href="javascript:clib_hideAlert()" style="cursor:pointer;text-decoration:none;">';
	html += '<button style="cursor:pointer;color:white;background-color:#D82C38;font-size:8px;font-weight:bold;">X</button>';
	if (!fgDismiss) html += '</a>';
	html += '</th></tr>';
	html += '<tr><td colspan=5 align="center">';
	if (fPrevNext && (url != null)) html += '<a onClick="clib_hideAlert()" href="javascript:clib_hideAlert()" style="cursor:pointer;text-decoration:none;">';
	html += '<img src="' + img + '" border=0 width=' + wImg + ' height=' + hImg + ' style="cursor:';
	if (url == null) html += 'default">';
	else html += 'pointer" onclick="' + (onUrl == null ? 'clib_showPicUrl()' : onUrl) + '">';
	if (fPrevNext && (url != null)) html += '</a>';
	html += '</td></tr></table>';
	if (fgDismiss) html += '</a>';
	clib_innerHTML(clib_alertDiv,html);
	clibx_onAlertClose = onClose;
	clibx_placeAlert(true,wImg,hImg);
	}

function clibx_placeAlert(fInit,w,h) {
	if (!fInit && !clibx_fAlert) return;
	var xW,yW,xO,yO;
	if (fInit) {
		clibx_wAlert = w;
		clibx_hAlert = h;
		}
	if (window.innerWidth == null) {	// IE 4+
		xW = document.body.clientWidth;
		xO = document.body.scrollLeft;
		yW = document.body.clientHeight;
		yO = document.body.scrollTop; 
		}
	else {								// NS 4+
		xW = window.innerWidth;
		xO = window.pageXOffset;
		yW = window.innerHeight;
		yO = window.pageYOffset;
		}
	var x = Math.max(20,Math.floor((xW-clibx_wAlert)/2) + xO); 
	var y = Math.max(20,Math.floor((yW-clibx_hAlert-100)/2) + yO);
//	clib_innerHTML('id_debugalert',x + ',' + y + ' / ' + clibx_xAlert + ',' + clibx_yAlert);
	if (fInit || (x != clibx_xAlert) || (y != clibx_yAlert)) {
		clibx_xAlert = x;
		clibx_yAlert = y;
		if (clib_placeDiv(clib_alertDiv,clibx_xAlert ,clibx_yAlert, 999, true)) {
			clib_fUseAlert = false;
			clibx_fAlert = false;
			}
		else setTimeout("clibx_fAlert=true",10);
		clib_focus(clib_alertDiv);
		fInit = false;
		}
	if (clib_fUseAlert) setTimeout('clibx_placeAlert(false)',50);
	return;
	}

var clibx_onAlertClose = null;
var clibx_fAlert = false;
var clibx_xAlert = null;
var clibx_yAlert = null;
var clibx_wAlert = null;
var clibx_hAlert = null;
var clibx_callback = null;
var clibx_fYesNo = null;
var clibx_fCallback = null;

function clib_showAlertStyleType () {
	this.members = 'aEnclosure,tEnclosure,sMessage,button';
	this.aEnclosure = "cursor:pointer; text-decoration:none";
	this.tEnclosure = "";
	this.sMessage = "";
	this.button = "cursor:pointer;width:40px;font-size:xx-small;background-color:silver;color:black;border:3px outset";
	}
var clib_showAlertStyle = new clib_showAlertStyleType ();

function clib_showAlert(msg1,msg2,img1,img2,fYesNo,callback) {
	if (msg1 == null) return;
	else if (msg1 == "") return;
	var s = clib_showAlertStyle;
	if (fYesNo == null) fYesNo = false;
	if (img1==null) img1 = (fYesNo ? clib_urlQuestion : clib_urlCaution);
	if (img2==null) img2 = (fYesNo ? clib_urlQuestion : clib_urlCaution);
	clibx_fYesNo = fYesNo;
	clibx_callback = callback;
	clibx_fCallback = null;
	if (clib_fUseAlert) {
		var x,y,xO,yO;
		var html = '';
		html += '<a onClick="clib_hideAlert();" href="javascript:clib_hideAlert()" style="' + s.aEnclosure + '">\n';
		html += '<table border=0 cellpadding=0 cellspacing=0 align=center><tr><td>';
		html += '<img id=clib_a_topleft border=0 width=1 height=1 src="' + clib_homePrefix + 'blank.gif"></td></tr><tr><td>';
		html += '<table align="center" width="' + clib_alertx + '"' + (s.tEnclosure == "" ? ' bgcolor="#CCCCCC" border=1' : '" style="' + s.tEnclosure + '"') + '>';
		html += '<tr><td align="center" valign="middle">\n';
		html += '<table border="0" align=center width="90%"><tr><td align="left" valign="middle"><font color="#000000"><span style="' + s.sMessage + '">\n\n';
		html += clib_convertAlertText(msg1,true);
		html += '\n\n</span></font></td></tr></table>';
		html += '</td><td align=center valign="middle" width="' + clib_alertx2 + '">';
		html += '<br><img src="' + img1 + '" border=0 onclick="clib_hideAlert()" style="cursor:pointer"><br><br>';
		if (fYesNo) {
			html += '<button style="' + s.button + '" onclick="clibx_fCallback = true;">Yes</button><br><br>';
			html += '<button style="' + s.button + '" onclick="clibx_fCallback = false;">No</button><br>&nbsp;';
			}
		else {
			html += '<button style="' + s.button + '" onclick="clib_hideAlert()">OK</button><br>&nbsp;';
			}
		html += '</td></tr></table>\n';
		html += '</td></tr><tr><td align=right>';
		html += '<img align=right id=clib_a_bottomright border=0 width=1 height=1 src="' + clib_homePrefix + 'blank.gif">';
		html += '</td></tr></table></a>\n';
		clib_innerHTML(clib_alertDiv,html);
		var tl = clib_objDimensions(clib_getElementId('clib_a_topleft'));
		var br = clib_objDimensions(clib_getElementId('clib_a_bottomright'));
		var wAlertBox = clib_alertx;
		var hAlertBox = 200;
		function checkNums(tl,br) {
			if ((tl == null) || (br == null)) return false;
			if ( isNaN(tl.left) || isNaN(tl.top) || isNaN(br.left) || isNaN(br.top) ) return false;
			return true;
			}
		if (checkNums(tl,br)) {
			wAlertBox = Math.max(wAlertBox,br.left-tl.left);
			hAlertBox = Math.max(hAlertBox,br.top-tl.top);
			}

		clibx_placeAlert(true,wAlertBox,hAlertBox);
		if (clib_fUseAlert) {		// might have been set false due to error
			if (msg2 != null) {
				clib_alertMsg2 = msg2;
				clib_alertImg2 = img2;
				}
			}
		}
	if (!clib_fUseAlert) {
		var m = clib_convertAlertText(msg1,false);
		if (m == "") return;
		alert(m);
		focus();
		m = clib_convertAlertText(msg2,false);
		if (m == "") return;
		alert(m);
		focus();
		if (clib_fDebug) clib_fUseAlert=!clib_fUseAlert;
		}
	}

function clib_convertAlertText(sb,fHtml) {
	var m = "";
	if (sb == null) return m;
	if (sb == "") return m;
	var iStart = 0;
	if (sb.charAt(iStart) == '!') {
		if (!fHtml) return m;
		else iStart++;
		}
	for (var i = iStart; i < sb.length; i++) {
		if (sb.charAt(i) == '~') {
			if (fHtml) m += '<br>';
			else m += '\n';
			}
		else if ((!fHtml) && (i + 3 < sb.length) && (sb.charAt(i) == '<') && (sb.charAt(i+1) == 'b') && (sb.charAt(i+2) == 'r') && (sb.charAt(i+3) == '>')) {
			m += '\n';
			i += 3;
			}
		else m += sb.charAt(i);
		}
	return m;
	}

function clib_hideAlert(fReturn) {
	if (!clibx_fAlert) return;
	if (fReturn == null) fReturn = false;
	clibx_fAlert = false;
	if (clibx_fYesNo) {
		clibx_fYesNo = false;
		eval(clibx_callback + '(' + (fReturn ? true : clibx_fCallback) + ')');
		clibx_callback = null;
		clibx_fCallback = null;
		}
	if (clibx_onAlertClose != null) eval(clibx_onAlertClose);
	clibx_onAlertClose = null;
	if (clib_fUseAlert) {
		clib_placeDiv(clib_alertDiv,0,0,0,false);
		if (clib_alertMsg2 != null) clib_showAlert(clib_alertMsg2,null,clib_alertImg2,null);
		clib_alertMsg2 = null;
		}
	}

function clib_nbsp(str) {
	if ((str == null) || (str == '')) return str;
	var rgStr = str.split(' ');
	if (rgStr.length <= 1) return str;
	var nbspStr = rgStr[0];
	for (var i = 1; i < rgStr.length; i++) nbspStr += '&nbsp;' + rgStr[i];
	return nbspStr;
	}

function clib_initCookies(fLog) {
	if (fLog == null) fLog = false;
	clib_fCookieLog = fLog;
	clib_fNoCookies = false;
	var i,j,tok,loc;
	if ((i = document.cookie.toLowerCase().indexOf('aspsessionid')) != -1) {
		j = document.cookie.indexOf('=',i);
		tok = document.cookie.substr(i,(j-i));
		clib_setCookie(tok,0);
		}
	if (!fLog) return;
	loc = "!" + window.parent.document.location; loc = loc.substr(1); loc=loc.toLowerCase();
	i = loc.indexOf(clib_website);
	if (i == -1) { if (loc.length == 0) loc = "badLocation"; }
	else {
		loc = loc.substr(i + clib_website.length);
		if (loc.length < 2) loc = clib_website;
		}
	if (loc == clib_website) loc = '/index.html';
	n = parseInt(clib_getCookie(loc),10);
	if (isNaN(n)) n=1;
	else n++;
	clib_setCookie(loc,n);
	}

function clib_logCookie(logEvent,text) {
	if (clib_fNoCookies || !clib_fCookieLog) return;
	var x = clib_getCookie(logEvent);
	if (x == null) x = "";
	x = x + '/' + text;
	clib_setCookie(logEvent,x,'/');
	}


function clib_getCookie(id) {
	if (clib_fNoCookies) return null;
	var offset,end;
	var val=null;
	var search = id + "=";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			val = unescape(document.cookie.substring(offset, end));
			return val;
			}
		}
	return val;
	}

function clib_deleteCookie(name, path) {
	if (clib_fNoCookies) return;
	if (path==null) path = "/";
	var param = name + "=; expires=-10; path=" + escape(path);
	document.cookie = param;
	}

function clib_setCookie(name, value, path) {
	if (clib_fNoCookies) return;
	if (path==null) path = "/";
	var today = new Date();
	var expire = new Date();
	expire.setTime(today.getTime() + 1000*60*60*24*365);
	var param =  name + "=" + escape(value) + "; expires=" + expire.toGMTString();
	if (path != "") param += "; path=" + escape(path);
	document.cookie = param;
	}

function clib_initDivs() {
	clib_fUseAlert = true;
	clib_urlCaution = clib_homePrefix + clib_imageLoc + clib_urlCautionSuffix;
	clib_urlQuestion = clib_homePrefix + clib_imageLoc + clib_urlQuestionSuffix;
	var html = '<div id="' + clib_alertDiv + '"';
	html += ' style="position:absolute;top:15;left:15;text-align:left;color:gray;border-color:gray;height:0;width:0;visibility:hidden;"';
	html += '>&nbsp;</div>';
	document.write(html);
	}

function clib_getMonthName(d) {
	if (d == null) d = new Date();
	return clib_rgMonths[d.getMonth()];
	}

function clib_daysUntil(d) {
	var todayDate = new Date();
	var eventDate = new Date(d);
	if (( todayDate.getMonth() == eventDate.getMonth() ) && ( todayDate.getYear() == eventDate.getYear() ))
		return eventDate.getDate() - todayDate.getDate();
	todayDate = new Date( (todayDate.getMonth() + 1) + '/' + (todayDate.getDate()) + '/' + todayDate.getFullYear());
	var msDay = 1000 * 60 * 60 * 24;
	var dToday = todayDate.getTime() / msDay;
	var dEvent = eventDate.getTime() / msDay;
	return Math.ceil(dEvent - dToday);
	}

function clib_debugList() {
	var args = clib_debugList.arguments;
	var nargs = args.length;
	var msg = '(';
	for (var i = 0; i < nargs; i++) {
		if (i > 0) msg += ',';
		msg += args[i];
		}
	msg += ')';
	var id = clib_getElementId('debugdiv');
	if (id == null) alert(msg);
	else clib_innerHTML('debugdiv',msg);
	}

function clibx_getFunctionName(f) {
	if (clib_isNull(f)) return null;
	var txt = f + ' ';
	var rg = txt.split('(');
	if (rg.length > 0) txt = rg[0]; else return null;
	rg = txt.split('function ');
	if (rg.length > 0) return rg[1]; else return txt;
	}

var clib_htmlDebugLog = '';

function clib_debugLog(msg) {
	clib_htmlDebugLog += msg + '<br>';
	clib_innerHTML('debugdiv',clib_htmlDebugLog);
	}

function clib_debugFunction(f,xtraMsg) {
	if (f == null) f = false;
	if (!f && !clib_fDebug) return;
	var rgF = new Array();
	var nrgF = 0;
	var msg = 'debug function ';
	var fn = clib_debugFunction.caller;
	var c = clibx_getFunctionName(fn);
	var fFirst = true;
	var i;
		while (c != null) {
		rgF[nrgF] = c + '(';
		for (i = 0; i < fn.arguments.length; i++) {
			if (i > 0) {
				rgF[nrgF] += ', ';
				}
			rgF[nrgF] += fn.arguments[i];
			}
		rgF[nrgF] += ')';
		fn = fn.caller;
		c = clibx_getFunctionName(fn);
		fFirst = false;
		nrgF++;
		}
	for (i = nrgF-1; i >= 0; i--) msg += rgF[i] + (i > 0 ? ' --->' : '') +'\n';
	if (xtraMsg != null) msg = xtraMsg + '\n' + msg;
	var id = clib_getElementId('debugdiv');
	if (id == null) alert(msg);
	else clib_debugLog(msg);
	}

clib_initClibLibrary();
