function MyTrimming(titre_id, titre_img_id, titre_height, chapeau_id, chapeau_img_id, chapeau_height, total_height, ellipsis_reposition)
{
	ellipsis_reposition = (ellipsis_reposition == null) ? true : ellipsis_reposition;
	Trim(titre_id, titre_img_id, titre_height, ellipsis_reposition);
	objTitre = document.getElementById(titre_id);
	
	if (objTitre.offsetHeight < titre_height)
	{
		Trim(chapeau_id, chapeau_img_id, total_height - objTitre.offsetHeight, ellipsis_reposition);
	}
	else
	{
		Trim(chapeau_id, chapeau_img_id, chapeau_height, ellipsis_reposition);
	}
}

function Trim(objID, imgID, height, ellipsis_reposition, optID) {
	obj = document.getElementById(objID);
	img = document.getElementById(imgID);
	ellipsis_reposition = (ellipsis_reposition == null) ? true : ellipsis_reposition;

	if (obj.scrollHeight <= obj.offsetHeight)
	{
		img.style.display = "none";
		return true;
	}
	else
	{	
		if (height != 0)
			obj.style.height = height + "px";

		if (obj.scrollHeight > obj.offsetHeight)
		{
			/*
			if (img.tagName == "IMG")
				img.style.marginTop = (height - 6) + "px";
			else*/

			if (optID == null) {
				if (height != 0 && ellipsis_reposition)
					img.style.height = height + "px";
				img.style.display = "";
			} else {
				opt = document.getElementById(optID);
				
				if (document.all) {
					if (opt.offsetHeight < 189) {
						if ((opt.offsetHeight / 21) % 2 != 0) {
							height = height - 2;
							obj.style.height = height + "px";
						} else {
							height = height + 5;
							obj.style.height = height + "px";
						}
						img.innerHTML = "<span style='position: absolute; bottom: 0px; right: 0px;'><h4>...</h4></span>";
						if (ellipsis_reposition)
							img.style.height = height + "px";
						img.style.display = "";
					} else if (opt.offsetHeight > 189) {
						height = height - 5;
						obj.style.height = height + "px";
						if (ellipsis_reposition)
							img.style.height = height + "px";
						img.style.display = "";
					}
				} else {
					if (opt.offsetHeight < 198) {
						if ((opt.offsetHeight / 22) % 2 != 0) {
							height = height - 4;
							obj.style.height = height + "px";
						} else {
							height = height + 4;
							obj.style.height = height + "px";
						}
						img.innerHTML = "<span style='position: absolute; bottom: 0px; right: 0px;'><h4>...</h4></span>";
						if (ellipsis_reposition)
							img.style.height = height + "px";
						img.style.display = "";
					} else if (opt.offsetHeight > 198) {
						if (ellipsis_reposition)
							img.style.height = height + "px";
						img.style.display = "";
					}
				}
			}
		}
		return false;
	}
}

function GetReponseFromUser() {
	responses = document.getElementsByName('response');
	for(i=0; i < responses.length; i++) {
		if (responses[i].checked) {
			return responses[i].value;
		}
	}
	return 0;
}

function GetVoteResult(response_id, timestamp) {
	if (response_id > 0) {
		var params = 'vote_id='+response_id+'&timestamp='+timestamp;
		ajax = new Ajax.Updater({success: 'survey'},'sondage/sondage.html',{method:'get', parameters: params, onFailure: function() {alert('Failed to commit your voting');}});
	}
}

function displayImageThumbnailList(categorie_repertoire, div, hidden, image_infos) {
	div = div || 'imgActualite';
	hidden = hidden || 'image_id';
	image_infos = image_infos || 'true';

	openWindow("http://www.stade.fr/admin/image/thumbnail_liste.php?div="+ div +"&hidden="+ hidden +"&categorie_repertoire="+ categorie_repertoire+"&image_infos="+image_infos, 1000, 600);
	return false;
}

function clearImage(div, hidden) {
	div = div || 'imgActualite';
	hidden = hidden || 'image_id';
	document.getElementById(div).innerHTML = na;
  	document.getElementById(hidden).value = 0;
}

function openImage(type, src, vWidth, vHeight) {
	winDef = "status=no,resizable=no,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=yes,height="+vHeight+",width="+vWidth+",";
	winDef = winDef.concat("top=").concat((screen.height - vHeight)/2).concat(",");
	winDef = winDef.concat("left=").concat((screen.width - vWidth)/2);
	newwin = window.open("include/popup47d9.html?type="+type+"&fichier="+src, "_blank", winDef);

	return false;
}

function openWindow(url, width, height) {
	winDef = "status=no,resizable=no,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=yes,height="+height+",width="+width+",";
	winDef = winDef.concat("top=").concat((screen.height - height)/2).concat(",");
	winDef = winDef.concat("left=").concat((screen.width - width)/2);

	new_window = window.open(url, "_blank", winDef);
	return false;
}

function MM_swapImgRestore() { //v3.0
  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_preloadImages() { //v3.0
  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_findObj(n, d) { //v4.01
  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 MM_swapImage() { //v3.0
  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_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}


function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function gauche(){

	if(document.getElementById('navvert')){

		var contenu = document.getElementById('contenu').offsetHeight;
		var sky = document.getElementById('navvert');
		var skyheight = document.getElementById('navvert').offsetHeight;

		if(contenu > skyheight){
			sky.style.height = (contenu+1)+"px";

		}
	}
}

function droite(){

	if(document.getElementById('complements')){
		var contenu = document.getElementById('contenu').offsetHeight;
		var backg = document.getElementById('complements');
		var backgheight = document.getElementById('complements').offsetHeight;

		if(contenu > backgheight){
			backg.style.height = (contenu-161)+"px";
		}
	}
}

var menus = [
	new ypSlideOutMenu("menu1", "down", 0, 0, 705, 30),
	new ypSlideOutMenu("menu2", "down", 0, 0, 705, 30),
	new ypSlideOutMenu("menu3", "down", 0, 0, 705, 30),
	new ypSlideOutMenu("menu4", "down", 0, 0, 705, 30),
	new ypSlideOutMenu("menu5", "down", 0, 0, 705, 30),
	new ypSlideOutMenu("menu6", "down", 0, 0, 705, 30),
	new ypSlideOutMenu("menu7", "down", 0, 0, 705, 30)
	]
for (var i = 0; i < menus.length; i++) {
	menus[i].onactivate = new Function("document.getElementById('nav" + i + "').className='etatDessus';");
	menus[i].ondeactivate = new Function("document.getElementById('nav" + i + "').className='';");

}
ypSlideOutMenu.writeCSS();



// swap layers joueurs //

// resize fix for ns4
var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

var cur_lyr;	// holds id of currently visible layer
function swapLayers(id) {
  if (cur_lyr) hideLayer(cur_lyr);
  showLayer(id);
  cur_lyr = id;
}

function showLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "visible";
}

function hideLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "hidden";
}

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? getLyrRef(id,document): null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

// get reference to nested layer for ns4
// from old dhtmllib.js by Mike Hall of www.brainjar.com
function getLyrRef(lyr,doc) {
	if (document.layers) {
		var theLyr;
		for (var i=0; i<doc.layers.length; i++) {
	  	theLyr = doc.layers[i];
			if (theLyr.name == lyr) return theLyr;
			else if (theLyr.document.layers.length > 0)
	    	if ((theLyr = getLyrRef(lyr,theLyr.document)) != null)
					return theLyr;
	  }
		return null;
  }
}

function MM_swapImageBg(id,put) 
{
    document.getElementById(id).style.backgroundImage="url('img/common/navhoriz/bton-menu-" + put + ".gif')";
}

function MM_swapImageBg2(id,put) 
{
    document.getElementById(id).style.backgroundImage="url('../img/common/navhoriz/bton-menu-" + put + ".gif')";
}