// ************************************************************** //
// * Au dela de l'Oraison                                       * //
// ************************************************************** //
// * Copyright (c) 2007-2008                                    * //
// * Web           http://www.samantha-bailly.com               * //
// ************************************************************** //
// ************************************************************** //
// * $ Date: 2007-10-06 19:50:46 +0200 (Sat, 06 Oct 2007)     $ * //
// * $ Developper: Dietrich Christophe                        $ * //
// * $ Developper: DESPORTES Florian                          $ * //
// ************************************************************** //
// ************************************************************** //
// * $ Source: script_contact.js                              $ * //
// * $ Source type: javascript with mootools framework        $ * //
// * $ Works with: includes/contact.inc.php                   $ * //
// ************************************************************** //


window.addEvent("domready", function() {
	$("msg").addEvent("keyup", length_verif);
	$("msg").addEvent("keydown", length_verif);
	$("form").addEvent("submit", check_form);
});


function length_verif() {
	var texte = $("msg").value;
	var taille = texte.length;
	$("longueur").innerHTML = taille;
	if( taille >= 1024 ) {
		$("msg").value = texte.substr(0, 1024);
		$("longueur").innerHTML = 1024;
	}
}


function check_form(evt) {
	var input_nom   = $("nom").value;
	var input_mail  = $("mail").value;
	var input_sujet = $("sujet").value;
	var input_code  = $("code").value;
	var textarea    = $("msg").value;
	if( input_nom == "" || input_mail == "" || input_sujet == "" || input_code == "" || textarea == "" ) {
		evt.preventDefault();
		evt.stopPropagation();
		var texte = "Merci de remplir le(s) champ(s) suivant(s) :\n";
		if( input_nom   == "" ) { texte += "- Nom\n";     $("nom").focus();   }
		if( input_mail  == "" ) { texte += "- Email\n";   $("mail").focus();  }
		if( input_sujet == "" ) { texte += "- Sujet\n";   $("sujet").focus(); }
		if( input_code  == "" ) { texte += "- Code\n";    $("code").focus();  }
		if( textarea    == "" ) { texte += "- Message\n"; $("msg").focus();   }
		alert(texte);
		return false;
	} else {
		return true;
	}
}
