
/*
Paramètres à passer
=> ALERTE : 'width=500,height=500'
=> ADMIN : 'width=max,height=max' (utilise la largeur max dispo)
=> LOGING : 'width=350,height=200,scrollbars=no'
=> PHOTOS : 'width=500,height=500'
=> CONTACT : 'width=580,height=360'
*/

function PopUp(URL,attributs)
{
	var sepAttributs = ",";
	var leftOrTop = false;

	// Attributs par defaut de la fenêtre
	var alwaysRaised = "yes";
	var resizable = "yes";
	var directory = "no";
	var location = "no";
	var menubar = "no";
	var personalbar = "no";
	var status = "no";
	var toolbar = "no";
	var height = 600;
	var width = 800;
	var scrollbars = "yes";

	var left = 0;
	var top = 0;

	// On regarde si des attributs ont été spécifiés
	// si oui, on remplace les valeurs par défaut
	var tabAttributs = new Array();
	var tabCouple = new Array();
	tabAttributs = attributs.split(sepAttributs);

	for (var i=0 ; i < tabAttributs.length ; i++)
	{
		// element du tableau => "cle=valeur"
		tabCouple = tabAttributs[i].split("=");

		if (tabCouple.length == 2)
		{
			if (tabCouple[0] == "alwaysRaised")
				alwaysRaised = tabCouple[1];
			else if (tabCouple[0] == "personalbar")
				personalbar = tabCouple[1];
			else if (tabCouple[0] == "scrollbars")
				scrollbars = tabCouple[1];
			else if (tabCouple[0] == "resizable")
				resizable = tabCouple[1];
			else if (tabCouple[0] == "directory")
				scrollbars = tabCouple[1];
			else if (tabCouple[0] == "menubar")
				menubar = tabCouple[1];
			else if (tabCouple[0] == "location")
				location = tabCouple[1];
			else if (tabCouple[0] == "width")
			{
				if (tabCouple[1] == "max")
				{
					width = window.screen.width - 50 ;
					razTopLeft = true;
				}
				else
					width = tabCouple[1];
			}
			else if (tabCouple[0] == "height")
            {
				if (tabCouple[1] == "max")
					height = window.screen.height - 50 ;
				else
					height = tabCouple[1];
            }
			else if (tabCouple[0] == "toolbar")
				toolbar = tabCouple[1];
			else if (tabCouple[0] == "status")
				status = tabCouple[1];
			else if (tabCouple[0] == "left")
			{
				left = tabCouple[1];
				leftOrTop = true;
			}
			else if (tabCouple[0] == "top")
			{
				top = tabCouple[1];
				leftOrTop = true;
			}
		}
	}

	if (!leftOrTop)
	{
		// Pour le positionnement, par défaut on centre la popup
		if (window.screen.width >= width) left = (window.screen.width - width) / 2;
		if (window.screen.height >= height) top = (window.screen.height - height) / 2 - 25;
	}

	var caracteristiques = "";
	caracteristiques += "alwaysRaised=" + alwaysRaised + sepAttributs;
	caracteristiques += "resizable=" + resizable + sepAttributs;
	caracteristiques += "directory=" + directory + sepAttributs;
	caracteristiques += "location=" + location + sepAttributs;
	caracteristiques += "menubar=" + menubar + sepAttributs;
	caracteristiques += "personalbar=" + personalbar + sepAttributs;
	caracteristiques += "status=" + status + sepAttributs;
	caracteristiques += "toolbar=" + toolbar + sepAttributs;
	caracteristiques += "scrollbars=" + scrollbars + sepAttributs;
	caracteristiques += "height=" + height + sepAttributs;
	caracteristiques += "width=" + width + sepAttributs;
	caracteristiques += "left=" + left + sepAttributs;
	caracteristiques += "top=" + top;

	openedWindow = open (URL,'',caracteristiques);
}

function PopUpModal(URL,attributs,NomPopUp)
{
	var sepAttributs = ",";
	var leftOrTop = false;

	// Attributs par defaut de la fenêtre
	var alwaysRaised = "yes";
	var resizable = "yes";
	var directory = "no";
	var location = "no";
	var menubar = "no";
	var personalbar = "no";
	var status = "no";
	var toolbar = "no";
	var height = 600;
	var width = 800;
	var scrollbars = "yes";
		
	var left = 0;
	var top = 0;
	
	// On regarde si des attributs ont été spécifiés
	// si oui, on remplace les valeurs par défaut
	var tabAttributs = new Array();
	var tabCouple = new Array();
	tabAttributs = attributs.split(sepAttributs);
	
	for (var i=0 ; i < tabAttributs.length ; i++)
	{
		// element du tableau => "cle=valeur"
		tabCouple = tabAttributs[i].split("=");
		
		if (tabCouple.length == 2)
		{
			if (tabCouple[0] == "alwaysRaised") 
				alwaysRaised = tabCouple[1];
			else if (tabCouple[0] == "personalbar") 
				personalbar = tabCouple[1];
			else if (tabCouple[0] == "scrollbars") 
				scrollbars = tabCouple[1];
			else if (tabCouple[0] == "resizable") 
				resizable = tabCouple[1];
			else if (tabCouple[0] == "directory") 
				scrollbars = tabCouple[1];
			else if (tabCouple[0] == "menubar") 
				menubar = tabCouple[1];
			else if (tabCouple[0] == "location") 
				location = tabCouple[1];
			else if (tabCouple[0] == "width") 
			{
				if (tabCouple[1] == "max")
				{
					width = window.screen.width - 50 ;
					razTopLeft = true;
				}
				else
					width = tabCouple[1];
			}
			else if (tabCouple[0] == "height") 
            {
				if (tabCouple[1] == "max")
					height = window.screen.height - 50 ;
				else
					height = tabCouple[1];
            }
			else if (tabCouple[0] == "toolbar") 
				toolbar = tabCouple[1];																								
			else if (tabCouple[0] == "status") 
				status = tabCouple[1];																								
			else if (tabCouple[0] == "left") 
			{					
				left = tabCouple[1];																								
				leftOrTop = true;
			}
			else if (tabCouple[0] == "top") 
			{
				top = tabCouple[1];																								
				leftOrTop = true;
			}
		}
	}

	if (!leftOrTop)	
	{
		// Pour le positionnement, par défaut on centre la popup 
		if (window.screen.width >= width) left = (window.screen.width - width) / 2;
		if (window.screen.height >= height) top = (window.screen.height - height) / 2 - 25;
	}
	
	var caracteristiques = "";
	caracteristiques += "alwaysRaised=" + alwaysRaised + sepAttributs;
	caracteristiques += "resizable=" + resizable + sepAttributs;
	caracteristiques += "directory=" + directory + sepAttributs;
	caracteristiques += "location=" + location + sepAttributs;
	caracteristiques += "menubar=" + menubar + sepAttributs;
	caracteristiques += "personalbar=" + personalbar + sepAttributs;
	caracteristiques += "status=" + status + sepAttributs;
	caracteristiques += "toolbar=" + toolbar + sepAttributs;
	caracteristiques += "scrollbars=" + scrollbars + sepAttributs;
	caracteristiques += "height=" + height + sepAttributs;
	caracteristiques += "width=" + width + sepAttributs;
	caracteristiques += "left=" + left + sepAttributs;
	caracteristiques += "top=" + top;
	
	openedWindow = open (URL,NomPopUp,caracteristiques);
}
