/**
 * @file : planningmaster.js
 * @autor : paul tabet analemme
 * @date : 28/01/2009
 * @version : 0.1 - lite
 */
var dd, delai;
var main = {
	wScreen:0,
	hScreen:0,
	mouseX: 0,
	mouseY: 0,
	scrollX: 0,
	scrollY: 0,
	/**
	 * @brief : chargement du site, des evenements et des outils
	 */
	load: function(){
		main.windowSize();
	},
	/**
	 * @brief: definit la taille du document en cours
	 * pour récuperer les valeurs utiliser les accesseurs getWidth() et getHeight()
	 */
	windowSize: function(){
		if (document.body){
			main.wScreen = (document.body.clientWidth);
			main.hScreen = (document.body.clientHeight);
		}else{
			main.wScreen = (window.innerWidth);
			main.hScreen = (window.innerHeight);
		}
	},
	/**
	 * @brief : sous classe stage, permet de recuperer certaines valeurs en rapport avec l'objet window
	 */
	stage: {
		getWidth: function(){
		main.windowSize();
		return main.wScreen;
		},
		getHeight: function(){
			main.windowSize();
			return main.hScreen;	
		},
		positionMouse: function(e){
			main.mouseX = (navigator.appName.substring(0,3) == "Net") ? e.pageX - main.scrollX : event.x - main.scrollX;
			main.mouseY = (navigator.appName.substring(0,3) == "Net") ? e.pageY - main.scrollY : event.y - main.scrollY ;
		},
		positionScroll: function(){
			var t = Array((document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft,(document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop);
			main.scrollX = t[0];
			main.scrollY = t[1];
		}
	},
	/**
	 * @brief : sous classe obj, permet de recupérer certaines information par rapport à un objet
	 */
	obj: {
		getWidth: function(obj){
			try{
				var obj2 = document.getElementById(obj);
				return obj2.offsetWidth;
			}catch(evt){}
		},
		getHeight: function(obj){
			try{
				var obj2 = document.getElementById(obj);
				return obj2.offsetHeight;
			}catch(evt){}
		},
		getTop: function(obj){
			try{
				var obj2 = document.getElementById(obj);
				return obj2.offsetTop;
			}catch(evt){}
		},
		getLeft: function(obj){
			try{
				var obj2 = document.getElementById(obj);
				return obj2.offsetLeft;
			}catch(evt){}
		}
	}
}
window.onload = main.load;

function debuteTemps(delai1) {
	var hhmmss = "  ", min, sec;
	delai = delai1;

	adate = new Date()
	hhmmss += adate.getHours();
	if (hhmmss < 10) hhmmss = "0" + hhmmss.replace(/^\s*|\s*$/g,"");
	min = adate.getMinutes();
	if (min < 10) hhmmss += ":0" + min;
	else hhmmss += ":" + min;
	sec = adate.getSeconds();
	if (sec < 10) hhmmss += ":0" + sec;
	else hhmmss += ":" + sec;
	hhmmss = " " + hhmmss;
	document.getElementById("heure").innerHTML = hhmmss;
	//heure.innerHTML = hhmmss;

	dd = setTimeout("debuteTemps(delai)",delai1);
}

function LoadCenterStage(){
	//alert('hauteur centre : ' + main.obj.getHeight('contenu'));
	Total_Height = main.obj.getHeight('contenu') + 93;
	//alert('hauteur totale : ' + Total_Height);
	if (Total_Height < 400){
		Total_Height = 400;
		document.getElementById('contenu').style.height = Total_Height + 'px';
	}
	//alert('hauteur centre : ' + main.obj.getHeight('contenu'));
	if (document.getElementById('barre_image')){
		Total_Height = main.obj.getHeight('contenu')+93;
	} else {
		Total_Height = main.obj.getHeight('content')-17;
	}

	//alert('hauteur centre recalculé : ' + Total_Height);
	Menu_Height = Total_Height - main.obj.getHeight('pied_de_page') - main.obj.getHeight('quick_login')-11;
	document.getElementById('side_menu').style.height = Menu_Height + 'px';
	
	debuteTemps(1000);
}

function ShowMessage(div_id, msg_type, message, orientation){
	if (orientation == 'Up'){
		Value_1 = 'UR';
		Value_2 = 'LL';
		if (msg_type == 'inform'){
			MsgTop = '<div style=\'background-image: url(/images/bulles/bulle_top.png); width: 325px; height: 5px;\' class=\'text\'>&nbsp;</div><div style=\'background-image: url(/images/bulles/bulle_center.png); text-align: left; padding-left: 12px; padding-right: 10px; padding-top: 2px; padding-bottom: 2px;\' class=\'text\'>';
			MsgBottom = '</div><div style=\'background-image: url(/images/bulles/bulle_bottom_dl.png); width: 325px; height: 12px;\' class=\'text\'>&nbsp;</div>';
		} else {
			MsgTop = '<div style=\'background-image: url(/images/bulles/bulle_top_rouge.png); width: 325px; height: 5px;\' class=\'text\'>&nbsp;</div><div style=\'background-image: url(/images/bulles/bulle_center_rouge.png); text-align: left; padding-left: 12px; padding-right: 10px; padding-top: 2px; padding-bottom: 2px;\' class=\'text\'>';
			MsgBottom = '</div><div style=\'background-image: url(/images/bulles/bulle_bottom_rouge_dl.png); width: 325px; height: 12px;\' class=\'text\'>&nbsp;</div>';
		}
	} else if (orientation == 'Down'){
		Value_1 = 'LR';
		Value_2 = 'UL';
		if (msg_type == 'inform'){
			MsgTop = '<div style=\'background-image: url(/images/bulles/bulle_top_ul.png); width: 325px; height: 12px;\' class=\'text\'>&nbsp;</div><div style=\'background-image: url(/images/bulles/bulle_center.png); text-align: left; padding-left: 12px; padding-right: 10px; padding-top: 2px; padding-bottom: 2px;\' class=\'text\'>';
			MsgBottom = '</div><div style=\'background-image: url(/images/bulles/bulle_bottom.png); width: 325px; height: 5px;\' class=\'text\'>&nbsp;</div>';
		} else {
			MsgTop = '<div style=\'background-image: url(/images/bulles/bulle_top_rouge_ul.png); width: 325px; height: 12px;\' class=\'text\'>&nbsp;</div><div style=\'background-image: url(/images/bulles/bulle_center_rouge.png); text-align: left; padding-left: 12px; padding-right: 10px; padding-top: 2px; padding-bottom: 2px;\' class=\'text\'>';
			MsgBottom = '</div><div style=\'background-image: url(/images/bulles/bulle_bottom_rouge.png); width: 325px; height: 5px;\' class=\'text\'>&nbsp;</div>';
		}
	} else if (orientation == 'UpLeft'){
		Value_1 = 'UL';
		Value_2 = 'LR';
		if (msg_type == 'inform'){
			MsgTop = '<div style=\'background-image: url(/images/bulles/bulle_top.png); width: 325px; height: 5px;\' class=\'text\'>&nbsp;</div><div style=\'background-image: url(/images/bulles/bulle_center.png); text-align: left; padding-left: 12px; padding-right: 10px; padding-top: 2px; padding-bottom: 2px;\' class=\'text\'>';
			MsgBottom = '</div><div style=\'background-image: url(/images/bulles/bulle_bottom_dr.png); width: 325px; height: 12px;\' class=\'text\'>&nbsp;</div>';
		} else {
			MsgTop = '<div style=\'background-image: url(/images/bulles/bulle_top_rouge.png); width: 325px; height: 5px;\' class=\'text\'>&nbsp;</div><div style=\'background-image: url(/images/bulles/bulle_center_rouge.png); text-align: left; padding-left: 12px; padding-right: 10px; padding-top: 2px; padding-bottom: 2px;\' class=\'text\'>';
			MsgBottom = '</div><div style=\'background-image: url(/images/bulles/bulle_bottom_rouge_dr.png); width: 325px; height: 12px;\' class=\'text\'>&nbsp;</div>';
		}
	} else {
		Value_1 = 'LL';
		Value_2 = 'UR';
		if (msg_type == 'inform'){
			MsgTop = '<div style=\'background-image: url(/images/bulles/bulle_top_ur.png); width: 325px; height: 12px;\' class=\'text\'>&nbsp;</div><div style=\'background-image: url(/images/bulles/bulle_center.png); text-align: left; padding-left: 12px; padding-right: 10px; padding-top: 2px; padding-bottom: 2px;\' class=\'text\'>';
			MsgBottom = '</div><div style=\'background-image: url(/images/bulles/bulle_bottom.png); width: 325px; height: 5px;\' class=\'text\'>&nbsp;</div>';
		} else {
			MsgTop = '<div style=\'background-image: url(/images/bulles/bulles/bulle_top_rouge_ur.png); width: 325px; height: 12px;\' class=\'text\'>&nbsp;</div><div style=\'background-image: url(/images/bulles/bulle_center_rouge.png); text-align: left; padding-left: 12px; padding-right: 10px; padding-top: 2px; padding-bottom: 2px;\' class=\'text\'>';
			MsgBottom = '</div><div style=\'background-image: url(/images/bulles/bulle_bottom_rouge.png); width: 325px; height: 5px;\' class=\'text\'>&nbsp;</div>';
		}
	}
	if (msg_type == 'inform'){
		overlib(MsgTop + message + MsgBottom, ANCHOR, div_id, ANCHORALIGN, Value_1, Value_2, WIDTH, 325, FGCOLOR,'', BGCOLOR,'');
	} else {
		overlib(MsgTop + message + MsgBottom, ANCHOR, div_id, ANCHORALIGN, Value_1, Value_2, WIDTH, 325, FGCOLOR,'', BGCOLOR,'');
	}
}

function StartForm(){
	clearTimeout(Timer)
	for (i=0;i<document.MainForm.elements.length;i++){
		//alert(document.MainForm.elements[i].type);
		if (document.MainForm.elements[i].type == 'text'){
			if (document.MainForm.elements[i].value == '' || document.MainForm.elements[i].value == '0' || document.MainForm.elements[i].value == '0,00'){
				document.MainForm.elements[i].focus();
				break;
			}
		} else if (document.MainForm.elements[i].type == 'textarea' && document.MainForm.elements[i].value == '') {
			document.MainForm.elements[i].focus();
			break;
		} else if (document.MainForm.elements[i].type == 'select-one') {
			if (document.MainForm.elements[i].selectedIndex == 0 && document.MainForm.elements[i].options[0].value == ''){
				document.MainForm.elements[i].focus();
				break;
			}
		}
	}
}
