﻿// JScript 文件
Ext.onReady(function(){
  Ext.QuickTips.init();
  var registerDlg;
 
  var emailTextBox1=new Ext.form.TextField({
                    fieldLabel: '电子邮箱',
                    name: 'emailTextBox1',
                    allowBlank:false,
                    maxLength:50,
                    blankText:'请输入电子邮箱',
                    width:210,
                    labelSeparator:'：',
                    vtype:'email',
                    vtypeText:'请输入有效的电子邮箱' 
                }); 
             
 var userNameTextBox1=new Ext.form.TextField({
                    fieldLabel: '用户名',
                    labelSeparator:'：',
                    name: 'userNameTextBox1',
                    allowBlank:false,
                    maxLength:50,
                    blankText:'请输入用户名',
                    width:210
                });
 
var passwordTextBox1=new Ext.form.TextField({
                    fieldLabel: '密码',
                    inputType:'password',
                    labelSeparator:'：',
                    name: 'passwordTextBox1',
                    allowBlank:false,
                    maxLength:50,
                    blankText:'请输入密码',
                    width:210
                });
          
var confirmTextBox=new Ext.form.TextField({
                    fieldLabel: '确认密码',
                    inputType:'password',
                    labelSeparator:'：',
                    name: 'confirmTextBox',
                    allowBlank:false,
                    maxLength:50,
                    blankText:'请输入确认密码',
                    width:210
                });              
 var validateTextBox=new Ext.form.TextField({
                    fieldLabel: '验证码',
                    labelSeparator:'：',
                    name: 'validateTextBox',
                    allowBlank:false,
                    maxLength:4,
                    blankText:'请输入验证码',
                    width:100
               });       
  var register=Ext.get('register');  
  register.on('click', function(e){
    if(!registerDlg){
             registerDlg = new Ext.Window({
                el:'register-div',
                layout:'form',
                width:325,
                height:240,
                closeAction:'hide',
                modal :true,
                plain: true,
                title:'注册框',
                border:false,
                bodyBorder:false,
                resizable:false,
                //html:'<div>fd<div/>',
                labelWidth:70, 
                //defaults:{bodyStyle:'padding:10px'}, 
                items:[userNameTextBox1,emailTextBox1,passwordTextBox1,confirmTextBox,{html:'<img id="validate-img" style="border-left: #CAD9EC 80px solid; border-right: #CAD9EC 365px solid;background-color: #CAD9EC;"/>',border:false},validateTextBox,{html:'<a href="Agreement.aspx" target="_blank" style="border-left: #CAD9EC 78px solid; border-top: #CAD9EC 2px solid;border-bottom: #CAD9EC 2px solid;border-right: #CAD9EC 91px solid;background-color: #CAD9EC;text-decoration: none;color:blue;">阅读爱读的服务条款和声明</a>',border:false}],// '<img id="face-img" src="Images/face/em1.gif" alt="face" style="border-left: #CAD9EC 120px solid; border-right: #CAD9EC 365px solid;background-color: #CAD9EC;" />', 
                buttons: [{
                    text:'我同意爱读的服务条款并注册',
                    handler:userRegister
                },{
                    text: '取消',
                    handler: function(){
                       registerDlg.hide();
                    }
                }]
            }); 
        
        };
   
      userNameTextBox1.reset();
      passwordTextBox1.reset();
      emailTextBox1.reset(); 
      confirmTextBox.reset();
      validateTextBox.reset();
      registerDlg.show(this);
      Ext.get('validate-img').dom.src='Gif.aspx?id='+ Math.random();  
  });
  function userRegister(){
     if(!userNameTextBox1.validate() |!emailTextBox1.validate() |!passwordTextBox1.validate() |!confirmTextBox.validate() |!validateTextBox.validate()){
            return;
      }
    if(passwordTextBox1.getValue()!=confirmTextBox.getValue()){
         Ext.MessageBox.show({
                    title: '错误提示',
                    msg: '密码和确认密码不同！',
                    buttons: Ext.MessageBox.OK,
                    animEl: 'mb9',
                    //fn: showResult,
                    icon: Ext.MessageBox.ERROR
                  });
        return; 
    }
    Ext.MessageBox.show({
                               msg: '正在注册，请等待...',
                               width:250,
                               wait:true,
                               animEl: 'mb7'
                           });
        Ext.Ajax.request({
		        url: 'data/user_register.aspx',
		        params: {name:userNameTextBox1.getValue(),email:emailTextBox1.getValue(),password:passwordTextBox1.getValue(),code:validateTextBox.getValue()},
		       
		        callback: function(options,success,response){
		           
		           
		           var oResponse = Ext.decode(response.responseText);
		           if(oResponse.success){
		              
		               document.location=oResponse.response;
		              
		              
		           }
		           else{
		              Ext.MessageBox.hide();
		              Ext.MessageBox.show({
                            title: '错误提示',
                            msg: oResponse.response,
                            buttons: Ext.MessageBox.OK,
                            animEl: 'mb9',
                            //fn: showResult,
                            icon: Ext.MessageBox.ERROR
                       });
		           }
		          
		        },
		        success:function(){
		           //Ext.MessageBox.hide();
		        },
        		failure:function(){
        		    Ext.MessageBox.show({
                    title: '错误提示',
                    msg: '通信失败！',
                    buttons: Ext.MessageBox.OK,
                    animEl: 'mb9',
                    //fn: showResult,
                    icon: Ext.MessageBox.ERROR
                  });
        		}
	          });  
  }
});