// JavaScript Document


function VerifContact(){
	erreur = 0;
	
	$("#nom,#prenom,#email,#demande,#message").css("background-color","#ffffff");
	$("#nom,#prenom,#email,#demande,#message").css("border","1px solid #999999");

	if($("#nom").val()==""){ erreur++; ColorAlert($("#nom")); }
	if($("#prenom").val()==""){ erreur++; ColorAlert($("#prenom")); }
	if($("#email").val()=="" || verifmail($("#email").val())==0){ erreur++; ColorAlert($("#email")); }
	if($("#demande").val()==""){ erreur++; ColorAlert($("#demande")); }
	if($("#message").val()==""){ erreur++; ColorAlert($("#message")); }
	
	if(erreur==0){ return true; }else{ return false; }

}


function UpdateCGV(){
	if($("#acceptcgv").attr("checked")==true){
		$("#submitbout").removeAttr("disabled");
		$(".alerte").fadeOut("normal");
	}else{
		$("#submitbout").attr("disabled","disabled");
		$(".alerte").fadeIn("normal");
	}
}


function UpdatePort(elt){
	$("#form").attr("action","commander");
	$("#form").submit();
}




function VerifDeleteFromSelection(elt){
	if (confirm("Etes-vous certain de vouloir supprimer cet objet de votre sélection ?")) {
		document.location.href = "panier?del="+elt;
	}
}

function AddToSelection(produit){
	$.post('_AddToCartFast.php', { id: produit }, function(data) {
		$("#AddToSelection").fadeOut(300,function(){
			$("#ficheMessage").show();
			$('#ItemListeLight').html(data).animate({ backgroundColor: "#616161",color:"white" }, 1000,function(){ $('#ItemListeLight').animate({ backgroundColor: "#eeeeee",color:"#58585a" }, 1000); });
		});
	});
}


function verifFormInscript(){
	erreur = 0;
	
	$("#civilite,#telephone,#nom,#prenom,#email,#emailconfirm,#password,#passwordconfirm,#adresse,#postal,#ville,#pays").css("background-color","#ffffff");
	$("#civilite,#telephone,#nom,#prenom,#email,#emailconfirm,#password,#passwordconfirm,#adresse,#postal,#ville,#pays").css("border","1px solid #999999");

	if($("#civilite").val()==""){ erreur++; ColorAlert($("#civilite")); }
	if($("#telephone").val()==""){ erreur++; ColorAlert($("#telephone")); }
	if($("#nom").val()==""){ erreur++; ColorAlert($("#nom")); }
	if($("#prenom").val()==""){ erreur++; ColorAlert($("#prenom")); }
	if($("#email").val()==""){ erreur++; ColorAlert($("#email")); }
	
	if($("#emailconfirm").val()=="" || $("#emailconfirm").val()!=$("#email").val()){ erreur++; ColorAlert($("#emailconfirm")); }
	
	if($("#password").val()==""){ erreur++; ColorAlert($("#password")); }
	
	if($("#passwordconfirm").val()=="" || $("#passwordconfirm").val()!=$("#password").val()){ erreur++; ColorAlert($("#passwordconfirm")); }
	
	if($("#adresse").val()==""){ erreur++; ColorAlert($("#adresse")); }
	if($("#postal").val()==""){ erreur++; ColorAlert($("#postal")); }
	if($("#ville").val()==""){ erreur++; ColorAlert($("#ville")); }
	if($("#pays").val()==""){ erreur++; ColorAlert($("#pays")); }
	
	if(erreur==0){ return true; }else{ return false; }

}



function verifFormEdit(){
	erreur = 0;
	
	$("#civilite,#telephone,#nom,#prenom,#email,#password,#adresse,#postal,#ville,#pays").css("background-color","#ffffff");
	$("#civilite,#telephone,#nom,#prenom,#email,#password,#adresse,#postal,#ville,#pays").css("border","1px solid #999999");

	if($("#civilite").val()==""){ erreur++; ColorAlert($("#civilite")); }
	if($("#telephone").val()==""){ erreur++; ColorAlert($("#telephone")); }
	if($("#nom").val()==""){ erreur++; ColorAlert($("#nom")); }
	if($("#prenom").val()==""){ erreur++; ColorAlert($("#prenom")); }
	if($("#email").val()==""){ erreur++; ColorAlert($("#email")); }
	if($("#password").val()==""){ erreur++; ColorAlert($("#password")); }	
	if($("#adresse").val()==""){ erreur++; ColorAlert($("#adresse")); }
	if($("#postal").val()==""){ erreur++; ColorAlert($("#postal")); }
	if($("#ville").val()==""){ erreur++; ColorAlert($("#ville")); }
	if($("#pays").val()==""){ erreur++; ColorAlert($("#pays")); }
	if(erreur==0){ return true; }else{ return false; }

}

function verifFormEditLivraison(){
	erreur = 0;
	
	$("#nom,#prenom,#adresse,#postal,#ville").css("background-color","#ffffff");
	$("#nom,#prenom,#adresse,#postal,#ville").css("border","1px solid #999999");

	if($("#nom").val()==""){ erreur++; ColorAlert($("#nom")); }
	if($("#prenom").val()==""){ erreur++; ColorAlert($("#prenom")); }
	if($("#adresse").val()==""){ erreur++; ColorAlert($("#adresse")); }
	if($("#postal").val()==""){ erreur++; ColorAlert($("#postal")); }
	if($("#ville").val()==""){ erreur++; ColorAlert($("#ville")); }
	if(erreur==0){ return true; }else{ return false; }

}


function ColorAlert(ki){
	$(ki).animate({ backgroundColor: "#ffe3e3",borderColor: "#8F0000" }, 400);
}



function CheckInscript(){
	$("#emailinscript").css("background-color","#ffffff");
	$("#emailinscript").css("border","1px solid #999999");

	if($("#emailinscript").val()!="" && verifmail($("#emailinscript").val())){
		return true;
	}else{
		ColorAlert($("#emailinscript"));
		return false;
	}
}


function CheckConnec(){
	$("#email,#password").css("background-color","#ffffff");
	$("#email,#password").css("border","1px solid #999999");

	if($("#email").val()!="" && verifmail($("#email").val()) && $("#password").val()!=""){
		return true;
	}else{
		ColorAlert($("#email"));
		ColorAlert($("#password"));
		return false;
	}
}

function CheckOubli(){
	$("#email").css("background-color","#ffffff");
	$("#email").css("border","1px solid #999999");

	if($("#email").val()!="" && verifmail($("#email").val())){
		$("#submit").hide('fast');
		return true;
	}else{
		ColorAlert($("#email"));
		return false;
	}
}

function verifmail(adrr){
	 var reg= /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
	 if(reg.test(adrr)==true) return true;
	 else return false;  
}


function ShowTab(ki,Tab){
	//$("#tabs").find("div").hide();
	$("#tabs .onglet").hide();
	$("#tabs"+Tab).show();
	$("#tabs").find("li a").removeClass("on");
	$(ki).addClass('on');
	//$('html, body').stop(true,true).animate({scrollTop:300}, 'slow');
}


function AddNewsletter(){
	$('#Newsletter').dialog({ width: 450,height:150,modal: true,show: "blind",title:"Inscription à la newsletter" });
}
function SendNewsletter(){
	
	if(verifmail($("#nlad").val())){
		$.post("_inc.addtonewsletter.php", { adresse: $("#nlad").val() }, 
		function(data) { 
			$("#nlresult").html("<strong>Merci de votre intérêt !</strong>");
			//$('#Newsletter').dialog("close");
		});
	}else{
		ColorAlert($("#nlad"));
	}
	
}

function ShowSendFriend(){
	$('#SendFriend').dialog({ width: 450,height:180,modal: true,show: "blind",title:"Envoyer à un ami" });
}

function SendFriend(){
	if(verifmail($("#sfmail").val()) && verifmail($("#sfdest").val()) && $("#sfnom").val()!=""){
		$.post("_inc.sendtofriend.php", { nom: $("#sfnom").val(),mail: $("#sfmail").val(),dest: $("#sfdest").val(),adresse: $("#sfadresse").val(),produit: $("#sfproduit").val() }, 
		function(data) { 
			$("#SendFriendResult").html("<tr><td><br /><br /><strong>Merci de votre intérêt !</strong></td></tr>");
			//$('#Newsletter').dialog("close");
		});
	}else{
		ColorAlert($("#sfnom"));
		ColorAlert($("#sfmail"));
		ColorAlert($("#sfdest"));
	}
	
}



function ShowProductPict(ki,moi){
	
	$(".ficheImgPtList").find("img").removeClass("on");
	
	$(moi).addClass("on");
	
	$(".ficheImgGd img").stop(true, true).fadeOut("fast",function(){
		$(".ficheImgGd img").attr("src","VISUELS/mid/"+ki).fadeIn("normal");		
		
		
	})
	alert($(".ficheImgGd a").attr("href"));
}



function SwitchSlideHomeGD(MyPic){
	if($("#hgi"+(MyPic+1)).attr("id")){
		MyPic = MyPic+1;
	}else{
		MyPic = 1;
	}
	$("#hgi"+(MyPic)).fadeIn("slow").delay(5000).fadeOut("slow",function(){
		SwitchSlideHomeGD(MyPic);
	});
}

function SwitchSlideHomePT(MyPic){
	if($("#hpt"+(MyPic+1)).attr("id")){
		MyPic = MyPic+1;
	}else{
		MyPic = 1;
	}
	$("#hpt"+(MyPic)).fadeIn("slow").delay(6000).fadeOut("slow",function(){
		SwitchSlideHomePT(MyPic);
	});
}

function SwitchSlideHomePROD(MyPic){
	if($("#hprod"+(MyPic+1)).attr("id")){
		MyPic = MyPic+1;
	}else{
		MyPic = 1;
	}
	$("#hprod"+(MyPic)).fadeIn("slow").delay(4000).fadeOut("slow",function(){
		SwitchSlideHomePROD(MyPic);
	});
}


function PopUp(elt){
	window.open(elt,'aux3archers','toolbar=0,menubar=0,location=0,scrollbars=1,width=600,height=500');
}

function Imprime(){
	window:print();
}

