/*****  Script développé dans le cadre de  JEK INNOVACTION  *****/


function ShowItorNot(ind){
    if(ind == '' || typeof(ind)=='undefined'){
      ind=0;
    }
    if(typeof(mySlide1)!='undefined'){
      if(ind!=1){
        /*e = new Event(e).stop();*/
        mySlide1.slideOut();
      }
      else
        mySlide1.slideIn();
    }
    if(typeof(mySlide2)!='undefined'){
      if(ind!=2){
      /*e = new Event(e).stop();*/
      mySlide2.slideOut();
      }
      else
        mySlide2.slideIn();
    }
    if(typeof(mySlide3)!='undefined'){
      if(ind!=3){
      /*e = new Event(e).stop();*/
      mySlide3.slideOut();}
      else
        mySlide3.slideIn();
    }
    if(typeof(mySlide4)!='undefined'){
      if(ind!=4){
      /*e = new Event(e).stop();*/
      mySlide4.slideOut();}
      else
        mySlide4.slideIn();
    }
    if(typeof(mySlide5)!='undefined'){
      if(ind!=5){
      /*e = new Event(e).stop();*/
      mySlide5.slideOut();}
      else
        mySlide5.slideIn();
    }
    if(typeof(mySlide6)!='undefined'){
      if(ind!=6){
      /*e = new Event(e).stop();*/
      mySlide6.slideOut();}
      else
        mySlide6.slideIn();
    }
    if(typeof(mySlide7)!='undefined'){
      if(ind!=7){
      /*e = new Event(e).stop();*/
      mySlide7.slideOut();}
      else
        mySlide7.slideIn();
    }
    if(typeof(mySlide8)!='undefined'){
      if(ind!=8){
      /*e = new Event(e).stop();*/
      mySlide8.slideOut();}
      else
        mySlide8.slideIn();
    }
}


function setOpacity(obj,valeur){
	if(window.navigator["appName"]=='Microsoft Internet Explorer'){
	  obj.style.filter = "alpha(opacity='" + valeur + "')";
	}
	else{
		obj.style.opacity = valeur/100;
		obj.style.MozOpacity = valeur/100;
		obj.style.KHTMLOpacity = valeur/100;
	}
}	

function refreshion(){
	Objet=document.getElementById("Logorithme").id;
	for (var i=0;i<11;i++)
		setTimeout("setOpacity("+Objet+","+i*10+")",100*i);		
}


function Go(Page,sess,elementPage){
	/*** elementPage est un paramètrre facultatif dans la fonction Go ***/
	if(!(elementPage) || typeof(elementPage)=='undefined' ){
		elementPage="Corps";
	}
	if( (sess) && (sess!='undefined') ){
		var otherQuery="";
		if((iSplit=String(sess).indexOf(';'))!=-1){
			iEndStr=String(sess).length;
			otherQuery=String(sess).substring(iSplit+1,iEndStr);
			sess=String(sess).substring(0,iSplit);
		}
		/*** Recupérer les variables de session et de connexion ***/
		if(document.getElementById(sess)){
			varSess=document.getElementById(sess).value;
		}
		else if(window.parent.document.getElementById(sess)){
			varSess=window.parent.document.getElementById(sess).value;
		}
		varSess+=otherQuery;
		if(window.parent.document.getElementById(elementPage))
			window.parent.document.getElementById(elementPage).src=Page+"?la_session="+varSess;
		else if(document.getElementById(elementPage))
				document.getElementById(elementPage).src = Page+"?la_session="+varSess;
		else if(parent.frames[elementPage])
			parent.frames[elementPage].window.location.href = Page+"?la_session="+varSess;
	}
}


function AjaxRequest(url,id,elem){
/*** Main directory : Popoolup ***/
  var xhr_object = null;
  var position = id;

	if(window.XMLHttpRequest){ /*** Firefox et autres ***/
	   xhr_object = new XMLHttpRequest();
	}
	else if(window.ActiveXObject){ /** Internet Explorer  **/
	 try {
        xhr_object = new ActiveXObject("Msxml2.XMLHTTP");
     }
     catch (e) {
        xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
     }
	}
	else { /*** XMLHttpRequest non supporté par le navigateur ***/
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	   xhr_object = false;
	}

      
	/**** On ouvre la requete vers la page désirée   ****/
	xhr_object.open("GET", url, true);
	xhr_object.onreadystatechange = function(){
		if ( xhr_object.readyState == 4 ){
		  /**** j'affiche dans la DIV spécifiées le contenu retourné par le fichier ****/
		  document.getElementById(elem).innerHTML = xhr_object.responseText;
		}
	}
	/*** dans le cas du get ***/
	xhr_object.send(null);
}


function Register(Mat,Mdp,elem){
	
	var id = 5;
	var varSess="";
	var url = "";
	
	if($("la_session")){
		varSess = $('Session').value;
	}
	else if(window.parent.document.getElementById('Session')){
		varSess = window.parent.document.getElementById('Session').value;
	}
	else varSess = document.getElementById("Session").value;
	
	url = 'Login.php?Session='+varSess+'&Mat='+Mat+'&Mdp='+Mdp;
	if(!(elem) || typeof(elem)=='undefined'){
		if(window.parent.document.body)
			elem=window.parent.document.body;
		else elem=document.body;
	}
	var myAjax = new Ajax(url,{
		update:elem,
		method : 'get',
		onComplete: function(){
			var divLoad = new Element ('div',{'id':'divLoad','class':'loadStyle'}).inject(document.body);
			divLoad.setStyles({'z-index':500,'top':'0px','left':'0px','width':'100%','height':'100%'});
			var spText1 = new Element('p',{'id':'textLoad','class':'loadText'}).setHTML('Chargement en cours...<br>').inject(divLoad);
			spText1.setStyles({'bottom':'375px','left':'450px'});
			var img1 = new Element('img',{'src':'Images/Form/LogoJek.gif','border':'0px'}).inject(spText1);
			/***
			var spText2 = new Element('p',{'id':'textLoad','class':'loadText'}).setHTML('<br>Veuillez patienter<br>').inject(spText1);
			***/
			var img2 = new Element('img',{'src':'Images/Form/loading.gif','border':'0px'}).inject(spText2);
			var close =  new Element('a',{'id':'closeConn'}).setHTML('FERMER LA CONNEXION').addEvent('click',function(){
				myAjax.cancel();
				divLoad.remove();
			}).inject(divLoad);
			close.setStyles({'bottom':'25px','left':'450px'});
			setTimeout("ConnecteOK('"+varSess+"')",2000);
		},
		onCancel: function(){
			divLoad.remove();
		}
	});
	myAjax.request();
	/***AjaxRequest(url,id,elem);***/
}

function getFieldValue(ElemField){
	if(typeof($(ElemField))!="undefined"){
		valueOfField = $(ElemField).value;
	}
	else if(window.parent.document.getElementById(ElemField)){
		valueOfField = window.parent.document.getElementById(ElemField).value;
	}
	else valueOfField = document.getElementById(ElemField).value;
	return valueOfField;
}

function PrintPage(sPage,sArg,ElemIn,ind){
/****** DIV DE CHARGEMENT *******/
			var divLoad = new Element ('div',{'id':'divLoad','class':'loadStyle'}).inject(document.body);
			divLoad.setStyles({'position':'absolute','z-index':500,'top':'0px','left':'0px','width':'100%','height':'100%'});
			var spText1 = new Element('p',{'id':'textLoad','class':'loadText'}).setHTML('Chargement en cours...<br>').inject(divLoad);
			spText1.setStyles({'bottom':'375px','left':'450px'});
			var img1 = new Element('img',{'src':'Images/Form/LogoJek.gif','border':'0px'}).inject(spText1);
			var spText2 = new Element('p',{'id':'textLoad','class':'loadText'}).setHTML('<br>Veuillez patienter<br>').inject(spText1);
			var img2 = new Element('img',{'src':'Images/Form/loading.gif','border':'0px'}).inject(spText2);
			var close =  new Element('a',{'id':'closeConn'}).setHTML('FERMER LA CONNEXION').addEvent('click',function(){
				if(typeof(myAjax)!='undefined')
					myAjax.cancel();
				divLoad.remove();
			}).inject(divLoad);
			close.setStyles({'bottom':'25px','left':'450px'});
/****** DIV DE CHARGEMENT *******/
			
	var id = 5;
	var sSess="";
	var sUrl = "";
	var sLang = "";
	
	sSess = getFieldValue('Session');
	sLang = getFieldValue('Langue');
	
	sUrl = sPage+'?Session='+sSess+'&Langue='+sLang+sArg;
	
	if(!(ElemIn) || typeof(ElemIn)=='undefined'){
		if(window.parent.document.body)
			ElemIn=window.parent.document.body;
		else ElemIn=document.body;
	}
	
	var myAjax = new Ajax(sUrl,{
		update : ElemIn,
		method : 'get',
		onComplete: function(){
			divLoad.remove();
			ShowItorNot(ind);
			/*****
			MiseEnForme(ind);
			setTimeout("FreeSpare()","750");
			*****/
		},
		onCancel: function(){
			divLoad.remove();
		}
	});
	AjaxRequest('RecupImage.php?'+sArg,1,'tdImgPage');
	myAjax.request();
	/***AjaxRequest(url,id,elem);***/
}

function GetNewPage(sPage,sInd,sDiv){
		iTaille = sPage.length;
		iDebArg = sPage.indexOf('?');
		sArg = sPage.substr(iDebArg+1,iTaille);
		sSess = getFieldValue('Session');
		sLang = getFieldValue('Langue');
		
		sUrlImage = 'RecupImage.php?&Session='+sSess+'&Langue='+sLang+sArg;
		sPage += '&Session='+sSess+'&Langue='+sLang+sArg;
		AjaxRequest(sUrlImage,0,'tdImgPage');
		AjaxRequest(sPage,sInd,sDiv);
}

function ConnecteOK(varSess){
	if($('conn_civilite')){
		var varConn="&CIV="+$('conn_civilite').value;
		if($('conn_nom'))
			varConn+="&NomA="+$('conn_nom').value;
		if($('conn_prenom'))
			varConn+="&PrenomA="+$('conn_prenom').value;
		if($('conn_matricule'))
			varConn+="&Matri="+$('conn_matricule').value;
		if($('conn_droit'))
			varConn+="&Droit="+$('conn_droit').value;
	
		window.location.href="index2.php?&la_session="+varSess+varConn;
	}
	else{
		alert('Erreur lors de votre essai de connexion !!\nVeuillez vérifier votre matricule et/ou votre mot de passe.');
		if($('divLoad'))
			$('divLoad').remove();
	}
	/*
	if(typeof(TblAssoConn)!='undefined' && (TblAssoConn['civilite']!='') &&(TblAssoConn['civilite']!='undefined') ){
		var varConn="&CIV="+TblAssoConn['civilite'];
		varConn+="&NomA="+TblAssoConn['nom'];
		varConn+="&Prenom="+TblAssoConn['prenom'];
		varConn+="&Matri="+TblAssoConn['matricule'];
		varConn+="&Droit="+TblAssoConn['droit'];
	}
	*/
}

function FreeSpare(){
	/****** DIV DE CHARGEMENT *******/
			var divLoadEnd = new Element ('div',{'id':'divLoad','class':'loadStyle'}).inject(document.body);
			divLoadEnd.setStyles({'position':'absolute','z-index':500,'top':'0px','left':'0px','width':'100%','height':'100%'});
			var spText1 = new Element('p',{'id':'textLoad','class':'loadText'}).setHTML('Fin du Chargement <br>').inject(divLoadEnd);
			spText1.setStyles({'bottom':'375px','left':'450px'});
			var img1 = new Element('img',{'src':'Images/Form/LogoJek.gif','border':'0px','width':'50px'}).inject(spText1);
			var spText2 = new Element('p',{'id':'textLoad','class':'loadText'}).setHTML('<br>Veuillez patienter<br>').inject(spText1);
			var img2 = new Element('img',{'src':'Images/Form/loading.gif','border':'0px'}).inject(spText2);
			var close =  new Element('a',{'id':'closeConn'}).setHTML('FERMER LA CONNEXION').addEvent('click',function(){
				if(typeof(myAjax)!='undefined')
					myAjax.cancel();
				divLoadEnd.remove();
			}).inject(divLoadEnd);
			close.setStyles({'bottom':'25px','left':'450px'});
			/****** DIV DE CHARGEMENT *******/
	divLoadEnd.remove();		
}


function GetSizePage(){
	idbHeight = document.body.clientHeight;
	idbWidth = document.body.clientWidth;
	if( (idbHeight > 500) && (idbWidth > 800) ){
		if( (idbWidth > 1152)){
			if(idbHeight > 680){ /***** Tenant compte de la hauteur de la barre de navigation  ~150 864-164=700*****/
				idbWidth = 827;/***idbWidth = 1152-325;***/
				idbHeight = 420;/***idbHeight = idbHeight-260;***/
			}
			else{
				/***idbWidth = idbWidth-325;***/
				idbWidth = 827;
				idbHeight = idbHeight-260;
			}
			$('HEAD_JEK').setStyles({'width':idbWidth+325,'height':idbHeight+260});
		}
		else if(idbHeight > 680){ /***** Tenant compte de la hauteur de la barre de navigation  ~150 864-164=700*****/
				idbHeight = 420;/***idbHeight = idbHeight-260;***/
				idbWidth = idbWidth-325;
			$('HEAD_JEK').setStyles({'width':idbWidth+325,'height':idbHeight+260});
		}
		else if((idbWidth < 1152) && (idbHeight < 680)){
			idbWidth = idbWidth-325;
			idbHeight = idbHeight-260;
		}
		$('tdDimensionW').value = idbWidth;
		$('tdDimensionH').value = idbHeight;
		 
		$('iTheme1_DIV').setStyles({'height':idbHeight,'width':idbWidth});
		$('iTheme2_DIV').setStyles({'height':idbHeight,'width':idbWidth});
		$('iTheme3_DIV').setStyles({'height':idbHeight,'width':idbWidth});
		$('iTheme4_DIV').setStyles({'height':idbHeight,'width':idbWidth});
		$('iTheme5_DIV').setStyles({'height':idbHeight,'width':idbWidth});
	}
}

