$(document).ready(function(){


variable = getVar('mail');
formok = getVar('form');

if(variable=="sent"){
popin("<span style='color:#86c246'>Votre demande de contact a bien été enregistrée !</span>");
if(formok=="form1"){ _gaq.push(['_setAccount', 'UA-20895543-2']); _gaq.push(['_trackPageview', 'pagesVirtuelles/formEmailHeader/SubmitOK']); }
if(formok=="form2"){ _gaq.push(['_setAccount', 'UA-20895543-2']); _gaq.push(['_trackPageview', 'pagesVirtuelles/formContact/SubmitOK']); }
} 

var error =0;
$("#form1").submit(function(){
	var mess = "";
	email = $('#email1').val();
	if(VerifForm(email) == false){
		mess += "Veuillez saisir un email valide";
		popin(mess);
		return false;
	}
});

$("#form2").submit(function(){
	var mess = "";
	email = $('#email2').val();
	nom = $('#nom').val();
	prenom = $('#prenom').val();
	tel = $('#tel').val();

	if(nom == "Nom"){mess += "Veuillez saisir votre nom <br />";error = 1;}
	if(prenom == "Prénom"){mess += "Veuillez saisir votre prénom <br />";error = 1;}
	if(VerifForm(email) == false){mess += "Veuillez saisir un email valide <br />";error = 1;}
	if(error == 1){
		popin(mess);
		return false;
	}
});



function VerifForm(adresse){
	var place = adresse.indexOf("@",1);
	var point = adresse.indexOf(".",place+1);
	if ((place > -1)&&(adresse.length >2)&&(point > 1)){
		formulaire.submit();
		return true;
	}
	else{
		return false;
	}
}






 function getVar (nomVariable)
 {
 var infos = location.href.substring(location.href.indexOf("?")+1, location.href.length)+"&"
 if (infos.indexOf("#")!=-1)
 infos = infos.substring(0,infos.indexOf("#"))+"&"
 var variable=0
 {
 nomVariable = nomVariable + "="
 var taille = nomVariable.length
 if (infos.indexOf(nomVariable)!=-1)
 variable = infos.substring(infos.indexOf(nomVariable)+taille,infos.length).substring(0,infos.substring(infos.indexOf(nomVariable)+taille,infos.length).indexOf("&"))
 }
 return variable;
 } 







function popin(mess){
	$.fn.colorbox({width:"400px", height:"110px", html:mess,opacity:0.5,transition:'none'});
	 setTimeout($.fn.colorbox.close, 3000);
}


	$("#email1").focus(function(){
		if($(this).val() == "Tapez votre email ici"){
			$(this).val('');
			$(this).css('color','#333');
		}
	});
	$("#email1").blur(function(){
		if($(this).val() == ""){
			$(this).val('Tapez votre email ici');
			$(this).css('color','#C0C0C0');	
		}
	});

	$("#nom").focus(function(){
		if($(this).val() == "Nom"){
			$(this).val('');
			$(this).css('color','#333');
		}
	});
	$("#nom").blur(function(){
		if($(this).val() == ""){
			$(this).val('Nom');
			$(this).css('color','#C0C0C0');	
		}
	});

	$("#prenom").focus(function(){
		if($(this).val() == "Prénom"){
			$(this).val('');
			$(this).css('color','#333');
		}
	});
	$("#prenom").blur(function(){
		if($(this).val() == ""){
			$(this).val('Prénom');
			$(this).css('color','#C0C0C0');	
		}
	});

	$("#email2").focus(function(){
		if($(this).val() == "Email"){
			$(this).val('');
			$(this).css('color','#333');
		}
	});
	$("#email2").blur(function(){
		if($(this).val() == ""){
			$(this).val('Email');
			$(this).css('color','#C0C0C0');	
		}
	});

	$("#tel").focus(function(){
		if($(this).val() == "Téléphone"){
			$(this).val('');
			$(this).css('color','#333');
		}
	});
	$("#tel").blur(function(){
		if($(this).val() == ""){
			$(this).val('Téléphone');
			$(this).css('color','#C0C0C0');	
		}
	});

});



function getParamValue(param,url)
{
	var u = url == undefined ? document.location.href : url;
	var reg = new RegExp('(\\?|&|^)'+param+'=(.*?)(&|$)');
	matches = u.match(reg);
	if(matches==null){
		return "";
	}
	else{
		return matches[2] != undefined ? decodeURIComponent(matches[2]).replace(/\+/g,' ') : '';
	}
}
