/*
//	Derek's Basic JavaScript Library
//
//	Element Manipulation
*/

/*//---------------------------------------------*/
/*// Name: initPop(id)							 */
/*// Desc: Initializes Popup element			 */
/*//---------------------------------------------*/

function initPop(id,popup) {
	floatHide(id);
}

/*//---------------------------------------------*/
/*// Name: getElemPos(id)						 */
/*// Desc: Gets position of an element			 */
/*//---------------------------------------------*/

function getElemPos(id) {
	var dimReg = /([0-9\.]+)px/;
	var elem = document.getElementById(id);
	var top, left;
	if (elem.currentStyle) {
		top = dimReg.exec(elem.currentStyle["top"])[1];
		left = dimReg.exec(elem.currentStyle["left"])[1];
	} else {
		top = dimReg.exec(document.defaultView.getComputedStyle(elem,null).getPropertyValue("top"))[1];
		left = dimReg.exec(document.defaultView.getComputedStyle(elem,null).getPropertyValue("left"))[1];
	}
	top = Number(top);
	left = Number(left);
	return {top:top, left:left};
}

/*//---------------------------------------------*/
/*// Name: getWinDim()							 */
/*// Desc: Gets current window dimensions		 */
/*//---------------------------------------------*/

function getWinDim() {
	var width, height, scrollWidth, scrollHeight;
	if (typeof(window.innerWidth) == 'number') {
		width = window.innerWidth;
		height = window.innerHeight;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		width = document.documentElement.clientWidth;
		height = document.documentElement.clientHeight;
	} else if (document.body && ( document.body.clientWidth || document.body.clientHeight )) {
		width = document.body.clientWidth;
		height = document.body.clientHeight;
	}
	width = Number(width);
	height = Number(height);
	return {width:width, height:height};
}

/*//---------------------------------------------*/
/*// Name: getElemDim(id)						 */
/*// Desc: Gets current element dimensions		 */
/*//---------------------------------------------*/

function getElemDim(id) {
	var dimReg = /([0-9\.]+)px/;
	var elem = document.getElementById(id);
	var width, height;
	if (elem.currentStyle) {
		if (dimReg.exec(elem.currentStyle["height"]) == null)
			height = 250;
		else {
			height = dimReg.exec(elem.currentStyle["height"])[1];
		}
		width = dimReg.exec(elem.currentStyle["width"])[1];
	} else {
		if (dimReg.exec(document.defaultView.getComputedStyle(elem,null).getPropertyValue("height")) == null)
			height = 250;
		else {
			height = dimReg.exec(document.defaultView.getComputedStyle(elem,null).getPropertyValue("height"))[1];
		}
		width = dimReg.exec(document.defaultView.getComputedStyle(elem,null).getPropertyValue("width"))[1];
	}
	width = Number(width);
	height = Number(height);
	return {width:width, height:height};
}

/*//---------------------------------------------*/
/*// Name: getDocHeight()						 */
/*// Desc: Gets pixel height of entire document	 */
/*//---------------------------------------------*/

function getDocHeight() {
	var docHeight;
	if (window.innerHeight && window.scrollMaxY) {
		docHeight = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) {
		docHeight = document.body.scrollHeight;
	} else {
		docHeight = document.body.offsetHeight + document.body.offsetTop
	}
	return docHeight;
}

/*//---------------------------------------------*/
/*// Name: centerElem(id)						 */
/*// Desc: Centers a movable element within		 */
/*//	   the given window space		 		 */
/*//---------------------------------------------*/

function centerElem(id) {
	var dim = getElemDim(id);
	var win = getWinDim();
	var newTop, newLeft;
	/*newTop = (win.height-dim.height)/2;*/
	newTop = 16;
	newLeft = (win.width-dim.width)/2;
	document.getElementById(id).style.top = newTop+"px";
	document.getElementById(id).style.left = newLeft+"px";
}

/*//---------------------------------------------*/
/*// Name: floatHide(id)						 */
/*// Desc: Hides an element, adds image			 */
/*//---------------------------------------------*/

function floatHide(id,banner) {
	document.getElementById(id).style.visibility = 'hidden';
	if(document.getElementById('aniGif')) {
		document.getElementById('aniGif').style.visibility='visible';
	}
	document.getElementById('flashContainer').style.visibility = 'visible';
}

/*//---------------------------------------------*/
/*// Name: floatShow(id)						 */
/*// Desc: Displays an element					 */
/*//---------------------------------------------*/

function floatShow(id) {
	var winDim = getWinDim();

	// Set Dimensions of our Overlay
	document.getElementById(id).style.height = getDocHeight()+"px";
	
	// Center popup box
	centerElem("popBox");
	if(document.getElementById('aniGif')) {
		document.getElementById('aniGif').style.visibility='hidden';
	}
	document.getElementById('flashContainer').style.visibility = 'hidden';
	document.getElementById(id).style.visibility = 'visible';
}

/*//---------------------------------------------*/
/*// Name: requestData(id,data)					 */
/*// Desc: Drops data into specified element	 */
/*//---------------------------------------------*/

function requestData (id,data)
{
	var httpRequest;
	var widthMod = 0;

	if (arguments[2] > 0) {
		widthMod = arguments[2];
	} else {
		widthMod = 700;
	}
	document.getElementById('popBox').style.width = widthMod+"px";
	floatShow('overlay');
	document.getElementById(id).innerHTML = "<p align=\"center\" class=\"bodyContent\">Loading...</p>";
	
	try	{
		httpRequest = new XMLHttpRequest();
	} catch (e)	{
		try	{
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e)	{
			try	{
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e)	{
				alert('Failed in creation of http request!');
				floatHide('overlay');
				return false;
			}
		}
	}
	
	httpRequest.onreadystatechange = function()	{
		if (httpRequest.readyState == 4) {
			if (httpRequest.status == 200) {
				document.getElementById(id).innerHTML = httpRequest.responseText;
				httpRequest = false;
			} else {
				alert('There was a problem with the request.');
				document.getElementById(id).innerHTML += "<div class=\"bodyLinks\" align=\"center\">[ <a href=\"#\" onClick=\"floatHide('overlay');\">Close</a> ]</div>";
			}
		}
	}
	httpRequest.open("GET", data, true);
	httpRequest.send(null);
}

function delayScroll() {
	setTimeout("scroll(0,0)",10);
}
