var ajaxEnvoiAmi = function (idAnnonce, email, texte){
	Ext.Ajax.request({
		url : '/Message/Mail/Ami/' , 
		params : { email : email, texte : texte, idAnnonce: idAnnonce },
//		method: 'POST',
		success: function ( result, request ) { 
			Ext.MessageBox.alert('Succes', result.responseText); 
		} ,
		failure: function ( result, request) { 
			Ext.MessageBox.alert('Echec', result.responseText); 
		} 
	});
}

var afficheEnvoiAmi =function (idAnnonce){
	Ext.DomHelper.insertFirst(Ext.getBody(),{
	 			id:"hello-win",
	 			tag : "div",
	 			cls : 'x-hidden', 
	 			children : {tag : "div", cls : "x-window-header" , html : "Envoyer cette annonce &agrave; un ami"}
	 		});
    var win;
    //msgCt = Ext.DomHelper.insertFirst(document.body, {id:'msg-div'}, true);
    //var button = Ext.get('show-btn');
 
    //button.on('click', function(){
    

        // create the window on the first click and reuse on subsequent clicks
       win = new Ext.Window({
                el:'hello-win',
				layout:'form',
                width:350,
                height:350,
//                closeAction:'hide',
//                plain: true,
               
               items: [
               		new Ext.form.TextField({
               			fieldLabel : "Adresse mail ",
               			id : "EnvoiAmi"+idAnnonce+"_mail",
               			width: 220, 
               			allowBlank:false, 
               			style: "margin-top: 5px"
               		})
               ,
               		new Ext.form.TextArea({
               			fieldLabel : "Votre message ",
               			id : "EnvoiAmi"+idAnnonce+"_texte",  
               			width: 220, 
               			height: 140
               		})       
               	,
    	           	new Ext.Panel({
	    	        title: 'Le code',
		            width: 60,
		            height: 50,
		            autoLoad:
            		{
               		url: '/Message/Index/getCaptchaImageMessage'
               		}
         			})
               	,
               		new Ext.form.TextField({
               			fieldLabel : "Tapez le code ",
               			id : "lecode",
               			width: 220, 
               			allowBlank:false, 
               			style: "margin-top: 5px"
               		})
                ],
               
                buttons: [{
                    text:'Envoyer', 
                    handler: function(){
                    	ajaxEnvoiAmi( idAnnonce, Ext.get("EnvoiAmi"+idAnnonce+"_mail").getValue(), Ext.get("EnvoiAmi"+idAnnonce+"_texte").getValue());
                    	win.close();
                    }
                   
                },{
                    text: 'Annuler',
                    id : 'quitButton',
                   	handler: function(){
                   		win.close();
                   }
                }]
            });
      win.show();
    //});
}
