// JScript File
	
function HideContent(d)
{
	if(d.length < 1) 
	{ 
		return; 
	}
	
	//Get all div element
	//oDom = document.getElementsByTagName('div');

    clearTimeout(popupTimerId);
	document.getElementById(d).style.display = "none";
	
}

var cX = 0; var cY = 0;
function UpdateCursorPosition(e){ 
    cX = e.pageX+5; cY = e.pageY+5;
}

function UpdateCursorPositionDocAll(e){ 
    cX = event.clientX; cY = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
}
if(document.all) { 
    document.onmousemove = UpdateCursorPositionDocAll; 
}
else { 
    document.onmousemove = UpdateCursorPosition; 
}
	
function AssignPosition(obj, d, optionAssignPosition) 
{
    iViewportWidth = getViewportWidth();
    iViewportHeight = getViewportHeight();

    aPosition = findPos(obj);
    iPosX = aPosition[0];
    iPosY = aPosition[1];
    sX = 0;
    sY = 0;
    
    // if the popup is not in the root, the absolute position of the popup does not show on the screen where you want
    // for the absolute position of the parent element is added and so on. therefore added the absolute position
    // in a var to be abstracted from the absolute pos of the popup. otherwise sX and sY will stay at 0
    if(optionAssignPosition == "flightpage" || optionAssignPosition == "hotelpage" || optionAssignPosition == "transferpage")
	{
	    bPos = findPos(document.getElementById("Wrapper"));
        sX = bPos[0];
        
        cPos = findPos(document.getElementById("ContentBookingsEngine"));
        sY = cPos[1];
	}
	if(optionAssignPosition == "cruiseCabin")
	{
	    bPos = findPos(document.getElementById("PriceMatrixContentDiv"));
        sX = bPos[0] - 20;
        
        var temp = document.body.scrollTop + document.documentElement.scrollTop;
        sY = bPos[1] - 20 + temp;
	}
	if(optionAssignPosition == "cabinOverview")
	{
		bPos = findPos(document.getElementById("ContentCenter"));
        sX = bPos[0];
        
        cPos = findPos(document.getElementById("ContentCenter"));
        sY = cPos[1];
	}
    
    // xpos
    if((cX + document.getElementById(d).offsetWidth) > iViewportWidth)
    {
        document.getElementById(d).style.left = (cX - sX - document.getElementById(d).offsetWidth - 0) + "px";
    }
    else
    {
        document.getElementById(d).style.left = (cX - sX) + "px";
    }
    
    // ypos
    if((cY + document.getElementById(d).offsetHeight) > iViewportHeight)
    
    {
        document.getElementById(d).style.top = (cY - sY - document.getElementById(d).offsetHeight) + "px";
    }
    else
    {
        document.getElementById(d).style.top = (cY - sY) + "px";
    }
}

function DisplayPopup(obj, d, optionAssignPosition)
{
    document.getElementById(d).style.display = "block";
	
	// if this parameter excists then pass it through to the final function AssignPosition
	if(optionAssignPosition)
	{
	    AssignPosition(obj, d, optionAssignPosition);
	}
	else
	{
	    AssignPosition(obj, d);
	}
}

// showContent, optional parameters are Message and optionAssignPosition
// optionAssignPosition is for positioning purposus if the popup is not in the root of the website. ( is quickfix )
function ShowContent(obj, d, Message, optionAssignPosition)
{		
    if(d.length < 1) { return; }
    		
	if(document.all)
	{
		document.onmousemove = UpdateCursorPositionDocAll;
	}
	else
	{
		document.onmousemove = UpdateCursorPosition;
		//document.getElementById(firstObj).innerHTML = firstObjContain;
	}
	
	if(Message)
	{
	    document.getElementById(d).innerHTML = Message;
	}
	
	// if this parameter, pass it through to further function
	if(optionAssignPosition)
	{
	    popupTimerId = setTimeout(function() { DisplayPopup(obj, d, optionAssignPosition); }, 100);
	}
	else
	{
	    popupTimerId = setTimeout(function() { DisplayPopup(obj, d); }, 100);
	}
	
	
}

function getViewportWidth()
{
	return self.innerWidth || (document.documentElement.clientWidth || document.body.clientWidth);
}
function getViewportHeight()
{
	return self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
