Ext.onReady(function() {
    
    function showQuickSearchWindow() {
        var windowId = 'quickSearchWindow';
        window = Ext.WindowMgr.get(windowId)
        if (window == null) {
          var window = new Ext.Window({
              title: 'Otsing',
              border: false,
              width: 300,
              height: 200,
              html: '<iframe style="width: 100%; height: 100%;" src="/geoweb/quicksearch/?_popup=quickSearchWindow"></iframe>',
              id: windowId
          });
          window.show();
        }
    }
    
    var menuItem = new Ext.menu.Item({text: 'Kiirotsing...', handler: showQuickSearchWindow});
    GUI.searchMenu.addItem(menuItem);
	
	GUI.quickSearch = function(form) {
		var windowId = 'searchResultsWindow';
		var w = Ext.WindowMgr.get(windowId)
		if (w == null) {
		  w = new Ext.Window({
			  title: 'Otsingutulemused',
			  border: false,
			  width: 320,
			  //autoWidth: true,
			  //autoHeight: true,
			  id: windowId,
			  autoScroll: true
		  });
		}
		
		Ext.Ajax.request({
		  url: '/geoweb/quicksearch/results/',
		  scope: this,
		  form: form,
		  method: 'POST',
		  success: function(response, options) {
			//var html = response.responseText;
			//w.show();
			//w.body.update(html);
			  var json = Ext.decode(response.responseText);
			  if (json.jsondata) {
				parent.GUI.showComplexSearchResultsWindow(json.jsondata);
			  }
		  },
		  failure: function(response, options) {
			/*var html = response.responseText;
			w.show();
			w.body.update(html);*/
		  }
		  /*failure: function(response, options) {
			Ext.MessageBox.show({
				title: 'Error',
				msg: 'Could not complete request',
				buttons: Ext.MessageBox.OK,
				icon: Ext.MessageBox.ERROR
			});
		  }*/
		});
	}
});
