$(document).ready(function(){
    $(".navigation_title").click(function () {
      $("#menu1").toggle("slide",  {direction: "up" }, 1000);
    });
    
    $(".latestnews_title").click(function () {
      $("#menu2").toggle("slide",  {direction: "up" }, 2000);
    });

    $(".commemoratives_title").click(function () {
      $("#menu3").toggle("slide",  {direction: "up" }, 1000);
    });
  
  
     
    $(".aPays").click(function() {
    	loadDataImg();
$("#content").load(($(this).attr("href")).replace('#pays', 'indexPays.php?idPays='));

$.getScript("plugins/thickbox/thickbox.js");

   });
    
    
     
    var p = window.location.toString();
    if(p.indexOf("#pays") != -1) {
    	loadDataImg();
    	p = p.replace('#pays', 'indexPays.php?idPays=');
    	$("#content").load(p);
    }
    
    if(p.indexOf("#tousLesPays") != -1) {
    	loadDataImg();
    	$("#content").load('tousLesPays.php');
    }

        if(p.indexOf("#toutesLesPieces") != -1) {
    	loadDataImg();
    	$("#content").load('toutesLesPieces.php');
    }
        
        if(p.indexOf("#classeursListe") != -1) {
        	loadDataImg();
        	$("#content").load('classeursListe.php');
        }
        if(p.indexOf("#FAQ") != -1) {
        	loadDataImg();
        	$("#content").load('FAQ.php');
        }
    
        if(p.indexOf("#inscription") != -1) {
    	loadDataImg();
    	$("#content").load('inscription.php');
    }
    
      if(p.indexOf("#contact") != -1) {
    	loadDataImg();
    	$("#content").load('contact.php');
    }

    
    $("#aAllPays").click(function() {
loadDataFromDiese(this);


   });
   
    
    $("#aAllCoins").click(function() {
loadDataFromDiese(this);

   });
   
    $("#aAllStarterKits").click(function() {
loadDataFromDiese(this);

   });
   
    $(".aComm").click(function() {
    	loadDataImg();
$("#content").load(($(this).attr("href")).replace('#commemorative', 'commemo.php?annee='));

   });
    


  });

  
 
   

 $(document).ready(function(){
   $(".navCotation").click(function() {
$("#idCotations").load(($(this).attr("href")).replace('#cotation', 'cotation.php?idPays='));

   });
   
   
   });
  
   
   
  $(document).ready(function(){


   $(".aNav").click(function() {
  
loadDataFromDiese(this);

   });
   
   });
   
  
   function goTo(link) {
   		loadDataImg();
   		$("#content").load(link.replace('#', '') + ".php");
   }
   
   function loadDataImg() {
   		$("#content").empty().append('<div id="idLoadData"><img src="images/ajax-loader.gif" /></div>');
   		goToTop();
   }
   
   function loadDataFromDiese(thiss) {
   	 	loadDataImg();
   		$("#content").load(($(thiss).attr("href")).replace('#', '') + ".php");
   }

   function goToTop() {
	   $('html, body').animate({
			scrollTop: $("body").offset().top
			}, 2000);
   }

// Envoyer un mail pour demander des informations (page contact.php)
   function envoyer() {
   		var vSujet = document.getElementById('idSujet').value;
   		var retSujet = checkFieldById('idSujet');
   		var vMessage = document.getElementById('idMessage').value;
   		var retMess = checkFieldById('idMessage');
   		var vEmail = document.getElementById('idEmail').value;
   		var retEmail = checkFieldEmail('idEmail');
   	
   		if(retSujet &&  retMess) {
   	$(document).ready(function(){
   		$.post("contact.php",
   { email: vEmail , sujet: vSujet , message: vMessage, valide: 'true' },
   function(data){
     document.getElementById("content").innerHTML = data;
     
   }
 );
   	});
   		}
   }
   
   
   function checkFieldById(id) {
   		if(document.getElementById(id).value == "") {
   			document.getElementById(id).style.borderColor = 'red';
   			document.getElementById(id+"Error").innerHTML = "Ce champ est obligatoire.";
   			return false;
   		} else {
   			document.getElementById(id).style.borderColor = '#CCCCCC';
   			document.getElementById(id+"Error").innerHTML = "";
   			return true;
   		}
   }
   
   function checkFieldEmail(id) { // vérification de l'adresse mail
	var email = document.getElementById(id);
	var reg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]{2,}[.][a-zA-Z]{2,4}$/

	if(email.value == "") {
		email.style.borderColor = 'red';
		document.getElementById(id+"Error").innerHTML = "Ce champ est obligatoire.";
		return false;
	} else if (reg.exec(email.value) == null) {
		email.style.borderColor = 'red';
		document.getElementById(id+"Error").innerHTML = "Adresse incorrecte.";
		return false;
	} else {
		email.style.borderColor = '#CCCCCC';
		document.getElementById(id+"Error").innerHTML = "";
		return true;
	}
}

function saveInscription() { // vérification des champs
	
	var vSurname = document.getElementById('idSurname').value;
	var retSurname = checkFieldById('idSurname');
	var vName = document.getElementById('idName').value;
	var retName = checkFieldById('idName');
	var vEmail = document.getElementById('idEmail').value;
   	var retEmail = checkFieldEmail2('idEmail');
   	var vLogin = document.getElementById('idLogin').value;
   	var retLogin = checkFieldLogin2('idLogin');
   	var retCode = ckCode('idCode');
   	
   	var vBirth = document.getElementById('idBirth').value;
   	
	//var ck_login = ckLogin();
	var vPassword = document.getElementById('idPassword').value;
	var retPassword = ckPassword('idPassword');
	
	if(retSurname && retName && retEmail && retPassword && retLogin && retCode) {
		$(document).ready(function(data){
   		$.post("inscription.php",
   { inscriptionOk: 1 , surname: vName , name: vSurname, birth: vBirth, email: vEmail, login: vLogin, password: vPassword}, function(data){
   	 	
   	if(data != 'ok') {
   		tb_show("Inscription échouée", "validation.php?valid=INSCKO&height=110&width=360&KeepThis=true&TB_iframe=true",false);
   	} else {
   		tb_show("Inscription validée", "validation.php?valid=INSCOK&height=110&width=360&KeepThis=true&TB_iframe=true",false);
   	}
   })}
		
	); 
	}
}

function checkFieldEmail2(id) {
	var verif1 = checkFieldEmail(id);
	var vemail = document.getElementById(id).value;
	
	if(verif1) {
	
$(document).ready(function(){
   		$.post("includes/checkExist.php",
   { email: vemail , valide: 'true' },
   function(data){
     if(data == "1") {
     	document.getElementById(id).style.borderColor = 'red';
		document.getElementById(id+"Error").innerHTML = "Cet email est déjà utilisé.";
     	return false;
     } else {
     	document.getElementById(id).style.borderColor = '#CCCCCC';
		document.getElementById(id+"Error").innerHTML = "";
     	return true;
     	
     }
     
   }
 );
   	});
	}
	
	if(document.getElementById(id+"Error").innerHTML == "") {
		return true;
	} else {
		return false;
	}
}


function checkFieldLogin2(id) {
	var verif1 = ckLogin(id);
	var vlogin = document.getElementById(id).value;
	if(verif1) {
	
$(document).ready(function(){
   		$.post("includes/checkExist.php",
   { login: vlogin , valide: 'true' },
   function(data){
     if(data == "1") {
     	document.getElementById(id).style.borderColor = 'red';
		document.getElementById(id+"Error").innerHTML = "Cet login est déjà utilisé.";
		return false;
     } else {
     	document.getElementById(id).style.borderColor = '#CCCCCC';
		document.getElementById(id+"Error").innerHTML = "";
     	return true;
     }
     
   }
 );
   	});
	}
	
	if(document.getElementById(id+"Error").innerHTML == "") {
		return true;
	} else {
		return false;
	}
	
}

function ckLogin(id) { // vérification du login
	var login = document.getElementById(id);
	
	if (login.value == "") {
		login.style.borderColor = 'red';
		document.getElementById(id+"Error").innerHTML = "Ce champ est obligatoire.";
		return false;
	} else if (login.value.length < 5) {
		login.style.borderColor = 'red';
		document.getElementById(id+"Error").innerHTML = "5 caractères minimum.";
		return false;
	} else {
		login.style.borderColor = '';
		document.getElementById(id+"Error").innerHTML = "";
		return true;
	}
}

function ckCode(id) {
	var vCode = document.getElementById(id).value;
	$(document).ready(function(){
   		$.post("plugins/cryptographp_1.4/verifier.php",
   { code: vCode  },
   function(data){
     if(data.substring(0, 4) == "fals") {
     	document.getElementById(id).style.borderColor = 'red';
		document.getElementById(id+"Error").innerHTML = "Le code entré ne correspond pas.";
		return false;
     } else {
     	document.getElementById(id).style.borderColor = '#CCCCCC';
		document.getElementById(id+"Error").innerHTML = "";
     	return true;
     }
   	
     
   }
 );
   	});
   	
   	if(document.getElementById(id+"Error").innerHTML == "") {
		return true;
	} else {
		return false;
	}
   	
}

function unsubscribe() {
	if(confirm("Voulez-vous vraiment vous désinscire ? Si oui, toute votre collection sera supprimée et vous ne pourrez plus y accéder même après une réinscription.")) {
		$(document).ready(function(data){
   		$.post("modificationInformations.php",
   { unsubOk: 1 }, function(data){
   	
   	if(data != 'ok') {
   		tb_show("Désinscription KO", "validation.php?valide=DESINCKO&height=110&width=360&KeepThis=true&TB_iframe=true",false);
   	} else {
   		tb_show("Désinscription OK", "validation.php?valid=DESINCOK&height=110&width=360&KeepThis=true&TB_iframe=true",false);
   	}
   })}
		
	);
	}
}

function ckPassword(id) { // vréification du mot de passe
	var password = document.getElementById(id);
	var password2 = document.getElementById(id+"2");
	var passwordErr = document.getElementById(id+"Error");
	var password2Err = document.getElementById(id+"2Error");
	
	if (password.value != password2.value) {
		password.style.borderColor = 'red';
		password2.style.borderColor = 'red';
		
		
		password2Err.innerHTML = "";
		passwordErr.innerHTML = "Mots de passe différents";
		return false;
	} else if (password.value == "" && password2.value == "") {
		password.style.borderColor = 'red';
		passwordErr.innerHTML = "Ce champ est obligatoire.";
		
		password2.style.borderColor = 'red';
		password2Err.innerHTML = "Ce champ est obligatoire.";
		return false;
	} else if (password.value.length < 5 && password2.value.length < 5) {
		password.style.borderColor = 'red';
		
		passwordErr.innerHTML = "5 caractères minimum.";
		
		password2.style.borderColor = 'red';
		
		password2Err.innerHTML = "5 caractères minimum.";
		
		return false;
	} else {
		password.style.borderColor = '#CCCCCC';
		passwordErr.innerHTML = "";
		
		password2.style.borderColor = '#CCCCCC';
		password2Err.innerHTML = "";
		return true;
	}
}

function loadCotation(id) {
  $(document).ready(function(){
$("#idCotations").load("cotation.php?idPays="+id);

   });
   
}


function loadCotationCom(annee) {
  $(document).ready(function(){
$("#idCotations").load("cotationCommemo.php?annee="+annee);

   });
   
}

function saveMajInfoPerso() {
var vSurname = document.getElementById('idSurname').value;
	var retSurname = checkFieldById('idSurname');
	var vName = document.getElementById('idName').value;
	var retName = checkFieldById('idName');
	var vEmail = document.getElementById('idEmail').value;
	var vOldMail = document.getElementById('idOldMail').value;
   	var retEmail = checkFieldEmail3('idEmail', 'idOldMail');
   	
   	var vBirth = document.getElementById('idBirth').value;
   	
	var vPassword = document.getElementById('idPassword').value;
	var retPassword = ckPassword('idPassword');
	
	if(retSurname && retName && retEmail && retPassword  ) {
		$(document).ready(function(data){
   		$.post("modificationInformations.php",
   { majInfoPersoOk: 1 , surname: vName, name: vSurname , birth: vBirth, email: vEmail, password: vPassword}, function(data){
   	
   	if(data != 'ok') {
   		tb_show("Validation échouée", "validation.php?valid=MAJKO&height=110&width=360&KeepThis=true&TB_iframe=true",false);
   	} else {
   		tb_show("Validation OK", "validation.php?valid=MAJOK&height=110&width=360&KeepThis=true&TB_iframe=true",false);
   	}
   })}
		
	);

	
	
	}
}

function checkFieldEmail3(id, id2) {
	
	if(document.getElementById(id).value != document.getElementById(id2).value) {
	
	var verif1 = checkFieldEmail(id);
	var vemail = document.getElementById(id).value;
	
	if(verif1) {
	
$(document).ready(function(){
   		$.post("includes/checkExist.php",
   { email: vemail , valide: 'true' },
   function(data){
     if(data == "1") {
     	document.getElementById(id).style.borderColor = 'red';
		document.getElementById(id+"Error").innerHTML = "Cet email est déjà utilisé.";
     	return false;
     } else {
     	document.getElementById(id).style.borderColor = '#CCCCCC';
		document.getElementById(id+"Error").innerHTML = "";
     	return true;
     	
     }
     
   }
 );
   	});
	}
	
	if(document.getElementById(id+"Error").innerHTML == "") {
		return true;
	} else {
		return false;
	}
	} else {
		
		document.getElementById(id).style.borderColor = '#CCCCCC';
		document.getElementById(id+"Error").innerHTML = "";
     	return true;
	}
}

function recuIdentifiants() {
	var chkEmail = document.getElementById('idEmail').value;
$(document).ready(function(data){
   		$.post("recuperation.php",
   { recupOK: 1 , emailP: chkEmail }, function(data){
   	 	
   	if(data == 'ok') {
   		tb_show("Identifiants trouvés", "validation.php?valid=IDOK&height=110&width=360&KeepThis=true&TB_iframe=true",false);
   	} else {
   		tb_show("Identifiants introuvables", "validation.php?valid=IDKO&height=110&width=360&KeepThis=true&TB_iframe=true",false);
   	}
   })}
		
	); 
}


