// Common

var d=document;
var BASE_URL='http://localhost/eclisse';
var IMAGES_URL=BASE_URL+'images/';
var COMMON_URL=BASE_URL+'common/';
var SECTION_URL='';

var XH=null;

function removeAllChild(obj)
{
  if(typeof(obj)=='string')
    {obj=d.getElementById(obj);}
  if(obj)
  {
    while(obj.firstChild)
      {obj.removeChild(obj.firstChild);}
  }
}

function setEvent(obj,ev,fnc)
{
  if(typeof(obj)=='string')
    {obj=d.getElementById(obj);}

  if(BROWSER=='Internet Explorer')
    {obj[ev]=new Function(fnc);}
  else
    {obj.setAttribute(ev,fnc);}
}

var timeouts=new Array();

function setVisibility(e,f,v,fd,af,at,oc)
{
  if(typeof(e)=='string')
    {e=d.getElementById(e);}

  if(e)
  {
    if(!fd || noFade)
    {
      if(f=='visibility')
        {e.style.visibility=v;}
      else if(f=='display')
        {e.style.display=v;}

      if(typeof(oc)=='function')
        {oc();}
    }
    else
    {
      if(!(af>=0) || !(at>=0))
      {
        if((f=='visibility' && v=='hidden') || (f=='display' && v=='none'))
        {
          af=100;
          at=0;
        }
        else
        {
          af=0;
          at=100;
        }
      }


      setVisibilityFade(e,f,v,af,at,oc);
    }
  }
}

function  setVisibilityFade(e,f,v,af,at,oc)
{
  if(typeof(e)=='string')
    {e=d.getElementById(e);}

  if(e)
  {
    if((f=='visibility' && v=='hidden') || (f=='display' && v=='none'))
    {
      if(!timeouts[e.id])
      {
        timeouts[e.id]=new Array();
        timeouts[e.id]['opacity']=af;
        if(BROWSER=='Internet Explorer')
          {e.style.filter='alpha(opacity='+(timeouts[e.id]['opacity'])+')';}
        else
          {e.style.opacity=(timeouts[e.id]['opacity']/100);}
        timeouts[e.id]['eventId']=window.setTimeout("setVisibilityFade('"+e.id+"','"+f+"','"+v+"','"+af+"','"+at+"')",5);
        if(typeof(oc)=='function')
          {timeouts[e.id]['oc']=oc;}
      }
      else
      {
        window.clearTimeout(timeouts[e.id]['eventId']);
        if(timeouts[e.id]['opacity']>at)
        {
          if(timeouts[e.id]['opacity']>=85)
            {timeouts[e.id]['opacity']-=5;}
          else if(timeouts[e.id]['opacity']>=60)
            {timeouts[e.id]['opacity']-=10;}
          else if(timeouts[e.id]['opacity']>=40)
            {timeouts[e.id]['opacity']-=15;}
          else
            {timeouts[e.id]['opacity']-=25;}

          if(timeouts[e.id]['opacity']<0)
            {timeouts[e.id]['opacity']=0;}

          if(BROWSER=='Internet Explorer')
            {e.style.filter='alpha(opacity='+(timeouts[e.id]['opacity'])+')';}
          else
            {e.style.opacity=(timeouts[e.id]['opacity']/100);}
          timeouts[e.id]['eventId']=window.setTimeout("setVisibilityFade('"+e.id+"','"+f+"','"+v+"','"+af+"','"+at+"')",5);
        }
        else
        {
          setVisibility(e.id,f,v);
          if(typeof(timeouts[e.id]['oc'])=='function')
            {timeouts[e.id]['oc']();}
          delete timeouts[e.id];
        }
      }
    }
    else
    {
      if(!timeouts[e.id])
      {
        timeouts[e.id]=new Array();
        timeouts[e.id]['opacity']=af;
        if(BROWSER=='Internet Explorer')
          {e.style.filter='alpha(opacity='+(timeouts[e.id]['opacity'])+')';}
        else
          {e.style.opacity=(timeouts[e.id]['opacity']/100);}
        setVisibility(e.id,f,v);
        timeouts[e.id]['eventId']=window.setTimeout("setVisibilityFade('"+e.id+"','"+f+"','"+v+"','"+af+"','"+at+"')",5);
      }
      else
      {
        window.clearTimeout(timeouts[e.id]['eventId']);
        if(timeouts[e.id]['opacity']<at)
        {
          if(timeouts[e.id]['opacity']>=70)
            {timeouts[e.id]['opacity']+=5;}
          else if(timeouts[e.id]['opacity']>=40)
            {timeouts[e.id]['opacity']+=10;}
          else
            {timeouts[e.id]['opacity']+=15;}

          if(timeouts[e.id]['opacity']>100)
            {timeouts[e.id]['opacity']=100;}

          if(BROWSER=='Internet Explorer')
            {e.style.filter='alpha(opacity='+(timeouts[e.id]['opacity'])+')';}
          else
            {e.style.opacity=(timeouts[e.id]['opacity']/100);}
          timeouts[e.id]['eventId']=window.setTimeout("setVisibilityFade('"+e.id+"','"+f+"','"+v+"','"+af+"','"+at+"')",5);
        }
        else
          {delete timeouts[e.id];}
      }
    }
  }
}

function clearTimeouts()
{
  for(var i=0;i<timeouts.length;i++)
    {window.clearTimeout(timeouts[i]['eventId']);}
  timeouts=new Array();
}

function getVisibility(e,f)
{
  if(typeof(e)=='string')
    {e=d.getElementById(e);}

  if(e)
  {
    if(f=='visibility')
      {return e.style.visibility;}
    else if(f=='display')
      {return e.style.display;}
  }
}

function getXPos(obj)
{
  if(typeof(obj)=='string')
    {obj=d.getElementById(obj);}

  if(obj)
  {
    var curleft=0;
    if(obj.offsetParent)
    {
      while(obj.offsetParent)
      {
        curleft+=obj.offsetLeft
        obj=obj.offsetParent;
      }
    }
    else if (obj.x)
      curleft+=obj.x;
    return curleft;
  }
  else
    {return -1;}
}

function getYPos(obj)
{
  if(typeof(obj)=='string')
    {obj=d.getElementById(obj);}

  if(obj)
  {
    var curtop=0;
    if(obj.offsetParent)
    {
      while(obj.offsetParent)
      {
        curtop+=obj.offsetTop
        obj=obj.offsetParent;
      }
    }
    else if (obj.y)
      curtop+=obj.y;
    return curtop;
  }
  else
    {return -1;}
}

function getInnerWindowWidth()
{
  if (!window.innerWidth)
    {return d.documentElement.clientWidth;}
  else
    {return window.innerWidth;}
}

function getInnerWindowHeight()
{
  if(!window.innerHeight)
    {return d.documentElement.clientHeight;}
  else
    {return window.innerHeight;}
}

function windowCenterX()
{
  if(d.documentElement.scrollLeft>=0)
    {return getInnerWindowWidth()/2+d.documentElement.scrollLeft;}
  else
    {return getInnerWindowWidth()/2+window.pageXOffset;}
}

function windowCenterY()
{
  return getInnerWindowHeight()/2+pageScrollTop();
}

function pageScrollTop()
{
  if(d.documentElement.scrollTop>=0)
    {return d.documentElement.scrollTop;}
  else
    {return window.pageYOffset;}
}

function setFullScreenHeight(obj)
{
  if(typeof(obj)=='string')
    {obj=d.getElementById(obj);}

  obj.style.height=(d.getElementById('dBody').offsetHeight>getInnerWindowHeight())?d.getElementById('dBody').offsetHeight+'px':getInnerWindowHeight()+'px';
}

function loadArray(s,d)
{
  return s.split(d);
}

function showLoadingOverlay()
{
  showOverlayFullScreen('loadingOverlay');
  setVisibility('loadingOverlay','visibility','visible',true,0,50);
}

function hideLoadingOverlay()
{
  setVisibility('loadingOverlay','visibility','hidden',true,50,0,hideOverlayFullScreen('loadingOverlay'));
}

function showOverlayFullScreen(obj)
{
  if(typeof(obj)=='string')
    {obj=d.getElementById(obj);}

  if(obj)
  {
    obj.style.width='100%';
    obj.style.height='100%';
  }
}

function hideOverlayFullScreen(obj)
{
  if(typeof(obj)=='string')
    {obj=d.getElementById(obj);}

  if(obj)
  {
    obj.style.width='0px';
    obj.style.height='0px';
  }
}

function onLoad()
{
  getBrowser();
}

function onUnload()
{
  if(typeof(onUnloadPage)=='function')
    {onUnloadPage();}
}

function createXMLHttpRequest()
{
  if (window.ActiveXObject)
    {return new ActiveXObject("Microsoft.XMLHTTP");}
  else if (window.XMLHttpRequest)
    {return new XMLHttpRequest();}
}




// Browser Detection

var BROWSER='';
var BROWSER_VERSION='';
var BROWSER_VERSION_NUMBER='';

function getBrowser()
{
  var uA=navigator.userAgent;
  if(uA.indexOf('Opera')!=-1)
  {
    BROWSER='Opera';
    var s=uA.indexOf('Opera')+6;
    var e=uA.indexOf(' ',s);
    if(e>0)
      {BROWSER_VERSION=uA.substr(s,e-s);}
    else
      {BROWSER_VERSION=uA.substr(s);}
  }
  else if (uA.indexOf('MSIE')!=-1)
  {
    BROWSER='Internet Explorer';
    var s=uA.indexOf('MSIE ')+4;
    var e=uA.indexOf(';',s);
    BROWSER_VERSION=uA.substr(s,e-s);
  }
  else if (uA.indexOf('Firefox')!=-1)
  {
    BROWSER='Firefox';
    BROWSER_VERSION=uA.substr(uA.indexOf('Firefox/')+8);
  }
  else if (uA.indexOf('Safari')!=-1)
  {
    BROWSER='Safari';
    if(uA.indexOf('Version')!=-1)
      {BROWSER_VERSION=uA.substr(uA.indexOf('Version/')+8,(uA.indexOf(' ',uA.indexOf('Version/')+8))-(uA.indexOf('Version/')+8));}
    else
      {BROWSER_VERSION=uA.substr(uA.indexOf('safari/')+7);}
  }
  else if ((uA.indexOf('mozilla/5.0')!=-1) && (uA.indexOf('rv:')!=-1) && (uA.indexOf('gecko/')!=-1))
  {
    BROWSER='Mozilla';
    var s=uA.indexOf('rv:')+3;
    var e=uA.indexOf(')',s);
    if(e>0)
      {BROWSER_VERSION=uA.substr(s,e-s);}
    else
      {BROWSER_VERSION=uA.substr(s);}
  }

  if(BROWSER_VERSION!='')
  {
    var fp=true;
    var index=0;
    for(var i=0;i<BROWSER_VERSION.length;i++)
    {
      if(BROWSER_VERSION[i]>=0)
        {index=i;}
      else if(BROWSER_VERSION[i]=='.' && fp)
      {
        index=i;
        fp=false;
      }
      else
        {break;}
    }
    BROWSER_VERSION_NUMBER=BROWSER_VERSION.substr(0,index+1);

    if(!(BROWSER_VERSION_NUMBER>0))
      {BROWSER_VERSION_NUMBER='';}
  }
}

function checkIntRT(str)
{
  return str.replace(/([^0-9\-])+/g,'');
}

function checkFloatRT(str)
{
  return str.replace(/([^0-9.\-])+/g,'');
}










function selMod(id)
{
  d.location='index.php?a=wizard_param&p=selmod&ra=wizard_selspe&id='+id;
}

function selModAttr(id,idv)
{
  d.location='index.php?a=wizard_param&p=selmodattr&ra=wizard_selspe&id='+id+'&idv='+idv;
}

function selAccAttr(id,idv)
{
  d.location='index.php?a=wizard_param&p=selaccattr&ra=wizard_selacc&id='+id+'&idv='+idv;
}

function selAccAcc(id,idt,obj)
{
  var url='index.php?a=wizard_param&p=selaccacc&ra=wizard_selacc&id='+id+'&idt='+idt;

  if(id>0)
  {
    if(idt==2 || idt==8)
    {
      if(input=d.getElementById('exd_A_'+idt))
      {
        if(input.value>0)
          {url=url+'&'+input.name+'='+input.value;}
        else
        {
          alert('Completare il campo A');
          d.getElementById('accessori_'+idt+'_0').checked=true;
          obj.checked=false;
          return;
        }
      }
      if(input=d.getElementById('exd_H_'+idt))
      {
        if(input.value>0)
          {url=url+'&'+input.name+'='+input.value;}
        else
        {
          alert('Completare il campo H');
          d.getElementById('accessori_'+idt+'_0').checked=true;
          obj.checked=false;
          return;
        }
      }
      if(input=d.getElementById('exd_SensoApertura_'+idt))
      {
        if(input.value!='')
          {url=url+'&'+input.name+'='+input.value;}
        else
        {
          alert('Selezionare il senso di apertura');
          d.getElementById('accessori_'+idt+'_0').checked=true;
          obj.checked=false;
          return;
        }
      }
      if(input=d.getElementById('exd_NTraversi_'+idt))
      {
        if(input.value>0)
          {url=url+'&'+input.name+'='+input.value;}
        else
        {
          if(d.getElementById('exd_H_'+idt).value*d.getElementById('exd_A_'+idt).value<2000000)
            {url=url+'&'+input.name+'=0';}
          else
          {
            alert('Inserire il numero di traversi');
            d.getElementById('accessori_'+idt+'_0').checked=true;
            obj.checked=false;
            return;
          }
        }
      }
      if(input=d.getElementById('exd_SpessorePareteFinita_'+idt))
      {
        if(input.value!='')
          {url=url+'&'+input.name+'='+input.value;}
        else
        {
          alert('Completare il campo Spessore Parete Finita');
          d.getElementById('accessori_'+idt+'_0').checked=true;
          obj.checked=false;
          return;
        }
      }

      if(input=d.getElementById('exd_SpessoreRivestimentoLS_'+idt))
      {
        if(input.value!='')
          {url=url+'&'+input.name+'='+input.value;}
        else
        {
          alert('Completare il campo Spessore Rivestimento');
          d.getElementById('accessori_'+idt+'_0').checked=true;
          obj.checked=false;
          return;
        }
      }
      if(input=d.getElementById('exd_SpessoreRivestimentoLNS_'+idt))
      {
        if(input.value!='')
          {url=url+'&'+input.name+'='+input.value;}
        else
        {
          alert('Completare il campo Spessore Rivestimento');
          d.getElementById('accessori_'+idt+'_0').checked=true;
          obj.checked=false;
          return;
        }
      }
    }
    else if(idt==25)
    {
      if(input=d.getElementById('exd_colore_RAL_'+idt))
      {
        if(input.value!='')
          {url=url+'&'+input.name+'='+escape(input.value);}
        else
        {
          alert('Selezionare il Colore RAL');
          d.getElementById('accessori_'+idt+'_0').checked=true;
          obj.checked=false;
          return;
        }
      }
    }
  }

  d.location=url;
}

function wizardAggiungiCarrello()
{
  d.location='index.php?a=carrello_modifica&f=aggiungi_wizard&ra=carrello&quantita='+d.getElementById('quantita').value;
}

function svuotaCarrello()
{
  if (window.confirm('Sei sicuro?')==1)
  {
    d.location='index.php?a=carrello_modifica&f=svuota&ra=carrello';
  }
}

function ordine()
{
  if(d.getElementById('id_cliente'))
    {id_cliente=d.getElementById('id_cliente').value;}
  else
    {id_cliente=0;}
  d.location='index.php?a=ordine&id_cliente='+id_cliente;
}

function eliminaSelezionati()
{
  frm=d.getElementById('formCarrello');
  frm.f.value="elimina_selezionati";
  frm.submit();
}

function aggiornaQuantita()
{
  frm=d.getElementById('formCarrello');
  frm.f.value="aggiorna";
  frm.submit();
}

function aggiornaIntestazione()
{
  frm=d.getElementById('formModIntestazione');
  frm.f.value="aggiornaint";
  frm.submit();
}


function visualizzaDecori()
{
  window.open('popup.php?a=foto_decori','foto_decori','location=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=no,width=1000,height=600');
}

function selezionaPorta(id)
{
  opt=window.opener.d.getElementById('accessori_20_'+id);
  if(opt)
  {
    opt.checked=true;
    window.opener.d.location='index.php?a=wizard_param&p=selaccacc&ra=wizard_selacc&id='+id+'&idt='+20;
    window.close();
  }
}

function visualizzaInferriate()
{
  window.open('popup.php?a=inferriate','foto_decori','location=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=no,width=1000,height=600');
}

function selezionaInferriata(id)
{
  opt=window.opener.d.getElementById('accessori_25_'+id);
  if(opt)
  {
    opt.checked=true;
    window.opener.d.location='index.php?a=wizard_param&p=selaccacc&ra=wizard_selacc&id='+id+'&idt='+25;
    window.close();
  }
}

function cambiaPassword()
{
  frm=d.getElementById('formCambiaPassword');
  if(!(frm.password_attuale.value!=''))
    {alert('É necessario inserire la Password Attuale');}
  else if(!(frm.nuova_password.value!=''))
    {alert('É necessario inserire la Nuova Password');}
  else if(frm.nuova_password.value!=frm.conferma_password.value)
    {alert('Le password inserite non coincidono');}
  else
    {frm.submit();}
}

function BCselIntCart(v)
{
  d.location='index.php?a=browser_catalogo&filter=1&intcart='+v;
}

function BCselIntExt(v)
{
  d.location='index.php?a=browser_catalogo&filter=1&intext='+v;
}

function BCselVal(n,v)
{
  d.location='index.php?a=browser_catalogo&filter=1&'+n+'='+v;
}

function salvaOrdine()
{
  if(d.getElementById('id_cliente'))
    {d.location='index.php?a=salva_ordine&id_cliente='+d.getElementById('id_cliente').value+'&note='+escape(d.getElementById('note').value);}
  else if(d.getElementById('riferimento'))
    {d.location='index.php?a=salva_ordine&rif='+escape(d.getElementById('riferimento').value)+'&note='+escape(d.getElementById('note').value);}
  else
    {d.location='index.php?a=salva_ordine';}
}

function cancellaOrdine(id)
{
  if (window.confirm('Sei sicuro?')==1)
  {
    d.location='index.php?a=cancella_ordine&id='+id;
  }
}

function caricaOrdine(id)
{
  d.location='index.php?a=carica_ordine&id='+id;
}

function stampaCarrello(id,rs,tc)
{
  window.open('stampe/stampa_carrello.php?id='+id+'&rs='+rs+'&tc='+tc,'','location=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,width=800,height=600');
}

function stampaCarrelloUtente(id)
{
  window.open('stampe/stampa_carrello_utente.php?id='+id,'','location=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,width=800,height=600');
}

function stampaOrdine(id)
{
  window.open('stampe/stampa_modulo_ordine.php?id='+id,'','location=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,width=800,height=600');
}

function offertaXLS(id)
{
  window.open('stampe/esporta_ordine_csv.php?id='+id,'','location=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,width=800,height=600');
}

function confermaOrdine(id)
{
  if (window.confirm('Stai per confermare l\'ordine. Procedere?')==1)
  {
    if(d.getElementById('id_cliente'))
      {d.location='index.php?a=salva_ordine&conferma=1&id_cliente='+d.getElementById('id_cliente').value;}
    else if(d.getElementById('riferimento'))
      {d.location='index.php?a=salva_ordine&conferma=1&conferma=1&rif='+escape(d.getElementById('riferimento').value);}
    else
      {d.location='index.php?a=salva_ordine&conferma=1';}
  }
}

function confermaOrdineSalvato(id)
{
  if (window.confirm('Stai per confermare l\'ordine. Procedere?')==1)
  {
    d.location='index.php?a=conferma_ordine&id='+id;
  }
}

function ricerca()
{
  qc=d.getElementById('qCodice').value;
  if(qc.indexOf('/')==-1)
    {d.location='index.php?a=pric&c='+qc;}
  else
    {alert('Attenzione! Il codice inserito corrisponde a più prodotti. Per la scelta corretta proseguire nella sezione “Non conosci il prodotto?”');}
}

function inviaContatto()
{
  frm=d.getElementById('formContatto');
  if(!(frm.descrizione.value!=''))
    {alert('É necessario completare il campo Descrizione');}
  else
    {frm.submit();}
}

function goHome()
{
  d.location='index.php';
}

function ah2m(el)
{
  id=el.id.substr(5);
  a=parseInt(d.getElementById('exd_A'+id).value);
  h=parseInt(d.getElementById('exd_H'+id).value);
  if(a*h>=2000000)
    {setVisibility('ah2m','display','block');}
  else
    {setVisibility('ah2m','display','none');}
}

function scaricaProgetto(id)
{
  window.open('stampe/esporta_carrello_progetto.php?id='+id,'','location=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,width=800,height=600');
}

function hrefSpessoreKitCart(url,sd)
{
  sp=prompt('Inserire lo spessore della parete finita (100mm/125mm)',100)
  sp=parseInt(sp.substr(0,3));
  if(sp==100 || sp==125)
    {d.location=url+'&spf='+sp;}
  else
    {alert('Inserire un valore corretto');}
}



$(function(){
  action=$('body').attr('className');

  if(action=='browser_catalogo')
  {
    $("#menuItem2").simpletip({ persistent: false, position: 'right', offset: [-140, 0], content: 'SENZA STIPITI NÉ COPRIFILI' });
    $("#menuItem8").simpletip({ persistent: false, position: 'right', offset: [-140, 0], content: 'PANNELLO PORTA + STIPITI + COPRIFILI' });
    $("#menuItem3").simpletip({ persistent: false, position: 'right', offset: [-140, 0], content: 'CONTROTELAIO + PANNELLO PORTA + STIPITI + COPRIFILI + KIT DI CHIUSURA' });
    $("#menuItem11").simpletip({ persistent: false, position: 'right', offset: [-120, 0], content: 'PORTE IN VETRO ALLUMINIO' });

    $('a.fotoAcc').fancybox({'overlayOpacity': 0.7, 'overlayColor': '#000000'});
  }
  else if(action=='wizard_selacc')
  {
    $('a.fotoAcc').fancybox({'overlayOpacity': 0.7, 'overlayColor': '#000000'});
    $('a.istrVA').fancybox({'overlayOpacity': 0.7, 'overlayColor': '#000000'});
  }
  else if(action=='carrello')
  {
    $('#aModIntestazione').click(function() {$.blockUI({ message: $('#formModIntestazione'), css: { width: '900px', height: '200px', left:'50%', marginLeft:'-450px', cursor: 'normal' } });});}
});

function impostaRitiro(tf)
{
  d.location='index.php?a=carrello_modifica&f=imprit&rs='+((tf)?'1':'0');
}