RegistWindow = function() {
	this.registPanel = new Ext.FormPanel({
		xtype : 'form',
		labelAlign : 'top',
		title : '基本信息',
		bodyStyle : 'padding:5px',
		scope : this,
		items : [{
			xtype : 'panel',
			layout : 'column',
			border : false,
			scope : this,
			items : [{
						columnWidth : .5,
						layout : 'form',
						border : false,
						scope : this,
						defaultType : 'textfield',
						defaults : {
							anchor : '90%'
						},
						items : [{
									id : 'logName',
									fieldLabel : '用户名*',
									allowBlank : false,
									blankText : '用户名必须填写',
									maxLength : 10,
									name : 'logName',
									validationEvent : 'change',
									validateOnBlur : false,
									scope : this,
									validator : this.isValidateLogName
								}, {
									id : 'logPwd',
									fieldLabel : '密码*',
									allowBlank : false,
									blankText : '密码必须填写',
									inputType : 'password',
									name : 'logPwd',
									anchor : '90%'
								}]
					}, {
						columnWidth : .5,
						layout : 'form',
						border : false,
						defaultType : 'textfield',
						defaults : {
							anchor : '90%',
							scope : this
						},
						items : [{
									id : 'productSn',
									fieldLabel : '产品序列号*',
									allowBlank : false,
									blankText : '产品序列号必须填写',
									name : 'productSn',
									anchor : '90%',
									validationEvent : 'change',
									validateOnBlur : false,
									scope : this,
									validator : this.isValideSn
								}, {
									id : 'cuserpassword',
									inputType : 'password',
									fieldLabel : '确认密码*',
									name : 'cuserpassword',
									allowBlank : false,
									blankText : '确认密码不能为空！',
									invalidText : '两次密码不一致！',
									validator : function() {
										if (Ext.get('logPwd').dom.value == Ext
												.get('cuserpassword').dom.value)
											return true;
										return false;
									}
								}]
					}]
		}, {
			id : 'contactWays',
			xtype : 'tabpanel',
			plain : true,
			activeTab : 0,
			height : 285,
			defaults : {
				bodyStyle : 'padding:5px'
			},
			items : [{
						title : '联系信息A',
						layout : 'form',
						defaults : {
							anchor : '80%'
						},
						defaultType : 'textfield',
						items : [{
									fieldLabel : '单位名称*',
									name : 'userName',
									allowBlank : false
								}, {
									fieldLabel : '联系地址*',
									name : 'address',
									allowBlank : false
								}, {
									fieldLabel : '邮政编码*',
									name : 'postcode',
									allowBlank : false
								}, {
									fieldLabel : '联系人*',
									name : 'contacter',
									allowBlank : false
								}, {
									fieldLabel : '身份证',
									name : 'idCardNo'
								}]
					}, {
						title : '联系信息B',
						layout : 'form',
						defaults : {
							anchor : '80%'
						},
						defaultType : 'textfield',
						items : [{
									id : 'ok',
									xtype : 'panel',
									layout : 'column',
									border : false,
									scope : this,
									items : [{
												columnWidth : .30,
												layout : 'form',
												border : false,
												items : {
													xtype : 'textfield',
													fieldLabel : '区号*',
													name : 'areaCode',
													width : '80',
													allowBlank : false,
													maxLength : 4,
													regex : /^\d{3,4}$/,
													regexText : '请输入3-4位数字表示的区号'
												}
											}, {
												columnWidth : .70,
												layout : 'form',
												border : false,
												items : {
													xtype : 'textfield',
													fieldLabel : '固定电话*',
													labelSeparator : '',
													name : 'phone',
													width : '200',
													allowBlank : false,
													regex : /^\d*$/,
													regexText : '只能输入数字'
												}
											}]
								}, {
									fieldLabel : '手机*',
									name : 'cellphone',
									allowBlank : false,
									regex : /^\d*$/,
									regexText : '只能输入数字'
								}, {
									fieldLabel : 'Email*',
									name : 'email',
									allowBlank : false,
									vtype : 'email'
								}, {
									fieldLabel : 'QQ号码',
									name : 'otherContactWay'
								}]
					}, {
						cls : 'x-plain',
						title : '其它说明',
						layout : 'fit',
						items : {
							xtype : 'textarea',
							name : 'memo'
						}
					}, {
						id : 'protocle',
						cls : 'x-plain',
						title : '注册协议',
						layout : 'fit',
						items : {
							xtype : 'panel',
							autoScroll : true,
							autoLoad : {
								url : 'getRegistProtocle.do',
								nocache : true,
								scripts : true
							}
						}
					}]
		}],
		bbar : [{
					xtype : 'tbfill'
				}, {
					xtype : 'tbseparator'
				}, {
					text : '同意注册协议, 注册',
					scope : this,
					iconCls : 'cx-submit-3',
					formBind : true,
					type : 'submit',
					handler : this.doRegister
				}, {
					xtype : 'tbseparator'
				}, {
					text : '关闭',
					iconCls : 'cx-close-2',
					scope : this,
					handler : function() {
						this.close();
					}
				}]
	});

	RegistWindow.superclass.constructor.call(this, {
				id : 'regist-panel',
				title : '客户注册',
				layout : 'fit',
				autoScroll : true,
				height : 500,
				width : 400,
				scope : this,
				items : this.registPanel
			});

	// 初始化ToolTips提示
	this.on('show', this.initTips);
};

Ext.extend(RegistWindow, Ext.Window, {
			/**
			 * 初始化提示信息
			 */
			initTips : function() {
				new Ext.ToolTip({
					target : 'logName',
					html : '不超过10个汉字，或20个字节(数字，字母和下划线)',
					trackMouse : true
				});
				new Ext.ToolTip({
					target : 'logPwd',
					html : '最少4个字符，不超过16个字符(数字，字母和下划线)',
					trackMouse : true
				});
				new Ext.ToolTip({
					target : 'productSn',
					html : '您购买的产品包装盒上粘贴的产品序列号（xxxx-xxxxxxxxxx）或项目工程量清单管理注册码',
					trackMouse : true
				});
				new Ext.ToolTip({
					target : 'contactWays',
					html : '请如实详尽填写, 以便我们向您提供优质周到的服务...',
					trackMouse : true
				});
			},

			/**
			 * 判断用户输入的是否是一个合法的用户名
			 * 
			 * @param {}
			 *            value
			 * @return {Boolean}
			 */
			isValidateLogName : function(value) {
				if (value == null || value.length <= 0) {
					return false;
				}
				Ext.Ajax.request({
					url : 'isValidateLogName.do',
					params : {
						logName : value
					},
					scope : this,
					success : function(response, options) {
						if (response.responseText != '') {
							var rst = Ext.util.JSON
									.decode(response.responseText);
							if (rst && rst.success) {
							} else {
								this.markInvalid('该用户名已经被使用, 请重新输入.');
							}
						}
					},
					failure : function(response, options) {
					}
				});
				return true;
			},

			/**
			 * 判断用户输入的序列号是否合法
			 * 
			 * @param {}
			 *            value
			 * @return {Boolean}
			 */
			isValideSn : function(value) {
				Ext.Ajax.request({
					url : 'isValideSn.do',
					params : {
						sn : value
					},
					scope : this,
					success : function(response, options) {
						if (response.responseText != '') {
							var rst = Ext.util.JSON
									.decode(response.responseText);
							if (rst && rst.success) {
							} else {
								this.markInvalid(rst.message);
							}
						}
					},
					failure : function(response, options) {
					}
				});
				return true;
			},

			/**
			 * 提交注册表单
			 */
			doRegister : function() {
				if (!this.registPanel.form.isValid()) {
					Ext.MessageBox.show({
						title : '消息',
						msg : '注册信息尚未填写完整, 请填写!',
						buttons : Ext.Msg.OK,
						icon : Ext.MessageBox.INFO
					})
					return;
				}
				// 提交到服务器操作
				this.registPanel.form.doAction('submit', {
							url : 'cstRegister.do',
							waitMsg : '正在提交数据, 请稍候...',
							waitTitle : '提示',
							scope : this,
							success : function(form, action) {
								if (action.result.success) {
									Ext.MessageBox.show({
										title : '消息',
										msg : '注册成功!',
										buttons : Ext.Msg.OK,
										icon : Ext.MessageBox.INFO
									});
								} else {
									Ext.MessageBox.show({
										title : '错误',
										msg : action.result.message,
										buttons : Ext.Msg.OK,
										icon : Ext.MessageBox.ERROR
									});
								}
							},
							failure : function(form, action) {
								Ext.MessageBox.hide();
								Ext.MessageBox.show({
									title : '错误',
									msg : (Ext.isEmpty(action.result))
											? '与服务器连接失败, 请稍候再试...'
											: action.result.message,
									buttons : Ext.Msg.OK,
									icon : Ext.MessageBox.ERROR
								});
							}
						});
			}
		});