// JavaScript Document
$(document).ready(function()
		{
		
	  
/*
$('#headerzone').before('<p id="au"></p>');

$('#au').css({
		position:"absolute",
		top:"0",
		left:"0",
        color:"#f00",
        backgroundColor: "#000",
		zIndex:"1000000",
		width:"100%",
		height : $(document).height(),
		
		
    }).fadeTo('fast', 0);
	*/


		$('.idiome').click(function() {
			
			//alert($(this).attr('id'));
			changeto = 'l='+$(this).attr('id');
			
			$.ajax({
				
					type: "POST",
					url: "ajax.change_langue.php",
					data: changeto,
					
					success: function(msg){
					
						
							document.location.href=document.location;
						
				
					},
					error:  function(msg){
				
						alert('oop');
				
				
					}
				
				});
			
			//
			
		});
		
		$('#choixalbum').change(function() { 
		
						//document.location.href="header.php?idAlbum="+$(this).val();
						if($(this).val() == 0 ){
							
							$('#framediv').html('<iframe width="650" height="800" frameborder="0" scrolling="no" src="http://s338379357.onlinehome.fr/vide.php"></iframe>')
							
						}else{
							
							$('#framediv').html('<iframe width="650" height="800" frameborder="0" scrolling="no" src="http://s338379357.onlinehome.fr/galerie/'+$(this).val()+'/galerie.php"></iframe>')
			
						}
		
		
		});
								
		/*
		$("#slider").easySlider({
		
			auto: false,
			continuous: true,
			controlsShow:		true,
			numeric: true,
			
			pause:		3000,
			speed: 		300
		
		});
	
window.setInterval(function() {
    alert($('#trace').attr('class'))
}, 5000);
	

	
	(function($){
		
		en_avant = function() {
			datas=$('#trace').attr('class');	
			$.ajax({
			
				type: "POST",
				url: "ajax.affiche_en_avant.php",
				data: "id_en_avant="+courriel+"&action="+Resultat,
				
				success: function(msg){
				
					alert(msg);	
				
				},
				error:  function(msg){
				
					alert('oop');
				
				
				}
				
				});
				
			}		
	})(jQuery);
	*/
		// PLUGIN SUPERBOX 
		$(function(){

			$.superbox.settings = {
			boxId: "superbox", // Attribut id de l'élément "superbox"
			boxClasses: "", // Classes de l'élément "superbox"
			overlayOpacity: .8, // Opacité du fond
			boxWidth: "800", // Largeur par défaut de la box
			boxHeight: "800", // Hauteur par défaut de la box
			loadTxt: "Chargement...", // Texte de loading
			closeTxt: "Fermer", // Texte du bouton "Close"
			prevTxt: "Previous", // Texte du bouton "previous"
			nextTxt: "Next" // Texte du bouton "Next"
			};
			
			$.superbox();
	
		});
			
		if (top != self) { 
		
			$('html').html("");
		}
		
		// PLUGIN EASY SLIDER 
		
		// FORMULAIRE ABO / DESABO NEWSLETTER 
		$('#btSubmitNewsletter').click(function() { 
		
			//alert('toto');
			
			
			$(".coche").each(function(){
			
				if($(this).is(':checked')){
				
					Resultat= $(this).val();
				}
				
			});
			
			courriel = $("#newslettercourriel").val()
			
			var maReg = new RegExp ( "^\\w[\\w+\.\-]*@[\\w\-]+\.\\w[\\w+\.\-]*\\w$", "gi" ) ;
			
			if ( courriel.search( maReg ) == -1 ) {
				
				alert (MESSAGE_ERROR_JAVASCRIPT_EMAIL ) ;

			} else{
				
				$.ajax({
				
					type: "POST",
					url: "ajax.newsletter_action.php",
					data: "courriel="+courriel+"&action="+Resultat,
					
					success: function(msg){
					
						alert(msg);	
				
					},
					error:  function(msg){
				
						alert('oop');
				
				
					}
				
				});
				
			}


		})

		// ENVOIE FORMULAIRE CONTACT //
		$('#btformcontact').click( function(e) {
											
			e.preventDefault();	
			message=false;
			
			var maReg = new RegExp ( "^\\w[\\w+\.\-]*@[\\w\-]+\.\\w[\\w+\.\-]*\\w$", "gi" ) ;					
			
			nom				=$.trim( $("#nom").val() );
			prenom			=$.trim( $("#prenom").val() );
			courriel		=$.trim( $("#courriel").val() );
			mess			=$.trim( $("#mess").val() );

			if(nom == ""){
			
				message = MESSAGE_ERROR_JAVASCRIPT_NOM+"\n";
			}

			if ( courriel.search( maReg ) == -1 ) {
				
			
				message = message+MESSAGE_ERROR_JAVASCRIPT_EMAIL+"\n";
			
			}

			if(mess == ""){
			
				message =  message+MESSAGE_ERROR_JAVASCRIPT_MESSAGE+"."+"\n";
			}
			
			
			if(message != false){
				
				alert(message);
				
			}else{
				
				$('#btformcontact').attr("disabled", "true");
				
				$.ajax({ // fonction permettant de faire de l'ajax
					   
					type: "POST", // methode de transmission des données au fichier php
					url: "ajax.contac_action.php", // url du fichier php
					data: "nom="+nom+"&prenom="+prenom+"&courriel="+courriel+"&mess="+mess, // données à transmettre
					
					success: function(msg){ // si l'appel a bien fonctionné
				
					
					
					$("#nom").val('');
					$("#prenom").val('');
					$("#courriel").val('');
					$("#mess").val('');	
					$('#btformcontact').attr("disabled", false);
					
					alert(msg);
					
					},
				
					error:  function(msg){
				
					alert('oop');
					alert(msg);
				
				
					}
				
				});		
				
				
			}
										  
		});
		
		// ENVOIE FORMULAIRE CONTACT //

		// IDENTIFICATION 
		$('#ident_form').submit( function(e) {
										  
			e.preventDefault();	
			
		
			error	=false;
			message='';
			
			login	=$.trim( $("#login").val() );
			pass	=$.trim( $("#password").val() );
			
				
			var maReg = new RegExp ( "^\\w[\\w+\.\-]*@[\\w\-]+\.\\w[\\w+\.\-]*\\w$", "gi" ) ;
			
			if ( login.search( maReg ) == -1 ) {
				
				error = true;
				message = message+MESSAGE_ERROR_JAVASCRIPT_EMAIL;
			
			}
			if(pass == ""){
			
				message = message+"\n"+MESSAGE_ERROR_JAVASCRIPT_PASSWORD;
			}
			
			if(error != false){
				
				alert(message);
				
			}else{
				
				$.ajax({ // fonction permettant de faire de l'ajax
					   
					type: "POST", // methode de transmission des données au fichier php
					url: "ajax.identification.php", // url du fichier php
					data: "login="+login+"&pass="+pass, // données à transmettre
					
					success: function(msg){ // si l'appel a bien fonctionné
				
					if(msg==0) // si la connexion en php a fonctionnée
					{	
					alert(ITEM_ECHEC_AUTENTIFICATION);
					}
				
					//3
					if(msg==1)  // si la connexion en php n'a pas fonctionnée
					{
					alert(ITEM_ECHEC_AUTENTIFICATION);
					// on affiche un message d'erreur dans le span prévu à cet effet
					}
				
					if(msg==2)  // si la connexion en php n'a pas fonctionnée
					{
					alert(ITEM_ECHEC_AUTENTIFICATION);
					// on affiche un message d'erreur dans le span prévu à cet effet
					}
				
					if(msg==3)  
					{
					
					document.location.href="redirection.php";		
				
					}								
				
				},
				error:  function(msg){
				
				alert('oop');
				
				
				}
				
				});				
				
			}

		});
		
		// MODIF COMPTE 	
		
		$('#modifcompte').submit( function(e) {
			
			e.preventDefault();	
	
			var error=false;
			var message='';
			var maReg = new RegExp ( "^\\w[\\w+\.\-]*@[\\w\-]+\.\\w[\\w+\.\-]*\\w$", "gi" ) ;	
			
			nomClient		=$.trim( $("#nomClient").val() );
			prenomClient	=$.trim( $("#prenomClient").val() );
			emailClient		=$.trim( $("#emailClient").val() );
			telFixeClient	=$.trim( $("#telFixeClient").val() );
			adresseClient	=$.trim( $("#adresseClient").val() );
			codePostaClient	=$.trim( $("#codePostaClient").val() );
			villeClient		=$.trim( $("#villeClient").val() );
			paysClient		=$.trim( $("#paysClient").val() );
			
			if(nomClient.length<1){
				error = true;
				message=message+"\n"+ MESSAGE_ERROR_JAVASCRIPT_NOM;
			
			}
			
			if(prenomClient.length<1){
				error = true;	
				message=message+"\n"+MESSAGE_ERROR_JAVASCRIPT_PRENOM;
					
			}
					
					
			if ( emailClient.search( maReg ) == -1 ) {
				error = true;
				message=message+"\n"+MESSAGE_ERROR_JAVASCRIPT_EMAIL;
			
			}


			if(telFixeClient.length<1){
				error = true;
				message =message+"\n"+MESSAGE_ERROR_JAVASCRIPT_TELEPHONE;
			
			}

			if(adresseClient.length<1){
				error = true;
				message =message+"\n"+MESSAGE_ERROR_JAVASCRIPT_ADRESSE;
			
			}
					
	
			if(codePostaClient.length<1){
				error = true;
				message =message+"\n"+MESSAGE_ERROR_JAVASCRIPT_CODEPOSTAL;
			
			}

			if(villeClient.length<1){
				error = true;
				message=message+"\n"+MESSAGE_ERROR_JAVASCRIPT_VILLE ;
			
			}

			if(paysClient==0){
				error = true;
				message=message+"\n"+MESSAGE_ERROR_JAVASCRIPT_PAYS ;
			
			}
			/**/
			if(error != false){
			
				alert(message);
			
			}else{
				
				var datas = $(this).serialize();
				////////////////////////////
				$.ajax({
				
				type: 'POST',      // envoi des données en POST
				url: "ajax.modifcompte.php",     // envoi au fichier défini dans l'attribut action
				data: datas,     // sélection des champs à envoyer
				
				success: function(msg) {
					msg = $.trim(msg);
					
					if(msg!='') {
					
						alert (msg);
						document.location.href=document.location;
					}
					
		
				
					
				},
				
				error : function () {
				  
					alert ('oops');
				  
				}
				
				});					
				////////////////////////////				
							
			}
		
			
		});
		
		// OUVERTURE COMPTE 		

		$('#createcompteform').submit( function(e) {
												
			e.preventDefault();	
			
			var error=false;
			var message='';
			var maReg = new RegExp ( "^\\w[\\w+\.\-]*@[\\w\-]+\.\\w[\\w+\.\-]*\\w$", "gi" ) ;			
			
			nomClient		=$.trim( $("#nomClient").val() );
			prenomClient	=$.trim( $("#prenomClient").val() );
			emailClient		=$.trim( $("#emailClient").val() );
			telFixeClient	=$.trim( $("#telFixeClient").val() );
			adresseClient	=$.trim( $("#adresseClient").val() );
			codePostaClient	=$.trim( $("#codePostaClient").val() );
			villeClient		=$.trim( $("#villeClient").val() );
			paysClient		=$.trim( $("#paysClient").val() );
			password		=$.trim( $("#password").val() );
			
			if(nomClient.length<1){
				error = true;
				message=message+"\n"+ MESSAGE_ERROR_JAVASCRIPT_NOM;
			
			}
			
			if(prenomClient.length<1){
				error = true;	
				message=message+"\n"+MESSAGE_ERROR_JAVASCRIPT_PRENOM;
					
			}
					
					
			if ( emailClient.search( maReg ) == -1 ) {
				error = true;
				message=message+"\n"+MESSAGE_ERROR_JAVASCRIPT_EMAIL;
			
			}


			if(telFixeClient.length<1){
				error = true;
				message =message+"\n"+MESSAGE_ERROR_JAVASCRIPT_TELEPHONE;
			
			}

			if(adresseClient.length<1){
				error = true;
				message =message+"\n"+MESSAGE_ERROR_JAVASCRIPT_ADRESSE;
			
			}
					
	
			if(codePostaClient.length<1){
				error = true;
				message =message+"\n"+MESSAGE_ERROR_JAVASCRIPT_CODEPOSTAL;
			
			}

			if(villeClient.length<1){
				error = true;
				message=message+"\n"+MESSAGE_ERROR_JAVASCRIPT_VILLE ;
			
			}

			if(paysClient==0){
				error = true;
				message=message+"\n"+MESSAGE_ERROR_JAVASCRIPT_PAYS ;
			
			}

			if(password.length<1){
				error = true;
				message =message+"\n"+MESSAGE_ERROR_JAVASCRIPT_PASSWORD;
			
			}

			if(error != false){
				
				alert(message);
				
			}else{
				
				var datas = $(this).serialize();
				////////////////////////////
				$.ajax({
				
				type: 'POST',      // envoi des données en POST
				url: "ajax.ouverture.php",     // envoi au fichier défini dans l'attribut action
				data: datas,     // sélection des champs à envoyer
				
				success: function(msg) {
				
					if(msg==0){
						
						document.location.href="redirection.php";	
						
					}else{
							alert (msg);
					}
					
				},
				
				error : function () {
				  
					alert ('oops');
				  
				}
				
				});					
				////////////////////////////
				
			}
			
			
		});	
		

		
		// AJOUT DANS LE CADDIE
		$('.intocaddie').click( function() {
	
			datas="ID_PRODUIT="+$(this).attr('id');	
				////////////////////////////
				$.ajax({
				
				type: 'POST',      // envoi des données en POST
				url: "ajax.ajoutdanscaddie.php",     // envoi au fichier défini dans l'attribut action
				data: datas,     // sélection des champs à envoyer
				
				success: function(msg) {
				
					jQuery.noticeAdd({
					text: msg+' '+ addedtocart,
					stay: false,
					type: 'succes'
					
					
					});		
					
					intopoppanier();	
				
					
					
					
				},
				
				error : function () {
				  
					alert ('oops');
				  
				}
				
				});					
				////////////////////////////			
			
				
		
		});
		
		(function($){
		
			intopoppanier = function() {
				
	
				$('#poppanier').text('...');
				////////////////////////////
				$.ajax({
				
				type: 'POST',      // envoi des données en POST
				url: "ajax.majpoppanier.php",     // envoi au fichier défini dans l'attribut action
				
				
				success: function(msg) {
			
					$('#poppanier').html(msg);
					
					
				},
				
				error : function () {
				  
					$('#poppanier').text('opps');
				  
				}
				
				});					
				////////////////////////////
				
			}		
		})(jQuery);
				
		// RECALCULER LE PANIER 			  ///
		(function($){
		
			recalcul = function() {

				var error=0;
				var n=$(".prodqty").length;
				
				$(".prodqty").each(function(){
					
					if(isNaN($(this).val() ) || $(this).val()< 0 ) error = 1 ;
					
				});
	
				
				if(error>0){
				
					alert (ERROR_QTY_JAVASCRIPT);
				
				}else{
					
					var datatosend='';
					
					for(a=0;a<n;a++){
						
						datatosend +='idprod['+a+']='+ $("#idprod_"+a).val() + '&quantite['+a+']='+ $("#quantite_"+a).val()+'&centi['+a+']='+$("#centi_"+a).val()+'&';
						
					}
					
					datatosend +='nOfProd='+n;
					
					
					/////////////////////////////////////////////////////
					$.ajax({
				
					type: "POST",
					url: "ajax.recalcul.panier.php",
					data: datatosend,
					
					success: function(msg){
					
						//location.reload();
						document.location.href=document.location;
				
					},
					
					error:  function(msg){
				
						alert('oop');
				
				
					}
				
					});
					/////////////////////////////////////////////////////
						
				}
				
			};
		
		
		})(jQuery);

		// POURSUIVRE VERS ADRESSE LIVRAISON  ///
		$('#panier').submit( function(e) {

		 e.preventDefault(); // on empeche l'envoi du formulaire par le navigateur
		 var datas = $(this).serialize();
		 $.ajax({
			  type: 'POST',      // envoi des données en POST
			  url: "ajax.panier.etape1.php",     // envoi au fichier défini dans l'attribut action
			  data: datas,     // sélection des champs à envoyer
			  success: function(msg) {     // callback en cas de succès
			  
				  document.location.href="expedition.php";						   
			  }
		 });
			 
			 
	
		});
		
		// POURSUIVRE VERS TRANSPORT  ///
		$('#expedition').submit( function(e) {

			 e.preventDefault(); // on empeche l'envoi du formulaire par le navigateur
			 
			$(".adresselivraison").each(function(){
			
				//if(isNaN($(this).val() ) || $(this).val()< 0 ) error = 1 ;
				if($(this).is(':checked')){
					
				data = "idadresse="+($(this).val());
				
				}
			
			});
		
			$.ajax({
				   
			  type: 'POST',      // envoi des données en POST
			  url: "ajax.panier.etape2.php",     // envoi au fichier défini dans l'attribut action
			  data: data,     // sélection des champs à envoyer
			  success: function(msg) {     // callback en cas de succès
			  
				  document.location.href="recapitulatif.php";						   
			  },
			  
			  error : function () {
				  
					alert ('oops');
				  
			  }
			  
			});
			
	
		});
		
		$('#transportform').submit( function(e) {

			e.preventDefault(); // on empeche l'envoi du formulaire par le navigateur
			$(".idTransport").each(function(){
			
				//if(isNaN($(this).val() ) || $(this).val()< 0 ) error = 1 ;
				if($(this).is(':checked')){
				
					data = "idtransporteur="+($(this).val());
				
				}
			
			});
			
			$.ajax({
				   
			  type: 'POST',      // envoi des données en POST
			  url: "ajax.panier.etape3.php",     // envoi au fichier défini dans l'attribut action
			  data: data,     // sélection des champs à envoyer
			  success: function(msg) {     // callback en cas de succès
			  
				  document.location.href="recapitulatif.php";						   
			  },
			  
			  error : function () {
				  
					alert ('oops');
				  
			  }
			  
			});
			
										  
		});	

		$('#paiementform').submit( function(e) {
			
			e.preventDefault(); // on empeche l'envoi du formulaire par le navigateur
			stop = 0;
			$("#boutonfinal").hide(); 
		
			datas="grandtotal="+$('#grdTotal').val();
			datas+="&commandeout="+$('#commandeout').val();
			
			$(".idPaiement").each(function(){
			
				//if(isNaN($(this).val() ) || $(this).val()< 0 ) error = 1 ;
				if($(this).is(':checked')){
				
					data = "&idPaiement="+($(this).val());
				
				} else {
					
					stop = 1;
					
				}
			
			});
			
			
			
			
			
			$.ajax({
		 
			  type: 'POST',      // envoi des données en POST
			  url: "ajax.panier.etapefinal.php",     // envoi au fichier défini dans l'attribut action
			  data: datas+data,     // sélection des champs à envoyer
			  success: function(msg) {     // callback en cas de succès
				  
				msg =  $.trim(msg) ;
				/*alert(msg.length);*/
				
				if(msg=="cheque"){
					
					window.location.href="commande_ok.php";
					
					
				}else{
				
					
					 var amount=msg.split("_");
					
					
					$("#call_id").val(amount[1]);
					$("#call_request").submit();

				}
				
				
			  },
			  
			  error : function () {
				  
					alert ('oops');
				  
			  }
			
			});
			/**/
										  
		});	
		


		// AJOUTER UNE ADRESSE AU CARNET ADRESSE 
		$('#addadresseform').submit( function(e) {
			e.preventDefault()
			
			var error='';
			
			nomClient		=$.trim( $("#nomClient").val() );
			prenomClient	=$.trim( $("#prenomClient").val() );		
			telFixeClient	=$.trim( $("#telFixeClient").val() );
			adresseClient	=$.trim( $("#adresseClient").val() );
			codePostaClient	=$.trim( $("#codePostaClient").val() );
			villeClient		=$.trim( $("#villeClient").val() );
			paysClient		=$.trim( $("#paysClient").val() );
			
			if(nomClient.length<1){
			
				error =error+"\n"+ MESSAGE_ERROR_JAVASCRIPT_NOM;
				
			
			}
			
			if(prenomClient.length<1){
			
				error =error+"\n"+MESSAGE_ERROR_JAVASCRIPT_PRENOM;
			
			}
			
			if(adresseClient.length<1){
			
				error =error+"\n"+MESSAGE_ERROR_JAVASCRIPT_ADRESSE;
			
			}
			

			if(codePostaClient.length<1){
			
				error =error+"\n"+MESSAGE_ERROR_JAVASCRIPT_CODEPOSTAL;
			
			}

			if(villeClient.length<1){
			
				error=error+"\n"+MESSAGE_ERROR_JAVASCRIPT_VILLE ;
			
			}

			if(paysClient==0){
			
				error=error+"\n"+MESSAGE_ERROR_JAVASCRIPT_PAYS ;
			
			}			
			
			if(error.length>0){
			
			
				alert (error);
	
			}else{
				
				var datas = $(this).serialize();
				//alert (datas);
				/////////////////////////////////////////////////////
				$.ajax({
			
					type: "POST",
					url: "ajax.ajoutadresse.php",
					data: datas,
					
					success: function(msg){
					
						//location.reload();
						document.location.href=msg;
				
					},
					error:  function(msg){
				
						alert('oop');
				//$('#p_'+id).attr('src', 'images/delete.png' );
				
					}
			
				});
				/////////////////////////////////////////////////////
			}
			
			
			
		})		
		// EDITER UNE ADRESSE DU CARNET ADRESSE
		$('#editadresseform').submit( function(e) {
			e.preventDefault()
			
			var error='';
			
			nomClient		=$.trim( $("#nomClient").val() );
			prenomClient	=$.trim( $("#prenomClient").val() );		
			telFixeClient	=$.trim( $("#telFixeClient").val() );
			adresseClient	=$.trim( $("#adresseClient").val() );
			codePostaClient	=$.trim( $("#codePostaClient").val() );
			villeClient		=$.trim( $("#villeClient").val() );
			paysClient		=$.trim( $("#paysClient").val() );
			
			if(nomClient.length<1){
			
				error =error+"\n"+ MESSAGE_ERROR_JAVASCRIPT_NOM;
				
			
			}
			
			if(prenomClient.length<1){
			
				error =error+"\n"+MESSAGE_ERROR_JAVASCRIPT_PRENOM;
			
			}
			
			if(adresseClient.length<1){
			
				error =error+"\n"+MESSAGE_ERROR_JAVASCRIPT_ADRESSE;
			
			}
			

			if(codePostaClient.length<1){
			
				error =error+"\n"+MESSAGE_ERROR_JAVASCRIPT_CODEPOSTAL;
			
			}

			if(villeClient.length<1){
			
				error=error+"\n"+MESSAGE_ERROR_JAVASCRIPT_VILLE ;
			
			}

			if(paysClient==0){
			
				error=error+"\n"+MESSAGE_ERROR_JAVASCRIPT_PAYS ;
			
			}			
			
			if(error.length>0){
			
			
				alert (error);
	
			}else{
				
				var datas = $(this).serialize();
				//alert (datas);
				/////////////////////////////////////////////////////
				$.ajax({
			
				type: "POST",
				url: "ajax.editadresse.php",
				data: datas,
				
				success: function(msg){
				
					//location.reload();
					document.location.href=msg;
			
				},
				error:  function(msg){
			
					alert('oop');
			//$('#p_'+id).attr('src', 'images/delete.png' );
			
				}
			
				});
				/////////////////////////////////////////////////////				
				
				
			}
			
			
			
		})	
		
		// SUPPRIMER UNE ADRESSE DU CARNET D'ADRESSE
		$('.deladresse').click( function() {
						
			if(confirm(MESSAGE_CONFIRM_JAVASCRIPT_DELETE_ADRESSE)){
				
				$.ajax({
				
					type: 'POST',      // envoi des données en POST
					url: "ajax.delete.adresse.php",     // envoi au fichier défini dans l'attribut action
					data: "id="+$(this).attr('id'),     // sélection des champs à envoyer
					success: function(msg) {     // callback en cas de succès
					
					// document.location.href="recapitulatif.php";		
					location.reload();
				},
				
				error : function () {
				
					alert ('oops');
				
				}
				
				});
			}
						//datas="ID_PRODUIT="+$(this).attr('id');	
		})								 
		
		
		intopoppanier();
		
		
	//$('#headerzone').before('<p id="au" style="height:100%;background-color:#333;color:#333;padding:20px;font-size:18px;font-weight:bold;text-align:center"></p>');

			
})
		
