document
		.write('<script src="/xsl/catalog/captcha.js" type="text/javascript"></script>');

Ext.form.Field.prototype.msgTarget = 'side';

Ext.ns("Opinion");

Opinion.Combo = Ext.extend(Ext.form.ComboBox, {
			initEvents : function() {
				Opinion.Combo.superclass.initEvents.call(this);
				if (this.valueField) {
					this.on("blur", this.restoreSelected, this);
					this.el.on("keyup", function(e) {
								if (e.getKey() == e.ESC)
									this.restoreSelected();
							}, this);
				}
			},
			restoreSelected : function() {
				if (this.lastSelectionText) {
					this.el.dom.value = this.lastSelectionText;
					this.clearInvalid();
				}
			}
		});
Ext.reg("combo", Opinion.Combo);

Opinion.Panel = Ext.extend(Ext.form.FormPanel, {
			balls : [5, 4, 3, 2, 1],
			constructor : function(c) {
				Opinion.Panel.superclass.constructor.call(this, Ext.apply(c, {
									title : "Оставить свой отзыв",
									standardSubmit : true,
									bodyStyle : "padding: 5px 10px",
									items : [c.hotelId ? {
												name : "hotel",
												xtype : "hidden",
												value : c.hotelId
											} : {
												fieldLabel : "Гостиница",
												hiddenName : "hotel",
												xtype : "combo",
												minChars : 2,
												allowBlank : false,
												displayField : "text",
												valueField : "id",
												store : new Ext.data.JsonStore({
															url : "/public/booking/common/opinions/hotels.jsp",
															fields : ["id", "text"]
														}),
												width : 200
											}, {
												fieldLabel : "Уровень отеля",
												hiddenName : "comfort",
												xtype : "combo",
												width : 100,
												editable : false,
												store : this.balls
											}, {
												fieldLabel : "Уровень обслуживания",
												hiddenName : "service",
												xtype : "combo",
												width : 100,
												editable : false,
												store : this.balls
											}, {
												fieldLabel : "Комментарий к оценке",
												name : "text",
												xtype : "textarea",
												allowBlank : false,
												width : 200
											}, {
												fieldLabel : "Код",
												name : "captcha",
												xtype : "captcha",
												context : "/catalog",
												allowBlank : false,
												width : 200
											}],
									labelAlign : "top",
									buttons : [{
												text : "Отправить",
												handler : function() {
													this.getForm().submit();
												},
												scope : this
											}]
								}));
				this.getForm().el.dom.action = "/catalog/post.jsp";
			}
		});

Ext.onReady(function() {
			new Opinion.Panel({
						renderTo : "opinions",
						hotelId : options.hotel
					});
		});
