function affDialog(msg, title){
	$("#dialog").dialog("destroy");
	if (title!="")
	{
		$("#dialog-message").attr("title",title);
	}
	$("#dialog-message .contenu_message").html(msg);
	$("#dialog-message").dialog({
		modal: true,
		buttons: {
			Ok: function() {
				$(this).dialog('close');
			}
		}
	});
}
$(document).ready(function(){
	$("#rechercher").click(function(){
		if ($(this).attr("value")=="Recherche")
		{
			$(this).attr("value","");
		}
	});
	$("#rechercher").blur(function(){
		if ($(this).attr("value")=="")
		{
			$(this).attr("value","Recherche");
		}
	});
	$("#valide_recherche").click(function(){
		if ($("#rechercher").attr("value")=="Recherche")
		{
			$("#rechercher").attr("value","");
		}
		if ($("#rechercher").attr("value")!=""&&$("#rechercher").attr("value").length>3)
		{
			$("#f_rechercher").submit();
		}
		else
		{
			affDialog("Veuillez saisir plus de 3 caracteres.");
			$("#rechercher").focus();
		}
	});
	$("#identifiant_pro").focus(function(){
		if ($(this).attr("value")=="Identifiant")
		{
			$(this).attr("value","");
			$(this).focus();
		}
	});
	$("#mdp_pro").focus(function(){
		if ($(this).attr("value")=="motpasse")
		{
			$(this).attr("value","");
			$(this).focus();
		}
	});
	$("#identifiant").focus(function(){
		if ($(this).attr("value")=="Identifiant")
		{
			$(this).attr("value","");
			$(this).focus();
		}
	});
	$("#mdp").focus(function(){
		if ($(this).attr("value")=="motpasse")
		{
			$(this).attr("value","");
			$(this).focus();
		}
	});
	$("#identifiant_pro,#mdp_pro").keypress(function(event) {
		if(event.keyCode==13)
		{
			if ($("#identifiant_pro").attr("value")!=""&&$("#identifiant_pro").attr("value")!="Identifiant")
			{
				if ($("#mdp_pro").attr("value")!=""&&$("#mdp_pro").attr("value")!="motpasse")
				{
					$.ajax({
						url: '/ajaxVerifComptePro.php',
						type: 'POST',
						data: $("#identifiant_pro").serialize()+"&"+$("#mdp_pro").serialize(),
						success: function(data){
							if (data==1)
							{
								if(window.location.pathname=="/inscription.php"||window.location.pathname=="/mdp_oublie.php"||window.location.pathname=="/mdp_oublie_pro.php")
								{
									window.location="/index.php";
								}
								else
								{
									window.location.reload();
								}
							}
							else
							{
								affDialog("Compte inexistant ou pas encore actif.");
							}
						}
					});
				}
				else
				{
					affDialog("Veuillez saisir un mot de passe");
				}
			}
			else
			{
				affDialog("Veuillez saisir un identifiant");
			}
		}
	});
	$("#identifiant,#mdp").keypress(function(event) {
		if(event.keyCode==13)
		{
			if ($("#identifiant").attr("value")!=""&&$("#identifiant").attr("value")!="Identifiant")
			{
				if ($("#mdp").attr("value")!=""&&$("#mdp").attr("value")!="motpasse")
				{
					$.ajax({
						url: '/ajaxVerifCompteClient.php',
						type: 'POST',
						data: $("#identifiant").serialize()+"&"+$("#mdp").serialize(),
						success: function(data){
							if (data==1)
							{
								if(window.location.pathname=="/inscription.php"||window.location.pathname=="/mdp_oublie.php"||window.location.pathname=="/mdp_oublie_pro.php")
								{
									window.location="/index.php";
								}
								else
								{
									window.location.reload();
								}
							}
							else
							{
								affDialog("Compte inexistant.");
							}
						}
					});
				}
				else
				{
					affDialog("Veuillez saisir un mot de passe");
				}
			}
			else
			{
				affDialog("Veuillez saisir un identifiant");
			}
		}
	});
	$("#connexion_pro").click(function(){
		if ($("#identifiant_pro").attr("value")!=""&&$("#identifiant_pro").attr("value")!="Identifiant")
		{
			if ($("#mdp_pro").attr("value")!=""&&$("#mdp_pro").attr("value")!="motpasse")
			{
				$.ajax({
					url: '/ajaxVerifComptePro.php',
					type: 'POST',
					data: $("#identifiant_pro").serialize()+"&"+$("#mdp_pro").serialize(),
					success: function(data){
						if (data==1)
						{
							if(window.location.pathname=="/inscription.php"||window.location.pathname=="/mdp_oublie.php"||window.location.pathname=="/mdp_oublie_pro.php")
							{
								window.location="/index.php";
							}
							else
							{
								window.location.reload();
							}
						}
						else
						{
							affDialog("Compte inexistant ou pas encore actif.");
						}
					}
				});
			}
			else
			{
				affDialog("Veuillez saisir un mot de passe");
			}
		}
		else
		{
			affDialog("Veuillez saisir un identifiant");
		}
	});
	$("#connexion").click(function(){
		if ($("#identifiant").attr("value")!=""&&$("#identifiant").attr("value")!="Identifiant")
		{
			if ($("#mdp").attr("value")!=""&&$("#mdp").attr("value")!="motpasse")
			{
				$.ajax({
					url: '/ajaxVerifCompteClient.php',
					type: 'POST',
					data: $("#identifiant").serialize()+"&"+$("#mdp").serialize(),
					success: function(data){
						if (data==1)
						{
							if(window.location.pathname=="/inscription.php"||window.location.pathname=="/mdp_oublie.php"||window.location.pathname=="/mdp_oublie_pro.php")
							{
								window.location="/index.php";
							}
							else
							{
								window.location.reload();
							}
						}
						else
						{
							affDialog("Compte inexistant.");
						}
					}
				});
			}
			else
			{
				affDialog("Veuillez saisir un mot de passe");
			}
		}
		else
		{
			affDialog("Veuillez saisir un identifiant");
		}
	});
});
