// Petit bout de code obligatoire au début de chaque page JS
var xhr = null;
var mouse_x=0;
var mouse_y=0;
if (navigator.appName=="Microsoft Internet Explorer") var IE=true;
else var IE=false;
if (navigator.appName=='Microsoft Internet Explorer' && navigator.appVersion.indexOf('7.0')==-1) var IE6=true;
else var IE6=false;
document.onmousemove = getMousePosition;

// Fonction obligatoire pour AJAX
function getConnection() {
	if(window.XMLHttpRequest) xhr = new XMLHttpRequest(); else if(window.ActiveXObject) try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } else xhr = false;
}

// Fonction qui enregistre la position de la souris à chaque fois qu'elle bouge
function getMousePosition(evt) {
	if(!evt) evt=window.event;
	mouse_x=evt.clientX;
	mouse_y=evt.clientY;
}

// Fonction qui effectue une requête AJAX et qui envoie quelque chose en retour
function ajaxAvecRetour() {
	// Variables configurables
	var page='page.php';
	var parametres='param1=valeur1&param2=valeur2';

	getConnection();
	xhr.onreadystatechange = function() {
		if(xhr.readyState == 4 && xhr.status == 200) {
			var doc = xhr.responseXML;
			var element = doc.getElementsByTagName('racine').item(0);
			/* C'est ici que l'on traîte les informations reçues  */
		}
	}
	xhr.open("POST",page,true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send(parametres);
}

// Fonction qui effectue une requête AJAX sans attendre de retour
function ajaxSansRetour() {
	// Variables configurables
	var page='page.php';
	var parametres='param1=valeur1&param2=valeur2';

	getConnection();
	xhr.open("POST",page,false);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send(parametres);
}

// Cette fonction appelle une fenêtre popup et la centre au milieu de l'écran
function showPopup() {
	// Variables configurables
	var width=600;
	var height=300;
	var page='page.php';

	var widthScreen, heightScreen;
	if (window.innerWidth) {
		widthScreen=window.innerWidth;
		heightScreen=window.innerHeight;
	} else if (document.body && document.body.offsetWidth) {
		widthScreen=document.body.offsetWidth;
		heightScreen=document.body.offsetHeight;
	} else {
		widthScreen=0;
		heightScreen=0;
	}
	var positionLeft, positionTop;
	positionLeft=((widthScreen-width)/2);
	positionTop=((heightScreen-height)/2);
	window.open(page,'null','directories=no, menubar=no, status=no, location=no, scrollbars=yes, resizable=no, height='+height+', width='+width+', top='+positionTop+', left='+positionLeft);
}

// Fonction qui passe tous les champs contenus dans le tableau tab pour tester s'il y a des champs vide
function verifyPost(tab,idErr) {
	if (!idErr && idErr!=0) idErr='';
	var msg_err=document.getElementById('error'+idErr);
	var err=0;
	var errMail=0;
	var errRobot=0;
	for (var i=0 ; i<tab.length ; i++) {
		if (document.getElementById(tab[i]) && document.getElementById(tab[i]).value=='') err++;
		else {
			if (tab[i].indexOf('email')!=-1 || tab[i].indexOf('Email')!=-1) {
				var vTest = /^[a-zA-Z0-9\.\-\_]+@[a-zA-Z0-9\.\-\_]+\.[a-zA-Z]{2,4}$/i;
				if (!vTest.test(document.getElementById(tab[i]).value)) errMail++;
			}
			if (tab[i].indexOf('robot')!=-1) {
				getConnection();
				xhr.open("GET",'includes/ajax_code_secret.php',false);
				xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				xhr.send(null);
				var doc = xhr.responseText;
				if (document.getElementById(tab[i]).value.toLowerCase()!=doc.toLowerCase()) errRobot++;
			}
		}
	}
	if (err>0) {
		if (msg_err.innerHTML!='') msg_err.style.textDecoration='blink';
		msg_err.innerHTML='Vous devez remplir tous les champs marqués d\'une astérisque *.<br><br>';
		setTimeout('undisplayError('+idErr+')',4000);
		return false;
	}
	else if (errMail>0) {
		if (msg_err.innerHTML!='') msg_err.style.textDecoration='blink';
		msg_err.innerHTML='L\'adesse email n\'est pas valide.<br><br>';
		setTimeout('undisplayError('+idErr+')',4000);
		return false;
	} else if (errRobot>0) {
		if (msg_err.innerHTML!='') msg_err.style.textDecoration='blink';
		msg_err.innerHTML='Le code anti-robot n\'est pas valide.<br><br>';
		setTimeout('undisplayError('+idErr+')',4000);
		var today = new Date();
		var str = today.getFullYear()+''+today.getMonth()+''+today.getDay()+''+today.getHours()+''+today.getMinutes()+''+today.getSeconds();
		document.getElementById('antirobot').src='antirobot/gd.php?'+str;
		$('robot').value='';
		return false;
	} else return true;
}

function verifyCheckbox(tab) {
	for (var i=0 ; i<tab.length ; i++) {
		if ($(tab[i]).checked == false) {
			$('error').innerHTML='Vous devez cocher les cases à cocher.<br><br>';
			return false;
		}
	}
	return true;
}

function mail2() {
	var msg_err=document.getElementById('error');
	if (msg_err.innerHTML!='') msg_err.style.textDecoration='blink';
	msg_err.innerHTML='L\'adesse email ne correspond pas avec la confirmation.<br><br>';
	setTimeout('undisplayError()',4000);
	return false;	
}

// Fonction liée à verifyPost(), qui vérifie si le mail est valide
function verifyMail(adresse,idErr) {
	if (!idErr && idErr!=0) idErr='';
	var email = document.getElementById(adresse).value;
	//var verif = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,4}$/
	//if (verif.exec(email) == null) {
	var vTest = /^[a-zA-Z0-9\.\-\_]+@[a-zA-Z0-9\.\-\_]+\.[a-zA-Z]{2,4}$/i;
	if (!vTest.test(email)) {
		var msg_err=document.getElementById('error'+idErr);
		if (msg_err.innerHTML!='') msg_err.style.textDecoration='blink';
		msg_err.style.fontWeight='bold';
		msg_err.style.color='#FF0000';
		msg_err.style.textAlign='center';
		msg_err.innerHTML='L\'adresse email est invalide.<br><br>';
		setTimeout('undisplayError('+idErr+')',4000);
		return false;
	}
	else return true;
}

// Fonction liée à verifyPost(), qui fait clignoter le message d'erreur s'il est déjà affiché et que l'utilisateur réessaie d'activer le formulaire
function undisplayError(idErr) {
	if (!idErr && idErr!=0) idErr='';
	document.getElementById('error'+idErr).style.textDecoration='';
}

// Fonction qui calcule la position d'un objet
function findPos(AObject) {
	var posX = 0, posY = 0;
	while(AObject != null) {
		posX += AObject.offsetLeft;
		posY += AObject.offsetTop;
		AObject = AObject.offsetParent;
	}
	var pos = [];
	pos['x'] = posX;
	pos['y'] = posY;
	return pos;
}

function countdown(url) {
	var seconds = document.getElementById('timeSeconds');
	var time = seconds.innerHTML;
	time = time-1;
	if (time==-1) document.location.href=url;
	else {
		seconds.innerHTML=time;
		setTimeout('countdown("'+url+'");',1000);
	}	
}

function closeDrawer() {
	var drawer = document.getElementById('drawer');
	var height = drawer.offsetHeight-22;
	drawer.style.overflow='hidden';
	executeCloseDrawer(height);
}

function executeCloseDrawer(h) {
	var drawer = document.getElementById('drawer');
	h=h-10;
	drawer.style.height=h+'px';
	if (IE) {
		drawer.style.backgroundPosition='top';
		drawer.style.backgroundPosition='0px '+(h-2)+'px';
	}
	if (h>0) setTimeout('executeCloseDrawer('+h+');',50);
	else {
		drawer.style.height='0px';
		drawer.innerHTML='';
	}
}

function openBackground(itemId, w, h) {
	closeBackground(1);
	if ($('error')) $('error').innerHTML='';
	var contentBackground=document.getElementById('contentBackground');
	var div=document.getElementById(itemId);
	div.className='itemBackground';
	if (w) div.style.width=w+'px';
	else div.style.width='400px';
	if (h) div.style.height=h+'px';
	positionDiv(div);
	if (div.innerHTML.indexOf('<!-- close -->')==-1) div.innerHTML+='<div style="margin-top:10px; text-align:center;"><a href="javascript:closeBackground(0);" style="color:#DDDDDD;">Fermer</a></div><!-- close -->';
	contentBackground.style.display='block';
	div.style.display='block';
}

function closeBackground(act) {
	var divs = document.getElementById('contentBackground').getElementsByTagName('div');
	for (var i=0 ; i<divs.length ; i++) {
		if (divs[i].id!='background' && divs[i].parentNode.id=='contentBackground') divs[i].style.display='none';
	}
	if (act!=1) document.getElementById('contentBackground').style.display='none';
}

function positionDiv(div) {
	var h=document.body.offsetHeight;
	var w=document.body.offsetWidth;

	div.style.left=((w/2)-(parseInt(div.style.width)/2))+'px';
	div.style.top='25px';

	if (IE6) {
		div.style.position='absolute';
	} else {
		div.style.position='fixed';
	}
}

var nbSponsor=1;
function addSponsor() {
	nbSponsor++;
	var sponsorVide=$('sponsorVide');
	var contentSponsor=$('contentSponsor');
	var newDiv=document.createElement('div');
	newDiv.innerHTML=sponsorVide.innerHTML;
	var reg = new RegExp("nbSponsor","gi");
	newDiv.innerHTML=newDiv.innerHTML.replace(reg,nbSponsor);
	contentSponsor.appendChild(newDiv);
	
	/*var contentSponsor=document.getElementById('contentSponsor');
	var newDiv=document.createElement('div');
	newDiv.innerHTML='<table width="100%" style="background-color:#797a7c; border:solid 1px black; margin-bottom:5px;"><tr><td colspan="3" class="title2">{t}Sponsor{/t} '+nbSponsor+'</td></tr><tr><td class="text_blue">Entreprise*<br /><input type="text" name="sponsor'+nbSponsor+'Name" id="sponsor'+nbSponsor+'Name" style="width:140px;" /></td><td class="text_blue">Rue & Num*<br /><input type="text" name="sponsor'+nbSponsor+'Street" id="sponsor'+nbSponsor+'Street" style="width:140px;" /></td><td class="text_blue">NPA* / Ville*<br /><input type="text" name="sponsor'+nbSponsor+'NPA" id="sponsor'+nbSponsor+'NPA" style="width:40px; margin-right:4px;" /><input type="text" name="sponsor'+nbSponsor+'City" id="sponsor'+nbSponsor+'City" style="width:140px;" /></td></tr><tr><td class="text_blue">Tél<br /><input type="text" name="sponsor'+nbSponsor+'Tel" id="sponsor'+nbSponsor+'Tel" style="width:140px;" /></td><td class="text_blue">Fax<br /><input type="text" name="sponsor'+nbSponsor+'Fax" id="sponsor'+nbSponsor+'Fax" style="width:140px;" /></td><td class="text_blue">Image<br /><input type="file" name="sponsor'+nbSponsor+'Image" id="sponsor'+nbSponsor+'Image" /></td></tr><tr><td class="text_blue" style="padding-bottom:3px;">Site Web <font size="1">(ex: www.exemple.ch)</font><br /><input type="text" name="sponsor'+nbSponsor+'Website" id="sponsor'+nbSponsor+'Website" style="width:140px;" /></td><td class="text_blue" style="padding-bottom:3px;">Montant fixe*<br /><input type="text" name="sponsor'+nbSponsor+'AmountFixed" id="sponsor'+nbSponsor+'AmountFixed" onkeyup="verifyAmount('+nbSponsor+');" style="width:50px;" /> <span style="color:#FFF;">CHF</span></td><td class="text_blue" style="padding-bottom:3px;"><table cellspacing="0" cellpadding="0"><tr><td>Montant par km*<br /><input type="text" name="sponsor'+nbSponsor+'AmountKm" id="sponsor'+nbSponsor+'AmountKm" onkeyup="verifyAmount('+nbSponsor+');" style="width:50px;" /> <span style="color:#FFF;">CHF</span></td><td valign="top" style="padding-left:35px;">Total :<br /><span id="somme'+nbSponsor+'" style="color:#FFF;">0</span> <span style="color:#FFF;">CHF</span></td></tr></table></td></tr></table>';
	contentSponsor.appendChild(newDiv);*/
}

function verifyAmount(num) {
	var moyenneKm=250;
	var somme=0;
	var fixe=document.getElementById('sponsor'+num+'AmountFixed');
	var km=document.getElementById('sponsor'+num+'AmountKm');
	fixe.value=fixe.value.replace(/\'/gi,'');
	km.value=km.value.replace(/\'/gi,'');
	if (isNumeric(fixe.value)) somme=somme+fixe.value*1;
	if (isNumeric(km.value)) somme=somme+(km.value*moyenneKm)*1;
	if (isNumeric(km.value) && km.value!='' && km.value!=0) document.getElementById('somme'+num).innerHTML='~'+somme;
	else document.getElementById('somme'+num).innerHTML=somme;
}

function verifyInscriptionSponsors() {
	var tab=new Array('Name','Street','NPA','City');
	//,'AmountFixed','AmountKm'
	var error=0;
	var error2=0;
	for (var i=1 ; document.getElementById('sponsor'+i+'Name') ; i++) {
		var rempli=0;
		for (var j=0 ; j<tab.length ; j++) {
			if (document.getElementById('sponsor'+i+tab[j]).value!='') rempli++;
		}
		if (rempli<tab.length && rempli>0) error++;
		if (rempli>0 && ((document.getElementById('sponsor'+i+'AmountFixed').value=='' && document.getElementById('sponsor'+i+'AmountKm').value=='') || (!isNumeric(document.getElementById('sponsor'+i+'AmountFixed').value) && !isNumeric(document.getElementById('sponsor'+i+'AmountKm').value)))) error2++;
	}
	if (error>0) {
		document.getElementById('error').innerHTML='Vous devez remplir tous les champs notés d\'une astérisque *.<br><br>';
		return false;
	} else {
		if (error2>0) {
			document.getElementById('error').innerHTML='Vous devez remplir au minimum 1 montant par sponsor (fixe ou par km).<br><br>';
			return false;	
		} else return true;
	} 
}

function verifyInscriptionPlayers() {
	var error=0;
	for (var i=2 ; i<=8 ; i++) {
		if ($('playerFirstName'+i).value!='' || $('playerLastName'+i).value!='') {
			if ($('playerFirstName'+i).value=='' || $('playerLastName'+i).value=='' || $('playerBirthday'+i+'[Day]').value=='' || $('playerBirthday'+i+'[Month]').value=='' || $('playerBirthday'+i+'[Year]').value=='') {
				error=1;
			} else if ($('playerEmail'+i).value!='') {
				   		if (!verifyMail('playerEmail'+i,'')) return false;
				   }
		}
	}
	if (error>0) {
		$('error').innerHTML='Les participants doivent contenir le prénom, le nom et la date de naissance.<br><br>';
		return false;
	} else return true;
}

function scrollConditions() {
	var conditions=$('conditions');
	if (conditions.scrollHeight-conditions.scrollTop-conditions.offsetHeight<=10) $('buttonAccept').disabled=false;
}

function saveTitle(pdf) {
	// Variables configurables
	var page='ajax_save_title.php';
	var title=$('titlePdf').value;
	title=escape(title);
	var parametres='pdf='+pdf+'&title='+title;

	getConnection();
	xhr.open("POST",page,false);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send(parametres);
	$('buttonMaj').disabled=true;
}

function isNumeric(num) {
	var exp = new RegExp('^[0-9-.]+$','g');
	return exp.test(num);
}

function sendFriend() {
	if (!verifyPost(new Array('email','commentaire'))) return false;
	// Variables configurables
	var page='includes/ajax_send_message.php';
	var email=document.getElementById('email').value;
	email=escape(email);
	var message=$('commentaire').value;
	message=escape(message);
	var firstname=$('firstname').value;
	firstname=escape(firstname);
	var lastname=$('lastname').value;
	lastname=escape(lastname);
	var parametres='message='+message+'&email='+email+'&firstname='+firstname+'&lastname='+lastname;

	getConnection();
	xhr.open("POST",page,false);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send(parametres);
	$('email').value='';
	$('commentaire').value='';
	closeBackground(0);
}

function $(text) {
	return document.getElementById(text);	
}

function fPosterMsg() {
	document.getElementById("dLienPosterMsg").style.display='none';
	document.getElementById("dPosterMsg").style.display='';
}

function fAnnulerPosterMsg() {
	document.getElementById("dPosterMsg").style.display='none';
	document.getElementById("dLienPosterMsg").style.display='';
	document.getElementById("cPseudo").value='';
	document.getElementById("cMail").value='';
	document.getElementById("cSujet").value='';
	document.getElementById("cMessage").value='';
}

var mvtZoom=130;
var mvtMove=100;
function mapZoom(act,img) {
	if ($('imgMap'+img).src.indexOf('disabled')!=-1) return;
	var map = $('map');
	var width = parseInt(map.style.width);
	var left = parseInt(map.style.left);
	var top = parseInt(map.style.top);
	var sizeW=575;
	var sizeH=404;
	var mvt = mvtZoom;

	switch(act) {
		case 1 :
			width = width+mvt;
			left=left-mvt/2;
			top=top-mvt/3;
		break;
		case -1 :
			width = width-mvt;
			left=left+mvt/2;
			top=top+mvt/3;
		break;
	}
	if (width<sizeW) width=sizeW;

	map.style.width=width+'px';
	map.style.top=top+'px';
	map.style.left=left+'px';

	width = parseInt(map.style.width);
	left = parseInt(map.style.left);
	top = parseInt(map.style.top);
	var height = parseInt(map.offsetHeight);
	var endX=width+left;
	var endY=height+top;

	if (endX<sizeW) left=left+(sizeW-endX);
	if (endY<sizeH) top=top+(sizeH-endY);
	if (left>0) left=0;
	if (top>0) top=0;

	map.style.left=left+'px';
	map.style.top=top+'px';

	mapCheckZones();
}

function mapMove(act,img) {
	if ($('imgMap'+img).src.indexOf('disabled')!=-1) return;
	var map = $('map');
	var left = parseInt(map.style.left);
	var top = parseInt(map.style.top);
	var width = parseInt(map.style.width);
	var height = parseInt(map.offsetHeight);
	var sizeW=575;
	var sizeH=404;
	var mvt = mvtMove;
	switch(act) {
		case 1 :
			top = top+mvt;
		break;
		case 2 :
			left = left-mvt;
		break;
		case 3 :
			top = top-mvt;
		break;
		case 4 :
			left = left+mvt;
		break;
	}
	if (left>0) left=0;
	if (top>0) top=0;
	
	var endX=width+left;
	var endY=height+top;
	
	if (endX<sizeW) left=left+(sizeW-endX);
	if (endY<sizeH) top=top+(sizeH-endY);

	map.style.left=left+'px';
	map.style.top=top+'px';

	mapCheckZones();
}

function mapCheckZones() {
	var map = $('map');
	var left = parseInt(map.style.left);
	var top = parseInt(map.style.top);
	var width = parseInt(map.style.width);
	var height = parseInt(map.offsetHeight);
	var sizeW=575;
	var sizeH=404;
	var endX=width+left;
	var endY=height+top;
	if ($('imgMap2').src.indexOf('disabled')!=-1 && top<0) imgMapEnable(2);
	else if ($('imgMap2').src.indexOf('disabled')==-1 && top>=0) imgMapDisable(2);
	if ($('imgMap3').src.indexOf('disabled')!=-1 && left<0) imgMapEnable(3);
	else if ($('imgMap3').src.indexOf('disabled')==-1 && left>=0) imgMapDisable(3);
	if ($('imgMap4').src.indexOf('disabled')!=-1 && endX>sizeW) imgMapEnable(4);
	else if ($('imgMap4').src.indexOf('disabled')==-1 && endX<=sizeW) imgMapDisable(4);
	if ($('imgMap5').src.indexOf('disabled')!=-1 && width>sizeW) imgMapEnable(5);
	else if ($('imgMap5').src.indexOf('disabled')==-1 && width<=sizeW) imgMapDisable(5);
	if ($('imgMap6').src.indexOf('disabled')!=-1 && endY>sizeH) imgMapEnable(6);
	else if ($('imgMap6').src.indexOf('disabled')==-1 && endY<=sizeH) imgMapDisable(6);
}

function imgMapEnable(n) {
	$('imgMap'+n).src=$('imgMap'+n).src.replace('-disabled','');
	$('imgMap'+n).className='';
}

function imgMapDisable(n) {
	$('imgMap'+n).src=$('imgMap'+n).src.replace('.png','-disabled.png');
	$('imgMap'+n).className='link-disabled';
}


function raceInfoPrint(n) {
	if (n==0) {
		for (i=1 ; $('info'+i) ; i++) {
			$('info'+i).style.display='';
		}
	} else {
		for (i=1 ; $('info'+i) ; i++) {
			if (i==n) $('info'+i).style.display='';
			else $('info'+i).style.display='none';
		}	
	}
	for (i=0 ; $('menu2-'+i) ; i++) {
		if (i==n) $('menu2-'+i).style.color='#FEE400';
		else $('menu2-'+i).style.color='';
	}
}

var page=1;
function galleryNext(direction,total) {
	var gallery=$('gallery');
	var width=542;
	if (direction==-1) {
		var margin=width;
		page--;
	} else {
		var margin=-width;
		page++;
	}
	if (page<1) {
		page=total;
		margin=-(width*(total-1));
	}
	else if (page>total) {
		page=1;
		margin=(width*(total-1));
	}
	galleryMove(0,margin);
	galleryPageColors(page);
}

function galleryMove(m,margin) {
	var gallery=$('gallery');
	gallery.style.marginLeft=parseInt(gallery.style.marginLeft)+margin+'px';
//	if (m<margin)
}

var imageTemp='';
function galleryImageSrc(src) {
	var image=$('galleryImage');
	image.src='/themes/default/img/loader.gif';
	imageTemp=src;
	setTimeout("galleryImageSrc2('"+src+"')",100);
}

function galleryImageSrc2(src) {
	var image=$('galleryImage');
	image.src=src;
	setBackgroundWidth();
}
function setBackgroundWidth() {
	var image=$('galleryImage');
	var width=parseInt(image.width);
	var screenWidth=window.screen.width;
	if (width>40) {
		var div=document.getElementById('itemBackground');
		div.style.width=width+'px';
		positionDiv(div);
	} else setTimeout('setBackgroundWidth()',1);
}

function galleryGetPage(p) {
	var width=542;
	var diff=(p-page)*-1;
	page=p;
	var margin=diff*width;
	
	galleryMove(0,margin);
	galleryPageColors(p);
}

function galleryPageColors(p) {
	var aLink=document.getElementsByTagName('a');
	for (var i=0 ; i<aLink.length ; i++) {
		if (aLink[i].id) if (aLink[i].id.indexOf('page_')!=-1) aLink[i].style.color='#FFFFFF';	
	}
	$('page_'+p).style.color='#a2a2a2';
}
var diapoStart=0;
function moveImage(act) {
	if (diapoStart==1) return;
	var image=imageTemp.substring(imageTemp.lastIndexOf("/")+1);

	var page='/php/includes/ajax_get_image.php';
	var parametres='act='+act+'&image='+image;

	getConnection();
	xhr.onreadystatechange = function() {
		if(xhr.readyState == 4 && xhr.status == 200) {
			var doc = xhr.responseText;
			var image=$('galleryImage');
			galleryImageSrc(doc);
			setTimeout("loadImageTemp('"+doc+"')",200);
		}
	}
	xhr.open("POST",page,true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send(parametres);
}

function loadImageTemp() {
	var image=imageTemp.substring(imageTemp.lastIndexOf("/")+1);

	var page='/php/includes/ajax_get_image_temp.php';
	var parametres='image='+image;

	getConnection();
	xhr.onreadystatechange = function() {
		if(xhr.readyState == 4 && xhr.status == 200) {
			var doc = xhr.responseText;
			var image=doc.split(':');
			document.getElementById('imgTemp1').src=image[0];
			document.getElementById('imgTemp2').src=image[1];
		}
	}
	xhr.open("POST",page,true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send(parametres);
}
function galleryDiapo(act) {
	if (act==1) {
		diapoStart=1;
		openBackground('itemBackground',900);
	}
	else {
		if (document.getElementById('itemBackground').style.display=='none') {
			diapoStart=0;
			return;
		}
	}

	var image=imageTemp.substring(imageTemp.lastIndexOf("/")+1);

	var page='/php/includes/ajax_get_image.php';
	var parametres='act=1&image='+image;

	getConnection();
	xhr.onreadystatechange = function() {
		if(xhr.readyState == 4 && xhr.status == 200) {
			var doc = xhr.responseText;
			var image=$('galleryImage');
			galleryImageSrc(doc);
			setTimeout("loadImageTemp('"+doc+"')",500);
		}
	}
	xhr.open("POST",page,true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send(parametres);


	setTimeout('galleryDiapo(0)',5000);
}

function createMini(name) {
	// Variables configurables
	var page='includes/ajax_create_mini.php';
	var parametres='dir='+name;

	getConnection();
	xhr.open("POST",page,false);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send(parametres);
}
/*
function moveText(act) {
	var div=$('content_title5');
	if (act==1) div.style.marginLeft='400px';
	else div.style.marginLeft=(parseInt(div.style.marginLeft)-25)+'px';
	if (parseInt(div.style.marginLeft)<0) div.style.marginLeft='0px';
	else setTimeout('moveText(0)',400);
}*/