var currentPaginationNumber = 1;



function showElement(iddiv,displayStyle)
{
	if(!displayStyle)
		var displayStyle = "block"
	document.getElementById(iddiv).style.display=displayStyle;
}

function hideElement(iddiv)
{
	document.getElementById(iddiv).style.display='none';
}

function dateObjectToSql(date)
{
	
	
	today = date.getFullYear();

	var month = date.getMonth();
	today += '-';
	today += (month<10)?"0"+month:month;
	
	today += '-';
	today += (date.getDate()<10)?"0"+date.getDate():date.getDate();
	
	today += ' ';
	today += (date.getHours()<10)?"0"+date.getHours():date.getHours();
	
	today += ':';
	today += (date.getMinutes()<10)?"0"+date.getMinutes():date.getMinutes();
	
	today += ':';	
	today += (date.getSeconds()<10)?"0"+date.getSeconds():date.getSeconds();
	
	return today;
}

function getTodaySql()
{
	var date = new Date();
	return dateObjectToSql(date);
}

function getTodayFrench()
{
	date = new Date();
	
	return dateObjectToFrench(date);
}

function getTodayFrenchWithTime()
{
	date = new Date();
	time = 1;
	return dateObjectToFrench(date,time);
}


function dateObjectToInt(date)
{
	dateInt = ""+date.getFullYear();
	dateInt+= (	date.getMonth() > 9 )?date.getMonth():"0"+date.getMonth();
	dateInt+= (	date.getDate() > 9 )?date.getDate():"0"+date.getDate();
	return parseInt(dateInt);
	
	
}
function dateObjectToFrench(date,time)
{

	today = (date.getDate()<10)?"0"+date.getDate():date.getDate();
	today += '/';
	
	var month = date.getMonth()+1;
	today += (month<10)?"0"+month:month;
	today += '/';
	
	today += date.getFullYear();
	today += ' ';
	
	if(time)
	{
		today += (date.getHours()<10)?"0"+date.getHours():date.getHours();
		today += ':';
		today += (date.getMinutes()<10)?"0"+date.getMinutes():date.getMinutes();
	}
	return today;
}

function frenchDateToDateObject(originalvalue) // en entree date au format  jj/mm/aaaa hh:ii
{
	var date_day = originalvalue.substring(0,2);
	if(date_day.charAt(0) == '0')
		date_day = date_day.charAt(1);
	date_day = parseInt(date_day);
	
	
	var date_month = originalvalue.substring(3,5);
	if(date_month.charAt(0) == '0')
		date_month = date_month.charAt(1);
	date_month = parseInt(date_month)-1;
	
	
	var date_year = parseInt(originalvalue.substring(6,10));
	
	var date_hour = originalvalue.substring(11,13);
	if(date_hour.charAt(0) == '0')
		date_hour = date_hour.charAt(1);
	date_hour = parseInt(date_hour);
	
	date_min = originalvalue.substring(14,16);
	if(date_min.charAt(0) == '0')
		date_min = date_min.charAt(1);
	date_min = parseInt(date_min);
	
	var date = new Date(date_year,date_month,date_day,date_hour,date_min,0);
	
	return date;
	
}


function showForDev(text)
{
	if(window.location.href.match("dev=1"))
		alert(text);
	
}


function setAndClearTimeout(functiontoexecute,time,timeoutName)
{
	
	var timeoutName = 'timeout_occurrence_' + timeoutName;
	if(window[timeoutName])
		clearTimeout(window[timeoutName]);
	window[timeoutName] = setTimeout(functiontoexecute,time);
	
}



//// affiche puis cache un element

function showAndHide(id)
{
	var elem = document.getElementById(id);
	
	if(!elem.showAndHide_marker)
	{
		if(elem.clientHeight && elem.clientWidth)
			elem.showAndHide_marker = 'visible';
		else
			elem.showAndHide_marker = 'hidden';
	}
	if(elem.showAndHide_marker == 'hidden')
	{
		elem.showAndHide_marker = "visible";
		elem.style.display = "block";
	}
	else if(elem.showAndHide_marker == 'visible')
	{
		elem.showAndHide_marker = "hidden";
		elem.style.display = "none";
	}
}


//// rechargement des blocks


function loadUrlInDiv(url,blockdest,options)
{
	if(options)
	{
		var parameters = options.parameters;
		var onSuccess2 = options.onSuccess;
	}
	
	url = url.replace('\#','');




	new Ajax.Request
	(	
		url,
		{
			method : "POST",
			parameters : parameters,
			onSuccess : function(transport)
			{
				var retour = transport.responseText;
				document.getElementById(blockdest).innerHTML  = transport.responseText;
				
				
				if(onSuccess2)
					onSuccess2();
				
			}
		}
	);	
}


function loadBlockContent(blocksource,blockdest,options)
{
	//Loader.show();
	if(!blocksource || !blockdest)
		return null;
		
	if(options)
	{
		var parameters = options.parameters;
		var urlparameters = options.urlparameters;
		var onSuccess2 = options.onSuccess;
	}
	


	var url = window.location.href; 

	url = url.replace('\#','');

	if(url.match("[?]"))
		url += '&';
	else
		url += '?';

	url += "blocksourcename="+blocksource;
	if(urlparameters) 
		for(var prop in urlparameters)
			url += '&'+prop+'='+urlparameters[prop];


	
	new Ajax.Request
	(	
		url,
		{
			method : "POST",
			parameters : parameters,
			onSuccess : function(transport)
			{
				var retour = transport.responseText;
				if(retour.match('#~!blocks_separator!~#') && blocksource.match(';'))
				{
					loadedBlocks = retour.split('#~!blocks_separator!~#');
					divsList = blockdest.split(';');
					for(var p=0;p<divsList.length;p++)
					{
						setOuterHtml(document.getElementById(divsList[p]+'1'),loadedBlocks[p]);
						
				
					}
				}
				else
				{
					setOuterHtml(document.getElementById(blockdest+'1'),transport.responseText);
					
				}
				
				if(onSuccess2)
					onSuccess2();
				//Loader.hide();
			}
		}
	);	
}


function reloadBlock(divname,options)
{
	loadBlockContent(divname,divname,options)
}

function reloadBlocksArray(blocksArray,parameters)
{
	var str = '';
	for(var i= 0; i< blocksArray.length; i++)
	{
		if(str && blocksArray[i])
			str += ';';
		str += blocksArray[i];
	}
	

	
	
	reloadBlock(str,parameters);	
}


function reloadBlocksByClass(classname,parameters)
{
	var domElements = getElementsByClass(classname);
	if(!domElements.length)
		return null;
	
	var blocksArray = new Array();
	
	for(var i=0; i<domElements.length; i++)
		blocksArray.push(domElements[i].className);
	
	
	reloadBlocksArray(blocksArray,{parameters : parameters});

}


function reloadTables(parameters) // deprecated
{ 
		reloadBlocksByClass(' table',parameters);
			
}


//// PAGINATION AJAX TABLEAUX



function paginationAjax(module,page,paginationlink)
{
	if(!document.getElementById('tabligne_'+module+'1'))
	{
		alert('erreur sur la pagination');
		return null;
	}
	
	var parametersArray = new Array();
	parametersArray['p'+module] = page;
	
	reloadBlock
	(
	 	document.getElementById('tabligne_'+module+'1').parentNode.className,
		{
			parameters : parametersArray,
			onSuccess : function()
			{ 
				reloadBlock(paginationlink.parentNode.className,{parameters : parametersArray});
				currentPaginationNumber = page;
			}
		}
	);
}



function isIe6()
{
	var IE6 = false; 

	var strChUserAgent = navigator.userAgent;
	var intSplitStart = strChUserAgent.indexOf("(",0);
	var intSplitEnd = strChUserAgent.indexOf(")",0);
	var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);
	
	if(strChMid.indexOf("MSIE 6") != -1) IE6 = true;

	return IE6;
}
function hideAllSelects()
{
		var selectFields = document.getElementsByTagName('SELECT');
		for(var i=0; i<selectFields.length; i++)
			selectFields[i].style.visibility = 'hidden';		
}
function showAllSelects()
{
	var selectFields = document.getElementsByTagName('SELECT');
	for(var i=0; i<selectFields.length; i++)
		selectFields[i].style.visibility = 'visible';
}


//////////////// POUR LA TEMPORISATION DES MENUS




function setMenuDynamique(idmenu,linkclass,sousmenuclass)
{

	var menu = document.getElementById(idmenu);
	var currentShowedMenu = '';
	var potential_lis = menu.getElementsByTagName('div');
	
	var lis = new Array();
	var i = 0;
	for(var j=0; j<potential_lis.length;j++)
	{
		if(potential_lis[j].className.match(linkclass))
		{
			lis[i] = potential_lis[j];
			i++;
		}
	}
	var lastTimeoutObj = '';
	
	
	for(var i = 0; i< lis.length ; i++)
	{
		var li = lis[i];
		
		if(li.childNodes)
		{
			for(var c=0; c<li.childNodes.length; c++)
			{
				if(li.childNodes[c].className && li.childNodes[c].className.match(sousmenuclass))
				{
					li.menuToShow = li.childNodes[c];
					
					
					
				}
			}
				
		}
		
		
		
		
		li.onmouseover = function()
		{
		
			clearTimeout(this.timeout);
			if(this.menuToShow)
			{
				
					if(isIe6())
						hideAllSelects();
		
					this.menuToShow.style.left = this.offsetWidth+'px';
					this.timeout2 = setTimeout("document.getElementById('"+this.id+"').menuToShow.style.display = 'block';",250);
					
			
			}
		}
		li.onmouseout = function()
		{			
				if(isIe6())
					showAllSelects();
				
				if(this.menuToShow)
				{
					this.timeout = setTimeout("document.getElementById('"+this.id+"').menuToShow.style.display = 'none';",250);
				}
		}
	}
}






///// SIMPLIFICATION AJAX

function ajaxInsert(url,after)
{
	new Ajax.Request(url, {
					 method:'post', onSuccess : after
					
					 });				
	return false;
}

function ajaxRequestPrompt(url)
{
	var val = prompt('Veuillez entrer la valeur');
	new Ajax.Request(url+val, {
					 method:'post' 
					
					 });				
	return false;
}


function deleteObjectById(identitie,entitieType,onsuccess)
{
	new Ajax.Request
	(
	 	'indexAjax.php?ajaxmodule=ajax&opajax=deleteobjectbyid&identitie='+identitie+'&entitietype='+entitieType,
		{
			method : 'POST',
			onSuccess : onsuccess
		}
	);
}




/////////////////////////////// FONCTION PERMETTANT DE METTRE UN FOND D'une certaine couleur SUR LA DIV ACTIVE


var currentFocusDiv = null;
var currentFocusDivOriginalBorder = "";
var currentFocusDivOriginalBackground = "";



function styleFocus(e) 
{

	if(currentFocusDiv )
	{
		if(currentFocusDivOriginalBackground)
			currentFocusDiv.style.background = currentFocusDivOriginalBackground;
		else
			currentFocusDiv.style.background = "";
	}	
	if(window.event)
	{
		if(window.event.srcElement.style.background!='#B9B7B7')
		{
			currentFocusDivOriginalBackground = window.event.srcElement.style.background;

		}
		window.event.srcElement.style.background = '#B9B7B7';
		currentFocusDiv = window.event.srcElement;
		
	}
	else
	{
		if(e.target.style.background!='#B9B7B7')
			currentFocusDivOriginalBackground = e.target.style.background;
		e.target.style.background = '#B9B7B7';
		currentFocusDiv = e.target;
		
	
	}

}





// fonction permettant de deplacer une div


var moveDivFunction;
var selectedDivId;
var selectedDivOriginalBackground;
function selectDiv(divObject) 
{
	

	
	selectedDivOriginalBackground = divObject.style.background;
	
	divObject.style.background = "#FBE6BD";
	selectedDivId = divObject.id;
	
	
	moveDivFunction = function(event)
	{
		//window.onmousedown = function(){};
		
		
		
		var currentTarget = event.target;
		var element = document.getElementById(selectedDivId);
		
		
		

	
		if(currentTarget && currentTarget.id == selectedDivId)
		{
			
			currentTarget.style.background = selectedDivOriginalBackground;
			selectedDivId = null;
			window.onclick = null;

		}
		else
		{
			
			
			
			while(!currentTarget.getAttribute("idblock"))
			{
				if(currentTarget.parentNode);
					currentTarget = currentTarget.parentNode;
			}
			
			var typeDeplacement = prompt("Vous avez Choisi de déplacer l'element "+selectedDivId+" vers l'element "+currentTarget.id+"\n\nTaper 1 pour le placer avant\nTaper 2 pour le placer après\nTaper 3 pour le placer dedans\nTaper 0 ou cliquez sur \"annuller\" pour annuller l'opération");
		
			if(!typeDeplacement)
				return false;
		
			
			if(!selectedDivOriginalBackground)
				selectedDivOriginalBackground = 'transparent';
				
				
			var idblock = element.getAttribute('idblock');
			var idblockdest = currentTarget.getAttribute('idblock');
			
			if(typeDeplacement == 1)
			{
				currentTarget.parentNode.insertBefore(element,currentTarget);
				var movetype = 'before';
				
			}
			else if(typeDeplacement == 2)
			{
				if(currentTarget.nextSibling)
					currentTarget.parentNode.insertBefore(element,currentTarget.nextSibling);
				else
					currentTarget.parentNode.appendChild(element);
				
				var movetype = 'after';
			}
			else if(typeDeplacement == 3)
			{
				currentTarget.appendChild(element);
				var movetype = 'inside';
			}
			if(idblock && idblockdest && movetype)
				ajaxInsert('indexAjax.php?ajaxmodule=activeblock&opajax=moveblock&idactiveblock='+idblock+'&idblockdest='+idblockdest+"&movetype="+movetype);	
			else
				alert('erreur ___ idblock : '+idblock+', idblockdest : '+idblockdest+', movetype : '+movetype);
			window.onclick = null;
		}
	}
	
	
	setTimeout('window.onclick = moveDivFunction;',100);
	

}


//////////// fonction ajustemment frame //////////////

function resizeFrame(id)
{
  //récupère la hauteur de la page
  var the_height=   document.getElementById(id).contentWindow.document.body.scrollHeight;

 //change la hauteur de l'iframe
  document.getElementById(id).height= the_height;
}


/// FONCTION GENERANT UN APPEL VERS UNE PAGE refressh session permettant de rafraichir la session active sans recharger la page


function refreshSession()
{
	if(document.getElementById("appel_refresh_sess"))
		document.body.removeChild(document.getElementById("appel_refresh_sess"));
	
	var appel = document.createElement("script");
	
	appel.setAttribute("type","text/javascript");
	appel.setAttribute("id","appel_refresh_sess");
	appel.setAttribute("src","refresh_session.php");
	document.body.appendChild(appel);
	setTimeout("refreshSession();",600000);
}

setTimeout("refreshSession();",600000);





// DETECTION DE FLASH

function detectFlash()
{
	if( navigator.mimeTypes.length > 0 )
		return navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin != null;
	else if( window.ActiveXObject )
	{
		try
		{
			new ActiveXObject( "ShockwaveFlash.ShockwaveFlash" );
			return true;
		}
		catch( oError )
		{
			return false;
		}
	}
	else
		return false;
}

function hideAllFlash()
{
	var allFlash = document.getElementsByTagName('OBJECT');
	for(var i=0; i<allFlash.length; i++)
	{
		allFlash[i].originalVisibility = allFlash[i].style.visibility;
		allFlash[i].style.visibility = "hidden";
		
	}
}

function showAllFlash()
{
	var allFlash = document.getElementsByTagName('OBJECT');
	for(var i=0; i<allFlash.length; i++)
	{
		if(allFlash[i].originalVisibility)
			allFlash[i].style.visibility = allFlash[i].originalVisibility;
		else
			allFlash[i].style.visibility = '';
	}
	
}




// DETECTION DE LA PRESSION D'UNE TOUCHE


function  DetecteTouche(e, touche)
{
	var EnterKey;
	
	
	if(document.all) 
	{
		ev = window.event;
		EnterKey = ev.keyCode;
	}
	else
	{        
		EnterKey = e.keyCode;
	}
	
	//showForDev(EnterKey);
	
	return  (EnterKey == touche) 
	
}


// SIMPLIFICATION DU INNERHTML




function setBaliseContent(id,content)
{
	if(document.getElementById(id))
		document.getElementById(id).innerHTML = content;
	
}

function addBaliseContent(id,content)
{
	if(document.getElementById(id))
		document.getElementById(id).innerHTML += content;
	
}
function getBaliseContent(id)
{

	
	if(document.getElementById(id))
	{

		return document.getElementById(id).innerHTML;
	}
	else
		return '';
}


// envoi de post


function sendPost(data)
{
    var form = new Element('form',{method:'post'});
    for (var n in data)
    {
        form.appendChild(new Element('input',{
            type:'hidden',
            name:n,
            value:data[n]}));
    } 
    $$('body')[0].appendChild(form);
    form.submit();
}


// detection du changement de données dans un formulaire , et dire si un submit est necessaire

function detecteChangeForm(idform)
{
				var formulaire = document.getElementById(idform);
				
				var allSubmitsButtons = getElementsByClass("ajaxsubmit",formulaire);
	
				if(!allSubmitsButtons.length)
					var allSubmitsButtons = getElementsByClass("ajaxsubmit");
			
				if(!allSubmitsButtons.length)
						return false;
					
				var formElements = formulaire.elements;
			
				var valuesString = '';
			
				for(var i = 0; i < formElements.length; i++)
				{
					var elem = formElements[i];
					
					if(i>0)
						 valuesString += ';';
					
					if(elem.tagName.toLowerCase()== 'select' && elem.selectedIndex != "-1") 
						valuesString += elem.options[elem.selectedIndex].value;
					else
						valuesString += elem.value;
					
				}
				
				if(formulaire.valuesString)
				{
					if(formulaire.valuesString == valuesString)
					{
						return false;
					}
					else
					{
						
						
						for(var p=0; p<allSubmitsButtons.length;p++)
							allSubmitsButtons[p].className="ajaxsubmit onoffbutton0";
									
						formulaire.onclick = null;
						formulaire.onkeypress = null;	
					
					}
				}
				
				formulaire.onclick = function()
				{
					detecteChangeForm(this.id);
				}
				
				formulaire.onkeyup = function()
				{
					detecteChangeForm(this.id);
				}
				formulaire.valuesString = valuesString;
		

			

}



////NEED SUBMIT : affiche une fenetre proposant l'enregistrement d'un formulaire 


function needSubmit(mod)
{
	var formname = 'form'+mod+'1';
	formname = formname.toLowerCase();
	
	var ajaxrecord = 'record'+mod;
	
	var needSubmitContent = 'Voulez vous enregistrer maintenant ?<br/>';
	needSubmitContent += "<input type=\"button\" value=\"oui\" onclick=\"hideLtBox();if(window['"+ajaxrecord+"']){"+ajaxrecord+"();}else{document.forms['"+formname+"'].submit()}\"/>";
	needSubmitContent += "&nbsp;<input type=\"button\" value=\"non\" onclick=\"hideLtBox();\"/>";	
				
	showLtBox(needSubmitContent);
}



function recordAllForms() // va chercher dans un array contenant toutes les fonctions d'enregistrement
{
	if(!ajaxRecordFunctionsList)
		return null;
		
	for(var i=0; i<ajaxRecordFunctionsList.length; i++)
	{
		recordFunction = ajaxRecordFunctionsList[i];
		
		recordFunction();
		
	}
		
}


// MISE A JOUR DUNE VALEUR EN BDD



function UpdateValueInBdd(value,options)
{
	
	if(!options)
		options = {};
		
	var identitie = options.identitie;
	var idelement = options.idelement;
	var bddid = options.bddid;
	var table = options.table;
	var onsuccess = options.onsuccess;
	var field = options.field;
		
	
	var updateUrl = "indexAjax.php?ajaxmodule=ajax&opajax=updatefieldvalue&value="+value;
	if(identitie)
		updateUrl += "&identitie="+identitie;
	if(idelement)
		updateUrl += "&idelement="+idelement;
	if(bddid)
		updateUrl += "&bddid="+bddid;
	if(table)
		updateUrl += "&modulename="+table;
	if(field)
		updateUrl += "&elementname="+field;
		
	
		ajaxInsert(updateUrl,onsuccess);		
	
}			



// ENREGISTREMENT AJAX D UN FORMULAIRE 

function getFormByField(field)
{
	
	while(field.parentNode)
	{
	
		field = field.parentNode;	
		
		if(field.tagName.toUpperCase() == 'FORM')
			return field;
	}
}

function ajaxRecordEntitie(identitie,entitietype,values,onSuccess)
{
	var ajaxRecordUrl = 'indexAjax.php?ajaxmodule=ajax&opajax=recordobject&entitietype='+entitietype+'&identitie='+identitie;
	
	new Ajax.Request
	(
		ajaxRecordUrl,
		{
			method : "POST",
			parameters : values,
			onSuccess : onSuccess				

		}
	);
	
}

var controlFieldArray = new Array();
var captchasArray = new Array();
function addFieldControl(formid,field,idcontrolmethod)
{
	if(!controlFieldArray[formid])
		controlFieldArray[formid] = new Array();
	controlFieldArray[formid].push({field : field, idcontrolmethod : idcontrolmethod});
	
}
function getFieldControls(formid)
{
	return controlFieldArray[formid];	
}
function addCaptcha(formid,captchafield)
{

	captchasArray[formid] = captchafield;
}
/*
function controlField(formid,idfieldform,entitietype,onSuccess)
{

	var formtorecord = document.getElementById(formid);
	
	var identitie = formtorecord.elements[0].value;
	
	var values = getFormValues(formtorecord);
	
	new Ajax.Request
	(
		'indexAjax.php?ajaxmodule=ajax&opajax=formcontrol&entitietype='+entitietype+'&identitie='+identitie+'&idfieldform='+idfieldform,
		{
			method : "POST",
			parameters : values,
			onSuccess : function(transport)
			{
				if(transport.responseText == '1')
				{
					formtorecord.control = 1;
					if(onSuccess)
						onSuccess();
				}
				else
				{
					formtorecord.control = 0;
					showLtBox(transport.responseText);
					
				}
			}
		}	 
	);
}
*/

function checkAndRecordForm(formid,formfunction,entitieType,after,onFail,msgConfirm)
{
	
	var controls = getFieldControls(formid);
	var captcha_field = captchasArray[formid];
	var form = document.getElementById(formid);

	if(!controls && !captcha_field)
	{
		
		if(formfunction)
			formfunction(after,msgConfirm);
		else
			form.submit();
			
		return true;
	}
	
	var identitie = form.elements['id'+entitieType].value
	values = getFormValues(form);


	if(controls)
	{
		var controlsText = "";
	
		for(var i=0; i<controls.length; i++)
		{
			if(document.getElementById(controls[i].field).hidden)
				continue;
			if(controlsText)
				controlsText += ';';
			controlsText += controls[i].idcontrolmethod+':'+controls[i].field;
		}
	
		values['controls'] = controlsText;
	}
	
	
	if(captcha_field)
	{
		var captcha_saisi = getFieldValue(captcha_field);
		var captcha_number = getFieldValue(captcha_field+'_captcha_number');
	
		values['captcha_control'] = captcha_number+':'+captcha_saisi;
		showForDev(values['captcha_control']);
	}
	
	
	
	new Ajax.Request
	(
	 	'indexAjax.php?ajaxmodule=ajax&opajax=formcontrol&entitietype='+entitieType+'&identitie='+identitie,
		{
			method:'post',
			parameters : values,
			onSuccess: function(transport)
			{
				if(transport.responseText)
				{
					var responsesList = transport.responseText.split('{#_control_field_sep_#}');
					var errorMsg = '';
			
					for(var i=0; i<responsesList.length; i++)
					{
								
			
						var response = responsesList[i];
						var arguments = response.split('{#_control_argument_sep_#}');
						var field = arguments[0];
						var newValue = arguments[1];	
						
						var error = arguments[2];
						
						
						if(field && newValue)
						{
							setFieldValue(	form.elements[field] , newValue );

							
								 
						}
						if(error)
						{
							if(errorMsg)
								errorMsg += '<br/>';
							errorMsg += error;
							
						}
						
					}
					if(errorMsg)
					{
						if(onFail)
							onFail();
						
						if(document.getElementById("message_fieldformcontrol1"))
							setBaliseContent('message_fieldformcontrol1',errorMsg);
						else
							showLtBox(errorMsg,{height:20,contentOpacity:100});
						
						
						
						return '';
					}
					else if(document.getElementById("message_fieldformcontrol1"))
					{
						
						setBaliseContent('message_fieldformcontrol1','');
					}
				}
				
				
				if(formfunction)
				{
					formfunction(after,msgConfirm);
				}
				else
				{
					
					form.submit();
				}
					
			}
		}		
	);
	
}



function ajaxRecordForm(formid,formoptions)
{

	
	//Loader.show();
	var identitie = formoptions.identitie;
	var entitietype = formoptions.entitietype;
	var onSuccess2 = formoptions.onSuccess;
	



	if(!identitie)
		identitie = '0';


	var formtorecord = document.getElementById(formid);
	
	
	var values = getFormValues(formtorecord);

	var ajaxRecordUrl = 'indexAjax.php?ajaxmodule=ajax&opajax=recordobject&entitietype='+entitietype+'&identitie='+identitie;
	
	new Ajax.Request
	(
		ajaxRecordUrl,
		{
			method : "POST",
			parameters : values,
			onSuccess : function(transport)
			{
				//window.onbeforeunload = null;
				
				if(onSuccess2)
					onSuccess2(transport);
				
				//Loader.hide();
				
				
				document.getElementById(formid).valuesString = '';
				if(showFilesList)
					showFilesList(entitietype);
			}
		}
	);
}



function getFormValues(formtorecord)
{
	var values = new Array();
	
	
	
	
	
	var allInputs = formtorecord.getElementsByTagName('INPUT');
	var allTextareas = formtorecord.getElementsByTagName('TEXTAREA');
	var allSelects = formtorecord.getElementsByTagName('SELECT');


	// TRAITEMENT POUR FCK EDITOR
	for(var i=0; i< allInputs.length;i++)
	{
		if(allInputs[i].id.match('is_fck_') && parseInt(allInputs[i].value) > 0)
		{
			var fck_content_id = allInputs[i].id.replace('is_fck_','');
			/* ANCIENNE VERSION
			var oEditor = FCKeditorAPI.GetInstance(fck_content_id) ;
			var content = oEditor.GetHTML() ;
			*/
			var content = CKEDITOR.instances[fck_content_id].getData()	
			formtorecord.elements[fck_content_id].value = content;

		}
	}
	// FIN TRAITEMENT POUR FCK EDITOR

	for(var i=0; i< allInputs.length;i++)
	{
		values[allInputs[i].id] = allInputs[i].value;
	}
	for(var i=0; i< allTextareas.length;i++)
		values[allTextareas[i].id] = allTextareas[i].value;
	for(var i=0; i< allSelects.length;i++)
	{
		var selectObject = allSelects[i];
		var selectObjectRealName = selectObject.id.replace('[]','');
		var bascHiddenInputName = 	'is_relationelement_'+selectObjectRealName;

		if(document.getElementById(bascHiddenInputName) && selectObject.multiple)
		{
			var basculeObjectValues = '';

			for(var j=0; j<selectObject.options.length; j++)
			{
				if(j>0)	
					basculeObjectValues += '!#!';
				basculeObjectValues += selectObject.options[j].value;
			}
			

			values[selectObjectRealName] = basculeObjectValues;
		
		}
		else if(selectObject.selectedIndex != '-1')
		{

			values[selectObject.id] = selectObject.options[selectObject.selectedIndex].value;
		}
	}	
	
	return values;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////
/////////////////////////////////////////////////		Scripts pour les formulaires
/////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////


/// MONTRER / CACHER






function showField(idfield)
{
	if(document.getElementById('lab_'+idfield))
		document.getElementById('lab_'+idfield).style.display = '';
	if(document.getElementById('chk'+idfield))
		document.getElementById('chk'+idfield).style.display = '';
	if(document.getElementById('btn_'+idfield))
		document.getElementById('btn_'+idfield).style.display = '';
	if(document.getElementById(idfield+'_limiteur'))
		document.getElementById(idfield+'_limiteur').style.display = '';
	if(document.getElementById(idfield+'_cm'))
		document.getElementById(idfield+'_cm').style.display = '';
	if(document.getElementById('afterlab_'+idfield))
		document.getElementById('afterlab_'+idfield).style.display = '';

	
	
	if(document.getElementById(idfield) && document.getElementById(idfield).type != "hidden")
	{

		document.getElementById(idfield).style.display = '';
		document.getElementById(idfield).hidden = 0;
	}
	
	
	
	
}

function hideField(idfield)
{
	if(document.getElementById('lab_'+idfield))
		document.getElementById('lab_'+idfield).style.display = 'none';
	if(document.getElementById('chk'+idfield))
		document.getElementById('chk'+idfield).style.display = 'none';
	if(document.getElementById('btn_'+idfield))
		document.getElementById('btn_'+idfield).style.display = 'none';
	if(document.getElementById(idfield+'_limiteur'))
		document.getElementById(idfield+'_limiteur').style.display = 'none';
	if(document.getElementById(idfield+'_cm'))
		document.getElementById(idfield+'_cm').style.display = 'none';
	if(document.getElementById('afterlab_'+idfield))
		document.getElementById('afterlab_'+idfield).style.display = 'none';
	
	if(document.getElementById(idfield) && document.getElementById(idfield).type != "hidden")
	{
		document.getElementById(idfield).hidden = 1;
		document.getElementById(idfield).style.display = 'none';	
	}
	
	
	
}


function removeElement(field)
{
	if(typeof(field) != 'object')
		field = document.getElementById(field);
	
	field.parentNode.removeChild(field);

}
 
function removeBlockElement(id)
{
	var i = 1;
	while(document.getElementById(id+i))
	{
		removeElement(id+i);
		i++;
	}
	
}

function removeField(idfield)
{

	if(document.getElementById('lab_'+idfield))
		removeElement('lab_'+idfield);
	if(document.getElementById('chk'+idfield))
		removeElement('chk'+idfield);
	if(document.getElementById('btn_'+idfield))
		removeElement('btn_'+idfield);
	if(document.getElementById(idfield+'_limiteur'))
		removeElement(idfield+'_limiteur');
	if(document.getElementById(idfield+'_cm'))
		removeElement(idfield+'_cm');
	if(document.getElementById('afterlab_'+idfield))
		removeElement('afterlab_'+idfield);
	if(document.getElementById(idfield) && document.getElementById(idfield).type != "hidden")
		removeElement(idfield);		
	

	
}

function disableField(idfield)
{
	
	
	var field = document.getElementById(idfield);

	if(!field)
		return '';
		
	if(document.getElementById('chk'+idfield))
	{
		document.getElementById('chk'+idfield).disabled = "true";
		return true;
	}
	
	field.disabled = "true";
	
	
	if(field.className.match('datetimefield') && !field.className.match(' datetimefield_disabled'))
		field.className += " datetimefield_disabled";
	
	if(document.getElementById('btn_'+idfield))
		document.getElementById('btn_'+idfield).style.display = 'none';
	
	
}

function enableField(idfield)
{
	
	var field = document.getElementById(idfield);

	if(!field)
		return '';
	
	if(document.getElementById('chk'+idfield))
	{
		document.getElementById('chk'+idfield).disabled = "false";
		return true;
	}
	
	if(field.className.match(' datetimefield_disabled'))
		field.className = field.className.replace(" datetimefield_disabled",'');
	
	field.disabled = null;
	
	if(document.getElementById('btn_'+idfield))
		document.getElementById('btn_'+idfield).style.display = '';
}


// RECUPERATION DE LA VALEUR d UN CHAMP



function getFieldValue(idfield)
{

	if(document.getElementById(idfield+'_id'))
		idfield = idfield+'_id';
	//if(document.getElementById('is_relationelement_'+idfield))
		//idfield = idfield+'[]';
	
	var field = document.getElementById(idfield);


	if(field)
		var type = field.tagName;
	var value = '';
	

	if(document.getElementById('is_relationelement_'+idfield))
	{
		var bascule = document.getElementById(idfield+'[]');	
		for(var i=0; i<bascule.options.length; i++)
		{
			if(bascule.options[i].value && bascule.options[i].value != 'undefined' && bascule.options[i].value != 'null')
			{
				if(value)	
					value += ';';
				value += bascule.options[i].value;
			}
		}
	}
	else if(type == 'SELECT')
		value = field.options[field.selectedIndex].value;
	else if(type == 'INPUT' && field.type.toUpperCase() == 'CHECKBOX')
	{
		value = (field.checked)?'1':'0';
	}
	else if(field)
		value = field.value;
		
	return value;
}


function setFieldValue(idfield,value)
{
	
	if(typeof(idfield) =='object')
	{
		var field = idfield;
		idfield = field.id;
	}
	else
		var field = document.getElementById(idfield);
	
	
	if(document.getElementById(idfield+'_id'))
	{
		document.getElementById(idfield+'_id').value = value;
	}
	
	

	var type = field.tagName;
	

	
	if(type == 'INPUT' && field.type.toUpperCase() == 'CHECKBOX')
	{
		field.checked = (value && value!='0')?true:false;
	}
	else
		field.value = value;
		
	
}

function getFieldDisplayValue(idfield)
{
	var field = document.getElementById(idfield);

	var type = field.tagName;
	var value = '';
	

	if(document.getElementById('is_relationelement_'+idfield))
	{
		var bascule = document.getElementById(idfield+'[]');	
		for(var i=0; i<bascule.options.length; i++)
		{
			if(bascule.options[i].value && bascule.options[i].value != 'undefined' && bascule.options[i].value != 'null')
			{
				if(value)	
					value += ';';
				value += bascule.options[i].innerHTML;
			}
		}
	}
	else if(type == 'SELECT')
		value = field.options[field.selectedIndex].innerHTML
	else
		value = field.value;
		
	return value;
}

// intervertir fckeditor / textarea

function intervertirFckeditorTextarea(idfield)
{
	var is_fck_field = document.getElementById("is_fck_"+idfield);
	if(!is_fck_field)
		return null;
	var is_fck_editor = 0;
	if(is_fck_field.value == "1")
		is_fck_editor = 1;
	var container = document.getElementById(idfield+'_fckeditor_container');
	//var value = getFieldValue(idfield);
	var oEditor = FCKeditorAPI.GetInstance(idfield);
	
	if(is_fck_editor)
	{
		var value = oEditor.GetHTML() ;
	
		
		document.getElementById(idfield+"_showeditor_button").value = "Afficher l'\éditeur";
		//var hiddenField = document.getElementById(idfield);
		//hiddenField.id = idfield+"_fck_hiddeninput";
		
		var textarea = document.createElement("textarea");
		textarea.id = idfield;
		textarea.name = idfield;
		textarea.className = idfield;

		textarea.value = value;
		
		container.style.display  = "none";
		container.parentNode.insertBefore(textarea,container);
		
		is_fck_field.value = 0;
	}
	else
	{
		var value = getFieldValue(idfield);
		document.getElementById(idfield+"_showeditor_button").value = "Masquer l'\éditeur";
		var textarea = document.getElementById(idfield);
		textarea.parentNode.removeChild(textarea);
		container.style.display = "";
		
		oEditor.SetHTML(value);
		
		//var hiddenField = document.getElementById(idfield+"_fck_hiddeninput");
		//hiddenField.id = idfield;
		
		//hiddenField.value = value;
		
		is_fck_field.value = 1;
		
		//var fckFrame = document.getElementById(idfield+"___Frame");
		//fckFrame.src = fckFrame.src;
		
		
	}
}

// AFFICHAGE DE LA VALEUR DUN CHAMP

function displayFieldValue(idfield)
{

	
	var field = document.getElementById(idfield);
	
	var type = field.tagName;
	
	var value;
	
	if(type == 'SELECT')
		value = field.options[field.selectedIndex].innerHTML
	else
		value = field.value;
		
	return value;
}

//
function plus_moins_button(button,sens,minvalue,maxvalue)
{
	

	var field = button.parentNode.previousSibling;
	
	while(field.tagName.toLowerCase() != 'input')
		field = field.previousSibling;
	
	var currentValue = parseInt(field.value);
	if(sens == '+' && ( maxvalue == 0 || currentValue < maxvalue ) )
		field.value = currentValue + 1;
	else if(sens == '-' && currentValue > minvalue)
		field.value = currentValue - 1;
	else if(sens == '+')
		field.value = minvalue;
	else if(sens == '-')
		field.value = maxvalue;
	
	if(field.onchange)
	{
		if(field.timeoutOnchange)
			clearTimeout(field.timeoutOnchange);
	
		field.timeoutOnchange = setTimeout(function(){field.onchange();},500);
	}
	
}

function input_duree(idfield)
{
	
	var nbhoursinoneday = parseInt(getFieldValue(idfield+'_nbhoursinoneday'));
	if(!nbhoursinoneday)
		var nbhoursinoneday = 24;
	var minutes = parseInt(getFieldValue(idfield+'_minutes'));
	if(document.getElementById(idfield+'_days'))
		var days = parseInt(getFieldValue(idfield+'_days'));
	var hours = parseInt(getFieldValue(idfield+'_hours'));
	
	
	if(days)
		var total = (minutes+(days*60*nbhoursinoneday)+(hours*60))/60;
	else
		var total = (minutes+(hours*60))/60;
		
	total = Math.floor(total * 100000000) / 100000000; 
	
	setFieldValue(idfield,total);
	
	
}








// AJOUT DUN EVENEMNT SUR LE ONCHANGE


function addToOnchange(idfield,onchange2)
{
	if(document.getElementById("chk"+idfield))
		addEvent(document.getElementById('chk'+idfield),'click',onchange2,false);
	else
		addEvent(document.getElementById(idfield),'change',onchange2,false);
	
}




/// ajout d'un evenement

function addEvent(obj,evType,fn,capt){ 

  if(!obj)
  	return null;

  if(obj.addEventListener){

    obj.addEventListener(evType,fn,capt);return true;} // NS6+ 

  else if(obj.attachEvent)obj.attachEvent("on"+evType,fn) // IE 5+ 

  else {

   return false;

  } 

} 

// ajout d'un evenement sur le onload

function addOnLoad(functiontolaunch)
{
	addEvent(window,"load",functiontolaunch,false);
}


/// getElementsByIdLike


function getElementByIdLike(id)
{
	var allDivs = document.getElementsByTagName("*");
	
	for(var i=0; i<allDivs.length ; i++)
		if(allDivs[i].id.match(id))
			return allDivs[i];
}
function getElementsByIdLike(id)
{
	var allDivs = document.getElementsByTagName("*");
	var array = new Array();
	for(var i=0; i<allDivs.length ; i++)
		if(allDivs[i].id.match(id))
			array.push(allDivs[i]);

	return array;
}


// getElementsByClass

function getElementsByClass(className,idparent)
{
/*	
	if(window.location.href.match("intra.gkm"))
		alert(className);
	*/
	if(idparent)
	{
		if(typeof(idparent) == 'string')
			var doc = document.getElementById(idparent);
		else
			var doc = idparent;
	}
	else
		var doc = document;
	elements = new Array();
	var allElements = doc.getElementsByTagName('*');
	
	
	
	if(allElements.length)
	{
		for(var i=0; i<allElements.length; i++)
		{
			if(allElements[i].className.match(className))
				elements.push(allElements[i]);
			
		}
	}
	

	return elements;

}

function getElementByClass(className,idparent)
{
	var list = getElementsByClass(className,idparent);
	if(list.length)
		return list[0];
	
}


// INFOS FENETRE


function getWindowHeight()
{
	
	
	if(window.innerHeight)
	{
		var haut = (window.innerHeight);
	}
	else if ( document.documentElement)
	{
			var haut = document.documentElement.clientHeight;
	}
	
	return haut;

}


function getWindowWidth()
{
	if (window.innerWidth)
	{
		var larg = (window.innerWidth);
		
	}
	else if(document.body)
	{
		var larg = (document.body.clientWidth);
	}
	return larg;

}



function getWindowTop()
{
	if(document.body.scrollTop) // google chrome
		var top = document.body.scrollTop;
	else if(document.documentElement) // ie 
		var top = document.documentElement.scrollTop;
	else // firefox
		var top = document.body.pageYOffset;
	
	return top;
}




// perchargement

function prechargimg() 
{
	var doc=document;
	if(doc.images)
	{ 
		if(!doc.precharg)
			doc.precharg=new Array();
		var i,j=doc.precharg.length,x=prechargimg.arguments; 
		for(i=0; i<x.length; i++)
			if (x[i].indexOf("#")!=0)
			{ 
				doc.precharg[j]=new Image;
				doc.precharg[j++].src=x[i];
			}
	}
}

// outerHTML
/*
function setOuterHtml(node,html)
{
	var parent = node.parentNode;
	var nextNode = node.nextSibling;
	
	
	
	if(nextNode)
	{
		allNextNodes = new Array();
		while(nextNode)
		{
			if(nextNode.id)
			{
				allNextNodes.push(nextNode);
				nextnextNode = nextNode.nextSibling;
			//	alert('on supprime '+nextNode.id);
				parent.removeChild(nextNode);
				
				nextNode = nextnextNode;
			}
			else
				nextNode = nextNode.nextSibling;
		}
		

		//alert('on supprime '+node.id);
		parent.removeChild(node);
		//alert('on ajoute le html');
		parent.innerHTML += html;
		
		
		for(var i=0; i<allNextNodes.length; i++)
		{
			//alert('on ajoute '+allNextNodes[i].id);
			parent.appendChild(allNextNodes[i]);
		}
	}
	else
	{
		parent.removeChild(node);	
		parent.innerHTML += html;
	}
}
*/



function setOuterHtml(node,html)
{
			
	var idnode = node.id;
	
	var parent = node.parentNode;
	
	var htmlNode = document.createElement('div');
	htmlNode.innerHTML = html;
	parent.replaceChild(htmlNode,node);
	
	var newNode = document.getElementById(idnode);

	parent.insertBefore(newNode,htmlNode);
	parent.removeChild(htmlNode);
	
	
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////
/////////////////////////////////////////////////		Scripts pour la LTBox
/////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////




function hideLtBox()
{
	if(!isIe6())
		document.body.style.overflow = "auto";
	showAllFlash();
	document.body.removeChild(document.getElementById('LTBackground')); 
	document.body.removeChild(document.getElementById('LTCadre'));  
	if(document.getElementById('LTClose'))
		document.body.removeChild(document.getElementById('LTClose'));  
	
	
	if(isIe6())
	{
		allSelect = document.getElementsByTagName('select');
		for(var i=0; i<allSelect.length; i++)
			allSelect[i].style.visibility = allSelect[i].oldVisibility;
	}
}

prechargimg('images/corner-top-right.png','images/corner-top-left.png','images/corner-bottom-right.png','images/corner-bottom-left.png');


/* Permet d'afficher en frame dans une url le contenu d'une LTBXOx */
function showLtBoxFrame(url,options)
{
	
	if(!options)
		options = {};
	
	var frameWidth = (options.width)?options.width:500;
	var frameHeight = (options.height)?options.height:350;
	
	options.width = frameWidth;
	options.height = frameHeight;
	
	showLtBox
	(
		'<iframe frameborder="0" src="'+url+'" width="100%" height="'+frameHeight+'"></iframe>',options
	);	
	
}

function showLtBoxAjaxContent(url,options)
{
	if(!options)
		options = {};
	
	new Ajax.Request(url,{method:'post',onSuccess:function(transport){showLtBox(transport.responseText,options);}});
	
	
}



function showLtBox(content, options)
{
	hideAllFlash();
	if(!options)
		options = {};
	
	var backgroundOpacity = (options.backgroundOpacity)?options.backgroundOpacity:60;
	var backgroundColor = (options.backgroundColor)?options.backgroundColor:'#000';
	var contentOpacity = (options.contentOpacity)?options.contentOpacity:80; 
	var after = options.after;
 
	var top = (options.top)?options.top:50;
	var width = (options.width)?options.width:500;
	var height = (options.height)?options.height:350;
	var display_title = (options.display_title)?options.display_title:false;
	
	
	
	if(isIe6())
	{
		allSelect = document.getElementsByTagName('select');
		for(var i=0; i<allSelect.length; i++)
		{
			allSelect[i].oldVisibility = allSelect[i].style.visibility;
			allSelect[i].style.visibility = "hidden";
		}
	}
	
	
	if(!document.getElementById("LTBackground"))
	{
		var LTBackground = document.createElement("div");
		LTBackground.id = "LTBackground";
		LTBackground.style.top = getWindowTop()+'px';
		LTBackground.style.left = "-5px";
		LTBackground.style.padding = "10px";
		LTBackground.style.width = "99%";
		if(isIe6())			
			LTBackground.style.height = screen.availHeight+'px';
		else
			LTBackground.style.height = "98%";
			

		LTBackground.style.position = "absolute";
		LTBackground.style.display = "none";
		LTBackground.onclick = function()
		{
			hideLtBox();
			//document.getElementById("LTBackground").style.display = "none";
			//document.getElementById("LTContent").style.display = "none";
		};		
		//LTBackground.style.opacity = "0.7";
		LTBackground.style.zIndex = "98";
		LTBackground.style.backgroundColor = backgroundColor;
		
	
		
		document.body.appendChild(LTBackground);
	}
	
	if(!isIe6())
		document.body.style.overflow = "hidden";
	

	if(!document.getElementById("LTContent"))
	{
		var LtContentTop = document.createElement('div');
		LtContentTop.style.height = '14px';
		LtContentTop.style.width = width+'px';
		LtContentTop.id = 'LTContentTop';
		
		var LtContentTopLeft = document.createElement('span');
		LtContentTopLeft.style.height = '14px';
		LtContentTopLeft.style.width = '16px';
		LtContentTopLeft.style.display = 'inline-block';
		LtContentTopLeft.style.backgroundImage = 'url(/images/corner-top-left.png)';
		
		var LtContentTopCenter = document.createElement('span');
		LtContentTopCenter.id = "LTContentTopCenter";
		LtContentTopCenter.style.height = '14px';
		LtContentTopCenter.style.width = (width-32)+'px';
		LtContentTopCenter.style.display = 'inline-block';
		LtContentTopCenter.style.backgroundColor = '#FFF';
		
		var LtContentTopRight = document.createElement('span');
		LtContentTopRight.style.height = '14px';
		LtContentTopRight.style.width = '16px';
		LtContentTopRight.style.display = 'inline-block';
		LtContentTopRight.style.backgroundImage = 'url(/images/corner-top-right.png)';
		
		LtContentTop.appendChild(LtContentTopLeft);
		LtContentTop.appendChild(LtContentTopCenter);
		LtContentTop.appendChild(LtContentTopRight);
		

		var LTCadre = document.createElement("div");
		LTCadre.id = "LTCadre";
		LTCadre.style.marginLeft = "50%";
		LTCadre.style.left = "-"+(width/2)+"px";
		LTCadre.style.top = (getWindowTop()+top)+'px';
		//LTCadre.style.padding = "10px";
		LTCadre.style.width = width+"px";
		LTCadre.style.zIndex = "99";
		LTCadre.style.fontFamily = "calibri, arial";
		LTCadre.style.fontSize = "12px";
		LTCadre.style.overflow = "visible";
		LTCadre.style.position = "absolute";
		//LTCadre.style.border = "solid 2px #666";
		//LTCadre.style.backgroundColor = "#FFF";


		var LTContent = document.createElement("div");
		LTContent.id = "LTContent";
		//LTContent.style.border = "solid 2px #666";
		LTContent.style.padding = "10px";
		LTContent.style.minHeight = height+'px';
		LTContent.style.maxHeight =  (screen.availHeight-top-250)+'px';

		LTContent.style.overflow = 'auto';
			
		LTContent.style.backgroundColor = "#FFF";
	
		
	
	
	
	
		var LtContentBottom = document.createElement('div');
		LtContentBottom.style.height = '14px';
		LtContentBottom.style.width = width+'px';
		LtContentBottom.id = 'LTContentBottom';
		
		
		
		var LtContentBottomLeft = document.createElement('span');
		LtContentBottomLeft.style.height = '14px';
		LtContentBottomLeft.style.width = '16px';
		LtContentBottomLeft.style.display = 'inline-block';
		LtContentBottomLeft.style.backgroundImage = 'url(/images/corner-bottom-left.png)';
		
		var LtContentBottomCenter = document.createElement('span');
		LtContentBottomCenter.style.height = '14px';
		LtContentBottomCenter.style.width = (width-32)+'px';
		LtContentBottomCenter.id = 'LTContentBottomCenter';
		LtContentBottomCenter.style.display = 'inline-block';
		LtContentBottomCenter.style.backgroundColor = '#FFF';
		
		var LtContentBottomRight = document.createElement('span');
		LtContentBottomRight.style.height = '14px';
		LtContentBottomRight.style.width = '16px';
		LtContentBottomRight.style.display = 'inline-block';
		LtContentBottomRight.style.backgroundImage = 'url(/images/corner-bottom-right.png)';
	
		LtContentBottom.appendChild(LtContentBottomLeft);
		LtContentBottom.appendChild(LtContentBottomCenter);
		LtContentBottom.appendChild(LtContentBottomRight);
	

		
		LTCadre.appendChild(LtContentTop);
		LTCadre.appendChild(LTContent);
		LTCadre.appendChild(LtContentBottom);
		
		
		

		var LTClose = document.createElement("div");
		LTClose.id = "LTClose";
		LTClose.style.right = "4px";
		LTClose.style.top = "4px";
		LTClose.style.padding = "3px";
		LTClose.style.fontWeight = "bold";
		LTClose.style.color = "#343434";
		LTClose.style.zIndex = "99";
		LTClose.style.position = "absolute";
		LTClose.onmouseover = function()
		{
			this.style.color = "#000";
		}
		LTClose.onmouseout = function()
		{
			this.style.color = "#343434";
		}
		
		LTClose.style.fontSize = "17px";
		LTClose.innerHTML = "X";
		LTClose.style.cursor = "pointer";
		LTClose.onclick = function()
		{
			hideLtBox();
		};		



	
		LTCadre.style.display = "none";
		document.body.appendChild(LTCadre); 
		
		
		
		
		
			document.getElementById("LTBackground").style.display = "block";

	
			
			changeOpacity
			(
				'LTBackground',
				0,
				backgroundOpacity,
				10,
				function()
				{
					document.getElementById('LTCadre').style.display = "block";
					changeOpacity
					(
						'LTCadre',
						0,
						contentOpacity,
						5,
						function()
						{
							if(typeof(content) == 'object')
							{
								content.style.display = "";
								document.getElementById("LTContent").appendChild(content);
								
							}
							else
								document.getElementById("LTContent").innerHTML = content;
							document.getElementById("LTContent").appendChild(LTClose); 	
							if(after)
								after();
						}			
					);
					
					
				
				
				}
			);
			
			window.onscroll = function()
			{
				if(document.getElementById('LTBackground'))
					document.getElementById('LTBackground').style.top = getWindowTop()+'px';
				if(document.getElementById('LTCadre'))
				   document.getElementById('LTCadre').style.top = (getWindowTop()+50)+'px';	
				
			}
	}
	else
	{
		changeOpacity('LTCadre',contentOpacity,0,5,function()
		{
			document.getElementById("LTCadre").style.width = width+"px";
			document.getElementById("LTContentBottom").style.width = width+"px";
			document.getElementById("LTContentTop").style.width = width+"px";
			document.getElementById("LTContentTopCenter").style.width = (width-32)+"px";
			document.getElementById("LTContentBottomCenter").style.width = (width-32)+"px";
			if(typeof(content) == 'object')
			{
				content.style.display = "";
				document.getElementById("LTContent").appendChild(content);
				
			}
			else
				document.getElementById("LTContent").innerHTML = content;
			changeOpacity('LTCadre',0,contentOpacity,5,function()
			{
					
					document.getElementById("LTContent").appendChild(LTClose); 	
					if(after)
						after();
							
			});
		});
		
	}

	

	
	

	
	
	

	
	
	//document.getElementById("LTContent").style.display = "block";

	
}






























/*
 exemple d'utilisation :
 new LtDiaporama(image1,image2,image3 etc... ).launch();


 sinon 
 
 diap = new LtDiaporama();
 diap.addImage(img);
 diap.addImage(img);
 diap.launch();


*/



function LtDiaporama()
{	
	this.images = new Array();
	this.currentImageNumber = 0;
	
		this.options = {};
	
	
	var diapoObj = this;

	
	this.launch = function(firstImage)
	{
		if(!firstImage)
			firstImage = 1;
		document.body.style.overflow = "hidden";
		
		this.backgroundOpacity = (this.options.backgroundOpacity)?this.options.backgroundOpacity:60;
		
		
		this.backgroundColor = (this.options.backgroundColor)?this.options.backgroundColor:'#000';
		this.borderColor = (this.options.borderColor)?this.options.borderColor:'#FFF';
		this.borderSize = (this.options.borderSize)?this.options.borderSize:0;
		this.contentOpacity = (this.options.contentOpacity)?this.options.contentOpacity:100; 
		this.top = (this.options.top)?this.options.top:100;
		
		hideAllFlash();
		
		if(isIe6())
		{
			allSelect = document.getElementsByTagName('select');
			for(var i=0; i<allSelect.length; i++)
			{
				allSelect[i].oldVisibility = allSelect[i].style.visibility;
				allSelect[i].style.visibility = "hidden";
			}
		}
		if(this.images.length > 1)
			this.showFleches();
		this.showBackgroundAndFirstPicture(firstImage);
		
	}
	
	this.quit = function()
	{
		
		document.body.style.overflow = "";
		document.body.removeChild(this.LTBackground);
		document.body.removeChild(this.LTImage);
		document.body.removeChild(this.LTClose);
		if(this.fleche_left)
			document.body.removeChild(this.fleche_left);
		if(this.fleche_right)
			document.body.removeChild(this.fleche_right);
		this.LTBackground = null;
		this.LTImage = null;
		this.LTClose = null;
		this.fleche_left = null;
		this.fleche_right = null;
		
		window.onscroll = null;
		
		if(!isIe6())
			document.body.style.overflow = "auto";
		
		showAllFlash();
		
		if(isIe6())
		{
			allSelect = document.getElementsByTagName('select');
			for(var i=0; i<allSelect.length; i++)
				allSelect[i].style.visibility = allSelect[i].oldVisibility;
		}
		
		this.currentImageNumber = 0;
	}
	
	this.next = function()
	{
		if(this.currentImageNumber == this.images.length)
			var nextImageNumber = 1;
		else
			var nextImageNumber = this.currentImageNumber + 1;
			
		this.hideCurrentImage(function(){diapoObj.showImage(diapoObj.images[nextImageNumber-1]);});
		this.currentImageNumber = nextImageNumber;
	}
	
	this.previous = function()
	{
		if(this.currentImageNumber == 1)
			var previousImageNumber = this.images.length;
		else
			var previousImageNumber = this.currentImageNumber - 1;
		
		this.hideCurrentImage(function(){diapoObj.showImage(diapoObj.images[previousImageNumber-1]);});
		
		this.currentImageNumber = previousImageNumber;
	}
	
	this.addImage = function(imageSrc)
	{
		if(imageSrc.toLowerCase().match('jpg') || imageSrc.toLowerCase().match('jpeg') || imageSrc.toLowerCase().match('gif') || imageSrc.toLowerCase().match('png'))
		{
			var imagepreload =new Image;
			imagepreload.src = imageSrc;
			
			document.precharg.push(imagepreload);
			this.images.push(imageSrc);	
		}
	}
	
	
	this.showFleches = function()
	{
		this.fleche_left = document.createElement('img');
		this.fleche_left.src = 'images/mini_left1.png';
		this.fleche_left.id = 'diapo_fleche_left';
		this.fleche_left.style.position = "absolute";
		this.fleche_left.style.top= getWindowTop()+20+'px';
		//this.fleche_left.style.top= getWindowTop()+(document.body.clientHeight/4)+'px';
		this.fleche_left.style.marginLeft = "50%";
		this.fleche_left.style.left = '-20px';
		this.fleche_left.style.cursor = "pointer";
		this.fleche_left.style.height = "30px";
		this.fleche_left.style.zIndex = '99';
		this.fleche_left.onclick = function(){ diapoObj.previous(); };
		
		document.body.appendChild(this.fleche_left);
		
		this.fleche_right = document.createElement('img');
		this.fleche_right.id = 'diapo_fleche_right';
		this.fleche_right.src = 'images/mini_right1.png';
		this.fleche_right.style.position = "absolute";
		this.fleche_right.style.top= getWindowTop()+20+'px';
		//this.fleche_left.style.top= getWindowTop()+(document.body.clientHeight/4)+'px';
		this.fleche_right.style.marginLeft = "50%";
		this.fleche_right.style.left = '20px';
		this.fleche_right.style.cursor = "pointer";
		this.fleche_right.style.height = "30px";
		this.fleche_right.style.zIndex = '99';
		this.fleche_right.onclick = function(){ diapoObj.next(); };
		
		document.body.appendChild(this.fleche_right);
	}
	
	this.showBackgroundAndFirstPicture = function(firstImage)
	{
		
		
		this.LTBackground = document.createElement("div");
		this.LTBackground.id = "LTBackground";
		this.LTBackground.ltDiapo = this;
		this.LTBackground.style.top = getWindowTop()+'px';
		this.LTBackground.style.left = "-5px";
		this.LTBackground.style.padding = "10px";
		this.LTBackground.style.width = "99%";
		if(isIe6())			
			this.LTBackground.style.height = screen.availHeight+'px';
		else
			this.LTBackground.style.height = "98%";
			

		this.LTBackground.style.position = "absolute";
		this.LTBackground.style.display = "none";
		this.LTBackground.onclick = function()
		{
			this.ltDiapo.quit();
		};		
		//this.LTBackground.style.opacity = "0.7";
		this.LTBackground.style.zIndex = "98";
		this.LTBackground.style.backgroundColor = this.backgroundColor;
		
	
		
		document.body.appendChild(this.LTBackground);
		
		this.LTBackground.style.display = "block";
		
		
		
		
		
		
		
		changeOpacity
		(
			'LTBackground',
			0,
			diapoObj.backgroundOpacity,
			10,
			function()
			{
				
				if(!diapoObj.images.length)
					return false;
				
				image1 = diapoObj.images[firstImage-1];
				diapoObj.currentImageNumber = firstImage;
				
				diapoObj.showImage(image1);
			}
			
		);
		
		
		window.onscroll = function()
		{
		
			if(diapoObj.LTBackground) diapoObj.LTBackground.style.top = getWindowTop()+'px';
			if(diapoObj.LTImage) diapoObj.LTImage.style.top = (getWindowTop()+50)+'px';	
			
		}
	}
	
	this.hideCurrentImage = function(after)
	{
		document.body.removeChild(diapoObj.LTClose);
		diapoObj.LTClose = null;
		changeOpacity
		(
			'LTCadre',
			diapoObj.contentOpacity,
			0,
			5,
			function()
			{
				document.body.removeChild(diapoObj.LTImage);
				diapoObj.LTImage = null;
				
				after();
			}
		);	
	}
	
	this.showImage = function(src)
	{
		
		var image = new Image();
		image.src = src;
						
		while(!image.width || !image.height)
		{
		 	setTimeout(function(){diapoObj.showImage(src);},100);
			return null;
			
		}
		
		
		var imageWidth = image.width;
		var imageHeight = image.height;
		
		if(imageWidth > getWindowWidth())
		{
			imageWidth = getWindowWidth()-100;
			imageHeight = (imageWidth*image.height)/image.width;		
			
		}
		if(imageHeight > getWindowHeight())
		{
			imageHeight = getWindowHeight()-150;
			imageWidth = (imageHeight*image.width)/image.height;		
		}
		
		this.LTImage = document.createElement('img');
		
		this.LTImage.id = "LTCadre";
		this.LTImage.style.backgroundColor = '#FFF';
		this.LTImage.style.marginLeft = "50%";
		this.LTImage.style.width = imageWidth+"px";
		this.LTImage.style.height = imageHeight+"px";
		this.LTImage.src = src;
		this.LTImage.style.left = "-"+(imageWidth/2)+"px";
		this.LTImage.style.top = (getWindowTop()+this.top)+'px';
		if(this.borderSize > 0)
			this.LTImage.style.border = 'solid '+this.borderSize+'px '+this.borderColor;
		this.LTImage.style.zIndex = "98";
		this.LTImage.style.overflow = "visible";
		this.LTImage.style.display = 'none';
		this.LTImage.style.position = "absolute";
		//LTCadre.style.border = "solid 2px #666";
		//LTCadre.style.backgroundColor = "#FFF";
		
		
		document.body.appendChild(this.LTImage);
		
		
		this.LTClose = document.createElement("img");
		this.LTClose.id = "LTClose";
		this.LTClose.src = "images/close_button_mini.png";
		
		this.LTClose.ltDiapo = this;
		this.LTClose.style.marginLeft = "50%";
		this.LTClose.style.display = "none";
		this.LTClose.style.backgroundColor = "#666";
		this.LTClose.style.left = ((imageWidth/2)*-1)-20+imageWidth+'px';
		this.LTClose.style.top = (getWindowTop()+this.top)+10+'px';
		
		/*
		this.LTClose.style.padding = "3px";
		this.LTClose.style.fontWeight = "bold";
		this.LTClose.style.fontFamily = "arial";
		this.LTClose.style.color = "#343434";
		this.LTClose.style.fontSize = "12px";
		*/
		this.LTClose.style.zIndex = "99";
		this.LTClose.style.position = "absolute";
		this.LTClose.style.cursor = "pointer";
		this.LTImage.style.display = "block";
		
		this.LTClose.onmouseover = function()
		{
			this.style.color = "#000";
		}
		this.LTClose.onmouseout = function()
		{
			this.style.color = "#343434";
		}
		
		
		this.LTClose.onclick = function()
		{
			this.ltDiapo.quit();
		};		
		
		
		changeOpacity
		(
			'LTCadre',
			0,
			diapoObj.contentOpacity,
			5,
			function()
			{
				if(diapoObj.LTClose)
					diapoObj.LTClose.style.display = "";
			}
			
		);
		
		
		
		document.body.appendChild(this.LTClose); 
		
		
	}
	
	
	if(LtDiaporama.arguments.length)
		for(var j=0;j<LtDiaporama.arguments.length; j++)
			this.addImage(LtDiaporama.arguments[j]);

	
}

function intrasphersDiaporama(identitie,modulename,fileclass,optionsList,numeroImage)
{
	if(!numeroImage)
		numeroImage = 1;
	new Ajax.Request
	(
	 	'indexAjax.php?ajaxmodule=file&opajax=get_diaporama_images',
		{
			method:'post',
			parameters:
			{
				identitie:identitie,
				fileclass:fileclass,
				modulename:modulename
			},
			onSuccess: function(transport)
			{
				var string = transport.responseText;
				if(!string)
					return null;
				
				var files = string.split('!#!');
				
				
				
				var diaporama = new LtDiaporama();
				if(optionsList)
					diaporama.options = optionsList;
				for(var i=0; i< files.length;i++)
				{
					diaporama.addImage(files[i]);
				}
				diaporama.launch(numeroImage);
				
			}
		}	
	);
	
}



function intrasphersDiaporama2(identitie,modulename,fileclass,optionsList,idfile)
{
	
	new Ajax.Request
	(
	 	'indexAjax.php?ajaxmodule=file&opajax=get_diaporama_images',
		{
			method:'post',
			parameters:
			{
				identitie:identitie,
				fileclass:fileclass,
				modulename:modulename,
				idfile:idfile
			},
			onSuccess: function(transport)
			{
				var string = transport.responseText;
				if(!string)
					return null;
				
				var response = string.split('----');
				var numeroImage = parseInt(response[1]); 
				var files = response[0].split('!#!');
				
				
				
				var diaporama = new LtDiaporama();
				if(optionsList)
					diaporama.options = optionsList;
				for(var i=0; i< files.length;i++)
				{
					diaporama.addImage(files[i]);
				}
				if(!numeroImage)
					numeroImage = 1;
				diaporama.launch(numeroImage);
				
			}
		}	
	);
	
}


function showLtImageBox(src, options)
{
	hideAllFlash();
	if(!options)
		options = {};
	
	var backgroundOpacity = (options.backgroundOpacity)?options.backgroundOpacity:60;
	var backgroundColor = (options.backgroundColor)?options.backgroundColor:'#000';
	var contentOpacity = (options.contentOpacity)?options.contentOpacity:100; 
	var after = options.after;
 
	var top = (options.top)?options.top:50;
	var display_title = (options.display_title)?options.display_title:false;
	
	
	
	if(isIe6())
	{
		allSelect = document.getElementsByTagName('select');
		for(var i=0; i<allSelect.length; i++)
		{
			allSelect[i].oldVisibility = allSelect[i].style.visibility;
			allSelect[i].style.visibility = "hidden";
		}
	}
	
	
	if(!document.getElementById("LTBackground"))
	{
		var LTBackground = document.createElement("div");
		LTBackground.id = "LTBackground";
		LTBackground.style.top = getWindowTop()+'px';
		LTBackground.style.left = "-5px";
		LTBackground.style.padding = "10px";
		LTBackground.style.width = "99%";
		if(isIe6())			
			LTBackground.style.height = screen.availHeight+'px';
		else
			LTBackground.style.height = "98%";
			

		LTBackground.style.position = "absolute";
		LTBackground.style.display = "none";
		LTBackground.onclick = function()
		{
			hideLtBox();
			//document.getElementById("LTBackground").style.display = "none";
			//document.getElementById("LTContent").style.display = "none";
		};		
		//LTBackground.style.opacity = "0.7";
		LTBackground.style.zIndex = "98";
		LTBackground.style.backgroundColor = backgroundColor;
		
	
		
		document.body.appendChild(LTBackground);
	}
	
	if(!isIe6())
		document.body.style.overflow = "hidden";
	

	if(!document.getElementById("LTImage"))
	{
		var LTImage = document.createElement('img');
		
		LTImage.id = "LTCadre";
		LTImage.style.marginLeft = "50%";
		LTImage.src = src;
		
		
		var imageWidth = LTImage.width;
		var imageHeight = LTImage.height;
		
		if(imageWidth > getWindowWidth())
		{
			imageWidth = getWindowWidth()-100;
			imageHeight = (imageWidth*LTImage.height)/LTImage.width;		
			
		}
		if(imageHeight > getWindowHeight())
		{
			imageHeight = getWindowHeight()-150;
			imageWidth = (imageHeight*LTImage.width)/LTImage.height;		
		}
		
		LTImage.width = imageWidth;
		LTImage.height = imageHeight;
		
		LTImage.style.left = "-"+(LTImage.width/2)+"px";
		LTImage.style.top = (getWindowTop()+top)+'px';
		LTImage.style.border = 'none';//LTImage.style.border = 'solid 10px #FFF';
		LTImage.style.zIndex = "98";
		LTImage.style.overflow = "visible";
		
		LTImage.style.display = 'none';
		LTImage.style.position = "absolute";
		//LTCadre.style.border = "solid 2px #666";
		//LTCadre.style.backgroundColor = "#FFF";

		document.body.appendChild(LTImage);
		
		
		var LTClose = document.createElement("div");
		LTClose.id = "LTClose";
		LTClose.style.marginLeft = "50%";
		LTClose.style.left = ((LTImage.width/2)*-1)+7+LTImage.width+'px';
		LTClose.style.top = (getWindowTop()+top-2)+'px';
		LTClose.style.padding = "3px";
		LTClose.style.fontWeight = "bold";
		LTClose.style.fontFamily = "arial";
		LTClose.style.color = "#343434";
		LTClose.style.zIndex = "99";
		
		LTClose.style.position = "absolute";
		LTClose.onmouseover = function()
		{
			this.style.color = "#000";
		}
		LTClose.onmouseout = function()
		{
			this.style.color = "#343434";
		}
		
		LTClose.style.fontSize = "12px";
		LTClose.innerHTML = "X";
		LTClose.style.cursor = "pointer";
		LTClose.onclick = function()
		{
			hideLtBox();
		};		


		
		document.body.appendChild(LTClose); 
		
		
		document.getElementById("LTBackground").style.display = "block";

	
			
			changeOpacity
			(
				'LTBackground',
				0,
				backgroundOpacity,
				10,
				function()
				{
					document.getElementById('LTCadre').style.display = "block";
					changeOpacity
					(
						'LTCadre',
						0,
						contentOpacity,
						5,
						function()
						{
							if(after)
								after();
						}			
					);
					
					
				
				
				}
			);
			
			window.onscroll = function()
			{
				if(document.getElementById('LTBackground'))
					document.getElementById('LTBackground').style.top = getWindowTop()+'px';
				if(document.getElementById('LTCadre'))
				   document.getElementById('LTCadre').style.top = (getWindowTop()+50)+'px';	
				
			}
	}
	

	
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////
/////////////////////////////////////////////////		Scripts pour le panel
/////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////



function createPanel(content)
{
	
	var panelWidth = 300;
	var panelHeight = 1000;	
	
	if(!document.getElementById("Panel"))
	{
		var Panel = document.createElement("div");
		Panel.id = "Panel";
		Panel.style.height = panelHeight+"px";
		Panel.style.top = "35px";
		
		
		
		Panel.style.left = "3px";
		Panel.style.position = "absolute";

		Panel.style.zIndex = "20";
	
		

		var PanelButton = document.createElement('div');
		PanelButton.id = "PanelButton";
		//PanelButton.style.border = "solid 1px #777";
		PanelButton.style.padding="0px";
		PanelButton.style.height="30px";
		PanelButton.style.width="30px";
		//PanelButton.style.background= "#DDD";
		//PanelButton.style.borderLeft= "none";
		PanelButton.style.position = "absolute";
		PanelButton.style.right = "0px";
		PanelButton.style.cursor = "pointer";
		PanelButton.style.top = "0px";
		PanelButton.style.left = "0px";
		
		PanelButton.onclick = function()
		{
			openPanel();	
		}
		
		var PanelButtonImg = document.createElement('img');
		PanelButtonImg.src = "images/contact_isphere_128.gif";
		PanelButtonImg.style.width = "30px";
		PanelButtonImg.style.height = "30px";
		
		PanelButton.appendChild(PanelButtonImg);
		
		
		var PanelContent = document.createElement('div');
		PanelContent.id = "PanelContent";
		PanelContent.style.height = "100%";
		PanelContent.style.width = "0px";
		PanelContent.style.overflow = "hidden";
		PanelContent.style.display = "none";
		PanelContent.style.paddingTop = "31px";
		PanelContent.style.opacity = "0.9";
		PanelContent.style.padding = "15px";
		PanelContent.style.backgroundColor = "#444";
		PanelContent.style.color = "#eee";
		PanelContent.style.border = "solid 1px #777";
		PanelContent.innerHTML = content;
		
		Panel.appendChild(PanelContent);
		Panel.appendChild(PanelButton);
		document.getElementById('main1').style.overflowLeft = "hidden";
		document.getElementById("main1").appendChild(Panel);
	}
}

function openPanel()
{
	var panelWidth = 300;
	
	var PanelContent = document.getElementById("PanelContent");
	PanelContent.style.display = "block";
	document.getElementById("PanelButton").onclick = function()
	{
		clearInterval(openingPanelInterval);
		closePanel();	
	}
	
	var openingPanelFunction = function()
    {
		var panelWidthInt = parseInt(PanelContent.style.width);
		if(panelWidthInt < panelWidth)
		{
			PanelContent.style.width = (panelWidthInt+10)+"px";
		}
		else
			clearInterval(openingPanelInterval);
	   
    }
	
	var openingPanelInterval = setInterval(openingPanelFunction,1);
		
}

function closePanel()
{
	var panelWidth = 300;
	
	var PanelContent = document.getElementById("PanelContent");
	


	document.getElementById("PanelButton").onclick = function()
	{
		clearInterval(closingPanelInterval);
		openPanel();	
	}
	
	var closingPanelFunction = function()
    {
		var panelWidthInt = parseInt(PanelContent.style.width);
		if(panelWidthInt > 0)
		{
			PanelContent.style.width = (panelWidthInt-10)+"px";
		}
		else
		{
			clearInterval(closingPanelInterval);
			PanelContent.style.display = "none";
		}
    }
	
	var closingPanelInterval = setInterval(closingPanelFunction,1);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////
/////////////////////////////////////////////////		Scripts pour le loader
/////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////



var Loader = new Loader();

function Loader()
{

	
	this.show = function()
	{
		if(this.running)
			return false;
		if(!document.getElementById("loaderDiv"))
		{
			
			var loaderDiv = document.createElement("div");
			loaderDiv.id = "loaderDiv";
			loaderDiv.style.top = getWindowTop()+'px';
			loaderDiv.style.left = "-5px";
			loaderDiv.style.padding = "10px";
			loaderDiv.style.width = "99%";
			loaderDiv.style.height = "98%";
			loaderDiv.style.position = "absolute";
			loaderDiv.style.display = "none";
			loaderDiv.style.zIndex = "98";
			loaderDiv.style.backgroundColor = "#000";






			
			
			var loader = document.createElement("img");
			loader.src = "images/ajax-loader.gif";
			loader.id = "loader";
			loader.style.top = "300px";
			loader.style.marginLeft = "50%";
			loader.style.left = "-50px";
			loader.style.position = "absolute";
			loader.style.display = "none";
			loader.style.zIndex = "99";
			
			loaderDiv.appendChild(loader);
			
			
			
			document.body.appendChild(loaderDiv);
			document.body.appendChild(loader);
			
			
		}
		
		document.getElementById("loaderDiv").style.display = "block";
		document.getElementById("loader").style.display = "block";
		
		this.running = 1;
		
		changeOpacity('loaderDiv',0,80,10);
		changeOpacity('loader',0,80,10);
		
		window.onscroll = function()
		{
			document.getElementById('loaderDiv').style.top = getWindowTop()+'px';
			document.getElementById('loader').style.top = (getWindowTop()+50)+'px';	
			
		}
		
	
	}

	this.hide = function()
	{
		
		document.getElementById("loaderDiv").style.display = "none";
		document.getElementById("loader").style.display = "none";
		this.running = 0;
	}
}




















var mouseLoader = new mouseLoader();

function mouseLoader()
{
	this.show = function()
	{
		if(this.running)
			return false;
		if(!document.getElementById("loaderDiv"))
		{
			
			var loaderDiv = document.createElement("div");
			loaderDiv.id = "mouseloaderDiv";
			loaderDiv.style.top = getWindowTop()+'px';
			loaderDiv.style.left = "-5px";
			loaderDiv.style.padding = "10px";
			loaderDiv.style.width = "99%";
			loaderDiv.style.height = "98%";
			loaderDiv.style.position = "absolute";
			loaderDiv.style.display = "none";
			loaderDiv.style.zIndex = "98";
			loaderDiv.style.cursor = "wait";

			
			
			var loader = document.createElement("img");
			loader.src = "images/ajax-loader2.gif";
			loader.id = "mouseloader";
			loader.style.top = "10px";
			loader.style.left = "10px";
			loader.style.position = "absolute";
			loader.style.display = "none";
			loader.style.zIndex = "99";
			
		
			
			
			
			document.body.appendChild(loaderDiv);
			document.body.appendChild(loader);
			
	
		}
		
		document.getElementById("mouseloaderDiv").style.display = "block";
		document.getElementById("mouseloader").style.display = "block";
		
		this.running = 1;
		window.onscroll = function()
		{
			document.getElementById('mouseloaderDiv').style.top = getWindowTop()+'px';
			document.getElementById('mouseloader').style.top = getWindowTop()+10+'px';
		}
	}
	this.hide = function()
	{
		document.getElementById("mouseloaderDiv").style.display = "none";
		document.getElementById("mouseloader").style.display = "none";
		this.running = 0;
	}
}






















/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////		
/////////////////////////////////////////////////	Scripts pour l'infobulle
/////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////











var currentInfobulle = "";
var contentinfobulle = new Array();
function killInfobulle()
{
	if(currentInfobulle)
		document.body.removeChild(document.getElementById(currentInfobulle));
	
	currentInfobulle = "";
}
function getInfobulle(div,e,cptid)	
{

	
	if(currentInfobulle)
		document.body.removeChild(document.getElementById(currentInfobulle));
	
	var Mouse_X = e.pageX;
	var Mouse_Y = e.pageY;
	
	if( !Mouse_X ||  !Mouse_Y)
	{                   
		var Mouse_X = window.event.clientX;
		var Mouse_Y = window.event.clientY+getWindowTop();
		
		
	}

	
	var infobulle = document.createElement('div');
		
	infobulle.id = cptid+"_infobulle";
//	infobulle.setAttribute("style","position:absolute;");
	
	
	infobulle.style.position = "absolute";

	infobulle.style.top = parseInt(Mouse_Y+3)+"px";
	infobulle.style.left = parseInt(Mouse_X+3)+"px";
	infobulle.style.zIndex = "999"; 
	infobulle.style.display = 'block';
	infobulle.style.backgroundColor = "#FEFAE9";
	infobulle.style.border = "solid 1px #777";
	infobulle.style.padding = "10px";
	infobulle.style.fontSize = "13px";
	infobulle.style.fontFamily = "Arial, Helvetica, sans-serif";
	
	
	infobulle.innerHTML = document.getElementById("infobulle_content"+cptid).innerHTML;

	document.body.appendChild(infobulle);
	
	currentInfobulle = infobulle.id;

	
	
}		

function setInfobulleContent(occ,content)
{

	contentinfobulle[occ] = content;


}	


//// OUVERTURE DIV PROGRESSIVE ( a tester )
function showDivDegrade(divid,height,width,speed,afterFunction)
{

	if(!speed)
		speed = 5;
	
	var div = document.getElementById(divid)
	if(!div.isOpeningInDegrade)
	{
		div.style.height = '0px';
		div.style.width = '0px';
		div.style.display = 'block';
	}
	
	div.isOpeningInDegrade = 1;
	
	var currentHeight = parseInt(div.style.height);
	var currentWidth = parseInt(div.style.width);
	
	div.style.height = (currentHeight+speed)+'px';
	div.style.width = (currentWidth+speed)+'px';
	
	currentHeight = currentHeight+speed	
	if(currentWidth < width)
	{
		var timeout = function()
		{
			showDivDegrade(divid,height,width,speed,afterFunction);
		}
		setTimeout(timeout,1);	
	}
	else
	{
		div.isOpeningInDegrade = 0;
		if(afterFunction)
			afterFunction();
	}
}













function openDivProg(divid,options) /// DEPRECATED AU PROFIT DE LA FONCTION DAPRES
{

	if(!options)
		options = {};
		
	var speed = (options.speed)?options.speed:5;
	var height = options.height;
	var width  = options.width;
	
	var min_height = (options.min_height)?options.min_height:0;
	var max_height = (options.max_height)?options.max_height:height;
	var min_width = (options.min_width)?options.min_width:0;
	var max_width = (options.max_width)?options.max_width:width;
	
	
	var after = options.after;
	var direction = (options.direction)?options.direction:1; // 1 vertical  2 horrizontal
	
	var div = document.getElementById(divid);
	
	
	
	var currentHeight = (parseInt(div.style.height))?parseInt(div.style.height):div.offsetHeight;
	var currentWidth = (parseInt(div.style.width))?parseInt(div.style.width):div.offsetWidth;
	
	
	if(div.isOpen)
	{
		
				
				if(!div.isOpeningInDegrade)
				{
					div.style.overflow = 'hidden';
				}
				
				div.isOpeningInDegrade = 1;
				
				
				if(direction == 1)
				{
					div.style.height = (currentHeight-speed)+'px';
					currentHeight = currentHeight-speed;
				}
				else
				{
					div.style.width = (currentWidth-speed)+'px';
					currentWidth = currentWidth-speed;
				}
				
				if( ( direction == 1 && (currentHeight-speed) > min_height ) || ( direction != 1 && ( currentWidth - speed ) > min_width ) )
				{
					var timeout = function()
					{
						openDivProg(divid,options)
					}
					setTimeout(timeout,1);	
				}
				else
				{
					div.isOpeningInDegrade = 0;
					//div.style.overflow = '';
					if(!min_height && !min_width)
						div.style.display = 'none';
					div.isOpen = 0;
				}
	}
	else
	{
			
						
				if(!div.isOpeningInDegrade)
				{
					div.style.overflow = 'hidden';
					
					if(direction == 1)
						div.style.height = (min_height)?min_height+'px':'0px';
					if(direction == 2)
						div.style.width = (min_width)?min_width+'px':'0px';
					
					div.style.display = 'block';
				}
				
				div.isOpeningInDegrade = 1;
				
				
				if(direction == 1)
				{
					var currentHeight = div.offsetHeight;
					var newHeight = (currentHeight+speed)+'px';
					div.style.height = newHeight;
				
					var currentValue = parseInt(newHeight);
					var finalValue = max_height;
				}
				else
				{
					var currentWidth = div.offsetWidth;
					var newWidth = (currentWidth+speed)+'px';
					div.style.width = newWidth;
					
					var currentValue = parseInt(newWidth);
					var finalValue = max_width;
				}
					
			
			
				if(currentValue < finalValue)
				{
					var timeout = function()
					{
						openDivProg(divid,options)
					}
					setTimeout(timeout,1);	
				}
				else
				{
					div.isOpeningInDegrade = 0;
					div.style.overflow = '';
					div.isOpen = 1;
					if(after)
						after();
				}
		
	}
	

}




/////// VERSION PLUS EFFICACE 


function fermetureProgressive(divid,options)
{
	if(!options)
		var options = {};
	options.sens = 'down';
	
	if(!options.startHeight)
	{
		options.startHeight = document.getElementById(divid).offsetHeight;
	}
	
	if(!options.height)
		options.height = 0;
	
	ouvertureProgressive(divid,options);
}
function ouvertureProgressive(divid,options)
{

	if(!options)
		options = {};
		
	var speed = (options.speed)?options.speed:5;
	var height = options.height;
	var startHeight = (options.startHeight)?options.startHeight:'0';
	var after = options.after;
	var div = document.getElementById(divid);
	
	
	if(!height && options.sens != 'down')
	{
		
		div.style.display = "block";
		var autoHeight = div.offsetHeight;
		div.style.display = "none";
		
		height = autoHeight;
		options.height = height;
		
	}
	
	
	
	if(!options.sens)
	{
		if(height > startHeight)
			options.sens = 'up';
		else
			options.sens = 'down';		
	}
	
	var sens = options.sens;
	
	
	if(!div.isOpeningInDegrade)
	{
		div.style.overflow = 'hidden';
		div.style.height = startHeight+'px';
		div.style.display = 'block';
	}
	
		
	div.isOpeningInDegrade = 1;
	
	
	var currentHeight = parseInt(div.style.height);
	if(sens == 'up')
		var newHeight = (currentHeight+speed)+'px';
	else
		var newHeight = (currentHeight-speed)+'px';

	div.style.height = newHeight;

	var currentValue = parseInt(newHeight);
	var finalValue = height;




	if( ( sens == 'up' && currentValue < finalValue) || ( sens == 'down' && currentValue > finalValue ) )
	{
		var timeout = function()
		{
			ouvertureProgressive(divid,options)
		}
		setTimeout(timeout,1);	
	}
	else
	{
		div.isOpeningInDegrade = 0;
		if(sens == 'up')
			div.style.overflow = '';
		else
			div.style.display = 'none';
			
		div.isOpen = 1;
		div.style.height = '';
		if(after)
			after();
	}
	

}













//// CHANGEMENT D'OPACITE DUNE DIV

function changeOpacity(divid,begin,end,speed,after)
{

	if(!speed)
		speed = 1;
	var opacity = 0;
	
	var div = document.getElementById(divid)
	
	div.isChangingOpacity = 1;
	opacity = begin;		
	
	
	if(begin<end)
		var sens = 1;
	else
		var sens = 0

	
	if(sens == 1)
		opacity = opacity + speed;
	else
		opacity = opacity - speed;
		
	if(opacity > 100)
		opacity = 100;
	if(opacity < 0)
		opacity = 0;
	
	var style = div.style
	
	style.opacity = (opacity / 100);
    style.MozOpacity = (opacity / 100);
    style.KhtmlOpacity = (opacity / 100);
    style.filter = "alpha(opacity=" + opacity + ")";

	if(opacity != end)
	{
		var timeout = function()
		{
			changeOpacity(divid,opacity,end,speed,after)
		}
		setTimeout(timeout,1);	
	}
	else
	{
		div.isChangingOpacity = 0;
		if(after)
			after();
		
	}
}


//// GENERATION FICHIERS XLS

function exportTableXls()
{
	var allDivs = document.getElementsByTagName('DIV');
	
	for(var i=0; i< allDivs.length; i++)
	{
		if(allDivs[i].className.match(' table'))
		{
			var table = allDivs[i];
			break;
		}
	}	
	
	if(!table)
	{
		alert("Aucune table détéctée sur cette page");	
		return false;
	}
	
	//var html = '<div>'+table.innerHTML+'</div>';
	
	
	var html = '<table>';
	
	
	
	for(var j=0; j<table.childNodes.length; j++)
	{
		

		
			
		
		if(table.childNodes[j])
		{
			
			
			var line = table.childNodes[j];
			if(!line.tagName)
				continue;
			if(line.tagName.toLowerCase() != 'div')
				continue;
			
			html += "\n\t"+'<tr>';
			
			for(var k=0; k< line.childNodes.length; k++)
			{
				if(!line.childNodes[k].tagName)
					continue;
				if(line.childNodes[k].tagName.toLowerCase() != 'div')
					continue;
				html += "\n\t\t"+'<td>';
				html += "\n\t\t\t"+line.childNodes[k].innerHTML;
				html += "\n\t\t"+'</td>';
			}
		
			html += "\n\t"+'</tr>';
		}
		
		
	}
	
	html += "\n"+'</table>';
	
	document.write(html)
	
	
	
	
	
}


function generateGoogleMap(num,street,cp,ville,options)
{
	// ex : generateGoogleMap('50','rue ferdinand buisson','62200','boulogne sur mer',{width:500,height:500,frameborder:0});
	if(options)
	{
		var scrolling = options.scrolling;
		var frameborder = options.frameborder;
		var height = options.height;
		var width = options.width;
		var marginheight = options.marginheight;
		var marginwidth = options.marginwidth;
	}

	var frame = document.createElement('iframe');
	frame.width = width;
	frame.scrolling = scrolling;
	frame.frameborder = frameborder;
	frame.marginheight = marginheight;
	frame.marginwidth = marginwidth;
	

	
	frame.src = "http://maps.google.fr/maps?f=q&amp;source=s_q&amp;hl=fr&amp;geocode=&amp;q="+q+"&amp;sll=46.75984,1.738281&amp;sspn=13.445012,26.784668&amp;ie=UTF8&amp;hnear=50+Rue+Ferdinand+Buisson,+62200+Boulogne-sur-Mer,+Pas-de-Calais,+Nord-Pas-de-Calais&amp;hq=&amp;z=16&amp;ll=50.716358,1.607099&amp;output=embed";
	
	document.getElementById('main1').appendChild(frame);
	
	
	
	
}



///// DEMANDE DE COMMENTAIRES SUR LE CHANGEMENT DUN CHAMP

function askComments(field,validFunction,iduser,idmodulename,identitie)
{
	var oldValue = field.originalDisplayValue;
	var newValue = getFieldDisplayValue(field.id);
	var idelement = field.idelement;
	var labelValue = document.getElementById('lab_'+field.id).innerHTML;
	
	
	var div = document.createElement('DIV');
	
	var formfieldformlog = document.createElement('FORM');
	formfieldformlog.name = "formfieldformlog";
	formfieldformlog.id = "formfieldformlog";
	
	var text = document.createElement('p');
	text.innerHTML = 'Vous venez de changez la valeur du champ "'+field.id+'"<br/>valeur initiale : '+oldValue+'<br/>valeur nouvelle : '+newValue+'<br/>Cela necessite un commentaire de votre part expliquant pourquoi vous l\'avez fait<br/><br/>';
	
	var newValueInput = document.createElement('INPUT');
	newValueInput.id = "newvalue";
	newValueInput.name = "newvalue";
	newValueInput.type = "hidden";
	newValueInput.value = newValue;
	
	
	var idmodulenameInput = document.createElement('INPUT');
	idmodulenameInput.id = "idmodulename";
	idmodulenameInput.name = "idmodulename";
	idmodulenameInput.type = "hidden";
	idmodulenameInput.value = idmodulename;
	
	var identitieInput = document.createElement('INPUT');
	identitieInput.id = "identitie";
	identitieInput.name = "identitie";
	identitieInput.type = "hidden";
	identitieInput.value = identitie;
	
	var iduserInput = document.createElement('INPUT');
	iduserInput.id = "iduser";
	iduserInput.name = "iduser";
	iduserInput.type = "hidden";
	iduserInput.value = iduser;
	
	var oldValueInput = document.createElement('INPUT');
	oldValueInput.id = "oldvalue";
	oldValueInput.name = "oldvalue";
	oldValueInput.type = "hidden";
	oldValueInput.value = oldValue;
	
	var idelementInput = document.createElement('INPUT');
	idelementInput.id = "idelement";
	idelementInput.name = "idelement";
	idelementInput.type = "hidden";
	idelementInput.value = idelement;
	
	var commentsInput = document.createElement('TEXTAREA');
	commentsInput.id = "comments";
	commentsInput.name = "comments";

	var button = "<input type=\"button\" value=\"valider\" onclick=\"ajaxRecordForm('formfieldformlog',{entitietype :'fieldformlog',onSuccess : function(){document.getElementById('"+field.id+"').originalDisplayValue = '"+newValue+"';hideLtBox();"+validFunction+";}});\"/>";


	formfieldformlog.appendChild(text);
	formfieldformlog.appendChild(iduserInput);
	formfieldformlog.appendChild(newValueInput);
	formfieldformlog.appendChild(idmodulenameInput);
	formfieldformlog.appendChild(identitieInput);
	formfieldformlog.appendChild(oldValueInput);
	formfieldformlog.appendChild(idelementInput);
	formfieldformlog.appendChild(commentsInput);
	formfieldformlog.innerHTML += button;
	div.appendChild(formfieldformlog);

	showLtBox(div.innerHTML);
}





















//// ajaxFilter

function updateUserParameter(idparam,iduser,value,after)
{
		var url = 'indexAjax.php?ajaxmodule=userparam&iduser='+iduser+'&opajax=record&idparam='+idparam+'&value='+value;

		new Ajax.Request
		(
			url,
			{
				method : "POST",
				onSuccess : after
			}							
		);
}

function ajaxFilter(options)
{
		var idfield = options.idfield;
		var iduser = options.iduser;
		var idparam = options.idparam;
		var fieldtype = options.fieldtype;
		
		var field = document.getElementById(idfield);
		
		
		
		

		var currentClassname = document.getElementById('filterbutton_'+idfield).className;
		if(currentClassname.match('filterbutton1'))
			var state = '1';
		else
			var state = '0';
		
		document.getElementById('filterbutton_'+idfield).state = state;
		
		
		var updateFunction = function()
		{
				var value = '';
				if(document.getElementById('filterbutton_'+idfield).state=='1')
					value = getFieldValue(idfield);
		
		
				currentPaginationNumber = 1;
		
				document.getElementById("loader"+idfield).style.display = '';
		
				updateUserParameter
				(
				 	idparam,
					iduser,
					value,
					function()
					{
						var blocksToReload = new Array();
						
						var tabligne = getElementByIdLike("tabligne_");
						
						// on verifie que le tableau ne contien pas "blocktoreload" car sinon il sera ajouté deux fois dans la liste des blocks a recharger et ca ne marchera pas
						if(tabligne && !tabligne.parentNode.className.match('blocktoreload'))
							blocksToReload.push(tabligne.parentNode.className);
						
							

						if(document.getElementById("allpagesLinksAjax1"))
							blocksToReload.push("allpagesLinksAjax");
						if(document.getElementById("nextLinkAjax1"))
							blocksToReload.push("nextLinkAjax");
						if(document.getElementById("backLinkAjax1"))
							blocksToReload.push("backLinkAjax");
						
						
						var otherBlocksToReload = getElementsByClass('blocktoreload');
						for(var i=0; i<otherBlocksToReload.length; i++)
							blocksToReload.push(otherBlocksToReload[i].className);
						
						
								
						if(blocksToReload.length)
						{
							reloadBlocksArray
							(
								blocksToReload,
								{
									onSuccess : function()
									{ 
									
										document.getElementById("loader"+idfield).style.display = "none";
									}
								}
							);
						}
						else
							document.getElementById("loader"+idfield).style.display = "none";
					}							
				);
		
		}
		
		var updateFunctionForOnchange = function()
		{
				if(document.getElementById('filterbutton_'+idfield).state == '1')
					setTimeout(updateFunction,30);			
		}
		
		
		document.getElementById('filterbutton_'+idfield).onclick = function()
		{
				if(this.state == '1')
					this.state = '0';
				else
					this.state = '1';
					
				this.className = 'filterbutton'+this.state; 
				
				updateFunction();
		
		}
		
		
		if(fieldtype == 'select')
				addEvent(field,'change',updateFunctionForOnchange,false);
		else if(fieldtype == 'datetimefield' || fieldtype == 'ajaxautocompleter')
				field.onchangeForFilters = updateFunctionForOnchange;
		else if(fieldtype == 'text')
		{
				var updateFunctionForText = function()
				{
						if(field.timeOutForFilters)
								clearTimeout(field.timeOutForFilters);
						field.timeOutForFilters = setTimeout(updateFunctionForOnchange,1000);					
				}
			
				addEvent(field,'keypress',updateFunctionForText,false);
		
		}
}

/// Ajax orderby 

	function updateOrderbyParam(field,orderway,iduser,idparamorderby,idparamorderway)
		{
			new Ajax.Request
			(
				"indexAjax.php?ajaxmodule=userparam&iduser="+iduser+"&idparam="+idparamorderby+"&value="+field,
				{
					method : "POST",
					onSuccess : function()
					{
						new Ajax.Request
						(
							"indexAjax.php?ajaxmodule=userparam&iduser="+iduser+"&idparam="+idparamorderway+"&value="+orderway,
							{
								method : "POST",
								onSuccess : function()
								{
									reloadTables();
								}
							}
						);
					}
				}
			);
		}		
		
		
		
		
		

function setCtrl_s(function_to_execute)
{
	document.body.onkeypress = function(event)
	{
    	if(event.ctrlKey == true && event.charCode == 115)
		{
			function_to_execute();
			return false;
		}
	}
    return true;
}


















//// defilbds

function defilbds(divname,sens)
{
	var cpt = 1;
	
	var nbdiv = 0;
	var div;
	while(div = document.getElementById(divname+cpt))
	{
		if(div.style.display != "none")
			var currentOccurrence = cpt;
		cpt++;
	}
	
	nbdiv = cpt-1;
	
	var occurrenceToLoad = 0;
	
	if(sens == 1)
	{
		if(currentOccurrence == nbdiv)
			occurrenceToLoad = 1;
		else
			occurrenceToLoad = currentOccurrence+1; 
	}
	else
	{
		if(currentOccurrence == 1)
			occurrenceToLoad = nbdiv;
		else
			occurrenceToLoad = currentOccurrence-1; 
	}
	
	//changeOpacity(divname+currentOccurrence,100,0,5,function()
	//{
		document.getElementById(divname+currentOccurrence).style.display = "none";
	//	changeOpacity(divname+occurrenceToLoad,0,100,5);
		document.getElementById(divname+occurrenceToLoad).style.display = "";
	//});

}


/* UPLOAD */

/*
 function uploadVerifInfos(idfield)
{
	
		var formupload = document.forms["formUpload"+idfield];
		var identitieField = formupload.elements["fileuploader_"+idfield+"_identitie"];
		identitie = identitieField.value;
		if(!identitie)
		{
		
			alert('Afin de pouvoir integrer des fichiers, vous devez valider ce formulaire au moins une fois');						
			validFlag = 0;
		}
		else
		{
			validFlag = 1;
		}
		
		return validFlag;
}
	
			*/
			 function intrasphersUpload(idfield,modulename,identitie)
			 {
				
				
			 	var formupload = document.getElementById("formUpload"+idfield);
				if(identitie)
					formupload.elements["fileuploader_"+idfield+"_identitie"].value = identitie;
				else
					formupload.elements["fileuploader_"+idfield+"_identitie"].value = document.forms['form'+modulename+'1'].elements['id'+modulename].value;
				
				
				formupload.submit();
				
				document.getElementById("messageCallBack"+idfield).innerHTML = '<img src="images/load.gif" />';
				formupload.elements[idfield].value = '';
				formupload.elements["fileuploader_"+idfield+"_title"].value = '';
				
			 }
			 
			
			
			 function showImagePreview(idfile)
			 {
				
				var infosDiv = document.getElementById("galleryimage"+idfile);
				
				var infos = new Array();
				
				for(var i=0; i < infosDiv.childNodes.length; i++)
				{
					if(infosDiv.childNodes[i].className)
						infos[infosDiv.childNodes[i].className] = infosDiv.childNodes[i].innerHTML;
				
				}
				
				
				var imagesInfos = document.getElementById("galleryInfos").getElementsByTagName("div");
				
				if(imagesInfos.length > 1)
				{
					
					for(var j=0; j<imagesInfos.length ; j++)
					{
						if(imagesInfos[j].id == "galleryimage"+idfile)
						{
							
							
							
							if(j == imagesInfos.length-1)
							{	
								var nextPictInfosDiv = imagesInfos[0];
								var previousPictInfosDiv = imagesInfos[j-1];
							}
							else if(!j)
							{
								var nextPictInfosDiv = imagesInfos[1];
								var previousPictInfosDiv = imagesInfos[imagesInfos.length-1];
							}
							else
							{
								var nextPictInfosDiv = imagesInfos[j+1];
								var previousPictInfosDiv = imagesInfos[j-1];	
							}
						}
					}
				
					
					var nextPictInfos = nextPictInfosDiv.getElementsByTagName("span");
					var previousPictInfos = previousPictInfosDiv.getElementsByTagName("span");
					
					var nextId = nextPictInfos[0].innerHTML;
					var previousId = nextPictInfos[0].innerHTML;
				
					var nextAndBackLinks = "<img src=\"images/right.gif\" style=\"position:absolute;height:25px;cursor:pointer;right:20px;top:40px;\" onclick=\"showImagePreview("+nextId+");\"/><img src=\"images/left.gif\" style=\"position:absolute;height:25px;cursor:pointer;left:20px;top:40px;\" onclick=\"showImagePreview("+previousId+");\">";
				
				
				
				}
				else
					var nextAndBackLinks ="";
				
				
			
				height = parseInt(infos["height"]);
				width = parseInt(infos["width"]);
				
				if(height > 470 || width > 470 )
				{
					if(height > width )
					{
						width = (width*470)/height;
						height = 470;
					}
					else
					{
						height = (height*470)/width;
						width = 470;
					}
				}
				
				
				
				var preview = nextAndBackLinks+"<div style=\"text-align:center\">"
				+"<h1>"+infos["title"]+"</h1>"
				+"<img src=\""+infos["src"]+"\" style=\"max-width:"+width+"px;max-height:"+height+"px;\"><br/><br/>"
				+"<div>"+infos["description"]+"</div>"
				+"</div>";
				
				width = width+20;
				height = height+75;
				
				showLtBox(preview,{width:500,height:height,contentOpacity:100});
				 
				 
			 }
		
			 
			 function moveFile(idfile,sens,modulename)
			 {
				new Ajax.Request("indexAjax.php?ajaxmodule=file&opajax=movefile&sens="+sens+"&idfile="+idfile,{onSuccess:function(){showFilesList(modulename);}}); 
			 }
		
		
			 function showFilesList(modulename,idfield)
			 {
				if(!document.getElementById("df"+modulename))
					return '';
				var identitie = 0;
				if(document.getElementById("id"+modulename))	
					identitie = document.getElementById("id"+modulename).value;
				if(!identitie)
					return false;
					
				new Ajax.Request
				(
					"indexAjax.php?ajaxmodule=file&opajax=list",
					{
						method : "POST", 
						parameters : 
						{
							modulename : modulename,
							identitie : identitie
						},
						onSuccess : function(transport)
						{
							document.getElementById("df"+modulename).innerHTML = transport.responseText;
						}									
					}
				);
			 }







function intrasphersAjaxLogin(uid,pwd,onLog,onFail,stayConnected)
{
	new Ajax.Request
	(
	 	"indexAjax.php?ajaxmodule=users&opajax=login",
		{
			
			method : "post",
			parameters : 
			{
				uid : uid,
				pwd : pwd,
				stayConnected :stayConnected 
			},
			onSuccess : function(transport)
			{
				
				var retour = transport.responseText.split('!--!');
				var code = retour[0];
				var message = retour[1];
				
				
				var logged = 0;
				if(code == 'logged' && onLog)
				{
					onLog(message);
				}
				
				if(code != 'logged' && onFail)
				{
					onFail(message);
				}
				
			
				
			}		
		}
	);
	
}


function exportPDF(page)
{

	if(page.match('='))
		page += "&pdfexport=1";
	else
		page += '?pdfexport=1';
		

	if(document.getElementById('frame_for_pdf_export'))
	{
		document.getElementById('frame_for_pdf_export').src = page;
		return null;
	}
	
	var frame = document.createElement('IFRAME');
	frame.style.display = "none";
	
	frame.src = page;
	frame.id = "frame_for_pdf_export";
	
	document.body.appendChild(frame);
}

function LTBulle(options)
{
	if(!options)
		var options = {};
		
	var id = (options.id)?options.id:'bulle';
	var content = options.content;
	var linkedElement = options.linkedElement;
	if(typeof(linkedElement) != 'object')
		var linkedElement = document.getElementById(linkedElement);
	
	this.createLTBulle = function()
	{
		var bulleElement = document.createElement("DIV");
		bulleElement.id = 'bulle';
		bulleElement.className = 'LTBulle';
		return bulleElement;
	}
}


function LTZoom(imageid,factor)
{
	
	var imageElement = document.getElementById(imageid);
	if(document.getElementById(imageid+"_zoomversion"))
			imageElement.parentNode.removeChild(document.getElementById(imageid+"_zoomversion"))
		
		
		
		var zoomVersion = document.createElement('IMG');
		zoomVersion.src = imageElement.src;
		zoomVersion.id = imageElement.id+"_zoomversion";
		zoomVersion.style.position = "absolute";
		zoomVersion.onmouseout = function()
		{
			imageElement.parentNode.removeChild(document.getElementById(imageid+"_zoomversion"))	
		}
		
		
		if(factor)
		{
			zoomVersion.height = imageElement.offsetHeight*factor;
			zoomVersion.width = imageElement.offsetWidth*factor;
		}
		
			zoomVersion.style.top = (imageElement.offsetTop-((zoomVersion.height-imageElement.height)/2))+"px";
		zoomVersion.style.left = (imageElement.offsetLeft-((zoomVersion.width-imageElement.width)/2))+"px";
	
		imageElement.parentNode.appendChild(zoomVersion);
}



function intrasphersCounter(name,after)
{
	ajaxInsert('indexAjax.php?ajaxmodule=counter&opajax=incremente&name='+name,after);	
	
}



function intrasphersChrono()
{
	this.running = 0;
	this.time = 0;
	this.baliseId = "";
	var time = this.time;
	
	var chronoObject = this;
	
	this.displayTime = function()
	{
		var secondes = chronoObject.time%60;
		var minutesTotal = (chronoObject.time-secondes)/60;
		var minutes = minutesTotal%60;
		var heures = (minutesTotal-minutes)/60;
		
		if(secondes < 10)
			secondes = "0"+secondes;
		if(minutes < 10)
			minutes = "0"+minutes;
		if(heures < 10)
			heures = "0"+heures;
		
		
		
		var display = heures+":"+minutes+":"+secondes;
		setBaliseContent(chronoObject.baliseId,display);
		
	}
	
	this.start = function()
	{
		this.running = 1;
		this.timer = setTimeout(function()
		{
			chronoObject.time = chronoObject.time + 1;
			if(chronoObject.baliseId)
				chronoObject.displayTime();
			chronoObject.start();
		},1000);
	}
	
	this.stop = function()
	{
		this.running = 1;
		clearTimeout(this.timer);		
	}
}


	function getSelectOptionByValue(idselect,value)
	{
		var select = document.getElementById(idselect);
		for(var i=0; i<select.options.length; i++)
		{
			if(select.options[i].value == value)
			{
				return select.options[i];
			}
		}
	}
	
	function colorOption(idselect,searchedValue,color)
	{
		var option = getSelectOptionByValue(idselect,searchedValue);
		option.style.backgroundColor = color;
	}
