﻿
/* Webpage Javascripts Library  */
// Yes these functions needs to be cleaned up! No time for house cleaning (yet) MHK

//Global javascript variables   
var ContentAreaHeight; // in pixels
var ContentAreaWidth; // in pixels
var BannerMenuHeight = 55; //Needs to be Dynamic to be accurate.
var MenuTabHeight = 0; //Needs to be Dynamic to be accurate.

var MaxContentAreaHeight;
var MaxContentAreaWidth;
var MinimumContentAreaHeight = 10;
var MinimumContentAreaWidth = 0;

//Search Page Variables
var LeftPanelWidth = 285; 

var xmlHttp


function GetXmlHttpObject() {
    var xmlHttp = null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}


function stateChanged() {
    if (xmlHttp.readyState == 4) {        
        //document.getElementById("txtHint").innerHTML = xmlHttp.responseText;        
        var x=1; // needed?
    }
}

function storeInSession(strname,strvalue) {

    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Your browser does not support AJAX!");
        return;
    }
    var url = "SESaveToSession.aspx";
    url = url + "?id=" + strname;
    url = url + "&val=" + strvalue;
    xmlHttp.onreadystatechange = stateChanged;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);

} 

 

 

function InitListView()
{
       SetMaxPanelHeight('SEGridContainer');
       SetMaxPanelWidth('SEGridContainer');       
}



function SetMaxPanelHeight(controlName)
{
  var control = document.getElementById(controlName);
  control.style.height = ContentAreaHeight - MenuTabHeight;
}

function SetMaxPanelWidth(controlName)
{
  var control = document.getElementById(controlName);
  control.style.width =  ContentAreaWidth - LeftPanelWidth;
}

function querySt(ji) {
hu = window.location.search.substring(1);
gy = hu.split("&");
for (i=0;i<gy.length;i++) {
ft = gy[i].split("=");
if (ft[0] == ji) {
return ft[1];
}
}
}
 
function GetContentPanelAreaSize()
{ 

    

 ContentAreaHeight=0;
 ContentAreaWidth=0;
 windowHeight();   
 windowWidth();   
 
 //Get max settings
 MaxContentAreaHeight = ContentAreaHeight-55;
 MaxContentAreaWidth = ContentAreaWidth-55;
 
 //Limit Minumum Size
 if (ContentAreaHeight < MinimumContentAreaHeight) {
    ContentAreaHeight=MinimumContentAreaHeight;  
   }
  //Limit Minumum Size
 if (ContentAreaWidth < MinimumContentAreaWidth) {
    ContentAreaWidth=MinimumContentAreaWidth;  
 }
 
// document.getElementById("MaxPanelHeight").value =  ContentAreaHeight - MenuTabHeight;;

 var isGateway = querySt("IsGateway");
 if (isGateway!="Yes") {
  ContentAreaHeight= ContentAreaHeight-95;
 }
 else
 {
  ContentAreaHeight= ContentAreaHeight+65;
 }
 
 ContentAreaWidth = (ContentAreaWidth - LeftPanelWidth); 
 storeInSession("MaxPanelHeight", ContentAreaHeight);
 storeInSession("MaxPanelWidth", ContentAreaWidth);
  
 return;
}


function windowWidth()
{

    if (window.innerWidth)
    {
        if (document.body.offsetWidth)
        {
            if (window.innerWidth<=document.body.offsetWidth)
            {
                ContentAreaWidth = document.body.offsetWidth;
                return document.body.offsetWidth;
            }
        }
        
        ContentAreaWidth = window.innerWidth;
        return (window.innerWidth);                     // Mozilla
    }


    if (document.documentElement.clientWidth) 
    {
        ContentAreaWidth = document.documentElement.clientWidth;
        return document.documentElement.clientWidth;    // IE6
    }


    if (document.body.clientWidth) 
    {
        ContentAreaWidth = document.body.clientWidth;
        return document.body.clientWidth;               // IE DHTML-compliant any other
     }
          
     ContentAreaWidth=-1;         
     return  -1;
}
                                                
                                                
                                               
function windowHeight()
{

        if (window.innerHeight)
        {
            if (document.body.offsetHeight)
            {
                if (window.innerHeight<=document.body.offsetHeight)
                {
                    ContentAreaHeight = (document.body.offsetHeight);
                    return document.body.offsetHeight + "px";
                }
            }
            ContentAreaHeight = (window.innerHeight); 
            return (window.innerHeight) + "px";                     // Mozilla
        }


        if (document.documentElement.clientHeight)
        {
            ContentAreaHeight = (document.documentElement.clientHeight); 
            return document.documentElement.clientHeight + "px";    // IE6
        }


        if (document.body.clientHeight) 
        {
            ContentAreaHeight = (document.body.clientHeight); 
            return document.body.clientHeight + "px";               // IE DHTML-compliant any other
        }
        
        ContentAreaHeight=-1;         
        return  -1;
        
}

function getScrollbarWidth()
{
    var inner = document.createElement("p");
    var outer = document.createElement("div")
    
    inner.style.width = "100%";
    inner.style.height = "500px";
    
    outer.style.position = "absolute";
    outer.style.top = "0px";
    outer.style.left = "0px";
    outer.style.visibility = "hidden";
    outer.style.width = "200px";
    outer.style.height = "150px";
    outer.style.overflow = "hidden";
    outer.appendChild(inner);
    
    document.body.appendChild(outer);
    
    
    var w1 = inner.offsetWidth;
    
    outer.style.overflow = "scroll";
    
    var w2 = inner.offsetWidth;
    
    if(w1 == w2) w2 = outer.clientWidth;
    
    document.body.removeChild(outer);
    
    return (w1 - w2);
    
    
}

function changeInnerHtml(elementId, innerHtml)
{
    var el = document.getElementById(elementId);
    el.innerHTML = innerHtml;          
}

function openWindowLockedDown(name, url, width, height, resize)
{
    if(void(0) == resize || null == resize) resize = "0";
    if(void(0) == width || null == width) width = "640";
    if(void(0) == height || null == height) resize = "480";
    
    var ftr = "";

    ftr += "toolbar=0, ";
    ftr += "directories=0, ";
    ftr += "status=0, ";
    ftr += "menubar=0, ";
    ftr += "scrollbars=0, ";
    ftr += "resizable=" + resize + ", ";
    ftr += "copyhistory=0, ";
    ftr += "width=" + width + ", ";
    ftr += "height=" + height + "";
    
    return window.open(url, name, ftr, true);
}

function __getOffset(id)
{
    var el = document.getElementById(id);
    var doc = document;
    
    if(!el || null == el){return;}
    
    var cEl = el;
    
    var ret = new Object();
    
    ret.X = new Number(0);
    ret.Y = new Number(0);
    
    ret.x = new Number(0);
    ret.y = new Number(0);
    
    while(null != cEl && cEl != doc)
    {
        if(cEl.offsetParent)
        {
            if(cEl.offsetLeft){ret.X += cEl.offsetLeft;}
            if(cEl.offsetTop){ret.Y += cEl.offsetTop;}
            
            cEl = cEl.offsetParent;
        }
        else
        {
            break;
        }
    }
    
    ret.x = ret.X;
    ret.y = ret.Y;
    return ret;
}              


/***********************************************
* Image w/ description tooltip- By Dynamic Web Coding (www.dyn-web.com)
* Copyright 2002-2007 by Sharon Paine
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* IMPORTANT: Put script after tooltip div or 
	 put tooltip div just before </BODY>. */

var dom = (document.getElementById) ? true : false;
var ns5 = (!document.all && dom || window.opera) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var nodyn = (!ns5 && !ie4 && !ie5 && !dom) ? true : false;

var origWidth, origHeight;

// avoid error of passing event object in older browsers
if (nodyn) { event = "nope" }

///////////////////////  CUSTOMIZE HERE   ////////////////////
// settings for tooltip 
// Do you want tip to move when mouse moves over link?
var tipFollowMouse= true;	
// Be sure to set tipWidth wide enough for widest image
var tipWidth= 330;
var offX= 20;	// how far from mouse to show tip
var offY= 12; 
var tipFontFamily= "Verdana, arial, helvetica, sans-serif";
var tipFontSize= "8pt";
// set default text color and background color for tooltip here
var tipFontColor= "#000000";
var tipBgColor= "#DDECFF"; 
var tipBorderColor= "#e1e1e1";
var tipBorderWidth= 3;
var tipBorderStyle= "ridge";
var tipPadding= 4;


////////////////////  END OF CUSTOMIZATION AREA  ///////////////////

// to layout image and text, 2-row table, image centered in top cell
// these go in var tip in doTooltip function
// startStr goes before image, midStr goes between image and text
var startStr = '<table width="' + tipWidth + '"><tr><td align="center" width="100%"><img width="320px" height="240px" src="';
var midStr = '&h=240&w=320" border="0"></td></tr><tr><td valign="top">';
var endStr = '</td></tr></table>';

////////////////////////////////////////////////////////////
//  initTip	- initialization for tooltip.
//		Global variables for tooltip. 
//		Set styles
//		Set up mousemove capture if tipFollowMouse set true.
////////////////////////////////////////////////////////////
var tooltip, tipcss;
function initTip() {
	if (nodyn) return;
	tooltip = (ie4)? document.all['tipDiv']: (ie5||ns5)? document.getElementById('tipDiv'): null;
	tipcss = tooltip.style;
	if (ie4||ie5||ns5) {	// ns4 would lose all this on rewrites
		tipcss.width = tipWidth+"px";
		tipcss.fontFamily = tipFontFamily;
		tipcss.fontSize = tipFontSize;
		tipcss.color = tipFontColor;
		tipcss.backgroundColor = tipBgColor;
		tipcss.borderColor = tipBorderColor;
		tipcss.borderWidth = tipBorderWidth+"px";
		tipcss.padding = tipPadding+"px";
		tipcss.borderStyle = tipBorderStyle;
	}
	if (tooltip&&tipFollowMouse) {
		document.onmousemove = trackMouse;
	}
}

//window.onload = initTip;

/////////////////////////////////////////////////
//  doTooltip function
//			Assembles content for tooltip and writes 
//			it to tipDiv
/////////////////////////////////////////////////
var t1,t2;	// for setTimeouts
var tipOn = false;	// check if over tooltip link
function doTooltip(evt,num,imagepath) {
    initTip();
	if (!tooltip) return;
	if (t1) clearTimeout(t1);	if (t2) clearTimeout(t2);
	tipOn = true;	
	if (ie4||ie5||ns5) {
		var tip = startStr + imagepath +  midStr + endStr;
		 
	 	tooltip.innerHTML = tip;
	}
	if (!tipFollowMouse) positionTip(evt);
	else t1=setTimeout("tipcss.visibility='visible'",100);
}

var mouseX, mouseY;
function trackMouse(evt) {
	standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
	mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
	mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;
	if (tipOn) positionTip(evt);
}

/////////////////////////////////////////////////////////////
//  positionTip function
//		If tipFollowMouse set false, so trackMouse function
//		not being used, get position of mouseover event.
//		Calculations use mouseover event position, 
//		offset amounts and tooltip width to position
//		tooltip within window.
/////////////////////////////////////////////////////////////
function positionTip(evt) {
	if (!tipFollowMouse) {
		standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
		mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
		mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;
	}
	// tooltip width and height
	var tpWd = (ie4||ie5)? tooltip.clientWidth: tooltip.offsetWidth;
	var tpHt = (ie4||ie5)? tooltip.clientHeight: tooltip.offsetHeight;
	// document area in view (subtract scrollbar width for ns)
	var winWd = (ns5)? window.innerWidth-20+window.pageXOffset: standardbody.clientWidth+standardbody.scrollLeft;
	var winHt = (ns5)? window.innerHeight-20+window.pageYOffset: standardbody.clientHeight+standardbody.scrollTop;
	// check mouse position against tip and window dimensions
	// and position the tooltip 
	if ((mouseX+offX+tpWd)>winWd) 
		tipcss.left = mouseX-(tpWd+offX)+"px";
	else tipcss.left = mouseX+offX+"px";
	if ((mouseY+offY+tpHt)>winHt) 
		tipcss.top = winHt-(tpHt+offY)+"px";
	else tipcss.top = mouseY+offY+"px";
	if (!tipFollowMouse) t1=setTimeout("tipcss.visibility='visible'",100);
}

function hideTip() {
	if (!tooltip) return;
	t2=setTimeout("tipcss.visibility='hidden'",100);
	tipOn = false;
}

 

