﻿function HKTGetIEVersion() {
    var agent = navigator.userAgent;
    var offset = agent.indexOf("MSIE");
    if (offset < 0) {
        return 0;
    }
    return parseFloat(agent.substring(offset + 5, agent.indexOf(";", offset)));
}
function HKTIsOSWin9x() {
    if ((navigator.userAgent.indexOf("Windows 98") != -1) || (navigator.userAgent.indexOf("Windows 95") != -1)) {
        return true;
    } else {
        return false;
    }
}
function HKTIsOSNT() {
    if (navigator.userAgent.indexOf("Windows NT")) {
        return true;
    } else {
        return false;
    }
}
function HKTIsIEAbove(version) {
    return (HKTGetIEVersion() >= version);
}

function HKTUrlAddParam(str1, str2) {
    if (str1.indexOf("?") > 0) {
        return str1 + "&" + str2;
    } else {
        return str1 + "?" + str2;
    }
}
function HKTCutDecimalDigits(val, digit) {
    var r = 1; //10<<digit;	
    for (var i = 0; i < digit; i++) {
        r = r * 10;
    }
    return parseInt(val * r) / r;
}

function HKTKeepSession() {
    if (HKTIsIEAbove(5)) {
        try {
            var SN_xml = new ActiveXObject("msxml");
            SN_xml.URL = "/adata/keepsn.aspx?rnd=" + _Rnd();
            var docroot = SN_xml.root;
            var nmyuserid = parseInt(docroot.children.item(0).text);
            if (nmyuserid >= 0) {
                G_bKeepByXML = true;
            } else {
                G_bKeepByXML = false;
            }

        } catch (e) {
            G_bKeepByXML = false;
        }

    }
    G_bKeepByXML = false;
    if (G_bKeepByXML == false) {
        HKTKeepSessionByInFrame();
    }
    setTimeout("HKTKeepSession()", G_timeSessionOut);
}
function HKTKeepSessionByInFrame() {
    if (G_bKeepSessionNoFrame == false) {
        if (document.all.IFRKeepSession == null) {
            document.body.insertAdjacentHTML("BeforeEnd", "<BR><div id=divKeepSession style='display:none;'><iframe id=IFRKeepSession></iframe></div>");
        }
        G_bKeepSessionNoFrame = true;
    }
    var obj = document.all.IFRKeepSession;
    if (obj != null) {
        obj.src = "/adata/keepsn.aspx?rnd=" + _Rnd();
    }
}
function HKTInsertText(obj, strInsertText) {
    if (strInsertText <= 0) return false;
    var objTextArea = obj; //
    if (objTextArea) {

        if (strInsertText == 'space') {
            strInsertText = '&nbsp;';
        }
        else if (strInsertText == 'lt') {
            strInsertText = '&lt;';
        }
        else if (strInsertText == 'gt') {
            strInsertText = '&gt;';
        }
        else if (strInsertText == 'amp') {
            strInsertText = '&amp;';
        }

        if (document.selection && document.selection.createRange) {
            objTextArea.focus();
            var objSelectedTextRange = document.selection.createRange();
            var strSelectedText = objSelectedTextRange.text;
            objSelectedTextRange.text = strInsertText + strSelectedText;
        }
        else {
            objTextArea.value += strInsertText;
            objTextArea.focus();
        }

    }
    return false;
}

function HKTOpenWindow(theURL, winName, features) {
    var objwin = window.open("about:blank", winName, features);
    if (objwin != null) {
        objwin.navigate(theURL);
    }
}
function HKTDebug(val) {
    HKTDebug(val, '', 'width=320,height=240');
}
function HKTDebug(val, winName, features) {
    //var win =window.open("about:blank",winName,features);
    //win.document.body.innerText=val;
    _debug(val);
}
var _console = null;
function _debug(msg) {
    if ((_console == null) || (_console.closed)) {
        _console = window.open("", "console", "scrollbars, resizable", "width=600, height=300, resizable");
        _console.document.open("text/plain");
    }
    _console.document.writeln(msg);
}

function HKTDebugHTML(val, winName, features) {
    var win = window.open("about:blank", winName, features);
    win.document.body.innerHTML = val;
}
function HKTDebugHTML(val) {
    HKTDebugHTML(val, '', 'width=320,height=240');
}
//读取窗体数据v1.0
function LoadWinData() {
    if (window.formKeepData != null) {
        if (formKeepData.keepform != "") {
            var objForm;
            var objE;
            eval("objForm=" + formKeepData.keepform);
            for (var i = 0; i < formKeepData.elements.length; i++) {
                if (formKeepData.elements[i].value != "==NONE==") {
                    if (formKeepData.elements[i].keeptype == "span") {
                        eval("objE=window.document." + formKeepData.elements[i].id);
                        if (objE != null) {
                            eval("objE.innerText=formKeepData.elements[i].value;");
                        }
                    }
                }
            }
        }
    }
}
//保存窗体数据v1.0
function SaveWinData() {
    if (window.formKeepData != null) {
        if (formKeepData.keepform != "") {
            var objForm;
            var objE;
            eval("objForm=" + formKeepData.keepform);
            for (var i = 0; i < formKeepData.elements.length; i++) {
                if (formKeepData.elements[i].keeptype == "span") {
                    eval("objE=window.document." + formKeepData.elements[i].id);
                    if (objE != null) {
                        eval("formKeepData.elements[i].value = objE.innerText");
                    }
                }
            }
        }
    }
}

function HKTReplace(str, a, b) {
    while (str.indexOf(a) != -1) {
        str = str.replace(a, b);
    }
    return str;
}

function HKTShowErrorTip(tip) {
    var obj = window.DivErrorTip;
    if (obj != null) {
        obj.style.display = "block";
        obj.innerHTML = tip;
        obj.className = "clErrorTip";

    } else {
        alert(tip);
    }
}

