
var posx;
var posy;
var placing;
var timeOutId;


function getElementHeight(Elem) {
	var elem = document.getElementById(Elem);
	xPos = elem.offsetHeight;
	return xPos;
}


function hideContent(objId) 
{
	if(objId.length < 1) { return; }
	document.getElementById(objId).style.display = "none";
}

function hideTimeContent(timeout) 
{
	if(timeOutId)
	{
		clearTimeout(timeOutId);
	}
	timeOutId = setTimeout("hideContent('infolayer')",timeout);
}

function showContent(objId,placing) 
{
	if(objId.length < 1) { return; }
	if( timeOutId )
	{
		clearTimeout(timeOutId);
		hideContent('infolayer');
	}
	elem = document.getElementById(objId);
	
	if(elem)
	{
		elem.style.z_index = -1;
		elem.style.top     = posy+'px';
		elem.style.left    = posx+'px';
		elem.style.display = "block";
	}
}



function showInfo(index,placing)
{
	
	if(ajaxObjects[index].response) 
	{
		var posy_new = 0;
		showContent('infolayer',placing);
		var elem = document.getElementById("infolayer")
		elem.innerHTML = ajaxObjects[index].response;
		//alert(ajaxObjects[index].response);
		if(placing=='left_bottom'||placing=='right_bottom')
		{
			var posy_new = parseInt(posy) - parseInt(elem.offsetHeight);
			elem.style.top = posy_new+'px';
		}
		elem.style.z_index = 100;
	}
}	

function showLoading(placing){
	var posy_new = 0;
	var style = "_m";
	showContent('infolayer',placing);
	var elem = document.getElementById("infolayer")
	var result = '<table cellspacing="0" cellpadding="0" class="infoTable"><tr>';
				
			if( placing == "left_top")
				result = result + '<td class="top'+style+'">Info</td><td rowspan="3" class="left_top"></td>';
			else if( placing == "left_bottom")
				result = result + '<td class="top'+style+'">Info</td><td rowspan="3" class="left_bottom"></td>';
			else if( placing == "right_top")
				result = result + '<td rowspan="3" class="right_top"></td><td class="top'+style+'">Info</td>';		
			else if( placing == "right_bottom")
				result = result + '<td rowspan="3" class="right_bottom"></td><td class="top'+style+'">Info</td>';
			result = result + '</tr><tr><td class="body">Loading Info...<img src="../gfx/ajax-loader.gif"><br><br></td></tr><tr><td class="bottom'+style+'"></td></tr></table>';
	elem.innerHTML =result;
	if(placing=='left_bottom'||placing=='right_bottom')
	{
		var posy_new = parseInt(posy) - parseInt(elem.offsetHeight);
		elem.style.top = posy_new+'px';
	}
	elem.style.z_index = 100;	
}

function getInfo(infoId,obj,locCodeName)
{
	var curleft = curtop = 0;
	
	if (obj.offsetParent) 
	{
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while(obj = obj.offsetParent) 
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}

	posx = curleft;
	posy = curtop;
	
	//depending on position on screen switch between 4 different layouts of info page
	var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	  }
  
	//450 - width of .infolayer window from css file
	if(posx > (myWidth-450))
	{
		placing = 'left';
		posx = curleft-440;
	}
	else
	{
		placing = 'right';
		posx = curleft+20;
	} 
	
	
	if(posy < (myHeight-150))
	{
		placing += '_top';
		posy = curtop-35;
	}
	else 
	{
		placing += '_bottom';
		posy = curtop+45;
	}
	
	//SHOW LOADING INFO
	showLoading(placing);
	
	var ajaxIndex = ajaxObjects.length;
	ajaxObjects[ajaxIndex] = new sack();
	var url = '/system/info/get_ajax_info.php?infoId=' + infoId + '&placing=' + placing + '&locCodeName=' + locCodeName;
	ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
	ajaxObjects[ajaxIndex].onCompletion = function() { showInfo(ajaxIndex,placing); } ;	// Specify function that will be executed after file has been found
	ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function			
}

