var racineSite = "";

var fenetre;


function FermerFenetres()
{
	if (fenetre != null)
	{
		try
		{
			fenetre.close();
		}
		catch(ex)
		{
		}
	}
}


function OuvrirFenetre(url, name, largeur, hauteur, centrer, options)
{
	lesOptions = "width=" + largeur;
	lesOptions += ", height=" + hauteur;
	
	if (centrer)
	{
		lesOptions += ", left=" + ((screen.availWidth - largeur) / 2);
		lesOptions += ", top=" + ((screen.availHeight - hauteur) / 2);
	}
	else
	{
		lesOptions += ", left=0, top=0";
	}
	
	if (options==null || options=="")
	{
		lesOptions += ", status=no, menu=no, toolbar=no, menubar=no, scrollbars=auto, location=no, resizable=yes";
	}
	else
	{
		lesOptions += ", " + options;
	}
	
	fenetre = window.open(url, name, lesOptions);
	fenetre.focus();
}


function OuvrirFenetreScroll(url, name, largeur, hauteur, centrer)
{
	OuvrirFenetre(url, name, largeur, hauteur, centrer, "status=no, menu=no, toolbar=no, menubar=no, scrollbars=yes, location=no, resizable=yes")
}


function OuvrirFenetreMax(url, name)
{
	var lesOptions = "width=" + (screen.availWidth - 12);
	lesOptions += ", height=" + (screen.availHeight - 30);
	
	lesOptions += ", left=0, top=0";
	
	lesOptions += ", status=no, menu=no, toolbar=no, menubar=no, scrollbars=yes, location=no, resizable=yes";
	
	fenetre = window.open(url, name, lesOptions);
	fenetre.focus();
}


function OuvrirFenetrePleinEcran(url, name)
{
	fenetre = window.open(url, name, "status=no, menu=no, toolbar=no, menubar=no, scrollbars=yes, location=no, resizable=yes, fullscreen=yes");
	fenetre.focus();
}


function RedimensionFenetre(largeurFen, hauteurFen, centrer)
{
	// Dimensions de l'écran
	largeurScr = screen.availWidth;
	hauteurScr = screen.availHeight;
	
	if (centrer)
	{
		// Centre de la fenetre dans l'écran
		posX = ((largeurScr-largeurFen)/2);
		posY = ((hauteurScr-hauteurFen)/2);
		if (posX<0) posX=0;
		if (posY<0) posY=0;
		window.moveTo(posX,posY);
	}
	
	// Redimension de la fenêtre
	if (largeurFen > largeurScr) largeurFen = largeurScr;
	if (hauteurFen > hauteurScr) hauteurFen = hauteurScr;
	window.resizeTo(largeurFen,hauteurFen);
	window.focus();
}


function DetailImage(urlImage)
{
	OuvrirFenetre(racineSite + "/Popup/DetailImage.aspx?urlImage=" + urlImage, "", "400", "300", true, "status=no, menu=no, toolbar=no, menubar=no, scrollbars=yes, location=no, resizable=yes");
}


function DetailImageFichier(numFichier)
{
	OuvrirFenetre(racineSite + "/Popup/DetailImage.aspx?numFichier=" + numFichier, "", "400", "300", true, "status=no, menu=no, toolbar=no, menubar=no, scrollbars=yes, location=no, resizable=yes");
}


function DetailFichier(numFichier)
{
	fenetre = window.open(racineSite + "/Popup/DetailFichier.aspx?numFichier=" + numFichier, "", "");
	fenetre.focus();
}


function FenetreSelectionSite()
{
	OuvrirFenetre(racineSite + "/Recherche/SitePopUp.aspx", "SelectionSite", 490, 185, true, null);
}


function FenetreMediatheque(fonctionRetour, typeFichier)
{
	OuvrirFenetre(racineSite + "/PopUp/Mediatheque/Default.aspx?fonctionRetour=" + fonctionRetour + "&typeFichier=" + typeFichier, "", 750, 500, true, "status=no, menu=no, toolbar=no, menubar=no, scrollbars=yes, location=no, resizable=yes");
}


function Fenetre40000Clochers(numPhoto)
{
	OuvrirFenetre("http://www.40000clochers.com/Photo.asp?NumPhoto=" + numPhoto, "Photo" + numPhoto, "400", "300", true, null);
}


function FenetreBebeRoi(numBebe)
{
	OuvrirFenetre("http://www.beberoi.com/FairePartPopup.asp?nb=" + numBebe, "Bebe" + numBebe, "700", "600", true, null);
}


function SelectionDateCalendrier(fonctionRetour)
{
	OuvrirFenetre(racineSite + "/Popup/Calendrier.aspx?fonctionRetour=" + fonctionRetour, "Calendrier", 230, 230, true, null);
}


function MotDePassePerdu()
{
	OuvrirFenetre(racineSite + "/Popup/EvoiMailPassword.aspx", "MotDePassePerdu", 430, 200, true, null);
}


function AjoutCommentaire(numElement)
{
	OuvrirFenetreScroll(racineSite + "/Popup/Commentaire/Action.aspx?action=ajouter&numElement=" + numElement, "Commentaire", 575, 425, true);
}


function ListeCommentaire(numElement)
{
	OuvrirFenetreScroll(racineSite + "/Popup/Commentaire/Liste.aspx?numElement=" + numElement, "Commentaire", 575, 425, true);
}


function ChoisirCouleur(couleurInitiale, parametres)
{
	couleurInitiale = escape(couleurInitiale);
	parametres = escape(parametres);
	url = racineSite + "/Popup/Couleur.aspx?couleur=" + couleurInitiale + "&parametres=" + parametres;
	OuvrirFenetre(url, "ChoisirCouleur", 460, 180, true, "");
}


function ChoisirStylePolice(idStyle, stylePolice, stylePoliceHover, couleurFond)
{
	var url = racineSite + "/Popup/Police.aspx?idStyle=" + escape(idStyle);
	url += "&stylePolice=" + escape(stylePolice);
	if (stylePoliceHover != null)
		url += "&stylePoliceHover=" + escape(stylePoliceHover);
	url += "&couleurFond=" + escape(couleurFond);
	
	OuvrirFenetre(url, "ChoisirStylePolice", 424, 220, true, "");
}


function InfoRss()
{
	OuvrirFenetre(racineSite + "/Popup/InfoRss.aspx", "InfoRss", 400, 260, true, "");
}


function InfosCarte()
{
	OuvrirFenetre(racineSite + "/Admin/Abonnement/InfosCarte.htm", "InfosPaiement", 500, 300, true, "");
}


function InfosCheque()
{
	OuvrirFenetre(racineSite + "/Admin/Abonnement/InfosCheque.htm", "InfosPaiement", 500, 300, true, "");
}


function VerifierEmail(email) 
{
	var arobase = email.indexOf("@");
	var point = email.lastIndexOf(".");
	if ((arobase < 2) || (point + 2 > email.length) || (point < arobase + 3))
		return false;
	else
		return true;
}


function AppliquerImage(idImage, urlImage)
{
	var objetIdImage = document.getElementById(idImage);
	if(objetIdImage != null)
	{
		objetIdImage.src = urlImage;
	}
}


function ChangerClasse(id, nomClasse)
{
	var objetId = document.getElementById(id);
	if (objetId != null)
	{
		objetId.className = nomClasse;
	}
}


function AfficherMasquerId(id, afficher)
{
	var objetId = document.getElementById(id);
	if (objetId != null)
	{
		var styleId = objetId.style;
		
		if (afficher == null)
		{
			if (styleId.display == "none")
			{
				afficher = true;
			}
			else
			{
				afficher = false;
			}
		}
		
		if (afficher == true)
		{
			styleId.display = "";
		}
		else
		{
			styleId.display = "none";
		}
	}
}


function ModifValeurInput(objInput, valeurTest, nouvelleValeur)
{
	if (objInput.value == valeurTest)
	{
		objInput.value = nouvelleValeur;
	}
}


function TestInputRadioChecked(inputRadio)
{
    for (var indiceRadio=0; indiceRadio<inputRadio.length; indiceRadio++)
    {
        if (inputRadio[indiceRadio].checked)
        {
			return true;
        }
    }
    return false;
}


function PreLoadImg()
{
	if (document.images)
	{
		var preload = new Array();
		
		for (var i=0; i<PreLoadImg.arguments.length; i++)
		{
			preload[i] = new Image();
			preload[i].src = PreLoadImg.arguments[i];
		}
	}
}


function ValiderSondage(numSondage)
{
	if (TestInputRadioChecked(document.forms["FormSondage" + numSondage].NumReponse))
	{
		document.forms["FormSondage" + numSondage].submit();
	}
}


function AppliquerHauteurPage()
{
	if (window.name!=null && window.parent.frames.length > 0 && window.parent.document.getElementById(window.name)!=null)
	{
		hauteurPage = document.getElementById("basPage").offsetTop;
		
		if (hauteurPage < 1)
			setTimeout("AppliquerHauteurPage()", 10);
		else
			window.parent.document.getElementById(window.name).style.height = hauteurPage;
	}
}


function AfficherDate(id, annee, mois, jour, heure, minute, seconde, formatSortie)
{
	// formatSortie : [dd]/[MM]/[yyyy] à [hh]:[mm]
	
	try
	{
		var laDate = new Date();
		laDate.setUTCFullYear(annee);
		laDate.setUTCMonth(mois - 1);
		laDate.setUTCDate(jour);
		laDate.setUTCHours(heure);
		laDate.setUTCMinutes(minute);
		laDate.setUTCSeconds(seconde);
		
		var str = formatSortie;
		
		str = str.replace("[yyyy]",	ChiffreMin(laDate.getFullYear(), 2));
		str = str.replace("[MM]",	ChiffreMin(laDate.getMonth() + 1, 2));
		str = str.replace("[dd]",	ChiffreMin(laDate.getDate(), 2));
		str = str.replace("[hh]",	ChiffreMin(laDate.getHours(), 2));
		str = str.replace("[mm]",	ChiffreMin(laDate.getMinutes(), 2));
		str = str.replace("[ss]",	ChiffreMin(laDate.getSeconds(), 2));
		
		document.getElementById(id).innerHTML = str;
	}
	catch(ex)
	{
	}
}


function ChiffreMin(valeur, nbChiffre)
{
	while (valeur.toString().length < nbChiffre)
	{
		valeur = "0" + valeur.toString();
	}
	
	return valeur;
}


function MM_preloadImages()
{
	var d=document;
	if(d.images)
	{
		if(!d.MM_p)
			d.MM_p=new Array();
		var i, j=d.MM_p.length, a=MM_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 MM_swapImage()
{
	var i,j=0,x,a=MM_swapImage.arguments;
	document.MM_sr = new Array;
	for(i=0;i<(a.length-2);i+=3)
	{
		if ((x=MM_findObj(a[i]))!=null)
		{
			document.MM_sr[j++]=x;
			if(!x.oSrc)
				x.oSrc=x.src;
			x.src=a[i+2];
		}
	}
}

function MM_swapImgRestore()
{
	var i,x,a=document.MM_sr;
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
		x.src=x.oSrc;
}

function MM_findObj(n, d)
{
	var p,i,x;
	
	if(!d)
		d=document;
	
	if((p=n.indexOf("?"))>0&&parent.frames.length)
	{
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	
	if(!(x=d[n])&&d.all)
		x=d.all[n];
	
	for (i=0;!x&&i<d.forms.length;i++)
		x=d.forms[i][n];
	
	for(i=0;!x&&d.layers&&i<d.layers.length;i++)
		x=MM_findObj(n,d.layers[i].document);
	
	if(!x && d.getElementById)
		x=d.getElementById(n);
	
	return x;
}


function FacebookShare()
{
	window.open('http://www.facebook.com/share.php?u=' + encodeURIComponent(window.location.href));
}


function NombreAleatoire(nombreMin, nombreMax)
{
	return Math.floor((nombreMax - nombreMin + 1) * Math.random() + nombreMin);
}

function OrdreAleatoire(nombreMin, nombreMax)
{
	var ordreAleatoire = new Array;
	var cpt = nombreMax - nombreMin;
	
	for (i=0; i<=cpt; i++)
	{
		ordreAleatoire[i] = nombreMin + i;
	}
	
	for (i=0; i<=cpt; i++)
	{
		var nombreAleatoire = NombreAleatoire(0, cpt);
		var sauvOrdre = ordreAleatoire[i];
		ordreAleatoire[i] = ordreAleatoire[nombreAleatoire];
		ordreAleatoire[nombreAleatoire] = sauvOrdre;
	}
	
	return ordreAleatoire;
}

