/*** Retrieves an element by id***/
function el(id) {return document.getElementById(id);}
/** Create an XML Request Object ***/
function ARO() {
	if(window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} 
	else if (window.ActiveXObject) { 
		return new ActiveXObject("Microsoft.XMLHTTP");  
	}
	else {
		return null;
	}
}
/** Performs an Ajax Req
	u=Url to request
	sf=suffessful fetch function defined as 
				function sf(respText) 
			where respText is the response text
	ff=failed fetch function defined as
				function ff(status)
			where status = request status
**/
function AjaxReq( u, sf, ff) {
	var ro=ARO();
	ro.onreadystatechange=function() {
		if(ro.readyState==4){
			if(ro.status==200) {
				sf(ro.responseText);
			}
			else {
				ff(ro.status);
			}
		}
	}
	ro.open('GET',u,true);
	ro.send(null);
}
/*** Attaches an event to an object
	n= name of event you are capturing (do not prefix with "on")
	e= object to add attach event to 
	f= function to call on event fire
	***/
function ae(n, e, f) { 
	if(e.addEventListener)
 { 
	e.addEventListener(n,f,false)} 
	else { e.attachEvent('on'+n,f)} 
}


//	Gets the left scroll position of the window
function scrollLeft() {
	return (document.all)?document.body.scrollLeft:window.pageXOffset; 
}

//	Gets the top scroll position of the window
function scrollTop() {
	return (document.all)?document.body.scrollTop:window.pageYOffset; 
}

//	Scrolls the window to the desired location
function ScrollWindowTo(x,y)
{
	window.scrollTo(x, y); 
}

//	Gets the client width of the window
//	Borrowed from http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}

//	Gets the client height of the window
//	Borrowed from http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}

//	filters width and height of client window
//	Borrowed from http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


function cookie_set( name,value,expires) {
	var exp=(expires==null?"":"; expires="+expires.toGMTString());
	document.cookie = name+"="+value+exp+"; path=/";
	
}


function LockPage(p) {
	var d=new String((document.URL?document.URL:document.url))
	d=d.substr(d.indexOf("//")+2);
	d=d.substr(d.indexOf("/"));	
	cookie_set(p,d);
}
function cookie_get(name) {
	name = name + "=";
	var all = document.cookie.split(';');
	for(var i=0;i < all.length;i++) {
		var c = new String(all[i]);
		c.replace(/^\s*/, '').replace(/\s*$/, ''); 
		if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
	}
	return null;
}

function cookie_clear(name) {
	createCookie(name,"",-1);
}
