﻿function dg(oid) { return document.getElementById(oid) }
function getScrollX() { return parseInt(document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) }
function getScrollY() { return parseInt(document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) }

function gradDivsOpacity(fromColor, toColor, stepNum, stepHeight, widthVal) {
    if (fromColor) { } else {fromColor = "#000000"}
    if (toColor) { } else {toColor = "#FFFFFF"}
    if (widthVal) { } else {widthVal = "100%"}
    if (stepNum > 100) {stepNum = 100}
    var oStep = parseInt(100 / stepNum); var oStepUp=0;
    var chunkDiv = document.createElement("div"); chunkDiv.style.position = "relative";chunkDiv.style.left = "0px";chunkDiv.style.top = "0px";

    for (i = 0; i <= stepNum; i++) {
        var tpDiv = document.createElement("div"); tpDiv.style.backgroundColor = "rgb(30,30,30)"; tpDiv.style.height = stepHeight + "px"; tpDiv.style.position = "";
        oStepUp += parseInt(oStep); setOpacity(parseInt(100-oStepUp), tpDiv);
        chunkDiv.appendChild(tpDiv);
    }
    return chunkDiv;
}

function loadDBoxContent() {
}

function suggestAjax(thisObj, e, callFrom) { //to attach to any textbox, call this function from its onkeyup event (onkeypress gives weird delay), and name the div containter by using 'con' + the textbox's id, the combo is automatically added with 'cb'
    if (checkKeyPress('Down', e)) {
        document.getElementById('cb' + thisObj.id).focus();
    } else {
        if (thisObj.value.length > 0) {
            if (checkKeyPress('Esc', e)) { document.getElementById('con' + thisObj.id).innerHTML = '' } else { ajaxRequest((callFrom == 'wx' ? '../forum/' : '') + 'wbajax.aspx', '?action=listusers&prefix=' + thisObj.value + '&targetid=' + thisObj.id, 'con' + thisObj.id, e, false); thisObj.focus(); }
        } else { document.getElementById('con' + thisObj.id).innerHTML = ''; }
    }
}
function checkKeyPress(checkKey, e) {
    var keyPressed = (window.event) ? event.keyCode : e.keyCode; // MSIE or Firefox?
    var EscKC = (window.event) ? 27 : e.DOM_VK_ESCAPE; // MSIE : Firefox
    var EnterKC = (window.event) ? 13 : e.DOM_VK_RETURN;
    var DownKC = 40; //e.DOM_VK_DOWN alert('D checked: '+ checkKey + "|" + keyPressed);

    if (checkKey == 'Esc' && keyPressed == EscKC) { return true }
    if (checkKey == 'Enter' && keyPressed == EnterKC) { return true }
    if (checkKey == 'Down' && keyPressed == DownKC) { return true }
}
/*DOM_VK_CANCEL: 3,
DOM_VK_HELP: 6,
DOM_VK_BACK_SPACE: 8,
DOM_VK_TAB: 9,
DOM_VK_CLEAR: 12,
DOM_VK_RETURN: 13,
DOM_VK_ENTER: 14,
DOM_VK_SHIFT: 16,
DOM_VK_CONTROL: 17,
DOM_VK_ALT: 18,
DOM_VK_PAUSE: 19,
DOM_VK_CAPS_LOCK: 20,
DOM_VK_SPACE: 32,
DOM_VK_PAGE_UP: 33,
DOM_VK_PAGE_DOWN: 34,
DOM_VK_END: 35,
DOM_VK_HOME: 36,
DOM_VK_LEFT: 37,
DOM_VK_UP: 38,
DOM_VK_RIGHT: 39,
DOM_VK_PRINTSCREEN: 44,
DOM_VK_INSERT: 45,
DOM_VK_DELETE: 46,
DOM_VK_0: 48,
DOM_VK_1: 49,
DOM_VK_2: 50,
DOM_VK_3: 51,
DOM_VK_4: 52,
DOM_VK_5: 53,
DOM_VK_6: 54,
DOM_VK_7: 55,
DOM_VK_8: 56,
DOM_VK_9: 57,
DOM_VK_SEMICOLON: 59,
DOM_VK_EQUALS: 61,
DOM_VK_A: 65,
DOM_VK_B: 66,
DOM_VK_C: 67,
DOM_VK_D: 68,
DOM_VK_E: 69,
DOM_VK_F: 70,
DOM_VK_G: 71,
DOM_VK_H: 72,
DOM_VK_I: 73,
DOM_VK_J: 74,
DOM_VK_K: 75,
DOM_VK_L: 76,
DOM_VK_M: 77,
DOM_VK_N: 78,
DOM_VK_O: 79,
DOM_VK_P: 80,
DOM_VK_Q: 81,
DOM_VK_R: 82,
DOM_VK_S: 83,
DOM_VK_T: 84,
DOM_VK_U: 85,
DOM_VK_V: 86,
DOM_VK_W: 87,
DOM_VK_X: 88,
DOM_VK_Y: 89,
DOM_VK_Z: 90,
DOM_VK_CONTEXT_MENU: 93,
DOM_VK_NUMPAD0: 96,
DOM_VK_NUMPAD1: 97,
DOM_VK_NUMPAD2: 98,
DOM_VK_NUMPAD3: 99,
DOM_VK_NUMPAD4: 100,
DOM_VK_NUMPAD5: 101,
DOM_VK_NUMPAD6: 102,
DOM_VK_NUMPAD7: 103,
DOM_VK_NUMPAD8: 104,
DOM_VK_NUMPAD9: 105,
DOM_VK_MULTIPLY: 106,
DOM_VK_ADD: 107,
DOM_VK_SEPARATOR: 108,
DOM_VK_SUBTRACT: 109,
DOM_VK_DECIMAL: 110,
DOM_VK_DIVIDE: 111,
DOM_VK_F1: 112,
DOM_VK_F2: 113,
DOM_VK_F3: 114,
DOM_VK_F4: 115,
DOM_VK_F5: 116,
DOM_VK_F6: 117,
DOM_VK_F7: 118,
DOM_VK_F8: 119,
DOM_VK_F9: 120,
DOM_VK_F10: 121,
DOM_VK_F11: 122,
DOM_VK_F12: 123,
DOM_VK_F13: 124,
DOM_VK_F14: 125,
DOM_VK_F15: 126,
DOM_VK_F16: 127,
DOM_VK_F17: 128,
DOM_VK_F18: 129,
DOM_VK_F19: 130,
DOM_VK_F20: 131,
DOM_VK_F21: 132,
DOM_VK_F22: 133,
DOM_VK_F23: 134,
DOM_VK_F24: 135,
DOM_VK_NUM_LOCK: 144,
DOM_VK_SCROLL_LOCK: 145,
DOM_VK_COMMA: 188,
DOM_VK_PERIOD: 190,
DOM_VK_SLASH: 191,
DOM_VK_BACK_QUOTE: 192,
DOM_VK_OPEN_BRACKET: 219,
DOM_VK_BACK_SLASH: 220,
DOM_VK_CLOSE_BRACKET: 221,
DOM_VK_QUOTE: 222,
DOM_VK_META: 224
*/

function ajaxRequest(url, Parameters, targetDivID, e, toNew) {
    //ShowWait("", "<span><img src=\"../graphics/ajaxwait2.gif\"  style=\"vertical-align:middle;\" />Loading data...</span>");
    var httpRq = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        httpRq = new XMLHttpRequest();
        if (httpRq.overrideMimeType) { httpRq.overrideMimeType('text/xml'); }
    } else {
        if (window.ActiveXObject) { // IE
            try { httpRq = new ActiveXObject("Msxml2.XMLHTTP"); }
            catch (e) {
                try { httpRq = new ActiveXObject("Microsoft.XMLHTTP"); }
                catch (e) { HideWait(); }
            }
        }
    }
    //custom block
    if (Parameters) {
    }
    //end of custom block

    if (!httpRq) { alert('Cannot create an XMLHTTP instance because you have denied ActiveX/plugin to run.\nWorldX data has not been loaded.'); return false; }
    httpRq.onreadystatechange = function() { ajaxReturnData(httpRq, targetDivID, toNew); }
    httpRq.open("GET", url + Parameters, true);
    try { httpRq.send(null) }
    catch (e) { alert("XMLHTTP request error: " + httpRq.status + ", " + e.description); }

    //final custom calls
}
//Put actual data into element
function ajaxReturnData(httpRq, targetDivID, toNew) {
    var tempChunk = '';
    if (httpRq.readyState > 0) { } //LoadStatus.innerHTML = "<br /><img src='./graphics/ajaxwait.gif'> processing..." + ((httpRq.readyState / 4)*100) + "%";}
    if (httpRq.readyState == 4) {
        if (httpRq.status == 200 || httpRq.responseText) {
            if (targetDivID) {
                if (httpRq.responseText.indexOf('[Alert Box]') >= 0 && httpRq.responseText.indexOf('[Alert Box]') <= 2) {
                    alert(httpRq.responseText.replace('[Alert Box]', 'Server Validation Error: \n'));
                } else {
                    document.getElementById(targetDivID).innerHTML = httpRq.responseText;
                    document.getElementById(targetDivID).scrollTop = 0;
                    if (toNew == false) { } else { window.location = '#' + targetDivID; }
                }
            } else { if (toNew == true) { openMe("", "", "", "", httpRq.responseText, "scrollbars=1, "); } else { alert(httpRq.responseText); } }
        } else { alert('There was a problem with the request. \n Status code:' + httpRq.status + "\n" + httpRq.responseText); HideWait(); }
        //HideWait();
    }
}