﻿
var isMSIE = (navigator.appName == "Microsoft Internet Explorer");

function sysHideElement(obj, displayType)
{
   if ( obj.style )
   {
      obj.style.visibility = 'hidden';
      if ( ! displayType )
         displayType = 'none';
      obj.style.display = displayType;
   }
   else
   {
      obj.visibility = 'hide';
   }
}

function sysShowElement(obj, displayType)
{
   if ( ! obj ) return;
   if ( obj.style )
   {
      obj.style.visibility = 'visible';
      if ( ! displayType )
         displayType = '';
      obj.style.display = displayType ;
   }
   else
      obj.visibility = 'show';
}

function sysIsVisible(obj)
{
   if ( obj.style )
      return (obj.style.visibility != 'hidden') && (obj.style.display != 'none');
   return obj.visibility == 'show';
}



var SCROLL_TIMER = null;
var SCROLL_LOOP = true;

function sysVertScroll(divId, dir, spd, loop, max) 
{
   var direction = "up";
   var speed = 10;

   var div = document.getElementById(divId);
   var page = div.style;

   direction = dir;
   speed = parseInt(spd);
   var y_pos = parseInt(page.top);
   
   if (direction == "down") 
   {
      if ( y_pos <= max ) // bloque le défilement du bas quand max atteint
         return;
   }

   if (loop == true) 
   {
      if (direction == "down") 
      {
         page.top = (y_pos - (speed)) + "px";
      } 
      else 
      {
         if (direction == "up" && y_pos < 0) 
         {
            page.top = (y_pos + (speed)) + "px";
         } 
         else 
         {
            if (direction == "top") 
                page.top = "0px";
         }
      }
   }

   SCROLL_TIMER = setTimeout("sysVertScroll('" + divId + "','" + direction + "'," +speed +"," + loop + "," + max + ")", 1);
}

function sysStopScroll() 
{
   SCROLL_LOOP = false;
   clearTimeout(SCROLL_TIMER);
}

function Dimension(w, h)
{
   this.width = w;
   this.height = h;
   return this;
}

function sysGetWindowSize() 
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return new Dimension(myWidth, myHeight);
}


//change the opacity for different browsers
function sysChangeOpacity(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function sysOpacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("sysChangeOpacity(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("sysChangeOpacity(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

// Fonction multi navigateur
function sysSetStyleClass(elt, className)
{
   if ( isMSIE )
   {
      elt.setAttribute("className", className);
   }
   else
   {
      elt.className = className;
   }
   elt.setAttribute("sysClassName", className);// spec 
}
function sysGetStyleClass(elt)
{
   return elt.getAttribute("sysClassName");// spec
}