//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 showToolTip(obj, e) {
  var tempX = 0;
  var tempY = 0;
  var offset = 5;
  var objHolder = obj;

	if (document.getElementById) {
		obj = document.getElementById(obj);
	} else if (document.all) {
		obj = document.all.item(obj);
	} else {
		obj = null;
	}
  if (obj == null) return;

  if (document.all) {
    tempX = event.clientX + document.body.scrollLeft;
    tempY = event.clientY + document.body.scrollTop;
  } else {
    tempX = e.pageX;
    tempY = e.pageY;
  }

  if (tempX < 0) { tempX = 0 }
  if (tempY < 0) { tempY = 0 }

  obj.style.top  = (tempY + offset) + 'px';
  obj.style.left = (tempX + offset) + 'px';

  obj.style.display = 'block';
  obj.style.visibility = 'visible';
}

function centerDiv(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 dedicatedConfigurator(itemId) {
	setAttr('popUp','class','configurator');
	centerDiv('popUp');
	new Ajax.Updater('popUp', '/dedicated/configurator.php', {asynchronous:true, evalScripts:true, onComplete:function(request, json){Element.hide('popUpLoading');}, onLoading:function(request, json){Element.show('popUpLoading');}, parameters:'itemId='+itemId});
}

function hidePopUp() {
	var div = document.getElementById("popUp");
	var str = '<div id="popUpLoading" style="position:relative; display:none;"><img src="/img/loading.gif" alt="Loading" hspace="3" align="middle" />Loading</div>';
	div.innerHTML = str;
	div.style.display = "none";
}