//Created by Sean Kane (http://celtickane.com/programming/code/ajax.php)
//Feather Ajax v1.0.0
// callback and error catch added by AGS

// Usage:
// var test = new AjaxObject();
// test.sndReq('post/get',url, params, callback)

function AjaxObject()
{
	this.createRequestObject = function()
	{
		var ro;
		var browser = navigator.appName;
		if ( browser == "Microsoft Internet Explorer")
		{
			try
			{
				ro = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				ro = new XMLHttpRequest();
			}
		}
		else
		{
			ro = new XMLHttpRequest();
		}
		return ro;
	}
	
	this.sndReq = function(action, url, params, callback)
	{
		if (action == 'post')
		{
			this.http.open('post',url);
			this.http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			this.http.send(params)
		}
		else
		{
			this.http.open('get',url+"?"+params);
		}
  
		this.http.onreadystatechange = function()
		{
			if (me.http.readyState == 4)
				eval(callback+"(me.http)");
			//if (me.http.readyState == 1) { document.getElementById('debug').innerHTML = "Loading..."; }
		}
		
		try
		{
			this.http.send(null);
		}
		catch(e)
		{
			// hide errors for now
			//alert("ajax error"+e);
		}
	}
	var me = this;
	this.http = this.createRequestObject();
}


function $() 
{
	var elements = new Array();

	for (var i = 0; i < arguments.length; i++) 
	{
		var element = arguments[i];
		if (typeof element == 'string')
		{
			element = document.getElementById(element);
		}
		
		if (arguments.length == 1) 
		{
			return element;
		}

		elements.push(element);
	}

	return elements;
}



function pageWidth()
{
	return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}
function pageHeight()
{
	return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;} function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;} function posTop() {return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

function centerId(id)
{
	var windowWidth = pageWidth();
	if (windowWidth > 800)
		$(id).style.left="112px";
	else
		$(id).style.left="0px";
//	var elementWidth = ($(id).style.width);
//	elementWidth = elementWidth.replace(/\D+/g, "");
//	var newLeft = Math.floor( (windowWidth-elementWidth)/2);
//	$(id).style.left=newLeft+"px";
}


function increaseHeight(id)
{
	window.onload=function()
	{
		var browserHeight=pageHeight();
		var idHeight=document.all[id].offsetHeight;	//should be ie specific but works with firefox
		if (idHeight*1 > browserHeight*1) return;
		browserHeight=(browserHeight*1-175);
		$(id).style.height=browserHeight+"px";
	}
}


function toggle(id)
{
	$(id).style.display= $(id).style.display=='none' ? '' : 'none';
}


function darkFaderIn(text,w,h)
{
	var newH= ((pageHeight()-h)/2) > 0 ? ((pageHeight()-h)/2) : h;
	var newW= ((pageWidth()-w)/2) > 0 ? ((pageWidth()-w)/2) : w;
	$('blackScreenText').style.width=w+"px";
	$('blackScreenText').style.height=h+"px";
	$('blackScreenText').style.left=newW+"px";
	$('blackScreenText').style.top=newH+"px";
	$('blackScreenText').innerHTML="<div style=\"height:"+(h-22)+"px; overflow: auto;\">"+text+"</div>";
	$('blackScreenText').innerHTML+="<div style=\"height:20px; text-align: right;\"><a href=\"#\" onclick=\"darkFaderOut();\">X Close</a>&nbsp;</div>";
	if ($('blackScreenText').show==false || !$('blackScreenText').show)
	{
		blinkOut('blackScreenText',0,100,500);
		blinkOut('blackScreenContainer',0,80,500);
		$('blackScreenText').show=true;
	}
}

function darkFaderOut()
{
	blinkOut('blackScreenText',100,0,500);
	blinkOut('blackScreenContainer',100,0,500);
	$('blackScreenText').show=false;
}

