// ************************************* Fonctions pour le rollover des images du menu *************************************************************
function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

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

// *****************************************************      GOOGLE MAP      ******************************************************************


	//-- Ici les coordonnes sous forme de tableau
	var Param = [[48.168984,6.441692]];
	//-- Meme Zoom pour tous
	var Zoom = 10;
	//-- Variable globale pour l'objet GMAP2 sous forme de tableau
	var map=[];

	var marker=[];
	//-- Nbr de map a creer
	var Nbr_Map = Param.length;
	//-- Variable globale pour les marqueurs sous forme de tableau
	var marker = new Array(); 

	//-------------------
	function initialize(tabadresse)
	{
	  //-- Teste si le navigateur est compatible avec l'API Gmaps
	
		if (GBrowserIsCompatible() && document.getElementById('map')) {
				//-- Creation des objets princiapux
				map = new GMap2( document.getElementById('map'));
				//-- personnalisation	
				map.addControl(new GSmallMapControl());
				map.addControl(new GMapTypeControl());
				map.setCenter(new GLatLng(Param[0][0],Param[0][1]), Zoom);
			
			for(var i = 0; i <Nbr_Map; i++)
			{	
				//-- Position du point
				var Pos = new GLatLng( Param[i][0], Param[i][1]); 
				
				
				tinyIcon = new GIcon();
				tinyIcon.image = "images/test.png";
				tinyIcon.shadow = "images/ombretest.png";
				tinyIcon.iconSize = new GSize(12, 20);
				tinyIcon.shadowSize = new GSize(22, 20);
				tinyIcon.iconAnchor = new GPoint(6, 20);
				tinyIcon.infoWindowAnchor = new GPoint(5, 1);
				 
				// Set up our GMarkerOptions object literal
				markerOptions = { icon:tinyIcon };
				
				marker[i] = new GMarker( Pos, markerOptions);
				//-- Ajout du marqueur
				map.addOverlay(marker[i]); 
			}
			
			GEvent.addListener(marker[0], "click", function() {
					marker[0].openInfoWindowHtml(
					"<table><tr><td align=\"center\" width=\"150\" style=\"color:#000\"><img src=\"images/logo_contact.jpg\" title=\""+tabadresse[0][0]+"\"/></td></tr><tr><td align=\"center\" width=\"150\" style=\"color:#000\"><b>"+tabadresse[0][0]+"<\/b><br \/>"+tabadresse[0][1]+"<br \/>"+tabadresse[0][2]+" "+tabadresse[0][3]+"<br \/><br \/>Tél. <b>"+tabadresse[0][4]+"</b><br \/>Fax. "+tabadresse[0][5]+"<\/td><\/tr><\/table>");
					
				});

				map.openInfoWindowHtml(map.getCenter(),
			"<table><tr><td align=\"center\" width=\"150\" style=\"color:#000\"><img src=\"images/logo_contact.jpg\" title=\""+tabadresse[0][0]+"\"/></td></tr><tr><td align=\"center\" width=\"150\" style=\"color:#000\"><b>"+tabadresse[0][0]+"<\/b><br \/>"+tabadresse[0][1]+"<br \/>"+tabadresse[0][2]+" "+tabadresse[0][3]+"<br \/><br \/>Tél. <b>"+tabadresse[0][4]+"</b><br \/>Fax. "+tabadresse[0][5]+"<\/td><\/tr><\/table>");

		}
	} 

function mounvementMap(tabadresse,pos,i)
{
	if (GBrowserIsCompatible() && document.getElementById('map')) {
		map = new GMap2( document.getElementById('map'));
		//-- personnalisation	
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(pos[0],pos[1]), 16);
		
		var Pos = new GLatLng( pos[0], pos[1]); 
		marker[i] = new GMarker( Pos, markerOptions);
		//-- Ajout du marqueur
		map.addOverlay(marker[i]); 
		
		GEvent.addListener(marker[i], "click", function() {
						marker[i].openInfoWindowHtml(
					"<table><tr><td align=\"center\" width=\"150\" style=\"color:#000\"><img src=\"images/logo_contact.jpg\" title=\""+tabadresse[0][0]+"\"/></td></tr><tr><td align=\"center\" width=\"150\" style=\"color:#000\"><b>"+tabadresse[i][0]+"<\/b><br \/>"+tabadresse[i][1]+"<br \/>"+tabadresse[i][2]+" "+tabadresse[i][3]+"<br \/><br \/>Tél. <b>"+tabadresse[i][4]+"</b><br \/>Fax. "+tabadresse[i][5]+"<\/td><\/tr><\/table>");
					
				});
		map.openInfoWindowHtml(map.getCenter(),
		"<table><tr><td align=\"center\" width=\"150\" style=\"color:#000\"><b>"+tabadresse[i][0]+"<\/b><br \/>"+tabadresse[i][1]+"<br \/>"+tabadresse[i][2]+" "+tabadresse[i][3]+"<br \/><br \/>Tél. <b>"+tabadresse[i][4]+"</b><br \/>Fax. "+tabadresse[i][5]+"<\/td><\/tr><\/table>");

	}
}	
// *****************************************************************************************************************************************

function addAddressToMap(response) {
	map.clearOverlays();
	if (!response || response.Status.code != 200) {
		alert("Désolé, l'adresse est impossible à localiser.");
	} else {
		place = response.Placemark[0];
		if(latitude != 0){
			point = new GLatLng(latitude, longitude);
			map.setCenter(new GLatLng(latitude, longitude), 15);
		}else{
			point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
		}
		marker = new GMarker(point);
		map.addOverlay(marker);
		marker.openInfoWindowHtml(place.address);
	}
}

function showLocation(address,coordlat,coordlong) {
	//alert("ok");
	geocoder.getLocations(address, addAddressToMap);
	latitude = coordlat;
	longitude = coordlong;
}
// *************************************************************************************************************

function sendData(balise, param, page){
	//alert(balise+" "+param+" "+page);
	if(document.all) {
		//Internet Explorer
		var XhrObj = new ActiveXObject("Microsoft.XMLHTTP") ;
	}else{
		//Mozilla
		var XhrObj = new XMLHttpRequest();
	}

	//définition de l'endroit d'affichage
	var content = document.getElementById(balise);
	XhrObj.open("POST", page);

	//Ok pour la page cible
	XhrObj.onreadystatechange = function() {
		if (XhrObj.readyState == 4 && XhrObj.status == 200){
			content.innerHTML = XhrObj.responseText ;
		}
	}

	if (XhrObj.readyState == 4 && XhrObj.status == 200){
		//content._innerhtml = XhrObj.responseText ;
		content.innerHTML = XhrObj.responseText ;
		alert(XhrObj.responseText);
	}

	XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	XhrObj.send(param);
}

function myGetElementById(elemID) {
	if (document.getElementById && document.getElementById(elemID)) {
		return document.getElementById( elemID );
	} else if (document.all && document.all[divID]) {
		return document.all[ divID ];
	} else if (document.layers && document.layers[divID]) {
		return document.layers[ divID ];
	} else {
		return false;
	}
}

function catchEnter(evenement,form){
	var touche = window.event ? evenement.keyCode : evenement.which;
	if(touche==13) {
		form.submit();
	}
}

//Pour formulaire de contact
function mouvementchamps(element,navIE)
{
	x = 1;
	if (navIE)
	{
		texte = 'alpha(opacity=';
		opacite = 20;
	}
	else
		opacite = 0.2;
	while (x <=5) { 
		//filter : alpha(opacity=0.1);
		if (navIE)
		{
			setTimeout("document.getElementById('"+element+"').style.filter =  '"+texte+opacite+")'",parseInt(x+'00'));
			opacite += 20;
		}
		else
		{
			setTimeout("document.getElementById('"+element+"').style.opacity = "+opacite,parseInt(x+'00'));
			opacite += 0.2;
			opacite = Math.round(opacite*100)/100; 
		}
		x++;
	}
}
//Verifie l'adresse E-Mail
function verifmail(adrr){
  var reg= /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
  if(reg.test(adrr)==true) return true ;
  else return false;  
}


//Vérification des champs du formulaire de contact
function verifFormContact()
{	
	if (document.getElementById('erreurenvoi'))
		document.getElementById('erreurenvoi').style.display="none";
	if (navigator.appName == "Microsoft Internet Explorer")
		navIE = true;
	else
		navIE = false;
	valide=true;
	if (document.getElementById('nom').value=="" || document.getElementById('nom').value=="Nom")
	{
		
		document.getElementById('styleformcontactnom').style.background ="url(images/champs_form_erreur.png) no-repeat 9px 4px";
		document.getElementById('nom').style.background ="#d931a0";
		document.getElementById('nom').style.color ="#ffffff";
		mouvementchamps('styleformcontactnom',navIE);
		mouvementchamps('nom',navIE);
		valide=false;
	}
	else
	{
	
		document.getElementById('nom').style.background ="#ffffff";
		document.getElementById('nom').style.color ="#7a7a7a";
		mouvementchamps('nom',navIE);
		document.getElementById('styleformcontactnom').style.background ="url(images/champs_form.png) no-repeat 9px 4px";
		mouvementchamps('styleformcontactnom',navIE);
	}
		
	if ((document.getElementById('mailcontact').value!="") && (verifmail(document.getElementById('mailcontact').value)==false))
	{
		
		document.getElementById('styleformcontactmailcontact').style.background ="url(images/champs_form_erreur.png) no-repeat 9px 4px";
		mouvementchamps('styleformcontactmailcontact',navIE);
		document.getElementById('mailcontact').style.background ="#d931a0";
		document.getElementById('mailcontact').style.color ="#ffffff";
		//document.getElementById('messageMailNonValide').style.display="block";
		//mouvementchamps('messageMailNonValide',navIE);
		mouvementchamps('mailcontact',navIE);
		valide=false;
	}
	else
	{
		
		document.getElementById('styleformcontactmailcontact').style.background ="url(images/champs_form.png) no-repeat 9px 4px";
		mouvementchamps('styleformcontactmailcontact',navIE);
		document.getElementById('mailcontact').style.background ="#ffffff";
		document.getElementById('mailcontact').style.color ="#7a7a7a";
		//document.getElementById('messageMailNonValide').style.display="none";
		mouvementchamps('mailcontact',navIE);
		
	}	
	if (document.getElementById('telephone').value=="" || document.getElementById('telephone').value=="Téléphone")
	{
		document.getElementById('styleformcontacttelephone').style.background ="url(images/champs_form_erreur.png) no-repeat 9px 4px";
		mouvementchamps('styleformcontacttelephone',navIE);
		document.getElementById('telephone').style.background ="#d931a0";
		document.getElementById('telephone').style.color ="#ffffff";
		mouvementchamps('telephone',navIE);
		valide=false;
	}
	else
	{
		document.getElementById('styleformcontacttelephone').style.background ="url(images/champs_form.png) no-repeat 9px 4px";
		mouvementchamps('styleformcontacttelephone',navIE);
		document.getElementById('telephone').style.background ="#ffffff";
		document.getElementById('telephone').style.color ="#7a7a7a"; 
		mouvementchamps('telephone',navIE);
	}	
	
	if (document.getElementById('zone_Text').value=="")
	{
		document.getElementById('styleformcontactzone_Text').style.background ="url(images/champst_form_erreur.png) no-repeat 9px 4px";
		
		mouvementchamps('styleformcontactzone_Text',navIE);
		document.getElementById('zone_Text').style.background ="#d931a0";
		document.getElementById('zone_Text').style.color ="#ffffff";
		mouvementchamps('zone_Text',navIE);
		valide=false;
	}
	else
	{
		document.getElementById('styleformcontactzone_Text').style.background ="url(images/champst_form.png) no-repeat 9px 4px";
		mouvementchamps('styleformcontactzone_Text',navIE);
		document.getElementById('zone_Text').style.background ="#ffffff";
		document.getElementById('zone_Text').style.color ="#7a7a7a"; 
		mouvementchamps('zone_Text',navIE);
	}
	if (document.getElementById('code').value=="")
	{
		document.getElementById('styleformcontactmailcode').style.background ="url(images/champs_form_erreur.png) no-repeat 9px 4px";
		
		mouvementchamps('styleformcontactmailcode',navIE);
		document.getElementById('code').style.background ="#d931a0";
		document.getElementById('code').style.color ="#ffffff";
		mouvementchamps('code',navIE);
		valide=false;
	}
	else
	{
		document.getElementById('styleformcontactmailcode').style.background ="url(images/champs_form.png) no-repeat 9px 4px";
		mouvementchamps('styleformcontactmailcode',navIE);
		document.getElementById('code').style.background ="#ffffff";
		document.getElementById('code').style.color ="#7a7a7a"; 
		mouvementchamps('code',navIE);
	}
	
	
	
	
	
	if (valide)
	{
		document.getElementById('messageerreur').style.display="none";
		document.form_contact.submit();
	}
	else
		document.getElementById('messageerreur').style.display="block";
	return valide;
}
