//-FONCTIONS GÉNÉRIQUES-------------------------------------
function $(id) { 
	return document.getElementById(id);
}

//-dimWindows
var dimWindows = {
	width : function () {
		if(window.innerWidth) {
			var	largeur = window.innerWidth;
		}
		else if(document.documentElement && document.documentElement.clientWidth) {
			var largeur = document.documentElement.clientWidth;
		}
		else if(document.body.clientWidth) {
			var largeur = document.body.clientWidth;	
		}
		return largeur;
	},
	height : function () {
		if(window.innerWidth) {
			var hauteur = window.innerHeight;
		}
		else if(document.documentElement && document.documentElement.clientWidth) {
			var hauteur = document.documentElement.clientHeight;
		}
		else if(document.body.clientWidth) {
			var hauteur = document.body.clientHeight;
		}
		return hauteur;
	}
}

//-dimElt
var dimElt = {
	left_height : function (layerID01,layerID02,position,T,L,W,H,deltaW,deltaH,maxHeight) {
		if(position == 'right') { L = dimWindows.width()-W; }
		if(H == 0) { H = dimWindows.height()-T; }
		if (maxHeight != 0 && H >= maxHeight) { 
			H = maxHeight ;
		}
		W = W-deltaW;
		H = H-deltaH;
		if($(layerID01)) {
			$(layerID01).style.top = (T + 'px');
			$(layerID01).style.left = (L + 'px');
			$(layerID01).style.width = (W + 'px');
			$(layerID01).style.height = (H + 'px');
		}
		if($(layerID02)) {
			$(layerID02).style.height = (H + 'px');
		}
	},
	width_height : function (layerID01,layerID02,T,L,deltaW,deltaH,maxWidth,maxHeight) {
		W = dimWindows.width()-L-deltaW;
		H = dimWindows.height()-T-deltaH;	
		if (W >= maxWidth) { 
			W = maxWidth ;
		}
		if (H >= maxHeight) { 
			H = maxHeight ;
		}
		if($(layerID01)) {
			$(layerID01).style.top = (T + 'px');
			$(layerID01).style.left = (L + 'px');
			$(layerID01).style.width = (W + 'px');
			$(layerID01).style.height = (H + 'px');
		}
		if($(layerID02)) {
			$(layerID02).style.width = (W + 'px');	
			$(layerID02).style.height = (H + 'px');
		}
	}
}

//-paramElt
var paramElt = {
	width : function () {
		if(window.innerWidth) {
			var	largeur = window.innerWidth;
		}
		else if(document.documentElement && document.documentElement.clientWidth) {
			var largeur = document.documentElement.clientWidth;
		}
		else if(document.body.clientWidth) {
			var largeur = document.body.clientWidth;	
		}
	},
	height : function () {
		if(window.innerWidth) {
			var hauteur = window.innerHeight;
		}
		else if(document.documentElement && document.documentElement.clientWidth) {
			var hauteur = document.documentElement.clientHeight;
		}
		else if(document.body.clientWidth) {
			var hauteur = document.body.clientHeight;
		}
	},
	center : function (layerID,largeurLayer,hauteurLayer) {
		if(window.innerWidth) {
			var	largeur = window.innerWidth;
			var hauteur = window.innerHeight;
		}
		else if(document.documentElement && document.documentElement.clientWidth) {
			var largeur = document.documentElement.clientWidth;
			var hauteur = document.documentElement.clientHeight;
		}
		else if(document.body.clientWidth) {
			var largeur = document.body.clientWidth;
			var hauteur = document.body.clientHeight;
		}	
		var X = ((largeur-largeurLayer)/2);
		var Y = ((hauteur-hauteurLayer)/2);
		$(layerID).style.left = X+"px";
		$(layerID).style.top = Y+"px";
	}
}

//-stateElt
var stateElt = {
	block : function(layerID) {
		$(layerID).style.display = 'block';
	},
	none : function(layerID) {
		$(layerID).style.display = 'none';
	},
	visible : function(layerID) {
		$(layerID).style.visibility = "visible";
	},
	hidden : function(layerID) {
		$(layerID).style.visibility = "hidden";
	},
	bgcolor : function(layerID,color) {
		$(layerID).style.backgroundColor = color;
	},
	bgimage : function(layerID,image) {
		$(layerID).style.backgroundImage = image;
	}
}

var ouvrir = {
	unsa_defense : function(fichier) {
		var W = window.screen.availWidth;
		var H =  window.screen.availHeight;
		var L = 0;
		var T = 0;
		if (navigator.appName=="Microsoft Internet Explorer") { W=(W-19); H=(H-40); L=4, T=4;	}
		var options = ("toolbar=no"+",menubar=yes"+",location=no"+",resizable=no"+",height="+H+",width="+W+",left="+L+",Top="+T+",scrollbars=no");
		var fenetreUD = window.open(fichier,'UNSA_DEFENSE',options);
	},
	xhtml : function(fichier) {
		var W = window.screen.availWidth;
		var H = window.screen.availHeight;
		var L = 0;
		var T = 0;
		if (navigator.appName=="Microsoft Internet Explorer") { W=(W-19); H=(H-73); L=4, T=4; }
		var options = ("toolbar=yes"+",menubar=no"+",location=no"+",resizable=no"+",height="+H+",width="+W+",left="+L+",Top="+T+",scrollbars=yes");
		var fenetreFichier = window.open(fichier,'XHTML',options);
	},
	pdf : function(fichier) {
		var W = window.screen.availWidth;
		var H = window.screen.availHeight;
		var L = 0;
		var T = 0;
		if (navigator.appName=="Microsoft Internet Explorer") { W=(W-19); H=(H-40); L=4, T=4; }
		var options = ("toolbar=no"+",menubar=no"+",location=no"+",resizable=no"+",height="+H+",width="+W+",left="+L+",Top="+T+",scrollbars=no");
		var fenetrePDF = window.open(fichier,'PDF',options);
	},
	autres : function(fichier) {
		var W = window.screen.availWidth;
		var H = window.screen.availHeight;
		var L = 0;
		var T = 0;
		if (navigator.appName=="Microsoft Internet Explorer") { W=(W-19); H=(H-40); L=4, T=4; }
		var options = ("toolbar=yes"+",menubar=yes"+",location=no"+",resizable=yes"+",height="+H+",width="+W+",left="+L+",Top="+T+",scrollbars=yes");
		var fenetreAutres = window.open(fichier,'Autres',options);
	}	
}

//-FONCTIONS--------------------------------------

//-afficheBlog
function afficheBlog(Y,layerID01,layerID02) {
	for (var n=1; n<=Y; n++) { 
		stateElt.none('URL'+n);
		stateElt.none('titreBlog'+n);
	}
	stateElt.block(layerID01);
	stateElt.block(layerID02);
}

//-afficheBreves
function afficheBreves(layerID01,layerID02,urlImage,urlDoc) {
	stateElt.block(layerID01);
	stateElt.block(layerID02);
	stateElt.bgimage(layerID02,urlImage);
	chargeDocumentDansFrame(urlDoc);
}

//-changeColorScroll
function changeColorScroll(couleurbase,couleurover,couleurligne,couleurfond) {                          
	function colorScroll(couleur) {
		with(document.body.style) {
		scrollbarDarkShadowColor=couleurligne;
		scrollbar3dLightColor=couleurligne;
		scrollbarArrowColor=couleurligne;
		scrollbarBaseColor=couleur;
		scrollbarFaceColor=couleur;
		scrollbarHighlightColor=couleur;
		scrollbarShadowColor=couleur;
		scrollbarTrackColor=couleurfond;
		}
	}
	function colorChangeIE() {
		var w = dimWindows.width();
		var h = dimWindows.height();
		if (window.event) {
			var x = event.clientX;
			var y = event.clientY;
		}
		if(x>w || y>h) { 
			colorScroll(couleurover);
		}
		else {
			colorScroll(couleurbase);
		}
	}                          
	if((document.body.clientWidth) || 
		 (document.documentElement && document.documentElement.clientWidth)) {
		colorScroll(couleurbase);
		document.onmousemove=colorChangeIE;
	}
}

//-chargeDocumentDansFrame
function chargeDocumentDansFrame(urlDoc) {
	var myFrameElement = top.iframeXML.window;
	myFrameElement.location.href = (urlDoc);
}

//-getkey
function getkey(e) {
	if (window.event) return window.event.keyCode;
		else if (e)	return e.which;
			else return null;
}

//-getMouseButton
function getMouseButton(e) { 
	if (window.event) return window.event.button;
		else if (e) return e.which;
			else return null; 
}

//-noMouseButton --> onmousedown="noMouseButton(event);"
function noMouseButton(e) {
	var key=getMouseButton(e);
	if ((key==2) || (key==3) || (key==4)) { 
		window.close(); 
	} 
}

//-leftHeight01 : position : left (à gauche de la page), right (à droite)
function leftHeight01(IDName03,T3,W3,position) {
	(position == 'right') ? L3 = dimWindows.width()-W3 : L3 = 0;
	$(IDName03).style.top = (T3 + 'px');
	$(IDName03).style.left = (L3 + 'px'); 
	$(IDName03).style.width = (W3 + 'px');
	$(IDName03).style.height = '29px';
}
	
//-leftHeight02 : position : left (à gauche de la page), right (à droite)
function leftHeight02(IDName04,IDName05,T4,W4,basPage,deltaH,position) {
	(position == 'right') ? L4 = dimWindows.width()-W4 : L4 = 5;
	H4 = dimWindows.height()-T4-basPage-deltaH;		
	$(IDName04).style.top = (T4 + 'px');
	$(IDName04).style.left = (L4 + 'px');
	$(IDName04).style.width = (W4 + 'px');
	$(IDName04).style.height = $(IDName05).style.height = (H4 + 'px');
}

//-ouvrirFichier
function ouvrirFichier(fichier) { 
	var W = window.screen.availWidth;
	var H = window.screen.availHeight;
	var L = 0;
	var T = 0;
	if (navigator.appName=="Microsoft Internet Explorer") { W=(W-19); H=(H-73); L=4, T=4; }
	var options = ("toolbar=yes"+",menubar=no"+",location=no"+",resizable=no"+",height="+H+",width="+W+",left="+L+",Top="+T+",scrollbars=yes");
	var maFenetre = window.open(fichier,'XHTML',options); }

//-ouvrirPDF
function ouvrirPDF(fichier) {
	var W = window.screen.availWidth;
	var H = window.screen.availHeight;
	var L = 0;
	var T = 0;
	if (navigator.appName=="Microsoft Internet Explorer") { W=(W-19); H=(H-40); L=4, T=4; }
	var options = ("toolbar=no"+",menubar=no"+",location=no"+",resizable=no"+",height="+H+",width="+W+",left="+L+",Top="+T+",scrollbars=no");
	var maFenetre = window.open(fichier,'PDF',options); }

//-topWidth
function topWidth(IDName06,L6,H6,deltaH) {
	T6 = dimWindows.height()-H6-deltaH;
	W6 = dimWindows.width()-L6;				
	$(IDName06).style.left = (L6 + 'px');
	$(IDName06).style.height = (H6 + 'px');
	$(IDName06).style.top = ( T6 + 'px');
	$(IDName06).style.width = (W6 + 'px');
}

//-widthHeight
function widthHeight(IDName01,IDName02,T1,L1,W1,basPage,deltaH,maxWidth) {
	W = dimWindows.width()-L1-W1;
	H = dimWindows.height()-T1-basPage-deltaH;	
	if (W >= maxWidth) { 
		W = maxWidth ;
	}
	if($(IDName01)) {
		$(IDName01).style.top = (T1 + 'px');
		$(IDName01).style.left = (L1 + 'px');
		$(IDName01).style.width = (W + 'px');
		$(IDName01).style.height = (H + 'px');
	}
	if($(IDName02)) {
		$(IDName02).style.width = (W + 'px');	
		$(IDName02).style.height = (H + 'px');
	} 
}

//-winName --> toutes fenêtres
function winName (nomFenetre) {
		this.window.name=nomFenetre; }

		
/**--------------------------------------------------------------------------------------------**/
/* Espace xmlhttprequest */
/**--------------------------------------------------------------------------------------------**/

/** 
 * XMLHTTPREQUEST 
 * Ne pas supprimer l'initialisation de 'mode' sinon pb sous IE
 */
var mode = false;
function getHTTPObject(mode,divtarget) {
	var xmlhttp = false;				
			
	/* Compilation conditionnelle d'IE */
	/*@cc_on
		@if (@_jscript_version >= 5)
			try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } 
			catch(e) {
				try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
				catch(E) { xmlhttp = false; }
				}
		@else
			xmlhttp = false;
	   @end @*/
			
			
	/* Création de l'objet si ce n'est pas déjà fait */
	if (!xmlhttp && (typeof XMLHttpRequest != 'undefined') && (xmlhttp.readyState != 4)) {
		try { xmlhttp = new XMLHttpRequest(); }
		catch(e) { xmlhttp = false; }
	}
		
	if (xmlhttp) {
		xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				switch(mode) {
					case('xTransform'): {
						document.getElementById(divtarget).innerHTML = xmlhttp.responseText;
						break; }
					case('xTop'): {
						top.document.getElementById(divtarget).innerHTML = xmlhttp.responseText;
						break; }
					case('xNull'): {
						xmlhttp = xmlhttp.responseText;
						break; }
					default: {
						xmlhttp = window.eval(xmlhttp.responseText);
						break; } 
				} }	} }
return (xmlhttp);
}

/** 
 * IE nécessite un parametre 'aleas' inutile
 * qui change à chaque appel GET pour prendre en compte la commande 
 */
function sendXHR(methode,url,mode,datas,divtarget) {	
	var http = getHTTPObject(mode,divtarget);
	if(!http) { return false; }
	if (methode == 'GET') { 
		if(datas == 'null') { 
			var objetDate = new Date();
	   		var aleas = objetDate.getTime();
			http.open("GET", url+"?"+aleas, true);
			}
	    else { 
	    	http.open("GET",url+"?"+datas,true);
	    	}
	    http.send(null);
	    } 
	if (methode == 'POST') {
		http.open("POST",url,true);
		http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		http.send(datas); }
	return true;
}