﻿// version 1.2 -- for BQ

var huw_iframeUrl = huw_host + '/Loading.aspx?destPage=widgets/GenericWidget.aspx&wid=' + huw_wid + '&source=' + window.location.host;
var huw_baseUrl = huw_host + '/css/images/BigQuestion';

// calculate the current window width //
function huw_pageWidth() {
    return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

// calculate the current window height //
function huw_pageHeight() {
    return window.innerHeight != null ? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null ? document.body.clientHeight : null;
}

// calculate the current window vertical offset //
function huw_topPosition() {
    return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

// calculate the position starting at the left of the window //
function huw_leftPosition() {
    return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}

function huw_openDialog() {

    var huw_cssCode;
    huw_cssCode = "#huw_overlay {z-index:999997;position:absolute;top:0;left:0;min-height:100%;width:100%;background:#000;opacity:.50;filter:alpha(opacity=50);}";
    huw_cssCode += "#huw_dialog {z-index:999998;position:absolute;width:720px;height:420px;}";
    huw_cssCode += "#huw_dialog #huw_close {z-index:999999;position:absolute;top:-20px;left:-20px;height:40px;width:40px;}";
    huw_cssCode += "#huw_dialog #huw_close img {display:block;border:0;}";
    huw_addCss(huw_cssCode);

    var dialog;
    var overlay;
    if (!document.getElementById('huw_dialog')) {
        dialog = document.createElement('div');
        dialog.id = 'huw_dialog';
        overlay = document.createElement('div');
        overlay.id = 'huw_overlay';
        document.body.appendChild(overlay);
        document.body.appendChild(dialog);
        overlay.setAttribute('onclick', 'huw_closeDialog()');
        overlay.onclick = huw_closeDialog;
    } else {
        dialog = document.getElementById('huw_dialog');
        overlay = document.getElementById('huw_overlay');
    }
    var width = huw_pageWidth();
    var height = huw_pageHeight();
    var left = huw_leftPosition();
    var top = huw_topPosition();
    var dialogwidth = dialog.offsetWidth;
    var dialogheight = dialog.offsetHeight;
    var topposition = top + (height / 2) - (dialogheight / 2);
    var leftposition = left + (width / 2) - (dialogwidth / 2);
    dialog.style.top = topposition + "px";
    dialog.style.left = leftposition + "px";
    overlay.style.height = document.body.offsetHeight + 'px';

    dialog.innerHTML = '<a href="javascript:huw_closeDialog()" id="huw_close"><img src="' + huw_host + '/css/images/close.png" width="40" height="40" alt="Close" /></a><iframe src="' + huw_iframeUrl + '" width="720" height="420" width="720" height="420" scrolling="no" frameborder="0" allowtransparency="true"></iframe>';
}

// hide the dialog box //
function huw_closeDialog() {
    var dialog = document.getElementById('huw_dialog');
    dialog.parentNode.removeChild(dialog);
    var overlay = document.getElementById('huw_overlay');
    overlay.parentNode.removeChild(overlay);
}

// add custom css //
function huw_addCss(cssCode) {
    var styleElement = document.createElement("style");
    styleElement.type = "text/css";
    if (styleElement.styleSheet) {
        styleElement.styleSheet.cssText = cssCode;
    } else {
        styleElement.appendChild(document.createTextNode(cssCode));
    }
    document.getElementsByTagName("head")[0].appendChild(styleElement);
}

if (!huw_position) { huw_position = bl; }
//var huw_tabUrl = huw_baseUrl + '/tab_' + huw_position + '.gif';
var huw_tabUrl = huw_host + '/css/themes/BQ_tab_' + huw_wid + '.gif';

if (huw_position == 'bl') {
    document.write("<a href=\"javascript:huw_openDialog();\" style=\"position:fixed;_position:absolute;width:280px;height:80px;bottom:0px;left:-200px;z-index:999996;\" onmouseout=\"javascript:this.style.left='-200px'\" onmouseover=\"javascript:this.style.left='0'\"><img src=\"" + huw_tabUrl + "\" style=\"border:0\" alt=\"\"\/><\/a>");
}
if (huw_position == 'l') {
    document.write("<a href=\"javascript:huw_openDialog();\" style=\"position:fixed;_position:absolute;width:160px;height:160px;top:300px;left:-130px;z-index:999996;\" onmouseout=\"javascript:this.style.left='-130px'\" onmouseover=\"javascript:this.style.left='0'\"><img src=\"" + huw_tabUrl + "\" style=\"border:0\" alt=\"\"\/><\/a>");
}
if (huw_position == 'l2') {
    document.write("<a href=\"javascript:huw_openDialog();\" style=\"position:fixed;_position:absolute;width:160px;height:160px;top:300px;left:-130px;z-index:999996;\" onmouseout=\"javascript:this.style.left='-130px'\" onmouseover=\"javascript:this.style.left='-120px'\"><img src=\"" + huw_tabUrl + "\" style=\"border:0\" alt=\"\"\/><\/a>");
}
if (huw_position == 'l_generic') {
    document.write("<a href=\"javascript:huw_openDialog();\" style=\"position:fixed;_position:absolute;width:160px;height:160px;top:300px;left:-140px;z-index:999996;\" onmouseout=\"javascript:this.style.left='-140px'\" onmouseover=\"javascript:this.style.left='-130px'\"><img src=\"" + huw_tabUrl + "\" style=\"border:0\" alt=\"\"\/><\/a>");
}

if (huw_position == 'r1') {
    document.write("<a href=\"javascript:huw_openDialog();\" style=\"position:fixed;_position:absolute;width:160px;height:160px;top:85px;right:-130px;z-index:999996;\" onmouseout=\"javascript:this.style.right='-130px'\" onmouseover=\"javascript:this.style.right='-120px'\"><img src=\"" + huw_tabUrl + "\" style=\"border:0\" alt=\"\"\/><\/a>");
}
    
if (huw_position == 'l_ovacome') {
    document.write("<a href=\"javascript:huw_openDialog();\" style=\"position:fixed;_position:absolute;width:160px;height:160px;top:143px;left:-130px;z-index:999996;\" onmouseout=\"javascript:this.style.left='-130px'\" onmouseover=\"javascript:this.style.left='-125px'\"><img src=\"" + huw_tabUrl + "\" style=\"border:0\" alt=\"\"\/><\/a>");
}

if (huw_position == 'l_gen') {
    document.write("<a href=\"javascript:huw_openDialog();\" style=\"position:fixed;_position:absolute;width:160px;height:160px;top:300px;left:-140px;z-index:999996;\" onmouseout=\"javascript:this.style.left='-140px'\" onmouseover=\"javascript:this.style.left='-130px'\"><img src=\"" + huw_host + "/css/themes/BQ_tab_generic.gif\" style=\"border:0\" alt=\"\"\/><\/a>");
}