function getSearchForm(obj) {

	var fieldName = getField('name', 'Név');
	var btnsearch = new Ext.Panel({
				//	layout: 'column',
					region : 'east',
//					anchor:'100%',
					width : 80,
					style : 'background: #FFF; align: center; padding:5px 2px 5px 0px',
					border : false,
					items : [{
							xtype: 'button',
							id: 'btnsearchid',
							minWidth: 65,
							iconCls :  'ok',
							formBind: false,
							text: 'Keresés',
							handler : clickSearchBtn
						}]
				});
	var btnsql = getCenteredButton('Szűrőfeltétel', 160, 'btnsql', showSQLwin, 'btnsqlid', false);
	
	var frmsearch = new Ext.form.FormPanel({
		border : false,
		//title : 'formsearch',
		height : 32,
		region : 'north',
   // bodyStyle : 'align: center; padding:5px 5px 5px 5px',
		items:[{
			layout:'border',
			height : 32,
			anchor : '100%',			
			border : false,
			items:[{
				region: 'center',
				layout : 'fit',
				border : false,
				bodyStyle : 'align: center; padding:5px 5px 5px 5px',
				items:[fieldName]
			},
			btnsearch]
		},
		btnsql]
	});

//	frmsearch.add(btnsearch);
	
/*	var btnmap = getCenteredButton('Térképről', 160, 'btnmap', clickMapBtn, 'btnmapid', false);
	frmsearch.add(btnmap);
	
	var btnsql = getCenteredButton('Szűrőfeltétel', 160, 'btnsql', showSQLwin, 'btnsqlid', false);
	frmsearch.add(btnsql);
*/
	frmsearch.setHeight(70);
			
	return new Ext.Panel({
				id : 'searchpanel',
				title : 'Keresés',
				layout : 'border',
				iconCls : 'search',
				border : false,
				defaultType : 'panel',
				items : [ frmsearch,
				  {id:'sep', region : 'center',layout : 'fit', border: false}
					]
			});
}


function getCenteredButton(caption, minwidth, iconcls, clicklistener, buttonid, validate) {
	var p = new Ext.Panel({
					layout: 'column',
					anchor:'100%',
					border : false,
					defaultType: 'panel',
					items : [{
						columnWidth :0.5,
					  border:false,
						height : 35
					},{
						width : minwidth + 5,
						border : false,
						style : 'align: center; text-align: center',
						items: [{
							xtype: 'button',
							id: buttonid,
							minWidth: minwidth,
							iconCls : iconcls,
							formBind: validate,
							text: caption,
							handler : clicklistener
						}]
					}, {
						columnWidth :0.5,
						border: false
					}]
				});
	return p;
}

function getField(fname, fcaption) {
    var f = new Ext.form.TextField({
                        hideLabel : true,
                        id : 'search'+fname,
                        name: fname,
						emptyText : 'Kereséshez adjon meg kulcsszót...',
                        anchor: '100%',  // anchor width by percentage
                        enableKeyEvents : true,
                        listeners : {keydown : fieldKeyDown}
                    });
    return f;
}

function fieldKeyDown(textfield, event){
  if (event.getKey()==Ext.EventObject.ENTER) {
  	var fn = textfield.getName();
  	if (fn=='name')
  		searchHidak(textfield.getValue(), '','');
  	else if (fn=='sql')
  		searchHidak('', '', textfield.getValue());
  }
}

function clickSearchBtn() {
	var nev = Ext.getCmp('searchname').getValue();
	searchHidak(nev, '', '');
}	

function clickMapBtn() {

	  var g = Ext.getCmp('searchresultgrid');
	   var p = Ext.getCmp('sep');
	
	  if (g == undefined) {
	    g = getSearchResultPanel();
	    p.add(g);
	    
	    p.doLayout(true);
	  }
	  
	  Ext.Ajax.request({
	    url: 'phpk/searchhid.php',
	    
	    success: function(response, options) {
	      var gx = p.findById('searchresultgrid');
			  gx.store.load({
	        params: {
	          "start": 0,
	          "limit": 100
	        }
	      });
				var msg = p.findById('searchmsg');
				var bar = p.findById('searchbar');
				msg.body.update('A térképi nézet szerinti keresés eredménye: ');
				msg.setVisible(true);
				msg.setHeight(15);
				bar.setHeight(60);
				p.doLayout();
				
	    },
	    params: {
				"map": 1,
	      "ulx": map.getBounds().getSouthWest().lat(),
	      "uly": map.getBounds().getNorthEast().lng(),
	      "brx": map.getBounds().getNorthEast().lat(),
				"bry": map.getBounds().getSouthWest().lng()
	    }
  	});
		
		var sp = Ext.getCmp('searchpanel');
		sp.expand();
}

function searchHidak(nev, hely, sql) {
  var g = Ext.getCmp('searchresultgrid');
  var p = Ext.getCmp('sep');
  var htmldesc="";
	if (nev!='') {
		htmldesc = 'A "<span style="color: #007700; font-style:bold">'+nev/*.substr(0,Math.min(nev.length, 20))*/+'</span>" kifejezésre keresés eredménye:';
	} else if (sql!='') {
		htmldesc = 'A "<span style="color: #007700; font-style:bold">'+sql/*.substr(0,Math.min(sql.length, 20))*/+'</span>" feltétel szerinti szűrés eredménye:';
	}
	
  if (g == undefined) {
    g = getSearchResultPanel();
    
    p.add(g);
    
    p.doLayout(true);
  }
  Ext.Ajax.request({
    url: 'phpk/searchhid.php',
    
    success: function(response, options) {
      var gx = p.findById('searchresultgrid');
      gx.store.load({
        params: {
          "start": 0,
          "limit": 100
        }
      });
		var msg = p.findById('searchmsg');
		var bar = p.findById('searchbar');
		msg.setHeight(15);
		bar.setHeight(60);
		if (htmldesc != '') {
			msg.body.update(htmldesc);
			msg.setVisible(true);
			if (htmldesc.length > 105) {			
				msg.setHeight(30);
				bar.setHeight(75);
			}
			if (htmldesc.length > 150) {
				msg.setHeight(45);
				bar.setHeight(90);
			}
		} 
		else {
			msg.body.update('A keresés eredménye: ');
		}
		p.doLayout();
    },
    params: {
      "map": 0,
      "nev": nev,
      "hely": hely,
      "sql": sql
    }
  })
};

