var x;
var y;
var larg;
var haut;

// Récupération de la taille de la fenêtre du client
function taille()
{
	larg = screen.width;
	haut = screen.height;
}

// Ecoute de la position du curseur
function position(e)
{
	x = (navigator.appName.substring(0,3) == "Net") ? e.pageX : event.x+document.body.scrollLeft;
	y = (navigator.appName.substring(0,3) == "Net") ? e.pageY : event.y+document.body.scrollTop;
}
if (navigator.appName.substring(0,3) == "Net")
	document.captureEvents(Event.MOUSEMOVE);
	
document.onmousemove = position;

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function affImage(img,largeur,hauteur)
{
	taille();
	var xlargeur = eval(x + "+" + largeur);
	var yhauteur = eval(y + "+" + hauteur);
	if (xlargeur > larg)
	{
		x = 0;
	}
	
	if (yhauteur > haut)
	{
		y = 0;
	}
	var el = document.getElementById('image');
	el.style.marginLeft = x+'px';
	el.style.marginTop = y+'px';
	document.getElementById('image').style.width = largeur+'px';
	document.getElementById('image').style.height = hauteur+'px';
	document.getElementById('image').innerHTML = '<img src="'+img+'"/>';
	document.getElementById('image').style.display = 'block';
}

function closeImage()
{
	document.getElementById('image').style.display = 'none';
	document.getElementById('image').innerHTML = '';
}

// Ouverture popup
function affPopup()
{
	taille();
	//document.getElementById('masque').style.opacity = '0.6';
	//document.getElementById('masque').style.filter = 'alpha(opacity=60)'; // Pour IE mais ça ne marche pas
	var el = document.getElementById('popup');
	if (x + 460 > larg)
	{
		x = x - 420;
	}
	
	if (y + 300 > haut)
	{
		y = y - 300;
	}
	el.style.marginLeft = x+'px';
	el.style.marginTop = y+'px';
	document.getElementById('popup').style.display = 'block';
}

// Fermeture popup
function closePopup ()
{
	document.getElementById('popup').style.display = 'none';
	write('');
	document.getElementById('masque').style.opacity='1';
}

// Ecriture dans la div contenu du popup
function write (texte)
{
	document.getElementById('popupcontenu').innerHTML = texte;
}

// Information du fichier
function info(fichier,tailleFichier,extension,filemtime,width,height)
{
	write (file('explorer/info.php?infoFichier='+fichier+'&infoTailleFichier='+tailleFichier+'&infoExtension='+extension+'&infoFilemtime='+filemtime+
		'&width='+width+'&height='+height));
	affPopup();
}

function creerRep(rep)
{
	write (file('explorer/creerrep.php?rep='+rep));
	affPopup();
}

function uploader(rep)
{
	write (file('explorer/uploader.php?rep='+rep));
	affPopup();
}

function options()
{
	write (file('explorer/options.php'));
	affPopup();
}

function connexion()
{
	write (file('explorer/connexion.php'));
	affPopup();
}

function deconnexion()
{
	write (file('explorer/connexion.php?logout=true'));
	affPopup();
}

function deletefile(adresse,fichier)
{
	if (window.confirm('Etes vous sur de vouloir supprimer le fichier \''+fichier+'\' ?'))  	
    {
		var retour = file('explorer/deletefile.php?fichier=.'+adresse);
		alert (retour);
		if (retour.substring(0,3) == 'Le ')
			document.location.reload();
	}
}

function deleterep(adresse,rep)
{
	if (window.confirm('Etes vous sur de vouloir supprimer le répertoire \''+rep+'\' ?'))  	
    {
		var retour = file('explorer/deleterep.php?fichier=.'+adresse);
		alert (retour);
		if (retour.substring(0,3) == 'Le ')
			document.location.reload();
	}
}

// Edition du titre --------------------------------------------------------------------------------------
function editNom (nom,adresse,i)
{
	var div = "nomFichier"+i;
	document.getElementById(div).innerHTML = '<input onblur="writeNom(\''+nom+'\',\''+adresse+'\',this.value,\''+i+'\')" type="text" value="'+nom+'">';
}

function writeNom (nom,adresse,newNom,i)
{
	var div = "nomFichier"+i;
	var retour = file('explorer/renommer.php?nom='+nom+'&adresse='+adresse+'&newNom='+newNom);
	if (retour.substring(0,6) == 'Action' || retour.substring(0,10) == 'Impossible')
	{
		document.getElementById(div).innerHTML = '<span id="'+div+'" ondblclick="editNom(\''+nom+'\',\''+adresse+'\',\''+i+'\')\">'+nom+'</span>';
		alert (retour);
	}
	else
	{
		document.getElementById(div).innerHTML = '<span id="'+div+'" ondblclick="editNom(\''+newNom+'\',\''+adresse+'\',\''+i+'\')\">'+newNom+'</span>';
	}
	//document.getElementById(div).innerHTML = newNom;
}

// Ajax
function file(fichier) // Pour les GET
{
    if(window.XMLHttpRequest) // FIREFOX
        xhr_object = new XMLHttpRequest();
    else if(window.ActiveXObject) // IE
        xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
    else
        return(false);
    xhr_object.open("GET", fichier, false);
    xhr_object.send(null);
    if(xhr_object.readyState == 4) return(xhr_object.responseText);
    else return(false);
}

function creerRepGo(nom,rep) // Création d'un rép en POST
{ 
	var xajax = null; 
	 
	if(window.XMLHttpRequest) xajax = new XMLHttpRequest(); 
	else if(window.ActiveXObject) xajax = new ActiveXObject("Microsoft.XMLHTTP"); 

	else return(false); 
	 
	//> variable=valeur&variable2=valeur&variable3=valeur ... 
	 
	var str = "nom="+nom; 
	
	xajax.open("POST",'explorer/creerrep.php?rep='+rep,false); 
	xajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=iso-8859-1"); 
	xajax.setRequestHeader("Content-Transfer-Encoding", "iso-8859-1"); 
	xajax.send(str); 
	if(xajax.readyState == 4) { 
		write(xajax.responseText); 
	} 
}

function optionsGo(go,cache,pass,creerrep,upload,php,renommer,supprimer,masquer,taille) // Modification des options en POST
{ 
	var xajax = null; 
	 
	if(window.XMLHttpRequest) xajax = new XMLHttpRequest(); 
	else if(window.ActiveXObject) xajax = new ActiveXObject("Microsoft.XMLHTTP"); 

	else return(false); 
	
	//> variable=valeur&variable2=valeur&variable3=valeur ... 
	 
	var str = 'go='+go+'&cache='+cache+'&pass='+pass+'&creerrep='+creerrep+'&upload='+upload+'&php='+php+'&renommer='+renommer+'&supprimer='+supprimer+'&masquer='+masquer+'&taille='+taille; 

	xajax.open("POST",'explorer/options.php',false); 
	xajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=iso-8859-1"); 
	xajax.setRequestHeader("Content-Transfer-Encoding", "iso-8859-1"); 
	xajax.send(str); 
	if(xajax.readyState == 4) { 
		write(xajax.responseText); 
	} 
}

function connexionGo(mot_de_passe) // Connexion en POST
{ 
	var xajax = null; 
	 
	if(window.XMLHttpRequest) xajax = new XMLHttpRequest(); 
	else if(window.ActiveXObject) xajax = new ActiveXObject("Microsoft.XMLHTTP"); 

	else return(false); 
	 
	//> variable=valeur&variable2=valeur&variable3=valeur ... 
	 
	var str = "mot_de_passe="+mot_de_passe; 
	
	xajax.open("POST",'explorer/connexion.php',false); 
	xajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=iso-8859-1"); 
	xajax.setRequestHeader("Content-Transfer-Encoding", "iso-8859-1"); 
	xajax.send(str); 
	if(xajax.readyState == 4) { 
		write(xajax.responseText); 
	} 
}