﻿function $A(ctlName) {
    return document.getElementById(ctlName);
}

function $B(ctlName) {
    return document.getElementById("ctl00_CB_" + ctlName);
}

function ctlA(e) {
    var xobj;
    if (window.event) {
        xobj = window.event.srcElement;
    } else {
        xobj = e.target;
    }
    return xobj;
}


function xmlCreateA() {
    var xmlHttp;
    if (typeof XMLHttpRequest != 'undefined') {
        xmlHttp = new XMLHttpRequest();
    } else {
    try {
        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e1) {
        try {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e2) {
        xmlHttp = null;
        }
    }
}
return xmlHttp;
}


function xmlSyncA(url, postData) {
    var  req = xmlCreateA();
    if (req == null) return;
    var method = (postData) ? "POST" : "GET";
    req.open(method, url, false);
    req.setRequestHeader('User-Agent', 'XMLHTTP/1.0');
    if (postData) req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    req.send(postData);
    return req.responseText;
}

function xmlAsyncA(url, postData, oncomplete, onconnecterror, onfinish) {
    var xtimeout;
    var req = xmlCreateA();
    if (req == null) return;
    var method = (postData) ? "POST" : "GET";
    req.open(method, url, true);
    req.setRequestHeader('User-Agent', 'XMLHTTP/1.0');
    if (postData) req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    xtimeout = window.setTimeout(function() {
        req.abort();
        if (onconnecterror) {
            onconnecterror();
        }
        if (onfinish) {
            onfinish();
        }
        alert("Cannot connect to Server, please try again later");
    }, 10000);
    req.onreadystatechange = function() {
        if (req.readyState != 4) return;
        if (req.status != 200 & req.status != 304) return;
        window.clearTimeout(xtimeout);
        oncomplete(req);
        if (onfinish) {
            onfinish();
        }
    }
    
    req.send(postData);
    
}

function comboFill(xobj, strData) {
    xobj.innerHTML = "";
    var A1 = strData.split("@@");
    var A2;
    var i;
    var o1;
    for (i = 0; i < A1.length; i++) {
        A2 = A1[i].split("##");
        o1 = document.createElement("OPTION");
        o1.value = A2[0];
        o1.text = A2[1];
        xobj.options.add(o1);
    }
}

function keyA(e) {
    var xKey;
    if (document.all) {
        e = window.event;
        xKey = e.keyCode;
    } else {
        xKey = e.which;
    }
    return xKey;
}

function ctlTopA(xobj) {
    var oNode = xobj;
    var iTop = 0;
    while (oNode.tagName != "BODY") {
        iTop += oNode.offsetTop;
        oNode = oNode.offsetParent;
    }
    return iTop + xobj.offsetHeight ;
}


function ctlLeftA(xobj) {
    var oNode = xobj;
    var iLeft = 0;
    while (oNode.tagName != "BODY") {
        iLeft+= oNode.offsetLeft;
        oNode = oNode.offsetParent;
    }
    return iLeft;
}

function pixelA(xunit) {
    xunit = xunit.replace("px");
    if (xunit == "") { xunit = "0"}
    return parseInt(xunit);
}


function ovA(e) {
    var xobj;
    xobj = ctlA(e);
    if (xobj.id != "divpop") {
        xobj.className = "cx1";
    }
}

function ouA(e) {
    var xobj;
    xobj = ctlA(e);
    if (xobj.id != "divpop") {
        xobj.className = "";
    }
}

function filterPop(xobj2) {
    var xobj;
    xobj = document.getElementById("divpop");
    xobj = xobj.firstChild;
    while (xobj != null) {
        if (xobj.nodeType == 1) {
            x2 = xobj.innerHTML.toUpperCase();
            if (x2.indexOf(xobj2.value.toUpperCase()) == 0) {
                xobj.style.display = "";
            } else {
                xobj.style.display = "none";
            }
        }
        xobj = xobj.nextSibling;
    }
}

function trimA(xstring) {
    return xstring.replace(/^\s+|\s+$/g, "");
}

function replaceA(srcString, findString, replString) {
    var _reg = new RegExp(findString, "gim");
    return srcString.replace(_reg, replString);
}

function numberFormatA(Expression, NumDigitsAfterDecimal) {
    var iNumDecimals = NumDigitsAfterDecimal;
    var dbInVal = Expression;
    var bNegative = false;
    var iInVal = 0;
    var strInVal
    var strWhole = "", strDec = "";
    var strTemp = "", strOut = "";
    var iLen = 0;

    if (dbInVal < 0) {
        bNegative = true;
        dbInVal *= -1;
    }

    dbInVal = dbInVal * Math.pow(10, iNumDecimals)
    iInVal = parseInt(dbInVal);
    if ((dbInVal - iInVal) >= .5) {
        iInVal++;
    }
    strInVal = iInVal + "";
    strWhole = strInVal.substring(0, (strInVal.length - iNumDecimals));
    strDec = strInVal.substring((strInVal.length - iNumDecimals), strInVal.length);
    while (strDec.length < iNumDecimals) {
        strDec = "0" + strDec;
    }
    iLen = strWhole.length;
    if (iLen >= 3) {
        while (iLen > 0) {
            strTemp = strWhole.substring(iLen - 3, iLen);
            if (strTemp.length == 3) {
                strOut = "," + strTemp + strOut;
                iLen -= 3;
            }
            else {
                strOut = strTemp + strOut;
                iLen = 0;
            }
        }
        if (strOut.substring(0, 1) == ",") {
            strWhole = strOut.substring(1, strOut.length);
        }
        else {
            strWhole = strOut;
        }
    }

    if (NumDigitsAfterDecimal == 0) {
        return strWhole;
    }
    
    if (bNegative) {
        return "-" + strWhole + "." + strDec;
    }
    else {
        xmoney = strWhole + "." + strDec;
        if (xmoney == ".00") { xmoney = "0.00" }
        return xmoney;
    }
}

function valA(xNum) {
    if (xNum == "") {xNum = "0";}
    var xNum2 = replaceA(xNum, ",", "");
    return parseFloat(xNum2);
}

function cancelBubbleA(e) {
    if (!e) { e = window.event }
    if (e.stopPropagation) {
        e.stopPropagation();
    } else {
    e.cancelBubble = true;
    }
}

function heightA() {
    var _h;
    var _h1 = document.body.scrollHeight;
    var _h2 = document.body.offsetHeight;
    if (_h1 > _h2) {
        _h = _h1;
    } else {
       _h = _h2;
   }
    return _h;
}

function widthA() {
    var _w1 = document.body.scrollWidth;
    var _w2 = document.body.offsetHeight;
    if (_w1 > _w2) {
        return _w1;
    } else {
       return _w2;
    }
}

function opacityA(opacity, xobj) {
    var s1 = xobj.style;
    s1.opacity = (opacity / 100);
    s1.MozOpacity = (opacity / 100);
    s1.KhtmlOpacity = (opacity / 100);
    s1.filter = "alpha(opacity=" + opacity + ")";
}


function topA() {
    return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

function LeftA() {
    return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}
