﻿var switchcode = function(obj) {
    var d = new Date();
    d = d.getMilliseconds();
    obj.src = "/code.aspx?id=" + d.toString();
};
var changecode = function(obj) {
    var d = new Date();
    d = d.getMilliseconds();
    $("#bcode").show();
    document.getElementById("bcode").src = "/billcode.aspx?id=" + d.toString();
};

$().ready(function() {
    if ($(".topmenu").length) {
        $("li", $(".topmenu")).each(function(index, li) {
            $(li).mouseover(function() {
                if (!li.className.endWiths("c")) {
                    li.className = li.className + "b";
                }
            }).mouseout(function() {
                li.className = li.className.replace("b", "");
            });
        });
    }
    if ($(".son_topmenuli1").length) {
        $("li", $(".son_topmenuli1").parent()).each(function(index, li) {
            $(li).mouseover(function() {
                if (!li.className.endWiths("c")) {
                    li.className = li.className + "b";
                }
            }).mouseout(function() {
                li.className = li.className.replace("b", "");
            });
        });
    }
});
var addBookmark = function(url, title) {
    if (window.sidebar) {
        window.sidebar.addPanel(title, url, "");
    } else if (document.all) {
        var external = window.external;
        external.AddFavorite(url, title);
    } else if (window.opera && window.print) {
        return true;
    }
};
var setHome = function(obj, vrl) {
    try {
        obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(vrl);
    }
    catch (e) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', vrl);
        }
    }
};
String.prototype.startWiths = function(s) {
    return (this.substr(0, s.length) == s);
};
String.prototype.endWiths = function(s) {
    return (this.substr(this.length - s.length) == s);
};
String.prototype.trim = function() {
    return (this || "").replace(/^\s+|\s+$/g, "");
};

var obj2str = function obj2str(o) {
    var r = [];
    if (typeof o == "string") return "\"" + o.replace(/([\'\"\\])/g, "\\$1").replace(/(\n)/g, "\\n").replace(/(\r)/g, "\\r").replace(/(\t)/g, "\\t") + "\"";
    if (typeof o == "object") {
        if (!o.sort) {
            for (var i in o) {
                r.push("\"" + i + "\":" + obj2str(o[i]));
            }
            if (!!document.all && !/^\n?function\s*toString\(\)\s*\{\n?\s*\[native code\]\n?\s*\}\n?\s*$/.test(o.toString)) {
                r.push("toString:" + o.toString.toString());
            }
            r = "{" + r.join() + "}"
        } else {
            for (var i = 0; i < o.length; i++)
                r.push(obj2str(o[i]))
            r = "[" + r.join() + "]"
        }
        return r;
    }
    return o.toString();
};
var dataV = {
    Email: function(str) {
        //邮箱正则
        return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(str);
    },
    UserName: function(str) {
        return /^[\w_]{4,30}$/.test(str); //用户名
    },
    Length: function(str, min, max) {
        //验证长度
        if (str.length > max || str.length < min)
            return false;
        else
            return true;
    },
    UserPwd: function(str) {
        return /^[\w_]{6,16}$/.test(str);
    },
    UserTrueName: function(str) {
        return /^[\u4E00-\u9FAFA-Za-z]+$/.test(str); //检测真实姓名
    },
    Integer: function(str) {
        return /^[-\+]?\d+$/.test(str); //单精度数
    },
    Double: function(str) {
        return /^[-\+]?\d+(\.\d+)?$/.test(str); //双精度数
    },
    QQ: function(str) {
        return /^[1-9]\d{4,11}$/.test(str); //验证QQ
    },
    Phone: function(str) {
        //验证电话
        return true;
    },
    English: function(str) {
        return /^[A-Za-z]+$/.test(str);
    },
    Chinese: function(str) {
        return /^[\u0391-\uFFE5]+$/.test(str); //验证中文
    },
    //验证Url连接
    Url: function(str) {
        return /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/.test(str);
    },
    //检测时间,粗略的检测了下年月日
    DateStr: function(str) {
        return /^((\d{4})|(\d{2}))[\-\.\/](\d{1,2})[\-\.\/](\d{1,2})/.test(str);
    }
};

