﻿$(document).ready(function(){
		/*Calcul de la quantité*/
		$( function() {

			prix = 0; 		// initialisation du prix		
			port = 0;
			prix_port = 0;
		
			// Calcul de la quantité pour L'album le couteau entre les dents
			$("#ced").keyup(function() {
				if (!$("#ced").val().match(/^[0-9]*$/)) { 					// Verifie si nombre
						$("#ced").css("border-color","#990000");
						$("#ced").next(".error-message").show().text("Veuillez saisir le nombre d'articles");
						$(".ced-quantite-message").fadeOut();
						$(".total").fadeIn().text("Aucun article séléctionné");
					} else if (parseInt($("#ced").val()) > parseInt($("#ced-quantity").val())) {	// Verifie si toujours en stock
						$("#ced").css("border-color","#990000");
						$("#ced").next(".error-message").show().text("Vous ne pouvez pas commander plus de "+$("#ced-quantity").val()+" articles");
						$(".ced-quantite-message").fadeOut();
						$(".total").fadeIn().text("Aucun article séléctionné");
					} else if ($("#ced").val() == "") { 						// Verifie si différent de zéro
						$("#ced").css("border-color","#000000");
						$("#ced").next(".error-message").show().text("Veuillez saisir le nombre d'articles");
						$(".ced-quantite-message").fadeOut();
						$(".total").fadeIn().text("Aucun article séléctionné");
					} else{
						$("#ced").css("border-color","#000000");
						$("#ced").next(".error-message").hide().text("");
						$(".ced-quantite-message").fadeIn().text($("#ced").val()*$("#ced-price").val()+"€");
						prix = $("#ced-price").val()*$("#ced").val();

						// Calcul des frais de port
						if ($("#ced").val()<5) port = 2;
						if ($("#ced").val()>=5 && $("#ced").val()<10) port = 4;
						if($("#ced").val()>10) port = 0;
						prix_port = prix + port;
						
						// Affichage de la commande
						if (prix > 0) {
							$(".total").fadeIn().text( prix +" € + "+port+"€ de frais de port = "+ prix_port +" €");
						} else {
							$(".total").fadeIn().text("Aucun article séléctionné");
						}
					}				
			});
		});
			
				
		/* Verification des données du formaulaire */		
		$(function() {
			$("#envoyer").click(function() {
			//$("#yer").click(function() {
				valid = true;
					// alert("ici");	
				/*Vérification du nom*/
				if($("#nom").val() == "" ) {
					$("#nom").css("border-color","#990000");
					$("#nom").next(".error-message").fadeIn().text("Votre nom");
					valid = false;
				} else if (!$("#nom").val().match(/^[a-zA-Z-'éêèçàù ]+$/i)){
					$("#nom").css("border-color","#990000");
					$("#nom").next(".error-message").fadeIn().text("Lettres de l'alphabet uniquement");
					valid = false;
				}
				else{
					$("#nom").css("border-color","#000000");
					$("#nom").next(".error-message").fadeOut();
				}

				
				/*Vérification du Prénom*/
				if($("#prenom").val() == "" ) {
					$("#prenom").css("border-color","#990000");
					$("#prenom").next(".error-message").fadeIn().text("Votre prénom");
					valid = false;
				} else if (!$("#prenom").val().match(/^[a-zA-Z-'éêèçàù ]+$/i)){
					$("#prenom").css("border-color","#990000");
					$("#prenom").next(".error-message").fadeIn().text("Lettres de l'alphabet uniquement");
					valid = false;
				}
				else{
					$("#prenom").css("border-color","#000000");
					$("#prenom").next(".error-message").fadeOut();
				}
				
				
				/*Vérification de l'adresse*/
				if($("#adresse").val() == "" ) {
					$("#adresse").css("border-color","#990000");
					$("#adresse").next(".error-message").fadeIn().text("Votre rue");
					valid = false;
				} else if (!$("#adresse").val().match(/^[a-zA-Z0-9-'éêèçàù ]+$/i)){
					$("#adresse").css("border-color","#990000");
					$("#adresse").next(".error-message").fadeIn().text("Rue non valide");
					valid = false;
				}
				else{
					$("#adresse").css("border-color","#000000");
					$("#adresse").next(".error-message").fadeOut();
				}

				
				/*Vérification du Code Postal*/
				if($("#postcode").val() == "" ) {
					$("#postcode").css("border-color","#990000");
					$("#postcode").next(".error-message").fadeIn().text("Votre Code postal");
					valid = false;
				} else if (!$("#postcode").val().match(/^[a-zA-Z0-9- ]+$/i)){
					$("#postcode").css("border-color","#990000");
					$("#postcode").next(".error-message").fadeIn().text("Le code postal n'est pas valide");
					valid = false;
				}
				else{
					$("#postcode").css("border-color","#000000");
					$("#postcode").next(".error-message").fadeOut();
				}

				
				/*Vérification de la ville*/
				if($("#ville").val() == "" ) {
					$("#ville").css("border-color","#990000");
					$("#ville").next(".error-message").fadeIn().text("Votre ville");
					valid = false;
				} else if (!$("#ville").val().match(/^[a-zA-Z-'éêèçàù ]+$/i)){
					$("#ville").css("border-color","#990000");
					$("#ville").next(".error-message").fadeIn().text("Lettres de l'alphabet uniquement");
					valid = false;
				}
				else{
					$("#ville").css("border-color","#000000");
					$("#ville").next(".error-message").fadeOut();
				}

					
				/*Vérification de l'adresse email*/
				
				if($("#email").val() == "" ) {
					$("#email").css("border-color","#990000");
					$("#email").next(".error-message").fadeIn().text("Votre email");
					valid = false;
				//} else if (!$("#email").val().match(/^[a-zA-Z0-9_\-\.]+@[a-z]+\.$/i)){
				} else if (!$("#email").val().match(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,3}$/)){
				
					$("#email").css("border-color","#990000");
					$("#email").next(".error-message").fadeIn().text("L'email n'est pas valide");
					valid = false;
				}
				else{
					$("#email").css("border-color","#000000");
					$("#email").next(".error-message").fadeOut();
				}

				/*Vérification du téléphone*/
				if (!$("#telephone").val().match(/^[0-9-.+ ]+$/i)){
					$("#telephone").css("border-color","#990000");
					$("#telephone").next(".error-message").fadeIn().text("Téléphone non valide");
					valid = false;
				}
				else{
					$("#telephone").css("border-color","#000000");
					$("#telephone").next(".error-message").fadeOut();
				}
				
				// Verifie si un article est selectionné
				if (prix == 0) {	
					$("#envoyer").next(".error-message").fadeIn().text("Aucun article sélectionné");
					valid = false;
				} else {
					$("#envoyer").next(".error-message").fadeOut();
				}
					
				if (valid){
					// Validation du formulaire
					$(function(){
						$("#formulaire").submit(function(){
							
							nom_com = $(this).find("input[name=nom]").val();
							prenom_com= $(this).find("input[name=prenom]").val();
							adresse_com = $(this).find("input[name=adresse]").val();
							postcode_com = $(this).find("input[name=postcode]").val();
							ville_com = $(this).find("input[name=ville]").val();
							email_com = $(this).find("input[name=email]").val();
							telephone_com = $(this).find("input[name=telephone]").val();
							paiement_com = $(this).find("select[name=paiement]").val();
							pays_com = $(this).find("select[name=pays]").val();
							commentaire_com = $(this).find("textarea[name=commentaire]").val();
							hash_com = $(this).find("input[name=hash]").val();
							//if (reset == 1) hash_com=hash_com-1;
							dd = new Date();
							sec_com = dd.getTime()/1000; 
							
							// ent_com = $(this).find("input[name=ent]").val();
							// bre_com = $(this).find("input[name=bre]").val();
							ced_com = $(this).find("input[name=ced]").val();
							
							$.post("commande.php", {nom: nom_com, prenom: prenom_com, adresse: adresse_com, postcode: postcode_com, ville: ville_com, email:email_com, ced: ced_com, telephone: telephone_com, paiement: paiement_com, prix: prix, pays:pays_com, commentaire: commentaire_com, hash: hash_com, sec:sec_com}, function(data){
																											
									// Suppression du formulaire
									$(".form").fadeOut();
									
									// Affichage du processus d'envoi de la commande
									$(".envoi").fadeIn();
									
									// Affichage de paragraff à propos du déroulement du paiement
									if ($("#paiement").val() == "cheque") {
											$(".moyen-paiement").fadeIn().text("");
									} else {
											$(".moyen-paiement").fadeIn().text("");
									}	
								});
						return false; // Pour empecher la soumission du formulaire
						});
					});
				} else return false;
			});		
		});				

		
		// Supression des données entrées
		$(function() {
			$("#reset").click(function() {
				// Suppression du formulaire
								 
				$(".form").fadeIn();				
				
				// Affichage du processus d'envoi de la commande
				$(".envoi").fadeOut();
				$(".total").fadeOut();
				//$(".bre-quantite-message").fadeOut();
				//$(".ent-quantite-message").fadeOut();
				$(".ced-quantite-message").fadeOut();
				
				prix = 0;
				prix_port = 0;
				
				reset = 1;
			});		
		});
	});

//FUNCTIONS BELLOW
function VideoHdIncrease(video_com){
	$.post("videohdincrease.php", {video: video_com}, function(data){
	// Mettre en place une action d'apres telechargement										
	});
}

//FUNCTIONS BELLOW
function VideoAppleIncrease(video_com){
	$.post("videoappleincrease.php", {video: video_com}, function(data){
	// Mettre en place une action d'apres telechargement										
	});
}
		
	
//FUNCTIONS BELLOW
function DownloadIncrease(album_com){
	
	if (album_com==0) $(".telechargementhelp0").fadeIn(500);
	if (album_com==1) $(".telechargementhelp1").fadeIn(500);
	if (album_com==2) $(".telechargementhelp2").fadeIn(500);
	if (album_com==3) $(".telechargementhelp3").fadeIn(500);
	if (album_com==4) $(".telechargementhelp4").fadeIn(500);
	if (album_com==5) $(".telechargementhelp5").fadeIn(500);
	if (album_com==6) $(".telechargementhelp6").fadeIn(500);
	if (album_com==7) $(".telechargementhelp7").fadeIn(500);
	if (album_com==8) $(".telechargementhelp8").fadeIn(500);
	if (album_com==9) $(".telechargementhelp9").fadeIn(500);
	$.post("downloadincrease.php", {album: album_com}, function(data){
	// Mettre en place une action d'apres telechargement										
	});
}

function OpenShutterAlbums(album){
	if (album==0) {
		if( $(".niveau2album0").is(':visible') ) {
			$(".niveau2album0").fadeOut();
		} else {
			$(".niveau2album0").fadeIn();    
		}
	}
	if (album==1) {
		if( $(".niveau2album1").is(':visible') ) {
			$(".niveau2album1").fadeOut();
		} else {
			$(".niveau2album1").fadeIn();    
		}
	}
	if (album==2) {
		if( $(".niveau2album2").is(':visible') ) {
			$(".niveau2album2").fadeOut();
		} else {
			$(".niveau2album2").fadeIn();    
		}
	}
	if (album==3) {
		if( $(".niveau2album3").is(':visible') ) {
			$(".niveau2album3").fadeOut();
		} else {
			$(".niveau2album3").fadeIn();    
		}
	}
	if (album==4) {
		if( $(".niveau2album4").is(':visible') ) {
			$(".niveau2album4").fadeOut();
		} else {
			$(".niveau2album4").fadeIn();    
		}
	}
	if (album==5) {
		if( $(".niveau2album5").is(':visible') ) {
			$(".niveau2album5").fadeOut();
		} else {
			$(".niveau2album5").fadeIn();    
		}
	}
	if (album==6) {
		if( $(".niveau2album6").is(':visible') ) {
			$(".niveau2album6").fadeOut();
		} else {
			$(".niveau2album6").fadeIn();    
		}
	}
	if (album==7) {
		if( $(".niveau2album7").is(':visible') ) {
			$(".niveau2album7").fadeOut();
		} else {
			$(".niveau2album7").fadeIn();    
		}
	}
	if (album==8) {
		if( $(".niveau2album8").is(':visible') ) {
			$(".niveau2album8").fadeOut();
		} else {
			$(".niveau2album8").fadeIn();    
		}
	}
	if (album==9) {
		if( $(".niveau2album9").is(':visible') ) {
			$(".niveau2album9").fadeOut();
		} else {
			$(".niveau2album9").fadeIn();    
		}
	}	
}

function OpenShutterTracklisting(album){
	if (album==0) {
		if( $(".niveau2tracklisting0").is(':visible') ) {
			$(".niveau2tracklisting0").fadeOut();
		} else {
			$(".niveau2tracklisting0").fadeIn();
		}
	}
	if (album==1) {
		if( $(".niveau2tracklisting1").is(':visible') ) {
			$(".niveau2tracklisting1").fadeOut();
		} else {
			$(".niveau2tracklisting1").fadeIn();    
		}
	}
	if (album==2) {
		if( $(".niveau2tracklisting2").is(':visible') ) {
			$(".niveau2tracklisting2").fadeOut();
		} else {
			$(".niveau2tracklisting2").fadeIn();    
		}
	}
	if (album==3) {
		if( $(".niveau2tracklisting3").is(':visible') ) {
			$(".niveau2tracklisting3").fadeOut();
		} else {
			$(".niveau2tracklisting3").fadeIn();    
		}
	}	
	if (album==4) {
		if( $(".niveau2tracklisting4").is(':visible') ) {
			$(".niveau2tracklisting4").fadeOut();
		} else {
			$(".niveau2tracklisting4").fadeIn();    
		}
	}	
	if (album==5) {
		if( $(".niveau2tracklisting5").is(':visible') ) {
			$(".niveau2tracklisting5").fadeOut();
		} else {
			$(".niveau2tracklisting5").fadeIn();    
		}
	}	
	if (album==6) {
		if( $(".niveau2tracklisting6").is(':visible') ) {
			$(".niveau2tracklisting6").fadeOut();
		} else {
			$(".niveau2tracklisting6").fadeIn();    
		}
	}
	if (album==7) {
		if( $(".niveau2tracklisting7").is(':visible') ) {
			$(".niveau2tracklisting7").fadeOut();
		} else {
			$(".niveau2tracklisting7").fadeIn();    
		}
	}
	if (album==8) {
		if( $(".niveau2tracklisting8").is(':visible') ) {
			$(".niveau2tracklisting8").fadeOut();
		} else {
			$(".niveau2tracklisting8").fadeIn();    
		}
	}	
	if (album==9) {
		if( $(".niveau2tracklisting9").is(':visible') ) {
			$(".niveau2tracklisting9").fadeOut();
		} else {
			$(".niveau2tracklisting9").fadeIn();    
		}
	}	
}

function OpenShutterInfos(album){
	if (album==0) {
		if( $(".niveau2infos0").is(':visible') ) {
			$(".niveau2infos0").fadeOut();
		} else {
			$(".niveau2infos0").fadeIn();    
		}
	}
	if (album==1) {
		if( $(".niveau2infos1").is(':visible') ) {
			$(".niveau2infos1").fadeOut();
		} else {
			$(".niveau2infos1").fadeIn();    
		}
	}
		if (album==2) {
		if( $(".niveau2infos2").is(':visible') ) {
			$(".niveau2infos2").fadeOut();
		} else {
			$(".niveau2infos2").fadeIn();    
		}
	}
		if (album==3) {
		if( $(".niveau2infos3").is(':visible') ) {
			$(".niveau2infos3").fadeOut();
		} else {
			$(".niveau2infos3").fadeIn();    
		}
	}
		if (album==4) {
		if( $(".niveau2infos4").is(':visible') ) {
			$(".niveau2infos4").fadeOut();
		} else {
			$(".niveau2infos4").fadeIn();    
		}
	}
		if (album==5) {
		if( $(".niveau2infos5").is(':visible') ) {
			$(".niveau2infos5").fadeOut();
		} else {
			$(".niveau2infos5").fadeIn();    
		}
	}
		if (album==6) {
		if( $(".niveau2infos6").is(':visible') ) {
			$(".niveau2infos6").fadeOut();
		} else {
			$(".niveau2infos6").fadeIn();    
		}
	}
		if (album==7) {
		if( $(".niveau2infos7").is(':visible') ) {
			$(".niveau2infos7").fadeOut();
		} else {
			$(".niveau2infos7").fadeIn();    
		}
	}
		if (album==8) {
		if( $(".niveau2infos8").is(':visible') ) {
			$(".niveau2infos8").fadeOut();
		} else {
			$(".niveau2infos8").fadeIn();    
		}
	}
		if (album==9) {
		if( $(".niveau2infos9").is(':visible') ) {
			$(".niveau2infos9").fadeOut();
		} else {
			$(".niveau2infos9").fadeIn();    
		}
	}
}

function OverDownload(album){
	if (album==0){
	$("#DownloadOff0").fadeOut(0, function () {
		$("#DownloadOver0").fadeIn(0);
          });
	}
	if (album==1){
	$("#DownloadOff1").fadeOut(0, function () {
		$("#DownloadOver1").fadeIn(0);
          });
	}
	if (album==2){
	$("#DownloadOff2").fadeOut(0, function () {
		$("#DownloadOver2").fadeIn(0);
          });
	}
	if (album==3){
	$("#DownloadOff3").fadeOut(0, function () {
		$("#DownloadOver3").fadeIn(0);
          });
	}	
	if (album==4){
	$("#DownloadOff4").fadeOut(0, function () {
		$("#DownloadOver4").fadeIn(0);
          });
	}	
	if (album==5){
	$("#DownloadOff5").fadeOut(0, function () {
		$("#DownloadOver5").fadeIn(0);
          });
	}	
	if (album==6){
	$("#DownloadOff6").fadeOut(0, function () {
		$("#DownloadOver6").fadeIn(0);
          });
	}	
	if (album==7){
	$("#DownloadOff7").fadeOut(0, function () {
		$("#DownloadOver7").fadeIn(0);
          });
	}	
	if (album==8){
	$("#DownloadOff8").fadeOut(0, function () {
		$("#DownloadOver8").fadeIn(0);
          });
	}	
	if (album==9){
	$("#DownloadOff9").fadeOut(0, function () {
		$("#DownloadOver9").fadeIn(0);
          });
	}	
}

function OutDownload(album){

	if (album==0){
	$("#DownloadOver0").fadeOut(0, function () {
		$("#DownloadOff0").fadeIn(0);
          });
	}
	if (album==1){
	$("#DownloadOver1").fadeOut(0, function () {
		$("#DownloadOff1").fadeIn(0);
          });
	}
	if (album==2){
	$("#DownloadOver2").fadeOut(0, function () {
		$("#DownloadOff2").fadeIn(0);
          });
	}
	if (album==3){
	$("#DownloadOver3").fadeOut(0, function () {
		$("#DownloadOff3").fadeIn(0);
          });
	}
	if (album==4){
	$("#DownloadOver4").fadeOut(0, function () {
		$("#DownloadOff4").fadeIn(0);
          });
	}
	if (album==5){
	$("#DownloadOver5").fadeOut(0, function () {
		$("#DownloadOff5").fadeIn(0);
		});
	}
	if (album==6){
	$("#DownloadOver6").fadeOut(0, function () {
		$("#DownloadOff6").fadeIn(0);
          });
	}	
	if (album==7){
	$("#DownloadOver7").fadeOut(0, function () {
		$("#DownloadOff7").fadeIn(0);
		});
	}
	if (album==8){
	$("#DownloadOver8").fadeOut(0, function () {
		$("#DownloadOff8").fadeIn(0);
		});
	}
	if (album==9){
	$("#DownloadOver9").fadeOut(0, function () {
		$("#DownloadOff9").fadeIn(0);
		});
	}
}
