﻿/*** Retrieves an element by id***/
function el(id) {return document.getElementById(id);}
function ev(e) { return (window.event!=null?event:e);}
/** 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 CancelEvent(e)
{
		
	var f=ev(e);
	if(f && f.preventDefault)
	{
		f.preventDefault();
	}
	else
	{
		f.returnValue=false;
		f.cancel=true;
	}
}
function key(e) {return (window.event?e.keyCode:e.which);}
function SetDefaultButton(e,b)
{
	var k=key(e);
	if (k==13)
	{
		CancelEvent(e);
		el(b).click();
		return false;
    }
}
