var currentPaginationNumber = 1;



//// rechargement des blocks


function reloadBlock(divname,options)
{
	//Loader.show();
	if(!divname)
		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="+divname;
	if(urlparameters) 
		for(var prop in urlparameters)
			url += '&'+prop+'='+urlparameters[prop];


	
	new Ajax.Request
	(	
		url,
		{
			method : "POST",
			parameters : parameters,
			onSuccess : function(transport)
			{
			
				setOuterHtml(document.getElementById(divname+'1'),transport.responseText);
				//document.getElementById(divname+'1').innerHTML = transport.responseText;
			
				
				if(onSuccess2)
					onSuccess2();
				//Loader.hide();
			}
		}
	);
}



function reloadTables(parameters)
{

	var allDivs = document.getElementsByTagName('DIV');
	for(var i=0; i<allDivs.length; i++)
		if(allDivs[i].className.match(" table"))
		{
			reloadBlock(allDivs[i].className,{parameters : parameters});
			return true;
		}
	
}

function reloadTables(parameters)
{ 
		var allDivs = document.getElementsByTagName('DIV');
		for(var i=0; i<allDivs.length; i++)
			if(allDivs[i].className.match(" table"))
			{
				//alert(allDivs[i].className);
				reloadBlock(allDivs[i].className,{parameters : 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.php5?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.php5?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;
}

// 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;
	}
	
	return  (EnterKey == touche) 
	
}


// SIMPLIFICATION DU INNERHTML


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.php5?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.php5?ajaxmodule=ajax&opajax=recordobject&entitietype='+entitietype+'&identitie='+identitie;
	
	new Ajax.Request
	(
		ajaxRecordUrl,
		{
			method : "POST",
			parameters : values,
			onSuccess : onSuccess				

		}
	);
	
}

var controlFieldArray = 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 controlField(formid,idfieldform,entitietype,onSuccess)
{

	var formtorecord = document.getElementById(formid);
	
	var identitie = formtorecord.elements[0].value;
	
	var values = getFormValues(formtorecord);
	
	new Ajax.Request
	(
		'indexAjax.php5?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)
{
	var controls = getFieldControls(formid);
	var form = document.getElementById(formid);
	
	if(!controls)
	{
		if(formfunction)
			formfunction();
		else
			form.submit();
			
		return true;
	}
	
	var controlsText = "";
	
	var identitie = form.elements['id'+entitieType].value

	
	values = getFormValues(form);
	
	
	for(var i=0; i<controls.length; i++)
	{
		if(controlsText)
			controlsText += ';';
		controlsText += controls[i].idcontrolmethod+':'+controls[i].field;
	}
	
	values['controls'] = controlsText;
	
	new Ajax.Request
	(
	 	'indexAjax.php5?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)
							form.elements[field].value = newValue;	
						if(error)
						{
							if(errorMsg)
								errorMsg += '<br/>';
							errorMsg += error;
						}
					}
					if(errorMsg)
					{
						showLtBox(errorMsg);
						return '';
					}
				}
				
				if(formfunction)
				{
					formfunction();
				}
				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.php5?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(initUploader)
					initUploader();
			}
		}
	);
}



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 = '';
	}
}

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).style.display = 'none';	
	
}

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);

	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
		value = field.value;
		
	return 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;
}

// 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.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(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('*');
	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];
	
}


// getWindowTop





function getWindowTop()
{
	
	if(document.documentElement)
	{
		var top = document.documentElement.scrollTop;
	}
	else
		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()
{
	document.body.removeChild(document.getElementById('LTBackground')); 
	document.body.removeChild(document.getElementById('LTCadre'));  	
	if(!isIe6())
		document.body.style.overflow = "auto";
		
	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');





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 showLtBox(content, options)
{

	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 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()+50)+'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.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()
			{
				document.getElementById('LTBackground').style.top = getWindowTop()+'px';
				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";

	
}





/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////
/////////////////////////////////////////////////		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)
{

	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();
				}
		
	}
	

}


//// 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.php5?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 tabligne = getElementByIdLike("tabligne_");
							if(tabligne)
							{
									reloadBlock
									(
									 		tabligne.parentNode.className,
											{
													onSuccess : function()
													{ 
														document.getElementById("loader"+idfield).style.display = "none";
													}
											}
									);				
							}
							else
								document.getElementById("loader"+idfield).style.display = "none";

							if(document.getElementById("allpagesLinksAjax1"))
								reloadBlock("allpagesLinksAjax");
							if(document.getElementById("nextLinkAjax1"))
								reloadBlock("nextLinkAjax");
							if(document.getElementById("backLinkAjax1"))
								reloadBlock("backLinkAjax");

					}							
				);
		
		}
		
		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.php5?ajaxmodule=userparam&iduser="+iduser+"&idparam="+idparamorderby+"&value="+field,
				{
					method : "POST",
					onSuccess : function()
					{
						new Ajax.Request
						(
							"indexAjax.php5?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 = "";
	});
	
	
	
	
}


