var regex = new RegExp("[A-Za-z0-9._-]{1,}@[A-Za-z0-9._-]{1,}[.][A-Za-z]{2,}", "gi");
var regex2 = new RegExp("[0-9]{4,}", "gi");
var euro = new RegExp("[0-9]{4,}", "gi");

function valide(evt) {
	var keyCode = evt.which ? evt.which : evt.keyCode;
	var interdit = '€';
	var euro = 'Euro';
	if (interdit.indexOf(String.fromCharCode(keyCode)) >= 0) {
		return false;
	}
}

function contact_web() {	

		_nom = escape(document.contact_annonce.nom.value);
		_email = escape(document.contact_annonce.email.value);
		_msg = escape(document.contact_annonce.message.value);
		
		$.get(
		  "./ajax_contact_web.php" , 
		  { id: _id, email: _email, nom: _nom, message: _msg } , 
		  function(data){ $("#reponses").fadeIn('fast').html(data); }
		 );	
}

function verifChampsImg() {
	compte = 0;
	if (document.formImg.titre.value.search(/\w/) == -1) {
		document.formImg.titre.style.background = "#ffcccc";
		compte++;
	} else document.formImg.titre.style.background = "";
	
	if (document.formImg.texte.value.search(/\w/) == -1) {
		document.formImg.texte.style.background = "#ffcccc";
		compte++;
	} else document.formImg.texte.style.background = "";
		
	if (document.formImg.cropImage.value.search(/\w/) == -1) {
		document.formImg.cropImage.style.background = "#ffcccc";
		compte++;
	} else document.formImg.cropImage.style.background = "";	
		
	if (document.formImg.tags.value.search(/\w/) == -1) {
		document.formImg.tags.style.background = "#ffcccc";
		compte++;
	} else document.formImg.tags.style.background = "";
	
	if (compte > 0) return false;
	else return true;
}

function afficher_image(_id)
{ 
	var t = new Date();
	$.get(
		"./ajax_afficher_image.php" , 
		{ id: _id, t: t.getTime()} , 
		function(data){ $("#image").fadeIn("fast").html(data); }
	);	

}

function ajouter_img(_id, _id_ann, _idAction) {	
	$("#pop_img").fadeIn("fast").html("Chargement ...");	
	$.get(
		"./ajax_post_img.php" , 
		{ idImage: _id, idCompte: _id_ann, idAction: _idAction } , 
		function(data){ $("#pop_img").fadeIn("fast").html(data); }
	);	
} 

function affichePhotos() {    
	$("#photos").fadeIn('fast').html('<img src="images/attente.gif"> Chargement de la galerie ...');    
	$.post(
		"./ajax_galerie.php" , 
		{} , 
		function(data){ $("#photos").html(data); }
	);    
} 

function postPhotos() {    
	$("#photos").fadeIn('fast').html('<img src="images/attente.gif"> Photos en traitement ...');    
	$.post(
		"./ajax_post_img.php" , 
		{} , 
		function(data){ 
			$("#photos").html(data); 
			affichePhotos();
		}
	);    
} 

function envoie_ami(_id, _idf) {
	var t = new Date();
	$.post(
		"./envoi_ami.php" , 
		{ id: _id, idf: _idf, t: t.getTime()} , 
		function(data){ $("#envoi_ami").fadeIn('fast').html(data); }
	);	
}

function envoie_ami_multi(_id, _idf) {
	$("#envoi_ami_multi").slideDown('fast').html("Envoi en cous ...");
	_nom = $("#prenom").val();  
	_email1 = $("#email1").val();
	_email2 = $("#email2").val();  
	_email3 = $("#email3").val();  
	_email4 = $("#email4").val();  
	
	var t = new Date();
	$.post(
		"./ajax_envoi_ami_multi.php" , 
		{ id: _id, idf: _idf, t: t.getTime(),nom: _nom, email1: _email1, email2: _email2, email3: _email3, email4: _email4 } , 
		function(data){ $("#envoi_ami_multi").slideDown('fast').html(data); }
	);    
}

function post_ami(_id, _idf) {
	_nom = escape(document.inviter.nom.value);
	_email = escape(document.inviter.email.value);
	_email1 = escape(document.inviter.email1.value);
	_email2 = escape(document.inviter.email2.value);
	_email3 = escape(document.inviter.email3.value);
	
	$("#envoi_ami").fadeIn('fast').html("Envoi en cours ...");
	
	var t = new Date();
	$.post(
		"./ajax_envoi_ami.php" , 
		{ id: _id, idf: _idf, nom: _nom, email: _email, email1: _email1, email2: _email2, email3: _email3, t: t.getTime()} , 
		function(data){ $("#envoi_ami").fadeIn('fast').html(data); }
	);	
}

function fermer (_div) {
	$("#"+_div).fadeOut("fast");
}

function voter(_idf, _idAction ,_idaf) {
	$.post(
		"./votes.php" , 
		{ idf: _idf, idAction: _idAction, idaf: _idaf} , 
		function(data){ $("#envoi_ami").fadeIn('fast').html(data); }
	);	
}

function reglement(_idAction) {
	$("#reglement").fadeIn('fast');
	$.post(
		"./reglement.php" , 
		{ idAction: _idAction } , 
		function(data){ $("#texte_reg").html(data); }
	);	
}



// limitation de nombre de caractères
var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
	if (window.event&&event.srcElement.value.length>=maxlength)
		return false
	else 
		if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
			var pressedkey=/[a-zA-Z0-9\.\,\/]/ 
			if (pressedkey.test(String.fromCharCode(e.which)))
				e.stopPropagation()
		}
}

function countlimit(maxlength,e,placeholder){
	var theform=eval(placeholder)
	var lengthleft=maxlength-theform.value.length
	var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
	if (window.event||e.target&&e.target==eval(placeholder)){
		if (lengthleft<0)
			theform.value=theform.value.substring(0,maxlength)
		placeholderobj.innerHTML=lengthleft
	}
}

function displaylimit(thename, theid, thelimit){
	var theform=theid!=""? document.getElementById(theid) : thename
	var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b> characteres Maximum.'

	//document.getElementById('limit').innerHTML = limit_text;

	if (document.all){
		eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
		eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
	}
	else 
		if (ns6){
			document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
			document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
		}
}

function Lien() {
	i = document.Choix.Liste.selectedIndex;
	if (i == 0) return;
	url = document.Choix.Liste.options[i].value;
	parent.location.href = url;
}

// --------------------------------------------------------
// sous-menu concours (participer)
// --------------------------------------------------------
var ouvert = 0;
function menu_participer() {
	if (ouvert == 0) {
		$("#menu_participer").slideDown("fast").html("Chargement ...");
		$.post(
			  "./ajax_menu_participer.php" ,
			  {} ,
			  function(data){ $("#menu_participer").slideDown("fast").html(data); }
			 );
		ouvert = 1;
	}
	else {
		fermer('menu_participer');
		ouvert = 0;
	}
}