
//fonction pour ajouter des log à un div
function addLogBox(reponse,autoLog){
	//génération d'un nouvel id
	autoLog.auto_id++;
	$(autoLog.id_div).innerHTML += reponse+"<br/>";
	autoLog.Effet.toBottom();
	if(fenetreInformation.currentTaille=='minimize'){
		autoLog.fxColor.start('color', '#CC4444').chain(function(){autoLog.fxColor.start('color', '#FFFFFF')});
	}
}
//prototype pour générer automatiquement des id pour les log
function ini_autoIdLog(iddiv){

	//initialisation du compteur
	this.auto_id = 0;
	this.id_div = iddiv;

	this.fxColor = new Fx.Tween($('titre_information'));
	this.Effet = new Fx.Scroll(iddiv, {offset: {'x': 0,'y': 4}});
	var gobottom = function (){
		new Fx.Scroll(iddiv, {offset: {'x': 0,'y': 4}}).toBottom();
	}
	this.gobottom = gobottom;
}

//encode vaiment tous les caractères
function gmk_urlencode(valeurnonencode){
	var valeurencode = valeurnonencode.replace(/\+/gi,'%2B');
	valeurencode = valeurencode.replace(/\&/gi,'%26');

	return valeurencode;
}

//fenetre d'alert personnalisée
function gmk_alert(contenu_alert,titre_alert,class_alert){
	$('customised_alert_window_titre').innerHTML=titre_alert;
	$('customised_alert_window_contenu').innerHTML=contenu_alert;
	if(!class_alert){
		$('customised_alert_window_titre').className='titreAlert';
	}else{
		$('customised_alert_window_titre').addClass(class_alert);
	}
	$('customised_alert_window_contenu').innerHTML += $('customised_alert_button').innerHTML;
	call_gmkOverlay('customised_alert_window');
}			
function removeTinyMCE(idTextArea){//elem.id+'_corps_".$lang_default."
	var textLang = idTextArea;
	var textLangTinyMce = idTextArea+'_parent';
	var contentCorps = tinyMCE.get(textLang);
	contentCorps = contentCorps.getContent();
	contentCorps = contentCorps.replace('/\+/g', '&#43');
	contentCorps = contentCorps.replace('/\\/g', '&#92');
	$(textLang).value=contentCorps;
	$(textLangTinyMce).parentNode.removeChild($(textLangTinyMce));
	$(textLang).setStyle('display','block');
}


function getTinyMCE(idTextArea){
	var widthColonne = $(idTextArea).parentNode.parentNode.parentNode.id+'_width';
	tinyMCE.init({
		mode : 'exact',
		elements : idTextArea,
		theme : 'advanced',
		plugins : 'simplepaste',
		height:'150px',
		width:$(widthColonne).value+'px',
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,cleanup",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		language : 'fr'
	});
}	

//appelle une fenêtre modale
function call_gmkOverlay(div_a_charger,width_a_charger,height_a_charger){
	$('gmkOverlay').toggleClass('cacher');

	$('gmkOverlayInside').grab($(div_a_charger));
	$(div_a_charger).removeClass('cacher');
	//$('gmkOverlayInside').setStyle('height','200px');
	//if(height_a_charger){
		//var height = height_a_charger+'px';
		//$('gmkOverlayInside').setStyle('height',height);
//	}else{
		//$('gmkOverlayInside').setStyle('height','100px');
	//}
	//if(width_a_charger){
	//	var width = width_a_charger+'px';
	//	$('gmkOverlayInside').setStyle('width',width);
	//}else{
	//	$('gmkOverlayInside').setStyle('width','200px');
	//}
	resizeOverlay();
}
function resizeOverlay(){
	if(!$('gmkOverlay').hasClass('cacher')){
		var myEffectOverlayInside = new Fx.Morph('gmkOverlayInside', {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
		var hauteur = window.getScroll().y+window.getSize().y;
		var retour = $('gmkOverlayInside').getStyles('width', 'height');
		var left = Math.round(((window.getSize().x-parseInt(retour['width']))/2)+window.getScroll().x);
		var top = Math.round(((window.getSize().y-parseInt(retour['height']))/2)+window.getScroll().y);
		$('gmkOverlayBG').setStyle('height',hauteur);
		myEffectOverlayInside.start({
		    'top': top,
		    'left':left
		});
		
		//$('gmkOverlayBG').setStyle('height',hauteur);
		
		//$('gmkOverlayInside').setStyles({top: top,left: left});
	}
}
function setInfoToBottom(){

	if(window.getScroll().y>0){
		var monbottom = '-'+window.getScroll().y+'px';
		$('global_information').setStyle('bottom', monbottom);
	}else{
		$('global_information').setStyle('bottom', '0px');
	}
	if(window.getScroll().x>0){
		var monright = '-'+window.getScroll().x+'px';
		$('global_information').setStyle('right', monright);
	}else{
		$('global_information').setStyle('right', '0px');
	}

}


function disp_detail(id){
	if ($(id).style.visibility == 'hidden') {
		$(id).style.visibility = 'visible';
		$(id).style.display = 'inline';
	} else {
		$(id).style.visibility = 'hidden';
		$(id).style.display = 'none';
	}
}
function effacerID(id){
	$(id).style.visibility = 'hidden';
	$(id).style.display = 'none';
}


var Hdiv = 150;	//hauteur du div
var Ldiv = 320; //largeur du div


function detailOver(e,id){
	if ($(id)){
		var bordDroit;
		var bordBas;
		var curX = e.clientX;
		var curY = e.clientY;
		var decallageY = window.getScroll().y;
		var decallageX = window.getScroll().x;
		
		/*
		var tailleElement = 'tailleElement_'+id;
		if(!tailleElement.x){
			var sizeElem = $(id).getSize();
			tailleElement = new saveTailleDiv(sizeElem.x,sizeElem.y);
			addLogBox("pas encore", info_log);
		}else{
			addLogBox("deja", info_log);
		}*/
	//	var tailleElement = $(id).getSize();
	var tailleElementX='180';
	var tailleElementY='30';

	/*	
		bordDroit = window.getSize().x-curX-200;
		bordBas = window.getSize().y-curY-50;
		addLogBox("borddroit"+bordDroit+" et bord bas "+bordBas, info_log);
		if(bordDroit>'0'){
			$(id).style.left = (curX+15+decallageX)+'px';
		}else{
			$(id).style.left = (curX-15+decallageX-500)+'px';//-Ldiv
		}
		
		if(bordBas>'0'){
			$(id).style.top = (curY+15+decallageY)+'px';
		}else{
			$(id).style.top = (curY+15+decallageY)+'px';
		}
		addLogBox("donc top = "+curY+"+15+"+decallageY+"="+(curY+15+decallageY)+" et left "+curX+"+15+"+decallageX+"="+(curX-15+decallageX-500), info_log);*/
		

		
		//$('debug').innerHTML = 'cur X = '+curX+', clientX = '+event.client.x+', pageX = '+event.page.y+'<br/>cur Y = '+curY+', clientY = '+event.client.x+', pageY = '+event.page.y;

		bordDroit = window.getSize().x-curX-10-tailleElementX;
		bordBas = window.getSize().y-curY-10-tailleElementY;
		if(bordDroit>'0'){
			$(id).style.left = (curX+15+decallageX)+'px';
		}else{
			$(id).style.left = (curX-15+decallageX-tailleElementX)+'px';//-Ldiv
		}
		
		if(bordBas>'0'){
			$(id).style.top = (curY+15+decallageY)+'px';
		}else{
			$(id).style.top = (curY+15+decallageY-tailleElementY)+'px';
		}
	
		$(id).removeClass('cacher');
	}
}


//Boutons

function add_enableBouton(idBouton,enablationDefault,reference){
	
	
	var myFx = new Fx.Tween($(idBouton).parentNode);
	var monBouton = idBouton;
	if(reference){
		var tableau = reference.define;
		var monSwitch = reference.getAllId;
		monSwitch[monSwitch.length] = monBouton;
		tableau[monBouton] = new Array();
		tableau[monBouton]['currentValue']=enablationDefault;
		tableau[monBouton]['fx']= myFx;
		
		reference.define = tableau;
		reference.getAllId = monSwitch;

	}else{
		var instancesBouton = new Array();
		
		instancesBouton[monBouton] = new Array();
		instancesBouton[monBouton]['fx'] = myFx;
		instancesBouton[monBouton]['currentValue']=enablationDefault;
		var monSwitch = new Array();
		monSwitch['0'] = monBouton;
		this.define = instancesBouton;
		this.getAllId = monSwitch;
	}
	
	if(enablationDefault==false){
		$(idBouton).parentNode.removeClass('bleu');
		$(idBouton).parentNode.addClass('gris');
		$(idBouton).setStyle('cursor', 'default');
		myFx.set('opacity','0.5');
	}else{
		$(idBouton).setStyle('cursor', 'pointer');
	}
}

function enableBouton(referenceBouton,enablation,referenceInstance){
	var monId = referenceBouton;
//	alert(cliquer_bouton_thisInstance.getAllId.length);

	if(enablation=='disable'){
		$(monId).parentNode.removeClass('bleu');
		$(monId).parentNode.addClass('gris');
		$(monId).setStyle('cursor', 'default');
		referenceInstance.define[monId]['currentValue']=false;
		referenceInstance.define[monId]['fx'].set('opacity','0.5');
	}else{
		$(monId).setStyle('cursor', 'pointer');
		referenceInstance.define[monId]['currentValue']=true;
		referenceInstance.define[monId]['fx'].set('opacity','1');
	}
	
}

function setFooter() {
	var windowHeight = window.getSize().y;
	if (windowHeight > 0) {
		var contenuHeight = $('content').getSize().y;
		var footerHeight = $('footer').getSize().y;
		var contenuMarge = parseInt($('content').getStyle('marginTop'));
		if (windowHeight - ((contenuHeight + contenuMarge) + footerHeight) >= 0) {
			$('structure').style.height = (windowHeight - footerHeight) + 'px';
		}else {
			$('structure').style.height = contenuHeight + contenuMarge + 'px';
		}
	}
}

function gmk_radio(cetid,lautre){
	if($(cetid).checked==true){
		$(lautre).checked=false;
	}else{
		$(lautre).checked=true;
	}
	
}