// JavaScript Document
<!--

function checkMail(email)
 {
 var verif = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]{2,}[.][a-zA-Z.]{2,10}$/
 if (verif.exec(email) == null)
 {
 return false;
 }
 else
 {
 return true;
 }

 } 


function uniqid (prefix, more_entropy) {

    if (typeof prefix == 'undefined') {
        prefix = "";
    }
 
   var retId;
    var formatSeed = function (seed, reqWidth) {
        seed = parseInt(seed,10).toString(16); // to hex str
        if (reqWidth < seed.length) { // so long we split
            return seed.slice(seed.length - reqWidth);
        }
        if (reqWidth > seed.length) { // so short we pad
            return Array(1 + (reqWidth - seed.length)).join('0')+seed;
        }
        return seed;
    };
 
    // BEGIN REDUNDANT
    if (!this.php_js) {
        this.php_js = {};
    }
    // END REDUNDANT
    if (!this.php_js.uniqidSeed) { // init seed with big random int
        this.php_js.uniqidSeed = Math.floor(Math.random() * 0x75bcd15);
    }
    this.php_js.uniqidSeed++;
 
    retId  = prefix; // start with prefix, add current milliseconds hex string
    retId += formatSeed(parseInt(new Date().getTime()/1000,10),8);
    retId += formatSeed(this.php_js.uniqidSeed,5); // add seed hex string
 
    if (more_entropy) {
        // for more entropy we add a float lower to 10
        retId += (Math.random()*10).toFixed(8).toString();
   }

    return retId;
}

function trim (myString)
{
return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');
}


function strlen (string) {
 
    var str = string+'';
    var i = 0, chr = '', lgth = 0;
 
    var getWholeChar = function (str, i) {
        var code = str.charCodeAt(i);
        var next = '', prev = '';
        if (0xD800 <= code && code <= 0xDBFF) { 
            if (str.length <= (i+1))  {
                throw 'High surrogate without following low surrogate';
            }
            next = str.charCodeAt(i+1);
            if (0xDC00 > next || next > 0xDFFF) {
                throw 'High surrogate without following low surrogate';
            }
            return str.charAt(i)+str.charAt(i+1);
        } else if (0xDC00 <= code && code <= 0xDFFF) {
            if (i === 0) {
                throw 'Low surrogate without preceding high surrogate';
            }
            prev = str.charCodeAt(i-1);
            if (0xD800 > prev || prev > 0xDBFF) { 
                throw 'Low surrogate without preceding high surrogate';
            }
            return false; 
        }
        return str.charAt(i);
    };
 
    for (i=0, lgth=0; i < str.length; i++) {
        if ((chr = getWholeChar(str, i)) === false) {
            continue;
        } 
        lgth++;
    }
    return lgth;
}





var obj = null;

function checkHover() {
   if (obj) {
      obj.next('.etape').slideUp('fast');
   } //if
} //checkHover

var phrase = 1;

function changePhrase () {
	
		$("#nouveau").animate({opacity:1}, 1000, function(){
			$(this).animate({opacity:0},200, function(){ 
				$(this).animate({opacity:1},200);
				changePhrase()
			});;
		});
		
}

$(document).ready( function () {
	

	$('.titreClick').click(function() {
	  var obj = this;
	  if ($(this).next('.etape').css('display') == "block")
	  {
		  $(this).next('.etape').slideUp('fast');
	  } else
	  {
		  $(this).nextAll('.etape').slideUp('fast');
	  	  $(this).prevAll('.etape').slideUp('fast');
		  $(this).next('.etape').slideDown('fast',function(){$.scrollTo( obj, 400);});
		  
		  //window.alert(this)
	  }
	  
   	 
    
   });
	
	

  	$("input:text, textarea, input:password").each(function(){
        if(this.value == '')
            this.value = this.title;
    });
    $("input:text, textarea, input:password").focus(function(){
        if(this.value == this.title)
            this.value = '';
    });
    $("input:text, textarea, input:password").blur(function(){
        if(this.value == '')
            this.value = this.title;
    });
    $("input:image, input:button, input:submit").click(function(){
        $(this.form.elements).each(function(){
            if(this.type =='text' || this.type =='textarea' || this.type =='password' ){
                if(this.value == this.title && this.title != ''){
                    this.value='';
                }
            }
        });
    });


	
	$(".inputsimu").keyup( function() 
	{
		var chaine = $(this).val();
		var longueur = chaine.length;
		var dernier = chaine.substr(longueur-1);
		if (dernier >= 0 || dernier == ".") 
		{ 
			// action
		}
		else if (dernier == ",")
		{
			$(this).val(chaine.substr(0,longueur-1)+".");
		}
		else 
		{
			$(this).val(chaine.substr(0,longueur-1));
		}
	});

	$("#calculer").mousedown(function()
	{
		$("#demande").css("display","block");
		var total = 0;
		if ($("#18c").val() > 0 || $("#14c").val() > 0 || $("#9c").val() > 0 || $("#dc").val() > 0 || $("#24c").val() > 0 || $("#pc").val() > 0)
		{
			$(".resultat").slideDown("normal", function(){$.scrollTo( "#calculer", 400);});
			$("#18c2").css("display","none");
			$("#14c2").css("display","none");
			$("#9c2").css("display","none");
			$("#dc2").css("display","none");
			$("#24c2").css("display","none");
			$("#pc2").css("display","none");
			if ($("#18c").val() > 0)
			{
				var cours = parseFloat($('#init18C').val());
				$("#18c2").css("display","block");
				$("#18c2 li.champs").text($("#18c").val()+" x "+cours+" €");
				$("#18c2 li.prix").text((parseFloat($("#18c").val())*cours).toFixed(2)+" €");
				total = total + parseFloat($("#18c").val())*cours;
			}
			if ($("#14c").val() > 0)
			{
				var cours = parseFloat($('#init14C').val());
				$("#14c2").css("display","block");
				$("#14c2 li.champs").text($("#14c").val()+" x "+cours+" €");
				$("#14c2 li.prix").text((parseFloat($("#14c").val())*cours).toFixed(2)+" €");
				total = total + parseFloat($("#14c").val())*cours;
			}
			if ($("#9c").val() > 0)
			{
				var cours = parseFloat($('#init9C').val());
				$("#9c2").css("display","block");
				$("#9c2 li.champs").text($("#9c").val()+" x "+cours+" €");
				$("#9c2 li.prix").text((parseFloat($("#9c").val())*cours).toFixed(2)+" €");
				total = total + parseFloat($("#9c").val())*cours;
			}
			
			if ($("#dc").val() > 0)
			{
				var cours = parseFloat($('#initODJ').val());
				$("#dc2").css("display","block");
				$("#dc2 li.champs").text($("#dc").val()+" x "+cours+" €");
				$("#dc2 li.prix").text((parseFloat($("#dc").val())*cours).toFixed(2)+" €");
				total = total + parseFloat($("#dc").val())*cours;
			}
			
			if ($("#24c").val() > 0)
			{
				var cours = parseFloat($('#initOF').val());
				$("#24c2").css("display","block");
				$("#24c2 li.champs").text($("#24c").val()+" x "+cours+" €");
				$("#24c2 li.prix").text((parseFloat($("#24c").val())*cours).toFixed(2)+" €");
				total = total + parseFloat($("#24c").val())*cours;
			}
			
			if ($("#pc").val() > 0)
			{
				var cours = parseFloat($('#initPO').val());
				$("#pc2").css("display","block");
				$("#pc2 li.champs").text($("#pc").val()+" x "+cours+" €");
				$("#pc2 li.prix").text((parseFloat($("#pc").val())*cours).toFixed(2)+" €");
				total = total + parseFloat($("#pc").val())*cours;
			}
			
			if (total < 75)
			{
				$("#demande").css("display","none");		
			}
					
			$("#total li.prix").text(total.toFixed(2)+" €");
			$("#malus span").text((total*.08).toFixed(2));
			$("#remise span").text((total-(total*.08)).toFixed(2));
			
			animateButton();
			
			if (total>=5000)
			{
				window.alert("La valeur de votre Or est supérieure à 5 000 euros, nous vous invitons à nous contacter au 0 811 03 24 54 pour organiser un moyen de transport personnalisé.");
				$("#demande").css("display","none");
			}
			
			if (total< 75)
			{
				window.alert("Merci de bien vouloir noter que nous n’acceptons pas d’objet(s) en Or dont la valeur totale est inférieure à 75 euros.");
				$("#demande").css("display","none");
			}
			
			
			
		} else
		{
			if ($(".resultat").css("display") != "none")
			{
					$(".resultat").slideUp("normal");
			}
		}
	});
	
	var joue = 1;
	var couleur = 1
	function animateButton(){
		if (joue==1) {
			if (couleur == 1) {
				$("#goldissimo").animate({ backgroundColor: "#d4a014" }, 300, function(){ animateButton("#goldissimo") });
				couleur = 0;
			} else {
				$("#goldissimo").animate({ backgroundColor: "#444" }, 300, function(){ animateButton("#goldissimo") });
				couleur = 1;
			}
		} else {
			$("#goldissimo").css("backgroundColor","#d4a014");
		}
	}
	
	function animateCalculer(){
		if (joue==1) {
			if (couleur == 1) {
				$("#calculer").animate({ backgroundColor: "#d4a014" }, 300, function(){ animateCalculer("#calculer") });
				couleur = 0;
			} else {
				$("#calculer").animate({ backgroundColor: "#444" }, 300, function(){ animateCalculer("#calculer") });
				couleur = 1;
			}
		} else {
			$("#calculer").css("backgroundColor","#d4a014");
		}
	}
	
	animateCalculer();
	
	function animateEnvoyer(){
		if (joue==1) {
			if (couleur == 1) {
				$("#envoyer2").animate({ backgroundColor: "#d4a014" }, 300, function(){ animateEnvoyer("#envoyer2") });
				couleur = 0;
			} else {
				$("#envoyer2").animate({ backgroundColor: "#444" }, 300, function(){ animateEnvoyer("#envoyer2") });
				couleur = 1;
			}
		} else {
			$("#envoyer2").css("backgroundColor","#d4a014");
		}
	}
	
	animateEnvoyer();

	$("#goldibouton").bind("mouseenter", function(){
   		joue = 0;
		$("#goldissimo").stop();
		$("#goldissimo").css("backgroundColor","#d4a014");
    });
	
	$("#goldibouton").bind("mouseleave", function(){
    	joue = 1;
		animateButton("#goldissimo")	
    });
	
	$("#goldibouton").bind("click", function(){
    	joue = 0;
		$("#goldissimo").stop();
		$("#goldissimo").css("backgroundColor","#444");
		$("#goldibouton").unbind("mouseenter");
		$("#goldibouton").unbind("mouseleave");
		$("#formulaire").slideDown("fast",function(){$.scrollTo( "#goldissimo", 400)});
    });

	

	$('#outils ul.creer').css({display:'none'});	 
	$('#outils ul li > a[href*=#enregistrer]').click(function() { $('#outils ul.outils').css({backgroundColor:'#ffed00'}).animate({backgroundColor:'#414b56'}, 1000); });
	$('#outils ul li > a[href*=#creer]').click(function() { $('#outils ul.creer').slideToggle('fast'); });					 
							 

	
	
	$('ul.liste').hide();
	$("ul.liste ul.sous").hide();
		$("ul.liste ul.up").show();
		
		// On modifie l'évènement "click" sur les liens dans les items de liste
		// qui portent la classe "toggleSubMenu" :
		$("ul.liste li.toggleSous > a").click( function () {
			
			$("ul.liste li.toggleSous a").removeClass("rouge").addClass("noir");
			
			$(this).removeClass("noir").addClass("rouge");
			var vitesse = 80;
			if ($(this).next("ul.sous:visible").length != 0) {
				$(this).next("ul.sous").slideUp(vitesse);
			}
			// Si le sous-menu est caché, on ferme les autres et on l'affiche :
			else {
				$("ul.liste ul.sous").slideUp(vitesse);
				$(this).next("ul.sous").slideDown(vitesse);
				
			}
			// On empêche le navigateur de suivre le lien :
			return false;
		});
							 
							 
	$('.apercu').css({display:"none"});
	$('.danslaboite').css({display:"none"});
	
	
	
	$('a[href*=#top]').click(function() {
		$.scrollTo( 0, 400);
		
	});
	
	$('.faq-link').click(function() {
		$.scrollTo( $(this).attr('href'), 400);
		return false;
	});
	
	$(document).keydown(function (e) {
		if(e.which == 118) {
			if (document.getElementById('grille').style.display == "block") {
			$('#grille').css({display:"none"});
		} else {
			$('#grille').css({display:"block"});
		}
			return false;
	 }
	});
	    


});
	
	function getWindowHeight() {
			var windowHeight = 0;
			if (typeof(window.innerHeight) == 'number') {
				windowHeight = window.innerHeight;
			}
			else {
				if (document.documentElement && document.documentElement.clientHeight) {
					windowHeight = document.documentElement.clientHeight;
				}
				else {
					if (document.body && document.body.clientHeight) {
						windowHeight = document.body.clientHeight;
					}
				}
			}
			return windowHeight;
		}
		function setFooter() {
			if (document.getElementById) {
				var windowHeight = getWindowHeight();
				if (windowHeight > 0) {
					var headerHeight = document.getElementById('header').offsetHeight;
					var bandeauHeight = document.getElementById('bandeau').offsetHeight;
					var contentHeight = document.getElementById('contenu').offsetHeight;
					var footerElement = document.getElementById('pied');
					var footerHeight  = footerElement.offsetHeight;
					
					if (windowHeight - (headerHeight + bandeauHeight + contentHeight + footerHeight) >= 0) {
						
						document.getElementById('grille').style.height = windowHeight+'px';
						
						
						ie = (navigator.appName == 'Microsoft Internet Explorer');			 
						if (ie) {
							footerElement.style.top = (windowHeight - (headerHeight + bandeauHeight + contentHeight + footerHeight)) + 'px';
						} else {
							$('#pied').animate({top:(windowHeight - (headerHeight + bandeauHeight + contentHeight + footerHeight)) + 'px'}, 200);
						}
					}
					else {
						ie = (navigator.appName == 'Microsoft Internet Explorer');		 
						if (ie) {
							footerElement.style.top = 0 + 'px';
						} else {
							$('#pied').animate({top:0}, 200);
						}
						
						document.getElementById('grille').style.height = headerHeight + bandeauHeight + contentHeight + footerHeight + 'px';
					}
					
					
				
				}
			}
		}

		window.onload = function() {
			setFooter();
			(function(){for(var l=document.links,h=window.location.hostname,i=0,a;a=l[i];i++){if(a.hostname!=h){a.target='_blank';}}})();
		}
		window.onresize = function() {
			setFooter();
			
		}
		





function create_account(){
	
	var nom = trim($('#form-nom').val());
	var prenom = trim($('#form-prenom').val());
	var email = trim($('#form-email').val());
	var email2 = trim($('#form-email2').val());
	var tel = trim($('#form-tel').val());
	var adresse = trim($('#form-adresse').val());
	var ville = trim($('#form-ville').val());
	var cp = trim($('#form-cp').val());
	var pref_reglement = trim($('#form-pref_reglement').val());
	
	//alert(email+'-'+email2);
	
	if(strlen(nom)<1){
		$('#form-error').html("<div>Vous devez indiquer votre nom</div>");	
	}
	
	else
	
	if(strlen(prenom)<1){
		$('#form-error').html("<div>Vous devez indiquer votre prénom</div>");	
	}
	
	else
	
	if(checkMail(email)==false){
		$('#form-error').html("<div>Votre adresse email n'est pas valide</div>");	
	}
	
	else
	
	if(email!=email2){
		$('#form-error').html("<div>Vous avez mal confirmé votre adresse email</div>");	
	}
	
	else
	
	if(strlen(tel)<1){
		$('#form-error').html("<div>Vous devez indiquer votre téléphone</div>");	
	}
	
	else
	
	if(strlen(adresse)<1){
		$('#form-error').html("<div>Vous devez indiquer votre adresse</div>");	
	}
	
	else
	
	if(strlen(ville)<1){
		$('#form-error').html("<div>Vous devez indiquer votre ville</div>");	
	}
	
	else
	
	if(strlen(cp)<1){
		$('#form-error').html("<div>Vous devez indiquer votre code postal</div>");	
	}
	
	else
	
	{
	
	$('#form-error').html("");	
	//$('#form-error').hide();	
	$('#myform').slideUp(300,function(){
		$('#load-account').slideDown(100,function(){
			$('#form-error').load('create_account.php?email='+encodeURIComponent(email)+'&nom='+encodeURIComponent(nom)+'&prenom='+encodeURIComponent(prenom)+'&tel='+encodeURIComponent(tel)+'&adresse='+encodeURIComponent(adresse)+'&ville='+encodeURIComponent(ville)+'&cp='+encodeURIComponent(cp)+'&pref_reglement='+encodeURIComponent(pref_reglement)+'&uid='+uniqid());	
		});	
	});	
}
setFooter();
}






function create_account2(){
	
	var nom = trim($('#form2-nom').val());
	var prenom = trim($('#form2-prenom').val());
	var email = trim($('#form2-email').val());
	var email2 = trim($('#form2-email2').val());
	var tel = trim($('#form2-tel').val());
	var adresse = trim($('#form2-adresse').val());
	var ville = trim($('#form2-ville').val());
	var cp = trim($('#form2-cp').val());
	var pref_reglement = trim($('#form2-pref_reglement').val());
	
	//alert(email+'-'+email2);
	
	if(strlen(nom)<1){
		$('#form2-error').html("<div>Vous devez indiquer votre nom</div>");	
	}
	
	else
	
	if(strlen(prenom)<1){
		$('#form2-error').html("<div>Vous devez indiquer votre prénom</div>");	
	}
	
	else
	
	if(checkMail(email)==false){
		$('#form2-error').html("<div>Votre adresse email n'est pas valide</div>");	
	}
	
	else
	
	if(email!=email2){
		$('#form2-error').html("<div>Vous avez mal confirmé votre adresse email</div>");	
	}
	
	else
	
	if(strlen(tel)<1){
		$('#form2-error').html("<div>Vous devez indiquer votre téléphone</div>");	
	}
	
	else
	
	if(strlen(adresse)<1){
		$('#form2-error').html("<div>Vous devez indiquer votre adresse</div>");	
	}
	
	else
	
	if(strlen(ville)<1){
		$('#form2-error').html("<div>Vous devez indiquer votre ville</div>");	
	}
	
	else
	
	if(strlen(cp)<1){
		$('#form2-error').html("<div>Vous devez indiquer votre code postal</div>");	
	}
	
	else
	
	{
	
	$('#form2-error').html("");	
	//$('#form-error').hide();	
	$('#myform2').slideUp(300,function(){
		$('#load2-account').slideDown(100,function(){
			$('#form2-error').load('create_account.php?email='+encodeURIComponent(email)+'&nom='+encodeURIComponent(nom)+'&prenom='+encodeURIComponent(prenom)+'&tel='+encodeURIComponent(tel)+'&adresse='+encodeURIComponent(adresse)+'&ville='+encodeURIComponent(ville)+'&cp='+encodeURIComponent(cp)+'&pref_reglement='+encodeURIComponent(pref_reglement)+'&uid='+uniqid());	
		});	
	});	
}
setFooter();
}








function newGoldissimo(){
	
	$('#newGoldissimo').hide();
	$('#loader').show();
	$('#actions').load('./modules/1.php?uid='+uniqid(),function(){
		alert("Votre demande de goldissimo a bien été enregistrée");
		window.location='mon-compte-actif.php';
	$('#loader').append("<em>Si vous n'êtes pas redirigé <a href='mon-compte-actif.php'>cliquez-ici</a></em>");	
	});	
	
	setFooter();
}


function majAccount(){
	
	if($('#form-cheque').is(':checked') == true){
		var payment = 1;		
	}
	
	else
	
	{
		var payment = 2;
	}
	
	var nom = trim($('#form-nom').val());
	var prenom = trim($('#form-prenom').val());
	var email = trim($('#form-email').val());
	var tel = trim($('#form-tel').val());
	var adresse = trim($('#form-adresse').val());
	var ville = trim($('#form-ville').val());
	var cp = trim($('#form-cp').val());
	var password = trim($('#form-password').val());
	
	//alert(email+'-'+email2);
	
	if(strlen(nom)<1){
		$('#form-error-account').html("<div>Vous devez indiquer votre nom</div>");	
	}
	
	else
	
	if(strlen(prenom)<1){
		$('#form-error-account').html("<div>Vous devez indiquer votre prénom</div>");	
	}
	
	else
	
	if(checkMail(email)==false){
		$('#form-error-account').html("<div>Votre adresse email n'est pas valide</div>");	
	}

	
	else
	
	if(strlen(password)<6){
		$('#form-error-account').html("<div>le mot de passe doit faire au moins 6 caractères</div>");	
	}
	
	else
	
	if(strlen(password)>30){
		$('#form-error-account').html("<div>le mot de passe doit faire au maximum 30 caractères</div>");	
	}
	
	else
	
	if(strlen(tel)<1){
		$('#form-error-account').html("<div>Vous devez indiquer votre téléphone</div>");	
	}
	
	else
	
	if(strlen(adresse)<1){
		$('#form-error-account').html("<div>Vous devez indiquer votre adresse</div>");	
	}
	
	else
	
	if(strlen(ville)<1){
		$('#form-error-account').html("<div>Vous devez indiquer votre ville</div>");	
	}
	
	else
	
	if(strlen(cp)<1){
		$('#form-error-account').html("<div>Vous devez indiquer votre code postal</div>");	
	}
	
	else
	
	{	
	
	$('#form-error-account').html("");
	
	$('#form-error-account').load('maj_account.php?email='+encodeURIComponent(email)+'&nom='+encodeURIComponent(nom)+'&prenom='+encodeURIComponent(prenom)+'&tel='+encodeURIComponent(tel)+'&adresse='+encodeURIComponent(adresse)+'&ville='+encodeURIComponent(ville)+'&cp='+encodeURIComponent(cp)+'&password='+encodeURIComponent(password)+'&payment='+encodeURIComponent(payment)+'&uid='+uniqid(),function(){
																																																																																										 	$('#maj-load').hide();	setFooter();
																																																																																										 });
	$('#maj-load').show();	
	
	
	}
	
	setFooter();
	
}



function login(){
var log_email = $('#log-email').val();
var log_password = $('#log-password').val();
$('#form-error-account').html('');
if(checkMail(log_email)==true && strlen(log_password)>1){
$('#load-login').show();
$('#form-error-account').load('identify.php?log_email='+encodeURIComponent(log_email)+'&log_password='+encodeURIComponent(log_password),function(){
$('#load-login').hide();
});
}

}


function purgeForm(){
	if($('#keywords').val() == $('#keywords').attr('title')){
		$('#keywords').val('');
	}
}



function checkContactForm(){
	
	
	var nom = trim($('#contact-nom').val());
	var prenom = trim($('#contact-prenom').val());
	var email = trim($('#contact-email').val());
	var email2 = trim($('#contact-email2').val());
	var message = trim($('#contact-message').val());
	
	//alert(email+'-'+email2);
	
	if(strlen(nom)<1){
		$('#form2-error').html("<div>Vous devez indiquer votre nom</div>");	
	}
	
	else
	
	if(strlen(prenom)<1){
		$('#form2-error').html("<div>Vous devez indiquer votre prénom</div>");	
	}
	
	else
	
	if(checkMail(email)==false){
		$('#form2-error').html("<div>Votre adresse email n'est pas valide</div>");	
	}
	
	else
	
	if(email!=email2){
		$('#form2-error').html("<div>Vous avez mal confirmé votre adresse email</div>");	
	}
	
	else
	
	if(strlen(message)<1){
		$('#form2-error').html("<div>Vous devez écrire un message</div>");	
	}
	
	else
	
	{
		$('#myform2').submit();	
	}
	
	
}



function retrievePassword(){
	
	var email = trim($('#contact-email').val());

	if(checkMail(email)==false){
		$('#form2-error').html("<div>Votre adresse email n'est pas valide</div>");	
	}

	else
	
	{
		$('#myform2').submit();	
	}
	
	
}


function deleteVente(id){
	
	if(confirm("Êtes-vous sûr de vouloir retirer cette vente de la liste ?")){
		
		$('#line-'+id).fadeOut(300);
		
		$('#actions').load('delete-vente.php?id='+id);
		
	}
	
	
}




//-->