﻿$(function() {
$.include('/js/menu.js');
setMenu(2);

    $.include({ file: ['jquery.validate.js', 'jquery.controller.js', 'jquery.modal.js', 'jquery.linkage.js'], path: '/js/jquery/' });

    $.ajax({
        url: 'http://res.7xingman.com/jsonp/RegionController.ashx?callback=?',
        data: 'MN=GetRegionServer&gameid=1',
        cache: true,
        dataType: 'jsonp',
        success: function(data) {
            $.linkage(data, 'region', 'server');
$("#region").val(9).change();
$("#server").val(913);
        }
    });

    $.validator.addMethod('activationCode', function(value, element) {
        return this.optional(element) || /^[A-Z]{5}$|^[A-Z0-9]{12,16}$/i.test(value);
    });
    $('#activeForm').validate({
        rules: {
            activationCode: {
                required: true,
                activationCode: true
            },
            area: 'required',
            server: 'required'
        },
        messages: {
            activationCode: {
                required: '请输入激活码',
                activationCode: '激活码错误'
            },
            area: '请选择区服务器列表',
            server: '请选择区服务器列表'
        },
        submitHandler: function() {
            $.controller({
                url: '/Server/BounsController.ashx',
                selector: '#activeForm',
                method: 'Activatate',
                errorHash: {
                    '3348': '请选择区服务器列表',
                    '262144': '账号未登录或凭证已经过期',
		//'262144':(function(){
		//		location.href = '/login.ashx?ReturnUrl=' + encodeURIComponent(location.href);return;
		//		})(),
                    '262145': '装备激活码错误',
                    '-262144': '不存在激活码',
                    '-262145': '激活码已经过期',
                    '-262146': '激活码已经被冻结',
                    '-262149': '该账号已经在此次活动中激活',
                    '-262150': '该激活码已经被他人使用',
                    '-262151': '已经在该区使用过该激活码'
                },
                success: function(json) {
                    $.alert('激活成功,请到游戏中领取物品!', '成功');
                }
            });
        }
    });
});
