/*** PATH ***/

var GB_ROOT_DIR = ROOT_WEBSITE + "/js/greybox/";
var markerURL = ROOT_WEBSITE + "/images/";

var map = null;
var geocoder = null;
var page = 1;
var dontUpdate = false;

/*** FUNCTION CALLED IN BODY ONLOAD="" ***/

function initialize(value) {

	  var windowOpened = false;
	  
	  if(GBrowserIsCompatible() && document.getElementById("carte_small")) {
	 		 map = new GMap2(document.getElementById("carte_small"));
			
			map.setCenter(new GLatLng(CurrPepLat, CurrPepLon), CurrZoom);
	
			var mapControl = new GSmallZoomControl ();
			map.addControl(mapControl);
	
			// React if the map is moved
			GEvent.addListener(map, "moveend", ListenGenerateMap);
	
			// Initialisation
			ajax('searchPepites.php',makeData(value),generateMap);
	  }

	  if (GBrowserIsCompatible() && document.getElementById("carte_interactive")) { 
	  
			map = new GMap2(document.getElementById("carte_interactive"));
			
			map.setCenter(new GLatLng(CurrPepLat, CurrPepLon), CurrZoom);
	
			map.addMapType(G_PHYSICAL_MAP);
			
			map.setMapType(CurrMapType);
	
			var mapControl = new GMapTypeControl();
			map.addControl(mapControl);
	
			// React if the map is moved
			GEvent.addListener(map, "moveend", ListenGenerateMap);
	
			// Initialisation
			ajax('searchPepites.php',makeData(value),generateMap);
		}

		// Rate system with stars
		NotationSystem();

		// Open external links in a new window
		open_ext_link();

		geocoder = new GClientGeocoder();

		playAudioVideo();	

	  
} 

/*** GOOGLE MAPS MANAGEMENT ***/

function makeData(param) {
var Center = map.getCenter();
  var Limit = map.getBounds();

	if(param && param.substr(0,5) == 'topic') {
		topic = param.substr(6,param.length);
		param = '';
	}
	if(!lang) {
		lang = 'fr';
	}

  var data = 
	param
	+'&Mapzoom='+map.getZoom()
	+'&ctrLat='+Center.lat()
	+'&ctrLon='+Center.lng()
	+'&minLat='+(parseFloat(Limit.getSouthWest().lat())+0)
	+'&maxLat='+(parseFloat(Limit.getNorthEast().lat())-0)
	+'&maxLon='+(parseFloat(Limit.getNorthEast().lng())-0)
	+'&minLon='+(parseFloat(Limit.getSouthWest().lng())+0)
	+'&mapType='+map.getCurrentMapType().getName(true)
	+'&PHPSESSID='+PHPSESSION
	+'&lang='+lang;
	+'&PEP_ID='+CurrPepId

	if(topic) {
		data += '&TOP_ID='+topic;
	}

	if(currUser) {
		data += '&USR_ID='+currUser;
	}

	if(param == 'sort=date') {sort = 'date';}
	else if(param == 'sort=rate') {sort = 'rate';}
	else if(param == 'sort=rank'){sort = 'rank';}
	else {data += '&sort='+sort;}

	if(param && param.substr(0,4) == 'page') {
		page = param.substr(5,param.length);
	}

 return data;
}

function ListenGenerateMap() {
   if(!dontUpdate) {
	ajax('searchPepites.php',makeData(),generateMap);
	}
}

 function generateMap(result) {
		var pepiteInfo;

		// remove overlib popups
		nd(); 

		// tell server if zoom changed and > 8
		if(CurrZoom != map.getZoom()) {
			if(map.getZoom() > 8) {
				ajax('registerVar.php','currZoom='+map.getZoom()+'&PHPSESSID='+PHPSESSION,null);
			}
			else if (CurrZoom > 8) {
				ajax('registerVar.php','currZoom=&PHPSESSID='+PHPSESSION,null);
			}
			CurrZoom = map.getZoom();			
		}

		xmlResult=loadXMLString(result);

		// The current pepite with a blue icon
		var Icons = new Array();
		Icons[0] = new GIcon(G_DEFAULT_ICON, markerURL+"marker-small-transparent.png");
		Icons[0].iconSize = new GSize(10,10);
		Icons[0].shadow = null;
		Icons[0].imageMap = new Array(0,0,0,10,10,10,10,0);
		Icons[0].transparent = markerURL+"marker-small-transparent.png";
		Icons[0].iconAnchor = new GPoint(10, 10);

		Icons[1] = new GIcon(G_DEFAULT_ICON, markerURL+"marker-small-gastronomie.png");
		Icons[2] = new GIcon(G_DEFAULT_ICON, markerURL+"marker-small-nature.png");
		Icons[3] = new GIcon(G_DEFAULT_ICON, markerURL+ "marker-small-patrimoine.png");

		Icons[11] = new GIcon(G_DEFAULT_ICON, markerURL+"marker-small-ici-gastronomie.png");
		Icons[12] = new GIcon(G_DEFAULT_ICON, markerURL+"marker-small-ici-nature.png");
		Icons[13] = new GIcon(G_DEFAULT_ICON, markerURL+ "marker-small-ici-patrimoine.png");
		
		Icons[21] = new GIcon(G_DEFAULT_ICON, markerURL+"picto_poitype_1.png");
		Icons[22] = new GIcon(G_DEFAULT_ICON, markerURL+"picto_poitype_2.png");
		Icons[23] = new GIcon(G_DEFAULT_ICON, markerURL+"picto_poitype_3.png");
		Icons[24] = new GIcon(G_DEFAULT_ICON, markerURL+"picto_poitype_4.png");
		Icons[25] = new GIcon(G_DEFAULT_ICON, markerURL+"picto_poitype_5.png");
		Icons[26] = new GIcon(G_DEFAULT_ICON, markerURL+"picto_poitype_6.png");
		
		Icons[31] = new GIcon(G_DEFAULT_ICON, markerURL+"picto_poitype_1-ici.png");
		Icons[32] = new GIcon(G_DEFAULT_ICON, markerURL+"picto_poitype_2-ici.png");
		Icons[33] = new GIcon(G_DEFAULT_ICON, markerURL+"picto_poitype_3-ici.png");
		Icons[34] = new GIcon(G_DEFAULT_ICON, markerURL+"picto_poitype_4-ici.png");
		Icons[35] = new GIcon(G_DEFAULT_ICON, markerURL+"picto_poitype_5-ici.png");
		Icons[36] = new GIcon(G_DEFAULT_ICON, markerURL+"picto_poitype_6-ici.png");


		for(i=1; i<=3; i++) {
			Icons[i].iconSize = new GSize(12,12);
			Icons[i].shadow = null;
			Icons[i].imageMap = new Array(5,5,5,15,15,15,15,5);
			Icons[i].transparent = markerURL+"marker-small-transparent.png";
			Icons[i].iconAnchor = new GPoint(12, 12);
		}

		for(i=11; i<=13; i++) {
			Icons[i].iconSize = new GSize(29,29);
			Icons[i].shadow = null;
			Icons[i].imageMap = new Array(5,5,5,24,24,24,24,5);
			Icons[i].transparent = markerURL+"marker-small-ici-transparent.png";
			Icons[i].iconAnchor = new GPoint(15, 15);
		}
		
		for(i=21; i<=26; i++) {
			Icons[i].iconSize = new GSize(20,20);
			Icons[i].shadow = null;
			Icons[i].imageMap = new Array(5,5,5,24,24,24,24,5);
			Icons[i].transparent = markerURL+"marker-small-ici-transparent.png";
			Icons[i].iconAnchor = new GPoint(15, 15);
		}
		
		for(i=31; i<=36; i++) {
			Icons[i].iconSize = new GSize(29,29);
			Icons[i].shadow = null;
			Icons[i].imageMap = new Array(5,5,5,24,24,24,24,5);
			Icons[i].transparent = markerURL+"marker-small-ici-transparent.png";
			Icons[i].iconAnchor = new GPoint(15, 15);
		}
		

		map.clearOverlays();
		var marker = new Array();
		var content = new Array();
		var url = new Array();
		var pepLat = null;
		var pepLon = null;
		var pepUrl= null; 
		var pepId = null;
		var pepTopic = null;
		var pepPoiClass =null;
		var pepClass = null;
		var pepTitle = null;
		var pepPicture = null;
		
		var tableau = xmlResult.getElementsByTagName("pepite");

		/*if(tableau[0]) { // There is at least one Pepite
			// Only reload if there is a change && new pepite is current one
			var NewPepId = tableau[0].getElementsByTagName("id")[0].childNodes[0].nodeValue;			
			if(typeof(tableau[0].getElementsByTagName("current")[0]) != 'undefined' && NewPepId && CurrPepId != NewPepId) {
				ajax('getPepite.php','PEP_ID='+NewPepId,
				function(html) {
					document.getElementById("article").innerHTML = html; 
					NotationSystem();
					open_ext_link();
					statAddPage();
					playAudioVideo();
				});
				CurrPepId = NewPepId;
			}
		}
		else {
			ajax('getPepite.php','USR_ID='+currUser, function(html) {document.getElementById("article").innerHTML = html;});
		}*/

		if(CurrPepId && CurrPepLat && CurrPepLon) {
			var latlng = new GLatLng(CurrPepLat, CurrPepLon);
			if(CurrClass==1){
				markerCurr = new GMarker(latlng, { icon:Icons[CurrTopic + 10] });
			}
			else{
			    markerCurr = new GMarker(latlng, { icon:Icons[CurrPoiType + 30] });
			}
			map.addOverlay(markerCurr);
		}

		for (var i=tableau.length-1; i>=0; i--) {

			
			 pepId = tableau[i].getElementsByTagName("id")[0].childNodes[0].nodeValue;
			 pepLon = tableau[i].getElementsByTagName("lon")[0].childNodes[0].nodeValue;
			 pepLat = tableau[i].getElementsByTagName("lat")[0].childNodes[0].nodeValue;
			 pepUrl = tableau[i].getElementsByTagName("url")[0].childNodes[0].nodeValue;
			 pepTopic = tableau[i].getElementsByTagName("topic")[0].childNodes[0].nodeValue;
			 pepPoiType = tableau[i].getElementsByTagName("poiType")[0].childNodes[0].nodeValue;
			 pepClass = tableau[i].getElementsByTagName("class")[0].childNodes[0].nodeValue;
			 pepTitle = tableau[i].getElementsByTagName("title")[0].childNodes[0].nodeValue;
			
			 if(tableau[i].getElementsByTagName("picture")[0].childNodes[0]) {
				 pepPicture = tableau[i].getElementsByTagName("picture")[0].childNodes[0].nodeValue;
			 }
			 else {
				pepPicture = null;
			 }

			
		
			
			 if(pepId) {
				  var latlng = new GLatLng(pepLat, pepLon);

				  url[pepId] = pepUrl;
				  content[pepId] = '<img src="photos/'+pepPicture+'_thumb.jpg"><br>'+pepTitle;

					
				//if gem is the current gem
				if(parseInt(pepId)==parseInt(CurrPepId)){
					 marker[i] = new GMarker(latlng, {icon:Icons[0]});
						
				}
				else{				
					//if address
					if(pepClass==0){
						 
						 marker[i] = new GMarker(latlng,  {icon:Icons[parseInt(pepPoiType)+ 20]} );
					}
					//gem
					else{
					   	marker[i] = new GMarker(latlng,  {icon:Icons[pepTopic]} );
					}
					
					marker[i].pepId = parseInt(pepId);
				}
				 
				marker[i].pepId = parseInt(pepId);  
			
				  map.addOverlay(marker[i]);
				  
					  GEvent.addListener(marker[i], "click", function() {	
						//ajax('searchPepites.php', url[this.pepId],generateMap);
						document.location = url[this.pepId];
						});

					  GEvent.addListener(marker[i], "mouseover", function() {
						   overlib(content[this.pepId], FGCOLOR, '#e2e1df', BGCOLOR, '#005692');
						 });

					  GEvent.addListener(marker[i], "mouseout", function() {
						  nd();
						 });
				}
		}


			
			
		// Center map on selected POI if there is

		/*if(tableau[0] && tableau[0].getElementsByTagName("mode")[0].childNodes[0].nodeValue == 'fromId') {
			dontUpdate = true;
			var zoomLevel = map.getZoom();
			if(zoomLevel < 8) {
				map.setCenter(new GLatLng(tableau[0].getElementsByTagName("lat")[0].childNodes[0].nodeValue, tableau[0].getElementsByTagName("lon")[0].childNodes[0].nodeValue), 8);
			}
			else {
				map.setCenter(new GLatLng(tableau[0].getElementsByTagName("lat")[0].childNodes[0].nodeValue, tableau[0].getElementsByTagName("lon")[0].childNodes[0].nodeValue));
			}
			dontUpdate = false;				
		}*/

		// If Main page of user center and zoom on his own pepites
		
		/*if(tableau[0] && tableau[0].getElementsByTagName("mode")[0].childNodes[0].nodeValue == 'fromUser') {
			dontUpdate = true;
			var minLat = tableau[0].getElementsByTagName("lat")[0].childNodes[0].nodeValue;
			var maxLat = tableau[0].getElementsByTagName("lat")[0].childNodes[0].nodeValue;
			var minLon = tableau[0].getElementsByTagName("lon")[0].childNodes[0].nodeValue;
			var maxLon = tableau[0].getElementsByTagName("lon")[0].childNodes[0].nodeValue;
			var currLat;
			var currLon;
			var newZoom;

			// Looking for min/max lon/lat
			for (var i=tableau.length-1; i>=0; i--) {
				currLat = parseFloat(tableau[i].getElementsByTagName("lat")[0].childNodes[0].nodeValue);
				if(currLat > maxLat) {maxLat = currLat;}
				if(currLat < minLat) {minLat = currLat;}

				currLon = parseFloat(tableau[i].getElementsByTagName("lon")[0].childNodes[0].nodeValue);
				if(currLon > maxLon) {maxLon = currLon;}
				if(currLon < minLon) {minLon = currLon;}
			}

			newZoom = map.getBoundsZoomLevel(
				new GLatLngBounds(
					new GLatLng(maxLat,minLon), 
					new GLatLng(minLat,maxLon)
				)
			);

			map.setCenter(new GLatLng((parseFloat(minLat)+parseFloat(maxLat))/2, (parseFloat(minLon)+parseFloat(maxLon))/2), newZoom);
			
			dontUpdate = false;				
		}*/

		var pageManagement = '';
		
		window.document.getElementById('pepites').innerHTML = xmlResult.getElementsByTagName("listHTML")[0].childNodes[0].nodeValue + pageManagement; //'<XMP>'+result+'</XMP>'; 
		if(window.document.getElementById('sort')) window.document.getElementById('sort').value = sort;
		
	}

function showAddress(address) {
      if (geocoder) {
        geocoder.getLocations(address+' France', goToAddress); 
      }
    }

 function goToAddress(response) {
	if (!response || response.Status.code != 200) {
		alert('Destination introuvable');
	  } else {
		place = response.Placemark[0];
		accuracy = place.AddressDetails.Accuracy;

		if(accuracy >= 6 ) {
			zoom = 13;
		}
		else if(accuracy >= 3 ) {
			zoom = 9;
		}
		else {
			zoom = 6;
		}

		point = new GLatLng(place.Point.coordinates[1],	place.Point.coordinates[0]);
		map.setCenter(point, zoom);
	  }
 }

/***** MISC ********/

function getElementsByClass(node,searchClass,tag) {
	var classElements = new Array();
	var els = node.getElementsByTagName(tag); // use "*" for all elements
	var elsLen = els.length;
	var pattern = new RegExp("\\b"+searchClass+"\\b");
	for (ii = 0, j = 0; ii < elsLen; ii++) {
		 if ( pattern.test(els[ii].className) ) {
		 classElements[j] = els[ii] ;
		 j++;
		}
	}
	return classElements;
}

function show(id) {

	var tags = getElementsByClass(document,'corps_infos_interieur','span');
	var tagslen = tags.length;

	for(i=0;i<tagslen;i++) {
		subid = tags[i].id.substring(7,tags[i].id.length);
		if(subid != id) {
			tags[i].style.display = 'none';
			window.document.getElementById('savoirplus'+subid).style.display = 'block';
			window.document.getElementById('img'+subid).src = 'images/bouton-depliement.png';
		}
	}

	if(id && window.document.getElementById('content'+id).style.display == 'none') {
		window.document.getElementById('content'+id).style.display = 'block';
		window.document.getElementById('savoirplus'+id).style.display = 'none';
		window.document.getElementById('img'+id).src = 'images/bouton-depliement-b.png';

	}
	else {
		window.document.getElementById('content'+id).style.display = 'none';
		window.document.getElementById('savoirplus'+id).style.display = 'block';
		window.document.getElementById('img'+id).src = 'images/bouton-depliement.png';
	}
}

function showInstruction(id) {

	for(i=1;i<=4;i++) {
		window.document.getElementById('instruction'+i).style.display = 'none';
	}
	window.document.getElementById('instruction'+id).style.display = 'block';

	if(id==4){
		window.document.getElementById('headerInstruction'+id).style.background = 'url(images/bgHeaderInstruction4_open.gif) no-repeat';
		window.document.getElementById('headerInstruction'+id).style.height = '22px';
	}
	else{
		window.document.getElementById('headerInstruction4').style.background = 'url(images/bgHeaderInstruction4.gif) no-repeat';
		window.document.getElementById('headerInstruction4').style.height = '26px';
	}
}

if(!topic) topic = -1;

/*
function overTab(id) {

	if (id == '1')
	{
		window.document.getElementById('onglet1').src='images/'+lang+'/tab1_over.gif';
	}
	else if (id == '2')
	{
		window.document.getElementById('onglet2').src='images/'+lang+'/tab2_over.gif';
	}
	else if (id == '3')
	{
		window.document.getElementById('onglet3').src='images/'+lang+'/tab3_over.gif';
	}
	else if (id == '4')
	{
		window.document.getElementById('onglet4').src='images/'+lang+'/tab4_over.gif';
	}
}
*/

/*
function changeTab(id) {

	if (id == '-1')
	{
		window.document.getElementById('onglet1').src='images/'+lang+'/tab1_activ.gif';
		window.document.getElementById('onglet2').src='images/'+lang+'/tab2_out_shadow1.gif';
		window.document.getElementById('onglet3').src='images/'+lang+'/tab3_out.gif';
		window.document.getElementById('onglet4').src='images/'+lang+'/tab4_out.gif';
	}
	else if (id == '1')
	{
		window.document.getElementById('onglet1').src='images/'+lang+'/tab1_out_shadow2.gif';
		window.document.getElementById('onglet2').src='images/'+lang+'/tab2_activ.gif';
		window.document.getElementById('onglet3').src='images/'+lang+'/tab3_out_shadow2.gif';
		window.document.getElementById('onglet4').src='images/'+lang+'/tab4_out.gif';
	}
	else if (id == '3')
	{
		window.document.getElementById('onglet1').src='images/'+lang+'/tab1_out.gif';
		window.document.getElementById('onglet2').src='images/'+lang+'/tab2_out_shadow3.gif';
		window.document.getElementById('onglet3').src='images/'+lang+'/tab3_activ.gif';
		window.document.getElementById('onglet4').src='images/'+lang+'/tab4_out_shadow3.gif';
	}
	else if (id == '2')
	{
		window.document.getElementById('onglet1').src='images/'+lang+'/tab1_out.gif';
		window.document.getElementById('onglet2').src='images/'+lang+'/tab2_out.gif';
		window.document.getElementById('onglet3').src='images/'+lang+'/tab3_out_shadow4.gif';
		window.document.getElementById('onglet4').src='images/'+lang+'/tab4_activ.gif';
	}

}
/

/***** RATE MANAGEMENT ********/

StarOutUrl=		'images/StarOut.gif';		//image par défaut
StarOverUrl=	'images/StarOver.gif';		//image d'une étoile sélectionnée
StarBaseId=		'Star';				//id de base des étoiles
NbStar=			5;					//nombre d'étoiles

LgtStarBaseId=StarBaseId.lastIndexOf('');

function NotationSystem() {
	for (i=1;i<NbStar+1;i++) {
		var img			=document.getElementById('Star'+i);

		if(!img) {
			return false;
		}
			
		img.onclick		=function() {
			reloadRate(Name2Nb(this.id))
			};
	
		img.alt			='Donner la note de '+i;
		//Texte au survol
		
		img.src			=StarOutUrl;
		img.onmouseover	=function() {StarOver(this.id);};
		img.onmouseout	=function() {StarOut(this.id);};
	}
}

function StarOver(Star) {
	StarNb=Name2Nb(Star);
	for (i=1;i<(StarNb*1)+1;i++) {
		document.getElementById('Star'+i).src=StarOutUrl;
	}
	for (i=1;i<(StarNb*1)+1;i++) {
		document.getElementById('Star'+i).src=StarOverUrl;
	}
	document.getElementById('rateTxt').innerHTML = RateTxt(StarNb*1);
}

function StarOut(Star) {
	StarNb=Name2Nb(Star);
	for (i=1;i<(StarNb*1)+1;i++) {
		document.getElementById('Star'+i).src=StarOutUrl;
	}
	document.getElementById('rateTxt').innerHTML = "choisissez votre note";
}

function Name2Nb(Star) {
	//Le survol d'une étoile ne nous permet pas de connaître directement son numéro
	//Cette fonction extrait donc ce numéro à partir de l'Id
	StarNb=Star.slice(LgtStarBaseId);
	return(StarNb);
} 


/***** AJAX MANAGEMENT ********/

function ajax(url, data, CallbackFunction)
{

  var request = window.XMLHttpRequest ?
	  new XMLHttpRequest() :
	  new ActiveXObject("MSXML2.XMLHTTP.3.0");

  request.open("POST", url, true);
  request.setRequestHeader("Content-Type",
						   "application/x-www-form-urlencoded");
  
  request.onreadystatechange = function()  {
	if (request.readyState == 4 && request.status == 200)
	{
	  if (request.responseText && CallbackFunction)
	  {
		  CallbackFunction(request.responseText);
	  }
	}
  };

  request.send(data);

  return false;
}

function ajaxForm(url, formId, id)
{

  var request = window.XMLHttpRequest ?
	  new XMLHttpRequest() :
	  new ActiveXObject("MSXML2.XMLHTTP.3.0");

   var data = '';
  request.open("POST", url, true);
  request.setRequestHeader("Content-Type",
						   "application/x-www-form-urlencoded");

   var form = document.getElementById(formId).elements;


  for(i=0; i<form.length ; i++) {
	data += '&'+form[i].name+'='+form[i].value;
  }
  
  document.getElementById(id).innerHTML = '<img src="images/loading.gif" style="padding:20px;">';
 
  request.onreadystatechange = function()  {
	if (request.readyState == 4 && request.status == 200)
	{
	  if (request.responseText)
	  {
		  document.getElementById(id).innerHTML = request.responseText;
	  }
	}
  };


  request.send(data);

  return false;
}

function loadXMLString(txt) 
{
try //Internet Explorer
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async="false";
  xmlDoc.loadXML(txt);
  return(xmlDoc); 
  }
catch(e)
  {
  try //Firefox, Mozilla, Opera, etc.
    {
    parser=new DOMParser();
    xmlDoc=parser.parseFromString(txt,"text/xml");
    return(xmlDoc);
    }
  catch(e) {alert(e.message)}
  }
return(null);
}


/***** AJAX LOAD/RELOAD OF PARTS OF SCREEN ********/

function login() {
	ajax('login.php','',loginCalled);
}

function logout() {
	ajax('login.php','action=logout&lang='+lang,loginCalled);
}

function loginCalled(html) {
	reloadComment();
	reloadPanel();
	reloadRate();

	//window.document.getElementById('instructions').innerHTML = html;
}

function reloadRate(rate) {
	if(CurrPepId) {
		var PepId = 'PEP_ID='+CurrPepId;	
		if(rate) {
			PepId += '&RAT_RATE='+rate;
		}
		ajax('rate.php',PepId+'lang='+lang,rateCalled);
	}
}

function reloadComment() {
	if(CurrPepId) {
		var PepId = 'PEP_ID='+CurrPepId+'&lang='+lang;
		ajax('addComment.php',PepId,commentCalled);
	}
}

function rateCalled(html) {
	window.document.getElementById('rate').innerHTML = html;
	NotationSystem();
}

function commentCalled(html) {
	window.document.getElementById('comment').innerHTML = html;
}

function reloadPanel() {
	ajax('panel.php','lang='+lang,panelCalled);	
}

function panelCalled(html) {
	window.document.getElementById('userPanel').innerHTML = html;	
}

function open_ext_link() {	
	var liens = window.document.getElementsByTagName('a');
	for (var i = 0 ; i < liens.length ; ++i)  {		
		if (liens[i].className == 'lien_ext')  {
			liens[i].title = 'S\'ouvre dans une nouvelle fenêtre';
			liens[i].onclick = function()  {
				window.open(this.href);
				return false;
			};
		}
	}
}

function statAddPage() {
	var url = window.document.getElementById('url').value;
	pageTracker._trackPageview(url);
}

function playAudioVideo() {
	if(window.document.getElementById('PEP_VIDEO'))
	{var video = window.document.getElementById('PEP_VIDEO').value;
	var video="/movies/"+video;}
	if(window.document.getElementById('PEP_VIDEO2'))
	{var video2 = window.document.getElementById('PEP_VIDEO2').value;
	var video2="/movies/"+video2;}
	if(window.document.getElementById('PEP_VIDEO3'))
	{var video3 = window.document.getElementById('PEP_VIDEO3').value;
	var video3="/movies/"+video3;}
	if(window.document.getElementById('PEP_VIDEO4'))
	{var video4 = window.document.getElementById('PEP_VIDEO4').value;
	var video4="/movies/"+video4;}
	if(window.document.getElementById('PEP_VIDEO5'))
	{var video5 = window.document.getElementById('PEP_VIDEO5').value;
	var video5="/movies/"+video5;}
	
	
	
	if(window.document.getElementById('PEP_PICTURE'))
	{var photo = window.document.getElementById('PEP_PICTURE').value;}
	
	if(window.document.getElementById('PEP_PICTURE2'))
	{var photo2 = window.document.getElementById('PEP_PICTURE2').value;}
	
	if(window.document.getElementById('PEP_PICTURE3'))
	{var photo3 = window.document.getElementById('PEP_PICTURE3').value;}
	
	if(window.document.getElementById('PEP_PICTURE4'))
	{var photo4 = window.document.getElementById('PEP_PICTURE4').value;}
	
	if(window.document.getElementById('PEP_PICTURE5'))
	{var photo5 = window.document.getElementById('PEP_PICTURE5').value;}
	
	
	if(window.document.getElementById('PEP_AUDIO'))
	{var audio = window.document.getElementById('PEP_AUDIO').value;
	var audio="/sounds/"+audio;
	
	}
	
	if(video) {
		var s1 = new SWFObject("swf/mediaplayer.swf","single","300","220","7");

		s1.addParam("allowfullscreen","true");
		s1.addVariable("width","300");
		s1.addVariable("height","220");		
		s1.addVariable("file",video);
		s1.addVariable("image",photo);
		s1.addParam("wmode","transparent");
		s1.write("video_article");
	}
	if(video2) {
		var s1 = new SWFObject("swf/mediaplayer.swf","single","300","220","7");

		s1.addParam("allowfullscreen","true");
		s1.addVariable("width","300");
		s1.addVariable("height","220");		
		s1.addVariable("file",video2);
		s1.addVariable("image",photo2);
		s1.addParam("wmode","transparent");
		s1.write("video_article2");
	}
	if(video3) {
		var s1 = new SWFObject("swf/mediaplayer.swf","single","300","220","7");

		s1.addParam("allowfullscreen","true");
		s1.addVariable("width","300");
		s1.addVariable("height","220");		
		s1.addVariable("file",video3);
		s1.addVariable("image",photo3);
		s1.addParam("wmode","transparent");
		s1.write("video_article3");
	}
	
	if(video4) {
		var s1 = new SWFObject("swf/mediaplayer.swf","single","300","220","7");

		s1.addParam("allowfullscreen","true");
		s1.addVariable("width","300");
		s1.addVariable("height","220");		
		s1.addVariable("file",video4);
		s1.addVariable("image",photo4);
		s1.addParam("wmode","transparent");
		s1.write("video_article4");
	}
	
	if(video5) {
		var s1 = new SWFObject("swf/mediaplayer.swf","single","300","220","7");

		s1.addParam("allowfullscreen","true");
		s1.addVariable("width","300");
		s1.addVariable("height","220");		
		s1.addVariable("file",video5);
		s1.addVariable("image",photo5);
		s1.addParam("wmode","transparent");
		s1.write("video_article5");
	}
	
	if(audio) {
		var s1 = new SWFObject("swf/mediaplayer.swf","single","190","20","7");
		s1.addParam("allowfullscreen","false");
		s1.addVariable("file",audio);
		s1.addParam("wmode","transparent");		
		s1.write("audio_article");
		
	}
	
	
};

function flash_login(){
	GB_showCenter('Connexion', '../../login.php', 410, 365);
}
function flash_userEdit(){
	GB_showCenter('Connexion', '../../userEdit.php', 500, 350);
}
