function verif_mail(m){
	if (m.length < 1) return false;
	var i = m.indexOf('@');
	var j = m.indexOf('.',i);
	var k = m.length-1;
	if(i<1 || j==-1 || (j-i)==1 || j==k){ return false; }else{ return true; }
}
function testImput(type, imput, erreurMsg){
	var ok = true;
	if (type == 'text'){
		if ($(imput).val().length < 1) ok = false;
	}else if (type == 'mail'){
		if ($(imput).val().length < 1) ok = false;
		if (!verif_mail($(imput).val())) ok = false;
	}
	if (ok){
		$(imput).css({ background: '#ffffff' });
		return '';
	}else{
		$(imput).css({ background: '#ff6' });
		return erreurMsg;
	}
}
function chamgePic(){
	var actuBG = $('#photoDeco img').attr('src');
	var souche = actuBG.substring(0,actuBG.lastIndexOf('/')+1);
	var actuImg = actuBG.substring(actuBG.lastIndexOf('/')+1);
	var listImg = new Array('photo1.jpg','photo2.jpg','photo3.jpg','photo4.jpg','photo5.jpg');
	//souche = souche.substring(4,souche.length);
	//actuImg = actuImg.substring(0,actuImg.length-1);
	//alert("actuBG : "+actuBG+"\nsouche : "+souche+"\nactuImg : "+actuImg+"\n");
	for (i=0; i<listImg.length; i=i+1) {
		if (listImg[i] == actuImg){
			var next = i+1;
			if (next >= listImg.length){
				$('#photoDeco img').attr('src',souche+listImg[0]);
			}else{
				$('#photoDeco img').attr('src',souche+listImg[i+1]);
			}
		}
	}
	setTimeout('chamgePic()',5000);
}
$(document).ready(function(){
	setTimeout('chamgePic()',5000);
	/*$('#mainMenu li.a').mousedown(function(){
		document.location.href = $(this).children('a').attr('href');
	});*/
	$('.readNext').mousedown(function(){
		document.location.href = $(this).children('a').attr('href');
	});
	$('#contactForm').submit(
		function(){
			var message = '';
			message+= testImput('text', $('input[@name="nom"]', this), '- Champ "Votre nom" obligatoire<br/>');
			message+= testImput('mail', $('input[@name="mail"]', this), '- Adresse "Votre email" incorrecte<br/>');
			message+= testImput('text', $('textarea[@name="msg"]', this), '- Champ "Votre message" obligatoire<br/>');
			if (message.length > 0){
				$('.error', this).remove();
				$(this).prepend('<div class="error"><h3>Erreur</h3>'+message+'</div>');
				return false;
			}
		}
	);
	$('#tarifsForm').submit(
		function(){
			var message = '';
			message+= testImput('text', $('input[@name="nom"]', this), '- Champ "Votre nom" obligatoire<br/>');
			message+= testImput('mail', $('input[@name="mail"]', this), '- Adresse "Votre email" incorrecte<br/>');
			message+= testImput('text', $('input[@name="entreprise"]', this), '- Champ "Votre entreprise" obligatoire<br/>');
			if (message.length > 0){
				$('.error', this).remove();
				$(this).prepend('<div class="error"><h3>Erreur</h3>'+message+'</div>');
				return false;
			}
		}
	);
	$('#newsletterForm').submit(
		function(){
			var message = '';
			message+= testImput('text', $('input[@name="nom"]', this), '- Champ "Votre nom" obligatoire<br/>');
			message+= testImput('mail', $('input[@name="mail"]', this), '- Adresse "Votre email" incorrecte<br/>');
			if (message.length > 0){
				$('.error', this).remove();
				$(this).prepend('<div class="error"><h3>Erreur</h3>'+message+'</div>');
				return false;
			}
		}
	);
	$('#inscriptionForm').submit(
		function(){
			var message = '';
			message+= testImput('text', $('input[@name="nom"]', this), '- Champ "Nom" obligatoire<br/>');
			message+= testImput('text', $('input[@name="societe"]', this), '- Champ "Soci&eacute;t&eacute;" obligatoire<br/>');
			message+= testImput('mail', $('input[@name="mail"]', this), '- Adresse "Email" incorrecte<br/>');
			message+= testImput('text', $('input[@name="tel"]', this), '- Champ "T&eacute;l&eacute;phone" obligatoire<br/>');
			if (message.length > 0){
				$('.error', this).remove();
				$(this).prepend('<div class="error"><h3>Erreur</h3>'+message+'</div>');
				return false;
			}
		}
	);
})
