﻿// MATY : Fichier Script JS

var all_sel_vis = new Array();

function registerSelect(name)
 {
   c = all_sel_vis.length;
   all_sel_vis[c] = name;
 }
 
function hideSelects()
 {
   if (document.all)
    {
	  for (i=0; i<all_sel_vis.length; i++)
	   {
	  
	     var ob = eval('document.frm.' + all_sel_vis[i]);
	     ob.style.visibility = 'hidden';
	   }
    }
 }

function showSelects()
 {
   if (document.all)
    {
	  for (i=0; i<all_sel_vis.length; i++)
	   {
	     var ob = eval('document.frm.' + all_sel_vis[i]);
	     ob.style.visibility = 'visible';
	   }
    }
 }

function dual(i) { return i>9 ? i : "0" + i; }

function isSKValid(key)
 {
   for (j=0; j<search_nones.length; j++) { if (key==search_nones[j]) { return false; } }
   return true;
 }

function updateMat()
 {
   var bij = document.srfrm.bijou.value;
   var ov  = document.srfrm.matiere.value;
   
   document.srfrm.matiere.length=0; k=0; lk = 0;
  
   for (i=0; i<search_mats.length; i++)
    {
      val = dual(i); key = bij + val;
      
      if (isSKValid(key))
       {
       	  opt = new Option(search_mats[i], val);
       	  document.srfrm.matiere.options[k] = opt;
       	  if (val==ov) { lk = k; }  k++;
       }
    }
    
    document.srfrm.matiere.selectedIndex = lk;
 }
 
function updatePMax()
 {
   var pmax = document.srfrm.pmaxi.selectedIndex;
   var pmin = document.srfrm.pmini.selectedIndex;
      
   if ((pmax>0) && (pmin>pmax)) { document.srfrm.pmaxi.selectedIndex = 0; }
    
 }
 
function updatePMin()
 {
   var pmax = document.srfrm.pmaxi.selectedIndex;
   var pmin = document.srfrm.pmini.selectedIndex;
      
   if ((pmin>0) && (pmin>pmax)) { document.srfrm.pmini.selectedIndex = 0; }
    
 }
var popup=0;

function openPopUp(link, name, w, h)
 {
   var width = w; var height = h; var url = link; popup++;
   if (name!='') { url += "&name="+name; }
   window.open(url, 'cp'+popup, 'resizable=no, location=no, width='+width+', height='+height+', status=no, scrollbars=yes, menubar=no');
 }

function openPagePopUp(link, name)
 {
   var width = 850; var height = 700; var url = link; popup++;
   if (name!='') { url += "&name="+name; }
   window.open(url, 'cp'+popup, 'resizable=yes, location=yes, width='+width+', height='+height+', status=yes, scrollbars=yes, menubar=yes');
 }

function show(id)
{
  var e = document.getElementById(id);
  if (e!=null) { e.style.display='block'; }
}

function hide(id)
{
  var e = document.getElementById(id);
  if (e!=null) { e.style.display='none'; }
}

function toggle(id)
{
  var e = document.getElementById(id);
  
  if (e!=null)
  {
    if (e.style.display=="none") 
     { e.style.display = "block"; }
    else { e.style.display="none"; }
  }
}

// -- fonctions panier


function removeBasket(num)
 {
   str = "Voulez vous vraiment retirer ce bijou ?";
   if (confirm(str)) { location = "remove.aspx?num=" + num; }
 }

function removeEmballage()
 {
    str = "Voulez vous vraiment retirer votre emballage cadeau ?";
    if (confirm(str)) { location = "remove.aspx?emballage=1"; }
 }


// -- fonctions espace client

function delAddy(seq)
 {
   str = "Voulez vous vraiment supprimer cette Adresse Secondaire ?";
   if (confirm(str)) { window.location = "adresses.aspx?clear=" + seq; }
 }
 
 
 
 
 
//Fonction pour modifier la visibilité d'un div via souris ou clic bouton
//VDC : 07/04/2008
function changeVisibilityAndPlaceCurrentDiv(strID, strVisible, strEvent, strInnerHtml)
{

    //si le strID existe
    if (document.getElementById(strID))
    {
        //on reccupere les coordonnées de la souris en fonction des besoins
        if (strEvent != "")
        {
              var mouseX, mouseY;
              
              if (strEvent.x!=null && strEvent.y!=null)
              {
                   mouseX = strEvent.x;
                   mouseY = strEvent.y;// + (document.scrollheight - document.body.Height);
              }
             
              if (strEvent.clientX!=null && strEvent.clientY!=null)
              {
                   mouseX = strEvent.clientX;
                   mouseY = strEvent.clientY;// + (document.scrollheight - document.body.Height);
              }              
              
              mouseY = mouseY + 15 + (document.body.scrollTop || document.documentElement.scrollTop);
              
              document.getElementById(strID).style.left = mouseX;
              document.getElementById(strID).style.top = mouseY;
        }
    
    
        if (strVisible == "")
        {
        
    
            if (document.getElementById(strID).style.visibility != "hidden")
            {
                document.getElementById(strID).style.visibility = "hidden"
            }else{
                document.getElementById(strID).style.visibility = "visible"
                document.getElementById("divDescRef").value = strID;
                document.getElementById(strID).style.left = mouseX;
                document.getElementById(strID).style.top = mouseY;
            }
            
        }else{
            
            //on masque les divs d'info poduit affiche
            /*
            for (var i=0; i<intNbLigne; i++)
            {
                if (intNbLigne != strTableIdAndNumLigne[1])
                {
                    document.getElementById(strID).style.visibility = 'hidden';
                }
            }
            */
            
            //on affiche le div d'infoproduit voulu
            document.getElementById(strID).style.visibility = strVisible;
        
        }
    }
}


//Donne la valeur numerique pour une string de type 12px
function getIntValueFromStyle(strStyle)
{
    return strStyle.replace(/px/,"");
}




//Fonction utilisée pour trouver la coord d'un objet JS
//VDC : 10/04/2008  http://www.quirksmode.org/js/findpos.html
function findPos(obj) 
{
    var curleft = curtop = 0;
	
	if (obj)
	{
        if (obj.offsetParent) 
        {
            do 
            {
		        curleft += obj.offsetLeft;
            } while (obj = obj.offsetParent);
        }   
        return curleft;
        
    }else{
         return 0;
    }
}
    
function findPostop(obj) 
{
    var curleft = curtop = 0;
    
    if (obj)
	{
        if (obj.offsetParent) {
            do {
                    curtop += obj.offsetTop;
            } while (obj = obj.offsetParent);
        }   
        return curtop;
    }else{
        return 0;
    }
    
    
}




//Fonction pour modifier la visibilité d'un div via souris ou clic bouton
//VDC : 07/04/2008
function changeVisibility(strID, strVisible)
{
    //si le strID existe
    if (document.getElementById(strID))
    {       
        if (strVisible == "" || strVisible == undefined)
        {        
            if (document.getElementById(strID).style.visibility != "hidden")
            {
                document.getElementById(strID).style.visibility = "hidden"
            }else{
                document.getElementById(strID).style.visibility = "visible"
                if (document.getElementById("divDescRef"))
                {
                    document.getElementById("divDescRef").value = strID;
                }
                /*
                if (mouseX != undefined)
                {
                    document.getElementById(strID).style.left = mouseX;
                }
                if (mouseY != undefined)
                {
                    document.getElementById(strID).style.top = mouseY;
                }
                */
            }
            
        }else{
            
            document.getElementById(strID).style.visibility = strVisible;
        
        }
    }
}


function openBij()
{
    window.open('http://guidedubijoutier.maty.com/appli.htm','catalogue','scrollbars=no,resizable=yes,status=no,menubar=no');
}