

$(document).ready(function() {



$('.footerLink').boxy();

$('.boxy').boxy();



$('.fbox').facebox();



    /*

      HOVER MENU A GAUCHE

    */

    $(".stroked").hover(function () {

       var id = this.id;

       $(this).each(function(){

       		$(".sn" + id).addClass("whiteMenuBg");

       		$(this).fadeIn("fast");       

    	});

    },

      function () {

      var id = this.id;

       $(".sn" + id).removeClass("whiteMenuBg");

      }   

    );
	

    $(".strokedSpecial").hover(function () {

       var id = this.id;

       $(this).each(function(){

       		$(".sn" + id).addClass("whiteMenuSpecialBg");

       		$(this).fadeIn("fast");       

    	});

    },

      function () {

      var id = this.id;

       $(".sn" + id).removeClass("whiteMenuSpecialBg");

      }   

    );

    



		$('#sitemap ul ul:first').prepend('<p id="dirshow"><a href="#">masquer</a></p>');

		$('#dirshow a').click(function(){

			var that = $(this),

					level3 = $('#sitemap li li li');

			if (!that.hasClass('hidelevel')) {

				level3.hide('normal');

				that.html('afficher tous').addClass('hidelevel');

			} else {

				level3.show('slow');

				that.html('fermer').removeClass('hidelevel');

			}

			return false;

		});



});



  /*

    function pour afficher le contenu 

  */

  function showMenu(menu, favoris) {
	 
	if (favoris){		
		menuPath="menuFav.show.php";
	}else{
		menuPath="menu.show.php";
	}


  // random number pour lanim

  var randomnumber=Math.floor(Math.random()*2)

  // on va seter la direction pour le retour

  if (randomnumber == 0) { 

    var direction="up";

  } else {

    if (randomnumber >= 1) {

      var direction="left";

    } else {

      var direction="left";

    }

  }



    // si le panier est ouvert on va le fermer

    if ($("#panierShow").is(":hidden")) {

      // ye deja fermer donc on fait rien...

    } else {

      // need to slide up ;P

      $("#panierShow").slideUp("slow");

      $(".leftImage").fadeIn("slow");

      

     $("#cart").fadeOut("slow", function () {

      $("#container").fadeIn("slow");



     });

    }

    

  //on va slider up 

  $("#menuBg").hide("slide", { direction: "left" }, 600, function () {

  $("#loader").show();

  $("#menuTop").hide("slide", { direction: "left" }, 600, function () {

  $("#menuTable").hide("slide", { direction: "left" }, 600, function () {



  // la variable ajax

  var html = $.ajax({

    type: "GET",

    url: menuPath,

    data: "id=" + menu,

    async: false

  }).responseText;



  // on va seter le contenu    



  // on va faire l'effect de retour random

  $("#container").html(html);



  //$("#menuTop").show("slide", { direction: "left" }, 600);

    $("#loader").hide();

  });

 });

 });

 updatePanier(0);

}



  function showGroup(menu, favoris) {
	if (favoris){		
		menuPath="groupFav.show.php";
	}else{
		menuPath="group.show.php";
	}



  // random number pour lanim

  var randomnumber=Math.floor(Math.random()*2)

  // on va seter la direction pour le retour

  if (randomnumber == 0) { 

    var direction="up";

  } else {

    if (randomnumber >= 1) {

      var direction="left";

    } else {

      var direction="left";

    }

  }



    // si le panier est ouvert on va le fermer

    if ($("#panierShow").is(":hidden")) {

      // ye deja fermer donc on fait rien...

    } else {

      // need to slide up ;P

      $("#panierShow").slideUp("slow");

      $(".leftImage").fadeIn("slow");

      

     $("#cart").fadeOut("slow", function () {

      $("#container").fadeIn("slow");



     });

    }

    

  //on va slider up 

  $("#menuBg").hide("slide", { direction: "left" }, 600, function () {

  $("#loader").show();

  $("#menuTop").hide("slide", { direction: "left" }, 600, function () {

  $("#menuTable").hide("slide", { direction: "left" }, 600, function () {



  // la variable ajax

  var html = $.ajax({

    type: "GET",

    url: menuPath,

    data: "id=" + menu,

    async: false

  }).responseText;



  // on va seter le contenu    



  // on va faire l'effect de retour random

  $("#container").html(html);



  //$("#menuTop").show("slide", { direction: "left" }, 600);

    $("#loader").hide();

  });

 });

 });

 updatePanier(0);

}



function updatePanier(user) {

  // ajax

  var html = $.ajax({

    type: "GET",

    url: "menu.panier.php",

    data: "user=" + user,

    async: false

  }).responseText;

  

  $(".cartContenu").html(html);

}





function showProfil() {

  // ajax

  var html = $.ajax({

    type: "GET",

    url: "profil.show.php",

    async: false

  }).responseText;

  

  $("#profilContainer").html(html);



  $("#profilContainer").fadeIn('slow');



}


function showHisto() {

  // ajax

  var html = $.ajax({

    type: "GET",

    url: "histo.show.php",

    async: false

  }).responseText;

  $("#histoContainer").html(html);

  $("#histoContainer").fadeIn('slow');

}


function showHistoDetail(commID) {

  // ajax

  var html = $.ajax({

    type: "GET",

    url: "histoDetail.show.php",

    data: "commID=" + commID,

    async: false

  }).responseText;

  $("#commDesc"+commID).html(html);

  $("#commDesc"+commID).fadeIn('slow');

}


function showAdresse() {

  // ajax

  var html = $.ajax({

    type: "GET",

    url: "adresse.show.php",

    async: false

  }).responseText;

  

  $("#adresseContainer").html(html);



  $("#adresseContainer").fadeIn('slow');



}



function checkAdresse() {

  var nom = document.addresse['nom'].value;

  var rue = document.addresse['rue'].value;

  var porte = document.addresse['porte'].value;

  var appartement = document.addresse['appartement'].value;

  var codePostal = document.addresse['codePostal'].value;

  var note = document.addresse['note'].value;



  var html = $.ajax({

    type: "GET",

    url: "adresse.add.php",

    data: "nom=" + nom +"&rue=" + rue +"&porte=" + porte +"&note=" + note +"&appartement=" + appartement +"&codePostal=" + codePostal,

    async: false

  }).responseText;

  

  showAdresse();

}



function updateMainCart(user) {

  // ajax

  var html = $.ajax({

    type: "GET",

    url: "cart.php",

    data: "user=" + user,

    async: false

  }).responseText;

  

  $("#cart").html(html);

}



function switchCommand(user,adr,payment,resto,hre,ustensile,NoteSuppl,hreLivraison) {
  var html = $.ajax({

    type: "GET",

    url: "switch.command.php",

    data: "user=" + user + "&adresse_id=" + adr + "&payment=" + payment + "&resto=" + resto + "&hre=" + hre + "&ust=" + ustensile + "&note=" + NoteSuppl + "&hrelivr=" + hreLivraison,

    async: false

  }).responseText;

  
  window.location.href="checkOut-done.php"

}



function updateEmptyCart() {

  // ajax

  var html = $.ajax({

    type: "GET",

    url: "menu.panier.php",

    data: "user=empty",

    async: false

  }).responseText;

  

  $(".cartContenu").html(html);

}



function delPanier(id,user) {

  // ajax

  var html = $.ajax({

    type: "GET",

    url: "menu.panier.del.php",

    data: "id=" + id,

    async: false

  }).responseText;



  updateMainCart(user);

}



function viderPanier(id) {

  // ajax

  var html = $.ajax({

    type: "GET",

    url: "menu.panier.vider.php",

    data: "user=" + id,

    async: false

  }).responseText;



  updateMainCart(id);

}

       

function commander(token) {

  // ajax

  var html = $.ajax({

    type: "GET",

    url: "menu.command.php",

    data: "token=" + token,

    async: false

  }).responseText;

  $("#resultAdd").html(html);

  updatePanier(0);

  

  $.facebox.close();

}



function startPanierUpdate(user){   

  updatePanier(user);

  timeoutID = window.setTimeout("checkPanier('"+user+"');",60000);

}



function checkPanier(user) {

  updatePanier(user);

  timeoutID = window.setTimeout("checkPanier('"+user+"');",60000);

}



function stopPanierUpdate(){   

   clearTimeout(timeoutID)

}



function addToFavorites(){

  if(window.external && document.all) {

    window.external.AddFavorite(location.href, "CHEZ LOUIS POULET & PIZZA - COMMANDER EN LIGNE");

  }

}



function sf(){

  document.addresse.submit();

}



function getPrix(token) {

  // ajax

  var html = $.ajax({

    type: "GET",

    url: "menu.calcul.command.php",

    data: "token=" + token,

    async: false

  }).responseText;

  

  $("#prixSousTotal").html(html);

}



function addOptions(token,option_id) {

  // ajax

  var html = $.ajax({

    type: "GET",

    url: "menu.options.command.php",

    data: "token=" + token + "&option=" + option_id,

    async: false

  }).responseText;

  getPrix(token);



}



function addExtras(token,option_id) {

  // ajax

  var html = $.ajax({

    type: "GET",

    url: "menu.extra.command.php",

    data: "token=" + token + "&option=" + option_id,

    async: false

  }).responseText;

  getPrix(token);

  



}



function addAutres(token,option_id) {

  // ajax

  var html = $.ajax({

    type: "GET",

    url: "menu.autres.command.php",

    data: "token=" + token + "&option=" + option_id,

    async: false

  }).responseText;

  getPrix(token);

  



}



function flushToken(token) {

  // ajax

  var html = $.ajax({

    type: "GET",

    url: "menu.flush.token.php",

    data: "token=" + token,

    async: false

  }).responseText;

  

}



function retirFavoris(menuID) {

  // ajax

  var html = $.ajax({

    type: "GET",

    url: "menu.flush.favoris.php",

    data: "menuID=" + menuID,

    async: false

  }).responseText;
  
	window.location.href="favoris.php";
}

function ajoutFavoris(menuID) {

  // ajax

  var html = $.ajax({

    type: "GET",

    url: "menu.ajout.favoris.php",

    data: "menuID=" + menuID,

    async: false

  }).responseText;
  
  alert("Ajout fait a vos favoris");
}

function showCart() {

  if ($("#panierShow").is(":hidden")) {

	  
      $("#container").fadeOut("slow");

      $("#cart").fadeIn("slow");

      $("#panierShow").slideDown("slow");

      $(".leftImage").fadeOut("slow");

      $("#leftMenu").slideUp("slow", function () { $("#leftMenuCart").slideDown("slow"); });

      stopPanierUpdate();

      updateMainCart();
      $("#ouvrePanier").hide();
      $("#fermePanier").show();

    } else {

	  
      $("#panierShow").slideUp("slow");

      $(".leftImage").fadeIn("slow");

      $("#cart").fadeOut("slow", function () {

      $("#container").fadeIn("slow");

      $("#leftMenuCart").slideUp("slow", function () { $("#leftMenu").slideDown("slow"); });

      updatePanier(0); });
	  
	  
      $("#fermePanier").hide();
      $("#ouvrePanier").show();

  }

}     



function prepareCommand(adr, adrReplacement, val_ustensile) {
	var adresseResto = getSelectedRadioValue(document.adresse.radiobutton_type);
	var heure = document.adresse.recup_heure.value;
	var ustensile = val_ustensile;
	var NoteSuppl = document.adresse.NoteSuppl.value;
	var hreLivraison  = document.adresse.hreLivraison.value;
  if ((adresseResto!="" || adr=="0")&&adresseResto!="false"){
	  if (adresseResto!="" && heure != ""){
		  //window.location.href="checkOut-payment.php?adr=" + adr + "&resto=false&hre=false";
		  	adr=adrReplacement;
	  		window.location.href="checkOut-payment.php?adr=" + adr + "&resto=" + adresseResto + "&hre=" + heure + "&ust=" + ustensile + "&note=" + NoteSuppl + "&hrelivr=" + hreLivraison;
	  }else{
		  alert("Veuillez choisir l'adresse du restaurant et l'heure de r\u00E9cup\u00E9ration de la commande.");
	  }
  }else{
	  if(adr!="0"){
		  window.location.href="checkOut-payment.php?adr=" + adr + "&resto=false&hre=false&ust=" + ustensile + "&note=" + NoteSuppl + "&hrelivr=" + hreLivraison;
	  }else{
		  alert("Veuillez choisir une adresse de livraison.");
	  }
  }
}





function enjoyCommand(adr, resto, hre, ust, note, hrelivr) {
	var payment = getSelectedRadioValue(document.paiement.radiobutton_type);
  if (payment!=""){
	  window.location.href="checkOut-confirm.php?adr=" + adr + "&payment=" + payment + "&resto=" + resto + "&hre=" + hre + "&ust=" + ust + "&note=" + note + "&hrelivr=" + hrelivr;
  }else{alert("Veuillez choisir un mode de paiement.");
  }
}



function setbg(color) {

  document.getElementById("styled").style.background=color

}



/*

    function pour afficher le facebox des breuvages 

  */

  function drinkAdd(drinkID) {
	switch(drinkID){
		case "Coca-Cola":
			sousmenu_id = "106";
			break;
		case "Cokediet":
			sousmenu_id = "107";
			break;
		case "Cocazero":
			sousmenu_id = "108";
			break;
		case "Sprite":
			sousmenu_id = "109";
			break;
		case "Minute":
			sousmenu_id = "110";
			break;
		case "Barq":
			sousmenu_id = "111";
			break;
		case "Fruitopia":
			sousmenu_id = "112";
			break;
  	}
	
	// ajax

  var html = $.ajax({

    type: "GET",

    url: "menu.get.user.php",

    async: false

  }).responseText;
	
	if (html!="") {
		jQuery.facebox({ ajax: 'menu.create.command.php?menu_id=15&col_id=67&sousmenu_id=' + sousmenu_id });
	}
  }
  
  function maillingAdd(email) {
	// ajax
	//alert("email"+email);
 	 var html = $.ajax({

    	type: "GET",

    	url: "inscriptionMailling.php",

    	data: "email=" + email,

    	async: false

 	 }).responseText;
  }
  
  
  function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function