//=============================================================================
// Fonctions globales Javascript
// Copyright 2003 - M-tech Industries
// Version        : 2.1
// Derniere modif : HJ 23/12/03
//=============================================================================


//-----------------------------------------------------------------------------
// Detection navigateur M-tech Industries
//-----------------------------------------------------------------------------

NavName = navigator.appName;
NavVers = navigator.appVersion; 
NavCode = navigator.appCodeName; 
NavAgent  = navigator.userAgent;
NavJSOK = navigator.javaEnabled();
NavRealName = NavName;

// Detection de l'OS
//-----------------------------------------------------------------------------
if (NavVers.indexOf('Mac') > -1) {
	NavOS = "Mac OS";
	if (NavAgent.indexOf('OS X') > -1 || NavAgent.indexOf('OmniWeb') > -1) {
		NavOS = "Mac OS X";
	}
	Win=0;
} else {
	if (NavVers.indexOf('Win') > -1) {
		if (NavAgent.indexOf('NT 5.1') > -1)  NavOS = "Windows XP";
		else if (NavVers.indexOf('NT 5') > -1)  NavOS = "Windows 2000";
		else if (NavVers.indexOf('NT') > -1)  NavOS = "Windows NT";
		else if (NavVers.indexOf('95') > -1)  NavOS = "Windows 95";
		else if (NavVers.indexOf('98') > -1)  NavOS = "Windows 98";		
		else NavOS = "Windows";
		Win=1;
	} else {
		NavOS = "Inconnu"
		Win=-1;
	}
}

// Detection du vrai nom
//-----------------------------------------------------------------------------
if (NavAgent.indexOf('Opera') > -1) {
	NavRealName="Opera";
} else {
	if (NavAgent.indexOf('OmniWeb') > -1) {
		NavRealName="OmniWeb";
	} else {
		if (NavAgent.indexOf('Safari') > -1) {
			NavRealName="Safari";
		} else {
			if (NavAgent.indexOf('Firefox') > -1) {
				NavRealName="Firefox";
			//} else {
			}
		}
	}
}


// Detection du nro de version
//-----------------------------------------------------------------------------
NavVersNum=NavVers.substr(0, 3);
if (NavAgent.indexOf('MSIE') > -1) {
	NavVersNum=NavAgent.substr(NavAgent.indexOf('MSIE')+5, 3);
}
if (NavAgent.indexOf('Opera') > -1) {
	NavVersNum=NavAgent.substr(NavAgent.indexOf('Opera')+6, 3);
}
if (NavAgent.indexOf('OmniWeb') > -1) {
	NavVersNum=NavAgent.substr(NavAgent.indexOf('OmniWeb')+8, 3);
}
if (NavAgent.indexOf('Netscape6') > -1) {
	NavVersNum=NavAgent.substr(NavAgent.indexOf('Netscape6')+10, 3);
}


if (NavName == 'Netscape')
	var IE = 0;
else
	var IE = 1;

var IE4 = (document.all && !document.getElementById) ? true : false;
var NS4 = (document.layers) ? true : false;
var IE5 = (document.all && document.getElementById) ? true : false;
var NS6 = (document.getElementById && !document.all) ? true : false;

// Detection de la langue
//-----------------------------------------------------------------------------
if (IE4 || IE5)
	var NavLang =  navigator.browserLanguage;
else
	var NavLang = navigator.language;

if (NavLang.indexOf('fr') > -1) NavLangFR = 'Fran&ccedil;ais';
else if (NavLang.indexOf('nl') > -1) NavLangFR = 'Neerlandais';
else if (NavLang.indexOf('en') > -1) NavLangFR = 'Anglais';
else if (NavLang.indexOf('de') > -1) NavLangFR = 'Allemand';
else if (NavLang.indexOf('ja') > -1) NavLangFR = 'Japonais';
else if (NavLang.indexOf('it') > -1) NavLangFR = 'Italien';
else if (NavLang.indexOf('pt') > -1) NavLangFR = 'Portugais';
else if (NavLang.indexOf('es') > -1) NavLangFR = 'Espagnol';
else if (NavLang.indexOf('sv') > -1) NavLangFR = 'Suedois';
else if (NavLang.indexOf('zh') > -1) NavLangFR = 'Chinois';
// Pour rediriger selon la langue :
//if (NavLang.indexOf('zh') > -1) document.location.href = NavLangFR +'.html';

//Ici la page par defaut si la langue n'est pas dans la liste 
else 
NavLangFR = 'Inconnu...';


// Affichage des infos
//-----------------------------------------------------------------------------
function AlertNavInfos() {
	alert("Navigateur : " + NavName + "\nVersion : " + NavVers + "\nNro : " + NavVersNum + "\nCode : " + NavCode + "\nAgent : " + NavAgent  + "\nOS : " + NavOS +  "\nLangue : " + NavLang + "\nIE4, IE5, NS4, NS6 : " + IE4 + "," + IE5 + ","  + NS4 + "," + NS6 );
}

function DisplayNavInfos() {
	document.write("Nom du navigateur : <B>" + NavRealName + "</b><BR>");
	document.write("Version du navigateur : <B>" + NavVersNum + "</b><BR>");
	document.write("Agent du navigateur : <B>" + NavAgent + "</b><BR>");
	document.write("D&eacute;tails du navigateur : <B>" + NavVers + "</b><BR>");
	document.write("Code du navigateur : <B>" + NavCode + "</b><BR>");
	document.write("Javascript actif : <B>" + NavJSOK + "</b><BR>");
	document.write("OS du navigateur : <B>" + NavOS + "</b><BR>");
	document.write("Type Windows ?   : <B>" + Win + "</b><BR>");
	document.write("Langue du navigateur : <B>" + NavLangFR + "</b><BR>");
}



//-----------------------------------------------------------------------------
// Gestion de fenetres
//-----------------------------------------------------------------------------


function LanceSite() {
	//alert(document.URL + "\n" + document.SitesForm.listeSites.value);
	//document.URL=document.SitesForm.listeSites.value;
	window.location=document.FormEdit.listeData.value
	return false;
}


function newWindow(wUrl,wName,wParams) {
//* url, name, width, height, resizable, scrollbars, menubar, toolbar, directories, location, status
	//url='calend.asp?champ='+field;
	//alert(wName);
	if (wName == "") {
		wName="theWin";
	}
	if (wParams == "") {
		wParams="width=300,height=200,resizable=no,scrollbars=no,menubar=no,toolbar=no,directories=no,location=no,status=no";
	}
	theWindow=window.open(wUrl,wName,wParams);
	theWindow.focus();
}


function remLink() {
  if (window.theWindow && window.theWindow.open && !window.theWindow.closed)
    window.theWindow.opener = null;
}


// Impression de la fenetre
function PrintWindow() {
    if (window.print) {
        if (confirm("Imprimer cette page ?")) {
            window.print();
        }
    } else {
		alert("Utilisez l'article 'Imprimer...' du menu 'Fichier' de " + NavName + ".\n" + NavName + " " + NavVersNum + " (" + NavOS + ") ne supporte pas la fonction 'window.print()'");
    }
}

// Positionnement de la fenetre a l'ecran
// http://www.xs4all.nl/~ppk/js/winprop.html
// !!! Chgt de parametres le 27/09/02 par HJ
function LocateWindow(theMode,alignX,alignY,deltaX,deltaY) {
// theMode : S(creen) ou P(arent)
// alignX : G(auche), M(ilieu) ou D(roite)
// alignY : H(aut), M(ilieu) ou B(as)

// Recup taille zone interieur fenetre :
	if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}
	else return;
	
// Recup taille fenetre parente :
	if (self.innerWidth)
	{
		parentWidth = window.opener.self.innerWidth;
		parentHeight = window.opener.self.innerHeight;
	}
	else if (document.body)
	{
		parentWidth = window.opener.document.body.clientWidth;
		parentHeight = window.opener.document.body.clientHeight;
	}
	else return;

// Recup position fenetre parente :
		if (self.innerWidth) {
			parentX = window.opener.self.screenX;
			parentY = window.opener.self.screenY;
		} else if (window.screenTop) { // document.body
			parentX = window.opener.screenLeft;
			parentY = window.opener.screenTop;
			} else {
				parentX = 0;
				parentY = 0;
			}

//alert(frameWidth + " x " + frameHeight + "\n" + parentWidth + " x " + parentHeight + "\n" + parentX + "," + parentY);

switch (alignX) {
	case "G" :
		if (theMode == "S") {
			posX=deltaX;
		} else {
		posX=parentX+deltaX;
		}
		break;
	case "D" :
		if (theMode == "S") {
			posX=self.screen.width-deltaX-frameWidth;
		} else {
			posX=(parentX+parentWidth)-deltaX-frameWidth;
		}
		break;
	default :
		if (theMode == "S") {
			posX=(self.screen.width-frameWidth)/2+deltaX;
		} else {
			posX=parentX+(parentWidth-frameWidth)/2+deltaX;
		}
		// Autres cas
}

switch (alignY) {
	case "H" :
		if (theMode == "S") {
			posY=deltaY;
		} else {
		posY=parentY+deltaY;
		}
		break;
	case "B" :
		if (theMode == "S") {
			posY=self.screen.height-deltaY-frameHeight;
		} else {
			posY=(parentY+parentHeight)-deltaY-frameHeight;
		}
		break;
	default :
		if (theMode == "S") {
			posY=(self.screen.height-frameHeight)/2+deltaY;
		} else {
			posY=parentY+(parentHeight-frameHeight)/2+deltaY;
			//alert("posY : P " + posY);
		}
		// Autres cas
}
	
	if ((posX+frameWidth)>self.screen.width) {
		posX=self.screen.width-frameWidth;
	}
	if ((posY+frameHeight)>self.screen.height) {
		posY=self.screen.height-frameHeight;
	}
		parent.window.moveTo(posX,posY);

}


//-----------------------------------------------------------------------------
// Gestion des images
//-----------------------------------------------------------------------------


// Cree ou met a jour une image en adaptant la taille
function ChangePict(thePict, theWidth, theHeight, theName, theOptions, theMode) {
// theMode : 0 = creation (document.write) 1 = update (document.src)
// ViewWidth : Largeur maxi d'affichage en pixels (0 sinon). Var globale.
// ViewHeight : Hauteur maxi d'affichage en pixels (0 sinon). Var globale.

	if (theName=="")  { theName="thePictName"; }

	if (ViewWidth>0 && theWidth>ViewWidth) {
		dispWidth=ViewWidth
		dispHeight=Math.round(ViewWidth*theHeight/theWidth)
	} else {
		dispWidth=theWidth
		dispHeight=theHeight	
	}
	if (ViewHeight>0  && theHeight>ViewHeight)  {
		dispWidth=Math.round(dispWidth*ViewHeight/dispHeight)
		dispHeight=ViewHeight			
	}
	
	if (theMode) {
		document.images[theName].src=thePict;
		document.images[theName].width=dispWidth;
		document.images[theName].height=dispHeight;
	} else {
		document.write("<img height=" + dispHeight + " width=" + dispWidth + " ")	
		document.write("src='" + thePict + "' " )
		document.write("name='" + theName + "' " + theOptions + ">")
	}
}


function DelPict(theImgObj,theField,theNoPictSrc) {
	//document.elements[theImgObj].src ?
	if (theImgObj.src.indexOf('common/nopict.gif') < 1) {
		if (validerSuppr(1)==true) { // Necessite Checkdata_lib.js !
			theImgObj.src=theNoPictSrc; //[HJ 19/11/04]'common/nopict.gif';
			theImgObj.border=0;
			theImgObj.width=100;
			//alert(document.thePict.height);
			theImgObj.height=54;
			tmp=eval("document.FormEdit." + theField);
			tmp.value='';
		}
	} else {
		alert("Rien a supprimer !");
	}
}

function DelFile(theFormField) {
	theFormField.value='';
}


// Ouvre une image en adaptant la taille de la fenetre
function OpenPict(theImgObj,W,H) {
	//theImgObj.src.indexOf('common/nopict.gif') < 1
	if (W==0 || H==0) {
		W=theImgObj.width;
		H=theImgObj.height;
	}
	if (W > 40 && H > 40) {
		if (!IE) {
			W += 15;
			H += 15;
		} else
		{
			W += 5;
			H += 5;
		}
	} else {
		W=540;
		H=360;
	}
	newWindow(theImgObj.src,'wPict','width=' + W + ',height=' + H + ',resizable=yes,scrollbars=no,menubar=no,toolbar=no,directories=no,location=no,status=no');
}


// Interdiction clic droit
function disableClick(e) {
	if (IE4) { // IE
		if (event.button==2||event.button==3) {
			if (event.srcElement.tagName=="IMG"){
				alert(theCopyRight);
				return false; } } }
	else if (NS4) { // NS 4
		if (e.which == 3) {
			alert(theCopyRight);
			return false; } }
	else if (NS6){ // NS 6
		if (e.which==3&&e.target.tagName=="IMG"){
			alert(theCopyRight)
			return false } }
}

function imageEvents() {
	for(i=0;i<document.images.length;i++)
		document.images[i].onmousedown=disableClick; // Event !
}

function noClick() { // Pour declencher, mettre dans BODY onload=noClick()
if (IE4)
	document.onmousedown=disableClick
else if (NS6)
	document.onmouseup=disableClick
else if (NS4)
	imageEvents()
}


//-----------------------------------------------------------------------------
// Gestion de temps de chargement de fichier
//-----------------------------------------------------------------------------
// Utilisation :
//	theSize=5066646;theConn=2;
//	document.write("(" + RoundSize(theSize,1) + " - " + RoundTime(GetDownloadTime(theSize,speedsConn[theConn])) +
//			" par " + namesConn[theConn] + ")");

// Globales
var namesConn=new Array("modem 28.8","modem 33.6","modem 56k","Numeris","ADSL","T1","T3");
var speedsConn=new Array(28800,33600,56000,64000,128000,256000,384000);

function GetDownloadTime(theSize,theSpeed) {	
	return Math.round(theSize/(theSpeed/8)); // Renvoie des s
}

function RoundTime(theTime) { // Temps en s
	if (theTime < 60) {
		theTimeStr=theTime + "&nbsp;s"
		//Date.getSeconds()
	} else {
		if (theTime < 3600) {
			theTimeStr=Math.round((theTime/60) - 0.5) + "&nbsp;mn&nbsp;" + theTime % 60  + "&nbsp;s"
			//Date.getMinutes()
		} else {
			theTimeStr=Math.round((theTime/3600) - 0.5) + "&nbsp;h&nbsp;" + theTime % 3600  + "&nbsp;mn"
			//Date.getHours()
		}
	}
	return theTimeStr;
}

function RoundSize(theSize,thePrec) { // Taille en octets
	thePrec=Math.round(thePrec);
	if (thePrec < 0) { thePrec=0; }
	if (theSize < 1024) {
		theSizeStr=theSize + "&nbsp;octets"
	} else {
		if (theSize < (1024*1024)) {
			theSizeStr=Math.round((theSize/1024)*Math.pow(10,thePrec))/Math.pow(10,thePrec) + "&nbsp;ko"
		} else {
			theSizeStr=Math.round((theSize/1024/1024)*Math.pow(10,thePrec))/Math.pow(10,thePrec) + "&nbsp;Mo"
		}
	}
	return theSizeStr;
}

//-----------------------------------------------------------------------------
// Cookies - HJ 17/09/03
//-----------------------------------------------------------------------------
function CookieSet (name, value) {
	var argv=CookieSet.arguments;
	var argc=CookieSet.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=name+"="+escape(value)+
		((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
		((path==null) ? "" : ("; path="+path))+
		((domain==null) ? "" : ("; domain="+domain))+
		((secure==true) ? "; secure" : "");
}

function CookieGet (name) {
	var arg=name+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen) {
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg)
                       return CookieGetVal (j);
               i=document.cookie.indexOf(" ",i)+1;
                       if (i==0) break;}
	return null;
}

function CookieGetVal(offset) {
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1)
     		endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}



//-----------------------------------------------------------------------------
// Debug
//-----------------------------------------------------------------------------
// Pour debug mettre dans la page:
// var DebugOn=false;
function DisplayDebug(theString) {	
	if ( DebugOn ) alert(theString); }


// Affichage des propriete de l'ecran
function PrintScreenProperties() {

var props = new Array(
	'self.pageXOffset',
	'self.pageYOffset',
	'self.screenX',
	'self.screenY',
	'self.innerHeight',
	'self.innerWidth',
	'self.outerHeight',
	'self.outerWidth',
	'self.screen.height',
	'self.screen.width',
	'self.screen.availHeight',
	'self.screen.availWidth',
	'self.screen.availTop',
	'self.screen.availLeft',
	'self.screen.Top',
	'self.screen.Left',
	'self.screenTop',
	'self.screenLeft',
	'self.screen.colorDepth',
	'self.screen.pixelDepth',
	'document.body.clientHeight',
	'document.body.clientWidth',
	'document.body.scrollHeight',
	'document.body.scrollWidth',
	'document.body.scrollLeft',
	'document.body.scrollTop',
	'document.body.offsetHeight',
	'document.body.offsetWidth',
	'document.body.offsetTop',
	'document.body.offsetLeft');

	for (var i=0;i<props.length;i++)
	{
		if (!self.screen && props[i].indexOf('self.screen') != -1) continue;
		if (!document.body && props[i].indexOf('document.body') != -1) continue;
		if (eval(props[i])) document.write('<BR>' + props[i] + ': ' + eval(props[i]));

	}
}
