/*
VERSION:
11/3/2008 	1.0.5	Added function `isNothing` (redundant) just in case the file lib_constant.js is not included.
7/24/2008	1.0.4 	Added function `disableRightClick`.
7/17/2008	1.0.3	Re-introduced a souped-up version of the function `popup`. 
					Also brought back functions `getScreenWidth` and `getScreenHeight`.
7/10/2008	1.0.2	getQS now returns an empty string if the query is not found.
3/13/2008	1.0.1	Updated baseDir to designate the level of the base directory.
			1.0.0	Begin versioning.
*/
function disableRightClick() {
if (document.layers){
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=function() {
		if (document.layers||document.getElementById&&!document.all){
			if (e.which==2||e.which==3){
				return false;
			}
		}		
	};
} else if (document.all&&!document.getElementById){
	document.onmousedown=function(){
		if (event.button==2){
			return false;
		}		
	};
}

document.oncontextmenu = new Function("return false");
};
function domain() {
	//returns the base url
	var url = window.location.protocol + "//" + window.location.host + "/";
	return url;
}
function baseDir(level) {
	//returns base url and the top level directory the current file resides in
	// example: if calling file resides in "http://www.test.com/files/test/index.htm"
	//		baseDir(0) returns "http://www.test.com/"
	//		baseDir(1) returns "http://www.test.com/files/"
	//		baseDir(2) returns "http://www.test.com/files/test/"
	var level = (typeof(level) != "number" || level < 0 ? 0 : level);	
	if(level == 0) { return domain(); }
	var url = window.location.pathname.split("/");
	url = url.slice(1, level+1);
	return domain() + url.join("/") + "/";
};
function go(url) { window.location.href=url; };
function dw(str) { document.write(str); };
function refresh() { window.location.href = window.location.href; };
function isEnterPress(evt) {
    var evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode :
        ((evt.which) ? evt.which : evt.keyCode);
    if (charCode == 13 || charCode == 3) {
        return true;
    } else {
        return false;
    }
};
function getQS(varName) {
	var qs = window.location.search;
	var rexp = new RegExp("("+varName+"=)","i");
	if ( varName == 0 ) { return qs; } // returns entire query string starting with ?
	else if ( qs.search(rexp) == -1 ) { return ''; } // can't find this variable name in query string
	else {
		rexp.compile("([\?|&]"+varName+"=)([^&]*)","gi");
		var arVal = qs.match(rexp); // returns an array of matching name=value pairs, i.e. ["test=1","test=2","test=3"]
		var thisStr = "";
		for (i in arVal) { // loop through previous compiled array
			if(typeof(arVal[i]) != "string") {
				continue;
			}
			arVal[i] = arVal[i] + "";
			thisStr = arVal[i].split("="); // split each name=value pair at =
			thisStr[1] = thisStr[1].replace(/\+/gi, ' '); //unescape doesn't recognize the + sign as a space
			arVal[i] = unescape(thisStr[1]); // reassign only the value to this spot in array
		}
		return arVal;
	}
};
function isNothing(v){return new String(v)==(''||'undefined'||'null');}
function setCookie(cookieName, cookieValue, expireDays, cookiePath) {
	var exdate = new Date();
	if(!isNothing(expireDays) && !isNaN(expireDays)) {
		var d = expireDays * 24; //days to hours
			d *= 60; //hours to minutes
			d *= 60; //minutes to seconds
			d *= 1000; //seconds to milliseconds
			exdate = new Date(exdate.valueOf() + d);
	}
	document.cookie = cookieName + "=" + escape(cookieValue) +
	";expires=" + exdate.toGMTString() +
	";path=" + (isNothing(cookiePath) ? "/" : cookiePath);
};
function getCookie(cookieName){
	if(document.cookie.length > 0) {
		c_start=document.cookie.indexOf(cookieName + "=")
		if (c_start != -1) { 
			c_start=c_start + cookieName.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 null;
};
function EventHandler() {
	this.arEvents = new Array();
	this.attach = function(executable) {
		//any string of valid javascript code
		this.arEvents.push(executable);
	}
	this.execute = function() {
		//to be called from the main event
		//such as window.onload
		//or as an inline script
		//such as after a form loads
		var i;
		var n = this.arEvents.length;
		for(i = 0; i < n; i++) {
			eval(this.arEvents[i]);
		};
		this.clearEvents(); //so it can't accidently be called twice
	}
	this.clearEvents = function() {
		this.arEvents.length = 0;
	}
};
function getDocumentHeight() {
	var docHeight;
	if (typeof document.height != 'undefined') {
		docHeight = document.height;
	} else if (document.compatMode && document.compatMode != 'BackCompat') {
		docHeight = document.documentElement.scrollHeight;
	} else if (document.body && typeof document.body.scrollHeight != 'undefined') {
		docHeight = document.body.scrollHeight;
	}
	return docHeight;
};
function popup(url, attr) {
	if(typeof(attr) != 'object') {
		attr = {};
	}
	if(!Math.isNumeric(attr['width'])) {
		attr['width'] = 640;
	}
	if(!Math.isNumeric(attr['height'])) {
		attr['height'] = 480;
	}
	if(!Math.isNumeric(attr['left'])) {
		attr['left'] = Math.floor((getScreenWidth() * .5) - (attr.width * .5));
	}
	if(!Math.isNumeric(attr['top'])) {
		attr['top'] = Math.floor((getScreenHeight() * .5) - (attr.height * .5)) - 40;
	}
	switch(attr['status']) {
		case 'no' : case 'yes' :
			break;
		default :
			attr['status'] = 'no';
	}
	switch(attr['toolbar']) {
		case 'no' : case 'yes' :
			break;
		default :
			attr['toolbar'] = 'no';
	}
	attr.scrollbars = 'yes';
	var a = [];
	for(var k in attr) {
		switch(typeof(attr[k])) {
			case 'string' : case 'number' :
			a.push(k + '=' + attr[k]);
			break;
		}
	}
	thisWin = window.open(url,"popup",a.join(','));
	thisWin.focus();
	return thisWin;
};
function getScreenWidth() {
	if (screen.width) { return screen.width }
	else if (screen.availWidth) { return screen.availWidth }
	else { return 640 }
};
function getScreenHeight() {
	if (screen.height) { return screen.height }
	else if (screen.availHeight) { return screen.availHeight }
	else { return 480 }
};
//-----------------------------------------------------------------------------------------
function zebraStripe(elemsArray) {
	elemsArray.each(function(s, i) {
		if(i % 2 == 0) { elemsArray[i].addClassName('alt'); }
	});
};