//Browser detection
ns4 = (document.layers) ? true : false;
ie4 = (document.all && !document.getElementById) ? true : false;
ie5 = (document.all && document.getElementById) ? true : false;
ns6 = (!document.all && document.getElementById) ? true : false;
mac = navigator.userAgent.indexOf("Mac") != -1;
//Positions
var x = 0;
var y = 0;

//Generates the popup layer
function PopUpCal(event, event_name, title_text, option) {
	WritePopup(event, event_name, title_text,  option);
	MoveTo(x, y);
	ToggleVisibility(1);
	
}
//Writes the code to create the popup layer
function WritePopup(event, event_name, title_text,  option) {
	str = "<div class='popupText'>" + event_name + "</div>";
	
	if(option != "") {
		str = str + "<div class='popupText2'><span class=body><br>" + option + "</span></div>";
	}
			
	if (ie4 || ie5) {
		if (mac) {
			x = event.x;
			y = event.y;
		}
		else {
		    x = window.event.clientX + document.body.scrollLeft;
		    y = window.event.clientY + document.body.scrollTop;
		}
	}
	else if (ns4 || ns6) {
   		x = event.pageX;
    	y = event.pageY;
	}

	if (ie4) {
		//document.all['popupOrange'].innerHTML = title_text;
		document.all['popupWhite'].innerHTML = str;
	}
	else if (ns4) {
		//var lyrBlue = (null)? eval('document.null.document.popupOrange.document') : document.layers['popupOrange'].document
		var lyrWhite = (null)? eval('document.null.document.popupWhite.document') : document.layers['popupWhite'].document
		lyrBlue.open()
		lyrBlue.write("<table border=0 cellpadding=0 cellspacing=0 width='210'><tr><td bgcolor=#FF9900 align='center'>" + title_text + "</td></tr></table>")
		lyrBlue.close()
		lyrWhite.open()
		lyrWhite.write("<table height='150' width='210'><tr><td valign=top>" + str + "</td></tr></table>")
		lyrWhite.close()
	}
	else if (ns6 || ie5) {
		//document.getElementById("popupOrange").innerHTML = title_text;
		document.getElementById("popupWhite").innerHTML = "<table height='100%' width='100%'><tr><td height='100%' valign=top>" + str + "</td></tr></table>";
	}
}
//Moves the div to the right location
function MoveTo(x, y) {
	
	test_height = -1;
	test_width = -1;
	if (ie4 || ie5) {
		test_height = document.body.clientHeight + document.body.scrollTop;
		test_width = document.body.clientWidth + document.body.scrollLeft;
		
		test_scrolltop = document.body.scrollTop;
	}
	else if (ns4 || ns6) {
		test_height = window.innerHeight + window.pageYOffset;
		test_width = window.innerWidth + window.pageXOffset;
		
		test_scrolltop = window.pageYOffset;
	}
	
	x = x + 15;
	y = y + 5;
	
	if(test_height >= 0) {
		if ((y+161) > test_height) {
			y = y-190;
		}
		
		if((y-test_scrolltop) < 5) { 
			y = 5 + test_scrolltop;
		}
		
		if ((x+216) > test_width) {
			x = x-215;
		}
	}
	
	if (ie4) {
		blueDiv.style.pixelLeft=x;
		blueDiv.style.pixelTop=y;
		whiteDiv.style.pixelLeft=x+5;
		whiteDiv.style.pixelTop=y+15;
	}
	else if (ns4) {
		document.layers[0].moveToAbsolute(x,y);
		document.layers[1].moveToAbsolute(x+5,y+15);
	}
	else if (ie5 || ns6) {
		//document.getElementById('popupOrange').style.left = x + 'px';
		//document.getElementById('popupOrange').style.top = y + 'px';
		document.getElementById('popupWhite').style.left = x + 5 + 'px';
		document.getElementById('popupWhite').style.top = y + 15 + 'px';
	}
}
//Clears the popup
function RemovePopup() {
	ToggleVisibility(0);
}
//Changes the visibility
function ToggleVisibility(v){
	/*
	if (ie4) {
	    document.all['popupOrange'].style.visibility = (v) ? "visible":"hidden";
	    document.all['popupWhite'].style.visibility = (v) ? "visible":"hidden";
	}
	else if(ns4) {
		document.layers[0].visibility=(v) ? "show":"hide"
		document.layers[1].visibility=(v) ? "show":"hide"
	}
	else if(ie5 || ns6) {
	    document.getElementById('popupOrange').style.visibility = (v) ? "visible":"hidden";
	    document.getElementById('popupWhite').style.visibility = (v) ? "visible":"hidden";
	}
	*/
	theFade.start();
}

