﻿function rootURL()
{
    var root = window.location.pathname;
    root = root.replace(/[^\/]+$/g, '');
    root = root.replace(/\/admin\/$/g, '/');
    return (root);
}
function locationURL(url)
{
    return (rootURL() + url);
}


/*添加扩展*/
$.cookies = (function()
{
    var constructor = function(){};
    constructor.prototype.get = function(name)
    {
        var reg = new RegExp('(^|;)\\s*' + escape(name) + '\\s*\=(.+?)(;|$)');
        
        var r = document.cookie.match(reg);
        if(r)
        {
            return unescape(r[2]);
        }
        else
        {
            return null;
        }
    };
    constructor.prototype.set = function(name, value, options)
    {
        options = options || {};
        var arr = new Array();
        
        var expires = new Date();
        expires.setTime(expires.getTime() + 60000 * (options.minutes == null ? 525960 : options.minutes));
        
        arr.push(escape(name) + '=' + escape(value));
        arr.push('expires=' + expires.toGMTString());
        arr.push('path=' + (options.path == null ? '/' : options.path));
        
        document.cookie = arr.join(';');
    };
    constructor.prototype.del = function(name, path)
    {
        return this.set(name, '', {minutes: 0, path: path});
    };
    
    return new constructor();
})();


//WEB前端
$.extend(
{
    link: function(href)
    {
        if(href.search(/^\*/) >= 0)
        {
            var querys = $.extend($.querys(), $.unparam(href.replace(/^\*/, '')));
            href = $.param(querys);
            href = window.location.pathname + (href.length > 0 ? '?' + href : '');
        }
        
        if(href.search(/[^\w]lang\=\w+/) >= 0)
        {
            href = href.replace(/([^\w]lang\=)\w+/, '$1' + $.lang());
        }
        else
        {
            href = href + (href.search(/\?/) > -1 ? '&' : '?') + 'lang=' + $.lang();
        }
        
        window.location.href = href;
    },
    querys: function()
    {
        return $.unparam(window.location.search.replace(/^\?/g, ''));
    },
    refresh: function()
    {
        window.location.reload();
    },
    lang: function()
    {
        return $('body').attr('lang').match(/^[a-z]+/i);
    },
    langText: function(s)
    {
        var val = $.langs()[$.lang()];
        var arr = s.split('$');
        val = arr.length > val ? val : 0;
        return arr[val];
    },
    langs: function()
    {
        return {en: 0, zh: 1};
    },
    setHomePage: function()
    {
        var body = $('body').get(0);
        body.style.behavior = 'url(#default#homepage)';
        body.setHomePage(window.location.href.replace(/[^\/]*?$/, ''));
    },
    addFavorite: function()
    {
        window.external.addFavorite(window.location.href, window.document.title);
    }
});



//数据重组
$.extend(
{
    unparam: function(value)
    {
        var r = {};
        var ss = value.split('&');
        for(var i = 0; i < ss.length; i++)
        {
            if(ss[i].search(/(^\w+)\=(.*)/) >= 0)
            {
                var mtch = ss[i].match(/(^\w+)\=(.*)/);
                r[mtch[1]] = mtch[2];
            }
        }
        return r;
    },
	loadScript: function(url, callback)
	{
	    var key = '$loadScript';
	    if(!$(document.body).data(key))
	    {
	        $(document.body).data(key, {})
	    }
	    
	    var data = $(document.body).data(key);
	    
	    if(data[url] === undefined)
	    {
	        data[url] = new Array();
	        data[url].push(callback);
	        
	        return jQuery.get(url, null, function()
	        {
                $.each(data[url], function(index, value)
                {
                    value();
                });
                data[url] = true;
	        }, 'script');
	        
	        return false;
	    }
	    else if(data[url] === true)
	    {
	        callback();
	        return false;
	    }
	    else
	    {
	        data[url].push(callback);
	        return false;
	    }
	},
    dialog: function(options, t)
    {
       var defaults = {
            width: 600,
            skin: 'default',
            lock: true,
            fixed: true,
            title: '',
            border: false,
            window: 'top',
            noFn: null,
            yesFn: null,
            yesText: null,
            noText: null,
            actionEvent: 'click'
        };
        options = $.extend(defaults, options);
        
        var scriptURL = locationURL('libs/artDialog/artDialog.js');
        $.loadScript(scriptURL, function()
        {
            if(t)
            {
                t.bind(options.actionEvent, function()
                {
                    if(options.iframe)
                    {
                        art.dialog.open(options.iframe, options);
                    }
                    else
                    {
                        art.dialog(options);
                    }
                });
            }
            else
            {
                if(options.iframe)
                {
                    art.dialog.open(options.iframe, options);
                }
                else
                {
                    art.dialog(options);
                }
            }

        });
    }
});


//私有函数
$.extend(
{
    _newID: function()
    {
        return Math.random().toString().replace(/^0\./, 'r');
    }
});



$.extend(
{
    setStyle: function(url)
    {
        var has = true;
        $('link[rel=stylesheet]').each(function()
        {
            if($(this).attr('href') == url)
            {
                has = false;
            }
        });
        
        if(has)
        {
            if($.browser.msie)
            {
                document.createStyleSheet(url);
            }
            else
            {
                $('head').append($('<link type="text/css" rel="stylesheet" />').attr('href', url));
            }
        }
    },
    flashObject: function(src, width, height, flashvars)
    {
        return $('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,28,0" width="' + width + '" height="' + height + '"><param name="movie" value="' + src + '" /><param name="quality" value="high" /><param name="flashvars" value="' + flashvars + '" /><param name="wmode" value="Transparent" /><embed src="' + src + '" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" wmode="Transparent" width="' + width + '" height="' + height + '" flashvars="' + flashvars + '"></embed></object>');
    }
});


$.fn.extend(
{
    zoom: function () {
        var t = $(this);
        var scriptURL = locationURL('libs/jquery/lightbox/lightbox.js');
        var cssURL = locationURL('libs/jquery/lightbox/css/jquery.lightbox.css');

        t.css({ cursor: 'pointer' })

        $.getScript(scriptURL, function () {
            t.lightBox({ fixedNavigation: true });
        });

        $.setStyle(cssURL);

        return t;
    },
    datebox: function () {
        var t = $(this);

        var scriptURL = locationURL('libs/jquery/ui/ui.datepicker.js');

        var cssURL_1 = locationURL('libs/jquery/ui/themes/base/ui.theme.css');
        var cssURL_2 = locationURL('libs/jquery/ui/themes/base/ui.core.css');
        var cssURL_3 = locationURL('libs/jquery/ui/themes/base/ui.datepicker.css');

        $.getScript(scriptURL, function () {
            var data = {
                dateFormat: 'yy-mm-dd',
                buttonImage: 'calendar.gif',
                buttonImageOnly: false,
                yearRange: '1950:2020',
                clearText: '清除',
                closeText: '关闭',
                prevText: '前一月',
                nextText: '后一月',
                hideIfNoPrevNext: false,
                currentText: '',
                dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
                dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'],
                changeMonth: true,
                changeYear: true,
                monthNames: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
                monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
            }

            t.datepicker(data);
        });

        $.setStyle(cssURL_1);
        $.setStyle(cssURL_2);
        $.setStyle(cssURL_3);
    },
    thumbnail: function (width, height) {
        var t = $(this);

        var imageSize = function (img, src, fn) {
            img.style.position = 'absolute';
            img.style.visibility = 'hidden';
            img.style.top = '0px';
            img.style.left = '0px';

            if ($.browser.msie) {
                img.attachEvent('onload', fn);
                document.body.insertAdjacentElement('beforeend', img);
            }
            else if ($.browser.safari) {
                img.addEventListener('load', fn, false);
                document.body.insertAdjacentElement('beforeend', img);
            }
            else if ($.browser.opera) {
                img.addEventListener('load', fn, false);
                document.body.insertAdjacentElement('beforeend', img);
            }
            else if ($.browser.mozilla) {
                img.addEventListener('load', fn, false);
                document.body.insertBefore(img, null);
            }

            img.src = src;
        }

        var img = document.createElement('img');
        var fn = function () {
            var _w = width;
            var _h = height;

            var W = 0;
            var H = 0;

            var WW = img.offsetWidth;
            var HH = img.offsetHeight;

            if (WW > _w) {
                H = (_w * HH) / WW;
                if (H > _h) {
                    H = _h;
                    W = (H * WW) / HH;
                }
                else {
                    W = _w;
                }
            }
            else if (HH > _h) {
                W = (_h * WW) / HH;
                if (WW > _w) {
                    W = _w
                    H = (W * HH) / WW
                }
                else {
                    H = _h
                }
            }
            else {
                W = WW;
                H = HH;
            }


            if (WW < _w && HH < _h) {
                t.height(HH);
                t.width(WW);
            }
            else {
                t.height(H);
                t.width(W);
            }
        }

        imageSize(img, t.attr('src'), fn);

        return t;
    },
    tips: function (text, fn) {
        var t = $(this);
        t.Dialog({ skin: 'tips', content: '<p style="background-image: url(App_Themes/main/common/loading_5.gif); margin: 0; text-indent: 1.7em; line-height: 18px;">' + text + '</p>', lock: true, border: false, width: 200, height: 60, title: false }, function () {
            if (fn) {
                fn();
            }
        });
    },
    dialog: function (options) {
        var defaults = {
            width: 600,
            skin: 'default',
            lock: true,
            fixed: true,
            title: '',
            border: false,
            window: 'top',
            noFn: false,
            yesFn: true,
            yesText: '关闭'
        };

        var t = $(this);
        options = $.extend(defaults, options);
        var scriptURL = locationURL('libs/artDialog/artDialog.js');
        var cssURL1 = locationURL('libs/artDialog/skin/default.css');
        var cssURL2 = locationURL('libs/artDialog/core/layout.css');

        t.click(function () {
            $.getScript(scriptURL, function () {
                if (options.iframe) {
                    options.yesFn = function () {
                        art.dialog.close();
                    }
                    art.dialog.open(options.iframe, options);
                }
                else {
                    art.dialog(options);
                }
            });
        });

        $.setStyle(cssURL1);
        $.setStyle(cssURL2);

        return t;
    },
    Dialog: function (options, fn) {
        var t = $(this);
        options = $.extend(
        {
        }, options);

        var scriptURL = locationURL('libs/artDialog/artDialog.js');

        var cssURL1 = locationURL('libs/artDialog/core/layout.css');
        var cssURL2 = locationURL('libs/artDialog/skin/default.css');
        var cssURL3 = locationURL('libs/artDialog/skin/tips.css');

        $.getScript(scriptURL, function () {
            var a = art.dialog(options);
            t.data('dialog', a);
            if (fn) {
                fn.call(a);
            }
        });

        $.setStyle(cssURL1);
        $.setStyle(cssURL2);
        $.setStyle(cssURL3);

        return t;
    },
    hoverCss: function (options) {
        var defaultCss = {};
        for (key in options) {
            defaultCss[key] = $(this).css(key);
        }

        $(this).hover(function () {
            $(this).css(options);
        }, function () {
            $(this).css(defaultCss);
        });
    },
    pseudoHover: function () {
        $(this).hover(function () {
            $(this).addClass('hover');
        }, function () {
            $(this).removeClass('hover');
        });
    },
    fly: function (options) {
        var t = $(this);

        var defaults = {
            distance: 169,
            count: 5,
            action: 'interval', //interval间隔(默认) smooth顺滑, 未兼容smooth模式，以后兼容
            speed: 1000,
            interval: 5000,
            buttonL: null,
            buttonR: null,
            upAndDown: false
        }
        options = $.extend(defaults, options);

        var Obj = function () {
            var width = options.distance * options.count;

            if (options.upAndDown) {
                t.css({ overflow: 'hidden', height: width + 'px' });
                t.append(t.children().css('display', 'block').clone(true));
            }
            else {
                t.css({ overflow: 'hidden', 'white-space': 'nowrap', width: width + 'px' });
                if ($.browser.msie) {
                    t.append(t.children().css('display', 'inline').clone(true));
                }
                else {
                    t.append(t.children().css('display', 'inline-block').clone(true));
                }
            }

            var scrollMove = function (v) {
                if (options.upAndDown) {
                    if (v == null) {
                        return t.scrollTop();
                    }
                    else {
                        t.scrollTop(v);
                    }
                }
                else {
                    if (v == null) {
                        return t.scrollLeft();
                    }
                    else {
                        t.scrollLeft(v);
                    }
                }
            }

            var current = 0;
            var target = 0;

            var move = function () {
                if (options.upAndDown) {
                    M = t.children().eq(0).outerHeight();
                }
                else {
                    M = t.children().eq(0).outerWidth();
                }

                var v = options.speed;

                if (target < current) {
                    if (current - v >= target) {
                        current = current - v;
                    }
                    else {
                        current = current - (current - target) * 0.1;
                    }
                    if (Math.abs(target - current) < 0.5) {
                        current = target;
                    }

                    if (current < 0) {
                        scrollMove(M + (current % M));
                    }
                    else {
                        scrollMove(current % M);
                    }
                } else if (target > current) {
                    if (current + v <= target) {
                        current = current + v;
                    }
                    else {
                        current = current + (target - current) * 0.1;
                    }
                    if (Math.abs(target - current) < 0.5) {
                        current = target;
                    }

                    if (current < 0) {
                        scrollMove(M + (current % M));
                    }
                    else {
                        scrollMove(current % M);
                    }
                }
                else {
                }
            }


            //为道尔而修改 2011-12-29
            var _stop = false;
            this.setStop = function (b) {
                _stop = b;
            }
            var moveSmooth = function () {
                if (!_stop) {
                    target += 3;

                    M = t.children().eq(0).outerWidth();
                    scrollMove(target % M);
                }
            }

            setInterval(moveSmooth, 40);



            var move_ = function () {
                if (options.upAndDown) {
                    target = current - (options.distance * 1);
                }
                else {
                    target = current - (options.distance * 1);
                }
            }
            //var timerID = setInterval(move_, options.interval);


            if (options.buttonL) {
                options.buttonL.click(function () {
                    clearInterval(timerID);
                    target = target - width;
                });
            }
            if (options.buttonR) {
                options.buttonR.click(function () {
                    clearInterval(timerID);
                    target = target + width;
                });
            }

            this.setCurrent = function (i) {
                clearInterval(timerID);
                target = options.distance * i;
            }
            this.Test = function (i) {
                alert(i);
            }
        };

        t.data('fly', new Obj());

        return t;
    },
    formSendMail: function (options) {
        var t = $(this);

        var defaults = {
            to: '183254569@qq.com',
            subject: '来自:' + document.title
        }
        options = $.extend(defaults, options);

        var i = -1;
        t.find('input,select,textarea').each(function () {
            i++;
            if ($(this).attr('name') == '') {
                $(this).attr('name', 'formSendMail_name_' + i);
            }
        });

        t.Validate({ debug: true, submitHandler: function () {
            t.tips('正在发送您的信息，请等待...', function () {
                var ajaxData = {};
                ajaxData.action = 'formSendMail';
                ajaxData.to = options.to;
                ajaxData.subject = options.subject;

                var tClone = t.clone();
                tClone.find('input,select,textarea').each(function () {
                    var t = $(this);
                    var val = '';

                    if (t.is(':checkbox')) {
                        val = $('<span style="border: 1px solid #555555; font-size: 12px; line-height: 12px; text-align: center; width: 12px; height: 12px; display: inline-block; margin-left: 5px; margin-right: 5px;"></span>');
                        if (t.is(':checked')) {
                            val.text('√');
                        }
                    }
                    else if (t.is(':radio')) {
                        val = $('<span style="border: 1px solid #555555; font-size: 12px; line-height: 12px; text-align: center; width: 12px; height: 12px; display: inline-block; margin-left: 5px; margin-right: 5px;"></span>');
                        if (t.is(':checked')) {
                            val.text('●');
                        }
                    }
                    else if (t.is('select')) {
                        val = $('<span style="font-weight: bold;"></span>').text(t.find('option:selected').text());
                    }
                    else if (t.is('textarea')) {
                        val = $('<div style="font-weight: bold;"></div>').text(t.text());
                    }
                    else {
                        val = $('<span style="font-weight: bold;"></span>').text(t.val());
                    }

                    if (t.is(':reset') || t.is(':submit')) {
                        t.remove();
                    }
                    else {
                        t.replaceWith(val);
                    }
                });
                ajaxData.content = tClone.html();

                $.post('ajax.aspx', ajaxData, function (v) {
                    t.data('tips').close();

                    alert(v.message);


                }, 'json');

            });

            return false;
        }
        });


        return t;
    },
    imagesLight: function (options) {
        var t = $(this);
        t.addClass('imagesLight');
        $.setStyle(locationURL('libs/jquery/imagesLight/skin/style.css'));


        var imageDatas = new Array();
        var datas = options.split('$');
        for (var i = 0; i < datas.length; i++) {
            if (datas[i].length > 0) {
                var data = datas[i].split('|');
                imageDatas.push({ image: data[0], thumbnail: data[1], title: data[2], link: data[3] });
            }
        }

        var wrap = $('<table cellpadding="0" cellspacing="0" class="previewWrap"><tr><td class="previewOuter"><div class="previewInner"><table cellpadding="0" cellspacing="0"><tr></tr></table></div></td></tr><tr><td></td></tr><tr><td></td></tr></table>');

        var buttonL = $('<button class="buttonLeft"></button>');
        var buttonR = $('<button class="buttonRight"></button>');
        wrap.find('td').eq(1).append(buttonL).append(buttonR);

        var thumbs = $('<div class="fly"><table cellpadding="0" cellspacing="0"><tr></tr></table></div>');
        var thumbsTr = thumbs.find('tr');
        wrap.find('td').eq(2).append(thumbs);


        for (var i = 0; i < imageDatas.length; i++) {
            var imageData = imageDatas[i];

            thumbsTr.append($('<th><table cellpadding="0" cellspacing="0"><tr><td><img title="' + imageData.title + '" src="' + imageData.thumbnail + '" /></td></tr></table></th>').click(function () {
                var url = $(this).data('str_515422');
                if (url) {
                    $.link(url);
                }
            }).mouseover(function () {
                var t = $(this);
                var No = t.data('int_016685');


                thumbs.find('th').removeClass('current');
                t.addClass('current');


                setTimeout(function () {
                    if (t.is('.current')) {
                        previewInner.data('fly').setCurrent(No);
                    }
                }, 900);
            }).data('int_016685', i).data('str_515422', imageData.link));
        }


        thumbs.fly({ distance: 104, count: 5, buttonL: buttonL, buttonR: buttonR, interval: 999999999 });


        var previewInner = wrap.find('.previewInner');
        for (var i = 0; i < imageDatas.length; i++) {
            var imageData = imageDatas[i];
            previewInner.find('tr').append($('<th><table cellpadding="0" cellspacing="0"><tr><td><img style="width: 550px; height: 400px;" src="' + imageData.image + '" /><em style="position: relative; top: -40px; width: 550px; height: 40px; display: block; font-style: normal; color: White; font-size: 15px; line-height: 40px;">　' + imageData.title + '<em></td></tr></table></th>'));
        }
        previewInner.fly({ distance: 550, count: 1, interval: 999999999 });



        t.append(wrap);

        return t;
    },
    chinaMap: function (options) {
        var t = $(this);
        t.append($.flashObject('swf/chinaMap.swf', 600, 500, 'xmlurl=chinaMapInfo.xml&title=营销网络&jsHandler=eventHandler'));
        return t;
    },
    flvPlayer: function (options) {
        var t = $(this);
        options = $.extend(
        {
            width: 200,
            height: 200,
            css: {}
        }, options);

        t.append($.flashObject('swf/vcast.swf', options.width, options.height, 'vcastr_file=' + options.src).css(options.css));

        return t;
    },
    Validate: function (options) {
        var t = $(this);
        options = $.extend(
        {
            errorElement: 'div',
            showErrors: function (errorMap, errorList) {
                if (errorList[0]) {
                    alert(errorList[0].message);
                }
            },
            onkeyup: false,
            onfocusout: false
        }, options);

        var scriptURL = locationURL('libs/jquery/validate/validate.js');

        $.getScript(scriptURL, function () {
            if ($.lang() == 'zh') {
                $.validator.messages =
                {
                    required: '必选字段',
                    remote: '请修正该字段',
                    email: '请输入正确格式的电子邮件',
                    url: '请输入合法的网址',
                    date: '请输入合法的日期',
                    dateISO: '请输入合法的日期 (ISO).',
                    number: '请输入合法的数字',
                    digits: '只能输入整数',
                    creditcard: '请输入合法的信用卡号',
                    equalTo: '请再次输入相同的值',
                    accept: '请输入拥有合法后缀名的字符串',
                    maxlength: '请输入一个长度最多是 {0} 的字符串',
                    minlength: '请输入一个长度最少是 5 的字符串',
                    rangelength: '请输入一个长度介于 {0} 和 {1} 之间的字符串',
                    range: '请输入一个介于 {0} 和 {1} 之间的值',
                    max: '请输入一个最大为 {0} 的值',
                    min: '请输入一个最小为 {0} 的值'
                };
            }

            t.validate(options);
        });

        return t;
    },
    formLogin: function (options) {
        var t = $(this);
        options = $.extend(
        {
            tips: true
        }, options);

        t.Validate(
        {
            rules:
            {
                UserName: 'required',
                Password: 'required',
                Code: 'required'
            },
            submitHandler: function () {
                var fn = function () {
                    var ajaxData = {};
                    ajaxData.action = 'formLogin';
                    ajaxData.UserName = t.find('input[name=UserName]').val();
                    ajaxData.Password = t.find('input[name=Password]').val();
                    ajaxData.Code = t.find('input[name=Code]').val();
                    $.post('ajax.aspx', ajaxData, function (v) {
                        if (t.data('tips')) {
                            t.data('tips').close();
                        }

                        if (v.result != 1) {
                            t.find("img[src*='validateimages.aspx']").attr('src', 'validateimages.aspx?' + Math.random());
                            alert(v.message);
                        }
                        else {
                            alert(v.message);
                            $.refresh();
                        }

                    }, 'json');
                };

                if (options.tips) {
                    t.tips('会员正在尝试登录，请等待...', fn);
                }
                else {
                    fn();
                }
            }
        });
    },
    userLogin: function () {
        var t = $(this);

        var isInit = false;
        t.click(function () {
            t.Dialog(
            {
                content: '<form class="userRegister"><table><tr><th>会　员:　</th><td><input type="text" class="text" name="UserName" /></td></tr>    <tr><th>密　码:　</th><td><input type="password" class="password" name="Password" /></td></tr>    <tr><th>验证码:　</th><td><input type="text" name="Code" class="text" style="width: 50px;" /><img src="validateimages.aspx" width="63" height="22" align="absmiddle" /></td></tr>    <tfoot><tr><td colspan="2"><input type="submit" class="button" value="登 录" /><input type="reset" class="button" value="关 闭" /></td></tr></tfoot></table></form>',
                fixed: true,
                border: false,
                closeFn: function () {
                },
                title: '会员登录 Login',
                width: 300,
                lock: true
            }, function () {
                $(this.content()).find('form').formLogin({ tips: false });
            });
        });
    },
    userRegister: function () {
        var t = $(this);
        t.click(function () {
            t.Dialog(
            {
                content: '<form class="userRegister"><table><tr><th>新会员:　</th><td><input type="text" class="text" name="UserName" value="" /></td></tr>    <tr><th>密　码:　</th><td><input value="" type="password" class="password" name="Password" /></td></tr>    <tr><th>重复密码:　</th><td><input value="" type="password" class="password" name="ConfirmPassword" /></td></tr>      <tr><th>Email:　</th><td><input value="" type="text" class="text" name="Mail" /></td></tr>    <tr><th>验证码:　</th><td><input type="text" name="Code" class="text" style="width: 50px;" /><img src="validateimages.aspx" width="63" height="22" align="absmiddle" /></td></tr>    <tfoot><tr><td colspan="2"><input type="submit" class="button" value="注 册" /><input type="reset" class="button" value="重 置" /></td></tr></tfoot></table></form>',
                fixed: true,
                border: false,
                closeFn: function () {
                },
                title: '会员注册 Register',
                width: 400,
                lock: true
            }, function () {
                var form = $(this.content()).find('form');
                form.Validate(
                {
                    rules:
                    {
                        UserName: 'required',
                        Password:
                        {
                            required: true,
                            minlength: 5
                        },
                        ConfirmPassword:
                        {
                            equalTo: 'input[name=Password]'
                        },
                        Mail:
                        {
                            email: true
                        },
                        Code: 'required'
                    },
                    submitHandler: function () {
                        var ajaxData = {};
                        ajaxData.action = 'userRegister';
                        ajaxData.UserName = form.find('input[name=UserName]').val();
                        ajaxData.Password = form.find('input[name=Password]').val();
                        ajaxData.Mail = form.find('input[name=Mail]').val();
                        ajaxData.Code = form.find('input[name=Code]').val();

                        $.post('ajax.aspx', ajaxData, function (v) {
                            if (v.result != 1) {
                                form.find("img[src*='validateimages.aspx']").attr('src', 'validateimages.aspx?' + Math.random());
                                alert(v.message);
                            }
                            else {
                                alert(v.message);
                                $.link('member.aspx');
                            }

                        }, 'json');
                    }
                });
            });
        });
    },
    userLogout: function () {
        var t = $(this);

        t.click(function () {
            t.tips('正在与服务器交互数据，请等待...', function () {
                var ajaxData = {};
                ajaxData.action = 'userLogout';
                var dialog = this;
                $.post('ajax.aspx', ajaxData, function (v) {
                    if (v.result == 1) {
                        alert(v.message);

                        $.refresh();
                    }
                }, 'json');
            });
        });
    },
    runClick: function () {
        var t = $(this);

        eval(t.attr('onclick').toString().replace(/^(function\s)\w+/, '$1onclick') + 'onclick.call(this);');

        return t;
    }
});















$(document).ready(function()
{
    if($.browser.msie)
    {
        document.execCommand('BackgroundImageCache', false, true);
    }
    
    
    $('.number,.serialnumber', this).keyup(function()
    {
        this.value = this.value.replace(/[^\d\.]/g, '');
    });
    
    
    $('form[key=search][method=get]').each(function()
    {
        var searchs = window.location.search.toString().replace(/^\?/i, '').split('&');
        for(var i = 0; i < searchs.length; i++)
        {
            var v = searchs[i].split('=');
            if(v.length == 2)
            {
                if(v[0] == 'page')
                {
                    v[1] = '0';
                }
                
                $(this).append('<input type="hidden" name="' + v[0] + '" value="' + v[1] + '" />');
            }
        }
    });
    
    
    $('input').each(function()
    {
        var t = $(this).attr('type');
        
        if(t == 'checkbox')
        {
            var v = $(this).attr('checked_');
            if(v != '' && v != '0' && v != null && v != undefined)
            {
                $(this).attr('checked', true);
            }
            else
            {
                $(this).attr('checked', false);
            }
        }
    });
    
    
    //单选的SELECT
    $('select').each(function()
    {
        for(var i = 0; i < this.options.length; i++)
        {
            this.options[i].innerHTML = $.langText(this.options[i].innerHTML);
        }
    });
    
    
    
    $('select[value_]').each(function()
    {
        var value_ = $(this).attr('value_');
        for(var i = 0; i < this.options.length; i++)
        {
            if(this.options[i].value == value_)
            {
                this.selectedIndex = i;
            }
        }
    });
    
    
});


$(document).ready(function()
{
    $('input[name=search]', this).each(function()
    {
        var value = $(this).val();
        $(this).click(function()
        {
            if($(this).val() == value)
            {
                $(this).val('');
            }
        });
    });
    
    
    
    
    
    

    
});







$(function()
{
    for(var i = 0; i < 2; i++)
    {
        $('*[oninit]', document).each(function()
        {
            try
            {
                eval($(this).attr('oninit'));
            }
            catch(e)
            {
                alert('错误代码:' + $(this).attr('oninit') + ' 错误信息:' + e.toString());
            }
            $(this).removeAttr('oninit');
        });
    }
    
    
    var alert_ = $.querys().alert || '';
    if(alert_.length > 0)
    {
       alert($.langText(decodeURI(alert_)));
    }
});
