//
// +----------------------------------------------------------------------+
// | PHP Version 4                                                        |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 Lille Metropole Communaute Urbaine (LMCU)         |
// +----------------------------------------------------------------------+
// | This file is part of Tiny.                                           |
// |                                                                      |
// | Tiny is free software; you can redistribute it and/or modify         |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation; either version 2 of the License, or    |
// | (at your option) any later version.                                  |
// |                                                                      |
// | Tiny is distributed in the hope that it will be useful,              |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
// | GNU General Public License for more details.                         |
// |                                                                      |
// | You should have received a copy of the GNU General Public License    |
// | along with Tiny; if not, write to the Free Software Foundation,      |
// | Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA        |
// +----------------------------------------------------------------------+
// | Authors: Laurent Glock <lglock@cudl-lille.fr>                        |
// +----------------------------------------------------------------------+
//

function turnGray() {
  if (!window.Event) {
      what = window.event.srcElement;
      if (what.tagName == "IMG") {
        if (what.src.indexOf("1.gif")>0) {
          what.src = what.src.substring(0,(what.src.indexOf("1.gif"))) + "0.gif";
    	  event.cancelBubble = true;
    	}
      }
  }
}

function turnColored() {
  if (!window.Event) {
      what = window.event.srcElement;
      if (what.tagName == "IMG") {
        if (what.src.indexOf("0.gif")>0) {
          what.src = what.src.substring(0,(what.src.indexOf("0.gif"))) + "1.gif";
          event.cancelBubble = true;
        }
      }
  }
}

function popupCentrer(sUrl, iWidth, iHeight)
{
  var sTb;
  var iTop=(screen.height-iHeight)/2;
  var iLeft=(screen.width-iWidth)/2;
  if (iWidth*iHeight == 0) {
    sTb = "status=yes,toolbar=yes,location=yes,scrollbars=yes,resizable=yes,menubar=yes,height=600,width=800,left=" + (screen.width-800)/2 + ",top=" + (screen.height-600)/2;
  } else {
    sTb = "status=yes,scrollbars=yes,resizable=no,height=" + iHeight + ",width=" + iWidth + ",left=" + iLeft + ",top=" + iTop;
  }
  window.open(sUrl, "Popup", toolbar=sTb);
}

function popupCentrerNavig(sUrl, iWidth, iHeight)
{
  var sTb;
  var iTop=(screen.height-iHeight)/2;
  var iLeft=(screen.width-iWidth)/2;
  sTb = "status=yes,toolbar=yes,location=yes,scrollbars=yes,resizable=yes,menubar=yes,height=" + iHeight + ",width=" + iWidth + ",left=" + 50 + ",top=" + 50;
  window.open(sUrl, "Popup", toolbar=sTb);
}

function popupImages(sUrl, iWidth, iHeight)
{
  var sTb;
  var iTop=(screen.height-iHeight)/2;
  var iLeft=(screen.width-iWidth)/2;
  sTb = "status=0,toolbar=0,location=0,resizable=yes,scrollbars=yes,menubar=0,height=" + iHeight + ",width=" + iWidth + ",left=" + iLeft + ",top=" + iTop;
  window.open(sUrl, "Popup", sTb);
}

function popupCerise(sUrl, iWidth, iHeight)
{
  var sTb;
  var iTop=(screen.height-iHeight)/2;
  var iLeft=(screen.width-iWidth)/2;
  sTb = "status=yes,toolbar=yes,location=0,resizable=0,scrollbars=0,menubar=0,height=" + iHeight + ",width=" + iWidth + ",left=" + iLeft + ",top=" + iTop;
  window.open(sUrl, "Popup", sTb);
}

function voirFicheProjet(iPrjId)
{
  var iHeight = 500;
  var iWidth = 600;
  var sTb;
  var iTop=(screen.height-iHeight)/2;
  var iLeft=(screen.width-iWidth)/2;
  sTb = "status=yes,scrollbars=yes,resizable=yes,height=" + iHeight + ",width=" + iWidth + ",left=" + iLeft + ",top=" + iTop;
  window.open("http://sezam/projets_fiche.php?view=front&prj_id="+iPrjId, "Popup", toolbar=sTb);
}

/* Partie de gestion de l'accessibilite pour les intranautes (augmentation ou diminution de la taille du texte)
*/
// Valeur de la CSS par defaut
//var sz=12;
function selectStyleCSS(site, dir) {
    // Liens pour les differentes CSS
    var li;
    // Récupération de la valeur du cookie
    // Pourrait être sorti dans un fonction à part entière
    index = document.cookie.indexOf("access_"+site);
    if ( index != -1) {
        nDeb = (document.cookie.indexOf( "=", index) + 1);
        nFin = document.cookie.indexOf( ";", index);
        if (nFin == -1) {nFin = document.cookie.length;}
        sz = unescape(document.cookie.substring(nDeb, nFin));
        //alert(sz);
    }
   // Test sur les valeurs 
    if (9<sz+dir&&sz+dir<19){
        // Ecriture de la valeur du cookie
        date = new Date();
        dateExp = date.getTime() + (15*24*3600);
        document.cookie = "access_" + site + "=" + escape (sz+dir) + "; expires=Mon, 01-Jan-07 00:00:01 GMT" + "; path=/";
        for(var i=0; li=document.getElementsByTagName("link")[i]; i++) {
            // Recuperation des CSS
            if (li.getAttribute("rel").indexOf("style") != -1 && li.getAttribute("title")) {
                // On active la bonne CSS
                if (li.getAttribute("title").indexOf("styl") !=-1) li.disabled = true;
                // On desactive les autres
                if (li.getAttribute("title").indexOf(sz+dir)>-1) li.disabled = false;
            }
        }
        // Incrementation de la valeur pour le choix de la CSS
        sz=sz+dir;
    }
}

function trim(val) 
{
  if (val.length < 1) {
    return "";
  }
  val = rtrim(val);
  val = ltrim(val);
  if (val == "") { 
    return "";
  } else {
    return val;
  }
} 

function rtrim(val)
{
  var w_space = String.fromCharCode(32);
  var v_length = val.length;
  var strTemp = "";
  if (v_length < 0) {
    return"";
  }
  var iTemp = v_length -1;
  while (iTemp > -1) {
    if (val.charAt(iTemp) == w_space) {
    } else {
      strTemp = val.substring(0,iTemp +1);
      break;
    }
    iTemp = iTemp-1;
  }
  return strTemp;
} 

function ltrim(val)
{
  var w_space = String.fromCharCode(32);
  if (v_length < 1) {
    return"";
  }
  var v_length = val.length;
  var strTemp = "";
  var iTemp = 0;
  while (iTemp < v_length) {
    if (val.charAt(iTemp) == w_space){
    } else {
      strTemp = val.substring(iTemp,v_length);
      break;
    }
    iTemp = iTemp + 1;
  } 
  return strTemp;
}

function ouvre_fenetre(x)
{
     w = window.screen.width ;
     h = window.screen.height ;
     if (w>1024) {
       largeur_fenetre = 900 ;
       hauteur_fenetre = 800;
     }
     else if (w>800) {
       largeur_fenetre = 700 ;
       hauteur_fenetre = 600;
     }
     else  {
       largeur_fenetre = 500 ;
       hauteur_fenetre = 400;
     }
     position_left = w-largeur_fenetre-30 ;
     newfen = window.open(x, 'mafenetre', 'width='+largeur_fenetre+', height='+hauteur_fenetre+', top=0, left='+position_left+', resizable=yes, menubar=yes, location=yes,toolbar=yes,scrollbars=yes');
     newfen.focus();
 }

function resetSearchForm() {
    if (document.topSearch.querytext.value == "Texte recherché") {
        document.topSearch.querytext.value = "";
    }
}

