﻿// JScript File

function RequestEx(mavariable)
{

var search = window.location.search;

var tab= search.split("&");
var variable = tab[0].split("=");
var name_variable;
var valeur_variable;

for (i=0;i<tab.length;i++ )
{

   variable = tab[i].split("=");
   if (i == 0)
   {
     name_variable   = variable[0].replace("?","");
     valeur_variable = variable[1];

   }
  else {
  name_variable   = variable[0]
  valeur_variable = variable[1];
  }
 if (name_variable == mavariable)
 {
   return  valeur_variable;
 }


}
}


//Recherche dans la liste des produits
function resr(noeud,idsearch/*,idx*/)
{

var noeudP = noeud.split("_");
noeudP = noeudP[1] + "_body";
IniatilisePid(false,noeudP);

var choix = document.getElementById(idsearch);
IniatilisePid(false,noeud);
//alert(choix.selectedIndex);
if (choix.options[choix.selectedIndex].value > 0)
{
Affiche(choix.options[choix.selectedIndex].value,noeud);
AfficheById(noeud);

}
else
{
var noeud= choix.options[choix.selectedIndex].value;
AfficheById(noeud);
IniatilisePid(true,noeud);
}
//all
if(choix.selectedIndex == 0)
{
var noeud= choix.options[choix.selectedIndex].value;
AfficheById(noeud);
IniatilisePid(true,noeud);

}
//else
//{
//IniatilisePid(true,noeud);

//}

}

function resrEx(noeud,idsearch/*,idx*/)
{


var choix = document.getElementById(idsearch);
IniatilisePid(false,noeud);
//alert(choix.selectedIndex);
if (choix.options[choix.selectedIndex].value > 0)
{
Affiche(choix.options[choix.selectedIndex].value,noeud);

}
else
{
IniatilisePid(true,noeud);

}

}

function AfficheById(id)
{

var idx = document.getElementById(id);
if(idx)
{
if (idx.style.display == "none")
{
idx.style.display = "block";

}
}
}
//affiche le TR voulu
function Affiche(indice,noeud)
{

var Listeproduits = document.getElementById(noeud).childNodes;
var cpt = 0;
var cpt2 = 0;
      for(i=0;i<Listeproduits.length;i++)
    {


    //var attributval = Listeproduits.attributes[0].nodeName;

    var name = Listeproduits[i].nodeName;
    //var attribut = Listeproduits[i].attributes[0].nodeName;
    //var valeur = Listeproduits[i].nodeValue;
    var elements = Listeproduits.item(i);

        if(name == "TR")
        {
            cpt2 =  cpt2 + 1;
           // cpt2++;
              //alert("indice : " +indice + "compteur: " + cpt2);
            if (indice ==  elements.getAttribute("id"))
            {
          
           // elements.setAttribute("id",idx+"_pid_"+cpt);
            elements.style.display = "block";

            cpt++;
            
            //Listeproduits[i].setAttribute("id","pid_"+i)
            //alert(Listeproduits[i].getAttribute("id"));
            }
        }
          if(name == "TABLE")
        {
            cpt2 =  cpt2 + 1;
           // cpt2++;
              //alert("indice : " +indice + "compteur: " + cpt2);
             var testid = elements.getAttribute("id");
            if (indice ==  elements.getAttribute("id"))
            {
          
           // elements.setAttribute("id",idx+"_pid_"+cpt);
            elements.style.display = "block";

            cpt++;
            
            //Listeproduits[i].setAttribute("id","pid_"+i)
            //alert(Listeproduits[i].getAttribute("id"));
            }
        }
         if(name == "DIV")
        {

            if (isShow)
            {

          //  elements.setAttribute("id",idx+"_pid_"+cpt);
            //elements.setAttribute("style","display:block");
            elements.style.display = "block";
            //elements.getAttribute("id");
            }
                else
                {
               // elements.setAttribute("id",idx+"_pid_"+cpt);
                elements.style.display = "none";
                }
        cpt++;
        //Listeproduits[i].setAttribute("id","pid_"+i)
        //alert(Listeproduits[i].getAttribute("id"));
        }
    }
}
function IniatilisePid(isShow,noeud/*,idx*/)
{
var Listeproduits = document.getElementById(noeud).childNodes;
var cpt = 0;
    for(i=0;i<Listeproduits.length;i++)
    {


    //var attributval = Listeproduits.attributes[0].nodeName;

    var name = Listeproduits[i].nodeName;
    //var attribut = Listeproduits[i].attributes[0].nodeName;
    //var valeur = Listeproduits[i].nodeValue;
    var elements = Listeproduits.item(i);

        if(name == "TR")
        {

            if (isShow)
            {

          //  elements.setAttribute("id",idx+"_pid_"+cpt);
            //elements.setAttribute("style","display:block");
            elements.style.display = "block";
            //elements.getAttribute("id");
            }
                else
                {
               // elements.setAttribute("id",idx+"_pid_"+cpt);
                elements.style.display = "none";
                }
        cpt++;
        //Listeproduits[i].setAttribute("id","pid_"+i)
        //alert(Listeproduits[i].getAttribute("id"));
        }
        
        
        if(name == "TABLE")
        {

            if (isShow)
            {

          //  elements.setAttribute("id",idx+"_pid_"+cpt);
            //elements.setAttribute("style","display:block");
            elements.style.display = "block";
            //elements.getAttribute("id");
            }
                else
                {
               // elements.setAttribute("id",idx+"_pid_"+cpt);
                elements.style.display = "none";
                }
        cpt++;
        //Listeproduits[i].setAttribute("id","pid_"+i)
        //alert(Listeproduits[i].getAttribute("id"));
        }
        
         if(name == "DIV")
        {

            if (isShow)
            {

          //  elements.setAttribute("id",idx+"_pid_"+cpt);
            //elements.setAttribute("style","display:block");
            elements.style.display = "block";
            //elements.getAttribute("id");
            }
                else
                {
               // elements.setAttribute("id",idx+"_pid_"+cpt);
                elements.style.display = "none";
                }
        cpt++;
        //Listeproduits[i].setAttribute("id","pid_"+i)
        //alert(Listeproduits[i].getAttribute("id"));
        }
    }
}


function IniatilisePidEx(isShow,noeud,idnoeud)
{
var Listeproduits = document.getElementById(noeud).childNodes;
var cpt = 0;
    for(i=0;i<Listeproduits.length;i++)
    {


    //var attributval = Listeproduits.attributes[0].nodeName;

    var name = Listeproduits[i].nodeName;
    var elements = Listeproduits.item(i);

        if(name == "TR")
        {

            if (isShow)
            {

          //  elements.setAttribute("id",idx+"_pid_"+cpt);
            //elements.setAttribute("style","display:block");
            elements.style.display = "block";
            //elements.getAttribute("id");
            }
                else
                {
               // elements.setAttribute("id",idx+"_pid_"+cpt);
                elements.style.display = "none";
                }
        cpt++;
        //Listeproduits[i].setAttribute("id","pid_"+i)
        //alert(Listeproduits[i].getAttribute("id"));
        }
        
        
        if(name == "TABLE")
        {

            if (isShow)
            {

          //  elements.setAttribute("id",idx+"_pid_"+cpt);
            //elements.setAttribute("style","display:block");
            elements.style.display = "block";
            //elements.getAttribute("id");
            }
                else
                {
               // elements.setAttribute("id",idx+"_pid_"+cpt);
                elements.style.display = "none";
                }
        cpt++;
        //Listeproduits[i].setAttribute("id","pid_"+i)
        //alert(Listeproduits[i].getAttribute("id"));
        }
        
         if(name == "DIV" )
        {
         var attribut = Listeproduits[i].attributes["id"].nodeName;
         var attributval = Listeproduits[i].attributes["id"].nodeValue;
           if (attributval == idnoeud  )
           {
            if (isShow)
            {

          //  elements.setAttribute("id",idx+"_pid_"+cpt);
            //elements.setAttribute("style","display:block");
            elements.style.display = "block";
            //elements.getAttribute("id");
            }
                else
                {
               // elements.setAttribute("id",idx+"_pid_"+cpt);
                elements.style.display = "none";
                }
        cpt++;
        //Listeproduits[i].setAttribute("id","pid_"+i)
        //alert(Listeproduits[i].getAttribute("id"));
           }
        }
    }
}


function AfficheEx(isShow,noeud)
{
var Listeproduits = document.getElementById(noeud).childNodes;
    for(i=0;i<Listeproduits.length;i++)
    {


    //var attributval = Listeproduits.attributes[0].nodeName;

    var name = Listeproduits[i].nodeName;
    //var attribut = Listeproduits[i].attributes[0].nodeName;
    //var valeur = Listeproduits[i].nodeValue;
    var elements = Listeproduits.item(i);

        if(name == "SELECT")
        {

            if (isShow)
            {

       
            elements.style.display = "block";
          
            }
                else
                {
            
                elements.style.display = "none";
                }
     
       
        }
    }
}


function selectChoixExa(idchoix,noeud,isShow,va)
{
var noeud2;
var isShow;
var choix = document.getElementById(idchoix);
var valchoix = choix.options[choix.selectedIndex].value;
var typesauce = document.getElementById(valchoix);

    AfficheEx(false,noeud);
    if (typesauce)
    {
    typesauce.style.display ="block";
    }

//true
if (isShow)
{
switch(valchoix)
{
//partie soupe

case "ctl07_soupe_d":
noeud2 ="tabs_soupe_d";
break;

case "ctl07_soupe_i":
noeud2 ="tabs_soupe_i";

break;

case "ctl07_soupe_l":
noeud2 ="tabs_soupe_l";
break;

//partie sauce
case "ctl07_sauce_d":
noeud2 = "tabs_sauce_d";
break;

case "ctl07_sauce_liq":
noeud2 ="tabs_sauce_liq";
break;

//bouillons
case "ctl07_bouillon_bouillon":
noeud2 ="tabs_bouillon";
break;

case "ctl07_bouillon_culinaire":
noeud2 ="tabs_bouillon_culinaire";
break;


default:
break;


}
var noeudparent = valchoix.split("_");
noeudparent = noeudparent[1] + "_body";
 if (noeud2 !="")
 {
    IniatilisePid(false,noeudparent);
    
    IniatilisePidEx(isShow,noeudparent,noeud2);
 
 }
}

}





function selectChoix(idchoix,noeud,isShow)
{
var noeud2;
var isShow;
var choix = document.getElementById(idchoix);
var valchoix = choix.options[choix.selectedIndex].value;
var typesauce = document.getElementById(valchoix);

    AfficheEx(false,noeud);
    if (typesauce)
    {
    typesauce.style.display ="block";
    }
//alert("yoo");
//true
if (isShow)
{
//int i = valchoix.indexOf("_");
var ret ="";
var matchstring ="";
//ret = valchoix.split("_");
var test = valchoix.substring(0,1);
//alert(test);
if(test != "_")
{
ret = valchoix.split("_");
matchstring = ret[1]+"_" +ret[2];
}
else
{

ret = valchoix.split("_");
matchstring = ret[2]+"_" +ret[3];
//valchoix = ret[2]+"_" +ret[3];

}
//alert(matchstring);
switch(matchstring)
{
//partie soupe

case "soupe_d":
noeud2 ="tabs_soupe_d";
break;

case "soupe_i":
noeud2 ="tabs_soupe_i";

break;

case "soupe_l":
noeud2 ="tabs_soupe_l";
break;

//partie sauce
case "sauce_d":
noeud2 = "tabs_sauce_d";
break;

case "sauce_liq":
noeud2 ="tabs_sauce_liq";
break;

//bouillons
case "bouillon_bouillon":
noeud2 ="tabs_bouillon_bouillon";
break;

case "bouillon_culinaire":
noeud2 ="tabs_bouillon_culinaire";
break;


default:
break;


}
//alert("valeur choix :"+valchoix);
var test2 = valchoix.substring(0,1);
if (test2 != "_")
{
var noeudparent = valchoix.split("_");
noeudparent = noeudparent[1] + "_body";
//alert("noeud 2: "+noeud2);
//alert("noeudparent : "+noeudparent);
 if (noeud2 !="")
 {
    IniatilisePid(false,noeudparent);
    
    IniatilisePidEx(isShow,noeudparent,noeud2);
 
 }
 }
 
 else
 
 {
  var noeudparent = valchoix.split("_");
 noeudparent = noeudparent[2] + "_body";
//alert("noeud 2: "+noeud2);
//alert("noeudparent : "+noeudparent);
 if (noeud2 !="")
 {
    IniatilisePid(false,noeudparent);
    
    IniatilisePidEx(isShow,noeudparent,noeud2);
 
 }
 }
}

}

function selectChoix2(idchoix,noeud,isShow)
{
var noeud2;
var isShow;
var choix = document.getElementById(idchoix);
var valchoix = choix.options[choix.selectedIndex].value;
var typesauce = document.getElementById(valchoix.ClientID);

    AfficheEx(false,noeud);
    if (typesauce)
    {
    typesauce.style.display ="block";
    }

//true
if (isShow)
{
switch(valchoix)
{
//partie soupe
case "soupe_d":
noeud2 ="tabs_soupe_d";
break;

case "soupe_i":
noeud2 ="tabs_soupe_i";

break;

case "soupe_l":
noeud2 ="tabs_soupe_l";
break;

//partie sauce
case "sauce_d":
noeud2 ="tabs_sauce_d";
break;

case "sauce_liq":
noeud2 ="tabs_sauce_liq";

break;


default:
break;


}
var noeudparent = valchoix.split("_");
noeudparent = noeudparent[1] + "_body";
 if (noeud2 !="")
 {
    IniatilisePid(false,noeudparent);
    
    IniatilisePidEx(isShow,noeudparent,noeud2);
 
 }
}

}

  function show(id)
        {
        
        if(document.getElementById(id).style.display == "none")
          {  
          
          document.getElementById(id).style.display = "block";
          
          
          }
            
            else
            {
            
            document.getElementById(id).style.display = "none";
            }
}

function fnOpenRecipe(strURL) {
		self.open(strURL,"Recettes","toolbar=0,location=0,directories=0,status=0,scrollbars=yes,resizable=0,copyhistory=0,menuBar=0,width=550,height=550");
}

function Info(strURL) {
		self.open(strURL,"Info","toolbar=0,location=0,directories=0,status=0,scrollbars=yes,resizable=0,copyhistory=0,menuBar=0,width=450,height=400");
}


function fnOpenImage(strURL) {
		self.open(strURL,"Recettes","toolbar=0,location=0,directories=0,status=0,scrollbars=yes,resizable=0,copyhistory=0,menuBar=0,width=480,height=525");
}
function redimImage(inImg, inMW, inMH)
{
  // Cette function recoit 3 parametres
  // inImg : Chemin relatif de l'image
  // inMW  : Largeur maximale
  // inMH   : Hauteur maximale
  var maxWidth = inMW;
  var maxHeight = inMH;
  // Declarations des variables "Nouvelle Taille"
  var dW = 0;
  var dH = 0;
  // Declaration d'un objet Image
  var oImg = new Image();
  // Affectation du chemin de l'image a l'objet
  oImg.src = inImg;
  // On recupere les tailles reelles
  var h = dH = oImg.height;
  var w = dW = oImg.width;
  // Si la largeur ou la hauteur depasse la taille maximale
  if ((h >= maxHeight) || (w >= maxWidth)) {
    // Si la largeur et la hauteur depasse la taille maximale
    if ((h >= maxHeight) && (w >= maxWidth)) {
      // On cherche la plus grande valeur
      if (h > w) {
        dH = maxHeight;
        // On recalcule la taille proportionnellement
        dW = parseInt((w * dH) / h, 10);
      } else {
        dW = maxWidth;
        // On recalcule la taille proportionnellement
        dH = parseInt((h * dW) / w, 10);
      }
    } else if ((h > maxHeight) && (w < maxWidth)) {
      // Si la hauteur depasse la taille maximale
      dH = maxHeight;
        // On recalcule la taille proportionnellement
      dW = parseInt((w * dH) / h, 10);
    } else if ((h < maxHeight) && (w > maxWidth)) {
      // Si la largeur depasse la taille maximale
      dW = maxWidth;
        // On recalcule la taille proportionnellement
      dH = parseInt((h * dW) / w, 10);
    }
  }
  // On ecrit l'image dans le document
  document.writeln("<img src=\"" + inImg + "\" width=\"" + dW + "\" height=\"" + dH + "\" border=\"0\">");
}

  function ouvre(page) { 

       window.open(page,'','menubar=no, status=no, scrollbars=yes, width=600, height=450');
}

  function ouvreTop(page) { 

       window.open(page,'','menubar=no, status=no, scrollbars=yes, width=550, height=450');
}

  function ouvreEx(page,widht,heigth) { 

       window.open(page,'',"menubar=no, status=no, scrollbars=yes, width="+widht+", height="+heigth+"");
}


