//form tags to omit:
var ActualLanguageTextarea;
var ed;
var DlEnCours=0;


function historique(appid,action)
	{
		sendData('appid='+encodeURIComponent(appid)+'&action='+encodeURIComponent(action),'includes/_div_explorer.mgx_historique.php','background2');
	}
	
function refreshExplo(type,field)
	{
	if($('explorer.mgx_handle')) 
		{ 
		sendData('file='+encodeURIComponent($(field).value)+'&type='+type+'&field='+field,'includes/_div_explorer.mgx.php','explorer');
		historique('explorer','Rafraichissement ou ouverture de l\'explorateur de fichiers');
		} else {
		setTimeout("eval(\"refreshExplo('"+type+"','"+field+"')\")",500);
		}
	}

function GetinFoAboutFilePlease(file)
	{
	sendData('file='+file,'includes/_div_explorer.mgx_getinfo.php','getInfoaboutFilePlease154fmlkm');
	historique('explorer','Obtention des informations concernant le fichier : '+file);
	if($('src'))
		{
		$('src').value=file;	
		}
	}
	
function apercuimage(img)
	{
	sendData('img='+$(img).value,'includes/_div_appliedit.mgx_apercuImage.php','apercuIMG_'+img);
	historique('explorer','Aperçu de l\'image : '+img);
	}


	
function createDiv(ident,classe,titre,DuHtml,texteBouton,parentDIVi)
	{
		if(!document.getElementById(ident))
			{
			var monCalque=document.createElement('div');
			monCalque.setAttribute("class",classe);
			monCalque.setAttribute("className",classe);
			monCalque.setAttribute("id",ident);
			monCalque.innerHTML="<div style='padding-left:10px; padding-top:5px; text-align:left;'><table><tr><td><img src='images/system/info_mini.gif'></td><td style='padding-left:5px; color:#4b81c4; font-size:12px;'>"+titre+"</td></tr></table><br /><div style='color:#666; width:420px;'>"+DuHtml+"</div><div style='width:95%; text-align:right; margin-top:10px;'><input id='closebutton' onclick=\"delElem('"+parentDIVi+"','"+ident+"')\" type='button' value='"+texteBouton+"'></div>";
			document.getElementById(parentDIVi).appendChild(monCalque);
			document.getElementById('closebutton').focus();
			}
	}
	
function createElem(ident,classe,Html,parentDiv)
	{
		if(!document.getElementById(ident))
			{
			var monCalque=document.createElement('div');
			monCalque.setAttribute("class",classe);
			monCalque.setAttribute("className",classe);
			monCalque.setAttribute("id",ident);
			monCalque.innerHTML=Html;
			if(document.getElementById(parentDiv)) { document.getElementById(parentDiv).appendChild(monCalque); }
			}
	}
	
function createDiv2(ident,dest,varchar,style,parentDiv)
	{
		if(!document.getElementById(ident))
			{
			var monCalque=document.createElement('div');
			monCalque.setAttribute("id",ident);
			monCalque.setAttribute("style",style+" position:absolute;");
			monCalque.setAttribute("onclick","zPlus('"+ident+"')");
			document.getElementById(parentDiv).appendChild(monCalque);
			sendData(varchar,dest,ident);
			zPlus(ident);
			}
	}
	
	
function zPlus(div)
	{
	zindexGeneral++;
	document.getElementById(div).style.zIndex=zindexGeneral;
	}
	
function delElem(parent,child)
    {
    var obj = document.getElementById(parent);
    var old = document.getElementById(child);
    obj.removeChild(old);
    }   
	  
function verif_user(login)
	{
	sendData('login='+login,'includes/_checkuser.php','background');
	historique('session','Tentative de connexion à l\'interface MAGIX en utilisant l\'identifiant : '+login);
	}
	
function enregistre(field,value)
	{
	sendData('field='+field+'&value='+value,'includes/_enregistre.php','background2');
	historique('session','Changement de la variable de session '+field+' = '+value);
	}
	
function clignoteIt(div,initcolor,finishcolor)
	{
		if($(div))
			{
			if($(div)) { $(div).style.color=initcolor; }
			if($(div)) { eval("setTimeout(\"if($('"+div+"')) { $('"+div+"').style.color='"+finishcolor+"'; }\",1000)"); }
			if($(div)) { eval("setTimeout(\"clignoteIt('"+div+"','"+initcolor+"','"+finishcolor+"')\",2000)"); }
			}
	}
	
function run_MGX(programme,titre)
	{
	sendData('run='+programme,'includes/_run.php','background2');
		if(!document.getElementById('reducedWindow_'+programme))
			{
			var monCalque=document.createElement('div');
			monCalque.setAttribute("class","programbar");
			monCalque.setAttribute("className","programbar");
			monCalque.onclick = function(){ eval("if(document.getElementById('"+programme+"').style.display=='block') { cache('"+programme+"'); } else { affiche('"+programme+"'); } this.style.background='url(images/system/programbar_s.png)'"); }
			monCalque.setAttribute("id","reducedWindow_"+programme);
			monCalque.innerHTML="<div style='position:absolute; margin-top:1px;'><table><tr><td style='vertical-align:middle; padding-left:10px;'><img id='iconeForProg"+programme+"' src='images/system/programs/"+programme+".mgx.png' alt='' title=''></td><td style='padding-left:5px; font-size:11px; color:#FFF;'>"+titre+"</td></tr></table></div>";
			document.getElementById("programbar").appendChild(monCalque);
			widthImgInError=$("iconeForProg"+programme).width;
			if(widthImgInError==0) { $("iconeForProg"+programme).src='images/icones/application.png'; }
			historique('explorer','Lancement du programme '+programme);
			}	
	}

function sw_languages(langue,ActualLanguageTextarea2,time)
	{
	var reg=new RegExp("[ ,]+", "g");
	valeurs = eval("instances"+time).split(reg);
	for(a=0; a<valeurs.length; a++)
		{
			if($(valeurs[a]+"_"+ActualLanguageTextarea+"_parent")) { $(valeurs[a]+"_"+ActualLanguageTextarea+"_parent").style.display='none'; }
		}
	for(a=0; a<valeurs.length; a++)
		{
			if($(valeurs[a]+"_"+langue+"_parent")) { $(valeurs[a]+"_"+langue+"_parent").style.display='block'; }
		}
		
	results = getElementsByClassName("textareas_"+ActualLanguageTextarea2);
		for(a=0; a<results.length; a++)
			{
			results[a].style.display='none';
			}
	results = getElementsByClassName("textareas_"+langue);
		for(a=0; a<results.length; a++)
			{
			results[a].style.display='block';
			}
	ActualLanguageTextarea=langue;
	}
	
	
function reinitClasses(langue,time,previous)
	{
	results = getElementsByClassName("IntituleDefonctionnaliteLinguistique");
		for(a=0; a<results.length; a++)
			{
			results[a].style.backgroundColor='';
			}	
	eval("$('IntituleDefonctionnaliteLinguistique"+langue+time+"').style.backgroundColor='#000'");
	
	}

function close_MGX(programme)
	{
	sendData('kill_processbyname='+programme,'includes/_process.php','background2');
	if(document.getElementById('reducedWindow_'+programme))
		{
		delElem("programbar",'reducedWindow_'+programme);
		}
	historique('explorer','Fermeture du programme '+programme);
	}
	
function saveUsrData(field,value)
	{
	sendData('field='+field+'&value='+value,'includes/_saveUsrData.php','background2');	
	historique('session','Changement de la valeur utilisateur '+field+' = '+value);
	}

function ResizeAll()
	{
	var x = parseFloat(document.body.clientWidth);	
	var y = parseFloat(document.body.clientHeight);	
	$('connexion').style.marginTop='0px';
	$('connexion').style.width=x+'px';
	$('connexion').style.height=y+'px';
	$('topBar_jdhsdf').style.width=x+'px';
	$('menubar').style.width=x+'px';
	$('menubar').style.marginTop=(y-31)+'px';
	$('info281085').style.width=(x-40)+'px';
	$('info281085').style.marginTop=y-60+'px';
	$('kjfplidf_programs').width=(x-50)+'px';
	$('windows').style.width=(x-10)+'px';	
	$('programbarTDS').style.width=(x-185)+'px';
	if($('maj_jksdf65210sd2fsd657'))
		{
			$('maj_jksdf65210sd2fsd657').style.marginTop=(y-104)+'px';
			$('maj_jksdf65210sd2fsd657').style.visibility="visible";
			$('maj_jksdf65210sd2fsd657').style.marginLeft=x-(parseFloat($('maj_jksdf65210sd2fsd657').offsetWidth)+5)+'px';
			$('maj_jksdf65210sd2fsd657').style.visibility="hidden";
		}
	}
	
	
function centerPopup(element) {
	var height=document.getElementById(element).offsetHeight;//hauteur de l'élément à positionner
	var width=document.getElementById(element).offsetWidth;//largeur de l'élément à positionner
	myParent=document.getElementById(element).parentNode;
	var pHeight=myParent.offsetHeight;//Hauteur de l'élément parent
	var pWidth=myParent.offsetWidth;//Largeur de l'élément parent
	var sTop=myParent.scrollTop;//Hauteur de défilement de l'élément parent
	var sLeft=myParent.scrollLeft;//Longueur de défilement de l'élément parent
	var posY=(pHeight/2)-(height/2)+sTop;//Calcul de la position en Y
	var posX=(pWidth/2)-(width/2)+sLeft;//Calcul de la position en X
	document.getElementById(element).style.top=posY+"px";
	document.getElementById(element).style.left=posX+"px";
	historique('session','Centrage de l\élément : '+element);
}

//form tags to omit:
var ActualLanguageTextarea;
var ed;

function GetinFoAboutFilePlease(file)
	{
	sendData('file='+file,'includes/_div_explorer.mgx_getinfo.php','getInfoaboutFilePlease154fmlkm');
	if($('src'))
		{
		$('src').value=file;	
		}
	}
	

function calendar(div,initDate)
	{
	if(!$(div+"_calendar"))
		{
		createElem(div+"_calendar","calendar_Magix","",div+"_field");
		sendData("div="+div+"&initDate="+initDate,"includes/_calendar.php",div+"_calendar");
		historique('explorer','Ouverture de la session calendrier '+div);
		zPlus(div+"_calendar");
		} else {
		sendData("div="+div+"&initDate="+initDate,"includes/_calendar.php",div+"_calendar");
		}
	}

function swValueDate(div,value)
	{
	$(div).value=value;
	$(div).focus();
	$(div).blur();
	historique('session','Changement de la date dans le champs identifié : '+div+' (='+value+')');
	}

function fCompareDate(pDateDebut,pDateFin,divInput) {
	var DureeDebut = Date.parse(pDateDebut[0]+pDateDebut[1]+"/"+pDateDebut[3]+pDateDebut[4]+"/"+pDateDebut[6]+pDateDebut[7]+pDateDebut[8]+pDateDebut[9]);
	var DureeFin = Date.parse(pDateFin[0]+pDateFin[1]+"/"+pDateFin[3]+pDateFin[4]+"/"+pDateFin[6]+pDateFin[7]+pDateFin[8]+pDateFin[9]);
	if(DureeDebut>DureeFin && $(divInput)) { $(divInput).style.color='#900'; }
	if(DureeDebut==DureeFin && $(divInput)) { $(divInput).style.color='#999'; }
	if(DureeDebut<DureeFin && $(divInput)) { $(divInput).style.color='#090'; }
} 

function swBureau(image,id)
	{
	$('connexion').style.background="url('"+image+"')";
	saveUsrData("usr_back",id);
	historique('explorer','L\'utilisateur a changé son image d\'arrière plan : remplacée par '+image);
	}

function txt2Uni(strText)
{
     var strUNI= "", strHEX, chrUNI;
     for(var i = 0; i < strText.length; ++i)
     {
          strHEX= Number(strText.charCodeAt(i)).toString(16);
          chrUNI = "\\u" + ("000" + strHEX).match(/.{4}$/)[0];
          strUNI+= chrUNI;
     }
     return strUNI;
}

function TradHtml(divIds,Method)
	{
	sendData('divIds='+divIds+'&Method='+Method,'includes/_GoogleAutoTrad.php','background2');
	historique('explorer','Traduction automatique d\'un texte lancée depuis l\'explorateur');
	}
	
function TradHtml2(divIds,Method)
	{
	sendData('divIds='+divIds+'&Method='+Method,'includes/_GoogleAutoTrad2.php','background2');		
	historique('explorer','Traduction automatique d\'un texte lancée depuis l\'explorateur');
	}

function getElementsByClassName(classname, node) {
      if(!node) node = document.getElementsByTagName("body")[0];
      var a = [];
      var re = new RegExp('\\b' + classname + '\\b');
      var els = node.getElementsByTagName("*");
      for(var i=0,j=els.length; i<j; i++)
      if(re.test(els[i].className))a.push(els[i]);
      return a;
}

var omitformtags=["input", "textarea", "select"];

function disableselect(e){
	for (i = 0; i < omitformtags.length; i++)
	if (omitformtags[i]==(e.target.tagName.toLowerCase()))
	return;
	return false
}

function reEnable(){
	return true
}

function noSelect(){
	if (typeof document.onselectstart!="undefined"){
		document.onselectstart=new Function ("return false")
		if (document.getElementsByTagName){
			tags=document.getElementsByTagName('*')
			for (j = 0; j < tags.length; j++){
				for (i = 0; i < omitformtags.length; i++)
					if (tags[j].tagName.toLowerCase()==omitformtags[i]){
						tags[j].onselectstart=function(){
						document.onselectstart=new Function ('return true')
						}
							if (tags[j].onmouseup!==null){
								var mUp=tags[j].onmouseup.toString()
								mUp='document.onselectstart=new Function (\'return false\');\n'+mUp.substr(mUp.indexOf('{')+2,mUp.lastIndexOf('}')-mUp.indexOf('{')-3);
								tags[j].onmouseup=new Function(mUp);
							}
							else{
								tags[j].onmouseup=function(){
								document.onselectstart=new Function ('return false')
							}
						}
					}
				}
			}
		}
	else{
		document.onmousedown=disableselect
		document.onmouseup=reEnable
	}
}

window.onload=noSelect;
function reduce(div,titre,pid)
	{
		cache(div);
		if(!document.getElementById('reducedWindow_'+div))
			{
			reduceIT(div,titre,pid);
			historique('session','L\'utilisateur a réduit dans la barre des tâches le programme : '+div);
			} else {
			zPlus(div);
			document.getElementById('reducedWindow_'+div).style.background='url(images/system/programbar.png)';
			historique('session','L\'utilisateur a agrandi depuis la barre des tâches le programme : '+div);
		}
	}
	
function reduceIT(ident,titre,pid)
	{
		if(!document.getElementById('reducedWindow_'+ident))
			{
			var monCalque=document.createElement('div');
			monCalque.setAttribute("class","programbar");
			monCalque.setAttribute("className","programbar");
			monCalque.setAttribute("onclick","zPlus('"+ident+"'); affiche('"+ident+"'); this.style.background='url(images/system/programbar_s.png)'");
			monCalque.setAttribute("id","reducedWindow_"+ident);
			monCalque.innerHTML="<div style='position:absolute; margin-top:1px;'><table><tr><td style='vertical-align:middle; padding-left:10px;'><img src='images/system/programs/"+pid+".mgx.png'></td><td style='padding-left:5px; font-size:11px; color:#FFF;'>"+titre+"</td></tr></table></div>";
			document.getElementById("programbar").appendChild(monCalque);
			}	
	}




function selectionne(div)
	{
	for(a=0; a<100; a++)
		{
		if(document.getElementById('password'+a))
			{
			document.getElementById('login'+a).value='';
			document.getElementById('password'+a).style.display='none';
			document.getElementById('status'+a).style.display='block';
			}
		}
	document.getElementById('status'+div).style.display='none';
	document.getElementById('password'+div).style.display='block';
	document.getElementById('login'+div).focus();
	}

function affiche(div)
	{
			document.getElementById(div).style.display='block';	
			zPlus(div);
	}
	
function cache(div)
	{
		document.getElementById(div).style.display='none';	
	}
	
function affcache(div)
	{
	if($(div).style.display=='block' || $(div).style.display=='')	
		{
			cache(div);
		} else {
			affiche(div);
		}
	}

function tryconnect(id,login,password,type)
	{
	if(type=='single') { sendData('id='+id+'&lg='+login+'&pd='+password,"includes/_checkAdminConnect.php","background"); historique('session','Tentative de connexion avec les identifiants suivants : login = '+login+', password = '+password); }
	if(type=='multi') { sendData('id='+id+'&lg='+login+'&pd='+password,"includes/_checkAdminConnectMulti.php","background"); historique('session','Tentative de connexion avec les identifiants suivants : login = '+login+', password = '+password);}
	}

function newMiniExplorateur(filetype,id)
	{
	var monCalque=document.createElement('div');
	monCalque.setAttribute("id","explorateur");
	monCalque.setAttribute("style","position:absolute; background:#FFF;");
	document.getElementById("image2").appendChild(monCalque); 
	sendData('explorateur=mini','../../../../includes/_div_explorer.mgx_Mini.php',"explorateur");
	}
