/*
================================================
Copyright 2006 - present, Dan Satterfield
All Rights Reserved.
================================================
*/
/*
VERSION:
04/05/2011	1.0.6	Removed dependancy on lib_number.js library. Added object `Cookie`. Fixed problem where `setCookie` was not handling path properly.
07/29/2010	1.0.5.lite	Removed several fairly useless functions:
									disableRightClick, baseDir, EventHandler, getDocumentHeight, zebraStripe
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 domain() {
//returns the base url
var url = window.location.protocol + "//" + window.location.host + "/";
return url;
};
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');};

/* setCookie and getCookie are left for backward compatibility */
function setCookie(cookieName, cookieValue, expireDays, cookiePath) {
var exdate = new Date();
if(!isNaN(expireDays) && expireDays != '' && expireDays > 0) {
	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);
} else {
	exdate = new Date('01/01/1971');
}
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;
};

/* this object is a more succinct way to manipulate cookies */
function Cookie(key, path) {
	this.key = key;
	this.path = path === undefined ? '' : path;
	this.set = function(val, days) {
		setCookie(this.key, val, days, this.path);
		return val;
	};
	this.get = function() {
		return getCookie(this.key);
	};
	this.clear = function() {
		var str = getCookie(this.key);
		setCookie(this.key, '', 0);
		return str;
	};
};

function popup(url, attr) {
	if(typeof(attr) != 'object') {
		attr = {};
	}
	if(isNaN(attr['width'])) {
		attr['width'] = 640;
	}
	if(isNaN(attr['height'])) {
		attr['height'] = 480;
	}
	if(isNaN(attr['left'])) {
		attr['left'] = Math.floor((getScreenWidth() * .5) - (attr.width * .5));
	}
	if(isNaN(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 800; }
};
function getScreenHeight() {
	if (screen.height) { return screen.height }
	else if (screen.availHeight) { return screen.availHeight }
	else { return 600; }
};
