/*
 * Ext JS Library 2.0.1
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */
Ext.onReady(function(){




    Ext.QuickTips.init();

    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';

    var bd = Ext.getBody();
	var aLocationForm=fReturnaLocationForm();
    /*
     * ================  Form 2  =======================
     */
    //bd.createChild({tag: 'h2', html: 'Form 2 - Adding fieldsets'});
	var aTypesBiens=fGetDynamicArray({grid:'typebien',startLoad:true,fCallBack:function(){}});
	aTypesBiens.addListener({
			'beforeload' :testFn ,
			 scope: this
		});
	

    var fsf = new Ext.FormPanel({
		id:"formHome",
        labelWidth: 75, 
        url:'save-form.php',
        frame:true,
        title: 'Recherche de bien :',
        bodyStyle:'padding:5px 5px 0',
        width: 570,
		items: aLocationForm,
		//
        buttons: [{
            text: 'Rechercher',
			disabled:true,
			id:'formHomeSubmit'
        }/*{
            text: 'Annuler'
        }*/]
    });


    fsf.render('mainForm');
	formHomeSubmit=Ext.getCmp('formHomeSubmit');
	formHomeSubmit.on('click',fnSubmitHome);
	var oElToHide=Ext.get('Etages');
	oElToHide.setStyle('display','none');
	fHideComponents(['ElementsQualitatifs','Exterieur','Chauffage','Destination','NbBedroom','NbRoom','TextCriteresOptionels']);
	fHideParents(['pricevente2','priceachat2','pricevente1','priceachat1','priceachat2','pricevente1','priceachat1','surfaceHabitable2','surfaceLand2','surfaceLiving2','surfaceLand','surfaceLiving','surfaceHabitable','pricelocataire1','pricelocataire2']);
	var oFormHomeTabpanel=Ext.getCmp('FormHomeTabpanel');
	
	oFormHomeTabpanel.on('tabchange',function(tabpanel,tab){
		var oTypeTransactionField=Ext.getCmp('typeTransactionField');	
		oTypeTransactionField.setValue(tab.id);
		sTypeTransaction=tab.id;
		switch(sTypeTransaction){
			case 'BienLocation':
				fHideParents(['pricevente2','priceachat2','pricevente1','priceachat1','pricelocataire1','pricelocataire2'])
				fHideParents(['pricelocation2','pricelocation1','pricecharges2','pricecharges1'],false)
			break;
			case 'BienVente':
				fHideParents(['priceachat2','priceachat1','pricelocation2','pricelocation1','pricecharges2','pricecharges1','pricelocataire1','pricelocataire2'])
				fHideParents(['pricevente2','pricevente1'],false)
			break;
			case 'BienAcheteur':
				fHideParents(['pricevente2','pricelocation2','pricevente1','pricelocation1','pricecharges2','pricecharges1','pricelocataire1','pricelocataire2'])
				fHideParents(['priceachat2','priceachat1'],false)
			break;
			case 'BienLocataire':
				fHideParents(['pricevente2','priceachat2','pricevente1','priceachat1','pricelocation1','pricecharges2','pricecharges1'])
				fHideParents(['pricelocataire1','pricelocataire2'],false)
			break;
		}
	})
   
});