function fbs_click() {
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(location.href)+'&t='+encodeURIComponent(document.title),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function printPage() {
	window.print();
	return false;
}
function showSendMail() {
	document.getElementById( 'errorMail' ).innerHTML = '';
	document.getElementById( 'mail_nom' ).value 		= '';
	document.getElementById( 'mail_from' ).value 		= '';
	document.getElementById( 'mail_to' ).value 			= '';
	document.getElementById( 'mail_message' ).value 	= '';

	var popup 			= document.getElementById( 'sendMail' );
	var scrollOffsets 	= document.viewport.getScrollOffsets();
	var top 			= scrollOffsets[1] + (document.viewport.getHeight() / 10);
	popup.style.top 	= (top < 0) ? "0px" : top + "px";
	
	var overlay = document.getElementById( 'overlay' );
	var pageSize = getPageSize();
	overlay.style.opacity   = 0.8;
	overlay.style.width 	= pageSize[0]+'px';
	overlay.style.height 	= pageSize[1]+'px';

	show('overlay');
	show('sendMail');
	
	return false;
}

function hideSendMail() {
	hide('sendMail');
	hide('overlay');
	
	return false;
}

function sendMail( dataID ) {
	var mail_nom 		= document.getElementById( 'mail_nom' ).value;
	var mail_from 		= document.getElementById( 'mail_from' ).value;
	var mail_to 		= document.getElementById( 'mail_to' ).value;
	var mail_message 	= document.getElementById( 'mail_message' ).value;
	
	var xhr  = getXhr();

	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			var xmlDoc 	= xhr.responseXML.documentElement;
			var rows	= parseFloat( xmlDoc.getElementsByTagName("query")[0].getAttribute('numrows') );
			var errorMessage = '';
			document.getElementById('errorMail').innerHTML = errorMessage;
			var errors = xmlDoc.getElementsByTagName("error");
			var valid = xmlDoc.getElementsByTagName("valid");
			for (var i=0; i < errors.length; i+=1) {
				errorMessage += '<p>'+errors[i].firstChild.nodeValue+'</p>';
			}
			if ( errors.length > 0 )
				document.getElementById('errorMail').innerHTML = errorMessage;
			else if ( valid.length > 0 ) {
				document.getElementById('errorMail').innerHTML = '<p class="valid">'+valid[i].firstChild.nodeValue+'</p>';
			}
		}
	}
	
	xhr.open("POST","/includes/mail.send.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("ID="+dataID+"&mail_nom="+mail_nom+"&mail_from="+mail_from+"&mail_to="+mail_to+"&mail_message="+mail_message);
	
	return false;
}


function showComment() {
	document.getElementById( 'errorComment' ).innerHTML = '';
	document.getElementById( 'code' ).value 			= '';
	document.getElementById( 'pseudo' ).value 			= '';
	document.getElementById( 'comment' ).value 			= '';

	var popup 			= document.getElementById( 'newComment' );
	var scrollOffsets 	= document.viewport.getScrollOffsets();
	var top 			= scrollOffsets[1] + (document.viewport.getHeight() / 10);
	popup.style.top 	= (top < 0) ? "0px" : top + "px";
	
	var overlay = document.getElementById( 'overlay' );
	var pageSize = getPageSize();
	overlay.style.opacity   = 0.8;
	overlay.style.width 	= pageSize[0]+'px';
	overlay.style.height 	= pageSize[1]+'px';

	show('overlay');
	show('newComment');
	
	return false;
}

function hideComment() {
	hide('newComment');
	hide('overlay');
	
	return false;
}

function addComment( dataID, security ) {
	var code 	= document.getElementById( 'code' ).value;
	var pseudo 	= document.getElementById( 'pseudo' ).value;
	var comment = document.getElementById( 'comment' ).value;
	
	var xhr  = getXhr();

	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			var xmlDoc 	= xhr.responseXML.documentElement;
			var rows	= parseFloat( xmlDoc.getElementsByTagName("query")[0].getAttribute('numrows') );
			var errorMessage = '';
			var errors = xmlDoc.getElementsByTagName("error");
			for (var i=0; i < errors.length; i+=1) {
				errorMessage += '<p>'+errors[i].firstChild.nodeValue+'</p>';
			}
			if ( errors.length > 0 )
				document.getElementById('errorComment').innerHTML = errorMessage;
			else {
				hideComment();
				code.value = '';
				pseudo.value = '';
				comment.value = '';
				document.location.reload(true);
			}
		}
	}
	
	xhr.open("POST","/includes/ajax.comment.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("ID="+dataID+"&code="+code+"&pseudo="+pseudo+"&comment="+comment+"&security="+security);
	
	return false;
}

/* OVERLAY PUB */
function initAdOverPage() {
	var canvas 		= document.getElementById( 'adover_canvas' );
	var objImage 	= document.getElementById( 'adover_object' );
	var closebtn	= document.getElementById( 'adover_close' );
	var leftPos		= objImage.width + objImage.offsetLeft-8;
	objImage.style.left = leftPos + 'px';
	closebtn.style.left = String(Number(leftPos-75)) + 'px';
	setTimeout("hideAdOverPage()",10000);
	setCookie('doitinparis-adover','true');
	return false;
}
function hideAdOverPage() {
	hide('adover');
}

function setCookie(c_name,value) {
	var exdate=new Date();
	//exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+";expires=";
}


function hideZoom() {
	hide('image');
	hide('overlay');
	
	var canvas 		= document.getElementById( 'image_canvas' );
	canvas.innerHTML = '';
	
	var image 		= document.getElementById( 'image' );
	image.style.width 		= 500+'px';
	image.style.height 		= 500+'px';
	image.style.marginLeft 	= -500/2+'px';
	
	return false;
}
function zoom( objLink, alt ) {
	var scrollOffsets 	= document.viewport.getScrollOffsets();
	
	var image 		= document.getElementById( 'image' );
	var lightboxTop = scrollOffsets[1] + (document.viewport.getHeight() / 10);
	image.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
	
	var canvas 		= document.getElementById( 'image_canvas' );
	var objImage 	= document.createElement("img");
	canvas.appendChild(objImage);
	show('image');
	
	var overlay = document.getElementById( 'overlay' );
	var pageSize = getPageSize();
	overlay.style.opacity   = 0.8;
	overlay.style.width 	= pageSize[0]+'px';
	overlay.style.height 	= pageSize[1]+'px';
	show('overlay');

	// preload image
	imgPreload = new Image();
	imgPreload.onload=function(){
		var width 	= imgPreload.width;
		var height 	= imgPreload.height;
		
		var lightboxTop 		= scrollOffsets[1] + (document.viewport.getHeight() / 10);
		image.style.width 		= width+'px';
		image.style.height 		= height+'px';
		image.style.marginLeft 	= -width/2+'px';
		image.style.top 		= (lightboxTop < 0) ? "0px" : lightboxTop + "px";

		canvas.style.width 	= width+'px';
		canvas.style.height = height+'px';

		objImage.src = objLink.href;
		show('image_canvas');
		
		var pageSize = getPageSize();
		overlay.style.opacity   = 0.8;
		overlay.style.width 	= pageSize[0]+'px';
		overlay.style.height 	= pageSize[1]+'px';
		
		return false;
	}
	imgPreload.src = objLink.href;
	return false;
}


function getXhr(){
	var xhr = null; 
	
	if (window.XMLHttpRequest) // Firefox et autres
		xhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject){ // Internet Explorer 
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	} else { // XMLHttpRequest non supporté par le navigateur 
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
		xhr = false; 
	} 
	return xhr;
}

function showDependantSelect( selectID, categoryID, value ) {
	var xhr = getXhr();

	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			var resultat = xhr.responseText;
			document.getElementById(selectID).innerHTML = resultat;
		}
	}
	
	xhr.open("POST","/admin/includes/ajax.category.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("ID="+categoryID+"&value="+value);
}

function showAdressesSelect( selectID, categoryID, value ) {
	var xhr = getXhr();

	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			var resultat = xhr.responseText;
			document.getElementById(selectID).innerHTML = resultat;
		}
	}
	
	xhr.open("POST","/admin/includes/ajax.adresses.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("ID="+categoryID+"&value="+value);
}

function showOneOnGoogleMap( id, address ) {
	var xhr = getXhr();

	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			var resultat = xhr.responseText;
			if (GBrowserIsCompatible()) {
				var map = new GMap2(document.getElementById("map_canvas"))
				map.addControl(new GSmallMapControl());
				var geocoder = new GClientGeocoder();
				geocoder.getLatLng(
					address,
					function(point) {
					  if (!point) {
						hideGoogleMap();
					  } else {
						map.setCenter(point, 15);
						var marker = new GMarker(point);
						map.addOverlay(marker);
						GEvent.addListener(marker, "click", function() {
							marker.openInfoWindowHtml( resultat );
						});
						marker.openInfoWindowHtml( resultat );
					  }
					}
				);
			}
		}
	}
	
	xhr.open("POST","/includes/ajax.adresse.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("ID="+id);
}
function showZoneGoogleMap( address ) {
	var canvas = hide('map_canvas');
	
	var map = new GMap2( canvas, {size: new GSize( 500, 500)} );
	map.addControl(new GSmallMapControl());
	map.setCenter(new GLatLng(48.8566667, 2.3509871), 13);

	var geocoder = new GClientGeocoder();
	geocoder.getLatLng(
		address,
		function(point) {
		  if (!point) {
			hideGoogleMap();
		  } else {
			map.setCenter(point, 15);
			show('map_canvas');
		  }
		}
	);
}

function showDetailedGoogleMap( ids, currentid ) {
	var canvas = hide('map_canvas');
	
	var map = new GMap2( canvas, {size: new GSize( 500, 500)} );
	map.addControl(new GSmallMapControl());
	map.setCenter(new GLatLng(48.8566667, 2.3509871), 13);


	GDownloadUrl("/includes/ajax.markers.php?ids="+ids, function(data) {
		var xml 		= GXml.parse(data);
		var markersXML 	= xml.documentElement.getElementsByTagName("marker");
		var markers = [];
		for (var i = 0; i < markersXML.length; i+=1) {
			var xml 	= markersXML[i];
			var id 	 	= parseFloat(xml.getAttribute("id"));
			var name 	= xml.getAttribute("name");
			var url 	= xml.getAttribute("url");
			var lines	= xml.getElementsByTagName("line");
			
			var html 	= '<p>';
			html 		+= '<strong>'+name+'</strong>';
			for (var n=0; n < lines.length; n+=1)
				html += '<br />'+lines[n].firstChild.nodeValue;
			if (url != '')	html += '<br /><a href="http://'+url+'" title"'+name+'">'+url+'</a>';
			html 		+= '</p>';
			
			var point 	= new GLatLng( parseFloat(xml.getAttribute("lat")), parseFloat(xml.getAttribute("lng")) );
			
			var marker  = createMarker( point, html );
			markers.push( marker );
			map.addOverlay(marker);
			if ( id == currentid ) {
				//map.setCenter(point, 15);
				marker.openInfoWindowHtml( html );
			}

		}
		centerMap( map, markers, true );
		show('map_canvas');
	});
}

function createMarker( point, html ) {
	var marker = new GMarker(point);
	GEvent.addListener(marker, "click", function() {
	  marker.openInfoWindowHtml(html);
	});
	return marker;
}

function showGlobalGoogleMap( address ) {
	var overlay = document.getElementById( 'overlay' );
	var pageSize = getPageSize();
	overlay.style.opacity   = 0.8;
	overlay.style.width 	= pageSize[0]+'px';
	overlay.style.height 	= pageSize[1]+'px';
	show('overlay');
	
	var map = show('map');
	var scrollOffsets 	= document.viewport.getScrollOffsets();
	var topValue 		= scrollOffsets[1] + (document.viewport.getHeight() / 10);
	map.style.top		= topValue+'px';
	
	showZoneGoogleMap( address );
	
	return false;
}

function showGoogleMap( currentid, ids ) {
	var overlay = document.getElementById( 'overlay' );
	var pageSize = getPageSize();
	overlay.style.opacity   = 0.8;
	overlay.style.width 	= pageSize[0]+'px';
	overlay.style.height 	= pageSize[1]+'px';
	show('overlay');
	
	var map = show('map');
	var scrollOffsets 	= document.viewport.getScrollOffsets();
	var topValue 		= scrollOffsets[1] + (document.viewport.getHeight() / 10);
	map.style.top		= topValue+'px';
	
	showDetailedGoogleMap( ids, currentid );
	
	return false;
}

function hideGoogleMap() {
	hide('map');
	hide('overlay');
	GUnload();
	return false;
}

function centerMap( map, markers, hasInfo ) {
	for (var i in markers) {
		var this_lat = markers[i].getLatLng().lat() || null;
		var this_lng = markers[i].getLatLng().lng() || null;
		
		if ( (this_lat && !isNaN(this_lat)) && (this_lng && !isNaN(this_lng)) ) {
			var minLat = minLat || this_lat;
			var maxLat = maxLat || this_lat;
			var minLng = minLng || this_lng;
			var maxLng = maxLng || this_lng;
			
			//get min and max markers and save in variables
			minLat = Math.min(minLat, this_lat);
			maxLat = Math.max(maxLat, this_lat);
			minLng = Math.min(minLng, this_lng);
			maxLng = Math.max(maxLng, this_lng);						
		}
	}
	
	//avg of the coordinates
	var centerLat = minLat + ((maxLat - minLat) / 2);
	var centerLng = minLng + ((maxLng - minLng) / 2);

	//what's the distance of our coordinates? (in kilometers)	
	var dist = (6371 * 
					Math.acos(
						Math.sin(minLat / 57.2958) *						 						
						Math.sin(maxLat / 57.2958) + (
							Math.cos(minLat / 57.2958) * 
							Math.cos(maxLat / 57.2958) * 
							Math.cos(maxLng / 57.2958 - minLng / 57.2958)	
						)
					)					
				);
	
	//default zoom level
	var zoomLvl = 10;
	
	//determine the zoom level out of the calculated distance
	if(dist < 24576)
		zoomLvl = 1; 			
	if(dist < 12288)
		zoomLvl = 2; 			
	if(dist < 6144)
		zoomLvl = 3; 			
	if(dist < 3072)
		zoomLvl = 4;			
	if(dist < 1536)
		zoomLvl = 5; 
	if(dist < 768)
		zoomLvl = 6;		
	if(dist < 384)
		zoomLvl = 7;
	if(dist < 192)
		zoomLvl = 8;
	if(dist < 96)
		zoomLvl = 9;		
	if(dist < 48)
		zoomLvl = 10;	
	if(dist < 24)    
		zoomLvl = 11;
	if(dist < 11)    
		zoomLvl = 12;
	if(dist < 4.8)    
		zoomLvl = 13;
	if(dist < 3.2)    
		zoomLvl = 14;		
	if(dist < 1.6)    
		zoomLvl = 15;		
	if(dist < 0.8)
		zoomLvl = 16;		
	if(dist < 0.3)
		zoomLvl = 17;
	
	
    if( hasInfo )
		zoomLvl = zoomLvl-1;
				
	//center map and set zoomLvl
	var point = new GLatLng(centerLat, centerLng);
	map.setCenter(point, zoomLvl);
};	


function hide( id ) {
	var div	= document.getElementById( id );
	div.style.display 	= 'none';
	return div;
}
function show( id ) {
	var div	= document.getElementById( id );
	div.style.display 	= 'block';
	return div;
}

document.viewport = {
	getDimensions: function() {
		var windowWidth, windowHeight;
	
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth 	= document.documentElement.clientWidth;
			windowHeight 	= document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth 	= document.body.clientWidth;
			windowHeight 	= document.body.clientHeight;
		}	
		return { width: windowWidth, height:windowHeight };
	},

	getWidth: function() {
		return this.getDimensions().width;
	},
	
	getHeight: function() {
		return this.getDimensions().height;
	},

	getScrollOffsets: function() {
		return 	[ 
				 window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft, 
				 window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop 
				];
	}
};

function getPosition(oElement) {
if( typeof( oElement.offsetParent ) != 'undefined' ) {
for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ) {
posX += oElement.offsetLeft;
posY += oElement.offsetTop;
}
return [ posX, posY ];
} else {
return [ oElement.x, oElement.y ];
}
}
function getPageSize() {
	        
	var scrollValues 	= getScrollSize();
	var windowValues 	= getWindowSize();
	var scrollPositions = getScrollXY();
	
	var xScroll 	= scrollValues[0], 	yScroll 		= scrollValues[1];
	var windowWidth = windowValues[0], 	windowHeight 	= windowValues[1];
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [ pageWidth, pageHeight, windowWidth, windowHeight, xScroll, yScroll, scrollPositions[0], scrollPositions[1] ];
}

function getWindowSize() {
	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth 	= document.documentElement.clientWidth;
		windowHeight 	= document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth 	= document.body.clientWidth;
		windowHeight 	= document.body.clientHeight;
	}	
	
	return [windowWidth,windowHeight];
}

function getScrollSize() {
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	return [ xScroll, yScroll ];
}

function getScrollXY() {
	var xScroll, yScroll;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		yScroll = window.pageYOffset;
		xScroll = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	}
	return [ xScroll, yScroll ];
}