// popHelp.js

// newFunction
// Royal Caribean Help Poppup DOM

 
    /* Simple Browser (Internet Explorer) Detection */
    var agt = navigator.userAgent.toLowerCase();
    var appVer = navigator.appVersion.toLowerCase();
   	var iePos  = appVer.indexOf('msie');
   	var ie6Pos = appVer.indexOf('msie 6');				
   	var is_ie   = (iePos!=-1);
    var is_ie6  = (ie6Pos!=-1);
	/* end Browser Detection */
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	//initialize variables
	var help_popSticky = 1;
	var help_popox = 10; 
	var help_popoy = 15; 
	var help_popw = 220;
	var help_popfx = -1; 
	var help_popfy = -1; 
	var help_popvp = 35; 
	var help_pophp = 36;	
	var help_popah = 20; 
	var help_popf = self;	
	var help_popam = 0; 
	var help_pophauto = 1;	
	var help_popvauto = 1; 
	var help_popdl = 0;	
	var help_popsh = 0;	
	var help_popsw = 0;	
	var help_popx = 0;
	var help_popy = 0;
	var help_poplyr = null;
	var help_divref = null;

	// to retrieve mouse position data
	document.onmousemove = mouseMove;

	//Initial Pop up Header txt
	var help_popTitle="";
	// Initial Pop up boby text
	var help_popText="";
	// Close window txt
	//var help_clink="<A HREF=\"javascript:window.parent.cClick()\" class='closeLink'>Close</A>";	
	var help_clink="<A HREF=\"javascript:window.parent.cClick()\" class='closeLink'>x</A>";	


// POPUP FUNCTION (tl,t,s,w,sh,sw)	
// tl=title text, t=body text, s=Pop Width(px), w= Window Close(1 = yes / 0 = no), sh=Scroll Text Box Height(px), sw= Scroll Text Box Width(px)

function popHelp(tl,t,w,s,sh,sw)
{
	//to check if scroll bars needed and apply if necessary
	if(sh || sw)
	{ 
		szDiv = "<DIV STYLE='overflow:auto";
		if(sh)
			szDiv += ";height:" + sh;
		else
			szDiv += ";overflow-y:hidden";
		if(sw)
			szDiv += ";width:" + sw;
		else
			szDiv += ";overflow-x:hidden";
		t = szDiv + "'>" + t + "</DIV>";
	}
	//define help pop up title, text and sticky distance
	help_popTitle = tl;
	help_popText = t;
	help_popSticky = s;
	// define help pop up window width
	window.status=tl;
	if(w)	
		help_popw = w;	
	// define scroll bar height
	help_popsh = sh;
	help_popsw = sw;
	
	if (is_ie) //for IE	Since the DOM is treated different across MS browsers
	{
		help_poplyr = help_popf.popCtxHelpDiv.style;
	 	help_divref = help_popf.document.all['popCtxHelpDiv'] ;
	 	
	}
	else // for not IE browsers
	{
	 	help_poplyr = help_popf.document.getElementById("popCtxHelpDiv");
	 	help_divref = help_poplyr ;
	}
 	
	//to remove any other previous pop up opened and not closed yet
	clearTimeout(help_popdl);
	//call pop up help function
	help_popdl = setTimeout("popD()",1);
	return;
}
// function that opens the Dinamyc Pop Up
function popD()
{
	var l;
	// brings the pop up content
	l = help_content_simple(help_popTitle, help_popText);
	if (help_popSticky)
	{
		help_popSticky = 1;
	}
	//set html content for the pop up
	popLW(l);
	help_popam = 0;
	//call popup
	//DISPpop();
	if (help_popSticky)
	{
		help_popam = 0;
		return false;
	}
	else
	{
		return true;
	}
}
// returns the html content for the pop up w/ title and bodt text
function help_content_simple(tl, t)
{
	txt = "<IFRAME SRC=\"/include/helpframe.html\" NORESIZE FRAMEBORDER=0 SCROLLING=NO ID=popFrame MARGINHEIGHT=0 MARGINWIDTH=0></IFRAME>";
	return txt;
}
// set and format inner html content for pop up
function popLW(t)
{
	t += "\n";
	if (is_ie) //for IE	
	{
	
		help_popf.document.all["popCtxHelpDiv"].innerHTML = t;
	}
	else
	{
		r = help_popf.document.createRange();
		r.setStartBefore(help_poplyr);
		domfrag = r.createContextualFragment(t);
		while (help_poplyr.hasChildNodes())
		{
			help_poplyr.removeChild(help_poplyr.lastChild);
		}
		 help_poplyr.appendChild(domfrag);
	}

}
// to retrieve the mouse coordinates and set the position to where open the pop help window.
function mouseMove(e)
{
	if (is_ie) //IE recognizes method event
	{
	var dsocleft=document.all? iebody.scrollLeft : pageXOffset
    var dsoctop=document.all? iebody.scrollTop : pageYOffset
	
		help_popx=(document.all) ? event.clientX : event.x; 
		help_popy=(document.all) ? event.clientY : event.y; 
		help_popx=help_popx+dsocleft; 
		help_popy=help_popy+dsoctop;
		
		
	
	}
	else
	{
		help_popx=e.pageX; 
		help_popy=e.pageY;
	}

	 if (help_popam == 1)
	 {
		 popPL();
	 }
}


function cClick()
{
	popHO(help_poplyr);
	help_popSticky = 0;
}



function popCF(f)
{ 
	
	if (is_ie) //for IE	
	{
		if (typeof f.document.all["popCtxHelpDiv"] == "undefined") return false;
	}
	else
	{
		if (f.document.getElementById('popCtxHelpDiv') == null) return false;
	}
	
	return true;
}




// function to set the pop up visible
function popSO(o)
{
	if (is_ie) //for IE	
		o.visibility = "visible";
	else
		o.style.visibility = "visible";
	
}

// close function (hides)
function popHO(o)
{
	if (is_ie) //for IE	
		o.visibility = "hidden";
	else
		o.style.visibility = "hidden";
	
	 if (help_popdl > 0) clearTimeout(help_popdl);
		 help_popdl = 0;
 
	self.status = "";
}

// set left and top corner coordinates
function popML(o,x,y)
{
	if (is_ie) //for IE	
	{
		o.left = x;
		o.top = y;
	}
	else
	{
		o.style.left = x + "px";
		o.style.top = y + "px";	
	}
}


// Display the pop up help window
function DISPpop()
{
	if (help_popam == 0)
	{
		popPL();
		popSO(help_poplyr);
	}

}
// set the position where the pop help window should open.
function popPL()
{
	var X, Y;
	if (help_popfx > -1)
	{
	
		X = help_popfx;
	}
	else
	{

	var dsocleft=document.all? iebody.scrollLeft : pageXOffset	
		wo = dsocleft;
		
		var cpopwidth = help_popf.document.body.clientWidth;
		
		if (help_pophauto == 1)
		{
			if ( (help_popx - wo) > ( (eval(cpopwidth)) - help_popw) )
			{
				help_pophp = 7;
			}
			else
			{
				help_pophp = 8;
			}
		}
		if (help_pophp == 8)
		{ 
			X = help_popx+help_popox;
			if ( (eval(X) + eval(help_popw)) > (wo + cpopwidth) )
			{
				X = cpopwidth + wo - help_popw;
				if (X < 0) X = 0;
			}
		}
		if (help_pophp == 7)
		{ 
			X = help_popx-help_popox-help_popw;
			if (X < wo) X = wo;
		}
	}
	
	if (help_popfy > -1)
	{
	
		Y = help_popfy;
	}
	else
	{	
	

var dsoctop=document.all? iebody.scrollTop : pageYOffset

		scrolloffset = dsoctop;	
		
	if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
      iheight = window.innerHeight;
  	} else if( document.documentElement && document.documentElement.clientHeight  ) {
    	//IE 6+ in 'standards compliant mode'
        iheight = document.documentElement.clientHeight;
  	} else if( document.body && document.body.clientHeight  ) {
    	//IE 4 compatible
       iheight = document.body.clientHeight;
  }
		
		iheight = (eval(iheight)) / 2;
		if ( (help_popy - scrolloffset) > iheight)
		{
		
			var aboveheight = help_divref.offsetHeight;
			Y = help_popy - (help_popoy + aboveheight);
			if (Y < scrolloffset) Y = scrolloffset;	
		}
		else
		{
			Y = help_popy + help_popoy;
		}
	}
	
  	popML(help_poplyr, X, Y);
}
// called from the pop up help window to setup pop up width, title and body text, close button and style
function HandlepopLoad(table,title,text,cl,lstyl)
{
	table.style.width = help_popw;
	title.innerHTML = help_popTitle;
	text.innerHTML = help_popText;
	if(help_popSticky)
	{
		cl.innerHTML=help_clink;
	}
	if(lstyl)
	{
		lstyl.color="#0000FF";
	}
}
// caller from the pop up window to adjust body text width and height properties
function HandlepopTextSize(w,h)
{
	var DocpopFrame = document.getElementById('popFrame');
	DocpopFrame.width = w;
	DocpopFrame.height = h;
	DISPpop();

}
//
					