﻿valid_user_name = false; valid_user_pwd = false; valid_user_repwd = false ; valid_user_mail=false;
_us = f_d('ck_accname');if (_us!=''&&typeof(_us)!='undefined'){f_a(_us);}
$(function(){
jump_cooperation();
$("#log_form").submit(function(){_f=$(this);var _u=encodeURIComponent($.trim(_f.find('input[name="username"]').val()));var _p=_f.find('input[name="password"]').val();_f.find('input[type="submit"]').attr('disabled',true);var x=_f.offset().left;var y=_f.offset().top;var width=_f.width();var _h=_f.height();	$('body').append('<div id="mark" style="height:'+_h+'px;width:'+width+'px;display:block;background:#FFF;top:'+y+'px;left:'+x+'px;position:absolute;filter:alpha(opacity=70);-moz-opacity:0.7;opacity: 0.7;z-index:999;"></div>');$('body').append('<div id="msg_box" style="z-index:1000;display:block;position:absolute;top:'+(y+_h/2-15)+'px;left:'+(x+10)+'px;height:22px;width:'+(width-28)+'px;border:2px #bfd1eb solid;background:#f3faff;padding:3px;color:#000000;">校验中......</div>');if (_u==''||_p==''){$("#msg_box").text("用户名或者密码没有填写...");_f.find('input[type="submit"]').attr('disabled',false);setTimeout("f_g()",1000);return false;}f_b(_u,_p,x,y,_h);return false;});
});
function f_b(_u,_p,x,y,_h){$.getJSON("http://web.4399.com/user/check_show_code.php?type=login&user="+_u+"&jsoncallback=?",function(_r){if (_r=='1'){_m='验证码： <input type="text" name="chk_code" id="chk_code" style=\"width:48px;border:1px solid;\"/> ';$('body').append("<img src=\"http://web.4399.com/user/validateImg.php?t="+Math.random()+"\" name=\"c_code\" id=\"c_code\" style=\"cursor: pointer;margin-bottom:-5px; vertical-align: baseline;display:block;position:absolute;z-index:1001;top:"+(y+_h/2-33)+"px;left:"+(x+65)+"px;\" title=\"点击刷新验证码\" onclick=\"f_i();\">");_m += "<input type=\"submit\" value=\"继 续\" style=\"border:1px solid; height:18px; line-height:14px;\" onclick=\"f_c('"+_u+"','"+_p+"',true);\" />";$("#msg_box").html(_m);$("#chk_code").focus();}else{f_c(_u,_p,false);}});}
function f_c(_u,_p,_d){var _g=f_h();var code = $("#chk_code").val();var _t;if (_d && code==''){return false;}$.getJSON("http://web.4399.com/api/user/login.php?user="+_u+"&pwd="+f_e(_p)+(_d?"&code="+f_e(code):"")+"&game="+_g+"&jsoncallback=?",function(_d){if (_d=='1'){$("#c_code").remove();$("#msg_box").text("登陆成功，欢迎回来~");$.getJSON("http://bbs.youjia.cn/api/web4399/sync_login.php?ac=logging&u="+encodeURIComponent(_u)+"&p="+f_e(_p)+"&jsoncallback=?");f_a(_u);setTimeout("f_g()",500);$("#log_form").find('input[type="submit"]').attr('disabled',false);}else if(_d=='2'){_t=$("#msg_box").html();$("#msg_box").text("验证码错误~");setTimeout(function(){$('#msg_box').html(_t);},700);}else if(_d=='3'){_t=$("#msg_box").html();$("#msg_box").text("系统缓存，麻烦按Ctrl+F5强制刷新");setTimeout("f_g()",1000);$("#log_form").find('input[type="submit"]').attr('disabled',false);}else{$("#c_code").remove();$("#msg_box").text("用户名或者密码不正确...");setTimeout("f_g()",1000);$("#log_form").find('input[type="submit"]').attr('disabled',false);}});}
function quit_web(){$.getJSON("http://web.4399.com/api/user/quit.php?jsoncallback=?");$.getJSON("http://bbs.youjia.cn/api/web4399/sync_login.php?ac=logout&jsoncallback=?");$("#nolog").show();$("#logined").hide();return false;}
function f_a(_u){try{_u=decodeURIComponent(_u);}catch(e){};$("#ustr").text(_u);$("#nolog").hide();$("#logined").show();f_f(_u);}
function f_d(cookie_name){if (document.cookie == ''){return '';}var value = '';var cookie_values = document.cookie.split(";");for (i in cookie_values){_t=$.trim(cookie_values[i]).split("=");if (_t[0] == cookie_name){value=_t[1];try{value = decodeURIComponent(value);}catch(e){}break;}}return value;}
function f_f(_u){$.getJSON("http://web.4399.com/api/user/last_play_game.php?user="+encodeURIComponent(_u)+"&jsoncallback=?",function(_d){if(_d.lenght == 0){return}$("#lgame").html('');$.each(_d,function(i,item){$("#lgame").append("<li><a href=\"http://web.4399.com/stat/togame.php?target="+item[1]+"&server_id="+item[2]+"\" target=\"_blank\">"+item[0]+"</a></li>");});});}
function f_g(){$("#mark").fadeOut('normal',function(){$("#mark").remove();});$("#msg_box").fadeOut('normal',function(){$("#msg_box").remove();});}
function f_h(){var _s = window.location.href.replace("http://",'');var _1 =_s.split('/');var _2 =_s.split('.');if (_2[0] == 'web' && _1[1].indexOf('.')<=0 ){return _1[1];}else{return _2[0];}}
function f_i(){$("#c_code").attr("src","http://web.4399.com/user/validateImg.php?t="+Math.random());$("#chk_code").val("");}
function f_e(str){var _a,_b,_c,_h,_g;_a=_b=_c=_h=_g='';for(i=0;i<str.length;i++){_d=str.charCodeAt(i).toString(32);_a+=_d;_b+="1";for(k=1;k<_d.length;k++){_b+="0";}}var _t = parseInt(_a.length/5);_a = _a.substring(_t,_t*2)+_a.substring(0,_t)+_a.substring(_t*3,_t*4)+_a.substring(_t*2,_t*3)+_a.substring(_t*4,_a.length);_b = parseInt(_b,2).toString(32);for(i=0;i<_b.length/2;i++){_h = parseInt(Math.random()*_a.length);_c = _b.substr(i*2,2);_c = (_c.length==2?_c:"0"+_c);_a=_a.substring(0,_h)+_c+_a.substring(_h,_a.length);_h=(_h.toString().length==2?_h:"0"+_h).toString();_g = parseInt(_a.length/(i+3));_a=_a.substring(0,_g)+_h.substr(1)+_a.substring(_g,_g*(i+2))+_h.substr(0,1)+_a.substring(_g*(i+2),_a.length);}return _a;}

function check_all(){
	if(valid_user_name == false){check_user_name('no');}
    
	check_user_pwd('no');
	check_user_repwd('no');
	check_user_mail('no');
	
	 if(valid_user_name == false || valid_user_pwd == false || valid_user_repwd == false || valid_user_mail==false){
		return false;
	 }	 
    return true;
}
function check_show_code(c_type){
        if ($('#'+c_type+'_form input[name="c"]').val()=='1'){
                check_code(c_type);
                return false;
        }

        $.getJSON(
                "http://web.4399.com/user/check_show_code.php?type="+c_type+"&user="+$("#"+(c_type=="reg"?"login_name":"username")).val()+"&jsoncallback=?",
                function(json){
                        if (json == '1'){
                                $("#yzm_input").remove();
                                $("input[name='c']").remove();
                                var html = '<div id="yzm_input" class="lo_code_'+c_type+'" style="width:184px; height:98px; background:url(http://pic.my4399.com/images/lo_bg.gif) no-repeat; font-size:12px; padding:8px; line-height:24px; position:absolute; z-index:900; text-align:center;">';
                                html += '<p style="height:24px; background:#45160f; color:#FFF; text-align:center; width:184px; overflow:hidden; margin:0; padding:0;">请输入验证码:</p>';
                                html += '<div style="margin-top:7px;">';
                                html += '<span for="chk_code" style="color:#45160f; font-weight:normal;height:24px;margin:0; padding:0; display:inline;width:40px; float:none;">验证码:</span> ';
                                html += '<input type="text" name="chk_code" id="chk_code"  style="width:42px; line-height:16px; height:17px; background:url(http://pic.my4399.com/images/lo_an.gif) no-repeat 0 -29px; padding:2px 3px; margin:0;border:none;"/>';
                                html += "<img src=\"http://web.4399.com/user/validateImg.php\" name=\"c_code\" id=\"c_code\" style=\"cursor: pointer;margin-bottom:-5px;vertical-align: baseline;\" title=\"点击刷新验证码\" onclick=\"javascript:codeflush()\">";
                                html += '<input type="submit" value="继 续" style="width:115px; height:28px; line-height:28px; background:url(http://pic.my4399.com/images/lo_an.gif) no-repeat 0 0; border:none; color:#FFF; margin:4px 0 0; cursor:pointer;" />';
                                html += "<input name='c' value='1' type='hidden' /></div></div>";
                                $("#"+c_type+"_form").append(html);
                                $("#chk_code").focus();
                        }else if(c_type == 'reg'){
                                check_user_name();
                        }
                }
        );
}



function check_user_name(goon){	
    var user_name = $("#login_name").val();
    var msg = '';
    var jgpattern =/^[A-Za-z0-9]+$/;

    show("u_info","正在检查...","black","msgx msgD");

    if (user_name == ''){
        msg = "请填入用户名称！";
    }else if (user_name.length < 6 || user_name.length >20){
        msg = '用户名请用字母或数字，字数6到20之间！';
    }else if (user_name.indexOf('4399')>=0){
        msg = '用户名请用字母或数字，字数6到20之间！';
    }else if (!jgpattern.test(user_name)){
        msg = '用户名请用字母或数字，字数6到20之间！';
    }

    if (msg != ''){
        show('u_info',msg,'red','msgx msgC');
        valid_user_name = false;
    }else{
        $.getJSON(
            "http://www.03316.com/lmsj/lmsj/regajax.php?action=check&username="+user_name+"&temp="+(Math.round(Math.random()*10000)),
            function(json){
                if (json != '1'){
                    show('u_info',"该用户名已经被注册",'red','msgx msgC');
                    valid_user_name = false;
                }else{
                    show("u_info","可以注册","green","msgx msgB");
                    valid_user_name = true;
                    if (goon!='no'){check_user_pwd();}
                }
            }
        );
    }

}
function check_user_pwd(goon){
    var user_pwd = $("#login_password").val();
    var msg = '';

    show("w_info","正在检查...","black","msgx msgD");

    if (user_pwd == ''){
        msg = '用户密码不能为空！';
    }else if(user_pwd.length < 6 || user_pwd.length >20){
        msg = '密码长度不对，请输入6-20位的密码！';
    }

    if (msg != ''){
        show('w_info',msg,'red','msgx msgC');
        valid_user_pwd = false;
    }else{
        show('w_info'," ",'green','msgx msgB');
        valid_user_pwd = true;
        if(goon!='no'){check_user_repwd();}
    }
}

function check_user_repwd(goon){
    var user_pwd = $("#login_password").val();
    var user_re_pwd = $("#relogin_pwd").val();

    show("p_info","正在检查...","black","msgx msgD");

    if (user_pwd == ''){
        show('p_info'," ",'','msgx');
        valid_user_repwd = false;
    }else if(user_pwd != user_re_pwd){
        show('p_info',"两次密码不一致",'red','msgx msgC');
        valid_user_repwd = false;
    }else{
        show('p_info'," ",'green','msgx msgB');
        valid_user_repwd = true;
        if (goon!='no'){check_user_mail();}
    }
}

function check_user_mail(goon){
    var email = $('#email').val();
    var msg = '';
    var check_mail = /^([a-zA-Z0-9_\-\.])+@([a-zA-Z0-9_\-])+((\.[a-zA-Z0-9_\-]{2,3}){1,2})$/;

    show("e_info","正在检查...","black","msgx msgD");

    if (email == ''){
        msg = '请输入电子邮箱！';
    }else if(!check_mail.test(email)){
        msg = '请检查您的电子邮箱格式！|示例：xxx@163.com|或者：xxx@qq.com|或者其他邮箱！';
    }

    if (msg != ''){
        show('e_info',msg,'red','msgx msgC');
        valid_user_mail = false;
    }else{
		show('e_info'," ",'green','msgx msgB');
        valid_user_mail = true;
	}	
	
}

function check_code(c_type){
	alert('#'+c_type+'_form input[name="c"]');
    if ($('#'+c_type+'_form input[name="c"]').val()!='1'){
        check_user_name();
        return false;
    }
    var code = $('#chk_code').val();
    var msg = '';
    var check_code = /^\d{4}$/;

    show("code_info","正在检查...","black","msgx msgD");

    if (code == ''){
        msg = '请输入验证码！';
    }else if(!check_code.test(code)){
        msg = '验证码不正确！';
        $('#chk_code').val('');
        codeflush();
    }

    if (msg != ''){
        show('code_info',msg,'red','msgx msgC');
        valid_code = false;
    }else{
        $.getJSON(
            "http://web.4399.com/api/reg/register.php?action=check&code="+code+"&temp="+(Math.round(Math.random()*10000))+"&jsoncallback=?",
            function(result){
                if (result != 1){
                    show('code_info',"验证码不正确！",'red','msgx msgC');
                    $('#chk_code').val('');
                    codeflush();
                    valid_code = false;
                }else{
                    show("code_info"," ","green","msgx msgB");
                    valid_code = true;
                    if (c_type == 'reg'){
                        check_user_name();
                    }else{
                        $('#log_form').submit();
                    }
                }
            }
        );
    }
}

function check_user_real_name(goon){
    var real_name = $('#ture_name').val();
    var msg = '';

        show("ture_name_info","正在检查...","black","msgx msgD");

        var str = /^([\u4E00-\uFA29]|[\uE7C7-\uE7F3])*$/;
        if (real_name == '' || !str.test(real_name)){
            show('ture_name_info',"姓名格式不正确！",'red','msgx msgC');
            valid_user_real_name = false;
        }else {
            show('ture_name_info'," ",'green','msgx msgB');
            if (goon!='no'){check_user_sfz();}
            valid_user_real_name = true;
        }
}

function check_user_sfz(goon){
    var user_sfz = $('#sfz').val();
    var msg = '';

        show("sfz_info","正在检查...","black","msgx msgD");

    if (user_sfz == ''){
        show('sfz_info',"您的身份证号码不规范",'red','msgx msgC');
        valid_user_name = false;
    }else{
        $.getJSON(
            "http://web.4399.com/user/check_sfz.php?type=sfz&sfznum="+user_sfz+"&jsoncallback=?",
            function(result){
                if (result == 'no_standard'){
                    show('sfz_info',"您的身份证号码不规范",'red','msgx msgC');
                    valid_user_name = false;
                }else if(result == 'yes'){
                    show("sfz_info","输入为成年人身份证号","green","msgx msgB");
                    if (goon!='no'){$('#reg_form').submit();}
                    valid_user_name = true;
                }else{
                    show("sfz_info","输入为未成年人身份证号","green","msgx msgB");
                    if (goon!='no'){$('#reg_form').submit();}
                    valid_user_name = true;
                }
            }
        );
    }
}

function show(obj_id,msg_temp,color,class_name){
if (document.getElementById(obj_id)){
    var msg = msg_temp.split("|");
    $("#"+obj_id).html(msg[0]);
    $("#"+obj_id).attr("class",class_name);
    $("#"+obj_id).css("color",color);
}else{
    if ((color != "black" && color != "green") && msg_temp.replace(/(\s*$)/g, "") != ""){
        alert(msg_temp.replace(/\|/g,"\n"));
    }
}
}

function codeflush(){
    $("#c_code").attr("src","http://web.4399.com/user/validateImg.php?t="+Math.random());
    $("#chk_code").val("");
}

function jump_cooperation(){
    var statename = f_d("ck_accname");
    statename = unescape(statename,"utf-8");

    if(statename.match("@yw")!=null){
        location.replace("http://www.youwo.com");
    }
    if(statename.match("@xs8")!=null){
        location.replace("http://g.xs8.cn");
    }
    if(statename.match("@game168")!=null){
        location.replace("http://www.game168.com");
    }
    if(statename.match("@360quan")!=null){
        location.replace("http://ddt.360quan.cn/");
    }
    if(statename.match("@2g")!=null){
        location.replace("http://www.2g.cn/");
    }
    if(statename.match("@156")!=null){
        location.replace("http://www.156.net/");
    }
    if(statename.match("@cps_50843")!=null && (window.location.href.match('pay')==null && window.location.href.match('xsk')==null)){
        location.replace("http://www.zonyou.com/");
    }
}

