
	//_editor_url = 'http://www.wirelessforum.it/spring/editor/htmlarea2/';          // URL to htmlarea files
	var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
	if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
	if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
	if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }

	if (win_ie_ver >= 5.5) {
		//document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
		//document.write(' language="Javascript1.2"></scr' + 'ipt>');
	} else {
		//document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>');
	}


  function ToggleLayer(layername) {
    if (document.getElementById(layername).style.visibility=='visible') {
      document.getElementById(layername).style.display = 'none';
      document.getElementById(layername).style.visibility = 'hidden';         
    } else {      
      document.getElementById(layername).style.display = 'block';
      document.getElementById(layername).style.visibility = 'visible';   
    }
    
    return false;
  }

  
  function MouseOut(item) {
	  item.style.backgroundColor='';
  }
  function MouseOver(item) {
	  item.style.backgroundColor='#D2FFD2';
  }


  function ShowImage(filename,largh,alt) {
    window.open(filename,"Prodotto",",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,height="+(alt+20)+",width="+(largh+20));
    
  }


  function CheckAndGo(from) {
    if ( (window.event.keyCode==13) || (from==1) ) {
      if (document.frmRicerca.txtWhat.value=='') {
        window.alert('Non è stato inserito il testo da ricercare.');
        return false;
      }
      document.frmRicerca.submit();
      return false;
    }
  }
  
  function ControlloImponibile (minimo) {
  	 if(document.fr_carrello.imponibile.value >= minimo) {
	    return true;
	 } else {
	    alert("Non è stato raggiunto l'importo minimo fatturabile.\nOccorre aggiungere altri prodotti al carrello");
	    return false;
	 }  
  
  }
  
  function cancella(path, nome) {
    var del = confirm(""+nome+"");
	  if (del==true) {
	    comando=path;
 	 	  window.open(comando,"_self");
	   }
    return false;
  }
  
  function CheckNewUser() {
	  if (document.frmSendData.username.value.length<6) {
	    alert("Il nome utente inserito è troppo corto (minimo 6 caratteri).");
	    return false;		    
	  }
  }  

  // -----------------------------------------------------------------------
  // Validazione dei dati immessi nel form di registrazione del carrello
  // Parametri: tipo - tipo di cliente 0 - azienda, 1 - privato
  // -----------------------------------------------------------------------
	function ValidateField(tipo)
	{
	  
		if (document.userData.azienda.value == "") {
		  if (tipo) {
		    alert("La compilazione del campo NOME e COGNOME e' obbligatoria");
		  } else {
  		  alert("La compilazione del campo RAGIONE SOCIALE e' obbligatoria");
  		}
		  return false;
  	}

		if (document.userData.indirizzo.value == "") {
  		alert("La compilazione del campo INDIRIZZO e' obbligatoria");
		  return false;
  	}
		
		if (document.userData.citta.value == "") {
		  alert("La compilazione del campo CITTA e' obbligatoria");
  		return false;
	  }
		
		/*
		if (document.userData.provincia.value == "") {
		  alert("La compilazione del campo PROVINCIA e' obbligatoria");
		  return false;
 	  }
 	  */

		if (document.userData.stato.value == "") {
		  alert("La compilazione del campo STATO e' obbligatoria");
		  return false;
 	  }
		
		if (document.userData.cap.value == "") {
		  alert("La compilazione del campo CAP e' obbligatoria");
  		return false;
	  }

    if (tipo==0) {
      // Azienda
		  if ( (document.userData.partita_iva.value == "") || (document.userData.partita_iva.value.length<6) ) {
		    alert("La compilazione del campo PARTITA IVA e' obbligatoria");
  		  return false;
	    }
	  }

	  if ( (document.userData.codice_fiscale.value == "") || (document.userData.codice_fiscale.value.length<6) ) {
	    alert("La compilazione del campo CODICE FISCALE e' obbligatoria");
		  return false;
    }	    	  

		if (document.userData.telefono.value == "") {
		  alert("La compilazione del campo TELEFONO e' obbligatoria");
  		return false;
	  }
				
		if (!isEmail(document.userData.email.value)) {
		  alert("L'indirizzo email non e' corretto!");
		  return false;
	  }
	  
	  if (document.getElementById("username")!=null) {
	    if (document.userData.username.value.length<6) {
  	    alert("Il nome utente inserito è troppo corto (minimo 6 caratteri).");
  	    return false;		    
  	  }
  	  
  	  if (document.userData.userpwd.value.length<6) {
  	    alert("La password inserita è troppo corta (minimo 6 caratteri).");
  	    return false;
  	  }		  		    		
  	}
  			    
		return true;
	}

  // -----------------------------------------------------------------------
	// Validazione indirizzo email
	// -----------------------------------------------------------------------
	function isEmail (s)
	{    
		// ci deve essere almeno un carattere prima di @
	  var i = 1;
	  var sLength = s.length;
	  
    // cerca @
    while ((i < sLength) && (s.charAt(i) != "@")) { 
      i++
	  }
		
    //ci devono essere almeno due caratteri dopo @
	  if ((i >= sLength) || (s.charAt(i) != "@")) return false;
	  else i += 2;
	  
    // cerca il punto
	  while ((i < sLength) && (s.charAt(i) != ".")) { 
      i++
	  }
	  
    // ci deve essere almeno due caratteri dopo il punto
	  
    if ((i >= sLength - 2) || (s.charAt(i) != ".")) return false;
	  else return true;
	}	

	// -----------------------------------------------------------------------
	// Controlla la quantità da inserire nel carrello
	// Riceve l'oggetto con il testo da controllare e il valore minimo ordinabile
	// -----------------------------------------------------------------------
  function CheckQuantity(fname,minvalue) {    
    if ((fname.value=="") || (fname.value<minvalue) || isNaN(fname.value)) {
	    alert("La quantità inserita deve essere compresa tra "+minvalue+" e 9999, non sono ammessi numeri decimali!");
	    fname.value=minvalue;
	    return false;
	    
	  }
  }

  // -----------------------------------------------------------------------
  // Controlla le quantità inserite nell'intero carrello
  // -----------------------------------------------------------------------
  function CheckQuantityCart() {
    
    for(j=0;j<(document.fr_carrello.elements.length-1);j++){
      var formObj=document.fr_carrello.elements[j];
      if (formObj.type=="text" && ((formObj.value=="") || (formObj.value<=0) || isNaN(formObj.value))) {
	      alert("La quantità inserita deve essere compresa tra 1 e 9999, non sono ammessi numeri decimali!");
	      formObj.value=1;
	      return false;
	    }
    }    

  }
 
  // -----------------------------------------------------------------------
  // Controlla i parametri del form di login
  // -----------------------------------------------------------------------
  function CheckLoginData() {
    
    if ( (document.frmLogin.txtUser.value=='') || (document.frmLogin.txtPwd.value=='') ) {
      window.alert('Non è stato inserito il nome utente o la password.');
      return false;
    }      
    return true;    
    
  }

  // -----------------------------------------------------------------------
  // Controlla i parametri del form di registrazione utente
  // -----------------------------------------------------------------------
  function CheckLoginCustData() {
    
    if ( (document.frmDati.txtUser.value=='') || (document.frmDati.txtPwd.value=='') ) {
      window.alert('Non è stato inserito il nome utente o la password.');
      return false;
    }      
    return true;    
    
  }
  
  // -----------------------------------------------------------------------
  //Link e-mail anti spam
  // -----------------------------------------------------------------------
  function e_mail_link(Server, Login, Display) {
    if ((Display.length == 0) || (Display.indexOf('@')+1)) {
      document.write("<a href=" + "'mai" + "lto:" + Login + "@" + Server + "'>" + Login + "@" + Server + "</a>"); 
    } else {
      document.write("<a href=" + "'mai" + "lto:" + Login + "@" + Server + "'>" + Display + "</a>"); 
    }
  }
    
    
  function PopUp(testo) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(testo, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=300');");
    
  }
    
    
  // -----------------------------------------------------------------------
  // Gestione lista Tags
  // -----------------------------------------------------------------------
  function FilterTags() {
    
    $("#tagMessage").html("<center><img src='images/waiting48.gif' align=absmiddle>&nbsp;Attendere...</center>");
    
    var tagValues = [];
    $('#tagForm :checked').each(function() {
      tagValues.push($(this).val());
    });
     
    filter=tagValues.join(";");
    
    //alert ("JS "+filter);
    
    // Chiama la pagina di filtraggio degli articoli
    $.post("script/tags_filtering.php","filter="+filter, function(data) {            
      
      // Ricavo la larghezza del DIV
      var divWidth=parseInt(($('#tagList').innerWidth()-30)/3);      
      var divTop=200;
      
      //alert(data);
      
      // Ricava gli Id passati dal filtraggio
      var toShow=data.split(";");      
      
      $("div[id^='article']").removeClass('articlebox2');
      $("div[id^='article']").addClass('articlebox');
      
      //alert (toShow.length);
      
      if (toShow.length==1) {
        $("#testoRicerca").html("Non sono stati trovati articoli corrispondenti ai criteri impostati");
      } else {
        if (toShow.length>24) {
          $("#testoRicerca").html("Sono stati trovati <b>"+(toShow.length-1)+"</b> articoli corrispondenti ai criteri impostati.<br>Solo i primi 24 risultati saranno mostrati");
        } else {
          $("#testoRicerca").html("Sono stati trovati <b>"+(toShow.length-1)+"</b> articoli corrispondenti ai criteri impostati.");
        }
      }
      
      for (i=0;i<toShow.length;i++) {
        
        // Visualizzo solo i primi 24
        if (i>24) break;
        
        if (toShow[i]!="") {
          
          //alert ('#article'+toShow[i]);
          //alert ($('#article'+toShow[i]).text()); 
          
          if ($('#article'+toShow[i]).attr('class')=="articlebox") {
            // Mostro il DIV
            $('#article'+toShow[i]).removeClass("articlebox");
            $('#article'+toShow[i]).addClass("articlebox2");
            
            // Posiziono il div
            $('#article'+toShow[i]).css('top',(divTop+40)*parseInt((i/3)));
            $('#article'+toShow[i]).css('left',10*((i%3)+1)+divWidth*(i%3));
            
            
          } else {
            // Lo nascondo
            $('#article'+toShow[i]).removeClass("articlebox2");
            $('#article'+toShow[i]).addClass("articlebox");            
          }
          

          //$('#article'+toShow[i]).show();
          
        }
      }
      
      $("#tagMessage").html("");
      
    });
    
  }
  
  
  // --------------------------------------------------------------------
  // Esegue il filtraggio dei prodotti EZ TCP
  // --------------------------------------------------------------------
  function doEzFilter() {
    
    $("#ezFilter").html("<center><br><br><img src='images/loadingez.gif'></center>");
    str=$("[name=ezFormFilter]").serialize();
    $.post("index.php?page=eztcp.php","cmd=dofilter&view=special&"+str, function(data) {
            
      $("#ezFilter").html(data);
      
    });
    
    return false;
  }
  
  // -----------------------------------------------------------------------
  // Visualizza il form per richiedere l'offerta
  // -----------------------------------------------------------------------  
  function FormOfferta(idprod) {
    
    // Ricava i dati del prodotto    
    $.post("script/ajax_offerta.php","todo=getdata&id="+idprod, function(data) {
      
      $("#fullScreen").css({"top":$(window).scrollTop()+"px"});
      $("#fullScreen").css({"left":$(window).scrollLeft()+"px"});
      $("#fullScreen").show();
      
      $("#formOfferta").html(data);      
      $("#formOfferta").css("top", ( $(window).height() - $("#formOfferta").height() ) / 2+$(window).scrollTop() + "px");
      $("#formOfferta").css("left", ( $(window).width() - $("#formOfferta").width() ) / 2+$(window).scrollLeft() + "px");      
      $("#formOfferta").show();
      
    });
    
    return false;
    
  }
  
  function InviaOfferta(minimo) {
    
    if ( (parseInt($("[name='txtQuantita']").val())<minimo) || $("[name='txtQuantita']").val()=="") {
      window.alert("La quantità minima per richiedere una offerta per questo prodotto è di "+minimo+" pezzi");
      return false;
    }
    
    if ( ($("[name='txtNome']").val()=="") || ($("[name='txtEmail']").val()=="") ) {
      window.alert("Non tutte le informazioni richieste sono state inserite");
      return false;
    }
    
    // Ricavo i dati del form
    dati=$("[name='frmOfferta']").serialize();
    
    $("#formOfferta").html("<center><br><br><br><img src='images/waiting48.gif' align=absmiddle>&nbsp;Invio dei dati in corso...</center>");
    
    $.post("script/ajax_offerta.php","todo=senddata&"+dati, function(data) {
      // Invio dell'offerta via email
      $("#formOfferta").html("<img src='images/ico_close.gif' class=closeicon onClick='javascript: return ChiudiOfferta()'><center><br><br><br>Richiesta di offerta correttamente inviata<br><br><br><input type=button class=standard_button onClick='javascript: ChiudiOfferta()' value=\" Termina \"></center>");
    });        
    
    return false;
  }
  
  function ChiudiOfferta() {    
    $("#fullScreen").hide();
    $("#formOfferta").hide();
    return false;
  }  
  
  
  function InvioAdesione() {

    if ( ($("[name='txtAzienda']").val()=="") || ($("[name='txtEmail']").val()=="") || ($("[name='txtTelefono']").val()=="") || ($("[name='txtPartitaIva']").val()=="") ) {
      window.alert("Non tutte le informazioni richieste sono state inserite");
      return false;
    }
    
    // Ricavo i dati del form
    dati=$("[name='frmAdesione']").serialize();
    
    $("#formAdesione").html("<center><br><br><br><img src='images/waiting48.gif' align=absmiddle>&nbsp;Invio dei dati in corso...</center>");
    
    
    $.post("script/ajax_adesione.php","todo=senddata&"+dati, function(data) {
      // Invio dell'offerta via email
      $("#formAdesione").html("<center><br><br><br><b>La richiesta di adesione è stata correttamente inviata</b><br><br>I commerciali Area SX provvederenno a contattarti quanto prima per fornirti tutti i dettagli di accesso al listino rivenditori.</center>");
    });        
  
    return false;
    
  }
  
  
  function UpdateCarrello() {
    
    // Ricava i dati del prodotto    
    $.post("script/ajax_carrello.php","", function(data) {
      
      $(".cart_status_text").html(data);
      
    });
    
    return false;
    
  }
  
  $(document).ready(function()
  {    
    $("#box_pubblicitaclose").click(function() {
      $("#box_pubblicita").hide();
    });
        
    if ($('showpub').length != 0) {
      
      $("#box_pubblicitacontent").html($('showpub').attr('whichpub'));
      $("#box_pubblicita").show();
      $("#box_pubblicita").animate({width:400,height:300},"slow");
    }
    
    UpdateCarrello();
    
  });
