﻿//$Revision: 19857 $

function getObj(id) {
    return document.getElementById(id);
}
function getBrowserHeight() {
    if (window.innerHeight) {
        winHeight = window.innerHeight;
    } else if ((document.body) && (document.body.clientHeight)) {
        winHeight = document.body.clientHeight;
    }
    if (document.documentElement && document.documentElement.clientHeight) {
        winHeight = document.documentElement.clientHeight;
    }
    return winHeight;
}
function getBrowserWidth() {
    if (window.innerWidth) {
        winWidth = window.innerWidth;
    } else if ((document.body) && (document.body.clientWidth)) {
        winWidth = document.body.clientWidth;
    }
    if (document.documentElement && document.documentElement.clientWidth) {
        winWidth = document.documentElement.clientWidth;
    }
    return winWidth;
}

function isIE() {
    return navigator.appName == "Microsoft Internet Explorer";
}
function dopostback(url, data, _class) {
    $.ajax({
        url: url,
        type: 'Post',
        data: data,
        dataType: 'json',
        timeout: 150000,
        error: function(ee, dd) {
            verifyImgRefresh();
            if(ee.readyState == 4 && ee.status == 200)
            {
                document.write(ee.responseText);
                return;
            }
            if (dd == 'timeout') {
                $("#errorinfo").html("提交超时，请重新再试").show();
                _class.close();
            }
            else {
                document.location.href = '../error.aspx?errormsg=' + dd;
            }
        },
        success: function(e) {
            verifyImgRefresh();
            if (e.State == 0) {
                $("#endinfo").html(e.Msg);
                $("#buyfield").hide();
                $("#endfield").show();
                var urlStr = url;
                if(urlStr.indexOf('buycard_zc_kingsofthe.aspx') >= 0)
                {
                    $("#span_verify").html("<img  id=\"verify_img\" align=absmiddle border=0 src='../esalesimg/img_kingsoft.aspx?rnd=\", Math.random(), \"'>");
                }
                else if (urlStr.indexOf('KingsoftEsalesPage.aspx') >= 0) {
                    $("#span_verify").html("<img  id=\"verify_img\" align=absmiddle border=0 src=\"verifyCode.aspx?rnd=" + Math.random() + "\">");
                }
                
                $("#errorinfo").html("").hide();
                _class.close();
            }
            else {
                $("#errorinfo").html(e.Msg).show();
                _class.close();
            }
        }
    });

    return false;
}

function dopostback_new(url, data, _class, esTypeID) {
    $.ajax({
        url: url,
        type: 'Post',
        data: data,
        dataType: 'json',
        timeout: 150000,
        error: function(ee, dd) {
            verifyImgRefreshNew(esTypeID);
            if(ee.readyState == 4 && ee.status == 200)
            {
                document.write(ee.responseText);
                return;
            }
            if (dd == 'timeout') {
                $("#errorinfo").html("提交超时，请重新再试").show();
                _class.close();
            }
            else {
                document.location.href = '../error.aspx?errormsg=' + dd;
            }
        },
        success: function(e) {
            
            if (e.State == 0) {
                $("#endinfo").html(e.Msg);
                $("#buyfield").hide();
                $("#endfield").show();
                var urlStr = url;
                if (urlStr.indexOf('KingsoftEsalesPage.aspx') >= 0) {
                    $("#span_verify").html("<img  id=\"verify_img\" align=absmiddle border=0 src=\"verifyCode.aspx?rnd=" + Math.random() + "&esaleTypeID="+ esTypeID +"\">");
                }
                $("#errorinfo").html("").hide();
                _class.close();
            }
            else {
                verifyImgRefreshNew(esTypeID);
                $("#errorinfo").html(e.Msg).show();
                _class.close();
            }
        }
    });

    return false;
}

function dopostback_more(url, data, _class,imgurl) {
    $.ajax({
        url: url,
        type: 'Post',
        data: data,
        dataType: 'json',
        timeout: 150000,
        error: function(ee, dd) {
        verifyImgRefresh_more(imgurl);
            if (dd == 'timeout') {
                $("#errorinfo").html("提交超时，请重新再试").show();
                _class.close();
            }
            else {
                document.location.href = '../error.aspx?errormsg=' + dd;
            }
        },
        success: function(e) {
        verifyImgRefresh_more(imgurl);
            if (e.State == 0) {
                $("#endinfo").html(e.Msg);
                $("#buyfield").hide();
                $("#endfield").show();
                $("#errorinfo").html("").hide();
                var urlStr = url;
                if(urlStr.indexOf('buycard_zc_kingsofthe.aspx') >= 0)
                {
                    $("#span_verify").html("<img  id=\"verify_img\" align=absmiddle border=0 src='../esalesimg/img_kingsoft.aspx?rnd=\", Math.random(), \"'>");
                }
                else if (urlStr.indexOf('KingsoftEsalesPage.aspx') >= 0) {
                    $("#span_verify").html("<img  id=\"verify_img\" align=absmiddle border=0 src=\"verifyCode.aspx?rnd=" + Math.random() + "\">");
                }
                _class.close();
            }
            else {
                $("#errorinfo").html(e.Msg).show();
                _class.close();
            }
        }
    });

    return false;
}
function popup() {
    this.html = '<div id="cover"></div>';
    if (isIE())
        this.html += '<iframe id="ifm" src="javascript:false;" frameborder="0"></iframe>';
    this.html += '<div class="popup" id="popWin"><div class="popCont"><div class="close" id="cls"><a href="javascript:void(0)" onclick="Popup.close()">×</a></div><h2></h2><div id="info"></div><div id="doing" class="doing">正在提交，请稍后。。。</div><div id="btns"><input type="button" value="确 定" id="y" class="btn02" />&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" id="n" value="取 消" class="btn02" /></div></div></div>';
    this.dom = document.createElement("div");
    this.bodyHeight = document.body.offsetHeight;
    this.bodyWidth = document.body.offsetWidth;
    this.clientHeight = getBrowserHeight();
    this.clientWidth = getBrowserWidth();
    this.bodyHeight = this.bodyHeight < this.clientHeight ? this.clientHeight : this.bodyHeight;
    this.ini();
}
popup.prototype = {
    ini: function() {
        try {
            Popup.close();
        } catch (e) {
        }
        this.dom.innerHTML = this.html;
        this.dom.style.display = "none";
        document.body.appendChild(this.dom);
        this.popWin = getObj("popWin");
        this.cover = getObj("cover");
    },
    show: function(width) {
        this.dom.style.display = "block";
        this.cover.style.height = this.bodyHeight + "px";
        if (isIE())
            getObj("ifm").style.height = this.bodyHeight + "px";
        this.popWin.style.top = (this.clientHeight - this.popWin.offsetHeight) / 2 + document.documentElement.scrollTop + "px";
        this.popWin.style.left = (this.clientWidth - this.popWin.offsetWidth) / 2 + document.documentElement.scrollLeft + "px";
    },
    close: function() {
        document.body.removeChild(this.dom);
    },
    alertMsg: function(t, s, func) {
        this.ini();
        var _class = this;
        this.dom.getElementsByTagName("h2")[0].innerHTML = t;
        if (s != "") {
            getObj("info").innerHTML = "<p>" + s + "<\/p>";
        }
        getObj("n").style.display = "none";
        getObj("y").onclick = function() {
            _class.close();
            if (func) {
                func();
            };
        }
        this.show();
    },
    confirmMsg: function(t, d, s, func) {
        this.ini();
        var _class = this;
        this.dom.getElementsByTagName("h2")[0].innerHTML = t;
        if (d.length > 0) {
            var str = [];
            for (var index = 0, l = d.length; index < l; index++) {
                str.push(["<h5>", d[index], "<\/h5>"].join(""));
            }
            getObj("info").innerHTML = str.join("");
        }
        if (typeof (s) != "") {
            getObj("info").innerHTML += "<p>" + s + "<\/p>";
        }
        getObj("y").onclick = function() {
            getObj("cls").style.display = "none";
            getObj("btns").style.display = "none";
            getObj("doing").style.display = "block";
            //getObj("doing").innerHTML = '<img src="../images/loading.gif" align="absmiddle" /> 正在提交，请稍后。。。';
            //_class.close();
            if (func) {
                func(true, _class);
            };
        }
        getObj("n").onclick = function() {
            _class.close();
            if (func) {
                func(false, _class);
            };
        }
        this.show();
    },
    loading: function(s) {
        this.ini();
        getObj("info").innerHTML = "<h5>" + s + "<\/h5>";
        getObj("n").style.display = "none";
        getObj("y").style.display = "none";
        getObj("cls").style.display = "none";
        this.show();
    }
}
window.onload = function() {
    Popup = new popup();
}
window.onresize = function() {
    Popup = new popup();
}

