// fonction Recherche
var saisieRechercheOK = false;

function PreparerChamps(champs, valeur)
{
    if (champs.value == valeur) {
        champs.value = "";
        saisieRechercheOK = true;
   }
}  
function RemettreChamps(champs, valeur)
{
    if (champs.value == "") {
        champs.value = valeur;
        saisieRechercheOK = false;
    }
}
function verifRecherche(formsearch)
{
    var objRecherche =document.getElementById("InputSearchWords").value;
	var objRechercheLength =document.getElementById("InputSearchWords").value.length;
    if (objRecherche == 'Rechercher...')
    {
        showAlert("Erreur","Veuillez saisir le mot recherché.");
        return false;
    }
    else if (objRechercheLength < 4)
    {
        showAlert("Erreur","Le mot recherché doit comporter au moins 4 caractères.");
        return false;
    }
    else
    {		
        return formsearch.submit();
		
    }
}
function f5(){
	window.location.reload( false );
}
function verif_authentification(){
	//alert($("#form_mail_au").val() + "  "+$("#form_password_au").val());
	$.ajax({
	   type: "POST",
	   url: 'modules/ajax.php?f=valid_authentification',
	   data: "login="+$("#form_mail_au").val()+"&psw="+$("#form_password_au").val(),
	   success: function(msg){
		 if(parseInt(msg) == 0){
			$("#form_mail_au").addClass("erreur");
			$("#form_password_au").addClass("erreur");
		 }else{
			 f5();
		 }
	   }
	});
}
function deconnexion(){
 $.ajax({
    type: "POST",
    url: 'modules/ajax.php?f=deconnexion',
    success: function(msg){
   f5();
   //if(parseInt(msg) == 0){ window.location.href = "index.php";  }
    }
 });
}
function authentification(){
	if($("#form_login").val() == "Email" && $("#form_psw").val() == "password"){
		//jQuery.facebox('modules/espace_client/mpoblier.php');
		jQuery.facebox(function() {
		  jQuery.get('modules/ajax.php?f=erreur_login_psw', function(data) {
			jQuery.facebox(data)
		  })
		}) 
	}else{
		//alert($("#form_login").val()+"   "+$("#form_psw").val());
		$.ajax({
		   type: "POST",
		   url: 'modules/ajax.php?f=authentification',
		   data: "login="+$("#form_login").val()+"&psw="+$("#form_psw").val(),
		   success: function(msg){
			 if(parseInt(msg) == 0){
				jQuery.facebox(function() {
				  jQuery.get('modules/ajax.php?f=erreur_login_psw', function(data) {
					jQuery.facebox(data)
				  })
				})  
			 }else{
				 f5();
			 }
		   }
		});
	}
}

function telecharger_fichier(img, lang)
{
    window.open("modules/telechargement/download/telecharger.php?nom="+img+"&lang="+lang, "Zone", "height=10, width=10, toolbar=0, menubar=0, scrollbars=1, resizable=1, status=0, location=no, channelmode=yes, left=0, top=0");
}
BG_IMG1 = "";
$(document).ready(function() {
	BG_IMG1 = $(".jMyCarouselHome li:first img").attr("alt");
	$("#image-full1").css("background-image","url(media/image_home/"+BG_IMG1+")");
	 /*$(".jMyCarouselHome li img").each(function(){
											alert($(this).attr("alt"));
											});*/
	
});
/* ------------------------------------------------------------------------------------	*/
/* 							Loder ImageFull												*/
/* ------------------------------------------------------------------------------------	*/
function loadingImageFull(srcimage,ele){
	imagePreloader = new Image; imagePreloader.src = srcimage ;
	if (imagePreloader.complete) {
		$("div.loading-image-full").hide();
		chargementImageFull(srcimage,ele);
	} else {
		$("div.loading-image-full").show();
		
		$(imagePreloader).unbind().bind('load', function() {
			$("div.loading-image-full").hide();
			chargementImageFull(srcimage,ele);
		});
	}
	
}
/* ------------------------------------------------------------------------------------	*/
/* 							Chargement d'un ImageFull									*/
/* ------------------------------------------------------------------------------------	*/
function chargementImageFull(srcimg,ele){
	/*$("#bgImg").css({"background-position":"50% 50%","background-repeat":"repeat"});*/
	$("#image-full2").hide().css("opacity",0);
	$("#image-full1").show().css({"opacity":"1"});
	$("#image-full2").css("background-image","url("+srcimg+")").show().animate({opacity: 1}, "slow");
	$(".jMyCarouselHome img.selected").removeClass("selected").animate({opacity: 1},"slow");
	$(ele).addClass("selected").animate({opacity: 0.6},"fast");
	$("#image-full1").animate({opacity: 0}, "slow", function(){
			$(this).css({"background-image":"url("+srcimg+")","opacity":"1"});
			$("#image-full2").hide();
			BG_IMG1 = srcimg;
		});
/*	$.ajax({
			type: "POST",
			url: "modules/ajax.php?f=produitsDetaille",
			data: "id_prod="+id,
			beforeSend : function(msg){
				//$("div.chargement").show();
			},
			success: function(msg){
				$("#detailProduit").hide().html("").append(msg).css({"opacity":"0","top":200});
				$("#detailProduit").show().animate({opacity:1, "top":150}, "slow");
			},
			error: function(){
				alert("Erreur Ajax");
			}
		});*/
}
function verifmail(adrr){
  var reg= /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
  if(reg.test(adrr)==true) return true;
  else return false;  
}
function verification(){
	//alert('x');
	var mail = $("#mail_utilisateur").val();
	var tel = $("#tel_utilisateur").val();
	//alert(mail+''+tel);
	if( (mail == "") || (tel == "") || (!verifmail(mail)) ){
		//alert('x');
		jQuery.facebox(function() {
			  jQuery.get('templates/ajax.php?f=erreur_mail_tel', function(data) {
				jQuery.facebox(data)
			  })
			}) 
	}else{
		$("#load_img").show();
		$.ajax({
		   type: "POST",
		   url: 'templates/ajax.php?f=verification',
		   data: "mail="+mail+"&tel="+tel,
		   success: function(msg){
			   //alert(msg);
			 if(parseInt(msg) == 0){
				 $("#load_img").hide();
				jQuery.facebox(function() {
				  jQuery.get('templates/ajax.php?f=erreur_mail_tel', function(data) {
					jQuery.facebox(data)
				  })
				})  
			 } if(parseInt(msg) == 1){
				 $("form#contatti").submit();
			 }
			 if(parseInt(msg) == 2){ 
				 $("#load_img").hide();
				jQuery.facebox(function() {
				  jQuery.get('templates/ajax.php?f=erreur_deja_inscrit', function(data) {
					jQuery.facebox(data)
				  })
				})  
			 }
		   }
		});
	}
}
function verif_contatti1(){
	var mail = $('#email_utilisateur1').val();
	//alert(mail);
	if( (mail == "") || (!verifmail(mail)) ){
		$("#email_utilisateur1").addClass("error");
			return false;
	}
	else{
		$("#load_img2").show();
		$.ajax({
		   type: "POST",
		   url: 'templates/ajax.php?f=verification_mail',
		   data: "mail="+mail,
		   success: function(msg){
			 if(parseInt(msg) == 0){
				 $("#load_img2").hide();
				jQuery.facebox(function() {
				  jQuery.get('templates/ajax.php?f=erreur_deja_inscrit', function(data) {
					jQuery.facebox(data)
				  })
				})  
			 } else $("form#contatti1").submit();
		   }
		});
	}
	
}

