// -----------------------------------------------------------------------------
// Détection du Navigateur, Version Nav., Système d'exploitation
// Ex.: <script type="text/javascript">document.write('Votre navigateur est ' + BrowserDetect.browser + ' ' + BrowserDetect.version + ' sur ' + BrowserDetect.OS + '.');</script>
// -----------------------------------------------------------------------------
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{	// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 	// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

BrowserDetect.init();


// -----------------------------------------------------------------------------
// Sélection du CSS si MSIE ou default
// -----------------------------------------------------------------------------
document.write ('<link href="/inc/default.css" rel="stylesheet" type="text/css" />');
//document.write ('<link href="/inc/print.css" media="print" rel="stylesheet" type="text/css" />');

if (BrowserDetect.browser == "Explorer")
{
	document.write ('<style>');
	/*
	document.write ('div#item_photo {');
	document.write ('left: expression( ( 100 + ( ignoreMe2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) ) + "px" );');
	document.write ('top: expression( ( 0 + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + "px" );');
	document.write ('}');
	*/
	//alert(document.documentElement.scrollWidth - (460 + 10 + 15));
	/*
	document.write ('div#item_thn {');
	document.write ('width: expression( (0 + document.documentElement.scrollWidth)+"px" );');
	document.write ('}');
	*/
	document.write ('div#item_content {');
	document.write ('height: expression( (document.documentElement.scrollHeight - 100)+"px" );');
	document.write ('}');
	
	document.write ('</style>');
	
	document.write ('<link href="/inc/ie.css" rel="stylesheet" type="text/css" />');
}

if (window.location == top.location)
{
	document.write ('<style>');
	document.write ('html {overflow-y: scroll !important;}');
	document.write ('</style>');
}


// -----------------------------------------------------------------------------
// Ouverture du menu
// -----------------------------------------------------------------------------
document.onLoad = AutoOpen();

function AutoOpen() {
	showmenu();
	setTimeout("showmenu('smenu2')", 1000);
}

function showmenu(id) {
	var d = document.getElementById(id);
	
	for (var i = 1; i<=15; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
	
	if (d) {
		d.style.display='block';
	}
	
	showsmenu();
}

function showsmenu(id) {
	var d = document.getElementById(id);
	
	for (var i = 1; i<=15; i++) {
		if (document.getElementById('ssmenu'+i)) {document.getElementById('ssmenu'+i).style.display='none';}
	}
	
	if (d) {
		d.style.display='block';
	}
}


// -----------------------------------------------------------------------------
// Permet de désactiver le menu contextuel sur la page internet
// -----------------------------------------------------------------------------
//document.oncontextmenu = function(){return false}

function setMouseOverLink(sMsg)
{
	window.status = sMsg;
	window.defaultStatus = sMsg;
	
	function mOver()
	{
		window.status = sMsg;
		return true;
	}
	
	function mBlur()
	{
		this.blur();
		return true;
	}
	
	for (var i = 0; i < document.links.length; i++)
	{
		document.links[i].onmouseover = mOver;
		document.links[i].onmouseout = mOver;
		document.links[i].onfocus = mBlur;
	}
}

// -----------------------------------------------------------------------------
// Switch Photos
// -----------------------------------------------------------------------------
function SwitchPhoto(ElName, PhotoAdr)
{
	if (BrowserDetect.browser == "Explorer")
		document.getElementById(ElName).src = PhotoAdr;
	else
		document.images[ElName].src = PhotoAdr;
}


// -----------------------------------------------------------------------------
// Confirmation avant d'éffectuer une action
// -----------------------------------------------------------------------------
function ConfirmLink()
{
	if (!confirm('Etes-vous sur de vouloir continuer cette action ?')) return false;
}


// -----------------------------------------------------------------------------
// Elimine les espace avant et apres une phrase
// -----------------------------------------------------------------------------
function trim(str)
{
	while (str.substring(0,1) == ' ')
		str = str.substring(1, str.length);
	
	while (str.substring(str.length-1, str.length) == ' ')
		str = str.substring(0, str.length-1);
	
	return str;
}

// -----------------------------------------------------------------------------
// Vérification si c'est bien une adresse mail valide
// -----------------------------------------------------------------------------
function checkmail(name)
{
	var stremail = name;
	var strinValid = / (&)|(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|[*'"]/;
	var strVaild = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	
	if (!strinValid.test(stremail) && strVaild.test(stremail))
		return true;
	else
		return false;
}

// -----------------------------------------------------------------------------
// Vérifie si c'est bien une date valide
// -----------------------------------------------------------------------------
function isDate(DateToCheck)
{
	if (DateToCheck == "")
		return true;
	
	var m_strDate = FormatDate(DateToCheck);
	
	if (m_strDate=="")
		return false;
	
	var m_arrDate = m_strDate.split("/");
	var m_DAY = m_arrDate[0];
	var m_MONTH = m_arrDate[1];
	var m_YEAR = m_arrDate[2];
	
	if (m_YEAR.length > 4)
		return false;
	
	m_strDate = m_MONTH + "/" + m_DAY + "/" + m_YEAR;
	var testDate = new Date(m_strDate);
	
	if (testDate.getMonth()+1==m_MONTH)
		return true;
	else
		return false;
}


// -----------------------------------------------------------------------------
// Formate la date
// -----------------------------------------------------------------------------
function FormatDate (DateToFormat, FormatAs)
{
	if (DateToFormat=="")
		return"";
	
	if (!FormatAs)
		FormatAs="dd/mm/yyyy";
	
	var strReturnDate;
	FormatAs = FormatAs.toLowerCase();
	DateToFormat = DateToFormat.toLowerCase();
	var arrDate
	var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	var strMONTH;
	var Separator;
	
	while (DateToFormat.indexOf("st")>-1)	DateToFormat = DateToFormat.replace("st","");
	while (DateToFormat.indexOf("nd")>-1)	DateToFormat = DateToFormat.replace("nd","");
	while (DateToFormat.indexOf("rd")>-1)	DateToFormat = DateToFormat.replace("rd","");
	while (DateToFormat.indexOf("th")>-1)	DateToFormat = DateToFormat.replace("th","");
	
	if (DateToFormat.indexOf(".")>-1)		Separator = ".";
	if (DateToFormat.indexOf("-")>-1)		Separator = "-";
	if (DateToFormat.indexOf("/")>-1)		Separator = "/";
	if (DateToFormat.indexOf(" ")>-1)		Separator = " ";
	
	arrDate = DateToFormat.split(Separator);
	DateToFormat = "";
	
	for (var iSD = 0;iSD < arrDate.length;iSD++)
	{
		if (arrDate[iSD]!="")				DateToFormat += arrDate[iSD] + Separator;
	}
	
	DateToFormat = DateToFormat.substring(0,DateToFormat.length-1);
	arrDate = DateToFormat.split(Separator);
	
	if (arrDate.length < 3)					return "";
	
	var DAY = arrDate[0];
	var MONTH = arrDate[1];
	var YEAR = arrDate[2];
	
	if (parseFloat(arrDate[1]) > 12)
	{
		DAY = arrDate[1];
		MONTH = arrDate[0];
	}
	
	if (parseFloat(DAY) && DAY.toString().length==4)
	{
		YEAR = arrDate[0];
		DAY = arrDate[2];
		MONTH = arrDate[1];
	}
	
	for (var iSD = 0;iSD < arrMonths.length;iSD++)
	{
		var ShortMonth = arrMonths[iSD].substring(0,3).toLowerCase();
		var MonthPosition = DateToFormat.indexOf(ShortMonth);
		
		if (MonthPosition > -1)
		{
			MONTH = iSD + 1;
			
			if (MonthPosition == 0)
			{
				DAY = arrDate[1];
				YEAR = arrDate[2];
			}
			
			break;
		}
	}
	
	var strTemp = YEAR.toString();
	
	if (strTemp.length==2)
	{
		if (parseFloat(YEAR)>40)			YEAR = "19" + YEAR;
		else								YEAR = "20" + YEAR;
	}
	
	if (parseInt(MONTH)< 10 && MONTH.toString().length < 2)		MONTH = "0" + MONTH;
	if (parseInt(DAY)< 10 && DAY.toString().length < 2)			DAY = "0" + DAY;
	
	switch (FormatAs)
	{
		case "dd/mm/yyyy":
			return DAY + "/" + MONTH + "/" + YEAR;
		
		case "mm/dd/yyyy":
			return MONTH + "/" + DAY + "/" + YEAR;
		
		case "dd/mmm/yyyy":
			return DAY + " " + arrMonths[MONTH -1].substring(0,3) + " " + YEAR;
		
		case "mmm/dd/yyyy":
			return arrMonths[MONTH -1].substring(0,3) + " " + DAY + " " + YEAR;
		
		case "dd/mmmm/yyyy":
			return DAY + " " + arrMonths[MONTH -1] + " " + YEAR;
		
		case "mmmm/dd/yyyy":
			return arrMonths[MONTH -1] + " " + DAY + " " + YEAR;
		
	}
	
	return DAY + "/" + strMONTH + "/" + YEAR;
}

function IsNumeric (sText)
{
	//var ValidChars = "0123456789.";
	var ValidChars = "0123456789";
	var IsNumber = true;
	var Char;
	
	for (i=0; i<sText.length && IsNumber==true; i++)
	{
		Char = sText.charAt(i);
		
		if (ValidChars.indexOf(Char) == -1)
			IsNumber = false;
	}
	
	return IsNumber;
}


// -----------------------------------------------------------------------------
// vérification de formulaire
// -----------------------------------------------------------------------------
function VerifForm (FormName)
{
	var f = document.forms[FormName].elements;	// nom du formulaire
	var block = false;							// retourner 'true' ou 'false'
	
	for (var i=0; i < f.length; i++)			// boucle pour trouver les elements obligatoires
	{
		var elem = f[i];						// element
		
		elem.value = trim(elem.value);			// nettoyage des espaces de debut et de fin
		
		switch (elem.lang)						// Is required
		{
			case "1" :							// si est un 'STRING'
				if (elem.value == "")
					block = true;
				break;
			
			case "2" :							// si est une adresse mail
				if (elem.value != "")
				{
					if (!checkmail(elem.value))
						block = true;
				}
				else
					block = true;
				break;
			
			case "3" :							// si est un 'PASSWORD'
				var illegalChars = /[\W_]/;		// allow only letters and numbers
				if (elem.value.length < 4 || illegalChars.test(elem.value))
					block = true;
				break;
			
			case "4" :							// si est un 'USERNAME'
				var illegalChars = /\W/;		// allow only letters, numbers, and underscores
				
				if (illegalChars.test(elem.value))
					block = true;
				
				if (elem.value == "")
					block = true;
				break;
			
			case "5" :							// si est un 'DATE'
				if (!isDate(elem.value))
					block = true;
				break;
			
			case "6" :							// si est un 'DATE'
				if (!IsNumeric(elem.value))
					block = true;
				break;
			
			/*case "6" :							// si est une 'application/zip, ...'
				
				break;*/
			
		}
		
		if (block == true)						// bloquage de l'envoi du formulaire
		{
			//alert("Attention, tous les champs de ce formulaire ne sont pas conformes, veuillez corriger les champs éronés.");
			alert("Attention, le champ intitule ' " + elem.alt + " ' de ce formulaire n'est pas conforme, veuillez corriger/completer ce champs erones.");
			elem.focus();
			elem.select();
			//return;
			return false;
		}
	}
	
	return true;
	//document.forms[FormName].submit();
}

///////////////////////////////////////////////////////////
// POP UP - START
///////////////////////////////////////////////////////////

// Set the horizontal and vertical position for the popup
PositionX = 100;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)
defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows
var AutoClose = true;

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
function popImage(imageURL,imageTitle){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,300);');
writeln('width=300-(document.body.clientWidth-document.images[0].width);');
writeln('height=300-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onLoad="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="George" src='+imageURL+' style="display:block" onClick="self.close()"></body></html>');
close();		
}}

///////////////////////////////////////////////////////////
// POP UP - END
///////////////////////////////////////////////////////////
