

//-------------------------------------------------------------------------------
function go(url) { window.location.href=url; }

//-------------------------------------------------------------------------------
function dw(str) { document.write(str); }

//-------------------------------------------------------------------------------
function refresh() { window.location.href = window.location.href; }

//-------------------------------------------------------------------------------
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 false; } // 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
			arVal[i] = new String(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 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;
};

// DISABLE RIGHT (CTRL) CLICK---------------------------------------------
function clickIE4(){
	if (event.button==2){
		return false;
	}
};

function clickNS4(e){
	if (document.layers||document.getElementById&&!document.all){
		if (e.which==2||e.which==3){
			return false;
		}
	}
};

function disableRightClick() {
	if (document.layers){
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown=clickNS4;
	} else if (document.all&&!document.getElementById){
		document.onmousedown=clickIE4;
	}
	
	document.oncontextmenu = new Function("return false");
};

//-------------------------------------------------------------------------------
/*
	A simple event handler class that takes
	a string of javascript code as it's parameter
	and stores it until an event, usually window.onload,
	calls the execute method. Executes the scripts
	in the order they are attached.
*/
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
		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;
	}
};

// WINDOW & SCREEN FUNCTIONS

//------------------------------------------------------------------------------------------------------------------------------------------------------------
/*
	i'm sure there are much better ways to do this in
	prototype, but this has a much smaller footprint
	for apps that don't require complicated functions
*/
	
	function popup(url, xWidth, yHeight, x, y, statusB, toolB) {
		var statbar = (typeof(statusB) != "boolean" ? true : statusB); //statusB is a boolean value, optional, default true
			statbar = (statbar == false ? 'no' : 'yes');
		var toolbar = (typeof(toolB) != "boolean" ? "no" : toolB);
			toolbar = (toolbar == true ? "yes" : "no");
		var attr = "width="+xWidth+",height="+yHeight+",toolbar="+toolbar+",status="+statbar+",scrollbars";
		x = x - 0; y = y - 0; //convert to number
		if (x == -1 && y == -1) { attr += ",left=" + halfx(xWidth) + ",top=" + halfy(yHeight); }
		else if ( x == -1 ) { attr += ",left=" + halfx(xWidth) + ",top=" + y; }
		else if ( y == -1 ) { attr += ",left=" + x + ",top=" + halfy(yHeight); }
		else { attr += ",left=" + x + ",top=" + y; }
		thisWin = window.open(url,"popup",attr);
		try { thisWin.focus(); } catch(e) { }
	};

	function getWinWidth() {
		var winWidth = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
		    //Non-IE
		    winWidth = window.innerWidth;
		  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		    //IE 6+ in 'standards compliant mode'
		    winWidth = document.documentElement.clientWidth;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		    //IE 4 compatible
		    winWidth = document.body.clientWidth;
		  }
		  return winWidth;
	};
	function getWinHeight() {
		  var winHeight = 0;
		  if( typeof( window.innerWidth ) == 'number' ) {
		    //Non-IE
		    winHeight = window.innerHeight;
		  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		    //IE 6+ in 'standards compliant mode'
		    winHeight = document.documentElement.clientHeight;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		    //IE 4 compatible
		    winHeight = document.body.clientHeight;
		  }
			return winHeight;
  	};
	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 halfx(itemWidth) {
		return Math.ceil( (getWinWidth() / 2) - (itemWidth / 2) );
	};
	function halfy(itemWidth) {
		return Math.ceil( (getWinHeight() / 2) - (itemWidth / 2) );
	};