﻿/******************************************************************
 *                  IMRobots.SmsTong.Admin Global Utils          *
 *                                                                *
 * File Name: Global.js                                           *
 * Written by: yangc (sheepchang@163.com)                         *
 * Important: to use this script don't                            *
 * remove these comments                                          *
 * Version 1.0 (MSIE 6.0 above,Firefox2.0,Netscape.)              *
 * Created Date: 2008-03-30										  *
 ******************************************************************/

var IMRobots = new Object();
IMRobots.SmsTong = new Object();
IMRobots.SmsTong.Admin = new Object();

/* 公共函数 */
IMRobots.SmsTong.Admin.Common =
{
    Initialize: function() {
        var Loader = new IMRobots.SmsTong.Admin.Common.Loader();

        Loader.onsuccess = function() {

        }

        Loader.js("/Statics/JavaScripts/Prototype.js", true);
    },

    Loader: function() {
        /**
        * 按需加载JS文件
        * @param {url} 要加载的JS文件地址
        * @param {finish} 是否执行成功方法
        * @type Object
        */
        this.js = function(url, finish) {
            var ss = document.getElementsByTagName("SCRIPT");

            for (i = 0; i < ss.length; i++) {
                if (ss[i].src && ss[i].src.indexOf(url) != -1) {
                    if (finish) {
                        this.onsuccess();
                        return;
                    }
                    return;
                }
            }

            s = document.createElement("SCRIPT");
            s.type = "text/javascript";
            s.src = url + "?" + Math.random();
            var head = document.getElementsByTagName("HEAD")[0];
            head.appendChild(s);

            var self = this;
            s.onload = s.onreadystatechange = function() {
                if (this.readyState && this.readyState == "loading") {
                    return;
                }
                else {
                    if (finish) {
                        self.onsuccess();
                    }
                }
            }

            s.onerror = function() {
                head.removeChild(s);
                self.onfailure();
            }
        }

        /**
        * 按需加载CSS文件
        * @param {url} 要加载的CSS文件地址
        * @param {finish} 是否执行成功方法
        * @type Object
        */
        this.css = function(url, finish) {
            var ss = document.getElementsByTagName("LINK");

            for (i = 0; i < ss.length; i++) {
                if (ss[i].src && ss[i].src.indexOf(url) != -1) {
                    if (finish) {
                        this.onsuccess();
                        return;
                    }
                    return;
                }
            }

            s = document.createElement("LINK");
            s.type = "text/css";
            s.rel = "stylesheet";
            s.href = url + "?" + Math.random();
            var head = document.getElementsByTagName("HEAD")[0];
            head.appendChild(s);

            var self = this;
            s.onload = s.onreadystatechange = function() {
                if (this.readyState && this.readyState == "loading") {
                    return;
                }
                else {
                    if (finish) {
                        self.onsuccess();
                    }
                }
            }

            s.onerror = function() {
                head.removeChild(s);
                self.onfailure();
            }
        }

        this.onsuccess = function() { };

        this.onfailure = function() { };
    },

    /**
    * 正在加载
    * @param {domid} DOM ID
    * @param {msg} 提示消息
    * @type Object
    */
    Loading: function(domid, msg) {
        var Loader = new IMRobots.SmsTong.Admin.Common.Loader();

        Loader.onsuccess = function() {
            var o = $(domid);
            var loading = $("loading");
            if (loading == undefined) {
                var dw = o.offsetWidth ? o.offsetWidth : o.width;
                var dh = o.offsetHeight ? o.offsetHeight : o.height;
                var createloading = function() {
                    var loading = document.createElement("div");
                    loading.id = "loading";
                    loading.style.backgroundColor = "#ffffff";
                    loading.style.fontSize = "12px";
                    loading.style.position = "absolute";
                    loading.style.width = dw + "px";
                    loading.style.height = dh + "px";
                    loading.style.left = "0px";
                    loading.style.top = "0px";
                    loading.style.display = "none";
                    loading.style.overflow = "hidden";
                    loading.style.textAlign = "center";
                    loading.innerHTML = "<div style=\"position:absolute;left:" + (dw / 2 - 60) + "px;top:" + (dh / 2 - 40) + "px;\"><img src=\"/statics/images/loading.gif\" border=\"0\" />" + (msg == undefined ? "正在加载..." : msg) + "</div>";
                    o.style.position = "relative";
                    o.appendChild(loading);
                    return loading;
                };
                this.Loadings = createloading();
                this.Loadings.style.display = "block";
                new Effect.Opacity("loading", { from: 0.4, to: 0.4 });
                return this.Loadings;
            }
            else {
                o.removeChild(loading);
            }
        }

        Loader.js("/Statics/JavaScripts/Prototype.js", true);
    },

    /**
    * 获取页面查询参数
    * @param {name} 查询参数名
    * @type String
    */
    GetQueryString: function(name) {
        var result = "";
        var querystr = this.GetValue().split("&");
        for (var i = 0; i < querystr.length; i++) {
            var sb = querystr[i].split("=");
            if (sb[0].toLowerCase() == name.toLowerCase()) {
                result = sb[1];
                break;
            }
        }
        return result;
    },

    /**
    * 获取页面查询参数
    * @type String
    */
    GetValue: function() {
        var i = document.location.href.indexOf("?");
        if (i >= 0) {
            return document.location.href.substr(i + 1);
        }
        else {
            return "";
        }
    },

    /**
    * 设置Cookie
    * @param {name} Cookie名
    * @param {value} Cookie值
    * @param {option} Cookie选项
    */
    SetCookie: function(name, value, option) {
        var str = name + "=" + escape(value);
        if (option) {
            if (option.expireDays) {
                var date = new Date();
                var ms = option.expireDays * 24 * 3600 * 1000;
                date.setTime(date.getTime() + ms);
                str += "; expires=" + date.toGMTString();
            }
            if (option.path) str += "; path=" + option.path;
            if (option.domain) str += "; domain=" + option.domain;
            if (option.secure) str += "; true";
        }

        document.cookie = str;
    },

    /**
    * 获取Cookie
    * @param {name} Cookie名
    * @type String
    */
    GetCookie: function(name) {
        var cookieArray = document.cookie.split("; ");
        var cookie = new Object();
        for (var i = 0; i < cookieArray.length; i++) {
            var arr = cookieArray[i].split("=");
            if (arr[0] == name) {
                return unescape(arr[1]);
            }
        }
        return "";
    },

    /**
    * 获取Cookie
    * @param {name} Cookie名
    */
    DelCookie: function(name) {
        SetCookie(name, "", { expireDays: -1 });
    },

    /**
    * 列表页面跳转
    * @param {baseurl} 页面
    * @param {max} 最大页码
    */
    ChangePage: function(baseurl, max) {
        var Loader = new IMRobots.SmsTong.Admin.Common.Loader();

        Loader.onsuccess = function() {
            var cp = parseInt($("GotoPage").value);
            if (cp != NaN && cp <= max && cp > 0) {
                window.location.href = baseurl + '&page=' + cp;
            }
            else {
                alert("您输入的页码错误！");
                $("GotoPage").value = "";
                $("GotoPage").focus();
            }
        }

        Loader.js("/Statics/JavaScripts/Prototype.js", true);
    },

    /**
    * 列表页面跳转
    * @param {baseurl} 页面
    * @param {max} 最大页码
    */
    StaticChangePage: function(baseurl, max) {
        var Loader = new IMRobots.SmsTong.Admin.Common.Loader();

        Loader.onsuccess = function() {
            var cp = parseInt($("GotoPage").value);
            if (cp != NaN && cp <= max && cp > 0) {
                window.location.href = baseurl + cp;
            }
            else {
                alert("您输入的页码错误！");
                $("GotoPage").value = "";
                $("GotoPage").focus();
            }
        }

        Loader.js("/Statics/JavaScripts/Prototype.js", true);
    },

    /**
    * 提交Form表单
    * @param {formname} Form名
    * @param {posturl} Post地址
    */
    FormPost: function() {
        this.Post = function(formname, posturl) {
            var postform = $(formname);
            var self = this;
            new Ajax.Request(
                                 posturl == undefined ? postform.action : posturl,
                                 {
                                     asynchronous: true,
                                     evalScripts: true,
                                     parameters: Form.serialize(postform),
                                     onComplete: function(resp) {
                                         self.onComplete(resp.responseText);
                                     }
                                 }
                                );
        }

        this.onComplete = function(resp) { };
    },

    /**
    * 获取URL数据
    */
    RemoteData: function() {
        /**
        * GET获取URL数据
        * @param {url} 请求地址
        */
        this.Get = function(url) {
            var i = url.indexOf("?");
            if (i >= 0) {
                url = url + "&" + Math.random();
            }
            else {
                url = url + "?" + Math.random();
            }

            var self = this;
            new Ajax.Request(
                                 url,
                                 {
                                     method: "get",
                                     asynchronous: true,
                                     evalScripts: true,
                                     onComplete: function(resp) {
                                         self.onComplete(resp.responseText);
                                     }
                                 }
                                );
        };

        /**
        * POST获取URL数据
        * @param {url} 请求地址
        * @param {params} 请求参数
        */
        this.Post = function(url, params) {
            var i = url.indexOf("?");
            if (i >= 0) {
                url = url + "&" + Math.random();
            }
            else {
                url = url + "?" + Math.random();
            }

            var self = this;
            new Ajax.Request(
                                 url,
                                 {
                                     method: "post",
                                     asynchronous: true,
                                     evalScripts: true,
                                     parameters: params == undefined ? "" : params,
                                     onComplete: function(resp) {
                                         self.onComplete(resp.responseText);
                                     }
                                 }
                                );
        }

        this.onComplete = function(resp) { };
    },

    /**
    * 获取远程JSON数据
    * @param {divObj} 返回填充DIV容器
    */
    RemoteJsonObject: function(divObj, toObj, url) {
        this.divObj = divObj;
        this.toObj = toObj;
        this.url = url;
        this.LoadJsonData(this);
    },

    /**
    * 加载远程JSON数据
    * @param {RJO} RJO对象
    */
    LoadJsonData: function(RJO) {
        var ifr = document.createElement('iframe');
        ifr.id = "ifr_" + RJO.divObj.id;
        ifr.width = "0";
        ifr.height = "0";
        document.body.appendChild(ifr);
        ifr.src = RJO.divObj.href;
        if (window.addEventListener) {
            ifr.addEventListener('load', function() {
                var o, ifrs = document.getElementsByTagName("iframe");
                for (var i = 0; i < ifrs.length; i++) {
                    if (ifrs[i].id == 'ifr_' + RJO.divObj.id) {
                        o = frames[i].jsondata;
                    }
                }
                if (o) {
                    IMRobots.SmsTong.Admin.Common.FixData(RJO.divObj.id, RJO.toObj.id, o);
                    document.body.removeChild(ifr);
                }
                else {
                    alert("匹配失败！");
                }
            }, false);
        }
        else {
            ifr.attachEvent('onload', function() {
                var o = frames['ifr_' + RJO.divObj.id].jsondata;
                if (o) {
                    IMRobots.SmsTong.Admin.Common.FixData(RJO.divObj.id, RJO.toObj.id, o);
                    document.body.removeChild(ifr);
                }
                else {
                    alert("匹配错误！");
                }
            });
        }
    },

    /**
    * 获取模板
    * @param {tempId} 模版容器ID
    * @param {tempId} 填充DIV容器ID
    * @param {jDoc} JSON数据
    */
    FixData: function(tempId, divid, jDoc) {
        var temp = $(tempId);
        var div = $(divid);
        if (!temp) {
            alert("JSON模版" + tempId + "不存在"); return;
        }
        var templetHTML;
        templetHTML = $(tempId).value == undefined ? $(tempId).innerHTML : $(tempId).value;
        templetHTML = templetHTML.replace(/&lt;%/g, "<%").replace(/%&gt;/g, "%>").replace(/\[%/g, "<%").replace(/%\]/g, "%>").replace(/\{%/g, "<%").replace(/%\}/g, "%>").replace(/\<!--%/g, "<%").replace(/%-->/g, "%>");
        div.innerHTML = this.StartFix(templetHTML, jDoc, 0);
        div.style.display = "block";
    },

    /**
    * 填充数据
    * @param {templetHTML} 模板HTML
    * @param {jDoc} JSON数据
    * @param {jLevel} 模板jLevel
    * @param {childNode} 子节点
    */
    StartFix: function(templetHTML, jDoc, jLevel, childNode) {
        var stRegPrefix = "<%repeat_" + jLevel + "\\s*match=\"([^\"]+)\"[^%]*%>";
        var stRegContent = "<%repeat_" + jLevel + "[^>]*%>((.|\\n)+)<%_repeat_" + jLevel + "%>";
        var r_repeat_match = new RegExp(stRegPrefix);
        var r_repeat_match_global = new RegExp(stRegPrefix, "g");
        var r_repeat_content = new RegExp(stRegContent);
        var r_repeat_match_next_level = new RegExp("<%repeat_" + (jLevel + 1) + " match=\"([^\"]+)\"");
        if (templetHTML.match(r_repeat_match) == null) {
            alert("没有找到JSON节点<%repeat_" + (jLevel) + "%>");
            return;
        }
        var arPrefix = templetHTML.match(r_repeat_match_global);
        var startPosition = 0;
        for (var i = 0; i < arPrefix.length; i++) {
            var st = arPrefix[i];
            var nodePath = st.replace(/^.*match=\"|\".*$/g, "");
            startPosition = templetHTML.indexOf(st);
            var endPosition = templetHTML.indexOf("<%_repeat_" + jLevel + "%>", startPosition);
            var replaceContent = templetHTML.substring(startPosition, endPosition + 13);
            startPosition += st.length;
            var repeatContent = templetHTML.substring(startPosition, endPosition);
            if (nodePath.indexOf('.') != -1) {
                var arjnode = nodePath.split('.')
                var nodes = jDoc[arjnode[1]];
                if (arjnode.length > 2) {
                    nodes = childNode[arjnode[arjnode.length - 1]];
                }
            }
            else {
                var nodes = jDoc;
            }
            var arContent = [];
            if (!nodes) {
                alert("返回JSON数据子节点不存在")
            }
            else {
                if (typeof (nodes.length) == "undefined") {
                    var z = 2;
                }
                else {
                    var z = nodes.length;
                }
                for (var j = 0; j < z; j++) {
                    var node = typeof (nodes.length) == "undefined" ? nodes : nodes[j];
                    var content = repeatContent;
                    if (repeatContent.match(r_repeat_match_next_level) != null) {
                        content = startFix(repeatContent, node, jLevel + 1, node);
                    }
                    var s = content;
                    var l = content.match(/<%=[^%]+%>/g);
                    for (var k = 0; k < l.length; k++) {
                        if (l[k].indexOf('@fun=') > 0) {
                            var func = l[k].replace(/^.*@fun=\"|\".*$/g, "");
                            var t = l[k].replace(/^<%=|@.*%>$/g, "");
                            if (t.indexOf(',') > 0) {
                                var str1 = [];
                                var str2 = [];
                                var at = t.split(',');
                                for (var nI = 0; nI < at.length; nI++) {
                                    str1[nI] = "str" + nI;
                                    str2[nI] = node[at[nI]];
                                }
                                var prefix = new Function(str1, "return " + func + "");
                                s = s.replace(/<%=[^%]+%>/, prefix(str2));
                            }
                            else {
                                var prefix = new Function("str", "return " + func + "");
                                s = s.replace(/<%=[^%]+%>/, prefix(node[t]));
                            }
                        }
                        else {
                            var t = l[k].replace(/^<%=|%>$/g, "");
                            if (node[t] == undefined) node[t] = '';
                            s = s.replace(/<%=(\w+)%>/, node[t]);
                        }
                    }
                    arContent[j] = s;
                }
                templetHTML = templetHTML.replace(replaceContent, arContent.join(""));
            }
        }
        return templetHTML;
    },

    /**
    * Tab切换
    * @param {idx} Tab index
    * @param {count} Tab总数
    */
    TabClick: function(idx, count) {
        for (i_tr = 0; i_tr < count; i_tr++) {
            if (i_tr == idx) {
                var tabImgLeft = document.getElementById('tabImgLeft__' + idx);
                var tabImgRight = document.getElementById('tabImgRight__' + idx);
                var tabLabel = document.getElementById('tabLabel__' + idx);
                var tabContent = document.getElementById('tabContent__' + idx);

                tabImgLeft.src = '/statics/images/Menu/tab_active_left.gif';
                tabImgRight.src = '/statics/images/Menu/tab_active_right.gif';
                tabLabel.style.backgroundImage = "url(/statics/images/Menu/tab_active_bg.gif)";
                tabContent.style.visibility = 'visible';
                tabContent.style.display = 'block';
                continue;
            }
            var tabImgLeft = document.getElementById('tabImgLeft__' + i_tr);
            var tabImgRight = document.getElementById('tabImgRight__' + i_tr);
            var tabLabel = document.getElementById('tabLabel__' + i_tr);
            var tabContent = document.getElementById('tabContent__' + i_tr);

            tabImgLeft.src = '/statics/images/Menu/tab_unactive_left.gif';
            tabImgRight.src = '/statics/images/Menu/tab_unactive_right.gif';
            tabLabel.style.backgroundImage = "url(/statics/images/Menu/tab_unactive_bg.gif)";
            tabContent.style.visibility = 'hidden';
            tabContent.style.display = 'none';
        }

        //var Loader = new IMRobots.SmsTong.Admin.Common.Loader();

        //Loader.onsuccess = function() {
        //document.write("<script type=\"text/javascript\" src=\"http://js.doyoo.net/j.jsp?c=22165&f=42162\"></script>");
        //}

        //Loader.js("http://js.doyoo.net/j.jsp?c=22165&f=42162", true);
    },

    //展开收缩
    ShowNotice: function(id) {
        var o = $("content_" + id);
        if (o.style.display == "none") {
            new Effect.BlindDown(o);
        }
        else {
            new Effect.BlindUp(o);
        }
    },

    /**
    * 选择状态
    * @param {obj} 状态select对象
    */
    ChangeStatus: function(obj) {
        var index1 = window.location.href.indexOf("?status=");
        var index2 = window.location.href.indexOf("&status=");

        if (index1 > 0 || index2 > 0) {
            var exitstype = IMRobots.SmsTong.Admin.Common.GetQueryString("status");

            window.location.href = window.location.href.replace("status=" + exitstype + "", "status=" + obj.value);
        }
        else {
            if (window.location.href.indexOf("?") > 0) {
                window.location.href = window.location.href + "&status=" + obj.value;
            }
            else {
                window.location.href = window.location.href + "?status=" + obj.value;
            }
        }
    },

    /**
    * 选择类型
    * @param {obj} 状态select对象
    */
    ChangeTypes: function(obj) {
        var index1 = window.location.href.indexOf("?type=");
        var index2 = window.location.href.indexOf("&type=");

        if (index1 > 0 || index2 > 0) {
            var exitstype = IMRobots.SmsTong.Admin.Common.GetQueryString("type");

            window.location.href = window.location.href.replace("type=" + exitstype + "", "type=" + obj.value);
        }
        else {
            if (window.location.href.indexOf("?") > 0) {
                window.location.href = window.location.href + "&type=" + obj.value;
            }
            else {
                window.location.href = window.location.href + "?type=" + obj.value;
            }
        }
    },

    /**
    * 选择通道
    * @param {obj} 状态select对象
    */
    ChangeChannels: function(obj) {
        var index1 = window.location.href.indexOf("?channel=");
        var index2 = window.location.href.indexOf("&channel=");

        if (index1 > 0 || index2 > 0) {
            var exitstype = IMRobots.SmsTong.Admin.Common.GetQueryString("channel");

            window.location.href = window.location.href.replace("channel=" + exitstype + "", "channel=" + obj.value);
        }
        else {
            if (window.location.href.indexOf("?") > 0) {
                window.location.href = window.location.href + "&channel=" + obj.value;
            }
            else {
                window.location.href = window.location.href + "?channel=" + obj.value;
            }
        }
    },

    /**
    * 选择通道
    * @param {obj} 状态select对象
    */
    ChangeTime: function(obj) {
        var index1 = window.location.href.indexOf("?time=");
        var index2 = window.location.href.indexOf("&time=");

        if (index1 > 0 || index2 > 0) {
            var exitstype = IMRobots.SmsTong.Admin.Common.GetQueryString("time");

            window.location.href = window.location.href.replace("time=" + exitstype + "", "time=" + obj.value);
        }
        else {
            if (window.location.href.indexOf("?") > 0) {
                window.location.href = window.location.href + "&time=" + obj.value;
            }
            else {
                window.location.href = window.location.href + "?time=" + obj.value;
            }
        }
    },

    ChangeSelect: function(obj, key) {
        var index1 = window.location.href.indexOf("?" + key + "=");
        var index2 = window.location.href.indexOf("&" + key + "=");

        if (index1 > 0 || index2 > 0) {
            var exitstype = IMRobots.SmsTong.Admin.Common.GetQueryString(key);

            window.location.href = window.location.href.replace("" + key + "=" + exitstype + "", "" + key + "=" + obj.value);
        }
        else {
            if (window.location.href.indexOf("?") > 0) {
                window.location.href = window.location.href + "&" + key + "=" + obj.value;
            }
            else {
                window.location.href = window.location.href + "?" + key + "=" + obj.value;
            }
        }
    }
};

/*登录页面*/
IMRobots.SmsTong.Admin.Login =
{
	Initialize: function()
	{
		
	},
	
	/**
     * 更换验证码
     */
	ReloadCode: function()
	{
	    var Loader = new IMRobots.SmsTong.Admin.Common.Loader();
        
        Loader.onsuccess = function()
        {
            $("verifyimg").src = "/VerifyCode.gif?" + Math.random();
	    }
        
        Loader.js("/Statics/JavaScripts/Prototype.js", true);
	},
	
	/**
     * 用户登录
     */
	DoLogin: function()
	{
	    var Loader = new IMRobots.SmsTong.Admin.Common.Loader();
        
        Loader.onsuccess = function()
        {
            if ($F("UserName") == "")
            {
                $("UserName").focus();
                $("error1").innerHTML = "<font color=\"red\">请输入用户名！</font>";
            }
            else if ($F("UserPwd") == "")
            {
                $("UserPwd").focus();
                $("error1").innerHTML = "<font color=\"red\">请输入密  码！</font>";
            }
            else if ($F("VerifyCode") == "")
            {   
                $("VerifyCode").focus();
                $("error1").innerHTML = "<font color=\"red\">请输入验证码！</font>";
            }
            else
            {
                $("button").disabled = "disabled";
                
                var RemoteData = new IMRobots.SmsTong.Admin.Common.RemoteData()
                RemoteData.Post("/Login", "UserName=" + encodeURIComponent($F("UserName")) + "&UserPwd=" + encodeURIComponent($F("UserPwd")) + "&VerifyCode=" + $F("VerifyCode"));
                RemoteData.onComplete = function(resp)
                {
                    if (resp == "true")
                    {
                        var url = GetQueryString("url");
                        if  (url == "" || unescape(url) == "/")
                        {
                            window.location.href = "/default.aspx";
                        }
                        else
                        {
                            window.location.href = unescape(url);
                        }
                    }
                    else if (resp == 0)
                    {
                        $("UserName").focus();
                        $("error1").innerHTML = "<font color=\"red\">请输入用户名！</font>";
                    }
                    else if (resp == 1)
                    {
                        $("UserPwd").focus();
                        $("error1").innerHTML = "<font color=\"red\">请输入密  码！</font>";
                    }
                    else if (resp == 2)
                    {
                        $("VerifyCode").focus();
                        $("error1").innerHTML = "<font color=\"red\">请输入验证码！</font>";
                    }
                    else if (resp == 3)
                    {
                        $("error1").innerHTML = "<font color=\"red\">数据库操作失败！</font>";
                    }
                    else if (resp == 4)
                    {
                        $("UserName").focus();
                        $("UserName").value = "";
                        $("error1").innerHTML = "<font color=\"red\">系统维护中！</font>";
                    }
                    else if (resp == 5)
                    {
                        $("UserPwd").focus();
                        $("UserPwd").value = "";
                        $("error1").innerHTML = "<font color=\"red\">用户名不存在！</font>";
                    }
                    else if (resp == 6) {
                        $("UserName").focus();
                        $("UserName").value = "";
                        $("error1").innerHTML = "<font color=\"red\">帐号被冻结！</font>";
                    }
                    else if (resp == 7) {
                        $("UserPwd").focus();
                        $("UserPwd").value = "";
                        $("error1").innerHTML = "<font color=\"red\">帐号密码错误！</font>";
                    }
                    else if (resp == 8)
                    {
                        $("VerifyCode").focus();
                        $("VerifyCode").value = "";
                        $("error1").innerHTML = "<font color=\"red\">用户名不存在！</font>";
                    }
                    else if (resp == 9)
                    {
                        $("VerifyCode").focus();
                        $("VerifyCode").value = "";
                        $("error1").innerHTML = "<font color=\"red\">插入日志记录失败！</font>";
                    }
                    else if (resp == 10)
                    {
                        $("VerifyCode").focus();
                        $("VerifyCode").value = "";
                        $("error1").innerHTML = "<font color=\"red\">登陆系统失败！</font>";
                    }
                    else if (resp == 11)
                    {
                        $("VerifyCode").focus();
                        $("VerifyCode").value = "";
                        $("error1").innerHTML = "<font color=\"red\">验证码错误！</font>";
                    }
                    else
                    {
                        $("error1").innerHTML = "<font color=\"red\">" + resp + "</font>";
                    }
                    
                    $("button").disabled = "";
                }
            }
	    }
        
        Loader.js("/Statics/JavaScripts/Common.js", false);
        Loader.js("/Statics/JavaScripts/Prototype.js", true);
	}
};

IMRobots.SmsTong.Admin.ChinaBank =
{
    Initialize: function() {

    },

    Pay: function() {
        if (!isNaN($F("price")) && ($F("price") * 1 >= 10.00)) {
            $("button").disabled = "disabled";
            var RemoteData = new IMRobots.SmsTong.Admin.Common.RemoteData();
            RemoteData.Post("/GateWay/OnlinePay/ChinaBank", "order_id=" + $("v_oid").value + "&pay_amount=" + $("price").value + "&v_amount=" + $("price").value + "&v_moneytype=" + $("v_moneytype").value + "&v_oid=" + $("v_oid").value + "&v_mid=" + $("v_mid").value + "&v_url=" + $("v_url").value);
            RemoteData.onComplete = function(resp) {
                if (resp == "1103754-101") {
                    alert("您没有操作权限！")
                }
                else if (resp == "1103754-102") {
                    alert("用户不存在！")
                }
                else if (resp == "1103754-103") {
                    alert("模块不存在！")
                }
                else if (resp == "1103754-104") {
                    alert("权限不存在！")
                }
                else if (resp != "error") {
                    //alert("提交订单成功！");
                    $("v_amount").value = $F("price");

                    //alert(resp);
                    $("v_md5info").value = resp;
                    $("form").submit();

                    window.top.showPopWin('在线充值', '/UserMgr/Pay/Info.aspx', 510, 170, null); new Draggable('ext-comp-1001');
                }
                else {
                    alert("提交订单失败！");
                }
            }
        }
        else {
            alert("请输入正确的金额，必须大于等于10.00元！");
        }
    }
};

IMRobots.SmsTong.Admin.CNCard =
{
    Initialize: function() {

    },

    Pay: function() {
        if (!isNaN($F("price")) && ($F("price") * 1 >= 10.00)) {
            $("button").disabled = "disabled";
            var RemoteData = new IMRobots.SmsTong.Admin.Common.RemoteData();
            RemoteData.Post("/GateWay/OnlinePay/CNCard", "order_id=" + $("c_order").value + "&pay_amount=" + $("price").value + "&c_mid=" + $("c_mid").value + "&c_order=" + $("c_order").value + "&c_orderamount=" + $("price").value + "&c_ymd=" + $("c_ymd").value + "&c_moneytype=" + $("c_moneytype").value + "&c_retflag=" + $("c_retflag").value + "&c_returl=" + $("c_returl").value + "&c_paygate=" + $("c_paygate").value + "&c_memo1=" + $("c_memo1").value + "&c_memo2=" + $("c_memo2").value + "&notifytype=" + $("notifytype").value + "&c_language=" + $("c_language").value);
            RemoteData.onComplete = function(resp) {
                if (resp == "1103754-101") {
                    alert("您没有操作权限！")
                }
                else if (resp == "1103754-102") {
                    alert("用户不存在！")
                }
                else if (resp == "1103754-103") {
                    alert("模块不存在！")
                }
                else if (resp == "1103754-104") {
                    alert("权限不存在！")
                }
                else if (resp != "error") {
                    //alert("提交订单成功！");
                    $("c_orderamount").value = $F("price");

                    //alert(resp);
                    $("c_signstr").value = resp;

                    $("form").submit();

                    window.top.showPopWin('在线充值', '/UserMgr/Pay/Info.aspx', 510, 170, null); new Draggable('ext-comp-1001');
                }
                else {
                    alert("提交订单失败！");
                }
            }
        }
        else
        {
            alert("请输入正确的金额，必须大于等于10.00元！");
        }
    }
};

IMRobots.SmsTong.Admin.AliPay =
{
    Initialize: function() {

    },

    Pay: function() {
        if (!isNaN($F("aliprice")) && ($F("aliprice") * 1 >= 10.00)) {
            $("button").disabled = "disabled";
            var RemoteData = new IMRobots.SmsTong.Admin.Common.RemoteData();
            RemoteData.Post("/GateWay/OnlinePay/AliPay", "order_id=" + $("out_trade_no").value + "&pay_amount=" + $("aliprice").value + "&service=" + $("service").value + "&partner=" + $("partner").value + "&sign_type=" + $("sign_type").value + "&out_trade_no=" + $("out_trade_no").value + "&subject=" + $("subject").value + "&body=" + $("body").value + "&total_fee=" + $("aliprice").value + "&show_url=" + $("show_url").value + "&seller_email=" + $("seller_email").value + "&return_url=" + $("return_url").value + "&notify_url=" + $("notify_url").value + "&payment_type=" + $("payment_type").value);
            RemoteData.onComplete = function(resp) {
                if (resp == "1103754-101") {
                    alert("您没有操作权限！")
                }
                else if (resp == "1103754-102") {
                    alert("用户不存在！")
                }
                else if (resp == "1103754-103") {
                    alert("模块不存在！")
                }
                else if (resp == "1103754-104") {
                    alert("权限不存在！")
                }
                else if (resp != "error") {
                    //alert("提交订单成功！");
                    $("total_fee").value = $("aliprice").value;
                    
                    //alert(resp);
                    $("sign").value = resp;
                    $("form").submit();

                    window.top.showPopWin('在线充值', '/UserMgr/Pay/Info.aspx', 510, 170, null); new Draggable('ext-comp-1001');
                }
                else {
                    alert("提交订单失败！");
                }
            }
        }
        else {
            alert("请输入正确的金额，必须大于等于10.00元！");
        }
    }
};

IMRobots.SmsTong.Admin.TenPay =
{
    Initialize: function() {

    },

    Pay: function() {
        if (!isNaN($F("tenprice")) && ($F("tenprice") * 1 >= 10.00)) {
            $("button").disabled = "disabled";
            var RemoteData = new IMRobots.SmsTong.Admin.Common.RemoteData();
            RemoteData.Post("/GateWay/OnlinePay/TenPay", "spbill_create_ip=" + $("spbill_create_ip").value + "&date=" + $("date").value + "&cs=" + $("cs").value + "&transaction_id=" + $("transaction_id").value + "&bargainor_id=" + $("bargainor_id").value + "&total_fee=" + Number($("tenprice").value) * 100 + "&desc=" + $("desc").value + "&fee_type=" + $("fee_type").value + "&return_url=" + $("return_url").value + "&attach=" + $("attach").value + "&bank_type=" + $("bank_type").value + "&sign=" + $("sign").value + "&cmdno=" + $("cmdno").value + "&sp_billno=" + $("sp_billno").value);
            RemoteData.onComplete = function(resp) {
                if (resp == "1103754-101") {
                    alert("您没有操作权限！")
                }
                else if (resp == "1103754-102") {
                    alert("用户不存在！")
                }
                else if (resp == "1103754-103") {
                    alert("模块不存在！")
                }
                else if (resp == "1103754-104") {
                    alert("权限不存在！")
                }
                else if (resp != "error") {
                    //alert("提交订单成功！");
                    $("total_fee").value = Number($("tenprice").value) * 100;

                    //alert(resp);
                    $("sign").value = resp;
                    $("form").submit();

                    window.top.showPopWin('在线充值', '/UserMgr/Pay/Info.aspx', 510, 170, null); new Draggable('ext-comp-1001');
                }
                else {
                    alert("提交订单失败！");
                }
            }
        }
        else {
            alert("请输入正确的金额，必须大于等于10.00元！");
        }
    }
};

IMRobots.SmsTong.Admin.Buy_Service =
{
    Initialize: function() {

    },

    SubmitForm: function() {
        var text = "";
        if ($F("username") == "") {
            $("username").focus();
            alert("请输入要充值的用户名！");
            return false;
        }
        else if ($("radio_1").checked == true) {
            text = $("lbl_1").innerHTML;
        }
        else if ($("radio_2").checked == true) {
            text = $("lbl_2").innerHTML;
        }
        else if ($("radio_3").checked == true) {
            text = $("lbl_3").innerHTML;
        }
        else if ($("radio_4").checked == true) {
            text = $("lbl_4").innerHTML;
        }
        else if ($("radio_5").checked == true) {
            text = $("lbl_5").innerHTML;
        }
        else if ($("radio_6").checked == true) {
            text = $("lbl_6").innerHTML;
        }
        else if ($("radio_7").checked == true) {
            text = $("lbl_7").innerHTML;
        }
        else if ($("radio_8").checked == true) {
            text = $("lbl_8").innerHTML;
        }
        else if ($("radio_9").checked == true) {
            text = $("lbl_9").innerHTML;
        }
        else if ($("radio_10").checked == true) {
            text = $("lbl_10").innerHTML;
        }
        else {
            alert("请选择一个需要购买的服务项目！");
            return false;
        }

        var cf = confirm("确认要购买服务：" + text + "？资费直接从您余额中扣除，请谨慎操作！");

        if (cf) {
            return true;
        }
        else {
            return false;
        }
    }
};

IMRobots.SmsTong.Admin.Send_Sms =
{
    Initialize: function() {
        var obj = document.getElementById('datepicker');

        if (obj)
            obj.innerHTML = "<input name=\"send_timer\" readonly=\"readonly\" type=\"text\" id=\"send_timer\" class=\"text_input\" size=\"50\" maxlength=\"30\" title=\"请输入定时间发送时间，为空立即发送!\" onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});\" />";
    }
};

IMRobots.SmsTong.Admin.UserUpdate =
{
    Initialize: function(user_date) {
        var obj = document.getElementById('datepicker');

        if (obj)
            obj.innerHTML = "<input name=\"user_date\" readonly=\"readonly\" type=\"text\" id=\"user_date\" class=\"text_input\" maxlength=\"30\" title=\"请输入过期日期!\" value='" + user_date + "' onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});\" />";
    }
};

IMRobots.SmsTong.Admin.Add_MobileNO =
{
    Initialize: function() {
        var obj = document.getElementById('datepicker');

        if (obj)
            obj.innerHTML = "<input name=\"birthday\" type=\"text\" id=\"birthday\" class=\"text_input\" maxlength=\"10\" title=\"请输入生日!\" readonly=\"readonly\" onfocus=\"WdatePicker();\" />";
    }
};

IMRobots.SmsTong.Admin.Modify_MobileNO =
{
    Initialize: function(birthday) {
        var obj = document.getElementById('datepicker');

        if (obj)
            obj.innerHTML = "<input name=\"birthday\" type=\"text\" id=\"birthday\" class=\"text_input\" maxlength=\"10\" title=\"请输入生日!\" readonly=\"readonly\"  value='" + birthday + "' onfocus=\"WdatePicker();\" />";
    }
};

IMRobots.SmsTong.Admin.MobileNO_List =
{
    Initialize: function() {

    },

    ChangeGroup: function(select) {
        var Loader = new IMRobots.SmsTong.Admin.Common.Loader();

        Loader.onsuccess = function() {
            var index1 = window.location.href.indexOf("?group=");
            var index2 = window.location.href.indexOf("&group=");

            if (index1 > 0 || index2 > 0) {
                var exitsgroup = IMRobots.SmsTong.Admin.Common.GetQueryString("group");

                window.location.href = window.location.href.replace("group=" + exitsgroup + "", "group=" + select.value);
            }
            else {
                if (window.location.href.indexOf("?") > 0) {
                    window.location.href = window.location.href + "&group=" + select.value;
                }
                else {
                    window.location.href = window.location.href + "?group=" + select.value;
                }
            }
        }

        Loader.js("/Statics/JavaScripts/Prototype.js", true);
    },

    SendChangeGroup: function(select) {
        window.location.href = "/SmsMgr/Send_Sms.aspx?group=" + select.value;
    },

    SendMMSChangeGroup: function(select) {
        window.location.href = "/MMSMgr/Send_MMS.aspx?group=" + select.value;
    },
    
    SelectAll: function() {
        var Loader = new IMRobots.SmsTong.Admin.Common.Loader();
        Loader.onsuccess = function() {
            if ($("chk_all").checked == true) {
                var chks = document.getElementsByName("checkbox");
                for (var i = 0; i < chks.length; i++) {
                    if (!chks[i].checked && (chks[i].disabled == "")) {
                        chks[i].checked = true;
                        IMRobots.SmsTong.Admin.MobileNO_List.AddRemoveValues(chks[i]);
                    }
                }

                if ($("chk_all").checked) $("chk_all").checked = "checked";
            }
            else {
                IMRobots.SmsTong.Admin.MobileNO_List.ClareAll();
                if ($("chk_all").checked) $("chk_all").checked = "";
            }
        }

        Loader.js("/Statics/JavaScripts/Prototype.js", true);
    },
    
    AddRemoveValues: function(oChk) {
        var Loader = new IMRobots.SmsTong.Admin.Common.Loader();

        Loader.onsuccess = function() {
            if (oChk.checked) {
                $('HdnId').value += "," + oChk.value;
                $('HdnValue').value += "," + $("mobile_" + oChk.value).innerHTML;
            }
            else {
                $('HdnId').value = $F('HdnId').replace("," + oChk.value, "");
                $('HdnValue').value = $F('HdnValue').replace("," + $("mobile_" + oChk.value).innerHTML, "");
            }
        }

        Loader.js("/Statics/JavaScripts/Prototype.js", true);
    },
    
    ClareAll: function() {
        var Loader = new IMRobots.SmsTong.Admin.Common.Loader();

        Loader.onsuccess = function() {
            var chks = document.getElementsByName("checkbox");
            for (var i = 0; i < chks.length; i++) {
                chks[i].checked = false;
            }
            $('HdnId').value = "";
            if ($('HdnValue')) $('HdnValue').value = "";
        }

        Loader.js("/Statics/JavaScripts/Prototype.js", true);
    },

    DeleteMobile: function() {
        var cf = confirm("确认要删除选择的吗？");

        if (cf) {
            var Loader = new IMRobots.SmsTong.Admin.Common.Loader();

            Loader.onsuccess = function() {
                $("action").value = "delete";
                $("form").submit();
            }

            Loader.js("/Statics/JavaScripts/Prototype.js", true);
        }
    },

    SendSms: function() {
        var cf = confirm("确认要给选择的号码发送短信？");

        if (cf) {
            var Loader = new IMRobots.SmsTong.Admin.Common.Loader();

            Loader.onsuccess = function() {
                $("action").value = "sendsms";
                $("form").submit();
            }

            Loader.js("/Statics/JavaScripts/Prototype.js", true);
        }
    },

    SetGroup: function(obj) {
        var Loader = new IMRobots.SmsTong.Admin.Common.Loader();

        Loader.onsuccess = function() {
            if ($F("HdnId") != "" && obj.options[obj.selectedIndex].value != 0) {
                var cf = confirm("确认要把选择的号码移动到分组〖" + obj.options[obj.selectedIndex].text + "〗？");
                if (cf) {
                    $("action").value = "setgroup";
                    $("form").submit();
                }
            }
            else {
                window.location.href = "/NumberMgr/MobileNO_List.aspx?group=" + obj.options[obj.selectedIndex].value;
            }
        }

        Loader.js("/Statics/JavaScripts/Prototype.js", true);
    }
};


IMRobots.SmsTong.Admin.Bind_MobileNO =
{
    Initialize: function() {

    },

    SetGroup: function(obj) {
        var Loader = new IMRobots.SmsTong.Admin.Common.Loader();

        Loader.onsuccess = function() {
            if ($F("HdnId") != "" && obj.options[obj.selectedIndex].value != 0) {
                var cf = confirm("确认要把选择的号码移动到分组〖" + obj.options[obj.selectedIndex].text + "〗？");
                if (cf) {
                    $("action").value = "setgroup";
                    $("form").submit();
                }
            }
            else {
                obj.selectedIndex = 0;
                alert("请选择要添加到分组的号码！");
            }
        }

        Loader.js("/Statics/JavaScripts/Prototype.js", true);
    }
};

IMRobots.SmsTong.Admin.UserMgr =
{
    Initialize: function() {

    },

    ChackSubmit: function() {
            if ($F("username") == "") {
                $("username").focus();
                alert("请输入要充值的用户名！");
                return false;
            }
            else if ($F("cardnum") == "") {
                $("cardnum").focus();
                alert("请输入充值卡号！");
                return false;
            }
            else if ($F("password") == "") {
                $("password").focus();
                alert("请输入充值密码！");
                return false;
            }

            var cf = confirm("确认给用户" + $F("username") + "充值？");

            if (cf)
                return true;
            else
                return false;
    }
};

IMRobots.SmsTong.Admin.Invoice_App =
{
    Initialize: function() {

    },

    ChackSubmit: function() {


        if ($F("company") == "") {
            $("company").focus();
            alert("请输入发票抬头！");
            return false;
        }
        else if ($F("taxation_no") == "") {
            $("taxation_no").focus();
            alert("请输入税务登记号！");
            return false;
        }
        else if ($F("amount") == "") {
            $("amount").focus();
            alert("请输入发票金额！");
            return false;
        }
        else if ($F("amount") == "") {
            $("amount").focus();
            alert("请输入发票金额！");
            return false;
        }
        else if (isNaN($F("amount")) || ($F("amount") * 1 < 1000.00)) {
            $("amount").focus();
            alert("发票金额必须大于等于1000元！");
            return false;
        }
        else if (($F("amount") * 1 % 100) != 0) {
            $("amount").focus();
            alert("发票金额必须是100元的整数倍！");
            return false;
        }
        else if ($F("amount") * 1 > $("invoice").innerHTML * 1) {
            $("amount").focus();
            alert("发票金额不能大于可开发票金额" + $("invoice").innerHTML + "元！");
            return false;
        }
        else if ($F("amount") * 0.08 > $F("balance") * 1) {
            $("amount").focus();
            alert("账户余额" + $F("balance") + "元不足以支付发票金额" + $F("amount") + "元%8的税点金额" + $F("amount") * 0.06 + "元，请充值" + $F("amount") * 0.08 + "元！");
            return false;
        }
        else if ($F("person") == "") {
            $("person").focus();
            alert("请输入联系人！");
            return false;
        }
        else if ($F("phone") == "") {
            $("phone").focus();
            alert("请输入联系电话！");
            return false;
        }
        else if ($F("zip") == "") {
            $("zip").focus();
            alert("请输入邮政编码！");
            return false;
        }
        else if ($F("address") == "") {
            $("address").focus();
            alert("请输入联系地址！");
            return false;
        }

        var cf = confirm("确认要申请发票，金额" + $F("amount") + "元，需要扣除账户余额" + $F("amount") * 1 * 0.08 + "元？");

        if (cf)
            return true;
        else
            return false;
    },

    ConfirmInvoice: function(id) {
        var cf = confirm("确认要查收发票？");

        if (cf) {
            var RemoteData = new IMRobots.SmsTong.Admin.Common.RemoteData();
            RemoteData.Post("/GateWay/Invoice/Confirm", "id=" + id);
            RemoteData.onComplete = function(resp) {
                if (resp == "1103754-101") {
                    alert("您没有操作权限！")
                }
                else if (resp == "1103754-102") {
                    alert("用户不存在！")
                }
                else if (resp == "1103754-103") {
                    alert("模块不存在！")
                }
                else if (resp == "1103754-104") {
                    alert("权限不存在！")
                }
                else if (resp == "-101") {
                    alert("用户不存在！")
                }
                else if (resp == "-102") {
                    alert("发票不存在！")
                }
                else if (resp == "-103") {
                    alert("发票状态不正确！")
                }
                else if (resp == "-104") {
                    alert("确认查收发票失败！")
                }
                else if (resp == "0") {
                    alert("确认查收发票成功！");
                    window.location.href = "/UserMgr/Invoice_App.aspx";
                }
                else {
                    alert("确认查收发票失败！");
                }
            }
        }
    }
};

IMRobots.SmsTong.Admin.Invoice_Mgr =
{
    Initialize: function() {

    },

    ChackSubmit: function() {


        if ($F("username") == "") {
            $("username").focus();
            alert("请输入用户名称！");
            return false;
        }
        else if ($F("company") == "") {
            $("company").focus();
            alert("请输入发票抬头！");
            return false;
        }
        else if ($F("taxation_no") == "") {
            $("taxation_no").focus();
            alert("请输入税务登记号！");
            return false;
        }
        else if ($F("amount") == "") {
            $("amount").focus();
            alert("请输入发票金额！");
            return false;
        }
        else if ($F("amount") == "") {
            $("amount").focus();
            alert("请输入发票金额！");
            return false;
        }
        else if ($F("person") == "") {
            $("person").focus();
            alert("请输入联系人！");
            return false;
        }
        else if ($F("phone") == "") {
            $("phone").focus();
            alert("请输入联系电话！");
            return false;
        }
        else if ($F("zip") == "") {
            $("zip").focus();
            alert("请输入邮政编码！");
            return false;
        }
        else if ($F("address") == "") {
            $("address").focus();
            alert("请输入联系地址！");
            return false;
        }

        var cf = confirm("确认要申请发票，金额" + $F("amount") + "元？");

        if (cf)
            return true;
        else
            return false;
    }
};

//<%=JsForController %>

function gotobuy(username) {
	var count = parseInt(document.getElementById('count').value);
	if (count !=NaN && count <= 10000000 && count > 0)
	{
		document.getElementById('form').action = 'http://payment.chanyoo.cn/pay.aspx?username='+username+'&count=' + document.getElementById('count').value;
		alert("请点击确定到新打开的页面窗口中完成在线支付操作！");
		return true;
	}
	else
	{
		alert("您输入的数量错误，购买的数量必须大于0小于100000000!");
		document.getElementById('count').value = '';
		document.getElementById('count').focus();
		return false;
	}
}

function KillErrors()
{
return true;
}
window.onerror = KillErrors;
