/**
 * Fonctions javascript propre au site web
 * 
 * @author : Service Informatique
 * @version : 2007-09-25
 * @copyright : Monné-Decroix (service informatique)
 */

/**
 * Ouvre le popup d'un numéro de la newsletter
 *
 * @param string val_url Url du numéro
 */
function openNewsletter(val_url){
	var str_name = "newsletter";
	var int_w = 650;
	var int_h = 600;
	var str_rezisable = 'yes';
	var str_srollbars = 'yes';
	openPopup(val_url, str_name, int_w, int_h, str_rezisable, str_srollbars);
}

/**
 * Ouvre le popup d'un plan type en PDF
 *
 * @param string val_url Url du PDF
 */
function openProgrammePlanType(val_url){
	var str_name = "plan_type";
	var int_w = 800;
	var int_h = 600;
	var str_rezisable = 'yes';
	var str_srollbars = 'yes';
	openPopup(val_url, str_name, int_w, int_h, str_rezisable, str_srollbars);
}

/**
 * Ouvre le popup d'un agrandissement d'image
 *
 * @param string val_urlImg Url de l'image
 * @param string val_name Nom de l'image
 */
function popupProgrammePlanSituation(val_urlImg, val_name){
	var str_url = 'agrandissement.php?url='+val_urlImg+'&name='+val_name+'&resize=0';
	var str_name = "plan_situation";
	var int_w = 800;
	var int_h = 600;
	var str_rezisable = 'yes';
	var str_srollbars = 'yes';
	openPopup(str_url, str_name, int_w, int_h, str_rezisable, str_srollbars);
}

/**
 * Ouvre le popup d'un agrandissement d'image
 *
 * @param string val_urlImg Url de l'image
 * @param string val_name Nom de l'image
 * @param integer int_w Largeur de l'image
 * @param integer int_h Hauteur de l'image
 */
function popupAgrandissement(val_urlImg, val_name, int_w, int_h){
	var str_url = 'agrandissement.php?url='+val_urlImg+'&name='+val_name+'&resize=1';
	var str_name = "agrandissement";
	var str_rezisable = 'no';
	var str_srollbars = 'no';
	openPopup(str_url, str_name, int_w, int_h, str_rezisable, str_srollbars);
}

/**
 * Deplace le pied de page en fonction de la hauteur de la fenetre
 *
 */
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function setFooter() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var contentHeight = document.getElementById('content').offsetHeight;
			
			var footerElement = document.getElementById('conteneur_pied');
			var footerHeight  = footerElement.offsetHeight;
			
			var corpsElement = document.getElementById('corps');
			var blocsElement = document.getElementById('blocs_information');
			var conteneurcorpsElement = document.getElementById('conteneur_corps');
			var corpsHeight  = corpsElement.offsetHeight;
			var blocsHeight  = blocsElement.offsetHeight;
			var conteneurcorpsHeight  = conteneurcorpsElement.offsetHeight;
			
			if (windowHeight - (contentHeight + footerHeight) >= 0) {
				// Agrandissement de la hauteur des blocs
				blocsElement.style.height = conteneurcorpsHeight + (windowHeight - (contentHeight + footerHeight)) + 'px';
				
				// Difference entre la hauteur initale et hauteur finale des blocs
				var growTailleBloc = conteneurcorpsHeight - contentHeight;
				
				// Recalcul de la hauteur du content
				contentHeight = conteneurcorpsHeight + (windowHeight - (contentHeight + footerHeight)) - growTailleBloc;
				
				// On fixe le top du footer
				footerElement.style.top = (windowHeight - (contentHeight + footerHeight)) + 'px';
				
			}
			else {
				footerElement.style.top = '0px';
			}
			
		}
	}
}


