// JavaScript Document
	$(document).ready(function() {
	// Affectation des images au menu
		$('ul.slides li').each(function(){   
			$(this).css('background', 'url(images/'+$(this).attr("id")+'.jpg)');
			if($(this).attr('class')=='current'){
				$(this).css('background', 'url(images/'+$(this).attr("id")+'_on.jpg)');
			}
		});
		
		$('#navigation a').mouseenter(function() {
			var id_actif=$(this).attr("id").split('_');
			var a_id=id_actif[1];
			if(a_id=='2' || a_id=='3'){
				$('#slide_2').css('background', 'url(images/slide_2_on.jpg)');
				$('#slide_3').css('background', 'url(images/slide_3_on.jpg)');
			}else{
				$('#slide_'+a_id).css('background', 'url(images/slide_'+a_id+'_on.jpg)');
			}
		});
		
		$('#navigation a').mouseleave(function() {
			var id_actif=$(this).attr("id").split('_');
			var a_id=id_actif[1];
			if($(this).attr("class")!='current'){
				if(a_id=='2' || a_id=='3'){
					$('#slide_2').css('background', 'url(images/slide_2.jpg)');
					$('#slide_3').css('background', 'url(images/slide_3.jpg)');
				}else{
					$('#slide_'+a_id).css('background', 'url(images/slide_'+a_id+'.jpg)');
				}
			}
		});
		
	// Affectation des évènements lors du survol de la souris
		$('ul.slides li').mouseenter(function(){   
			if($(this).attr('id')=='slide_2' ||	$(this).attr('id')=='slide_3')
			{
				$('#slide_2').css('background', 'url(images/slide_2_on.jpg)');
				$('#slide_3').css('background', 'url(images/slide_3_on.jpg)');
			}else{
				$(this).css('background', 'url(images/'+$(this).attr("id")+'_on.jpg)');
			}
		});
	// Affectation des évènements lorsque la souris quitte la zone
		$('ul.slides li').mouseleave(function(){   
			if($(this).attr('class')!='current'){																
				if($(this).attr('id')=='slide_2' ||	$(this).attr('id')=='slide_3')
				{
					$('#slide_2').css('background', 'url(images/slide_2.jpg)');
					$('#slide_3').css('background', 'url(images/slide_3.jpg)');
				}else{
					$(this).css('background', 'url(images/'+$(this).attr("id")+'.jpg)');
				}
			}
		});
	});

 function displayPoint(marker, index){
		$("#message").hide();
		
		var moveEnd = GEvent.addListener(map, "moveend", function(){
			var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng());
			$("#message")
				.fadeIn()
				.css({ top:markerOffset.y, left:markerOffset.x });
			GEvent.removeListener(moveEnd);
		});
		map.panTo(marker.getLatLng());
	}

function Appels(id_div,id_type,page){
		$.ajax({
			url: "ajax/appels.php?id_type="+id_type+"&starting="+page,
			global: false,
			type: "GET",
			dataType: "html",
				success: function(reponse){
					$("#"+id_div).html(reponse);
				}
		 });
}

	function lookup(table, champ1, champ2, DIVid, LISTid, INPUTid, inputString, secondvalue, secondchamp) {
		/*if(inputString.length == 0) {
			$('#'+DIVid).hide();
		} else {*/
			$.post("ajax/rpc.php", {table: ""+table+"",champ1: ""+champ1+"",champ2: ""+champ2+"",queryString: ""+inputString+"", DIVid: ""+DIVid+"", INPUTid: ""+INPUTid+"", secondvalue: ""+secondvalue+"", secondchamp: ""+secondchamp+""}, function(data){
				if(data.length >0) {
					$('#'+DIVid).show();
					$('#'+LISTid).html(data);
				}
			});
		/*}*/
	}
	
	function fill(INPUTid, DIVid, thisValue, secondchamp, cpvalue) {
		$('#'+INPUTid).val(thisValue);
		$('#'+secondchamp).val(cpvalue);
		setTimeout("$('#"+DIVid+"').hide();", 200);
	}

// Fonction de traitement du formulaire de contact
$('#frm_dossier').submit(function() {
	//^[[:w:]]([-_.]?[[:w:]])*@[[:w:]]([-.]?[[:w:]])*\.([a-z]{2,4})$
	//^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$
	//^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$
	var re1=  /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;    /*expr regul pour l'email */      
	var re2 = /^[-]?\d*\.?\d*$/;    /*expr regul pour les chiffres*/ 
	var re3 = /^(0[1-68][-.\s]?(\d{2}[-.\s]?){3}\d{2})$/; /*expr regul 10 caracteres pour les numero de telephone*/ 
	var re4 = /^[0-9]{3}[-.\s]?[0-9]{2}[-.\s]?[0-9]{9}$/; /*$expr pour numéro de Siret du type 000 12 123456789*/
	var tmp = true; 
	/*var lots_selection=$('textarea.tinymce').html();
	if(lots_selection==''){$("iframe").contents().find("body#tinymce").animate({backgroundColor: '#7FC352'},1000)};*/
	//var lots_selection=$("select[name='lots']>option:selected").length;
	var modalites=$('#modalites_retrait').val();
	if(modalites==''){$("#modalites_retrait").animate({backgroundColor: '#7FC352'},1000);tmp = false;};
	var lots_selection=$('.asmListItem').length;
	if(lots_selection<1){$('#asmSelect0').animate({backgroundColor: '#7FC352'},1000);tmp = false;}
		$("#frm_dossier :input").each(function(){   
			if($(this).attr('type')=='checkbox' || $(this).attr('type')=='radio'){
				$(this).css({backgroundColor: 'transparent'});
				}else{
				$(this).css({backgroundColor: '#FFFFFF'});
			}
			var valeur = $(this).val(); /*    valeur saisie par l'utilisateur    */ 
			var nom = $(this).attr("name");
			var classe = $(this).attr("class");
			$("#err_"+nom).hide();
			//if(nom.substr(-4) =='cblg' && (valeur=='00' || valeur=='0' || valeur=='')) {
			if(classe =='obligatoire') {
				if(nom=='email' && !valeur.match(re1)){
					$(this).animate({backgroundColor: '#7FC352'},1000);
				  tmp = false; // modification de tmp 
					$("#err_"+nom).html('Email non valide');
					$("#err_"+nom).show();
				}else if(nom=='telephone' && !valeur.match(re3)){
					$(this).animate({backgroundColor: '#7FC352'},1000);
				  tmp = false; // modification de tmp 
					$("#err_"+nom).show();
					$("#err_"+nom).html('Téléphone non valide');
				}else if(nom=='fax' && !valeur.match(re3)){
					$(this).animate({backgroundColor: '#7FC352'},1000);
				  tmp = false; // modification de tmp 
					$("#err_"+nom).show();
					$("#err_"+nom).html('Fax non valide');
				}else if((valeur=='')){
					$(this).animate({backgroundColor: '#7FC352'},1000);
					tmp = false; // modification de tmp   //return false;
					$('#erreur_formulaire').html('Les champs en surbrillance sont obligatoires');
				}
			}
		  });  
		return tmp
	});  

$('#frm_abonnement').submit(function() {
	//^[[:w:]]([-_.]?[[:w:]])*@[[:w:]]([-.]?[[:w:]])*\.([a-z]{2,4})$
	//^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$
	//^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$
	var re1=  /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;    /*expr regul pour l'email */      
	var re2 = /^[-]?\d*\.?\d*$/;    /*expr regul pour les chiffres*/ 
	var re3 = /^(0[1-68][-.\s]?(\d{2}[-.\s]?){3}\d{2})$/; /*expr regul 10 caracteres pour les numero de telephone*/ 
	var re4 = /^[0-9]{3}[-.\s]?[0-9]{2}[-.\s]?[0-9]{9}$/; /*$expr pour numéro de Siret du type 000 12 123456789*/
	var tmp = true; 
		$("#frm_abonnement :input").each(function(){   
			if($(this).attr('type')=='checkbox' || $(this).attr('type')=='radio'){
				$(this).css({backgroundColor: 'transparent'});
				}else{
				$(this).css({backgroundColor: '#FFFFFF'});
			}
			var valeur = $(this).val(); /*    valeur saisie par l'utilisateur    */ 
			var nom = $(this).attr("name");
			var classe = $(this).attr("class");
			$("#err_"+nom).hide();
			//if(nom.substr(-4) =='cblg' && (valeur=='00' || valeur=='0' || valeur=='')) {
			if(classe =='obligatoire') {
				if(nom=='email' && !valeur.match(re1)){
					$(this).animate({backgroundColor: '#7FC352'},1000);
				  tmp = false; // modification de tmp 
					$("#err_"+nom).html('Email non valide');
					$("#err_"+nom).show();
				}else if(nom=='telephone' && !valeur.match(re3)){
					$(this).animate({backgroundColor: '#7FC352'},1000);
				  tmp = false; // modification de tmp 
					$("#err_"+nom).show();
					$("#err_"+nom).html('Téléphone non valide');
				}else if(nom=='fax' && !valeur.match(re3)){
					$(this).animate({backgroundColor: '#7FC352'},1000);
				  tmp = false; // modification de tmp 
					$("#err_"+nom).show();
					$("#err_"+nom).html('Fax non valide');
				}else if((valeur=='')){
					$(this).animate({backgroundColor: '#7FC352'},1000);
					tmp = false; // modification de tmp   //return false;
					$('#erreur_formulaire').html('Les champs en surbrillance sont obligatoires');
				}
			}
		  });  
		return tmp
	});  

