//Sets attribute for any html tag
function setAttr(id, attr, attrValue){
	if (document.getElementById && document.getElementById(id)){
		if (attr == 'class' && document.all) attr = 'className';
		document.getElementById(id).setAttribute(attr, attrValue);
	}
}

// function to swap menu tabs
function swapTab(topTab, nodeTab, topCont, nodeCont) {
	var tTab = $(topTab);
	var nTab = $(nodeTab);
	var tCont = $(topCont);
	var nCont = $(nodeCont);

	for(i = 0; i < tTab.childNodes.length; i++) {
		if(tTab.childNodes[i].nodeType != 3) {
			if(tTab.childNodes[i].childNodes[0] == nTab) {
				tTab.childNodes[i].childNodes[0].className = 'tab_on';
			} else {
				tTab.childNodes[i].childNodes[0].className = 'tab_off';
			}
		}
	}

	for(i=0; i < tCont.childNodes.length; i++) {
		if(tCont.childNodes[i].nodeType == 1) {
			if(tCont.childNodes[i] == nCont) {
				tCont.childNodes[i].style.display = '';
			} else {
				tCont.childNodes[i].style.display = 'none';
			}
		}
	}
}

function positionIt(divId) {
	var div = document.getElementById(divId);
	div.style.display = "block";
	var divWidth = div.offsetWidth ? div.offsetWidth : div.style.width ? parseInt( div.style.width ) : 0;
	var divHeight = div.offsetHeight ? div.offsetHeight :  div.style.height ? parseInt( div.style.height ) : 0;
	var winWidth = getWindowWidth();
	var winHeight = getWindowHeight();
	var setX = (winWidth - divWidth) / 2;
	var setY = (winHeight - divHeight) / 2;
	if( setX < 0 ) setX = 0;
	if( setY < 0 ) setY = 0;
	div.style.left = setX + "px";
	div.style.top = setY + "px";

	var IfrRef = document.getElementById('popUpIF');
	if (IfrRef != null) {
		IfrRef.style.width = div.offsetWidth;
		var IfrmTop = setY + 25;
		var IfrmLeft = setX;
		IfrmTop = IfrmTop + "px";
		IfrmLeft = IfrmLeft + "px";
		IfrRef.style.top = IfrmTop;
		IfrRef.style.left = IfrmLeft;
		IfrRef.style.width = divWidth - 10;
		IfrRef.style.height = divHeight - 50;
		IfrRef.style.zIndex = div.style.zIndex - 1;
		IfrRef.style.display = "block";
		IfrRef.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
	}
}

function getWindowWidth() {
	var width = 0;
	if (document.documentElement && document.documentElement.clientWidth) {
		width = document.documentElement.clientWidth;
	} else if (document.body && document.body.clientWidth) {
		width = document.body.clientWidth;
	} else if ( window.innerWidth ) {
		width = window.innerWidth - 18;
	}
	return width;
};

function getWindowHeight() {
	var height = 0;
	if (document.documentElement && document.documentElement.clientHeight) {
		height = document.documentElement.clientHeight;
	} else if (document.body && document.body.clientHeight) {
		height = document.body.clientHeight;
	} else if ( window.innerHeight ) {
		height = window.innerHeight - 18;
	}
	return height;
};

function launchSupportCenter(activeTab) {
	setAttr('popUp','class','support_center');
	positionIt('popUp');
	new Ajax.Updater('popUp', '/support_center.php', {asynchronous:true, evalScripts:true, onComplete:function(request, json){Element.hide('popUpLoading');}, onLoading:function(request, json){Element.show('popUpLoading');}, parameters:'activeTab='+activeTab});
}


function hidePopUp() {
	var div = document.getElementById("popUp");
	var str = '<div id="popUpLoading" style="position:relative; display:none;"><img src="/img/loading.gif" alt="Loading" style="vertical-align:middle;" />Loading</div>';
	div.innerHTML = str;
	div.style.display = "none";
}
