﻿    if (document.images)
    {
      preload_image_object = new Image();
      // set image url
      image_url = new Array();
      image_url[0] = "images/nw.gif";
      image_url[1] = "images/ne.gif";
      image_url[2] = "images/sw.gif";
      image_url[3] = "images/se.gif";
      image_url[4] = "images/n.gif";
      image_url[5] = "images/s.gif";
      image_url[6] = "images/e.gif";
      image_url[7] = "images/w.gif";

       var i = 0;
       for(i=0; i<=7; i++) 
         preload_image_object.src = image_url[i];
    }
/* IE6 and before which don't implement hover correctly for anything but a href tag */
startList = function() {
    if (document.all && document.getElementById) {
        navRoot = document.getElementById("navMain");
        for (i = 0; i < navRoot.childNodes.length; i++) {
            node = navRoot.childNodes[i];
            if (node.nodeName == "LI") {
                node.onmouseover = function() {
                    this.className += " over";
                }
                node.onmouseout = function() {
                    this.className = this.className.replace(" over", "");
                }
            }
        }
    }
}
window.onload = startList;


function getBrowserHeight() {
    var intH = 0;
    var intW = 0;
    /*if (typeof window.innerWidth == 'number') {
        intH = window.innerHeight;
        intW = window.innerWidth;
    }
    else */
    if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        if (document.body.scrollHeight > document.body.offsetHeight) {
            intH = document.body.scrollHeight
        }
        else {
            intH = document.body.offsetHeight
        }

        if (document.body.scrollWidth > document.body.offsetWidth) {
            intW = document.body.scrollWidth
        }
        else {
            intW = document.body.offsetWidth
        }
        //intW = document.documentElement.clientWidth;

    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        intH = document.body.clientHeight;
        intW = document.body.clientWidth;
    }
    
    return { width: parseInt(intW), height: parseInt(intH) };
}

//gets only portion that open on client screen for positioning of question pop up
function getBrowserDisplayHeight() {
    var intH = 0;
    var intW = 0;

    if (typeof window.innerWidth == 'number') {
        intH = window.innerHeight;
        intW = window.innerWidth;
    }
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        intH = document.documentElement.clientHeight;
        intW = document.documentElement.clientWidth;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        intH = document.body.clientHeight;
        intW = document.body.clientWidth;
    }

    return { width: parseInt(intW), height: parseInt(intH) };
}

function SetLayerPosition() {
    SetLayerPosition("");
}

//need make these functions more adaptable 
function SetLayerPosition(strID) {

    if (strID == undefined) {
        strID = "";
    }
    var shadow = document.getElementById("shadow");
    //var iframe_ie6 = document.getElementById("iframe_ie6");

    var nHeight;

    var bws = getBrowserHeight();
    shadow.style.width = bws.width + "px";
    shadow.style.height = bws.height + "px";
    //iframe_ie6.style.width = bws.width + "px";
    //iframe_ie6.style.height = bws.height + "px";
    
    bws = getBrowserDisplayHeight();

    if (strID != "") {
        var question = document.getElementById(strID);

        if (bws.height > question.offsetHeight) {
        if(parseInt((bws.height - 60) / 2) >0 )
        {
            question.style.top = parseInt((bws.height - 60) / 2) + "px";
            }
            else
            {
                question.style.top = "0px";
            }
        }
        else {
        if( parseInt((bws.height - question.offsetHeight) / 2) > 0)
        {
            question.style.top = parseInt((bws.height - question.offsetHeight) / 2) + "px";
            }
            else
            {
                question.style.top = "0px";
            }
        }
        
        question.style.left = parseInt((bws.width - question.offsetWidth) / 2) + "px";
        question = null;
    }
    shadow = null;
    //iframe_ie6 = null;
}

function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [scrOfX, scrOfY];
}

function f_clientWidth() {
    return f_filterResults(
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
    return f_filterResults(
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
    return f_filterResults(
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
    return f_filterResults(
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}




function ShowLayer(strID) {
    

    var shadow = document.getElementById("shadow");
    //var iframe_ie6 = document.getElementById("iframe_ie6");
    var question = document.getElementById(strID);

    shadow.style.display = "block";
    question.style.display = "block";
    //iframe_ie6.style.display = "block";
    SetLayerPosition(strID);
    shadow = null;
    question = null;
    //iframe_ie6 = null;
}

function HideLayer(strID) {
    var shadow = document.getElementById("shadow");
    //var iframe_ie6 = document.getElementById("iframe_ie6");
    
    var question = document.getElementById(strID);

    shadow.style.display = "none";
    //iframe_ie6.style.display = "none";
    question.style.display = "none";

    shadow = null;
    //iframe_ie6 = null;
    question = null;
}

// make the specified div a windowed control in IE6
// this masks an iframe (which is a windowed control) onto the div,
// turning the div into a windowed control itself
function makeWindowed(str_p_div, width, height, top, left) {
    var p_div = document.getElementById(str_p_div);
    var is_ie6 =
           document.all &&
           (navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1 || navigator.userAgent.toLowerCase().indexOf("msie 5.") != -1);
    if (is_ie6) {
        //takes time so good for makeWindowed
        var bws = getBrowserHeight();
        var html =
              "<iframe style=\"position: absolute; display: block; " +
              "z-index: -1; width: " + width + "; height: " + height + "; top: " + top + "; left: " + left + ";" +
              "filter: mask(); background-color: #00ff00; \"></iframe>";
        if (p_div) p_div.innerHTML = html + p_div.innerHTML;
        // force refresh of div
        var olddisplay = p_div.style.display;
        p_div.style.display = 'none';
        p_div.style.display = olddisplay;
        //"z-index: -1; width: 1000px; height: 1000px; top: 0; left: 0;" +
        //"z-index: -1; width: " + p_div.width + "px; height: " + p_div.height + "px; top: -" + p_div.style.top + "; left: -" + p_div.style.left + ";" +
    };
}

// make the specified div a windowed control in IE6
// this masks an iframe (which is a windowed control) onto the div,
// turning the div into a windowed control itself
function makeWindowedShadow(str_p_div) {
    var p_div = document.getElementById(str_p_div);
    var is_ie6 =
           document.all &&
           (navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1 || navigator.userAgent.toLowerCase().indexOf("msie 5.") != -1);
    if (is_ie6) {
        var bws = getBrowserHeight();
        var html =
              "<iframe style=\"position: absolute; display: block; " +
              "z-index: -1; width: " + bws.width + "px; height: " + bws.height + "px; top: -" + p_div.style.top + "; left: -" + p_div.style.left + ";" +
              "filter: mask(); background-color: #ffffff; \"></iframe>";
        if (p_div) p_div.innerHTML = html + p_div.innerHTML;
        // force refresh of div
        var olddisplay = p_div.style.display;
        p_div.style.display = 'none';
        p_div.style.display = olddisplay;
    };
}


window.onresize = SetLayerPosition;

var timer;
function postBackTimer(strEventArgs) {

    clearTimeout(timer);
    timer = setTimeout("__doPostBack('__Page','" + strEventArgs + "');", 500);
}

imgPreloadB = Image(625, 625);
imgPreloadB.src = 'images/loading-maroon-big.gif'; 

function GreyDisplayZoom(strDiv, nYPosition, strImgSrc, strText, strItemText) {

    //question make part of second wait for image to load
    document.getElementById("img_Zoom").src = "images/loading-maroon-big.gif";
    
    document.getElementById('divGroupDescription').innerHTML = strText;
    document.getElementById('divZoomText').innerHTML = strItemText;
    //should position differently function should allow change
    
    var shadow = document.getElementById("shadow");
    //var iframe_ie6 = document.getElementById("iframe_ie6");
    var question = document.getElementById(strDiv);

    shadow.style.display = "block";
    question.style.display = "block";
    //iframe_ie6.style.display = "block";
    SetLayerPosition(strDiv);

    //since can be scrolled down --really want middle of viewable window + scroll
    // have the 
    question.style.top = (f_scrollTop() + 100) + 'px';
    shadow = null;
    question = null;
    document.getElementById('img_Zoom').src = strImgSrc;
    //iframe_ie6 = null;
    makeWindowedShadow('shadow');
    document.getElementById('shadow').setAttribute('onclick', 'HideLayer(\'divZoom\');document.getElementById(\'img_Zoom\').src = \'images/loading-maroon-big.gif\';');
    
}

function MouseCord(event) {

    // Detect if the browser is IE or not.
    // If it is not IE, we assume that the browser is NS.
    var IE = document.all ? true : false

    if (IE) { // grab the x-y pos.s if browser is IE
        tempX = event.clientX + f_scrollLeft()
        tempY = event.clientY + f_scrollTop()
    } else {  // grab the x-y pos.s if browser is NS
    tempX = event.pageX
    tempY = event.pageY
    }
    // catch possible negative values in NS4
    if (tempX < 0) { tempX = 0 }
    if (tempY < 0) { tempY = 0 }
    return { xPosition: tempX, yPosition : tempY };
}

/*function mouseX(evt) {
if (evt.pageX) return evt.pageX;
else if (evt.clientX)
return evt.clientX + (document.documentElement.scrollLeft ?
document.documentElement.scrollLeft :
document.body.scrollLeft);
else return null;
}
function mouseY(evt) {
if (evt.pageY) return evt.pageY;
else if (evt.clientY)
return evt.clientY + (document.documentElement.scrollTop ?
document.documentElement.scrollTop :
document.body.scrollTop);
else return null;
}*/


function changeImg(strImg, strSrc) {
    document.getElementById(strImg).src = strSrc;
}
