jQuery(document).ready(function(){
  jQuery('a[rel*=facebox]').facebox({opacity:'0.4'});
  jQuery('#nblicence').focus();
  
});

if(typeof yz=="undefined"){var yz={};}

yz.defaultVideoWidth = 1280;
yz.defaultVideoHeight = 768;

yz.getWindowHeight = function()
{
  if (typeof(window.innerHeight) == 'number')
    return window.innerHeight;
  if (document.documentElement && document.documentElement.clientHeight)
    return document.documentElement.clientHeight;
  if(document.body && document.body.clientHeight)
    return document.body.clientHeight;
  return 0;
};

yz.affPopupVideo = function(url, sVideoWidth, sVideoHeight)
{
  var w = sVideoWidth == '' ? 0 : parseInt(sVideoWidth);
  if (w <= 0)
    w = yz.defaultVideoWidth;
  var h = sVideoHeight == '' ? 0 : parseInt(sVideoHeight);
  if (h <= 0)
    h = yz.defaultVideoHeight;
  h += 20;
  
  w = w*1.0208;
  h = h*1.0205;
  
  var winL = (screen.width-w)/2;
  var winT = (screen.height-h)/3.5;
  var settings = 'height='+h+',';
  settings += 'width='+w+',';
  settings += 'top='+winT+',';
  settings += 'left='+winL+',';
  settings += 'resizable=yes';
  var win = window.open(url, null, settings);
  if (win)
    win.focus();
};

yz.focusformulaire = function(identifiant){
  identifiant.style.borderTop='1px solid rgb(31,128,219)';
  identifiant.style.borderRight='1px solid rgb(170,223,250)';
  identifiant.style.borderBottom='1px solid rgb(170,223,250)';
  identifiant.style.borderLeft='1px solid rgb(170,223,250)';
};

yz.blurformulaire = function(identifiant){
  identifiant.style.borderTop='1px solid rgb(180,180,180)';
  identifiant.style.borderRight='1px solid rgb(220,220,220)';
  identifiant.style.borderBottom='1px solid rgb(220,220,220)';
  identifiant.style.borderLeft='1px solid rgb(220,220,220)';
};

yz.calculcoutlicences = function(){
  var nblicence = jQuery('#nb_licence').val();
  var pu_licence=300;
  nbusermin = new Array(2,5,25,50,100,200);
  nbusermax = new Array(4,25,49,99,199,10000);
  nbmois = new Array(12,12,12,12,12,12);
  poucentage = new Array(0,5,10,15,20,25);
  
  
  if(isNaN(nblicence)){
    alert('Vous devez entrer un nombre.');
    return false;
  }
  
  if(nblicence < nbusermin[0]){
    alert('Le nombre minimum de licence est de '+nbusermin[0]+'.');
    return false;
  }
  
  if(nblicence > nbusermax[5]){
    alert('Le nombre maximum de licence est de '+nbusermax[5]+'.');
    return false;
  }
  tableautarifs = new Array(5);
  for(var i=0; i<6; i++){
    tableautarifs[i] = new Array(7);
    for(var j=0; j<7; j++){
      tableautarifs[i][j] = 0;
    }
  }

  for(var i=0; i<6; i++){
    tableautarifs[i][0] = nbusermin[i];
    tableautarifs[i][1] = nbusermax[i];
    tableautarifs[i][2] = nbmois[i];
    tableautarifs[i][3] = poucentage[i];
    if(i==0)
      tableautarifs[i][4] = pu_licence;
    else
      tableautarifs[i][4] = tableautarifs[i-1][4];
    tableautarifs[i][5] = (tableautarifs[i][4]-(tableautarifs[i][4]*tableautarifs[i][3]/100));
    tableautarifs[i][6] = tableautarifs[i][4]-tableautarifs[i][5];
  }
  
  var id=0;
  for(var i=0; i<6; i++){
    if(tableautarifs[i][0] <= nblicence && tableautarifs[i][1] > nblicence)
      id=i;
  }
  
  jQuery('#yz_nblicence').html(nblicence);
  jQuery('#yz_nbmois').html(nbmois[id]);
  jQuery('#yz_prixunitaire').html(tableautarifs[id][5]);
  jQuery('#yz_economie').html(nblicence*tableautarifs[id][4]-nblicence*tableautarifs[id][5]);
  jQuery('#yz_couttotal').html(nblicence*tableautarifs[id][5]);

};




var logiciels = {


  previous_logiciel: 0,
  current_logiciel: 0,
  next_logiciel: 0,
  logiciel: [],

  init:function() {
    this.logiciel = jQuery('.yz_logiciel');

    for(i=1; i < this.logiciel.length; i++) {
      this.logiciel[i].style.display = "none";
    }

    this.previous_logiciel = this.logiciel.length-1;
    this.next_logiciel = 1;
  },

  nextlogiciel:function() {
    jQuery(this.logiciel[this.current_logiciel]).fadeOut('fast');
    jQuery(this.logiciel[this.next_logiciel]).fadeIn('fast');

    if(this.next_logiciel == (this.logiciel.length-1)) {
      this.previous_logiciel = this.current_logiciel;
      this.current_logiciel = this.next_logiciel;
      this.next_logiciel = 0;
    } else {
      this.previous_logiciel = this.current_logiciel;
      this.current_logiciel = this.next_logiciel;
      this.next_logiciel++;
    }
  },

  previouslogiciel:function() {
    jQuery(this.logiciel[this.current_logiciel]).fadeOut('fast');
    jQuery(this.logiciel[this.previous_logiciel]).fadeIn('fast');

    if(this.previous_logiciel == 0) {
      this.previous_logiciel = this.logiciel.length-1;
      this.next_logiciel = this.current_logiciel;
      this.current_logiciel--;
    } else {
      this.next_logiciel = this.current_logiciel;
      this.current_logiciel = this.previous_logiciel;
      this.previous_logiciel--;
    }
  }
}



var clients = {


  current_client: 0,
  next_client: 1,
  client: [],

  init:function() {
    this.client = jQuery('.yz_client');

    for(i=1; i < this.client.length; i++) {
      this.client[i].style.display = "none";
    }

    if(this.client.length > 1) clients.galerie();
  },

  galerie:function() {
    self.setTimeout("clients.nextclient()",7000);
  },

  nextclient:function() {
    jQuery(this.client[this.current_client]).fadeOut('slow');
    jQuery(this.client[this.next_client]).fadeIn('slow');

    if(this.next_client == (this.client.length-1)) {
      this.current_client = this.next_client;
      this.next_client = 0;
    } else {
      this.current_client = this.next_client;
      this.next_client++;
    }
    clients.galerie();
  }
}

var actualite = {


  current_actu: 0,
  next_actu: 1,
  actu: [],

  init:function() {
    this.actu = jQuery('.yz_actualite');

    for(i=1; i < this.actu.length; i++) {
      this.actu[i].style.display = "none";
    }

    if(this.actu.length > 1) actualite.galerie();
  },

  galerie:function() {
    self.setTimeout("actualite.nextactu()",5000);
  },

  nextactu:function() {
    jQuery(this.actu[this.current_actu]).fadeOut('slow');
    jQuery(this.actu[this.next_actu]).fadeIn('slow');
    if(this.next_actu == (this.actu.length-1)) {
      this.current_actu = this.next_actu;
      this.next_actu = 0;
    } else {
      this.current_actu = this.next_actu;
      this.next_actu++;
    }
    actualite.galerie();
  }

}


