// 
var dropEnabled = "false";
var currPopupColor = "#CCCCCC";
	
/*
 * show_popup - makes popup div visible to user. 
 * 
 * Parameters:
 *		anchor_name - this is the name and id of the anchor that will be used for positioning the popup
 *		content 		- the string that will be used to set the innerHTML property of the div
 *		vert_shift 	- the number of pixels that the div will be shifted in relation to the vertical
 *									position of the anchor. A positive value shifts down, negative value shifts up.
 *		style_class - the CSS style class to use for the div that makes up the popup.
 *		shift_up      - determines if the bottom or top edge of the popup will be used for positioning
 *		              if true use bottom, else use top
 */
function show_popup(anchor_name, content, vert_shift, style_class, shift_up, bgColor)
{	
	if (content.length > 0)
	{
		// This is the div that will contain the popup content.
		var popup_div = document.getElementById("popup_div");
		// This is iframe element that is used for overlaying select elements.
		var iframe_el = document.getElementById("popup_iframe");
		
		// Set content of popup div
		popup_div.innerHTML = content;
		
		// Set class and show the div. Div needs to be shown before reading offsetHeight
		popup_div.className = style_class;
		popup_div.style.display = "block";
		popup_div.style.backgroundColor = currPopupColor = bgColor;
		popup_div.style.borderLeftColor = popup_div.style.borderRightColor = popup_div.style.borderBottomColor = currPopupColor;
		
		// Position the popup and make it visible
		var div_position = getAnchorPosition(anchor_name);
		if (shift_up == true){
			popup_div.style.top = (div_position.y ) + vert_shift - popup_div.offsetHeight + 'px';
		}
		else {
			popup_div.style.top = (div_position.y ) + vert_shift + 'px';
		}
		popup_div.style.left = (div_position.x - 1) + 'px';
		
		popup_div.style.zIndex = 100;
		
		// Position the iframe and make it visible.
		iframe_el.style.width = popup_div.offsetWidth;
    iframe_el.style.height = popup_div.offsetHeight;
		iframe_el.style.top = popup_div.style.top;
		iframe_el.style.left = popup_div.style.left;
    iframe_el.style.zIndex = popup_div.style.zIndex - 1;
    iframe_el.style.display = "block";
		
		dropEnabled = "true";
	}
}

// Hides the div from the user, uses a timeout to smooth out action
function hide_popup()
{
	dropEnabled = "false";
	setTimeout("hide_popup_div()", 1500);
}

// utility function called by hide_popup to actually hide the div
// if the user has moused over the div again after mousing off the
// div, the div will not be hidden
function hide_popup_div(){
	if (dropEnabled == "false")
	{
		var popup_div = document.getElementById("popup_div");
		var iframe_el = document.getElementById("popup_iframe");
		popup_div.innerHTML = "";
		popup_div.style.display = "none";
		iframe_el.style.display = "none";
	}
}

function make_cell_active(cell){
  cell.className = 'popup_active';
  cell.childNodes.item(0).style.color = currPopupColor;
}
 
function make_cell_inactive(cell){
  cell.className = 'popup_inactive';
  cell.childNodes.item(0).style.color = '#FFF';
}
  

// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
function getAnchorPosition(anchorname){var useWindow=false;var coordinates=new Object();var x=0,y=0;var use_gebi=false, use_css=false, use_layers=false;if(document.getElementById){use_gebi=true;}else if(document.all){use_css=true;}else if(document.layers){use_layers=true;}if(use_gebi && document.all){x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);}else if(use_gebi){var o=document.getElementById(anchorname);x=AnchorPosition_getPageOffsetLeft(o);y=AnchorPosition_getPageOffsetTop(o);}else if(use_css){x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);}else if(use_layers){var found=0;for(var i=0;i<document.anchors.length;i++){if(document.anchors[i].name==anchorname){found=1;break;}}if(found==0){coordinates.x=0;coordinates.y=0;return coordinates;}x=document.anchors[i].x;y=document.anchors[i].y;}else{coordinates.x=0;coordinates.y=0;return coordinates;}coordinates.x=x;coordinates.y=y;return coordinates;}
function getAnchorWindowPosition(anchorname){var coordinates=getAnchorPosition(anchorname);var x=0;var y=0;if(document.getElementById){if(isNaN(window.screenX)){x=coordinates.x-document.body.scrollLeft+window.screenLeft;y=coordinates.y-document.body.scrollTop+window.screenTop;}else{x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;}}else if(document.all){x=coordinates.x-document.body.scrollLeft+window.screenLeft;y=coordinates.y-document.body.scrollTop+window.screenTop;}else if(document.layers){x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;}coordinates.x=x;coordinates.y=y;return coordinates;}
function AnchorPosition_getPageOffsetLeft(el){var ol=el.offsetLeft;while((el=el.offsetParent) != null){ol += el.offsetLeft;}return ol;}
function AnchorPosition_getWindowOffsetLeft(el){return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;}
function AnchorPosition_getPageOffsetTop(el){var ot=el.offsetTop;while((el=el.offsetParent) != null){ot += el.offsetTop;}return ot;}
function AnchorPosition_getWindowOffsetTop(el){return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;}
