﻿$(document).ready(function()
{
	// CV accueil
	$("#cvaccueilcv").attr("size", "15");
	$("#cvaccueilsubmit").click(function(){
		$("#formcvaccueil").submit();
	});
	
	//rollover des boutons
	$("#b_menu1").hover(function(){$(this).attr("src", "images/ei_072.gif").css("cursor", "pointer");}, function(){$(this).attr("src", "images/ei_07.gif").css("cursor", "default");});
	$("#b_menu2").hover(function(){$(this).attr("src", "images/ei_082.gif").css("cursor", "pointer");}, function(){$(this).attr("src", "images/ei_08.gif").css("cursor", "default");});
	$("#b_menu3").hover(function(){$(this).attr("src", "images/ei_092.gif").css("cursor", "pointer");}, function(){$(this).attr("src", "images/ei_09.gif").css("cursor", "default");});
	$("#b_menu4").hover(function(){$(this).attr("src", "images/ei_102.gif").css("cursor", "pointer");}, function(){$(this).attr("src", "images/ei_10.gif").css("cursor", "default");});
	$("#b_menu5").hover(function(){$(this).attr("src", "images/ei_112.gif").css("cursor", "pointer");}, function(){$(this).attr("src", "images/ei_11.gif").css("cursor", "default");});
	$("#b_menu6").hover(function(){$(this).attr("src", "images/ei_122.gif").css("cursor", "pointer");}, function(){$(this).attr("src", "images/ei_12.gif").css("cursor", "default");});
	$("#b_menu7").hover(function(){$(this).attr("src", "images/ei_132.gif").css("cursor", "pointer");}, function(){$(this).attr("src", "images/ei_13.gif").css("cursor", "default");});
	$("#b_candidat").hover(function(){$(this).attr("src", "images/chercher2.jpg").css("cursor", "pointer");}, function(){$(this).attr("src", "images/chercher.jpg").css("cursor", "default");});
	$("#b_recruteur").hover(function(){$(this).attr("src", "images/deposer2.jpg").css("cursor", "pointer");}, function(){$(this).attr("src", "images/deposer.jpg").css("cursor", "default");});
	$("#b_recruteuri").hover(function(){$(this).attr("src", "images/sinscrire2.jpg").css("cursor", "pointer");}, function(){$(this).attr("src", "images/sinscrire.jpg").css("cursor", "default");});
	$("#b_candidati").hover(function(){$(this).attr("src", "images/sinscrire2.jpg").css("cursor", "pointer");}, function(){$(this).attr("src", "images/sinscrire.jpg").css("cursor", "default");});
	$("#b_inscription_recruteur").hover(function(){$(this).attr("src", "images/minscrire2.jpg").css("cursor", "pointer");}, function(){$(this).attr("src", "images/minscrire.jpg").css("cursor", "default");});
	$("#b_inscription_candidat").hover(function(){$(this).attr("src", "images/minscrire2.jpg").css("cursor", "pointer");}, function(){$(this).attr("src", "images/minscrire.jpg").css("cursor", "default");});
	$("#b_recruteurr").hover(function(){$(this).attr("src", "images/rechercher2.jpg").css("cursor", "pointer");}, function(){$(this).attr("src", "images/rechercher.jpg").css("cursor", "default");});
	$("#b_candidatr").hover(function(){$(this).attr("src", "images/rechercher2.jpg").css("cursor", "pointer");}, function(){$(this).attr("src", "images/rechercher.jpg").css("cursor", "default");});
	$("#b_connexion").hover(function(){$(this).attr("src", "images/connexion2.jpg").css("cursor", "pointer");}, function(){$(this).attr("src", "images/connexion.jpg").css("cursor", "default");});
	$("#cvaccueilsubmit").hover(function(){$(this).attr("src", "images/boutonaccueilcv2.jpg").css("cursor", "pointer");}, function(){$(this).attr("src", "images/boutonaccueilcv.jpg").css("cursor", "default");});
	
	// Bouton recherche accueuil
	$("#b_candidatr").click(function(){
		$("#recherche_offres").submit();
	});
	$("#b_recruteurr").click(function(){
		$("#recherche_cvs").submit();
	});
	
	// Boutons catégorie
	$("#b_administrateur").click(function(){
		$("#architecte").hide();
		$("#consultant").hide();
		$("#directeur").hide();
		$("#ingenieur").hide();
		$("#responsable").hide();
		$("#technicien").hide();
		$("#administrateur").show("slow");
	});
	$("#b_architecte").click(function(){
		$("#administrateur").hide();
		$("#consultant").hide();
		$("#directeur").hide();
		$("#ingenieur").hide();
		$("#responsable").hide();
		$("#technicien").hide();
		$("#architecte").show("slow");
	});
	$("#b_consultant").click(function(){
		$("#administrateur").hide();
		$("#architecte").hide();
		$("#directeur").hide();
		$("#ingenieur").hide();
		$("#responsable").hide();
		$("#technicien").hide();
		$("#consultant").show("slow");
	});
	$("#b_directeur").click(function(){
		$("#administrateur").hide();
		$("#architecte").hide();
		$("#consultant").hide();
		$("#ingenieur").hide();
		$("#responsable").hide();
		$("#technicien").hide();
		$("#directeur").show("slow");
	});
	$("#b_ingenieur").click(function(){
		$("#administrateur").hide();
		$("#architecte").hide();
		$("#consultant").hide();
		$("#directeur").hide();
		$("#responsable").hide();
		$("#technicien").hide();
		$("#ingenieur").show("slow");
	});
	$("#b_responsable").click(function(){
		$("#administrateur").hide();
		$("#architecte").hide();
		$("#consultant").hide();
		$("#directeur").hide();
		$("#ingenieur").hide();
		$("#technicien").hide();
		$("#responsable").show("slow");
	});
	$("#b_technicien").click(function(){
		$("#administrateur").hide();
		$("#architecte").hide();
		$("#consultant").hide();
		$("#directeur").hide();
		$("#ingenieur").hide();
		$("#responsable").hide();
		$("#technicien").show("slow");
	});
		
	// Bouton options recherche cvs
	$("#b_option_cvs").click(function(){
		$("#b_option_cvs").hide();
		$("#b_moption_cvs").show();
		$("#d_cvs_option").show("slow");
	});
	
	// Bouton masquer options recherche cvs
	$("#b_moption_cvs").click(function(){
		$("#b_moption_cvs").hide();
		$("#b_option_cvs").show();
		$("#d_cvs_option").hide("slow");
	});
	
	// Bouton candidat "Chercher une offre"
	$("#b_candidat").click(function(){
		$("#d_recruteur2").hide();
		$("#b_recruteur").show();
		$("#d_recruteur").show();
		$("#d_candidat").hide();
		$("#b_candidat").hide();
		$("#d_candidat2").show("slow");
	});
	
	// Bouton recruteur "Déposer une offre"
	$("#b_recruteur").click(function(){
		$("#d_candidat2").hide();
		$("#b_candidat").show();
		$("#d_candidat").show();
		$("#d_recruteur").hide();
		$("#b_recruteur").hide();
		$("#d_recruteur2").show("slow");
	});
	
	// Bouton candidat "s'inscrire"
	$("#b_candidati").click(function(){
		$("#td_centre").remove();
		$("#td_recruteur").remove();
		$("#td_centre0").remove();
		$("#td_recruteur0").remove();
		$("#d_candidat2").hide();
		$("#td_candidat")
			.css("width", "670")
			.css("background-image", "url()");
		$("#td_candidat0").hide();
		$("#d_candidati").show("slow");
	});
	
	// Bouton recruteur "s'inscrire"
	$("#b_recruteuri").click(function(){
		$("#td_centre").remove();
		$("#td_candidat").remove();
		$("#td_centre0").remove();
		$("#td_candidat0").remove();
		$("#d_recruteur2").hide();
		$("#td_recruteur")
			.css("width", "670")
			.css("background-image", "url()");
		$("#td_recruteur0").hide();
		$("#d_recruteuri").show("slow");
	});
	
	// Liste déroulante des départements des candidats pendant l'inscription
	$("#dep_candidat").change(function(){
		$("#com_candidat option").remove();
		$("#d_com").show();
		$("#i_com").show();
		$("<option>")
			.attr("value", "")
			.appendTo("#com_candidat");
		$("</option>")
			.appendTo("#com_candidat");
		$.getJSON("get_com.php", { dep_candidat: $("#dep_candidat").val() }, function(data)
		{
			$.each(data.items, function(index,item)
			{
				$("<option>")
					.attr("value", item.commune)
					.attr("id", "opt_candidat_"+item.id)
					.text(item.commune)
					.appendTo("#com_candidat");
				$("</option>")
					.appendTo("#com_candidat");
			});
			$("#com_candidat").show("slow");
		});
	});
	
	// Liste déroulante des départements des recruteurs pendant l'inscription
	$("#dep_recruteur").change(function(){
		$("#com_recruteur option").remove();
		$("#d_com2").show();
		$("#i_com2").show();
		$("<option>")
			.attr("value", "")
			.appendTo("#com_recruteur");
		$("</option>")
			.appendTo("#com_recruteur");
		$.getJSON("get_com.php", { dep_recruteur: $("#dep_recruteur").val() }, function(data)
		{
			$.each(data.items, function(index,item)
			{
				$("<option>")
					.attr("value", item.commune)
					.attr("id", "opt_recruteur_"+item.id)
					.text(item.commune)
					.appendTo("#com_recruteur");
				$("</option>")
					.appendTo("#com_recruteur");
			});
			
			$("#com_recruteur").show("slow");
		});
	});
	
	// Liste déroulante des départements des candidats pendant la recherche
	$("#dep_recherche").change(function(){
		$("#com_recherche option").remove();
		$("#d_com_recherche").show();
		$("<option>")
			.attr("value", "")
			.appendTo("#com_recherche");
		$("</option>")
			.appendTo("#com_recherche");
		$.getJSON("get_com.php", { dep_recherche: $("#dep_recherche").val() }, function(data)
		{
			$.each(data.items, function(index,item)
			{
				$("<option>")
					.attr("value", item.commune)
					.attr("id", "opt_recherche_"+item.id)
					.text(item.commune)
					.appendTo("#com_recherche");
				$("</option>")
					.appendTo("#com_recherche");
			});
			
			$("#com_recherche").show("slow");
		});
	});
	
	// Liste déroulante des communes des recruteurs pendant l'inscription
	$("#com_recruteur").change(function(){
		$("#d_cp2").show();
		$("#i_cp2").show();
		$.getJSON("get_cp.php", { com_recruteur: $("#com_recruteur").val() }, function(data)
		{
			$.each(data.items, function(index,item)
			{
				$("#cp_recruteur")
					.val(item.cp);
			});
		});
		$("#cp_recruteur").show("slow");
	});
	
	// Liste déroulante des communes des candidats pendant l'inscription
	$("#com_candidat").change(function(){
		$("#d_cp").show();
		$("#i_cp").show();
		$.getJSON("get_cp.php", { com_candidat: $("#com_candidat").val() }, function(data)
		{
			$.each(data.items, function(index,item)
			{
				$("#cp_candidat")
					.val(item.cp);
			});
		});
		$("#cp_candidat").show("slow");
	});
	
	// Bouton d'inscription des candidats "Je m'inscris"
	$("#b_inscription_candidat").click(function(){
		$("#erreur_inscription_candidat label").remove();
		$("#erreur_inscription_candidat br").remove();
		$("#erreur_inscription_candidat").hide();
		$("<br />")
			.appendTo("#erreur_inscription_recruteur");
		$("<br />")
			.appendTo("#erreur_inscription_candidat");
		if($("#mdp_candidat").val()=="" || $("#mdp2_candidat").val()=="" || $("#email_candidat").val()=="" || $("#prenom_candidat").val()=="" || $("#nom_candidat").val()=="" || $("#spe_candidat").val()=="")
		{
			$("<label />")
				.text("- Les champs obligatoires marqués d'un astérisque (*) ne sont pas tous remplis.")
				.css("font-size", "12px")
				.css("color", "#ff0000")
				.appendTo("#erreur_inscription_candidat");
			$("<br />")
				.appendTo("#erreur_inscription_candidat");
			$("#erreur_inscription_candidat").show("slow");
		}
		else
		{
			if(!verifEmail($("#email_candidat").val()))
			{
				$("<label />")
					.text("- Votre email est invalide. Vérifiez le format saisie.")
					.css("font-size", "12px")
					.css("color", "#ff0000")
					.appendTo("#erreur_inscription_candidat");
				$("<br />")
					.appendTo("#erreur_inscription_candidat");
				$("#erreur_inscription_candidat").show("slow");
			}
			else
			{
				if($("#mdp_candidat").val()!=$("#mdp2_candidat").val())
				{
					$("<label />")
						.text("- Les deux mots de passe ne sont pas identiques.")
						.css("font-size", "12px")
						.css("color", "#ff0000")
						.appendTo("#erreur_inscription_candidat");
					$("<br />")
						.appendTo("#erreur_inscription_candidat");
					$("#erreur_inscription_candidat").show("slow");
				}
				else
				{
					$.getJSON("inscription.php", { type: "candidat", mdp: $("#mdp_candidat").val(),  email: $("#email_candidat").val(), prenom: $("#prenom_candidat").val(), nom: $("#nom_candidat").val(), departement: $("#dep_candidat").val(), commune: $("#com_candidat").val(), cp: $("#cp_candidat").val(), specialite: $("#spe_candidat").val(), niveau_etude: $("#niveau_etude").val(), experience_pro: $("#experience_pro").val() }, function(data)
					{
						$.each(data.items, function(index,item)
						{
							if(item.erreur==0)
							{
								$("#form_candidat")
									.hide();
								$("#terminer_candidat")
									.show("slow");
							}
							else
							{
								if(item.erreur==1)
								{
									$("<label />")
										.text("- Votre e-mail est déjà enregistré dans notre base. Vérifiez si vous n'avez pas déjà créer un compte auparavant.")
										.css("font-size", "12px")
										.css("color", "#ff0000")
										.appendTo("#erreur_inscription_candidat");
									$("<br />")
										.appendTo("#erreur_inscription_candidat");
									$("#erreur_inscription_candidat").show("slow");
								}
								else
								{
									if(item.erreur==2)
									{
										$("<label />")
											.text("- L'inscription n'a pas pu se terminer. Vérifiez les valeurs entrées (Evitez les caractères spéciaux, Vérifiez par exemple si votre code postal dispose d'une valeur numérique).")
											.css("font-size", "12px")
											.css("color", "#ff0000")
											.appendTo("#erreur_inscription_candidat");
										$("<br />")
											.appendTo("#erreur_inscription_candidat");
										$("#erreur_inscription_candidat").show("slow");
									}
								}
							}
						});
					});
				}
			}
		}
	});
	
	// Bouton d'inscription des recruteurs "Je m'inscris"
	$("#b_inscription_recruteur").click(function(){
		$("#erreur_inscription_recruteur label").remove();
		$("#erreur_inscription_recruteur br").remove();
		$("#erreur_inscription_recruteur").hide();
		$("<br />")
			.appendTo("#erreur_inscription_recruteur");
		if($("#mdp_recruteur").val()=="" || $("#mdp2_recruteur").val()=="" || $("#email_recruteur").val()=="" || $("#prenom_recruteur").val()=="" || $("#nom_recruteur").val()=="" || $("#nom_societe_recruteur").val()=="" || $("#adresse_recruteur").val()=="" || $("#dep_recruteur").val()=="" || $("#commune_recruteur").val()=="" || $("#cp_recruteur").val()=="" || $("#numero_tel_recruteur").val()=="" || $("#nom_societe_recruteur").val()=="")
		{
			$("<label />")
				.text("- Les champs obligatoires marqués d'un astérisque (*) ne sont pas tous remplis.")
				.css("font-size", "12px")
				.css("color", "#ff0000")
				.appendTo("#erreur_inscription_recruteur");
			$("<br />")
				.appendTo("#erreur_inscription_recruteur");
			$("#erreur_inscription_recruteur").show("slow");
		}
		else
		{
			if(!verifEmail($("#email_recruteur").val()))
			{
				$("<label />")
					.text("- Votre email est invalide. Vérifiez le format saisie.")
					.css("font-size", "12px")
					.css("color", "#ff0000")
					.appendTo("#erreur_inscription_recruteur");
				$("<br />")
					.appendTo("#erreur_inscription_recruteur");
				$("#erreur_inscription_recruteur").show("slow");
			}
			else
			{
				if($("#mdp_recruteur").val()!=$("#mdp2_recruteur").val())
				{
					$("<label />")
						.text("- Les deux mots de passe ne sont pas identiques.")
						.css("font-size", "12px")
						.css("color", "#ff0000")
						.appendTo("#erreur_inscription_recruteur");
					$("<br />")
						.appendTo("#erreur_inscription_recruteur");
					$("#erreur_inscription_recruteur").show("slow");
				}
				else
				{
					$.getJSON("inscription.php", { type: "recruteur", mdp: $("#mdp_recruteur").val(),  email: $("#email_recruteur").val(), prenom: $("#prenom_recruteur").val(), nom: $("#nom_recruteur").val(), departement: $("#dep_recruteur").val(), commune: $("#com_recruteur").val(), cp: $("#cp_recruteur").val(), nom_societe: $("#nom_societe_recruteur").val(), adresse: $("#adresse_recruteur").val(), adresse_complement: $("#adresse_complement_recruteur").val(), cp: $("#cp_recruteur").val(), numero_tel: $("#numero_tel_recruteur").val(), nombre_employes: $("#nombre_employes_recruteur").val(), description_societe: $("#description_societe_recruteur").val() }, function(data)
					{
						$.each(data.items, function(index,item)
						{
							if(item.erreur==0)
							{
								$("#form_recruteur")
									.hide();
								$("#terminer_recruteur")
									.show("slow");
							}
							else
							{
								if(item.erreur==1)
								{
									$("<label />")
										.text("- Votre e-mail est déjà enregistré dans notre base. Vérifiez si vous n'avez pas déjà créer un compte auparavant.")
										.css("font-size", "12px")
										.css("color", "#ff0000")
										.appendTo("#erreur_inscription_recruteur");
									$("<br />")
										.appendTo("#erreur_inscription_recruteur");
									$("#erreur_inscription_recruteur").show("slow");
								}
								else
								{
									if(item.erreur==2)
									{
										$("<label />")
											.text("- L'inscription n'a pas pu se terminer. Vérifiez les valeurs entrées (Evitez les caractères spéciaux, Vérifiez par exemple si votre code postal ou votre numéro de téléphone dispose d'une valeur numérique).")
											.css("font-size", "12px")
											.css("color", "#ff0000")
											.appendTo("#erreur_inscription_recruteur");
										$("<br />")
											.appendTo("#erreur_inscription_recruteur");
										$("#erreur_inscription_recruteur").show("slow");
									}
								}
							}
						});
					});
				}
			}
		}
	});
});
