Ext.onReady(function(){ 
	Ext.QuickTips.init();
	Ext.apply(Ext.QuickTips.getQuickTip(), { showDelay: 0, trackMouse: true });
	
	var nom = new Ext.form.TextField({ renderTo: 'snom', name: 'nom', id: 'nom', allowBlank:false, maxLength:100, style:'padding:0;'});
	var prenom = new Ext.form.TextField({ renderTo: 'sprenom', name: 'prenom', id: 'prenom', allowBlank:false, maxLength:100, style:'padding:0;'});
	var societe = new Ext.form.TextField({ renderTo: 'ssociete', name: 'societe', id: 'societe', allowBlank:false, maxLength:100, style:'padding:0;'});
	var email = new Ext.form.TextField({ renderTo: 'semail', name: 'email', id: 'email', allowBlank:false, maxLength:100, style:'padding:0;', vtype:'email'});
	var msg = new Ext.form.TextArea({ renderTo: 'smessage', name: 'message', id: 'message', maxLength:300, style:'padding:0;width:573px;'});

	
	if (email_sent==true) {
		var confirmWin = new Ext.Window({ layout: 'fit', modal:true, plain:true, resizable:false, closeAction:'hide', constrain: true, autoHeight:true, width:450, 
			id:'confirmWin', title: 'Confirmation', html:'<div style="margin:2em; color:#000;"><p>Merci de votre int&eacute;r&ecirc;t pour ECOCEM France.<br />Votre demande a bien &eacute;t&eacute; envoy&eacute;e et sera trait&eacute;e dans les plus bref d&eacute;lais.</p><p>Cliquez <a href="http://www.ecocem.fr/">ici</a> pour retourner a la page d\'accueil ou <a href="javascript:closeConfirmWin();">ici</a> pour fermer cette fenetre.</p></div>'	});
		Ext.getCmp('confirmWin').show();
	}
	
});

function closeConfirmWin() {
	Ext.getCmp('confirmWin').hide();
}

function formSubmit(){
	var valid = true;
	
	if(Ext.get('nom').getValue()=='') {
		Ext.get('nom').addClass('x-form-invalid');
		valid = false;
	}
	if(Ext.get('prenom').getValue()=='') {
		Ext.get('prenom').addClass('x-form-invalid');
		valid = false;
	}
	if(Ext.get('societe').getValue()=='') {
		Ext.get('societe').addClass('x-form-invalid');
		valid = false;
	} 
	if(Ext.get('email').getValue()=='') {
		Ext.get('email').addClass('x-form-invalid');
		valid = false;
	}

	if (!valid) {
		alert('Veuillez remplir tous les champs obligatoires.');
		return false;
	} else if(Ext.get('message').getValue().length>300) {
		alert('Le champs message est limite a 300 caracteres.');
		return false;
	} else {
		return true;
	}
}


/****************************************************************************************************/
/****************************************************************************************************/

function gmapShow(animId,locType){
	var locDiv=Ext.get(animId).parent('.gmapDetails'), x, y;
	var winTitle=locDiv.child('h3').dom.innerHTML, pArr=locDiv.query('p'), 
	topContent='<h3>'+winTitle+'</h3>'+pArr[0].innerHTML+'<br>'+pArr[1].innerHTML;
	if (locType==1){ x=43.485124; y=5.361414; } else { x=53.341661; y=-6.199808; }
	if (!Ext.getCmp('gmapWin')){
		document.getElementById('map').style.display='';
		var win = new Ext.Window({ layout: 'fit', modal:true, plain:true, resizable:false, closeAction:'hide', constrain: true, autoHeight:true, width:716, 
			id:'gmapWin', title: winTitle, contentEl: 'map'	});
	} 
	try{ Ext.getCmp('gmapWin').setTitle(winTitle); Ext.getCmp('gmapWin').show(animId, function(){ loadMap(topContent, x, y); }); } 
	catch(e){ Ext.Msg.show({ title:'Modal window error', msg: e, buttons: Ext.Msg.OK, icon: Ext.MessageBox.ERROR    }); }
}

function loadMap(info, lat, long){
	if (GBrowserIsCompatible()) { //if the browser is not compatible with Google API
		var bounds = new GLatLngBounds();
		var map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GOverviewMapControl()); 	
		map.enableDoubleClickZoom();
   	map.setCenter(new GLatLng(0,0),0);	//going to dynamically set zoom to markers
		var upoint = new GLatLng(lat, long);
		var marker = new GMarker(upoint);
		GEvent.addListener(marker, "click", function(){ marker.openInfoWindowHtml(info); });
		map.addOverlay(marker);
      bounds.extend(marker.getPoint());	//set bounds according to marker coords
		map.setZoom(map.getBoundsZoomLevel(bounds)-1);	
		map.setCenter(bounds.getCenter());
		marker.openInfoWindowHtml(info);
	}
}


