// Bibliothèque de scripts - 
var arrImg = new Array();

//****************************************************************
// Affichage des sous-menus 
//****************************************************************

sfHover = function() {
	if (document.getElementById('menu'))
		{
			var sfEls = document.getElementById('menu').getElementsByTagName("LI");
			for (var i=0; i<sfEls.length; i++) {
				sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


//****************************************************************
// Fonction d'import des animations Flash 
//****************************************************************

function RunFlash(swf, hauteur, largeur, nom) {
	document.write("<object width=\""+largeur+"\" height=\""+hauteur+"\" id=\""+nom+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\">\n");
	document.write("<param name=\"quality\" value=\"high\">\n");
	document.write("<param name=\"wmode\" value=\"transparent\">\n");
	document.write("<param name=\"movie\" value=\""+swf+"\">\n");
	document.write("<embed src=\""+swf+"\" quality=\"high\" wmode=\"transparent\" width=\""+largeur+"\" height=\""+hauteur+"\" name=\""+nom+"\" align=\"middle\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\">\n");
	document.write("</object>\n");
}


//****************************************************************
// Affichage des POPUP 
//****************************************************************

function funcPopup(varUrl, varWidth, varHeight, varResize) {
	var ScreenW = screen.availWidth;
	var ScreenH = screen.availHeight;
	var WinPopUp = window.open(varUrl, 'popup', "toolbar=no, menubar=no, scrollbars=yes, resizable=" + varResize + ", location=no, directories=no, status=no, width=" + varWidth + ", height=" + varHeight);
	WinPopUp.moveTo(Math.round((ScreenW-varWidth)/2), Math.round((ScreenH-varHeight)/2));	
	WinPopUp.focus();
}


//****************************************************************
// Ajouter aux favoris 
//****************************************************************

function addToFavorites(anchor) {
	var urlAddress = "http://www.chasseur-d-antan.com/";
	var pageName = "www.chasseur-d-antan.com";
	if (window.external)
	{
		window.external.AddFavorite(anchor.getAttribute('href'), anchor.getAttribute('title'));
	}
}


//-------------------------------------------------------------------------------
//	Fonction de redimensionnement des images
//-------------------------------------------------------------------------------
function funcRedimImg(varImg, varWidth, varHeight)
	{
	var oldWidth = varImg.width;
	var oldHeight = varImg.height;
	arrImg[varImg.alt] = varImg.width + 'X' + varImg.height;
//	alert(varImg.alt + ' - ' + arrImg[varImg.alt]);
//	alert(varImg.width + ' X ' + varImg.height);

	var newWidth = oldWidth;
	var newHeight = oldHeight;
	if (varImg.width > varWidth)
		{
		newWidth = varWidth;
		newHeight = Math.round((varWidth/oldWidth) * oldHeight);
		varImg.width = newWidth;
		varImg.height = newHeight;
		oldWidth = newWidth;
		oldHeight = newHeight;
		}
	if (newHeight > varHeight)
		{
		newHeight = varHeight;
		newWidth = Math.round((varHeight/oldHeight) * newWidth);
		varImg.width = newWidth;
		varImg.height = newHeight;
		}
	}


//-------------------------------------------------------------------------------
// Fonction de suppression d'une image
//-------------------------------------------------------------------------------
function funcImgDelete(varImg, varImgNoFile)
	{
	varImg.outerHTML = '<img id="' + varImg.id + '" title="Photo" src="' + varImgNoFile + '" onLoad="funcRedimImg(this,200,200);">';
	}


//-------------------------------------------------------------------------------
//	Fonction de suppression d'une image en base
//-------------------------------------------------------------------------------
function funcImgDelToDb(varTable, varSelectField, varSelectValue, varFileField, varBlnMsg, varReload)
	{
//	alert('ok');
	var	strMessage = "<h4><center><font color=#FF0000>La suppression de l'image est en cours</font></center></h4>"
					+'<div align="center"><img src="../images/progression.gif"></div><br><br>';
	var strHtmlCode = 	 "<html>"
 						+"<body leftmargin=3 topmargin=3 marginwidth=3 marginheight=3 onBlur='focus();'>"
						+"<div align='left'><font color='#000000' style='font-family:Verdana, sans-serif;font-size:11;'>" + strMessage + "&nbsp;&nbsp;</font></div>"
						+ "</div>"
						+"</body></html>";
	WinPopupImgDel = window.open ("../_inc/funcImgUpload.asp?strAction=delete&strTable=" + varTable + "&strSelectField=" + varSelectField + "&strSelectValue=" + varSelectValue + "&strFileField=" + varFileField, "popupImgDel", "height=800, width=450, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, center=yes, directories=no, status=no, modal=1");
	}

function funcImgChange(varImg, varSrc)
	{
//	alert('varScr : ' + varSrc);
//	alert('varImg : ' + varImg.id);
	varImg.outerHTML = '<img alt="' + varImg.alt + '" id="' + varImg.id + '" title="Photo" src="' + rewriteLocalURL(varSrc) + '" onLoad="funcRedimImg(this,200,200);">';
//	varImg.src = varSrc;
//	funcRedimImg(varImg,112,75);	
	}
	


function rewriteLocalURL(url) { 
	var uri = url; 
	var spaceMatch = / /gi; 
	var slashMatch = /\\/gi;
//alert(url);

	// identify Windows-Scheme 
	if ((uri.charAt(1) == ':') && (uri.charAt(2) == '\\'))
		{ 
		uri = 'file:///' + uri.replace(slashMatch, "/");
		uri = uri.replace(spaceMatch, "%20"); 
		} 
	// identify Linux-Scheme 
	else if (uri.charAt(0) == '/')
		{ 
		uri = 'file:///' + uri; 
		}
	else
		{ 
		uri = 'file:///' + uri.replace(slashMatch, "/");
		uri = uri.replace(spaceMatch, "%20"); 
		} 

	//alert('uri : ' + uri);
	return uri; 
   } 



function funcCtlTailleImg(varForm)
	{
	var fso, fichier, k, strMessage, cptImg, imgWidth, imgHeight, strImg;
	blnImg = false;
	blnBigImg = false;
	cptImg = 0;
	strImg = '';
	strMessage = "<h4><center><font color=#FF0000>L'enregistrement est en cours</font></center></h4>"
				+'<div align="center"><img src="../images/progression.gif"></div><br><br>';



	for (k=0;k<document.getElementById(varForm).length;k++)
		if (document.getElementById(varForm)[k].getAttribute('type') == 'file')
			if (document.getElementById(varForm)[k].value != '')
				{
				cptImg = cptImg + 1;
				strImg = strImg + "&nbsp;&nbsp;Photo n° " + cptImg + " : " + arrImg[cptImg].substring(0, arrImg[cptImg].indexOf('X')) + " x " + arrImg[cptImg].substring(arrImg[cptImg].indexOf('X')+1,arrImg[cptImg].length) + " pixels<br>";
				}

	if (cptImg > 0)
		strMessage = strMessage + "Vos photos vont être automatiquement redimensionnées à la taille 640 x 480 pixels.<br><br>"
								+ "<b><font color=#FF0000>Le transfert des photos peut durer quelques minutes, merci de patienter.</font></b><br><br>"
								+ "Analyse des fichiers images envoyés :<br>"
								+ "<b>" + strImg + "</b><br><br>";

	strMessage = strMessage + "<p align=center><font style=font-size:9;>En cas de problème d'enregistrement, veuillez nous contacter.</font></p>";
	
	var strHtmlCode = 	 "<html>"
						+"<body leftmargin=3 topmargin=3 marginwidth=3 marginheight=3 onBlur='focus();'>"
						+"<div align='left'><font color='#000000' style='font-family:Verdana, sans-serif;font-size:11;'>" + strMessage + "&nbsp;&nbsp;</font></div>"
						+ "</div>"
						+"</body></html>";
	/*WinPopupEnreg = window.open ("", "PopUpEnreg", "height=300, width=450, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, center=yes, directories=no, status=no");
	WinPopupEnreg.document.write(strHtmlCode);
	WinPopupEnreg.document.close();

	WinPopupEnreg.moveTo(Math.round((screen.width-450)/2), Math.round((screen.height-300)/2));*/
	document.getElementById(varForm).submit();
	}



/*
	Coche / Decoche toutes un ensemble de cases
	varIdTout : id du checkbox qui permet de tout cocher / decocher
	varNameACocher : name des checkbox à cocher / decocher
*/
function funcCheckAll(varIdTout, varNameACocher) {
	
	var blnChecked;
	
	if (document.getElementById(varIdTout)) {
		
		// si la case est cochée : on coche tout
		if (document.getElementById(varIdTout).checked) {
			blnChecked = true;
		} else {
			blnChecked = false;		
		}
		
		// Coche / decoche toutes les cases à cocher
		var tabElt	= document.getElementsByName(varNameACocher);
		for (i=0; i<tabElt.length; i++) {
			tabElt[i].checked = blnChecked;
		}		
	}	
}


//--- Création de l'objet 'Ajax''
function funcGetXmlHR(){
	var objXmlHR = null;
	// Firefox et autres
	if(window.XMLHttpRequest) {
		objXmlHR = new XMLHttpRequest();
	// Internet Explorer
	} else if(window.ActiveXObject) {
		try {
			objXmlHR = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			objXmlHR = new ActiveXObject("Microsoft.XMLHTTP");
		}
	// XMLHttpRequest non supporté par le navigateur
	} else {
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		objXmlHR = false;
	}
	return objXmlHR;
}