var indSlide = 0;
var maxSlide = 0;
var slideShowSpeed = 3000;
var crossFadeDuration = 3;
function permute()
{
 var images = document.getElementsByTagName('img');
 for (var i=0;i<images.length;i++)
 {
  if ( images[i].name.substring(0,3) == 'IMG' && images[i].name.substring(3) != '' )
  {
   if ( images[i].name.substring(3) > maxSlide )
   {
    maxSlide = images[i].name.substring(3);
   }
  }
 }
 if ( images[0] ) document.getElementById('IMAGE').src = images[0].src;
 if ( maxSlide > 0 ) alterne();
}

function alterne()
{
 var images = document.getElementsByTagName('img');
 for (var i=0;i<images.length;i++)
 {
  if ( images[i].name.substring(0,3) == 'IMG' && images[i].name.substring(3,4) == indSlide && images[i].src != '' )
  {
   if ( document.all )
   {
    document.getElementById('IMAGE').style.filter = "blendTrans(duration=crossFadeDuration)";
    document.getElementById('IMAGE').filters.blendTrans.Apply();
   }
   document.getElementById('IMAGE').src = images[i].src;
   if (document.all)
   {
    document.getElementById('IMAGE').filters.blendTrans.Play();
   }
   indSlide = indSlide + 1;
   if ( indSlide > maxSlide ) indSlide = 0;
   setTimeout('alterne()',slideShowSpeed);
   return;
  }
 }
}

function shw(obj)
{
 document.getElementById(obj).style.visibility = "visible";
}
function hid(obj)
{
 document.getElementById(obj).style.visibility = "hidden";
}
function changeCouleur(ligne,classe)
{
 ligne.className = classe;
}

String.prototype.trim = function()
{
 var reg1 = new RegExp("^\\s*");
 var reg2 = new RegExp("\\s*$");
 return this.replace(reg1,"").replace(reg2,"");
};

function trim_all(form)
{
 for (var i=0;i<form.elements.length;i++)
 {
  if ( form.elements[i].type == 'text' || form.elements[i].type == 'textarea' )
  {
   form.elements[i].value = form.elements[i].value.trim();
  }
 }
}

function checkall(form,champ,chkflag)
{
 for (var i=0;i<form.elements.length;i++)
 {
  if ( form.elements[i].name.substring(0,champ.length) == champ )
  {
   form.elements[i].checked = chkflag;
  }
 }
}

function redirection(url)
{
 document.location.href = url;
}

function changeURL(formSelection)
{
 if ( formSelection.options[formSelection.selectedIndex].value.trim() != '' )
 {
  redirection(formSelection.options[formSelection.selectedIndex].value);
 }
}

function Confirmation(texte,url)
{
 if ( confirm(texte) )
 {
  redirection(url);
 }
}

function popup(url,width,height,nom)
{
 var n6 = (document.getElementById && ! document.all) ? 1 : 0;
 var plusN6 = 10;
 if ( width < 1 )
 {
  var windowWidth = Math.round(screen.width * width);
 }
 else
 {
  var windowWidth = parseInt(width);
 }
 if ( height < 1 )
 {
  var windowHeight = Math.round(screen.height * height);
 }
 else
 {
  var windowHeight = parseInt(height);
 }
 if ( n6 )
 {
  windowHeight = windowHeight + plusN6;
 }
 var windowLeft = (screen.width-windowWidth)/2;
 var windowTop  = (screen.height-windowHeight)/2;
 w = window.open(url,nom,'menubar=yes,status=yes,resizable=yes,scrollbars=yes,fullscreen=no,width='+windowWidth+',height='+windowHeight+',top='+windowTop+',left='+windowLeft);
}

function confirmSuppression(lienHref)
{
 if ( confirm("Confirmez-vous la suppression de cet élément ?") )
 {
  if ( lienHref != '' )
  {
   document.location.href = lienHref;
  }
  else
  {
   lienFct();
  }
 }
}
function confirmDivers(lienHref,texte)
{
 if ( confirm(texte) )
 {
  document.location.href = lienHref;
 }
}
function submitCallback(elt)
{
 elt.form.submit();
}
function initOnSubmit(formulaire,fonction,argument)
{
 var form = document.forms[formulaire];
 form.onsubmit =
 function()
 {
  eval('ret = '+fonction+'(form,argument)');
  return ret;
 }
}
function initOnChange(formulaire,fonction,champ)
{
    if ( document.forms[formulaire] )
    {
        var form = document.forms[formulaire];
        if ( form.elements[champ] )
        {
            var att  = form.elements[champ];
            att.onchange = function()
            {
                eval("var ret = "+fonction+"()");
                return ret;
            }
        }
    }
}
function CreateBookmarkLink(uu,tt)
{
 if ( tt == '' )
 {
  var title = document.title;
 }
 else
 {
  var title = tt;
 }
 if ( uu == '' )
 {
  var url = document.location.href;
 }
 else
 {
  var url = uu;
 }
 if (window.sidebar  && (typeof window.sidebar.addPanel == "function"))
 {
  // Mozilla Firefox Bookmark
  window.sidebar.addPanel(title,url,"");
 }
 else if( window.external )
 {
  // IE Favorite
  window.external.AddFavorite(url,title);
 }
 else
 {
  return true;
 }
}
function setHome()
{
 document.body.style.behavior='url(#default#homepage)';
 document.body.setHomePage(window.location.href);
}
function chgPlusMoins(type,indice,chemin,plus,moins)
{
 if ( document.getElementById(type+indice).style.display == 'none' )
 {
  document.getElementById(type+indice).style.display = 'block';
  document.getElementById('img'+type+indice).src = chemin+moins;
 }
 else
 {
  document.getElementById(type+indice).style.display = 'none';
  document.getElementById('img'+type+indice).src = chemin+plus;
 }
}
function RollIn(img)
{
 var imageRoll = document[img];
 imageRoll.imgRolln = imageRoll.src;
 imageRoll.src = imageRoll.lowsrc ? imageRoll.lowsrc : imageRoll.getAttribute ? imageRoll.getAttribute('lowsrc') : imageRoll.src;
}
function RollOut(img)
{
 document[img].src = document[img].imgRolln;
}
function debug()
{
 if ( document.getElementById('sousDebug').style.display == 'none' )
 {
  document.getElementById('sousDebug').style.display = 'block';
 }
 else
 {
  document.getElementById('sousDebug').style.display = 'none';
 }
}
function PartnerChange()
{
    var param = 'action=g_selpart';
    param += '&partenaire=' + document.formulaire.partenaire.value;
    param += '&mode=' + document.formulaire.mode.value;
    param += '&indice=' + document.formulaire.indice.value;
    new Ajax.Request('index.php',{method: 'get',parameters: param,onSuccess: getResponse,onFailure: reportError});
}
function getResponse(rep)
{
    var txt = rep.responseText;
    if ( txt != '' ) document.getElementById('selectmultiple1').innerHTML = txt;
}
function reportError(rep)
{
    alert("Erreur : "+rep.responseText);
}
