﻿
function jnj_adjust_popup(){
        var w, h, fixedW, fixedH, diffW, diffH;
        if (document.documentElement && document.body.clientHeight==0) {     // Catches IE6 and FF in DOCMODE
                fixedW = document.documentElement.clientWidth;
                fixedH = document.documentElement.clientHeight;
                window.resizeTo(fixedW, fixedH);
                diffW = fixedW - document.documentElement.clientWidth;
                diffH = fixedH - document.documentElement.clientHeight;
                w = fixedW + diffW + 16; // Vert Scrollbar Always On in DOCMODE.
                h = fixedH + diffH;
                if (w >= screen.availWidth) h += 16;
        } else if (document.all) {
                fixedW = document.body.clientWidth;
                fixedH = document.body.clientHeight;
                window.resizeTo(fixedW, fixedH);
                diffW = fixedW - document.body.clientWidth;
                diffH = fixedH - document.body.clientHeight;
                w = fixedW + diffW;
                h = fixedH + diffH;
                if (h >= screen.availHeight) w += 16;
                if (w >= screen.availWidth)  h += 16;
        } else {
                fixedW = window.innerWidth;
                fixedH = window.innerHeight;
                window.resizeTo(fixedW, fixedH);
                diffW = fixedW - window.innerWidth;
                diffH = fixedH - window.innerHeight;
                w = fixedW + diffW;
                h = fixedH + diffH;
                if (w >= screen.availWidth)  h += 16;
                if (h >= screen.availHeight) w += 16;
        }
        w = Math.min(w,screen.availWidth) + 100;
        h = Math.min(h,screen.availHeight);
        window.resizeTo(w,h);
        window.moveTo((screen.availWidth-w)/2, (screen.availHeight-h)/2);
}

// gridview hover over
var _oldStyle = new Array();
function jnj_gridview_over(source) {
    _oldStyle[0] = source.style.backgroundColor;
    _oldStyle[1] = source.style.color;
    
    source.style.backgroundColor = '#EFEFEF';
    source.style.color = 'black';
}
function jnj_gridview_out(source) {
    source.style.backgroundColor = _oldStyle[0];
    source.style.color = _oldStyle[1];
}

// mouse detection
var jnj_ie = document.all?true:false;
var jnj_mouse_x = 0;
var jnj_mouse_y = 0;

function jnj_mouse_init() {
    if (!jnj_ie) document.captureEvents(Event.MOUSEMOVE)
    document.onmousemove = jnj_get_mouse_xy;
}
function jnj_get_mouse_xy(e) {
    if (jnj_ie) { // grab the x-y pos.s if browser is IE
        var ScrollTop = document.body.scrollTop;
        if (ScrollTop == 0) {
            if (window.pageYOffset)
                ScrollTop = window.pageYOffset;
            else
                ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
        }
        try {
        jnj_mouse_x = event.clientX + document.body.scrollLeft;
        jnj_mouse_y = event.clientY + ScrollTop;
        } catch (e) { alert(e); }
    } else {  // grab the x-y pos.s if browser is NS
        jnj_mouse_x = e.pageX;
        jnj_mouse_y = e.pageY;
    }  
    if (jnj_mouse_x < 0){jnj_mouse_x = 0;}
    if (jnj_mouse_y < 0){jnj_mouse_y = 0;}  
    return true;
}

// help functions
function jnj_help_show(div) {
    var HelpPanel = $jnj_id(div);
    HelpPanel.style.visibility = "visible";
    HelpPanel.style.left = jnj_mouse_x + 'px';
    HelpPanel.style.top = jnj_mouse_y + 'px';
    jnj_set_selects_visibility(false);
}
function jnj_help_hide(div) {
    var HelpPanel = $jnj_id(div);
    HelpPanel.style.visibility = "hidden";
    jnj_set_selects_visibility(true);
}

// wrapper for document.getElementById
function $jnj_id() {
    var results = [], element;
    for (var i = 0; i < arguments.length; i++) {
        element = arguments[i];
        if (typeof element == 'string')
            element = document.getElementById(element);
        results.push(element);
    }
    return results.length < 2 ? results[0] : results;
}

function jnj_set_selects_visibility(visible) {
    var selects = document.getElementsByTagName("select");
    for (i = 0; i < selects.length; i++) {
        selects[i].style.visibility = visible ? 'visible' : 'hidden';
    }    
}

function jnj_popupLink(url, styleStr, width, height) {
    var left = (screen.width/2) - width/2;
    var top = (screen.height/2) - height/2;
    styleStr = styleStr + 'copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
    var popupWindow = window.open(url,"popupWindow" + (new Date().getTime()), styleStr);
    if (!popupWindow) {
        alert('You have a popup blocker enabled which prevented the popup window from appearing. Please disable the popup blocker in order to utilize this function of the website.');
    }
}

