// JavaScript Document
function affiche_selecteur()
{
  var url_page = document.location;
   $.get('/modules/traiteur_magasin/selection_magasin.php?url=' + url_page,function(data){ 

          $("#magasin_absolu").addClass("affiche_magasin_absolu");
          $("#bloc_selection").addClass("style_bloc_selection");
          $("#bloc_selection").html(data);
          
          var NomNav = navigator.appName; // place le nom du navigateur dans la variable NomNav (2)
         var VersNav = navigator.appVersion; // place la version du navigateur dans la variable VersNav (3)
         var NumVers = parseFloat(VersNav);
         
         if (NomNav == "Microsoft Internet Explorer")
         {
            var ieversion = version_navigateur();
            
            if (ieversion < 7)
            {
              //resize_conteneur();
              $("#magasin_absolu").height($('body').height() + "px");
            }
            else
            {
              $("#magasin_absolu").height($('body').height() + "px");  
            }
          }
          else
          {
            $("#magasin_absolu").height($('body').height() + "px");  
          }
   });
};

function version_navigateur()
{
  var ieversion = 0;
  if (navigator.appVersion.indexOf("MSIE") != -1)
  {
    t = navigator.appVersion.split("MSIE");
    ieversion = parseFloat(t[1]);
  }
  
  return ieversion;
}

function resize_conteneur()
{
  var body_height = $('#axome').height();
  var height_total = (body_height * -1);
  
  $("#magasin_absolu").height($('body').height() + "px");
  $('#magasin_absolu').css("margin-top",height_total + "px");
  $("#bloc_selection").css("margin-top",(height_total - $("#bloc_selection").height()) + "px");
  $("#bloc_selection").css("margin-left",(($("#magasin_absolu").width() / 2) - ($("#bloc_selection").width() / 2)) + "px");
}

$(window).resize(function() {
   var NomNav = navigator.appName; // place le nom du navigateur dans la variable NomNav (2)
   var VersNav = navigator.appVersion; // place la version du navigateur dans la variable VersNav (3)
   var NumVers = parseFloat(VersNav);
   
   if (NomNav == "Microsoft Internet Explorer")
    {
      var ieversion = version_navigateur();
      
      if (ieversion < 7)
      {
        resize_conteneur();
        // $("#magasin_absolu").height($('body').height() + "px");  
      }
      else
      {
        $("#magasin_absolu").height($('body').height() + "px");  
      }
    }
    else
    {
      $("#magasin_absolu").height($('body').height() + "px");  
    }
     
});

function affiche_logo_magasin(code_mag)
{
  $.get('http://www.supercasino.fr/spip.php?page=wslogomagasin',{ id: code_mag},function(data){          
          $("#logo_magasin").html(data);
  });
}

function trouve_dep2(num_dep)
{
  document.getElementById('code_casino').selectedIndex = num_dep;
}

/*
function verification_termine(i)
{
    div1='#verification_ftp'+i;
    div2='#verification_mysql'+i;
    if(($(div1).html().substring(0,20)=='<font color=\"green\">')&&($(div2).html().substring(0,20)=='<font color=\"green\">'))
    {
        div='#bouton'+i;
        $(div).removeAttr('disabled');
        $(div).attr('style','color=#ffffff');
    }
};
*/
//fonctions de mise a jour
function traitement(code,url)
{
    
    $.get("/modules/traiteur_magasin/enregistre_magasin.php?code_casino=" + code,
      function(data) {
        // $("#diapo_home").css("display","block");
        document.location.href = url;
      }
    );
    
    // alert(code);

}

function clique_departement(num_dep) {
  
  if (parseInt(num_dep,10) < 10)
  {
    num_dep = "0" + parseInt(num_dep,10);
  }
  
  
  $.get("/modules/traiteur_magasin/liste_magasin_dep.php?dep=" + num_dep,
  function(data){
    
    $("#code_casino").empty();
    
    //Bug Safari
    if(/Safari/.test(navigator.appVersion))
    {
        resultat_contenu=document.getElementById("code_casino");
        resultat_contenu.innerHTML=resultat_contenu.innerHTML+data;
    }
    else
    {
      
      $("#code_casino").html(data);
    }
  }
);
}

// parser la query string
function getQuerystring(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

function autre_mag()
{
  if (confirm("Cette op\u00E9ration va effacer votre menu pr\u00E9c\u00E9dent : "))
  {
    $.get("/modules/traiteur_magasin/changer_magasin.php",
    function(data){
 
      var idm = getQuerystring('idm');
      
      if (idm != "")
      {
        document.location.href = "http://www.traiteur-casino.com/";
      }
      else
      {
        document.location.href = document.location; 
      }
    });
    
    
  }
  
}
