﻿var $e = function(i) { return document.getElementById(i); }
var $v = function(i) { if ($e(i)) return $e(i).value; else return null; }
var $r = function(n) {
    while (n) {
        if (n.nodeType == 1 && n.tagName) return n;
        else n = n.nextSibling;
    }
    return null;
}
var SxjAjax = {
    init: function() {
        SxjAjax.Dialog.init();
    },
    ContactUs: function() {
        alert("请联系客服0574-86535185!");
    }
};
window.onload = function() { SxjAjax.init(); } //SxjAjax.Search.StartClock();
SxjAjax.Login = {
    submit: function() {
        var pwd = $e("pwd").value;
        var uname = $e("usr").value;
        if (pwd == "") {
            alert("请输入密码!");
        }
        else {
            if (uname == "") {
                alert("请输入用户名!");
            }
            else {
                var url = "/Portals/Member/DataAjax.ashx?cmd=get_login&fmt=html";
                var suc = function(h) {
                    if (h == "2") {
                        alert("登录失败!");
                    }
                    else {
                        alert("登录成功");
                        $e("login_txt").innerHTML = "欢迎您：" + h;
                    }
                }
                $.ajax({ type: "POST", data: { usr: uname, pwd: pwd }, url: url, cache: false, dataType: "html", success: suc });
            }
        }
    },
    DcSubmit: function() {
        var pwd = $e("pwd").value;
        var uname = $e("usr").value;
        if (pwd == "") {
            alert("请输入密码!");
        }
        else {
            if (uname == "") {
                alert("请输入用户名!");
            }
            else {
                var url = "/Portals/Member/DataAjax.ashx?cmd=get_login&fmt=html";
                var suc = function(h) {
                    if (h == "2") {
                        alert("登录失败!");
                    }
                    else {
                        alert("登录成功");
                        SxjAjax.Dialog.close();
                    }
                }
                $.ajax({ type: "POST", data: { usr: uname, pwd: pwd }, url: url, cache: false, dataType: "html", success: suc });
            }
        }
    },
    IndexSubmit: function() {
        var pwd = $e("pwd").value;
        var uname = $e("usr").value;
        if (pwd == "") {
            alert("请输入密码!");
        }
        else {
            if (uname == "") {
                alert("请输入用户名!");
            }
            else {
                var url = "/Portals/Member/DataAjax.ashx?cmd=get_Indexlogin&fmt=html";
                var suc = function(h) {
                    if (h == "2") {
                        alert("登录失败!");
                    }
                    else {
                        alert("登录成功");
                        $e("Loginbox").innerHTML = "<li class=\"title\">会员登录</li><li class=\"center\">欢迎您：" + h + "  <a href=\"javascript:void(0)\" onclick=\"SxjAjax.Login.OutLogin()\">退出</a></li><li class=\"bottom\"></li>";
                    }
                }
                $.ajax({ type: "POST", data: { usr: uname, pwd: pwd }, url: url, cache: false, dataType: "html", success: suc });
            }
        }
    },
    insitIndex: function() {
        var url = "/Portals/Member/DataAjax.ashx?cmd=insit_indexlogin&fmt=html";
        var suc = function(h) {
            if (h == "2") {
            }
            else {
                //alert("登录成功");
                $e("Loginbox").innerHTML = "<li class=\"title\">会员登录</li><li class=\"center\">欢迎您：" + h + "  <a href=\"javascript:void(0)\" onclick=\"SxjAjax.Login.OutLogin()\">退出</a></li><li class=\"bottom\"></li>";
            }
        }
        $.ajax({ type: "POST", data: {}, url: url, cache: false, dataType: "html", success: suc });
    },
    OutLogin: function() {
        var url = "/Portals/Member/DataAjax.ashx?cmd=outlogin&fmt=html";
        var suc = function(h) {
            if (h == "1") {
                window.location.href = "/";
            }
            else {
                alert("退出失败!");
            }
        }
        $.ajax({ type: "POST", data: {}, url: url, cache: false, dataType: "html", success: suc });
    },
    inist: function() {
        var url = "/Portals/Member/DataAjax.ashx?cmd=insit_login&fmt=html";
        var suc = function(h) {
            if (h == "2") {
            }
            else {
                //alert("登录成功");
                $e("login_txt").innerHTML = "欢迎您：" + h;
            }
        }
        $.ajax({ type: "POST", data: {}, url: url, cache: false, dataType: "html", success: suc });
    },
    OpenLogin: function() {
        var os = new oStringBuffer();
        os.append('<div style="font-size:12px;text-align:center;padding:5px;color:#000;">帐&nbsp;&nbsp;号：<input type="text" id="usr" class="input_login"/><br/>');
        os.append('密&nbsp;&nbsp;码：<input type="password" id="pwd" class="input_login"/><br/>');
        os.append('<input type="button" style="margin-top:7px;"  class="send" value="登录" onclick="SxjAjax.Login.submit()"/></div>');
        SxjAjax.Dialog.show('用户登录', os.toString(), { width: 258, height: 130 });
    },
    OpenDcLogin: function() {
        var os = new oStringBuffer();
        os.append('<div style="font-size:12px;text-align:center;padding:5px;color:#000;">帐&nbsp;&nbsp;号：<input type="text" id="usr" class="input_login"/><br/>');
        os.append('密&nbsp;&nbsp;码：<input type="password" id="pwd" class="input_login"/><br/>');
        os.append('<input type="button" style="margin-top:7px;"  class="send" value="登录" onclick="SxjAjax.Login.DcSubmit()"/></div>');
        SxjAjax.Dialog.show('用户登录', os.toString(), { width: 258, height: 130 });
    }
}
SxjAjax.Vote = {
    insist: function(a, b, c, d, e) {
        var os = new oStringBuffer();
        os.append('<div style="font-size:12px;text-align:center;padding:5px;color:#000;">');
        os.append('<label><input type="radio" name="radiovote" value="1" />实名</label><label><input type="radio" name="radiovote" value="2"  checked="checked"/>匿名</label><br/>');
        os.append('</div>');
        SxjAjax.Dialog.show('投票', os.toString(), { width: 258, height: 100 }, 'SxjAjax.Vote.select(' + a + ',' + b + ',' + c + ',' + d + ',' + e + ')');
    },
    select: function(a, b, c, d, e) {
        var selvalue = "2";
        //var obj = document.getElementsByName("radiovote");
        //for (i = 0; i < obj.length; i++) {
        //    if (obj[i].checked == true) {
        //        selvalue = obj[i].value
        //    }
        //}
        //alert(selvalue);
        if (selvalue == "1") {
            //alert("登录成功");
            var urlv = "/Portals/Member/DataAjax.ashx?cmd=vote&fmt=html";
            var sucv = function(h) {
                if (h == "3") {
                    alert("今天您已经投过票，请明天再来！");
                }
                else if (h == "2") {
                    alert("投票失败!");
                }
                else {
                    //var url = "/Portals/Member/DataAjax.ashx?cmd=insit_login&fmt=html";
                    //var suc = function(h) {
                    //    if (h == "2") {
                    alert("请先登录!");
                    SxjAjax.Vote.OpenLogin(a, b, c, e);
                    //    }
                    //    else {
                    //        SxjAjax.Dialog.close();
                    //        window.open("http://ask.87188718.com/Nbsme_8718/Web/8718-All/RefApp/Enterprise/Post.aspx?cid=" + b + "&aid=" + c + "&F_CCall=True&UId=" + uid + "&Pwd=" + pwd);
                    //        return;
                    //    }
                    //}
                    //$.ajax({ type: "POST", data: {}, url: url, cache: false, dataType: "html", success: suc });
                }
            }
            $.ajax({ type: "POST", data: { type: a, id: b, votetype: "1", votecount: d }, url: urlv, cache: false, dataType: "html", success: sucv });
        }
        else if (selvalue == "2") {
            //alert("投票成功!");
            var urlv = "/Portals/Member/DataAjax.ashx?cmd=vote&fmt=html";
            var sucv = function(h) {
                if (h == "3") {
                    alert("今天您已经投过票，请明天再来！");
                }
                else if (h == "2") {
                    alert("投票失败!");
                }
                else {
                    //SxjAjax.Dialog.close();
                    var os = new oStringBuffer();
                    os.append('<div style="font-size:12px;text-align:center;padding:5px;color:#000;">');
                    os.append('投票成功，谢谢参与，欢迎明天再来投票!');
                    os.append('</div>');
                    SxjAjax.Dialog.show('投票', os.toString(), { width: 258, height: 130 }, 'SxjAjax.Dialog.close()');
                }
            }
            $.ajax({ type: "POST", data: { type: a, id: b, votetype: "2", votecount: d }, url: urlv, cache: false, dataType: "html", success: sucv });
        }
    },
    OpenLogin: function(a, b, c, d) {
        var os = new oStringBuffer();
        os.append('<div style="font-size:12px;text-align:center;padding:5px;color:#000;">帐&nbsp;&nbsp;号：<input type="text" id="usr" class="input_login"/><br/>');
        os.append('密&nbsp;&nbsp;码：<input type="password" id="pwd" class="input_login"/>');
        os.append('没用帐户吗? 请<a href="http://www.71907190.com/RegPage.htm" target="_blank">注册</a>或进入网上接待室向我们咨询');
        os.append('</div>');
        SxjAjax.Dialog.show('用户登录', os.toString(), { width: 258, height: 160 }, 'SxjAjax.Vote.submit(' + a + ',' + b + ',' + c + ',' + d + ')');
    },
    submit: function(a, b, c, d) {
        var pwd = $e("pwd").value;
        var uname = $e("usr").value;
        if (pwd == "") {
            alert("请输入密码!");
        }
        else {
            if (uname == "") {
                alert("请输入用户名!");
            }
            else {
                var url = "/Portals/Member/DataAjax.ashx?cmd=get_votelogin&fmt=html";
                var suc = function(h) {
                    if (h == "2") {
                        alert("登录失败!");
                    }
                    else {
                        var a = h.split('@');
                        SxjAjax.Vote.OpenUrl("http://ask.87188718.com/Nbsme_8718/Web/8718-All/RefApp/Enterprise/Post.aspx?modid=" + d + "&cid=" + b + "&aid=" + c + "&F_CCall=True&UId=" + a[0] + "&Pwd=" + a[1]);
                        SxjAjax.Dialog.close();
                        return;
                    }
                }
                $.ajax({ type: "POST", data: { usr: uname, pwd: pwd }, url: url, cache: false, dataType: "html", success: suc });
            }
        }
    },
    OpenUrl: function(url) {
        var omvc = window.open(url);
        document.getElementById("reply_content").focus();
        if (omvc && omvc.open && !omvc.closed)
            omvc.focus();

    }
}
SxjAjax.Reply = {
    submit: function() {
        var ij = $e("nm_ck").checked;
        var type = "0";
        var content = $e("reply_txt").value;
        if (content == "") {
            alert("其请先输入内容!");
        }
        else {
            var ret = false;
            for (var i = 0; i < content.length; i++) {
                if (content.slice(i, i + 1) != " ") {
                    ret = true;
                    break;
                }
            }
            if (ret) {
                var id = $e("hid_id").value;
                var sss = id.split("@");
                var di = sss[0];
                var dii = sss[1];
                if (!ij) {
                    type = "1";
                }
                else {
                    type = "2";
                }
                var replcount = $e("hid_count").value;
                var url = "/Portals/Member/DataAjax.ashx?cmd=replysubmit&fmt=html";
                var suc = function(h) {
                    if (h == "2") {
                        alert("提交失败!");
                    }
                    else {
                        alert("提交成功");
                        var cm = E9.dom.get('ReplyContent');
                        insertHtml("afterbegin", cm, h);
                        $e("reply_txt").value = "";
                    }
                }
                $.ajax({ type: "POST", data: { content: content, id: di, type: type, replycount: replcount, s_type: dii }, url: url, cache: false, dataType: "html", success: suc });
            }
            else {
                alert("请输入正确的字符!谢谢");
            }
        }
    },
    PageTo: function(page) {
        var id = $e("hid_id").value;
        var sss = id.split("@");
        var di = sss[0];
        var dii = sss[1];
        var url = "/Portals/Member/DataAjax.ashx?cmd=replypageto&fmt=html";
        var suc = function(h) {
            if (h == "2") {
                alert("提交失败!");
            }
            else {
                var a = h.split("@#@");
                $e('ReplyContent').innerHTML = a[0];
                $e('page_txt').innerHTML = a[1];
            }
        }
        $.ajax({ type: "POST", data: { id: di, page: page, type: dii }, url: url, cache: false, dataType: "html", success: suc });
    }
}
SxjAjax.WebSurvey = {
    OpenDialog: function() {
        var url = "/Portals/Member/DataAjax.ashx?cmd=insit_login&fmt=html";
        var os = new oStringBuffer();
        var suc = function(h) {
          if (h == "2") {
            alert("请先登录!");
            SxjAjax.Login.OpenLogin();
          }
          else {
            os.append('<div style="font-size:12px;text-align:left;padding:5px;color:#000;">标&nbsp;&nbsp;题：<input type="text" id="dc_name" class="input_login"/><br/>');
            os.append('内&nbsp;&nbsp;容：<textarea id="dc_txt" name="dc_txt" style="width: 315px; height: 305px"></textarea><br/>');
            os.append('<input type="button" style="margin-top:7px;"  class="send" value="提交" onclick="SxjAjax.WebSurvey.submit()"/></div>');
            SxjAjax.Dialog.show('发表网上调查', os.toString(), { width: 450, height: 310 });
            var oFCKeditor = new FCKeditor("dc_txt");
            oFCKeditor.BasePath = "/fck_editor/";
            oFCKeditor.ReplaceTextarea();
            $e("dc_txt___Frame").src = $e("dc_txt___Frame").src;
          }
        }
        $.ajax({ type: "POST", data: {}, url: url, cache: false, dataType: "html", success: suc });
    },
    OpenDialogZaTan:function(){
        var os = new oStringBuffer();
        os.append('<div style="font-size:12px;text-align:left;padding:5px;color:#000;">标&nbsp;&nbsp;题：<input type="text" id="dc_name" class="input_login"/><br/>');
        os.append('内&nbsp;&nbsp;容：<textarea id="dc_txt" name="dc_txt" style="width: 315px; height: 305px"></textarea><br/>');
        os.append('<input type="button" style="margin-top:7px;"  class="send" value="提交" onclick="SxjAjax.WebSurvey.ZaTanSubmit()"/></div>');
        SxjAjax.Dialog.show('发布杂谈', os.toString(), { width: 450, height: 310 });
        var oFCKeditor = new FCKeditor("dc_txt");
        oFCKeditor.BasePath = "/fck_editor/";
        oFCKeditor.ReplaceTextarea();
        $e("dc_txt___Frame").src = $e("dc_txt___Frame").src;
    },
    submit: function() {
        //debugger;
        FCKeditorAPI.GetInstance('dc_txt').UpdateLinkedField();
        var url = "/Portals/Member/DataAjax.ashx?cmd=WebSurvey&fmt=html";
        var gid = $e("Gid_Value").value;
        var title = $e("dc_name").value;
        var content = $e("dc_txt").value;
        if (title == "") {
            alert("请输入标题!");
        }
        else {
            if (content == "") {
                alert("请输入内容!");
            }
            else {
                var suc = function(h) {
                    if (h == "2") {
                        alert("提交失败!");
                    }
                    else if (h == "1") {
                        alert("提交成功!");
                        SxjAjax.Dialog.close();
                    }
                }
                $.ajax({ type: "POST", data: { aid: gid, title: title, content: content }, url: url, cache: false, dataType: "html", success: suc });
            }
        }
    },
    ZaTanSubmit:function(){
        FCKeditorAPI.GetInstance('dc_txt').UpdateLinkedField();
        var url = "/Portals/Member/DataAjax.ashx?cmd=ZaTan&fmt=html";
        var gid = $e("Gid_Value").value;
        var title = $e("dc_name").value;
        var content = $e("dc_txt").value;
        if (title == "") {
            alert("请输入标题!");
        }
        else {
            if (content == "") {
                alert("请输入内容!");
            }
            else {
                var suc = function(h) {
                    if (h == "2") {
                        alert("提交失败!");
                    }
                    else if (h == "1") {
                        alert("提交成功!");
                        SxjAjax.Dialog.close();
                    }
                }
                $.ajax({ type: "POST", data: { aid: gid, title: title, content: content }, url: url, cache: false, dataType: "html", success: suc });
            }
        }
    }
}
SxjAjax.Search = {
    Submit: function() {
        var type = $e("classvalue").value;
        var txt = $e("Serch_Txt").value;
        if (type == "") {
            alert("请先选择类别!");
        }
        else {
            if (txt == "") {
                alert("请输入关键字!");
            }
            else {
                window.location.href = "/Search" + type + "-" + encodeURIComponent(txt) + "-" + "1.html";
            }
        }
    },
    Open_Div: function() {
        if (SxjAjax.Search.GetMd('hh').style.display == 'none') {
            SxjAjax.Search.GetMd('hh').style.display = '';
        }
        else {
            SxjAjax.Search.GetMd('hh').style.display = 'none';
        }
    },
    Select: function(str, value) {
        SxjAjax.Search.GetMd('class').value = value;
        SxjAjax.Search.GetMd('classvalue').value = str;
        SxjAjax.Search.GetMd('hh').style.display = 'none';
    },
    GetMd: function(objName) {
        if (document.getElementById) {
            return eval('document.getElementById("' + objName + '")');
        } else if (document.layers) {
            return eval("document.layers['" + objName + "']");
        } else {
            return eval('document.all.' + objName);
        }
    },
    StartClock: function() {
        var now = new Date();
        var hours = now.getHours();
        var minutes = now.getMinutes();
        var seconds = now.getSeconds();
        var vDay = parseInt(now.getDate());
        var arr = "日一二三四五六".split("");
        var vYear = parseInt(now.getYear());
        var vMonth = parseInt(now.getMonth() + 1);
        var timeValue = now.getYear() + "年" + (now.getMonth() + 1) + "月" + now.getDate() + "日" + " 星期" + arr[new Date(vYear, vMonth - 1, vDay).getDay()] + ((hours >= 12) ? " 下午 " : " 上午 ")
        $e("thetime").value = timeValue;
    }
}
SxjAjax.Dialog = {
    id: 'dialog',
    mask: 'mask_layout',
    dom: null,
    head: null,
    title: null,
    content: null,
    loading: null,
    init: function() {
        if (!this.dom) {
            insertHtml("beforeend", document.body,
             '<div class="layer_global" id="dialog" style="z-index:9000;display:none;position:absolute;">' +
                '<div class="layer_global_main" id="dialog_main">' +
                    '<div class="layer_global_title" id="dialog_head">' +
                        '<h3><img class="none" alt="icon" src="/eshop/in/img/b.gif" /><span id="dialog_title">title</span></h3>' +
                        '<button id="dialog_button" onclick="SxjAjax.Dialog.close();" title="close">╳</button></div>' +
                    '<div class="layer_global_cont" id="dialog_content" style="min-height:300px;"></div>' +
                '</div></div>' +
            '<div id="mask_layout" class="mask_layout" style="z-index: 5000; display:none;"></div>');
        }
        this.dom = $e(this.id);
        var m = $r(this.dom.childNodes[0]);
        this.head = $r(m.childNodes[0]);
        this.title = $r(this.head.childNodes[0]).lastChild;
        this.content = $r(this.head.nextSibling);
        if ($("#topzd").length > 0) {
            $e("topzd").style.right = ($(window).width() - 960) / 2-11;
        }
    },
    maskLayout: function(h) {
        var s = $('#' + this.mask);
        s.css('height', document.documentElement.offsetHeight);
        if (h && h != 'none') { s.css({ opacity: 0, display: 'block' }); s.animate({ opacity: 0.2 }, 'normal'); }
        else { s.animate({ opacity: 'hide' }, 'normal'); };
    },
    contentHTML: function(content, height, es, ec) {
        var h = '<div class="layer_global_cont mode_new_add" style="height:' + height + 'px">$1</div>';
        if (es || ec) {
            h += '<div class="global_tip_button"><div id="dialogloading" style="display:none;" class="replyloading"></div><button type=button onclick="$2" class="spr bt_tip" id="btn_pl_submit">确认</button>' +
            '<button type=button onclick="$3" class="spr bt_tip" id="btn_pl_back">取消</button></div>';
        }
        return h.format(content, es ? es : 'javascript:;', ec ? ec : 'SxjAjax.Dialog.close()');
    },
    show: function(title, content, option, submit) {
        this.dom.style.display = "block";
        for (var o in option) {
            this.dom.style[o] = parseInt(option[o]) + 'px';
        }
        var bw = document.documentElement.offsetWidth;
        var bh = document.documentElement.offsetHeight;
        var sw = document.documentElement.scrollLeft;
        var sh = document.documentElement.scrollTop;
        var dw = this.dom.offsetWidth;
        var dh = this.dom.offsetHeight;

        this.dom.style.left = ((bw - dw) / 2 + sw) + 'px';
        this.dom.style.top = ((bh - dh) / 2 + sh) + 'px';
        this.title.innerHTML = title;
        this.content.innerHTML = this.contentHTML(content, this.dom.offsetHeight - 64, submit);
        this.loading = $e('dialogloading');
        this.maskLayout(1);
    },
    close: function() {
        this.dom.style.display = 'none';
        this.title.innerHTML = "";
        this.content.innerHTML = "";
        this.maskLayout();
    }
}
SxjAjax.Collection = {
    h: function(o, l) {
        if (document.all) {
            window.external.addFavorite(o, l);
        }
        else if (window.sidebar) {
            window.sidebar.addPanel(o, l, "");
        }
    },
    s: function(o, l) {
        try {
            o.style.behavior = 'url(#default#homepage)';
            o.setHomePage(l);

        } catch (e) {
            if (window.netscape) {
                try {
                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                }
                catch (e) { }
                var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                prefs.setCharPref('browser.startup.homepage', l);
            }
        }
    }
}
