// Cache un onglet
function hideOnglet(onglet) {
	hide('tab_' + onglet);
	if (Ext.getDom('menu_tab_' + onglet)) {
		Ext.getDom('menu_tab_' + onglet).className = '';
	}
}

// Affichage d'un onglet
function showOnglet(onglet) {
	show('tab_' + onglet);
	if (Ext.getDom('menu_tab_' + onglet)) {
		Ext.getDom('menu_tab_' + onglet).className = 'on';
	}
}

function openDomaine(index, domaine_id) {
	swapDisplay(domaine_id,'on');
	xajax_afficherBargraphByDomaine(domaine_id);
}

function activerLigne(tableName, ligneId, statut) {
   listeTR = document.getElementById(tableName).getElementsByTagName('TR');
   if(listeTR) {
     for (i=0; i<listeTR.length+i; i++) {
  	   if (listeTR[i].id == ligneId) {
  		   listeTR[i].style.display = statut;
  		   break;
  	   }
     }
   }
}

function addLoadEvent(func) {
   var oldonload = window.onload;
   if (typeof window.onload != "function") {
	  window.onload = func;
   } else {
	  window.onload = function() {
		 if (oldonload) {
			oldonload();
		 }
		 func();
	  };
   }
}
function hide(id){
	if (Ext.getDom(id)) {
		Ext.getDom(id).style.display = 'none';
	}
}
function show(id){
	if (Ext.getDom(id)) {
		Ext.getDom(id).style.display = 'block';
	}
}
function hsDisplay(id) {
	if (Ext.getDom(id)) {
		if (Ext.getDom(id).style.display == "none") {
			Ext.getDom(id).style.display = "";
		} else {
			Ext.getDom(id).style.display = "none";
		}
	}
}
			
// FONCTIONS POUR UPLOAD DE FICHIERS
function initUploadXajax(formName, object_id, sid, cgiPath, cgiDebug, submitType) {
	if(document.getElementById(formName + "_file_inputs") == undefined || document.getElementById(formName + "_file_inputs").value == '') {
		return false;
	}

	if(cgiDebug == 1) {
		iframe = document.getElementById(formName + '_frameUpload');
		iframe.setAttribute("height", "150px");
		iframe.setAttribute("width", "100%");
		iframe.setAttribute("frameBorder", "1");
	 }

	document.getElementById(formName + "_file_inputs").disabled=false;
	document.getElementById(formName + "_uldCancel").style.display="block";
	if (submitType != 'onchange') {
		document.getElementById(formName + "_uldSubmit").disabled=true;
	}
	document.getElementById(formName + "_okstatus").style.display="none";
	document.getElementById(formName + "_progress_bar").style.display="block";
	document.getElementById(formName + "_loadtext").innerHTML="Initialisation de l'upload.";
	document.forms[formName].action=cgiPath+"?sid="+sid+"&cgidebug="+cgiDebug;
	document.forms[formName].submit();

	progressUploadXajax(formName, object_id, sid);
}

var cancelUploadAjax = false;
var loopProgressUploadAjax = 0;
function progressUploadXajax(formName, object_id, sid) {
	if(cancelUploadAjax){
		xajax_uploadHandler(formName, object_id, sid,-1);
	} else {
		xajax_uploadHandler(formName, object_id, sid, loopProgressUploadAjax);
		loopProgressUploadAjax += 1;
	}
}

function reinitUploadXajax(formName) {
	document.getElementById(formName + "_uldCancel").style.display="none";
	document.getElementById(formName + "_uldSubmit").disabled=false;
	loopProgressUploadAjax = 0;
	cancelUploadAjax = false;
}
// FIN FONCTIONS POUR UPLOAD DE FICHIERS

//FONCTIONS POUR LES DECLENCHEMENTS EVENEMENTIELS
function addLoadListener(func) {
		if (window.addEventListener) {
      		window.addEventListener("load", func, false);
   		} else if (document.addEventListener) {
      		document.addEventListener("load", func, false);
   		} else if (window.attachEvent) {
      		window.attachEvent("onload", func);
      	}
}

function addListener(event, element, func) {
	if (element.addEventListener) {
  		element.addEventListener(event, func, false);
	} else if (element.attachEvent) {
  		element.attachEvent("on" + event, func);
	}
}

//FIN FONCTIONS POUR LES DECLENCHEMENTS EVENEMENTIELS
//FONCTION POUR LA PAGINATION DE LA SYNTHESE DES TACHES
function gotoListTachePage(site_id, page) {
	document.getElementById('nextPage').value = page; 
	if(document.documentElement) document.documentElement.scrollTop = 0 ;
	xajax_afficherFiltreTachesList(site_id, xajax.getFormValues('formPageTaches'));
}
//FIN FONCTION POUR LA PAGINATION DE LA SYNTHESE DES TACHES

// Sélection du mois d'affichage d'une tâche pour les checkliste mensuelles
function tacheAffichageMoisCheckliste() {
	// Périodicité
	var periodicite_id = document.getElementById('periodicite_id').value;
	// Saisonnalité
	var saisons = new Array();
	// Toute l'année ?
	if (document.getElementById('saison').checked) {
		saisons.push(document.getElementById('saison').value);
	} else {
		for(var i = 0; i < document.getElementById('saison_select').length; i++) {
			if (document.getElementById('saison_select').options[i].selected) {
				saisons.push(document.getElementById('saison_select').options[i].value);
			}
		}
	}
	xajax_tacheAffichageMoisCheckliste(periodicite_id, saisons);
}

// Import de paramétrage pour les modules diagnostic
function importerParametrage(rubrique) {
	if ($('#import_parc_id').attr('value') == '') {
		alert('Merci de sélectionner un parc dans la liste.');
	} else if (confirm('ATTENTION, l\'import va supprimer tout le paramétrage du parc courant et vider toutes les visites immobilières déjà enregistrées. Êtes-vous sûr de vouloir continuer ?')) {
		document.location = 'process/parametrage_import.php?import_parc_id=' + $('#import_parc_id').attr('value') + '&rubrique=' + rubrique;
	}
}
