
/*********************************************/
/**  Scripts Javascript : scripts généraux  **/
/*********************************************/
/**  David Benkoël - HGT - août 2007        **/
/*********************************************/

function preloadImages()
{
	var d=document;
	if(d.images)
	{
		if(!d.MM_p)
			d.MM_p=new Array();
		var i,j=d.MM_p.length,a=preloadImages.arguments;
		for(i=0; i<a.length; i++)
    	if (a[i].indexOf("#")!=0)
    	{
    		d.MM_p[j]=new Image;
    		d.MM_p[j++].src=a[i];
    	}
  }
}

function swapImage(nomImage,evt)
// evt = "on" ou "off"
{
	choixOnOff = (evt == "on")?"off":"on";
	str = new String(eval("document." + nomImage + ".src"));
	tab1 = str.split(".");
	extension = tab1[tab1.length - 1];
	tab2 = str.split("_" + choixOnOff + "." + extension);
	eval("document." + nomImage + ".src = '" + tab2[0] + "_" + evt + "." + extension + "'");
}


function resizeWindow(largeur,hauteur)
{
	x = (Math.round((screen.availWidth - largeur)/ 2));
 	y = (Math.round((screen.availHeight - hauteur)/ 2));
	self.moveTo(x,y);
	self.resizeTo(largeur,hauteur);
}

function changeOnglet(noOnglet, typeImage, noOngletSel)
// noOnglet : n° de l'onglet sur lequel porte le changement
// typeImage == on, off, sel
// noOngletSel est le n° de l'onglet sélectionné
{
	if (noOnglet != noOngletSel)
	{
		str = new String(eval("document.onglet"+noOnglet+".src"));
  	src = str.substring(0,str.lastIndexOf("_",str.length));
		tab = str.split(".");
		ext = tab[tab.length - 1];
		eval("document.onglet"+noOnglet+".src = '" + src + "_" + typeImage + "." + ext + "'");
	}
}

function mouseOverOutImage(nomImage,choixOnOff)
{
	str = new String(eval("document." + nomImage + ".src"));
	tmp = (choixOnOff == "on")?"off":"on";
	tab = str.split("_" + tmp + ".gif");
	eval("document." + nomImage + ".src = '" + tab[0] + "_" + choixOnOff + ".gif'");
}

function creerItem()
{
	document.location = "index.php?page=" + document.Infos.page.value + "&action=creerItem";
}

function consulterItem()
{
	if (!document.Infos.idItemSelectionne.value)
		alert("Erreur : vous n'avez sélectionné aucun item.");
	else
	{
		document.Infos.action = "index.php?page=" + document.Infos.page.value + "&action=consulterItem";
		document.Infos.submit();
	}
}

function modifierItem()
{
	if (!document.Infos.idItemSelectionne.value)
		alert("Erreur : vous n'avez sélectionné aucun item.");
	else
	{
		document.Infos.action = "index.php?page=" + document.Infos.page.value + "&action=modifierItem";
		document.Infos.submit();
	}
}

function supprimerItem()
{
	if (!document.Infos.idItemSelectionne.value)
		alert("Erreur : vous n'avez sélectionné aucun item.");
	else
		if (confirm("Confirmation : souhaitez-vous vraiment supprimer l'item sélectionné ?"))
		{
			document.Infos.action = "index.php?page=" + document.Infos.page.value + "&action=supprimerItem";
			document.Infos.submit();
		}
}

function repondreMessage()
{
  document.Infos.action = "index.php?page=" + document.Infos.page.value + "&action=repondreMessage";
	document.Infos.submit();
}

function faireSuivreMessage()
{
  document.Infos.action = "index.php?page=" + document.Infos.page.value + "&action=faireSuivreMessage";
	document.Infos.submit();
}

function ouvrePopup(URL, nomPopup, largeurPopup, hauteurPopup)
{
  x = (Math.round((screen.availWidth - largeurPopup)/ 2));
 	y = (Math.round((screen.availHeight - hauteurPopup)/ 2));
	return window.open(URL,nomPopup,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,top="+y+",left="+x+",width=" + largeurPopup + ",height=" + hauteurPopup);
}

