function controlecount(moninput, maxinput, moncounter, mondiv) {
	var montxt=moninput.value;
	var moncount=montxt.length;
	if(moncount==maxinput) {
		document.getElementById(mondiv).style.display="block";
	} else if (moncount>maxinput) {
		moninput.value=montxt.substring(0,maxinput+1);
		moncount=maxinput;
		document.getElementById(mondiv).style.display="block";
	} else {
		document.getElementById(mondiv).style.display="none";
	}
	if(moninput.value == '')
		moncounter.value=0;
	else
		moncounter.value=moncount+1;
}

function ecrireDiv(montexte, mondiv) {
	document.getElementById(mondiv).innerHTML = montexte;
}

function envoyerform(nompage,maform,monaction){
		theform = eval('this.document.'+maform);
		
		var inputs=document.getElementsByTagName("*");
		// Max, Ne rend plus obligatoire, l'insertion du champ faction.
		for (var i=0; i<inputs.length;i++){
			if ( inputs.item(i).name == "faction") {
				theform.faction.value = monaction;
			}
		}

		theform.method = "POST";
		mapage = nompage;
		theform.action = mapage;
		theform.submit();

}

/* Vérification de l'existence du contenu d'un input */
function verifinputjs(moninput, monform, inputname, mondiv, message) {
	leform = eval('this.document.'+monform);
	linput = eval('this.document.'+monform+'.'+inputname);
	
	// variable de controle
	erreur = 1;
	
	/* si l'input est rempli */
	if(linput.value != '') {
		document.getElementById(mondiv).style.display="none";
		ecrireDiv("", mondiv);
		erreur = 1;
	} else {
		document.getElementById(mondiv).style.display="block";
		ecrireDiv(message, mondiv);
		erreur = 2;
	}
	
	/* ne pas envoyer le formulaire si une erreur a été detecté */
	if(erreur == 2)
		return false;
	else
		return true;
}

/* Vérification de l'adresse email */
function verifemailjs(monemail, monform, mondiv, messageobligatoire, messageinvalide) {
	leform = eval('this.document.'+monform);

	monemail = monemail.replace('    ', '');
	monemail = monemail.replace('   ', '');
	monemail = monemail.replace('  ', '');
	monemail = monemail.replace(' ', '');
	leform.email.value=monemail;

	/* si l'email est rempli */
	if(monemail != '') {
		verifformatmailf = verifformatmail(monemail);
		
		if(verifformatmailf == true) {
			/* afficher le div erreur de email et afficher message erreur */
			document.getElementById(mondiv).style.display="none";
			ecrireDiv("", mondiv);
			erreur = 1;
		} else {
			document.getElementById(mondiv).style.display="block";
			ecrireDiv(messageinvalide, mondiv);
			erreur = 2;
		}
	} else {
		/* afficher le div erreur de email et afficher message erreur */
		document.getElementById(mondiv).style.display="block";
		ecrireDiv(messageobligatoire, mondiv);
		erreur = 2;
	}
	
	/* ne pas envoyer le formulaire si une erreur a été detecté */
	if(erreur == 2)
		return false;
	else
		return true;
}

function verifformatmail(email) {
	var reg = new RegExp('^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$', 'i');

	if(reg.test(email)) {
		return(true);
	} else {
		return(false);
	}
}

function orderOfCreation(b) {
	return b+1;
}

function showTooltip(marker, tooltip, left, top) {
	tooltip.innerHTML = marker.tooltip;
	var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.fromDivPixelToLatLng(new GPoint(left,top),true),map.getZoom());
	var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
	var anchor=marker.getIcon().iconAnchor;
	var width=marker.getIcon().iconSize.width;
	var height=tooltip.clientHeight;
	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x - anchor.x + width, offset.y - point.y -anchor.y -height)); 
	pos.apply(tooltip);
	tooltip.style.visibility="visible";
}

// == shows all markers of a particular category, and ensures the checkbox is checked ==
function show(category,gmarkers) {
	for (var i=0; i<gmarkers.length; i++) {
		if (gmarkers[i].mycategory == category) {
			gmarkers[i].show();
		}
	}
	// == check the checkbox ==
	document.getElementById(category+"box").checked = true;
}

// == hides all markers of a particular category, and ensures the checkbox is cleared ==
function hide(category,gmarkers) {
	for (var i=0; i<gmarkers.length; i++) {
		if (gmarkers[i].mycategory == category) {
			gmarkers[i].hide();
		}
	}
	// == clear the checkbox ==
	document.getElementById(category+"box").checked = false;
	// == close the info window, in case its open on a marker that we just hid
	map.closeInfoWindow();
}

// == shows all markers of a particular category, and ensures the checkbox is checked ==
function showmmc(category,gmarkers) {
	for (var i=0; i<gmarkers.length; i++) {
		if (gmarkers[i].mycategory == category) {
			gmarkers[i].show();
		}
	}
}

// == hides all markers of a particular category, and ensures the checkbox is cleared ==
function hidemmc(category,gmarkers) {
	for (var i=0; i<gmarkers.length; i++) {
		if (gmarkers[i].mycategory == category) {
			gmarkers[i].hide();
		}
	}
}

// == a checkbox has been clicked ==
function boxclick(box,category,gmarkers) {
	if (box.checked) {
		show(category,gmarkers);
	} else {
		hide(category,gmarkers);
	}
}

function myclick(i) {
	GEvent.trigger(gmarkers[i],"click");
}

function showlink(monform, moninput, category, gmarkers) {
	theform = eval('this.document.'+monform);
	theinput = eval('this.document.'+monform+'.'+moninput);
	if(theinput.checked==1)
		hide(category,gmarkers);
	else
		show(category,gmarkers);
}

function affichedetailmth(id) {
	w=window.open('http://www.comcolibris.net/pages/acteurs/fiche.php?ID='+id,'mth'+id,'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,width=500,height=470');
	w.focus();
}

function annuaireRetourDepartement() {
	map.setZoom(zoomdepartement);
	masquefichecarte();
}

function annuairePlanAcces() {
	map.setZoom(15);
	masquefichecarte();
}

function supprimerCookieMMC() {
	var pathname=location.pathname;
	var myDomain=pathname.substring(0,pathname.indexOf('/', 0)) +'/';
	var date_exp = new Date();
	date_exp.setTime(date_exp.getTime()+(30*24*3600*1000));
	SetCookie('mmclat','',date_exp,myDomain);
	SetCookie('mmclng','',date_exp,myDomain);
	SetCookie('mmcadresse','',date_exp,myDomain);
}

function supprimerMMC() {
	supprimerCookieMMC();
	
	document.formMMC.adresseA.value = '';
	document.getElementById('linkMMC').style.display='none';
	document.getElementById('formMMC').style.display='block';
}

function supprimerBulleMMC() {
	supprimerCookieMMC();
	
	document.geo.adresseA.value = '';
	window.location.replace("http://www.lemarchecitoyen.net/pages/annuaire/mmc.php#afiche");
}

function selectedMMC() {
	document.geo.adresseA.value = '';
	document.geo.adresseA.focus();
}

function divpro() {
	Modalbox.show('/include/contact/divpro.php', {title: 'Accès LMC pro - Restons en contact !', width: 500});
	Modalbox.deactivate();
	return false;
}
function fermerpro() {
	Modalbox.hide();
	return false;
}
function fformpro(messageobligatoire, messageinvalide) {
	erreuremail = verifemailjs(document.formpro.email.value, 'formpro', 'emailDivE', messageobligatoire, messageinvalide);
	
	if(erreuremail != true) {
		Modalbox.resizeToContent();
		return false;
	} else {
		formproaction = file('/pages/pro/formpro.php', 'email=' + escape(document.formpro.email.value) + '&nom=' + escape(document.formpro.nom.value) + '&fonction=' + escape(document.formpro.fonction.value) + '&region=' + escape(document.formpro.region.value) + '&message=' + escape(document.formpro.message.value));
		if(formproaction == 1) {
			document.getElementById('envoyer').style.display="none";
			document.getElementById('confirmation').style.display="block";
			Modalbox.resizeToContent();
			setTimeout("Modalbox.hide()",2000);
			return true;
		} else {
			return false;
		}
	}
}

