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").show().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 envoie_ami(_idaf) {
	var t = new Date();
	$.get(
		"./envoi_ami.php" , 
		{ idaf: _idaf, t: t.getTime()} , 
		function(data){ $("#envoi_ami").show("fast").html(data); }
	);	
}

function post_ami(_idaf) {
	
	_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").show("fast").html("Envoi en cours ...");
	
	var t = new Date();
	$.post(
		"./ajax_envoi_ami.php" , 
		{ idaf: _idaf, nom: _nom, email: _email, email1: _email1, email2: _email2, email3: _email3, t: t.getTime()} , 
		function(data){ $("#envoi_ami").show("fast").html(data); }
	);	
}

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


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


function reglement(_idAction) {
	$("#reglement").show("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); 
		}
}
//-------------------------------------------

