// JavaScript Document
//Function test support ajax
//cargement dynamyque de fichr externe
var loadedobjects=""
var id_deplacement = null;
var id_defilement_gallery = null;
var numLoading = 0;
var onMenu = false;
var id_interval;
var tempsAffichage = 2000;
//if (isNaN(myFunctionAfficheResultTimer)==false) myFunctionAfficheResultTimer = $clear(myFunctionAfficheResultTimer);
function getElementsByClassName(nomClasse, element) {
  var resulat = new Array();
  if(nomClasse!="" || typeof element == 'object'){
    var mesFils = element.getElementsByTagName('*');
    var exp_reg = new RegExp("(^|\\s)" + nomClasse + "(\\s|$)");
    for (var i = 0; i < mesFils.length; i++) {
      var laClasse = (mesFils[i].className)? mesFils[i].className : "";
      if(laClasse != "" && (laClasse == nomClasse || laClasse.match(exp_reg))){
        resulat.push(mesFils[i])
      }
    }
  }
  return resulat;
};



fDomOffset = function( oObj, sProp ) {
	var iVal = 0;
	while (oObj && oObj.tagName != 'BODY') {
		eval('iVal += oObj.' + sProp + ';');
		oObj = oObj.offsetParent;
		}
	return iVal;
}
function loadobjs(){
	if (!document.getElementById)
	return
	for (i=0; i<arguments.length; i++){
		var file=arguments[i]
		var fileref=""
		if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
			if (file.indexOf(".js")!=-1){ //If object is a js file
				fileref=document.createElement('script')
				fileref.setAttribute("type","text/javascript");
				fileref.setAttribute("src", file);
			}
			else if (file.indexOf(".css")!=-1){ //If object is a css file
				fileref=document.createElement("link")
				fileref.setAttribute("rel", "stylesheet");
				fileref.setAttribute("type", "text/css");
				fileref.setAttribute("href", file);
			}
		}
		if (fileref!=""){
		document.getElementsByTagName("head").item(0).appendChild(fileref)
		loadedobjects+=file+" " //Remember this object as being already added to page
		
		}
	}
}

function loading_show(){

	var loading = document.getElementById('loading');
	
		//var left = ((screen.width/2) - 40/2);
  		//var top = ((screen.height/2) - 40/2);
		var left = (dim_window_w()/2) - 40/2;
  		var top = (dim_window_h()/2) - 40/2;
		loading.style.position = 'absolute';
		  
		loading.style.top = top + "px";
		loading.style.left = left+ "px";
		
	loading.style.display = 'block';
}

function loading_hide()
{
	
	var loading = document.getElementById('loading');
	if (loading) {
		loading.style.display = 'none';
	}
}
//Affichage ajax
function afficher_contenu_loadobjs(cible, cadre, formulaire, url_extern) {
	var xhr;
	if (window.XMLHttpRequest) xhr=new XMLHttpRequest ();
	else if (window.ActiveXObject) 	xhr=new ActiveXObject ('Microsoft.XMLHTTP');
	else {
	
		alert ('Votre navigateur ne supporte pas le XMLHttpRequest');
		return;
	}
	var page='' + cible;
	xhr.open ('POST', page, true);
	xhr.setRequestHeader ('Content-Type','application/x-www-form-urlencoded');
	xhr.onreadystatechange=function() {

		if(url_extern.length>0) {		
			loadobjs(url_extern);
		}
		if (xhr.readyState==4) {
			document.getElementById (cadre).innerHTML=xhr.responseText;
		}
	}
	xhr.send(formulaire);
}
function affiche_navigation(formulaire) {
	//alert(formulaire);
	afficher_contenu("../contenu/content_navigation.php", "content_navigation", formulaire)
}

//Affichage ajax
function afficher_contenu(cible, cadre, formulaire) {
	var xhr;
	if (window.XMLHttpRequest) xhr=new XMLHttpRequest ();
	else if (window.ActiveXObject) 	xhr=new ActiveXObject ('Microsoft.XMLHTTP');
	else {
	
		alert ('Votre navigateur ne supporte pas le XMLHttpRequest');
		return;
	}
	var page='' + cible;
	xhr.open ('POST', page, true);
	xhr.setRequestHeader ('Content-Type','application/x-www-form-urlencoded');
	xhr.onreadystatechange=function() {
		
		if (xhr.readyState==1) {
			loading_show();
		}
		if (xhr.readyState==4) {
			document.getElementById(cadre).innerHTML=xhr.responseText;
			loading_hide();
		}
	}
	xhr.send(formulaire);
}

//Affichage ajax
function afficher_contenu_callback(cible, cadre, formulaire, fct) {
	var xhr;
	var tabFct = fct.split('|');
	if (window.XMLHttpRequest) xhr=new XMLHttpRequest ();
	else if (window.ActiveXObject) 	xhr=new ActiveXObject ('Microsoft.XMLHTTP');
	else {
	
		alert ('Votre navigateur ne supporte pas le XMLHttpRequest');
		return;
	}
	var page='' + cible;
	xhr.open ('POST', page, true);
	xhr.setRequestHeader ('Content-Type','application/x-www-form-urlencoded');
	xhr.onreadystatechange=function() {
		if (xhr.readyState==1) {
			loading_show();
		}
		if (xhr.readyState==4) {
			if (document.getElementById)
				document.getElementById (cadre).innerHTML=xhr.responseText;
			loading_hide();
			for (var i = 0; i < tabFct.length; i++) {
				eval(tabFct[i]);
			}
		}
	}
	xhr.send(formulaire);
}

//Affichage ajax

function retourner_contenu_callback(cible,fct) 
{
    var xhr=null;
    
    if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //on définit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() {
		if (xhr.readyState==1) {
				loading_show();
		}
		if (xhr.readyState==4) {
			loading_hide();
			eval(fct+"(xhr)");
		} 
	};
    xhr.open("GET", cible, true);
    xhr.send(null);
}
function cntTabsPlusButton() {
	//definir le changement d'etat
	var cntTabsPlus = document.getElementById("cntTabsPlus");
	var tabCntTabsPlus = cntTabsPlus.getElementsByTagName("TD");
	if(tabCntTabsPlus[0].className=="unselected") {
		//affichage du bouton et du volet en etat actif
		tabCntTabsPlus[0].className="current";
		document.getElementById("containerPlus").className="containerPlusVisible";
	} else {
		//affichage du bouton et du volet en etat inactif
		tabCntTabsPlus[0].className="unselected";
		document.getElementById("containerPlus").className="containerPlusInvisible";
	}
	
	
	
}
/*function retourner_contenu_callback(cible, cadre, formulaire,nomFct) {
	var xhr;
	if (window.XMLHttpRequest) xhr=new XMLHttpRequest ();
	else if (window.ActiveXObject) 	xhr=new ActiveXObject ('Microsoft.XMLHTTP');
	else {	
		alert ('Votre navigateur ne supporte pas le XMLHttpRequest');
		return;
	}
	var page='' + cible;
	xhr.open ('POST', page, true);
	xhr.setRequestHeader ('Content-Type','application/x-www-form-urlencoded');
	xhr.onreadystatechange=function() {
		if (xhr.readyState==1) {
				loading_show();
		}
		if (xhr.readyState==4) {
			if (document.getElementById)
				//eval(nomFct+"("+xhr.responseText+")"); 
				return(xhr.responseText);
			loading_hide();
		}
	 }
	xhr.send(formulaire);
	
}
*/
//popup
var file;
function popup_Window(file, width, height, resize)
{
  var myWidth=width;
  var myHeight=height;
  var left = (screen.width/2) - myWidth/2;
  var top = (screen.height/2) - myHeight/2;
  var styleStr ='toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable='+resize+',copyhistory=yes,width='+myWidth+',height='+myHeight+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  verrou = 0;
  var msgWindow = window.open(file,"popupwindow",styleStr);
}

function dim_window_w() {
	var w="";
	if (document.all) {
		w=document.documentElement.clientWidth;
	} else {
		w=window.innerWidth;
	}
	return w;
}

function dim_window_h() {
	var h="";
	if (document.all) {
		h=document.documentElement.clientHeight;
		
		
	} else {
		h=window.innerHeight;
		
	}
	return h;
}
var myDragInstance;
var tempX = 0
var tempY = 0
var IE;
var popup_Window_ajax_init_w = "0px";
var popup_Window_ajax_init_h = "0px";
//Localisation de la sourie
function localiser(e) {
	if (navigator.appName == "Netscape")
	{document.captureEvents(Event.CLICK);}
	if (navigator.appName == "Microsoft Internet Explorer")
	{sX = event.clientX; sY = event.clientY;}
	else {sX = e.pageX;sY = e.pageY;}
	//alert("Coordonnées du clic x = " + sX + " et y = " + sY);
	tempX = sX;
	tempY = sY;
}
//document.onclick=localiser;

//popup_ajax

function popup_Window_ajax(cible,formulaire, width, height) {
	var myWidth=width;
	var myHeight=height;
	var window_ajax_id = "popup_Window_ajax";
	var screen_w = dim_window_w();
	var screen_h = dim_window_h();
	// recherche du noeud parent
	var left = (screen_w/2) - myWidth/2;
	var top = (screen_h/2) - myHeight/2;
	
	//Fond soubre
	var window_ajax_overlay = document.getElementById("popup_Window_ajax_overlay");
	if (!/MSIE (5\.5|6\.)/.test(navigator.userAgent)) {
	 window_ajax_overlay.style.width = "100%";
	 window_ajax_overlay.style.height = "100%";
	} else {
	 window_ajax_overlay.style.width = screen_w+"px";
	 window_ajax_overlay.style.height = screen_h+"px"; 
	}
	window_ajax_overlay.style.display = "block";
	
 	//popup
	var window_ajax = document.getElementById("popup_Window_ajax");
	window_ajax.style.height = popup_Window_ajax_init_h;
	window_ajax.style.width = popup_Window_ajax_init_w;
	window_ajax.style.top = dim_window_h()+"px";//tempY
	window_ajax.style.left = (dim_window_w()/2)+"px";//tempX
  	window_ajax.style.display = "block";
	var morph = new Fx.Morph(window_ajax_id);
	morph.start({
		width: width,
		height: height,
		top: top,
		left: left
	});
	morph.addEvents({
		'onComplete': function() {
				afficher_contenu_callback(cible, window_ajax_id, formulaire,'drag_it()');
			}
		}
	);
}
function popup_Window_ajax_callback(cible,formulaire, width, height,fct) {
	var myWidth=width;
	var myHeight=height;
	var window_ajax_id = "popup_Window_ajax";
	var screen_w = dim_window_w();
	var screen_h = dim_window_h();
	// recherche du noeud parent
	var left = (screen_w/2) - myWidth/2;
	var top = (screen_h/2) - myHeight/2;
	
	//Fond soubre
	var window_ajax_overlay = document.getElementById("popup_Window_ajax_overlay");
	if (!/MSIE (5\.5|6\.)/.test(navigator.userAgent)) {
	 window_ajax_overlay.style.width = "100%";
	 window_ajax_overlay.style.height = "100%";
	} else {
	 window_ajax_overlay.style.width = screen_w+"px";
	 window_ajax_overlay.style.height = screen_h+"px"; 
	}
	window_ajax_overlay.style.display = "block";
	
 	//popup
	var window_ajax = document.getElementById("popup_Window_ajax");
	window_ajax.style.height = popup_Window_ajax_init_h;
	window_ajax.style.width = popup_Window_ajax_init_w;
	window_ajax.style.top = dim_window_h()+"px";
	window_ajax.style.left = (dim_window_w()/2)+"px";
  	window_ajax.style.display = "block";
	var morph = new Fx.Morph(window_ajax_id);
	morph.start({
		width: width,
		height: height,
		top: top,
		left: left
	});
	morph.addEvents({
		'onComplete': function() {
				afficher_contenu_callback(cible, window_ajax_id, formulaire,'drag_it()|'+fct);
			}
		}
	);
}

function drag_it() {
	var window_ajax = document.getElementById("popup_Window_ajax");
	var drag_handle = getElementsByClassName("box_header", window_ajax)
	myDragInstance = window_ajax.makeDraggable({handle: drag_handle});
}
function close_popup_Window_ajax() {
  var window_ajax = document.getElementById("popup_Window_ajax");
  window_ajax.innerHTML = "";
  window_ajax.style.display = "none";
  var window_ajax_overlay = document.getElementById("popup_Window_ajax_overlay");
  window_ajax_overlay.style.display = "none";
}


function navigation_tab(menu, cible, div) {
	var tbody = document.getElementById("tbody_tab");
	//remise a zero
	var tabs = tbody.getElementsByTagName("td");
	for (i=0;i<tabs.length;i++) {
		tabs[i].className = "unselected";
	}
	//affichage d'onglet
	document.getElementById("td_"+menu).className = "current";
	afficher_contenu(cible, div, "");
}


//	affichage de l'info sur l'identification dns la partie footer du gabarit

function afficher_identifier_footer(sess) {
	var str_post = "";
	str_post += "&PHPSESSID="+sess;
	afficher_contenu("../../includes/menu_general/global_identite.php","global_identite",str_post);	
}
//	Affichage de la vignette compo

function afficher_info_vignette(lien,cible,post) {
	
	var monDiv = document.getElementById("info_vignette");
	//monDivContent.innerHTML = "";
	var monLeft = fDomOffset(lien, 'offsetLeft');
	var monTop = fDomOffset(lien, 'offsetTop');
	//alert("left : "+monLeft+" top : "+monTop);
	var left = (monLeft - 340);
	var top = (monTop - 70);
	
	//var left = (((dim_window_w()/2) + 0) - (300/2));
  	//var top = (dim_window_h()/2) - (100/2);
	
	monDiv.style.top = top+"px";
	monDiv.style.left = left+"px";
	
	afficher_contenu(cible,"info_vignette_content",post);
	monDiv.className = "info_vignette_visible";
	id_interval = setInterval("test_cacher_info_vignette()", tempsAffichage);
}
function test_cacher_info_vignette() {
	if(!onMenu) {
		cacher_info_vignette();
	} else {
		clearInterval(id_interval);
		id_interval = setInterval("test_cacher_info_vignette()", tempsAffichage);
	}
}
function cacher_info_vignette() {
	clearInterval(id_interval);
	var monDiv = document.getElementById("info_vignette");
	monDiv.className = "info_vignette_invisible";
	monDiv.style.top = "0px";
	monDiv.style.left = "0px";
}
function mouseOver_info_vignette() {
	onMenu = true;
}
function mouseOut_info_vignette() {
	onMenu = false;
}

//	Affichage de la popup dispo

function afficher_popup_dispo(lien) {
	
	var monDiv = document.getElementById("popup_dispo");
	//monDivContent.innerHTML = "";
	var monLeft = fDomOffset(lien, 'offsetLeft');
	var monTop = fDomOffset(lien, 'offsetTop');
	//alert("left : "+monLeft+" top : "+monTop);
	var left = (monLeft - 100);
	var top = (monTop - 160);
	
	//var left = (((dim_window_w()/2) + 0) - (300/2));
  	//var top = (dim_window_h()/2) - (100/2);
	
	monDiv.style.top = top+"px";
	monDiv.style.left = left+"px";

	monDiv.className = "popup_dispo_visible";
	id_interval = setInterval("cacher_popup_dispo()", tempsAffichage);
}
function cacher_popup_dispo() {
	clearInterval(id_interval);
	var monDiv = document.getElementById("popup_dispo");
	monDiv.className = "info_vignette_invisible";
	monDiv.style.top = "0px";
	monDiv.style.left = "0px";
}
function storage_select_tr(tr, id_table) {
	var tab_tr = document.getElementById(id_table).getElementsByTagName("tr");
	for (var i=0; i<tab_tr.length; i++) {
		tab_tr[i].className = "";
	}
	tr.className = "storage_content_tr_current";
}
