// FONCTIONS POUR L'API GOOGLE MAP
var map;
var i;
if (document.body)
{
	var larg = (document.body.clientWidth);
	var haut = (document.body.clientHeight);
} else {
	var larg = (window.innerWidth);
	var haut = (window.innerHeight);
}

function initialiser(ladiv,x,y,z) {
	if (GBrowserIsCompatible()) {
		this.i=1;
		var map = new GMap2(document.getElementById(ladiv));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.enableScrollWheelZoom();
		map.setCenter(new GLatLng(x,y),z);
		this.map=map;
	}
}

function initialiserplan(ladiv,x,y,z) {
	if (GBrowserIsCompatible()) {
		this.i=1;
		var myPano = new GStreetviewPanorama(document.getElementById("LaVue"));
        GEvent.addListener(myPano, "error", PasdeFlash);
		var map = new GMap2(document.getElementById(ladiv),{ size: new GSize(600,350) } );
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.enableScrollWheelZoom();
		map.disableDoubleClickZoom();
		map.setCenter(new GLatLng(x,y),z);
		svOverlay = new GStreetviewOverlay();
		map.addOverlay(svOverlay);
		GEvent.addListener(map,"click", function(overlay,latlng) {
          myPano.setLocationAndPOV(latlng);
        });
		this.map=map;
	}
}

function PasdeFlash(errorCode) {
	if (errorCode == FLASH_UNAVAILABLE) {
		alert("Votre navigateur ne supporte pas Flash.");
		return;
	}
}

function recentrer(x,y,z) {
	map=this.map;
	map.setCenter(new GLatLng(x,y),z);
}

function glissesur(oux,ouy) {
	map=this.map;
	map.panTo(new GLatLng(oux,ouy));
}

function metpoint(oux,ouy,contenu,option) {
	optage=0;
	if(option!='') {
			optage=1;
			var icone = new GIcon();
			if(option=="pharmacie") {
				icone.image = "themes/defaut/images/g_pharmacie.png";
				icone.iconSize = new GSize(25,25);
				icone.iconAnchor = new GPoint(12,12);
				icone.infoWindowAnchor = new GPoint(12,1);
			}
			if(option=="programme") {
				icone.image = "themes/bleu/images/icones/programme.png";
				icone.iconSize = new GSize(30,31);
				icone.iconAnchor = new GPoint(15,30);
				icone.infoWindowAnchor = new GPoint(15,1);
			}
	}
	map=this.map;
	point=new GLatLng(oux,ouy);
	if(option!='') {
		var marker=new GMarker(point,icone);
	} else {
		var marker=new GMarker(point);
	}
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(contenu);
	});
	map.addOverlay(marker);
}

function metpointdraggable() {
	map=this.map;
	var point = map.getCenter();
	marker = new GMarker(point,{draggable:true});
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml("Point mobile");
	});
	GEvent.addListener(marker, "dragstart", function() {
		marker.closeInfoWindow();
	});
	map.addOverlay(marker);
}

function retaille() {
	if(this.i==1) {
		map=this.map;
		if (document.body)
		{
			var larg = (document.body.clientWidth);
			var haut = (document.body.clientHeight);
		} else {
			var larg = (window.innerWidth);
			var haut = (window.innerHeight);
		}
		document.getElementById('carte').style.width=larg;
		document.getElementById('carte').style.height=haut;
		map.checkResize();
	}
}

function itineraire(div) {
	document.getElementById(div).innerHTML='';
	map=this.map;
	directionsPanel = document.getElementById(div);
	directions = new GDirections(map, directionsPanel);
	directions.load("from: "+document.getElementById('adresse').value+" "+document.getElementById('ville').value+" "+document.getElementById('cp').value+" France to: 21, rue de Lyon 29200 Brest France");
}

function itineraireload() {
	alert('chargez');
}

function itineraireerreur() {
	alert('');
}

// FIN DES FONCTIONS POUR L'API GOOGLE MAP

function Decouvre(ladiv) {
	document.getElementById(ladiv).style.visibility='visible';
}
function Despoil(ladiv,lappel) {
	document.getElementById(ladiv).style.visibility='visible';
	document.getElementById(lappel).style.display='none';
	document.getElementById(lappel).style.position='absolute';
}

function Petelatete(ladiv) {
	document.getElementById(ladiv).style.visibility='hidden';
}

function NouveauTopic(leforum) {
	window.open('index.php?rub=popntopic&forum='+leforum,'','width=750, height=450, scrollbars=no, menubar=no, status=no');
}

function NouveauPost(letopic) {
	window.open('index.php?rub=popnpost&topic='+letopic,'','width=750, height=450, scrollbars=no, menubar=no, status=no');
}

function PopSondage(letopic) {
	window.open('index.php?rub=popsondage','','width=600, height=420, scrollbars=no, menubar=no, status=no');
}

function FermeBulle(){
	document.getElementById('BulLoad').style.visibility='hidden';
}

function Deplie(lid){
	document.getElementById(lid).style.visibility='visible';
	document.getElementById(lid).style.position='fixed';
}

function Replie(lid){
	document.getElementById(lid).style.visibility='hidden';
	document.getElementById(lid).style.position='absolute';
}

function PopChat(){
	window.open('index.php?rub=popchat','','width=830, height=630, scrollbars=no, menubar=no, status=no');
}

function PopNTrajet(){
	window.open('index.php?rub=popntrajet','','width=830, height=630, scrollbars=no, menubar=no, status=no');
}

function CarteDef(ladiv){
	window.open('index.php?rub=popcartedef&ladiv='+ladiv,'','width=600, height=600, scrollbars=no, menubar=no, status=no');
}

function InsereLien(lelien) {
	document.getElementById('apercu').innerHTML="";
	if (window.XMLHttpRequest) {
		fxhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		fxhr = new ActiveXObject("Microsoft.XMLHTTP");   // Internet Explorer
	}
	fxhr.onreadystatechange = function() {
		if (fxhr.readyState == 4) {
			if(fxhr.status  == 200) {
				document.getElementById('apercu').innerHTML=fxhr.responseText;
			} else {
				coderr=fxhr.status;
			}
		}
	}
	fxhr.open("GET","./ajax/inslien.php?lelien="+lelien,true);
	fxhr.send(null);
}

function SondageCharge(sondage,ladiv) {
	var fxhr;
	if (window.XMLHttpRequest) {
		fxhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		fxhr = new ActiveXObject("Microsoft.XMLHTTP");   // Internet Explorer
	}
	fxhr.onreadystatechange = function() {
		if (fxhr.readyState == 4) {
			if(fxhr.status  == 200) {
				document.getElementById(ladiv).innerHTML=fxhr.responseText;
			} else {
				coderr=fxhr.status;
			}
		}
	}
	fxhr.open("GET","./ajax/chargesondage.php?sondage="+sondage,true);
	fxhr.send(null);
}

function VoteSondage(valeur) {
	alert("yo");
}

function VoteSondageSimple(sondage,choix,ladiv) {
	alert(sondage);
	var fxhr;
	if (window.XMLHttpRequest) {
		fxhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		fxhr = new ActiveXObject("Microsoft.XMLHTTP");   // Internet Explorer
	}
	fxhr.onreadystatechange = function() {
		if (fxhr.readyState == 4) {
			if(fxhr.status  == 200) {
				document.getElementById(ladiv).innerHTML=fxhr.responseText;
			} else {
				coderr=fxhr.status;
			}
		}
	}
	fxhr.open("GET","./ajax/votesondage.php",true);
	fxhr.send(null);
}

function Voter(sondage) {
	alert(document.sondage.choix.value);
}

// POUR LA MEF

function mozWrap(txtarea, open, close) {
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2)
		selEnd = selLength;

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + open + s2 + close + s3;
	return;
}

function format(f) {
	if (document.getSelection)  mozWrap(document.leform.texte, "[" + f + "]", "[/" + f + "]");
	else {
		var str = document.selection.createRange().text;
		document.leform.texte.focus();
		var sel = document.selection.createRange();
		sel.text = "[" + f + "]" + str + "[/" + f + "]";
	}
	return;
}

function smile(f) {
	if (document.getSelection)  mozWrap(document.leform.texte, '',''+f+' ');
	else {
		var str = document.selection.createRange().text;
		document.leform.texte.focus();
		var sel = document.selection.createRange();
		sel.text = str + ' ' + f + ' ';
	}
	return;
}

function apercuinser(f) {
	if (document.getSelection)  mozWrap(document.leform.texte, '',''+f+' ');
	else {
		var str = document.selection.createRange().text;
		document.leform.texte.focus();
		var sel = document.selection.createRange();
		sel.text = str + ' ' + f + ' ';
	}
	document.getElementById('apercu').innerHTML='';
	document.getElementById('lelien').value='';
	return;
}

function VerifNTopic() {
	erreurs=0;
	if(document.getElementById("titre").value=="") {
		erreurs++;
		alert("Veuillez saisir un titre");
	}

	if(document.getElementById("texte").value=="") {
		erreurs++;
		alert("Veuillez saisir du texte");
	}
	if(erreurs==0) {
		document.getElementById("previsu").value=0;
		document.leform.submit();
	}
}

function VerifNPost() {
	erreurs=0;
	if(document.getElementById("texte").value=="") {
		erreurs++;
		alert("Veuillez saisir du texte");
	}
	if(erreurs==0) {
		document.getElementById("previsu").value=0;
		document.leform.submit();
	}
}

function PrevisuNPost() {
	erreurs=0;
	if(document.getElementById("texte").value=="") {
		erreurs++;
		alert("Veuillez saisir du texte");
	}
	if(erreurs==0) {
		document.getElementById("previsu").value=1;
		document.leform.submit();
	}
}

function Citer(topic,lepost){
	window.open('index.php?rub=popnpost&topic='+topic+'&cite='+lepost,'','width=750, height=450, scrollbars=no, menubar=no, status=no');
}

function Editer(topic,lepost){
	window.open('index.php?rub=popnpost&topic='+topic+'&edit='+lepost,'','width=750, height=450, scrollbars=no, menubar=no, status=no');
}

function MesSujets() {
	window.open('index.php?rub=popmessujets','','width=400, height=450, scrollbars=no, menubar=no, status=no');
}

function PopaMoman(page){
	opener.location.href=page;
	location.reload(true);
}

function Rappel(topic,message) {
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");   // Internet Explorer
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if(xhr.status  == 200) {
				$.prompt(xhr.responseText);
			} else {
				coderr=xhr.status;
			}
		}
	}
	xhr.open("GET","./ajax/rappel.php?t="+topic+"&m="+message,true);
	xhr.send(null);
}

function RappelHT(message) {
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");   // Internet Explorer
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if(xhr.status  == 200) {
				$.prompt(xhr.responseText);
			} else {
				coderr=xhr.status;
			}
		}
	}
	xhr.open("GET","./ajax/rappelht.php?m="+message,true);
	xhr.send(null);
}

// MOTS FLASH

function ChargementFlash(){
	if (window.XMLHttpRequest) {
		fxhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		fxhr = new ActiveXObject("Microsoft.XMLHTTP");   // Internet Explorer
	}
	fxhr.onreadystatechange = function() {
		if (fxhr.readyState == 4) {
			if(fxhr.status  == 200) {
				document.getElementById('MotsFlash').innerHTML=fxhr.responseText;
				fxhr.close();
			} else {
				coderr=fxhr.status;
			}
		}
	}
	fxhr.open("GET","motsflash.php",true);
	fxhr.send(null);
}

function EnvoiFlash(){
	if (window.XMLHttpRequest) {
		fxhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		fxhr = new ActiveXObject("Microsoft.XMLHTTP");   // Internet Explorer
	}
	fxhr.onreadystatechange = function() {
		if (fxhr.readyState == 4) {
			if(fxhr.status  == 200) {
				document.getElementById('MotsFlash').innerHTML=fxhr.responseText;
			} else {
				coderr=fxhr.status;
			}
		}
	}
	fxhr.open("GET","./ajax/motsflash.php",true);
	fxhr.send(null);
}

// Pour iPhone
function iPhoneAlert() {
	if((navigator.userAgent.match(/iPhone/i))||(navigator.userAgent.match(/iPod/i))) {
		var question = confirm("Voulez-vous la version iPhone du site ?")
		if(question) {
			window.location = "http://i.montreuil.net";
		}
	}
}

// FIN iPhone

function Signaler(topic,post,hash){
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");   // Internet Explorer
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if(xhr.status  == 200) {
				alert(xhr.responseText);
				xhr.close();
			} else {
				coderr=xhr.status;
			}
		}
	}
	xhr.open("GET","./ajax/signaler.php?t="+topic+"&m="+post+"&h="+hash,true);
	xhr.send(null);
}


function Kick(topic,util){
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");   // Internet Explorer
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if(xhr.status  == 200) {
				alert(xhr.responseText);
				xhr.close();
			} else {
				coderr=xhr.status;
			}
		}
	}
	xhr.open("GET","./ajax/kick.php?t="+topic+"&u="+util,true);
	xhr.send(null);
}

function Verrouille(post){
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");   // Internet Explorer
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if(xhr.status  == 200) {
				alert(xhr.responseText);
				xhr.close();
			} else {
				coderr=xhr.status;
			}
		}
	}
	xhr.open("GET","./ajax/lock.php?p="+post,true);
	xhr.send(null);
}

function DeVerrouille(post){
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");   // Internet Explorer
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if(xhr.status  == 200) {
				alert(xhr.responseText);
				xhr.close();
			} else {
				coderr=xhr.status;
			}
		}
	}
	xhr.open("GET","./ajax/unlock.php?p="+post,true);
	xhr.send(null);
}

function CloturerTopic(topic){
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");   // Internet Explorer
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if(xhr.status  == 200) {
				alert(xhr.responseText);
				xhr.close();
			} else {
				coderr=xhr.status;
			}
		}
	}
	xhr.open("GET","./ajax/clotopic.php?t="+topic,true);
	xhr.send(null);
}

function Resolu(topic,post) {
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");   // Internet Explorer
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if(xhr.status  == 200) {
				alert(xhr.responseText);
				xhr.close();
			} else {
				coderr=xhr.status;
			}
		}
	}
	xhr.open("GET","./ajax/resolu.php?t="+topic+"&m="+post,true);
	xhr.open("GET","./ajax/resolu.php?t="+topic+"&m="+post,true);
	xhr.send(null);
}

function CiterPanier(topic,post) {
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");   // Internet Explorer
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if(xhr.status  == 200) {
				alert(xhr.responseText);
				xhr.close();
			} else {
				coderr=xhr.status;
			}
		}
	}
	xhr.open("GET","./ajax/citerpanier.php?t="+topic+"&m="+post,true);
	xhr.send(null);
}

function VidePanier() {
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");   // Internet Explorer
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if(xhr.status  == 200) {
				document.getElementById('texte').innerHTML+=(xhr.responseText);
				xhr.close();
			} else {
				coderr=xhr.status;
			}
		}
	}
	xhr.open("GET","./ajax/videpanier.php",true);
	xhr.send(null);
}
