OrderWin = function(rscId, rscType) {
	this.rscId = rscId;
	this.rscType = rscType;

	this.form = new Ext.FormPanel({
				xtype : 'form',
				labelAlign : 'left',
				labelWidth : 60,
				bodyStyle : 'padding:5px',
				defaultType : 'textfield',
				border : false,
				scope : this,
				items : [{
							id : 'orderWin-form-tab',
							xtype : 'tabpanel',
							plain : true,
							activeTab : 0,
							height : 230,
							defaults : {
								anchor : '90%',
								bodyStyle : 'padding:10px'
							},
							items : [{
										title : '资源信息',
										layout : 'form',
										defaults : {
											anchor : '95%'
										},
										defaultType : 'textfield',
										items : [{
													xtype : 'hidden',
													name : 'rscId',
													id : 'rscId'
												}, {
													xtype : 'hidden',
													name : 'rscType',
													id : 'rscType',
													value : this.rscType
												}, {
													id : 'rscCode',
													fieldLabel : '资源代号',
													name : 'rscCode',
													readOnly : true
												}, {
													id : 'rscName',
													fieldLabel : '资源名称',
													name : 'rscName',
													readOnly : true
												}, {
													id : 'editTime',
													fieldLabel : '更新时间',
													name : 'editTime',
													readOnly : true
												}, {
													id : 'rscDescribe',
													xtype : 'textarea',
													fieldLabel : '资源简介',
													name : 'rscDescribe',
													height : 100,
													readOnly : true
												}]
									}, {
										id : 'contactWays',
										title : '联系信息',
										layout : 'form',
										defaults : {
											anchor : '90%'
										},
										defaultType : 'textfield',
										items : [{
													id : 'customerId',
													xtype : 'hidden',
													name : 'customerId'
												}, {
													id : 'contacter',
													xtype : 'textfield',
													fieldLabel : '联系人',
													name : 'contacter',
													width : '80',
													allowBlank : false
												}, {
													id : 'areaCode',
													xtype : 'textfield',
													fieldLabel : '区号',
													name : 'areaCode',
													width : '80',
													allowBlank : false,
													regex : /^\d{3,4}$/,
													regexText : '请输入3-4位数字表示的区号'
												}, {
													id : 'phone',
													fieldLabel : '固定电话',
													name : 'phone',
													width : '200',
													allowBlank : false,
													regex : /^\d*$/,
													regexText : '只能输入数字'
												}, {
													id : 'cellphone',
													fieldLabel : '手机',
													name : 'cellphone',
													allowBlank : false,
													regex : /^\d*$/,
													regexText : '只能输入数字'
												}, {
													id : 'email',
													fieldLabel : 'Email',
													name : 'email',
													allowBlank : false,
													vtype : 'email'
												}, {
													id : 'otherContactWay',
													fieldLabel : 'QQ号码',
													name : 'otherContactWay'
												}]
									}, {
										id : 'memo-panel',
										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 : 'getOrderDeclaration.do',
												nocache : true,
												scripts : true
											}
										}
									}]
						}],
				bbar : [{
							xtype : 'tbfill'
						}, {
							xtype : 'tbseparator'
						}, {
							id : 'orderWin-btnSubmit',
							text : '提交',
							scope : this,
							iconCls : 'cx-submit-3',
							formBind : true,
							type : 'submit',
							handler : this.doSubmit
						}, {
							xtype : 'tbseparator'
						}, {
							text : '关闭',
							iconCls : 'cx-close-2',
							scope : this,
							handler : function() {
								this.close();
							}
						}]
			});

	OrderWin.superclass.constructor.call(this, {
				id : 'order-window-panel',
				title : '海巍科技 - 资源订购',
				layout : 'fit',
				autoScroll : true,
				height : 300,
				width : 400,
				scope : this,
				items : this.form,
				listeners : {
					scope : this,
					'activate' : function(p) {
						Ext.getCmp(this.id).getEl().mask('正在加载数据, 请稍候...');
					}
				}
			});

	// 初始化表单内容
	this.initForm(this.rscId);
};

Ext.extend(OrderWin, Ext.Window, {
	/**
	 * 初始化表单内容，将数据库中已经存贮的信息提出并显示
	 */
	initForm : function(rscId) {
		this.store = new Ext.data.Store({
					proxy : new Ext.data.HttpProxy({
								url : 'granted/rscCenter/getRscOrderInfo.do'
							}),
					reader : new Ext.data.JsonReader({
								root : 'record',
								totalProperty : 'totalProperty'
							}, ['customerId', 'contacter', 'areaCode', 'phone',
									'cellphone', 'email', 'otherContactWay',
									'rscId', 'rscCode', 'rscType', 'rscName',
									'editTime', 'rscDescribe'])
				});
		
		this.store.load({
			params : {
				rscType : this.rscType,
				rscId : this.rscId
			},
			scope : this,
			callback : function(r, option, success) {
				if (success && r.length > 0) {
					this.form.findById('rscId').setValue(r[0].data.rscId);
					this.form.findById('rscCode').setValue(r[0].data.rscCode);
					this.form.findById('rscName').setValue(r[0].data.rscName);
					this.form.findById('editTime').setValue(r[0].data.editTime);
					this.form.findById('rscDescribe').setValue(r[0].data.rscDescribe);
					this.form.findById('customerId').setValue(r[0].data.customerId);
					this.form.findById('contacter').setValue(r[0].data.contacter);
					this.form.findById('email').setValue(r[0].data.email);
					this.form.findById('areaCode').setValue(r[0].data.areaCode);
					this.form.findById('phone').setValue(r[0].data.phone);
					this.form.findById('otherContactWay').setValue(r[0].data.otherContactWay);
					this.form.findById('cellphone').setValue(r[0].data.cellphone);
					Ext.getCmp('orderWin-form-tab').setActiveTab('contactWays');
				} else {
					showError('初始化订单错误, 可能您已登录超时, 请重新登录后再进行操作!');
					this.close();
				}
				Ext.getCmp(this.id).getEl().unmask();
			}
		});
	},

	// 提交订单
	doSubmit : function() {
		if (!this.form.form.isValid()) {
			Ext.MessageBox.show({
						title : '消息',
						msg : '信息尚未填写完整, 请填写!',
						buttons : Ext.Msg.OK,
						icon : Ext.MessageBox.INFO
					})
			return;
		}
		// 提交到服务器操作
		this.form.form.doAction('submit', {
					url : 'granted/rscCenter/doOrderSubmit.do',
					waitMsg : '正在提交数据, 请稍候...',
					waitTitle : '提示',
					scope : this,
					success : function(form, action) {
						if (action.result.success) {
							Ext.MessageBox.show({
										title : '消息 -- 订单提交成功',
										msg : '<BR>感谢您订购我们的资源, 我们将尽快处理您的订单!',
										buttons : Ext.Msg.OK,
										icon : Ext.MessageBox.INFO
									});
							this.close();
						} 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
								});
					}
				});
	}
});