Ext.BLANK_IMAGE_URL = '/ext/resources/images/default/s.gif';

Ext.onReady(function(){
										 
var m = 'contact';
m += '@';
m += 'connectedobject';
m += '.';
m += 'com';

m = '<a href="mailto:'+m+'">'+m+'</a>';

Ext.get('ml_contact').update(m);

var txt_mail = new Ext.form.TextField({
        id: 'txt_mail',
        vtype: 'email',
				allowBlank: false,
				emptyText: 'Your email',
				invalidText: 'Invalid email',
				width: 180,
				enableKeyEvents: true,
				renderTo: 'email_sub'
																			});

txt_mail.on('keypress', function(t, e) 
	{
		if (e.keyCode == e.ENTER || e.keyCode == e.RETURN)
		{
			addMail();
		}
	});

addQuest = function()
{
	var txt_mail = Ext.getCmp('txt_mail').getValue();
	var email_type = '';
	if (Ext.getCmp('rd_1').checked)
	{
		email_type = Ext.getCmp('rd_1').inputValue;
	}
	else if (Ext.getCmp('rd_2').checked)
	{
		email_type = Ext.getCmp('rd_2').inputValue;
	}
	else if (Ext.getCmp('rd_3').checked)
	{
		email_type = Ext.getCmp('rd_3').inputValue;
	}
	else
	{
		Ext.Msg.show({
		 title:"Question"
		 ,msg:"Please make a choice"
		 ,modal:true
		 ,icon:Ext.Msg.ERROR
		 ,buttons:Ext.Msg.OK
		 });
	}
	
	if (email_type != '')
	{
		Ext.Ajax.request(
		{
				url: "subscribe.php?email="+txt_mail+"&email_type="+email_type,
				method: 'GET',
				disableCaching: false
		});
		setMsg('<br><br>See you soon !');
		Ext.get('btn_sub').hide();
	}
	
}

setMsg = function(more_text)
{
	var html = 'Thanks, we will contact you soon on your email <font color="#9CCD09"><b>'+txt_mail.getValue()+'</b></font>.';

	html += more_text;
	Ext.get('msg_sub').update(html)
}

addMail = function()
{
	var txt_mail = Ext.getCmp('txt_mail');
	if (txt_mail.isValid())
	{
		Ext.Ajax.request(
		{
				url: "subscribe.php?email="+txt_mail.getValue(),
				method: 'GET',
				disableCaching: false
		});
		
		//Ext.MessageBox.alert("Confirmation", "Merci, nous ne manquerons pas de vous tenir informé sur l'évolution de notre produit.");
		txt_mail.hide();
		Ext.getCmp('btn_mail').hide();
		setMsg('<br><br>In order to give you a more accurate answer, please specify your function:');
		
		new Ext.form.Radio({
			 id: 'rd_2',
			 name: 'rd',
			 labelSeparator: '', // pour éviter le ':' à gauche
			 inputValue: 'particulier',
			 checked: false,
			 boxLabel: 'Individual',
			 renderTo: 'btn_sub'
			 });
		
		new Ext.form.Radio({
			 id: 'rd_1',
			 name: 'rd',
			 labelSeparator: '', // pour éviter le ':' à gauche
			 inputValue: 'presse',
			 checked: false,
			 boxLabel: 'Press',
			 renderTo: 'btn_sub'
			 });

		new Ext.form.Radio({
			 id: 'rd_3',
			 name: 'rd',
			 labelSeparator: '', // pour éviter le ':' à gauche
			 inputValue: 'professionel',
			 checked: false,
			 boxLabel: 'Professional',
			 renderTo: 'btn_sub'
			 });
		
		var btn_mail = new Ext.Button({
				id: 'btn_quest',
				text: 'OK',
				handler: addQuest,
				style: 'margin-top:10px;border:none;',
				renderTo: 'btn_sub'
				});
	}
	else
	{
		  Ext.Msg.show({
		 title:"Error"
		 ,msg:"Invalid email"
		 ,modal:true
		 ,icon:Ext.Msg.ERROR
		 ,buttons:Ext.Msg.OK
		 });
		//Ext.MessageBox.alert(, "Cet email n'est pas valide.");
	}
}

var btn_mail = new Ext.Button({
				id: 'btn_mail',
				text: 'OK',
				handler: addMail,
				renderTo: 'btn_sub'
															});







});
