$(document).ready(function(){
	$(".form-contenu input[type!=submit], .form-contenu textarea").focus(function(){$(this).parent().addClass("focused");});
	$(".form-contenu input[type!=submit], .form-contenu textarea").blur(function(){$(this).parent().removeClass("focused");});
	$(".updateinfosonblur").blur(function(){update_statut(this);});
});

function update_statut(el){
	switch(el.id){
		case "nom":
			if($(el).val()==""){
				if(lang_js=="fr") $($("#nom").parent().parent().find("span.champ-note")[0]).html("<strong>Obligatoire</strong>");
				else $($("#nom").parent().parent().find("span.champ-note")[0]).html("<strong>Required</strong>");
				$("#nom").parent().addClass("wronginput");
			}
			else {
				$($("#nom").parent().parent().find("span.champ-note")[0]).html("<strong class=\"valid\">&nbsp;</strong>");
				$("#nom").parent().removeClass("wronginput");
			}
			break;
		case "num":
			if($(el).val()==""){
				if(lang_js=="fr") $($("#num").parent().parent().find("span.champ-note")[0]).html("<strong>Obligatoire</strong>");
				else $($("#num").parent().parent().find("span.champ-note")[0]).html("<strong>Required</strong>");
				$("#num").parent().addClass("wronginput");
			}
			else {
				$($("#num").parent().parent().find("span.champ-note")[0]).html("<strong class=\"valid\">&nbsp;</strong>");
				$("#num").parent().removeClass("wronginput");
			}
			break;
		case "mail_c":
			if($(el).val()==""){
				if(lang_js=="fr") $($("#mail_c").parent().parent().find("span.champ-note")[0]).html("<strong>Obligatoire</strong>");
				else $($("#mail_c").parent().parent().find("span.champ-note")[0]).html("<strong>Required</strong>");
				$("#mail_c").parent().addClass("wronginput");
			}
			else {
				var mailReg=new RegExp("^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$","");
				if(!$(el).val().match(mailReg)) {
					if(lang_js=="fr") $($("#mail_c").parent().parent().find("span.champ-note")[0]).html("<strong>Adresse incorrecte</strong>");
					else $($("#mail_c").parent().parent().find("span.champ-note")[0]).html("<strong>Wrong adress</strong>");
					$("#mail_c").parent().addClass("wronginput");
				}
				else {
					$($("#mail_c").parent().parent().find("span.champ-note")[0]).html("<strong class=\"valid\">&nbsp;</strong>");
					$("#mail_c").parent().removeClass("wronginput");
				}
			}
			break;
		case "msg":
			if($(el).val()==""){
				if(lang_js=="fr") $($("#msg").parent().parent().find("span.champ-note")[0]).html("<strong>Ecrivez un message</strong>");
				else $($("#msg").parent().parent().find("span.champ-note")[0]).html("<strong>Write something</strong>");
				$("#msg").parent().addClass("wronginput");
			}
			else {
				$($("#msg").parent().parent().find("span.champ-note")[0]).html("<strong class=\"valid\">&nbsp;</strong>");
				$("#msg").parent().removeClass("wronginput");
			}
			break;
	}	
}

function valid_contact(){
	var nom=$("#nom").val();
	var num=$("#num").val();
	var mail_c=$("#mail_c").val();
	var msg=$("#msg").val();
	var antisp=$("#antisp").val();
	var antisp2=$("#antisp2").val();
	
	var error=false;
	// Verif
	if(nom.length==0) {
		$("#nom").parent().addClass("wronginput");
		error=true;
		if(lang_js=="fr") $($("#nom").parent().parent().find("span.champ-note")[0]).html("<strong>Obligatoire</strong>");
		else $($("#nom").parent().parent().find("span.champ-note")[0]).html("<strong>Required</strong>");
	}
	
	if(num.length==0){
		$("#num").parent().addClass("wronginput");
		error=true;
		if(lang_js=="fr") $($("#num").parent().parent().find("span.champ-note")[0]).html("<strong>Obligatoire</strong>");
		else $($("#num").parent().parent().find("span.champ-note")[0]).html("<strong>Required</strong>");
	}
	
	if(mail_c.length==0){
		$("#mail_c").parent().addClass("wronginput");
		error=true;
		if(lang_js=="fr") $($("#mail_c").parent().parent().find("span.champ-note")[0]).html("<strong>Obligatoire</strong>");
		else $($("#mail_c").parent().parent().find("span.champ-note")[0]).html("<strong>Required</strong>");
	}
	else {
		var mailReg=new RegExp("^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$","");
		if(!mail_c.match(mailReg)) {
			$("#mail_c").parent().addClass("wronginput");
			error=true;
			$($("#mail_c").parent().parent().find("span.champ-note")[0]).html("<strong>Adresse in&nbsp;e</strong>");
		}
	}
	
	if(msg.length==0) {
		$("#msg").parent().addClass("wronginput");
		error=true;
		if(lang_js=="fr") $($("#msg").parent().parent().find("span.champ-note")[0]).html("<strong>Ecrivez un message</strong>");
		else $($("#msg").parent().parent().find("span.champ-note")[0]).html("<strong>Write something</strong>");
	}
	
	if(!error && antisp=="" && antisp2==""){
		$.post("/includes/pages/contact.php",{nom:nom, num:num, mail_c:mail_c, msg:msg, posted:2},function(data){
			$("#statut_mail").html("Merci pour votre message, nous vous répondrons dans les plus bref délais.");
			$(".form-contenu input[type!=submit], .form-contenu textarea").val("");
		});
	}
	
}