﻿// JScript File
/*------------------------------------------------------------------------------------------------------
 * ShowDetails.js
 * Written On: 02/20/2006  
 * Written By:  Mary Catelli
 * 
 *  BugzId: 2160    Factored out of Brad's code to display and hide div
 *  Requires a mask named "mask"
 *
 * 04/05/2007  Brad     Added checkScroll() function to make sure that the top of a dic is with in the current viewport.
 * ---------------------------------------------------------------------------------------------------*/     

function showHideDetailsLayer(id){
    var obj = document.getElementById(id);
    //checkScroll(obj);
    if (obj.style.visibility == 'hidden'){
        obj.style.visibility = 'visible';
        if(setMaskVisibility('visible',id) == true) checkScroll(obj);;
    } else {
        obj.style.visibility = 'hidden';
        if(setMaskVisibility('hidden',id) == true) checkScroll(obj);;
    }
    
}

function showHideDetailsLayerFromCodeBehind(id){
// function to be called when wanting to show a div from the code behind, the delay is used to 
// allow the page time to complete loading otherwise the mask will not be displayed.
    setTimeout("showHideDetailsLayer('" + id + "')", 500);
}

function setMaskVisibility(visible,idToShow){
// idToShow is the object that we want displayed on top, need it here only if we are having to use the setTimeout function to wait for the page to load

    var obj = document.getElementById('mask');
    if (visible == 'visible'){
        if (window.innerHeight && window.scrollMaxY) {// Firefox
            yWithScroll = window.innerHeight + window.scrollMaxY;
            xWithScroll = window.innerWidth + window.scrollMaxX;
        } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
            yWithScroll = document.body.scrollHeight;
            xWithScroll = document.body.scrollWidth;
        } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
            yWithScroll = document.body.offsetHeight;
            xWithScroll = document.body.offsetWidth;
        }
        //alert(yWithScroll);
        obj.style.width = xWithScroll + 'px';
        obj.style.height = yWithScroll + 'px';
    } else {
        obj.style.width = '0px';
        obj.style.height = '0px';
    }
    obj.style.visibility = visible;
    return true;
}

function checkScroll(obj) {
    obj.style.top = Math.round(document.documentElement.scrollTop+50)+'px';
    //obj.style.top = Math.round((document.documentElement.clientHeight/2)-(obj.style.height/2)+document.documentElement.scrollTop)+'px';
    //obj.style.left = Math.round((document.documentElement.clientWidth/2)-(obj.style.width/2))+"px";
}

function hideit(id){
   hideallids();
   showdiv(id);
   //document.getElementById('s_tab1').style.visibility="hidden";
   document.getElementById('s_tab1').style.display="none";
}

//here you place the ids of every element you want.
var ids=new Array('s_tab2','s_tab3');

function switchid(id){
	hideallids();
	showdiv(id);
	
	//do the tabs
	if(id=='s_tab3'){
		document.getElementById('s_tab2Left').src="images/tab_leftcorner.gif";
		document.getElementById('s_tab2Middle').className="tabBlue";
		document.getElementById('s_tab2Right').src="images/tab_rightcorner.gif";
		
		document.getElementById('s_tab3Left').src="images/tab_leftcornerOn.gif";
		document.getElementById('s_tab3Middle').className="tabOnBlue";
		document.getElementById('s_tab3Right').src="images/tab_rightcornerOn.gif";
	} else {
		document.getElementById('s_tab2Left').src="images/tab_leftcornerOn.gif";
		document.getElementById('s_tab2Middle').className="tabOnBlue";
		document.getElementById('s_tab2Right').src="images/tab_rightcornerOn.gif";
		
		document.getElementById('s_tab3Left').src="images/tab_leftcorner.gif";
		document.getElementById('s_tab3Middle').className="tabBlue";
		document.getElementById('s_tab3Right').src="images/tab_rightcorner.gif";
	}
	//end tabs
}

function hideallids(){
	//loop through the array and hide each element by id
	for (var i=0;i<ids.length;i++){
		hidediv(ids[i]);
	}		  
}

function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id	
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

window.addEvent=function(e,ev,f,c){if(e.addEventListener){e.addEventListener(ev,f,c);}else if(e.attachEvent){var r=e.attachEvent('on'+ev,f);return r;}else{e['on'+ev]=f;}};
function $N(v,d){var r=document.createElement(v);r.id=d;return r;};
function $s(v){return(v.style);}
function $ac(p,c){p.appendChild(c);}

var mOX = 10;
var mOY = 12;
var ttlayer = null;
var ToolTipEnabled = false;
var IE = /MSIE/.test(navigator.userAgent) && navigator.platform == "Win32";
var mx, my;

function initToolTip() {
	ttlayer=$N('div', 'tooltip-layer');s=$s(ttlayer);s.display='none';s.border='0px solid #bbbbbb';s.padding='10px';s.position='absolute';s.zIndex='999999';
	$ac(document.body,ttlayer);
	if (!IE){document.captureEvents(Event.MOUSEMOVE)}
	document.onmousemove = getMouseXY;	
}
window.addEvent(window,"load",initToolTip,false);

function ShowToolTip(src, alt) {
	if (!ToolTipEnabled && ttlayer){
		ttlayer.innerHTML = (src=='' ? alt : '<img src="'+src+'" alt="'+alt+'" border="0"/>');
		ttlayer.style.display = 'block';
		ToolTipEnabled = true;
	}
}

function HideToolTip() {
	ToolTipEnabled = false;
	if (ttlayer) ttlayer.style.display = 'none';
}

function getMouseXY(e) {
	if (ttlayer!=null&&ToolTipEnabled){
		if(IE){mx=event.clientX+document.body.scrollLeft;my=event.clientY+document.documentElement.scrollTop}
		else{mx=e.pageX;my=e.pageY}
		if(mx<0){mx=0;}if(my<0){my=0}
		var s=$s(ttlayer);
		var bh=document.body.clientHeight-12+document.documentElement.scrollTop;
		if(my+ttlayer.offsetHeight<bh){s.top=(my+mOY)+'px'}
		else if(my-ttlayer.offsetHeight<=0){s.top=(my-ttlayer.offsetHeight-mOY)+'px'}
		else{s.top=(my-ttlayer.offsetHeight>0?my-ttlayer.offsetHeight-mOY:my+mOY)+'px'}
		if(mx+ttlayer.offsetWidth<document.body.clientWidth){s.left=(mx+mOX)+'px'}
		else{s.left=(mx-ttlayer.offsetWidth-mOX>0?mx-ttlayer.offsetWidth-mOX:mx+mOX)+'px'}
		s.top=(ttlayer.offsetTop<0?'0px':s.top);
	}
	return true
}