/*
	WEB LIB
	Auteur : Vincent DUVERNET
	Société: Nolmë Informatique
	Date de création : 01 / 11 / 2003
	Date de MAJ      : 18 / 10 / 2005

*/

//
// Lib_Version ()
//
// Description : Affiche la version courante de la LIB
//
function Lib_Version ()
{
	alert ('WebLib par Nolmë Informatique - Vincent DUVERNET v1.0');
}

//
// Internet_DisplayHitCounter ()
//
// Description : Affiche le compteur du nombr de visite pour un site donne
//
function Internet_DisplayHitCounter (_oImage, _szName)
{
	_oImage.src = "http://www.bitwise.net/cgi-bin/counter?"+ _szName;
}


//
// Internet_DisplayMail ()
//
// Description : Affiche une adresse mail en évitant les renifleurs de mail des sites web
//
function Internet_DisplayMail (_Document, _szName, _szDomain)
{
	_Document.write('<a href=\"mailto:' + _szName + '@' + _szDomain + '\">');
	_Document.write(_szName + '@' + _szDomain + '</a>'); 
}


//
// Lib_TakeYear ()
//
// Description : 
//
function Lib_TakeYear (_theDate)
{
	x = _theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}


//
// Lib_LastModified ()
//
// Description : Affiche la dernière date de modification du document
//
function Lib_LastModified (_Document, _szCaption, _bDisplayDay)
{
	var x = new Date (_Document.lastModified);
	Modif = new Date(x.toGMTString());
	Year = Lib_TakeYear (Modif);
	Month = Modif.getMonth();
	Day = Modif.getDate();
	Mod = (Date.UTC(Year,Month,Day,0,0,0))/86400000;
	x = new Date();
	today = new Date(x.toGMTString());
	Year2 = Lib_TakeYear (today);
	Month2 = today.getMonth();
	Day2 = today.getDate();
	now = (Date.UTC(Year2,Month2,Day2,0,0,0))/86400000;
	daysago = now - Mod;
	if (daysago < 0)
		return '';
	unit = 'jours';
	if (daysago > 730)
	{
		daysago = Math.floor(daysago/365);
		unit = 'années';
	}
	else if (daysago > 60)
	{
		daysago = Math.floor(daysago/30);
		unit = 'mois';
	}
	else if (daysago > 14)
	{
		daysago = Math.floor(daysago/7);
		unit = 'semaines';
	}

	var towrite;
	if (daysago == 0)
	{
		towrite = 'aujourd\'hui';
	}
	else if (daysago == 1)
	{
		towrite = 'hier';
	}
	else
	{
		towrite = daysago + ' ' + unit;
	}

	_Document.write(_szCaption);
	_Document.write("<B><I>" + towrite + "</I></B>");
	_Document.write("<P>");
}


//
// Lib_CurrentDay ()
//
// Description : Affiche la dernière date de modification du document
// Paramètres  : 
//     _Document    : document destination
//     _szCaption   : Titre ou texte à placer avant
//     _bDispleyDay : Affiche le jour de la semaine
// Utilisation : Lib_CurrentDay(document, "Le :", 1)
//
function Lib_CurrentDay (_Document, _szCaption, _bDisplayDay)
{
	var aszDays   = new Array ("Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche");
	var aszMonths = new Array ("janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre");
	var aMaj = new Date;

	_Document.write(_szCaption);
	if (_bDisplayDay != 0)
	{
		_Document.write(aszDays[aMaj.getDay()]);
	}
	_Document.write(" " + aMaj.getDate() + " " + aszMonths[aMaj.getMonth()] + " " + aMaj.getFullYear() + "<P>");
}


//
// InternetBrowser_GetName ()
//
// Description : Retourne le nom du navigateur Internet
//
function InternetBrowser_GetName ()
{
	var szAgent = navigator.userAgent.toLowerCase();
	var szBrowser;

	if ((a = szAgent.indexOf("opera")) != -1)
	{
		szBrowser = "Opera";
	}
	else if ((a = szAgent.indexOf("msie")) != -1)
	{
		szBrowser = "Microsoft Internet Explorer";
	}
	else 
	{
		szBrowser = "Netscape Navigator";
	}
	return szBrowser;
}


//
// InternetBrowser_GetLanguage ()
//
// Description : Affiche la langue du navigateur Internet
//
function InternetBrowser_GetLanguage ()
{
	var szAgent = navigator.userAgent.toLowerCase();
	var szLanguage;

	if ((a = szAgent.indexOf("opera")) != -1)
	{
		szLanguage = navigator.language;
	}
	else if ((a = szAgent.indexOf("msie")) != -1)
	{
		szLanguage = navigator.systemLanguage;
	}
	else 
	{
		szLanguage = navigator.language;
	}
	return szLanguage;
}


//
// InternetBrowser_GetVersion ()
//
// Description : Affiche la version du navigateur Internet
//
function InternetBrowser_GetVersion ()
{
	var szAgent   = navigator.userAgent.toLowerCase();
	var szVersion = navigator.appVersion.substr(0,3);

	if ((a = szAgent.indexOf("opera")) != -1)
	{
		szVersion += szAgent.substr(a + 6, 4);
	}
	else if ((a = szAgent.indexOf("msie")) != -1)
	{
		szVersion = szAgent.substr(a + 5, 3);
	}
	else 
	{
		if ((a = szAgent.indexOf("gecko")) != -1)
		{
			szVersion += szAgent.substr(-3, 3);
		}
	}
	return szVersion;
}



//
// InternetBrowser_GetIP ()
//
// Description : Retourne l'IP du visiteur
//
function InternetBrowser_GetIP ()
{
VIH_BackColor = "palegreen";
VIH_ForeColor = "navy";
VIH_FontPix = "16";
VIH_DisplayFormat = "You are visiting from:<br>IP Address: %%IP%%<br>Host: %%HOST%%";
	var szBrowser =  VIH_DisplayFormat;

	return szBrowser;
}



//
// IE_CorrectPNG ()
//
// Description : Corrige la gestion des fichiers PNG sous Internet Explorer
// Utilisation : <script language="JavaScript">window.attachEvent("onload", correctPNG);</script>
//
function IE_CorrectPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
{
	if (!window.opera)
	{
		for(var i=0; i<document.images.length; i++)
		{
			var img = document.images[i]
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			{
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
					+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
					+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
					+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				img.outerHTML = strNewHTML
				i = i-1
		     	}
		}
	}
}
