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

var blocVeto = (function(){
	return {
		bt : 	{
					id:		"espace_veto",
					inscription :	"inscrireVeto"
				},
		bloc:	{
					id:		"bloc_veto"
				},
		els :	{
					name1:	"login_veto",
					name2:	"pass_veto",
					mess1:	"login",
					mess2:	"mot de passe"
				},
		init : function()
		{
			var o = blocVeto;
			if(!verifIndex() && !$("#"+o.bloc.id).find("p").length)
			{
				//$("#"+o.bloc.id).animate({top:"-80px"},500);
			}
			else if($("#"+o.bloc.id).find("p").length)
			{
			//	$("#"+o.bloc.id).animate({top:"0px"},500);
				var $lien = $("#"+o.bloc.id).attr("class");
				$("#"+o.bt.id).click(function(e)
				{
					e.preventDefault();
					window.location.href = $lien;
				});
			}
			else
				$("#"+o.bloc.id).css("top","-80px");
			
			
			if(!$("#"+o.bloc.id).find("p").length)
			{
				/*$("#"+o.bt.id).toggle(function()
				{
					$("#"+o.bloc.id).animate({
						top:"0px"
					},500);
				},function()
				{
					$("#"+o.bloc.id).animate({
						top:"-80px"
					},500);
				});*/
				checkElements();
			}
			$("#"+o.bt.inscription).click(function(e)
			{
				e.preventDefault();
				inscription();
			});
		}
	}
	function inscription()
	{
		var o = blocVeto;
		
		var n = "";
		n += "<div id='vetoMail'>";
		n += "<h1 class='titre'>Inscrivez vous :</h1>";
		n += "<form action='' method='post' name='mailInscription' >";
		n += "<label for='nom'>Nom : </label><input type='text' class='text' value='' name='nom' /><br />";
		n += "<label for='prenom'>Pr&eacute;nom : </label><input class='text' type='text' value='' name='prenom' /><br />";
		n += "<label for='ville'>Ville : </label><input type='text' class='text' value='' name='ville' /><br />";
		n += "<label for='adresse'>Adresse : </label><input type='text' class='text' value='' name='adresse' /><br />";
		n += "<label for='code_postal'>Code-Postal : </label><input type='text' class='text' value='' name='code_postal' /><br />";
		n += "<label for='tel'>Tel : </label><input class='text' type='text' value='' name='tel' /><br />";
		n += "<label for='mail'>E-mail : </label><input class='text' type='text' value='' name='mail' /><br />";
		n += "<label for='profession'>Profession : </label><input class='text' type='text' value='' name='profession' /><br />";
		n += "<input type='button' class='submit' value='Envoyer' name='validMail' />";		
		n += "</form>";
		n += "</div>";
		$("body").lightBox01(n,"",{Width:500});
		$("#vetoMail").find("input[name=validMail]").click(function()
		{
			$nom = $("#vetoMail").find("input[name=nom]").val();
			$prenom = $("#vetoMail").find("input[name=prenom]").val();
			$ville = $("#vetoMail").find("input[name=ville]").val();
			$adresse = $("#vetoMail").find("input[name=adresse]").val();
			$code_postal = $("#vetoMail").find("input[name=code_postal]").val();
			$tel = $("#vetoMail").find("input[name=tel]").val();
			$mail = $("#vetoMail").find("input[name=mail]").val();
			$profession = $("#vetoMail").find("input[name=profession]").val();
			
			$body = "Nom : "+$nom+"%0A";
			$body += "Prenom : "+$prenom+"%0A";
			$body += "Ville : "+$ville+"%0A";
			$body += "Adresse : "+$adresse+"%0A";
			$body += "Code Postal : "+$code_postal+"%0A";
			$body += "Tel : "+$tel+"%0A";
			$body += "Mail : "+$mail+"%0A";
			$body += "Profession : "+$profession+"%0A";
			
			window.location.href = "mailto:info@lacliniqueducheval.fr?subject=[lacliniqueducheval.fr - Inscription Espace Vétérinaires]&body="+$body;
		});
	}
	function verifIndex()
	{
		Expression = /\?/i;
		return Expression.test(window.location);
	}
	function checkElements()
	{
		var o = blocVeto;
		
		// pour le login
		$("#"+o.bloc.id).find("input[name="+o.els.name1+"]").focus(function()
		{
			$this = $(this);
			if($this.val() == o.els.mess1 )
			{
				$this[0].value = "";
			}
		});
		$("#"+o.bloc.id).find("input[name="+o.els.name1+"]").blur(function()
		{
			$this = $(this);
			if($this.val() == "" )
			{
				$this[0].value = o.els.mess1;
			}
		});
		initEvtMdp();
	}
	function initEvtMdp()
	{
		var o = blocVeto;
		
		// pour le mot de passe
		$("#"+o.bloc.id).find("input[name="+o.els.name2+"]").focus(function()
		{
			$this = $(this);
			if($this.val() == o.els.mess2 )
			{
				$this.replaceWith("<input type='password' name='"+$this.attr("name")+"' id='"+$this.attr("id")+"' class='"+$this.attr("class")+"' value=''>");
				$("#"+o.bloc.id).find("input[name="+o.els.name2+"]").focus();
				initEvtMdp();
			}
		});
		$("#"+o.bloc.id).find("input[name="+o.els.name2+"]").blur(function()
		{
			$this = $(this);
			if($this.val() == "" )
			{
				$this.replaceWith("<input type='text' name='"+$this.attr("name")+"' id='"+$this.attr("id")+"' class='"+$this.attr("class")+"' value='"+ o.els.mess2+"'>");
				initEvtMdp();
			}
		});

	}
})();

