// JavaScript Document
var disable_bg ; var popup_box

function open_popup(page_name, popup_name, query_string) {
	nonRefreshUpdate(page_name,'popup_name=' + URLEncode(popup_name) + query_string,'V2');
}

function create_popup(popup_name) {
    if(document.getElementById(popup_name + "_disable")) {
	    disable_bg = document.getElementById(popup_name + "_disable");
		disable_bg.className = "disable_bg";
		disable_bg.style.display = "block";
		disable_bg.style.zIndex = topMostLayer + 1;
    } else {
	    disable_bg = document.createElement("div");
            disable_bg.id = popup_name + "_disable";
            disable_bg.className = "disable_bg";
            disable_bg.style.display = "block";
            disable_bg.style.zIndex = topMostLayer + 1;
        document.body.appendChild(disable_bg);
    }
	if (document.getElementById(popup_name)) {
	    popup_box = document.getElementById(popup_name);
		popup_box.className = "htgm_popup_div";
		popup_box.style.zIndex = topMostLayer + 2;
		popup_box.style.display = "block";
		//popup_box.innerHTML = "";
	} else {
	    popup_box = document.createElement("div");
			popup_box.id = popup_name;
			popup_box.className = "htgm_popup_div";
			popup_box.style.zIndex = topMostLayer + 2;
			popup_box.style.display = "block";
		document.body.appendChild(popup_box);
	}
	
	topMostLayer = topMostLayer + 2;
}
		
function position_screen(popupBox, popupWidth, popupLeft, popupTop, setFocus) {
	if (ie5) {
		var windowWidth = (parseInt(document.body.offsetWidth)/2) + parseInt(document.body.scrollLeft);
		var windowHeight = (parseInt(document.body.offsetHeight)/2) + parseInt(document.body.scrollTop);
	} else {
		var windowWidth = (parseInt(document.body.innerWidth)/2);
		var windowHeight = (parseInt(document.body.innerHeight)/2);
	}
	
	var windowWidth = (parseInt(getVisibleXY()[0])/2) + parseInt(getScrollXY()[0]);
	var windowHeight = (parseInt(getVisibleXY()[1])/2) + parseInt(getScrollXY()[1]);
	
	var popupHeight = getOffsetHeight(popupBox.id);
	
	popupBox.style.width = popupWidth + "px";
	
	if (popupLeft==0) {
	    popupBox.style.left = (windowWidth - (popupWidth/2)) + "px";
	} else {
	    popupBox.style.left = popupLeft + "px";
	}
	if (popupTop == 0) {
	    popupTop = (windowHeight - (popupHeight / 2));
	    if (popupTop < 0) { popupTop = 0; };
	    popupBox.style.top = popupTop + "px";
	} else {
	    popupBox.style.top = popupTop + "px";
	}
	
	if(setFocus) {
		document.getElementById(setFocus).focus();
		document.getElementById(setFocus).select();	
	}
}

function close_dialogbox(dialogName) {
    document.getElementById(dialogName).style.display = "none";
    document.getElementById(dialogName + '_disable').style.display = "none";
}

var mouseover_timeout = 0;

function show_mouseover(show_text, popupWidth, popupLeft, popupTop, popupSide) {
    mouseover_timeout = setTimeout("display_mouseover('" + show_text + "', " + popupWidth + ", " + popupLeft + ", " + popupTop + ", '" + popupSide + "');", 1000);
}

function display_mouseover(show_text, popupWidth, popupLeft, popupTop, popupSide) {
    popup_box = document.getElementById('mouseover_details');
    popup_box.innerHTML = show_text;
    popup_box.style.zIndex = topMostLayer + 2;
    popup_box.style.top = popupTop + "px";
    popup_box.style.display = "block";

    if (popupSide == "right") {
        popup_box.style.left = (popupLeft - popup_box.offsetWidth) + "px";
    } else {
        popup_box.style.left = popupLeft + "px";
    }

    topMostLayer = topMostLayer + 1;
}

function hide_mouseover() {
    clearTimeout(mouseover_timeout);
    popup_box = document.getElementById('mouseover_details');
    popup_box.innerHTML = "";
    popup_box.style.display = "none";
}

function select_calendar_date(selectedDate, selectedID, selectedFunction) {
    try {
        document.getElementById(selectedID).value = selectedDate;
    } catch (ex) {}
     
    try {
        document.getElementById(selectedID).innerHTML = selectedDate;
    } catch (ex) { }

    try {data_changed = true;} catch (ex) {}

    try {eval(selectedFunction);} catch (ex) {}
}

function show_popout(box, left, top) {
	var main_box = document.getElementById(box);
	var show_box = document.getElementById(box + '_show');
	var blank_box = document.getElementById(box + '_blank');
	var content_box = document.getElementById(box + '_content');
	
	show_box.style.width = "40px";
	show_box.style.height = "34px";
	show_box.style.top = top + "px";
	show_box.style.left = left + "px";
	show_box.style.zIndex = topMostLayer + 1;
	show_box.innerHTML = blank_box.innerHTML;
	show_box.style.display = "";
	topMostLayer = topMostLayer + 1;
	var show_popout_timer = setTimeout ( function(){grow_popout(box)}, 25);			
}

function hide_popout (box) {
	var main_box = document.getElementById(box);
	var show_box = document.getElementById(box + '_show');
	var blank_box = document.getElementById(box + '_blank');
	var content_box = document.getElementById(box + '_content');
	
	if(browser=="MSIE7") {
		var box_height = getOffsetHeight(box + '_content')+12;
	} else {
		var box_height = getOffsetHeight(box + '_content');
	}
	
	content_box.innerHTML = show_box.innerHTML;
	show_box.style.height = box_height+"px";
	show_box.innerHTML = blank_box.innerHTML;
	var show_popout_timer = setTimeout ( function(){shrink_popout(box)}, 250);
}
		
function shrink_popout(box) {
	var show_box = document.getElementById(box + '_show');
	var blank_box = document.getElementById(box + '_blank');
	var content_box = document.getElementById(box + '_content');
	
	var box_width = 36;
	var box_height = 34;
	
	if( parseInt(show_box.style.width) > box_width ) {
		if((parseInt(show_box.style.width)-10)<box_width) {
			show_box.style.width = box_width+"px";
		} else {
			show_box.style.width = (parseInt(show_box.style.width)-10)+"px";
		}
	} else {
		show_box.style.height = (getOffsetHeight(box + '_show')-10)+"px";
	}
	
	if( parseInt(show_box.style.width)>box_width || parseInt(show_box.style.height) > box_height ) {
		show_popout_timer = setTimeout ( function(){shrink_popout(box)}, 25);		
	} else {
		show_box.style.display = "none";
	}
}

function grow_popout(box) {
	var show_box = document.getElementById(box + '_show');
	var blank_box = document.getElementById(box + '_blank');
	var content_box = document.getElementById(box + '_content');
	if(browser=="MSIE7") {
		box_width = 204;
		var box_height = getOffsetHeight(box + '_content')+12;
	} else {
		box_width = 200;	
		var box_height = getOffsetHeight(box + '_content');
	}
	
	if( parseInt(show_box.style.height) < box_height ) {
		if((parseInt(show_box.style.height)+10)>box_height) {
			show_box.style.height = box_height+"px";
		} else {
			show_box.style.height = (parseInt(show_box.style.height)+10)+"px";
		}
	} else {
		if((parseInt(show_box.style.width)+10)>box_width) {
			show_box.style.width = box_width+"px";
		} else {
			show_box.style.width = (parseInt(show_box.style.width)+10)+"px";
		}
	}
				
	if( parseInt(show_box.style.width)<box_width || parseInt(show_box.style.height) < getOffsetHeight(box + '_content') ) {
		show_popout_timer = setTimeout ( function(){grow_popout(box)}, 25);		
	} else {
		show_box.innerHTML = content_box.innerHTML;
		show_box.style.height = "auto";
	}
}
