// JavaScript Document

$(document).ready(function(){
						   
	//$(document).pngFix({blankgif:'img/blank.gif' });
	
	$('#nav li:not(.hp) a:not(.hover)').hover(function(){
		$(this).children('img').attr('src',$(this).children('img').attr('src').replace('-off','-on'));
	},function(){
		$(this).children('img').attr('src',$(this).children('img').attr('src').replace('-on','-off'));
	})
	
	$('#gallery a').lightBox(); // Select all links in object with gallery ID
	
	// Ouverture de la popup
	$(".openpopup").click(function(){
		popupcentree($(this).attr("href"),820,850,"menubar=no,toolbar=no,location=no,scrollbars=yes");
		return false;
	});
	
	// Fermeture de la popup
	$(".close a").click(function(){
		window.close();
	});
	
	$("a.blank").each(function(i){
		$(this).attr("target","_blank");				   
	});
	
	
	$("a.popover").click(function(event){
	  $("div#box").fadeIn("slow");
	});
	
	$("div#box a.close").click(function(event){
		$("div#box").fadeOut("slow");
	});
	
	$("#sendfriend").submit(function(event){
									 
	  var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	  $("p.error").html('envoi');
	  
	  if (!filter.test($("#email_from").val())) {
		$("p.error").html('Votre Adresse e-mail est invalide');
		return false;
	  }else if (!filter.test($("#email_to1").val())) {
		$("p.error").html('Vous devez renseigner au moins <br /> une adresse e-mail valide');
		return false;
	  }else{
		return true;  
	  }
	  
	});
	
	$("#inscription").submit(function(event){
		
	    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		$("label.email").html('Email');
		$("label.telephone").html('Téléphone');
		$("p.obligatoire").html("<span>*</span> champs obligatoires");
		$("p.obligatoire").css({ color: "white", fontWeight: "normal" });
		erreur = 0;
		
		if( $("#contact_email:checked").length == 1 ){
			if (!filter.test($("#email").val())) {
				$("label.email").html('Email <span>*</span>');
				erreur++;
			}
		}
		if( $("#contact_tel:checked").length == 1 ){
			if ( $( "#telephone").val().length != 10 ) {
				$("label.telephone").html('Téléphone <span>*</span>');
				erreur++;
			}
		}
		
		if( $("#contact_tel:checked").length != 1 && $("#contact_email:checked").length != 1 ){
			erreur++;
			$("p.obligatoire").html("Vous devez choisir un moyen d'être contacté");
			$("p.obligatoire").css({ color: "red", fontWeight: "bold" });
		}
		
		if( $("#nom").val().length == 0 || $("#prenom").val().length == 0 || $("#adresse").val().length == 0 || $("#cp").val().length == 0 || $("#ville").val().length == 0 || erreur!=0 ){
			return false;
		}
		
	});
						   
});
function checkEmail(email) {
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value)) {
return false;
}
}
function popupcentree(page,largeur,hauteur,options) {
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

function credits(){
	popupcentree("credits.html",800,850,"scrollbars='no'");
	//return false;
}

function mentions(){
	popupcentree("mentions.html",800,850,"scrollbars='no'");
	//return false;
}
function protection(){
	popupcentree("http://www.pg.com/privacy/french/privacy_notice.html",800,850,"scrollbars='no'");
	//return false;
}

/*$(function() {
	// Use this example, or...
	$('#gallery a').lightBox(); // Select all links in object with gallery ID
	// This, or...
	$('a.lightbox').lightBox(); // Select all links with lightbox class
	// This, or...
	$('a').lightBox(); // Select all links in the page
	// ... The possibility are many. Use your creative or choose one in the examples above
});*/
