﻿function checkUserNameVaild(username){
    $.ajax({
            url:'/Ajax/my/Register.aspx',
            data:'todo=ExistsUserName&username='+username+'',
            type:'POST',
            dataType:'json',
            success:function(data){
                            if(data.success)
                            {
                                recover("username");
                            }else{
                                 recover("username",false);
                            }
                        }
            
        });
}
function checkEmailVaild(email){
    $.ajax({
            url:'/Ajax/my/Register.aspx',
            data:'todo=ExistsEmail&email='+email+'',
            type:'POST',
            dataType:'json',
            success:function(data){
                            if(data.success)
                            {
                                recover("email");
                            }else{
                                recover("email",false);
                            }
                        }
            
        });
}

function checkTrueNameVaild(truename){
        if(truename.length==0){
            recover("truename");
            return;
        }
        $("#TrueNametips").show();
    if(truename.indexOf(" ")>0){
        $("#TrueNametips").attr("class","error");
        $("#TrueNametips").html("不允许有空格");
    }else if(truename.length==1){
        $("#TrueNametips").attr("class","error");
        $("#TrueNametips").html("真实姓名长度至少要2-2个以上");
    }
    else{
        $("#TrueNametips").attr("class","right");
        $("#TrueNametips").html("正确");
    }
}

function checkPhoneVaild(phonenumber){
    if(phonenumber.length==0){
            $("#"+"phone").parent().next().css("color","#666666");
            $("#"+"phone").parent().next().css("border","solid 0px #0000FF");
        return;
    }
    $.ajax({
            url:'/Ajax/my/Register.aspx',
            data:'todo=ExistsPhone&phone='+phonenumber+'',
            type:'POST',
            dataType:'json',
            success:function(data){
                            if(data.success)
                            {
                                recover("phone");
                            }else{
                                 recover("phone",false);
                            }
                        }
            
        });
}

function checkuserpasswordValue(userpassword){
    if(userpassword.length>=6&&userpassword.length<=20)
    {
            recover("userpassword");
    }else{
        recover("userpassword",false);
    }
}

function checkconfirmuserpassword(confirmuserpassword){
    if(confirmuserpassword==$("input[name='userpassword']").val()){
            recover("confirmuserpassword");
    }else{
        recover("confirmuserpassword",false);
    }
}

function checkanswer(answer){
    if($("#question").val()=="0"){
    $("#"+"answer").parent().next().css("color","#666666");
    $("#"+"answer").parent().next().css("border","solid 0px #0000FF");
    }else{
        var value = $("input[name='answer']").val();
        if(value.length<=1){
            recover("answer",false);
        }else{
            recover("answer",true);
        }
    }
}

function checkvcode(vcode){
    $.ajax({
            url:'/Ajax/my/Register.aspx',
            data:'todo=ExistsCode&vcode='+vcode+'',
            type:'POST',
            dataType:'json',
            success:function(data){
                if(data.success){
                    recover("vcode");
                }else{
                recover("vcode",false);
                }
            }
    })
}

function checkidentfiy(identify){
    if(!identify.match(/^\d{3}(\d|x|X)$/)){
        recover("identfiy",false);
    }else{
        recover("identfiy");
    }
}

function checkregisterForm(){
//    if($("#username").val()==""){
//        $("#usernametips").show();
//        $("#usernametips").attr("class","error");
//        $("#usernametips").html("请填写用户名");
//    }
//   if($("#email").val()==""){
//        $("#emailtips").show();
//        $("#emailtips").attr("class","error");
//        $("#emailtips").html("请填写邮箱");
//    }
//   if($("#userpassword").val()==""){
//        $("#userpasswordtips").show();
//        $("#userpasswordtips").attr("class","error");
//        $("#userpasswordtips").html("请填写用户密码");
//    }
//   if($("#confirmuserpassword").val()==""){
//        $("#confirmuserpasswordtips").show();
//        $("#confirmuserpasswordtips").attr("class","error");
//        $("#confirmuserpasswordtips").html("请填写用户重复密码");
//    }
//   if($("#identfiy").val()==""){
//        $("#identfiytips").show();
//        $("#identfiytips").attr("class","error");
//        $("#identfiytips").html("请填写身份证后4位");
//    }
//    if($("#vcode").val()==""){
//        $("#vcodetips").show();
//        $("#vcodetips").attr("class","error");
//        $("#vcodetips").html("请输入验证码");
//    }
        if($("input:checked").length==0){
            alert("只有同意服务条款协议才可注册");
            return false;
        }
//        
//        if($(".error").length>0){
//            alert("请将表单填写正确");
//            return false;
//        }
        
         return true;
//    var flag;
//    
//     if(document.getElementById("vcode").value.length!=4){checkvcode('xxxx');}
//    if($(".error").length>0||flag){
//        alert("请将表单填写正确");
//        return false;
//    }else if(!document.getElementById("tiaokuan").checked){
//        alert("只有同意服务条款协议才可注册");
//        return false;
//    }else{
//        return true;
//    }
//    return false;
}

function activateEmal(){
    showsentence('正在向服务器发送邮件，这可能需要花费你一些时间，请稍等...');
    $.ajax({
        url:'/Ajax/my/activate.aspx',
        data:'todo=activateEmal',
        type:'POST',
        dataType:'json',
        contentType: "application/x-www-form-urlencoded",
        success:function(data){
            if(data.success)
            {
                $("#sentence_content").html(data.returns);
            }else{
                $("#sentence_content").html(data.returns);
            }
        },
        error:function(xml,status){
             if(status=='error'){
                 try{
                 var json = eval('(' + xml.responseText + ')');
                 $("#sentence_content").html(json.Message+'\n'+json.StackTrace);
                 }catch(e){}
             }else{
                 $("#sentence_content").html(status);
             }
           }
    });
}

function sender(phone){
    this.scene=function(){
       var obj =  $("input[name='btnsender']");
       var total = 10;
       var interval = window.setInterval(a,1000)
       function a(){
            obj.attr("disabled",true);
            obj.attr("size","20");
            obj.val("获取验证码("+(total--)+")");
            if(total<0){
                window.clearInterval(interval);
                obj.removeAttr("disabled");
                obj.val("重发");
            }
       }
    }
    
    this.scene();
    $.ajax({
        url:'/PageService/UsersActivate.asmx/SendPhonemessage',
        data:'{phone:\''+phone+'\'}',
        type:'POST',
        dataType:'json',
        contentType: "application/json;utf-8",
        success:function(data){
              if(data.d!="success")alert(data.d);
        },
        error:function(xml,status){
             if(status=='error'){
                 try{
                 var json = eval('(' + xml.responseText + ')');
               // $("#sentence_content").html(json.Message+'\n'+json.StackTrace);
                 }catch(e){}
             }else{
              //   $("#sentence_content").html(status);
             }
           }
    });
}


//暂不激活
function unactivateEmal(){
    $.ajax({
        url:'/Ajax/my/activate.aspx',
        data:'todo=unactivateEmal',
        type:'POST',
        dataType:'json',
        success:function(data){
            if(data.success)
            {
              location.href=document.URL.match(/^http:\/\/[\w.]*/);
            }else{
                showsentence(data.returns);
            }
        }
    });
}

function showsentence(content)
{
    
	$.layerSetup({
				 id:"sentence",
				 title:'Short sentence',
				 target:window.parent,
				 cssurl:'/skin/js/Plugins/window/showwinmin1css/css.css',
				 content:content,
				 isbg:true,
				 templete:'<div class="showwint_mini_title"><span class="showwint_mini_close_btn"><a href="javascript:void(null);" class="layerclose"></a></span><span class="showwint_mini_title_content" id="@moveid@"><span id="@titleid@"></span></span></div><div class="showwint_mini_content"><div class="showwint_mini_content_content" id="@contentid@"></div><div class="btn_close"><input type="button" value="确定" name="queding" onclick="void(null)" ></div></div>'
				 });
	$.layershow();
}

function ChangeColor(id){
    $("#"+id).parent().next().css("color","#0000FF");
    $("#"+id).parent().next().css("border","solid 1px #0000FF");
}

function recover(id,bool){
    if(id!=undefined){
    
        if(bool || bool==null || bool==undefined){
            bool="right";
        }else{
            bool="error";
        }
        var obj = $("#"+id).next();
        if(obj.html()==undefined || obj.html()==null ||obj.attr("alt").length>0){
            $("#"+id).after("<img src=\"\/skin\/images\/check_"+bool+".gif\" />");
        }else{
            obj.attr("src","\/skin\/images\/check_"+bool+".gif");
        }
    }
    $("#"+id).parent().next().css("color","#666666");
    $("#"+id).parent().next().css("border","solid 0px #0000FF");
}
