﻿var IsNeedToShowLoading = true;

function $get(name) {
    return document.getElementById(name);
}

function AddEvent(obj, evType, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, false);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on" + evType, fn);
        return r;
    } else {
        return false;
    }
}

function DisplayLoad() {
    if (IsNeedToShowLoading) {
        parent.document.getElementById("LoadBg").style.display = "block";

        parent.document.getElementById("Load").style.top = (document.documentElement.clientHeight - parent.document.getElementById("Load").offsetHeight) / 3 + "px";
        parent.document.getElementById("Load").style.display = "block";
    }
    else {
        IsNeedToShowLoading = true;
    }
}

function HideLoad() {
    parent.document.getElementById("LoadBg").style.display = "none";

    parent.document.getElementById("Load").style.display = "none";
}

function CancelDisplayLoading(){
    IsNeedToShowLoading = false;
}

function FrameHideLoad() {
    document.getElementById("LoadBg").style.display = "none";

    document.getElementById("Load").style.display = "none";
}


function SetActiveTab(index,ctrl) 
{
    var tabpanel = ctrl.get_tabs()[index];
    ctrl.set_activeTab(tabpanel);
}

function CommonCheckABN(conctecABN) {
    var listABN = new Array(11);
    var listParam = new Array(10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19);
    var x = 0;
    for (var i = 0; i < conctecABN.length; i++) {

        var tempChar = conctecABN.substr(i, 1);
        if (tempChar != " ") {
            listABN[x] = tempChar;
            x++;
        }
    }

    var sum = 0;
    for (var j = 0; j < listABN.length; j++) {

        listABN[j] = j == 0 ? listABN[j] - 1 : listABN[j];

        sum += listABN[j] * listParam[j];
    }
    var returnResule = sum % 89;

    return returnResule;
}

function SubstringUrlParamenter(paraName, url) {
    var intPos = url.indexOf('?');
    var strRight = url.substr(intPos + 1);
    var arrTmp = strRight.split("&");
    for (var i = 0; i < arrTmp.length; i++) {
        var arrTemp = arrTmp[i].split("=");

        if (arrTemp[0].toUpperCase() == paraName.toUpperCase()) return arrTemp[1];
    }
    return "";
}

function isIE() { //ie? 
    if (window.navigator.userAgent.indexOf("MSIE") >= 1)
        return true;
    else
        return false;
}

if (!isIE()) { //firefox innerText define
    HTMLElement.prototype.__defineGetter__("innerText",
        function() {
            return this.textContent;
        }
    );
    HTMLElement.prototype.__defineSetter__("innerText",
        function(sText) {
            this.textContent = sText;
        }
    );
}

// correctly handle PNG transparency in Win IE 5.5 & 6.
function correctPNG() {
    
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])
    if ((version >= 5.5) && (document.body.filters)) {
        for (var j = 0; j < document.images.length; j++) {
            var img = document.images[j]
            var imgName = img.src.toUpperCase()
            if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
                var imgID = (img.id) ? "id='" + img.id + "' " : ""
                var imgClass = (img.className) ? "class='" + img.className + "' " : ""
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
                var imgStyle = "display:inline-block;" + img.style.cssText
                if (img.align == "left") imgStyle = "float:left;" + imgStyle
                if (img.align == "right") imgStyle = "float:right;" + imgStyle
                if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
                var strNewHTML = "<span " + imgID + imgClass + imgTitle
             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
             + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
                img.outerHTML = strNewHTML
                j = j - 1
            }
        }
    }
}
window.attachEvent("onload", correctPNG);
