gDispatchDir = "";
gLinkExt = "";
gImgPath = "";
gShowBanners = "";
gURI = "";
gIsIndex = 0;

function init(HTTPURL,SHOW_BANNERS,isIndex)
{
	gDispatchDir = HTTPURL+"dispatch/";
	//gLinkExt = "?page=0";
	gImgPath = HTTPURL+"images/hider_bg.gif";
	gShowBanners = SHOW_BANNERS;
	gURI = HTTPURL;
	gIsIndex = isIndex;
}

function ChkSameTabAndXMLProcess(classN,divid,activate,deactivate,phplink,overdiv)
{
	var nArguments = arguments.length;

	xmllink = gDispatchDir+phplink+gLinkExt;
	
	if(classN.indexOf("red",classN) > 0) return false;
	
	try
	{
		loginBox.slideOut(); //slide Out login menu if visible
	}
	catch (err) {}
	
	//change active tab
	activateleft = document.getElementById(activate+"_left");
	activateright = document.getElementById(activate+"_right");
	activatemain = document.getElementById(activate);
	activateleft.className = 'tabredleft';
	activateright.className = 'tabredright';
	activatemain.className = 'tabred';
	
	Dactivate(deactivate);
	
	if(nArguments > 6)
	{
		while(nArguments-- > 6) Dactivate(arguments[nArguments]);
	}
	
	XMLProcess(xmllink,divid,overdiv);
}

function Dactivate(deactivate)
{
	deactivateleft = document.getElementById(deactivate+"_left");
	deactivateright = document.getElementById(deactivate+"_right");
	deactivatemain = document.getElementById(deactivate);
	deactivateleft.className = 'tabgreyleft';
	deactivateright.className = 'tabgreyright';
	deactivatemain.className = 'tabgrey';
}

function XMLProcess(xmllink,divid,overdiv)
{
	RefreshBanners(gShowBanners);
	DoWait(divid, overdiv);
	loadXMLDoc(xmllink,"DoEnable('"+overdiv+"')",divid);
}

function DoWait(divel,overdiv)
{
	divid = document.getElementById(divel);
	
	//***************************************************//
	//if divel is in HTMLLiElement i.e. draging available//
	//NOTE: getAttribute('parentLiId') <-> parentLiId have to be the id of li element NOT the attribute itemID of the li element//
	//***************************************************//
	var liObjOffsetLeft=0;
	var liObjOffsetTop=0;
	try
	{
		var liId = divid.getAttribute('parentLiId');
		
		if(liId != null)
		{
			var liObj = document.getElementById(liId);
			liObjOffsetLeft = liObj.offsetLeft;
			liObjOffsetTop = liObj.offsetTop;
		}
	}
	catch (err) { }
	
	if(document.getElementById(overdiv))
	{
		//if is dragable destroy the overdiv ... will be create a new one later to update the new offsets after drag's end
		//if(liObjOffsetLeft > 0)
			document.body.removeChild(document.getElementById(overdiv));
		//else just show the old one 
		//else 
		//	document.getElementById(overdiv).style.display='block';
		
		//return;
	}
	
	img = gImgPath;
	
	if(divid.style.position == 'absolute');
	else divid.style.position='relative';
	
	if(liObjOffsetLeft > 0)
	{
		parentDivTop = parseInt(liObjOffsetTop + 26);
		parentDivLeft = parseInt(liObjOffsetLeft);
	}
	else
	{
		parentDivTop = divid.offsetTop;
		parentDivLeft = divid.offsetLeft;
	}
	
	parentDivWidth = divid.style.width;
	
	try
	{
		parentDivHeight = divid.style.height;
	}
	catch(err) {};
	
	if(!parentDivHeight) parentDivHeight = 0;
	//divid.style.position='abosolute';
	
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id',overdiv);
	newdiv.style.position='absolute';
	newdiv.style.left = parentDivLeft+"px";
	newdiv.style.top = parentDivTop+"px";
	newdiv.style.width = parentDivWidth;
	newdiv.style.height = parentDivHeight;
	//newdiv.style.background='url('+img+')';
	newdiv.style.backgroundColor='#E3E3E3';
	newdiv.style.backgroundRepeat='repeat';
	newdiv.style.zIndex=1;
	
	newdiv.style.MozOpacity='70';
	newdiv.style.opacity='0.7';
	newdiv.style.filter='alpha(opacity=70)';
	newdiv.style.overflow='auto';
	newdiv.style.display="block";
	
	// --- Check if width or height are set without 'px' <-> that's why there were some bugs in IE ... 
	if(isNaN(parseInt(parentDivWidth))) console.error("The width of div(id='"+divid.id+"') is not set proper (maybe the 'px' is missing)")
	if(isNaN(parseInt(parentDivHeight))) console.error("The height of div(id='"+divid.id+"') is not set proper (maybe the 'px' is missing)")
	
	//set load in circle icon
	loadCircleImg = gURI + "images/loading_.gif";
	imgTop = parseInt((parseInt(parentDivHeight)/2) - 18) + "px";
	imgLeft = parseInt((parseInt(parentDivWidth)/2) - 18) + "px";
	
	var newImg = document.createElement('img');
	newImg.setAttribute('src',loadCircleImg);
	newImg.style.position="absolute";
	newImg.style.top=imgTop;
	newImg.style.left=imgLeft;

	newdiv.appendChild(newImg);
	document.body.appendChild(newdiv);
}

function DoEnable(overdiv)
{
	if(document.getElementById(overdiv)) document.getElementById(overdiv).style.display='none';
}

function updWH(divid,w,h)
{
	//i = document.getElementById(img);
	d = document.getElementById(divid);
	
	d.style.height = h;
	d.style.width = w;
	
}

