var test="";

//FUNZIONI
function get_cookie(Name) {
  var search = Name + "=";
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search);
    // if cookie exists
    if (offset != -1) {
      offset += search.length;
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end));
      }
   }
  return returnvalue;
}
//----------------------------------------------------------------------------------------------------------
function pulisci_cookie()
{
 document.cookie="voce_scelta_sotto=";
 document.cookie="voce_scelta=";
 document.cookie="voce_precedente=";
 document.cookie="menu=";
 document.cookie="voce_precedente_2=";
 document.cookie="voce_scelta_2=";
// document.cookie='ric_scelta=';   
}

//width = screen.width;
//height = screen.height;

//alert(width + " x " + height);
//----------------------------------------------------------------------------------------------------------
function popup(theURL,winName,features) 
{ 
//  features=features + ",toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no";

  features= features + " ,resizable=0, location=0, status=0, menubar=0,toolbar=0";
  window.open(theURL,winName,features);

}
//----------------------------------------------------------------------------------------------------------
function apri_livehelp() 
     {
	  // nuovo_LiveHelp_52508=window.open('http://server.livehelp.it/client_user/default.asp?provenienza='+ escape(document.location.href) +'&info=&stanza=Assistenza%2D52508&ID=52508&gruppo=Assistenza','LiveHelpwin1_52508', 'status=yes,toolbar=no,width=500,height=400,resizable=yes');
	   //nuovo_LiveHelp_52508.focus();
	   
  window.open('http://www.agse.it:8888/LiveHelp/chat.php?code=U0VSVkVSUEFHRQ__','','width=590,height=610,left=0,top=0,resizable=yes,menubar=no,location=yes,status=yes,scrollbars=yes');	   
	   
	 } 

//----------------------------------------------------------------------------------------------------------
function leftTrim(sString) 
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
return sString;
}
//----------------------------------------------------------------------------------------------------------
function rightTrim(sString) 
{
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
}
//----------------------------------------------------------------------------------------------------------
function trimAll(sString) 
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
}

//----------------------------------------------------------------------------------------------------------
function bookmarksite(title, url){
  if (document.all)
	  window.external.AddFavorite(url, title);
  else if (window.sidebar)
	  window.sidebar.addPanel(title, url, "");
	}
//----------------------------------------------------------------------------------------------------------
function pressione_tasto_generico(e){

var unicode=e.keyCode? e.keyCode : e.charCode

  if (unicode == 13) 
     {
      invia_parametri_generico();
     }	 
}

//----------------------------------------------------------------------------------------------------------
function ShowAndHide(id1)
{

if(document.getElementById)
{
    el1=document.getElementById(id1);

    if(el1.style.display=="none"){
        el1.style.display="block";
        }
    else{
        el1.style.display="none";
        }
    }
}

//----------------------------------------------------------------------------------------------------------
function ChiudiAltro(id1)
{

if(document.getElementById)
{
    el1=document.getElementById(id1);

    el1.style.display="none";
}
}
//----------------------------------------------------------------------------------------------------------
function Visualizza_Immagine(id1,classe)
{

if(document.getElementById)
{
    el1=document.getElementById(id1);

    el1.className=classe;
}

if (classe=="bannerHome6")
{
  document.getElementById("scarica_software").style.display="block";
}
else
{
  document.getElementById("scarica_software").style.display="none";
}

}


var enablepersist="on" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="no" //Collapse previously open content when opening present? (yes/no)

var contractsymbol='- ' //HTML for contract symbol. For image, use: <img src="whatever.gif">
var expandsymbol='+ ' //HTML for expand symbol.

if (document.getElementById){
document.write('<style type="text/css">')
document.write('.switchcontent{display:none;}')
document.write('</style>')
}
//----------------------------------------------------------------------------------------------------------
function getElementbyClass(rootobj, classname){
var temparray=new Array()
var inc=0
var rootlength=rootobj.length
for (i=0; i<rootlength; i++){
if (rootobj[i].className==classname)
temparray[inc++]=rootobj[i]
}
return temparray
}
//----------------------------------------------------------------------------------------------------------
function sweeptoggle(ec){
var thestate=(ec=="expand")? "block" : "none"
var inc=0
while (ccollect[inc]){
ccollect[inc].style.display=thestate
inc++
}
revivestatus()
}
//----------------------------------------------------------------------------------------------------------
function contractcontent(omit)
{
 var inc=0
 while (ccollect[inc])
 {
   if (ccollect[inc].id!=omit)
     ccollect[inc].style.display="none"
     inc++
 }
}
//----------------------------------------------------------------------------------------------------------
function expandcontent(curobj, cid)
{
//  var spantags=curobj.getElementsByTagName("SPAN")
//  var showstateobj=getElementbyClass(spantags, "showstate")
//if (ccollect.length>0)
//      {
//        if (collapseprevious=="yes")
//            contractcontent(cid)
//            document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
        document.getElementById(cid).style.display="block"	
//        if (showstateobj.length>0)
//		   { //if "showstate" span exists in header
//             if (collapseprevious=="no")
//                showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol
//             else
         //        revivestatus()
//           }
//     }  
}

//----------------------------------------------------------------------------------------------------------
function revivecontent(){
contractcontent("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="block"
}

//----------------------------------------------------------------------------------------------------------
function revivestatus(){
var inc=0
while (statecollect[inc]){
if (ccollect[inc].style.display=="block")
statecollect[inc].innerHTML=contractsymbol
else
statecollect[inc].innerHTML=expandsymbol
inc++
}
}

//----------------------------------------------------------------------------------------------------------
function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

//----------------------------------------------------------------------------------------------------------
function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
}

//----------------------------------------------------------------------------------------------------------
//function saveswitchstate(){
//var inc=0, selectedItem=""
//while (ccollect[inc]){
//if (ccollect[inc].style.display=="block")
//selectedItem+=ccollect[inc].id+"|"
//inc++
//}
//
//document.cookie=window.location.pathname+"="+selectedItem
//}

//----------------------------------------------------------------------------------------------------------

//function do_onload(){
//uniqueidn=window.location.pathname+"firsttimeload"
//var alltags=document.all? document.all : document.getElementsByTagName("*")
//ccollect=getElementbyClass(alltags, "switchcontent")
//statecollect=getElementbyClass(alltags, "showstate")
//if (enablepersist=="on" && ccollect.length>0){
//document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
//firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
//if (!firsttimeload)
//revivecontent()
//}
//if (ccollect.length>0 && statecollect.length>0)
//revivestatus()
//}
//
//if (window.addEventListener)
//window.addEventListener("load", do_onload, false)
//else if (window.attachEvent)
//window.attachEvent("onload", do_onload)
//else if (document.getElementById)
//window.onload=do_onload
//
//if (enablepersist=="on" && document.getElementById)
//window.onunload=saveswitchstate
	
//----------------------------------------------------------------------------------------------------------	
function gest_carrello(act,chi)
   {
 
   document.forms["prodot_form"+chi].azione.value=act;
  		
   if (document.forms["prodot_form"+chi].qtacarrello.value == "")
   {
	   
    alert("<%=scheda_msg_9%>");
	
    document.forms["prodot_form"+chi].qtacarrello.focus();
	
    return false;	  
   }
  document.forms['prodot_form'+chi].submit();

}

//----------------------------------------------------------------------------------------------------------
function pressione_tasto_situazione(e,link_eseguire)

{

var keycode= null;
if (window.event) 
   {keycode = window.event.keyCode;}
else if (e) 
   {keycode = e.which;}

//alert("keycode: " + keycode);

 if (keycode == 13) 
     {
        Esegui_AJAX(link_eseguire);
          Carica_Contenuto_AJAX('Contenitore_AJAX','../pagine/utente_ordini_AJAX.asp?pagina=8&id_cat=0',1);
		return false;
     }	 
 else
     {
       return true;
     }
	 
}
	
//----------------------------------------------------------------------------------------------------------	
function pressione_link_situazione(link_eseguire)

{
       //alert('Vado');

        Esegui_AJAX(link_eseguire);
        
		//alert('Mument');
		
		Carica_Contenuto_AJAX('Contenitore_AJAX','../pagine/utente_ordini_AJAX.asp?pagina=8&id_cat=0',1);
		
		return false;
	 
}	

//function script_situazione(act,qualeform)
//        {
//    
//document.forms['prodotto_form' +qualeform ].azione.value=act;
//			
//   if (document.forms['prodotto_form' +qualeform ].qtasituazione.value == "")
//   {
//      alert("<%=msg_integrazione_5%>");
//      document.forms['prodotto_form' +qualeform ].qtasituazione.focus();
//      return false;	  
//   }
//   
//  document.forms['prodotto_form'+qualeform].submit();
//
//}
//----------------------------------------------------------------------------------------------------------	
var scelto_pagamento=0;

function controllo_invio_parametri()
 {
   var ok=false;
   var valido_ric=true;

  //Pagamento
  
   //Monopagamento clicca da solo
   //document.form_invio_ordine_finale.pagamento.click(self);
   //document.getElementById("paga0").click(self);
   
  
//   for (counter = 0;  counter <= document.getElementsByName("pagamento").length; counter++)
//    {
//     
//
//     if (scelto_pagamento==1)	  
//        { 
//	      ok=true;
//		  break;
//     	}
//    }
//
//    if (ok==false)
//       {
//        alert("<%=carrello_msg_27%>");
//        valido_ric=false;
//	    return false;
//       }
 
   if (valido_ric)
     {

f_pagamento =document.getElementById("paga0").value;
f_vettore=document.getElementById("vettore").value;

f_note_carrello=document.getElementById("note").value.replace("'","");

f_tipo=document.getElementById("tipo").value;
f_trasporto=document.getElementById("trasporto").value;

f_spese_imballaggio=document.getElementById("spese_imballaggio").value;
f_totale_fattura=document.getElementById("totale_fattura").value;
f_pagamento_tipologia=document.getElementById("pagamento_tipologia").value;
f_totale_fattura_hid=document.getElementById("totale_fattura_hid").value;
f_spese_imballaggio_hid=document.getElementById("spese_imballaggio").value;
f_totale_merce_hid=document.getElementById("totale_merce").value;
f_ragione_sociale_cliente=document.getElementById("ragione_sociale_cliente").value.replace("'","");
f_email_cliente=document.getElementById("email_cliente").value;
f_indirizzo=document.getElementById("indirizzo").value.replace("'","");
f_cap=document.getElementById("cap").value;
f_citta=document.getElementById("citta").value.replace("'","");
f_provincia=document.getElementById("provincia").value;
f_cod_premio=document.getElementById("scegli").value;


 
 Esegui_AJAX('../pagine/selezione_pagamento_AJAX.asp?pagamento='+f_pagamento+'&vettore='+f_vettore+'&note_ordine='+f_note_carrello+'&tipo='+f_tipo+'&trasporto='+f_trasporto+'&spese_imballaggio='+f_spese_imballaggio+'&totale_fattura='+f_totale_fattura+'&pagamento_tipologia='+f_pagamento_tipologia+'&totale_fattura_hid='+f_totale_fattura_hid+'&spese_imballaggio_hid='+f_spese_imballaggio_hid+'&totale_merce_hid='+f_totale_merce_hid+'&ragione_sociale_cliente='+f_ragione_sociale_cliente+'&email_cliente='+f_email_cliente+'&indirizzo='+f_indirizzo+'&cap='+f_cap+'&citta='+f_citta+'&provincia='+f_provincia+'&cod_premio='+f_cod_premio);
 
 // Carica_Contenuto_AJAX('Contenitore_AJAX','../pagine/utente_ordini_AJAX.asp?pagina=8&id_cat=0',1);
 
 document.getElementById("Div_Caricamento").style.display="block";
 
 document.location.href="../ppagina.asp?pagina=8&id_cat=0";

	 }
}

//----------------------------------------------------------------------------------------------------------

function paga_premio()
{
  ricalcolatore(0,'0000','0060',1,'0500',200); //default BARTOLINI senza CC
}

//----------------------------------------------------------------------------------------------------------
function ricalcolatore(flag,cod,cod_vet,ce_premio,tipo_shadow,trasporto_gratuito)
{

//form_invio_ordine_finale.pagamento_tipologia.value=tipo_shadow;

//val_merce = parseFloat(form_invio_ordine_finale.totale_merce.value.replace(",","."));
val_merce = parseFloat(document.getElementById("totale_merce").value.replace(",","."));



if (cod!="0000")
 {
 
  if ((val_merce<trasporto_gratuito)||(trasporto_gratuito==0) )
    {
     //form_invio_ordine_finale.spese_imballaggio.value=trimAll(form_invio_ordine_finale['spese_vettore_' + cod ].value);	
	 document.getElementById("spese_imballaggio").value=trimAll(document.getElementById("spese_vettore_" + cod).value);
	}
  
 }

//premi
aggiungi_il_premio=false;

if (ce_premio==1)
  {
//   for (counter = 0;  counter < form_invio_ordine_finale.scegli.length; counter++)

   for (counter = 0;  counter < document.getElementById("scegli").length; counter++)   
   
    {
     if (form_invio_ordine_finale.scegli[counter].checked)
        { 
		  aggiungi_il_premio=true;
		  break;     	
		}
    }	

  }

	 
	if (aggiungi_il_premio) 
	   {
		 document.getElementById("spese_premio").value="0,01";
	   } 
    else 
	   {
		 document.getElementById("spese_premio").value="0,00";
	   } 

//		 valore = parseFloat(form_invio_ordine_finale.totale_merce.value.replace(",","."));
//		 valore = valore + parseFloat(form_invio_ordine_finale.spese_premio.value.replace(",","."));
//		 valore = valore + parseFloat(form_invio_ordine_finale.spese_imballaggio.value.replace(",","."));
		 
		 valore = parseFloat(document.getElementById("totale_merce").value.replace(",","."));
		 valore = valore + parseFloat(document.getElementById("spese_premio").value.replace(",","."));
		 valore = valore + parseFloat(document.getElementById("spese_imballaggio").value.replace(",","."));
		 	 
         valore = Math.round(valore*100)/100;
		 
		 document.getElementById("totale_fattura").value=valore.toString().replace(".",",");
    	 document.getElementById("totale_fattura_hid").value=valore.toString().replace(".",",");	
	   
}

//----------------------------------------------------------------------------------------------------------
function invio_richiesta_nuovo_ordine()
{
	 
note_ordine=document.getElementById("note").value;

Esegui_AJAX('../scripts/script_note_ordine_AJAX.asp?note='+note_ordine);

Carica_Contenuto_AJAX('Contenitore_AJAX','../pagine/utente_ordini_AJAX.asp?pagina=8&id_cat=0',1);

}
//----------------------------------------------------------------------------------------------------------
function invio_richiesta_nuovo_indirizzo()
{
   var valido_ric=true;
   var ok=false;
   var scelta=-1;
   
form_ragionedest   =document.getElementById("ragionesped").value;
form_indirizzodest =document.getElementById("indirizzosped").value;
form_capdest       =document.getElementById("capsped").value;
form_cittadest     =document.getElementById("cittasped").value;
form_provdest      =document.getElementById("provsped").value;
form_note          =document.getElementById("note").value;

//   
////Dati spedizione differenti

        iscrizione_error_25="Inserire la Ragione Sociale per la Spedizione";
	    iscrizione_error_26="Inserire un Indirizzo Civico per la  Spedizione";
	    iscrizione_error_27 ="Inserire un CAP per la Spedizione";
	    iscrizione_error_28 ="Inserire una Cittą per la Spedizione";
	    iscrizione_error_29 ="Inserire una Provincia per la Spedizione";

//      //Ragione
	  if (form_ragionedest == "")
       {
        alert(iscrizione_error_25);
        document.getElementById("cellaragionesped").className="rosso";
        document.getElementById("ragionesped").className="input";	  	  	  	  	  	  
        document.getElementById("ragionesped").focus();
        valido_ric=false;
        return false;	  
       }
	   
//	  //Indirizzo
	     if (form_indirizzodest == "")
   {
      alert(iscrizione_error_26);
      document.getElementById("c14").className="rosso";	  	  
      document.getElementById("indirizzosped").className="input";	  	  	  	  	  	  
      document.getElementById("indirizzosped").focus();
      valido_ric=false;
      return false;	  
   }
//	  //Cap
	     if (form_capdest == "")
   {
      alert(iscrizione_error_27);
      document.getElementById("c15").className="rosso";	  	  
      document.getElementById("cittasped").className="input";	  	  	  	  	  	  
      document.getElementById("cittasped").focus();
      valido_ric=false;
      return false;	  
   }
//	  //Citta
	    if (form_cittadest == "")
   {
      alert(iscrizione_error_28);
      document.getElementById("c16").className="rosso";	  	  
      document.getElementById("cittasped").className="input";	  	  	  	  	  	  
      document.getElementById("cittasped").focus();
      valido_ric=false;
      return false;	  
   }
//	  //Provincia
	     if (form_provdest == "")
   {
      alert(iscrizione_error_29);
      document.getElementById("c17").className="rosso";	  	  
      document.getElementById("provsped").className="input";	  	  	  	  	  	  
      document.getElementById("provsped").focus();
      valido_ric=false;
      return false;	  
   }
    
     
   if (valido_ric)
    {
	
      Esegui_AJAX('../scripts/script_utente_indirizzi_AJAX.asp?ragionesped='+ form_ragionedest + '&indirizzosped=' + form_indirizzodest + '&capsped=' + form_capdest + '&cittasped=' + form_cittadest + '&provsped=' + form_provdest + '&note=' + form_note);

      Carica_Contenuto_AJAX('Contenitore_AJAX','../pagine/utente_ordini_checkout_AJAX.asp?',1);

	}
   
}

//----------------------------------------------------------------------------------------------------------
function script_carrello(act,qualeform)
{
    
document.forms['prodotto_form' +qualeform ].azione.value=act;
  no_invio=0; 			
			
 
   if (document.forms['prodotto_form' + qualeform ].qtacarrello.value == "")
      {
       no_invio=1;
       document.forms['prodotto_form' + qualeform ].qtacarrello.focus();
      }
  else
      {   
       
//      if (act>3)
//         {
//
//           if (confirm("Vuoi continuare?"))
//             {
              no_invio=0;	
//             }
//		   else
//		     {
//              no_invio=1;		     
//			 }
//         }
//		  
     }

	
  if (no_invio==0)
   {
    document.forms['prodotto_form' + qualeform].submit();	
   }	
  else
   {
	document.forms['prodotto_form' + qualeform].action="";	
   }
  
  
}

//----------------------------------------------------------------------------------------------------------
function carrello_gestione_invio(e,azione,prodotto_ord)
{

var keycode= null;
if (window.event) 
   {keycode = window.event.keyCode;}
else if (e) 
   {keycode = e.which;}

 if (keycode == 13) 
     {
	   script_carrello(azione,prodotto_ord);
	   return false;	   
     }	 
 else
     {
       return true;
     }
	 
}

//----------------------------------------------------------------------------------------------------------
function sequenza_carrello(azione,link_gestione,prodotto,form_prodotto,link_da_agg)
{
   link_eseguire=link_gestione + "?act="+azione+"&prod_car="+ prodotto +"&qta_car="+ document.forms[form_prodotto].qtacarrello.value;
   
   Esegui_AJAX(link_eseguire);
   
   AJAX_Carrello('Riepilogo_Carrello','Contenitore_AJAX',link_da_agg,1);
}

//----------------------------------------------------------------------------------------------------------
function sequenza_carrello_generale(azione,link_gestione,prodotto,form_prodotto,link_da_agg)
{	
   link_eseguire=link_gestione + "?act="+azione+"&prod_car="+ prodotto +"&qta_car="+ document.forms[form_prodotto].qtacarrello.value;
   
   Esegui_AJAX(link_eseguire);

   AJAX_Carrello('Riepilogo_Carrello','Contenitore_catalogo_AJAX',link_da_agg,1);
 
   //document.getElementById("ric_generico").value="";
   
   document.getElementById("ric_generico").focus();  
}

//----------------------------------------------------------------------------------------------------------
function manda_carrello_agg(e,azione,link_gestione,prodotto,form_prodotto,link_da_agg)
{

var keycode= null;
if (window.event) 
   {keycode = window.event.keyCode;}
else if (e) 
   {keycode = e.which;}

 if (keycode == 13) 
     {
	   sequenza_carrello(azione,link_gestione,prodotto,form_prodotto,link_da_agg);
	   return false;	   
     }	 
 else
     {
       return true;
     }
	 
}

//----------------------------------------------------------------------------------------------------------
function manda_carrello_agg_generale(e,azione,link_gestione,prodotto,form_prodotto,link_da_agg)
{

var keycode= null;
if (window.event) 
   {keycode = window.event.keyCode;}
else if (e) 
   {keycode = e.which;}

 if (keycode == 13) 
     {
	   sequenza_carrello_generale(azione,link_gestione,prodotto,form_prodotto,link_da_agg);
	   return false;	   
     }	 
 else
     {
       return true;
     }
	 
}
//----------------------------------------------------------------------------------------------------------
function cambia_colore_scelta(blocco)
{
  if (blocco=="marca")	
   {	   
     document.getElementById('menu_marche').style.display='block';
     document.getElementById('menuCatTel').style.display='none';
     document.getElementById('titolo_marca').className='colsxVerdeh2';
     document.getElementById('titolo_catalogo').className='colsxNerah2';
   }

  if (blocco=="catalogo")	
   {	   
      Chiudi_Tutto();
	  document.getElementById('menuCatTel').style.display='block';
	  document.getElementById('menu_marche').style.display='none';
      document.getElementById('titolo_catalogo').className='colsxVerdeh2';
      document.getElementById('titolo_marca').className='colsxNerah2';
   }
   
  if (blocco=="catalogo_solo")	
   {
      Chiudi_Tutto();
	  document.getElementById('menuCatTel').style.display='block';
	  document.getElementById('menu_marche').style.display='none';
      document.getElementById('titolo_catalogo').className='colsxVerdeh2';
   }
}

//----------------------------------------------------------------------------------------------------------

function script_situazione(act,qualeform)
{

  document.forms['prodotto_form' +qualeform ].azione.value=act;	
  no_invio=0; 
  


   if (document.forms['prodotto_form' + qualeform ].qtasituazione.value == "")
      {
       no_invio=1;
       document.forms['prodotto_form' + qualeform ].qtasituazione.focus();
      }
  else
      {   
       
      if (act>3)
         {
			 
		   testo="Vuoi continuare?";

           if (act==5) {testo="Vuoi cancellare l'Ordine?";}
           if (act==4) {testo="Vuoi cancellare gli Inevasi?";}		   
		   
           if (confirm(testo))
             {
              no_invio=0;	
             }
		   else
		     {
              no_invio=1;		     
			 }
         }
		  
     }

	
  if (no_invio==0)
   {
    document.forms['prodotto_form' + qualeform].submit();	
   }	
  else
   {
	document.forms['prodotto_form' + qualeform].action="";	
   }
}

//----------------------------------------------------------------------------------------------------------

function situazione_gestione_invio(e,azione,prodotto_ord)
{

var keycode= null;
if (window.event) 
   {keycode = window.event.keyCode;}
else if (e) 
   {keycode = e.which;}

 if (keycode == 13) 
     {
	   script_situazione(azione,prodotto_ord);
     }	 
 else
     {
	   return false;	   
     }
	 
}

//----------------------------------------------------------------------------------------------------------

function invio_richiesta_segnala()
{
   var valido_ric=true;
   var ok=false;
   var scelta=-1;
        
   //mittente
   if (document.getElementById("mittente_mail_segnala").value == "")
   {
      alert("Inserire un Nome per il Mittente");
      document.getElementById("c1").className="intCampo rosso";	  	  
      document.getElementById("mittente_mail_segnala").className="inputEvidenziato";
      document.getElementById("mittente_mail_segnala").focus();
      valido_ric=false;
      return false;	  
   } 
   
   
   //messaggio
   if (document.getElementById("msg").value == "")
   {
      alert("Inserire un Messaggio");
      document.getElementById("c1").className="intCampo rosso";	  	  
      document.getElementById("msg").className="inputEvidenziato";
      document.getElementById("msg").focus();
      valido_ric=false;
      return false;	  
   } 
   
  //Mail
   if (document.getElementById("mailmittente_mail_segnala").value == "")
   {
      alert("Inserire un indirizzo Mail");
      document.getElementById("c4").className="intCampo rosso";	  	  
      document.getElementById("mailmittente_mail_segnala").className="inputEvidenziato";	         	  	  	  	  
      document.getElementById("mailmittente_mail_segnala").focus();
      valido_ric=false;
      return false;	  
   }
   else
   {
	var x = document.getElementById("mailmittente_mail_segnala").value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) 
	{
	       valido_ric=true;
	}
	else 
	{
      alert("Inserire un indirizzo Mail valido");
      document.getElementById("c4").className="intCampo rosso";	  	  
      document.getElementById("mailmittente_mail_segnala").className="inputEvidenziato";
      document.getElementById("mailmittente_mail_segnala").focus();
      valido_ric=false;
      return false;	  
    }
   } 
   		
   if (valido_ric){document.getElementById("segnala_amico").submit();}
 
}

//----------------------------------------------------------------------------------------------------------



/*
 * This is the function that actually highlights a text string by
 * adding HTML tags before and after all occurrences of the search
 * term. You can pass your own tags if you'd like, or if the
 * highlightStartTag or highlightEndTag parameters are omitted or
 * are empty strings then the default <font> tags will be used.
 */
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
    highlightEndTag = "</font>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  
  return newText;
}


/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split(" ");
  }
  
  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
    if (warnOnFailure) {
      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    return false;
  }
  
  var bodyText = document.body.innerHTML;
  for (var i = 0; i < searchArray.length; i++) {
    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
  }
  
  document.body.innerHTML = bodyText;
  return true;
}


/*
 * This displays a dialog box that allows a user to enter their own
 * search terms to highlight on the page, and then passes the search
 * text or phrase to the highlightSearchTerms function. All parameters
 * are optional.
 */
function searchPrompt(defaultText, treatAsPhrase, textColor, bgColor)
{
  // This function prompts the user for any words that should
  // be highlighted on this web page
  if (!defaultText) {
    defaultText = "";
  }
  
  // we can optionally use our own highlight tag values
  if ((!textColor) || (!bgColor)) {
    highlightStartTag = "";
    highlightEndTag = "";
  } else {
    highlightStartTag = "<font style='color:" + textColor + "; background-color:" + bgColor + ";'>";
    highlightEndTag = "</font>";
  }
  
  if (treatAsPhrase) {
    promptText = "Please enter the phrase you'd like to search for:";
  } else {
    promptText = "Please enter the words you'd like to search for, separated by spaces:";
  }
  
  searchText = prompt(promptText, defaultText);

  if (!searchText)  {
    alert("No search terms were entered. Exiting function.");
    return false;
  }
  
  return highlightSearchTerms(searchText, treatAsPhrase, true, highlightStartTag, highlightEndTag);
}


/*
 * This function takes a referer/referrer string and parses it
 * to determine if it contains any search terms. If it does, the
 * search terms are passed to the highlightSearchTerms function
 * so they can be highlighted on the current page.
 */
function highlightGoogleSearchTerms(referrer)
{
  // This function has only been very lightly tested against
  // typical Google search URLs. If you wanted the Google search
  // terms to be automatically highlighted on a page, you could
  // call the function in the onload event of your <body> tag, 
  // like this:
  //   <body onload='highlightGoogleSearchTerms(document.referrer);'>
  
  //var referrer = document.referrer;
  if (!referrer) {
    return false;
  }
  
  var queryPrefix = "q=";
  var startPos = referrer.toLowerCase().indexOf(queryPrefix);
  if ((startPos < 0) || (startPos + queryPrefix.length == referrer.length)) {
    return false;
  }
  
  var endPos = referrer.indexOf("&", startPos);
  if (endPos < 0) {
    endPos = referrer.length;
  }
  
  var queryString = referrer.substring(startPos + queryPrefix.length, endPos);
  // fix the space characters
  queryString = queryString.replace(/%20/gi, " ");
  queryString = queryString.replace(/\+/gi, " ");
  // remove the quotes (if you're really creative, you could search for the
  // terms within the quotes as phrases, and everything else as single terms)
  queryString = queryString.replace(/%22/gi, "");
  queryString = queryString.replace(/\"/gi, "");
  
  return highlightSearchTerms(queryString, false);
}
/*----------------------------------------------------------------------------------------*/

function abilita_scheda(DIV_Vedi,DIV_Nascondi_1,DIV_Nascondi_2)
{	

//linguetta_tab-1
//linguetta_tab-2
//linguetta_tab-3

//id="lingua_tab-3" class="linguetta_tab-3

  if (document.getElementById('lingua_' + DIV_Vedi)) { document.getElementById('lingua_' + DIV_Vedi).className='linguetta_' + DIV_Vedi; }
  if (document.getElementById('lingua_' + DIV_Nascondi_1)) { document.getElementById('lingua_' + DIV_Nascondi_1).className='linguetta_' + DIV_Nascondi_1 + 'white'; }
  if (document.getElementById('lingua_' + DIV_Nascondi_2)) { document.getElementById('lingua_' + DIV_Nascondi_2).className='linguetta_' + DIV_Nascondi_2 + 'white'; }	

  if (document.getElementById(DIV_Vedi)) { document.getElementById(DIV_Vedi).style.display='block'; }
  if (document.getElementById(DIV_Nascondi_1)) { document.getElementById(DIV_Nascondi_1).style.display='none'; }
  if (document.getElementById(DIV_Nascondi_2)) { document.getElementById(DIV_Nascondi_2).style.display='none'; }
  
}

/*------------------------------------------------------------------------------------------*/

//(function( $ ){
//    /**
//     * The plugin already provides some sensible defaults that enable the user to use it without
//     * any kind of configuration.
//     * */
//    var defaults = {
//        prevLabel: "Previous",
//        nextLabel: "Next",
//        submitLabel: "Submit",
//        defaultPrevIcon: "ui-icon-circle-arrow-w",
//        defaultNextIcon: "ui-icon-circle-arrow-e",
//        defaultSubmitIcon: "ui-icon-circle-check",
//        endActionEnabled: true,
//        submitAction: function(){ alert("Please remember to set the submit action."); }
//    };
//
//    var opts = {};
//
//    var methods = {
//        /**
//         * The init is the only public method that this plugin exposes. Its options require the following fields:
//         * submitAction - the action to be executed when the submit button is clicked.
//         * */
//        init : function( options ){
//            var $baseElem = this;
//            $.extend(opts, defaults, options);
//            
//            return this.each(function(){
//                if(opts.height !== undefined){
//                    $baseElem.height(opts.height);
//                }else{
//                    $baseElem.height(_getMaxHeight($baseElem));
//                }
//                var links = [];
//                $baseElem.tabs();
//                $baseElem.find("ul li a").each(function() {
//                    links.push($(this));
//                });
//
//                var $prev = null;
//                var length = links.length;
//                for (var i = 0; i < length; i++) {
//                    var $baseDiv = $(links[i].attr("href"));
//                    $baseDiv.append("<div style='position: absolute; bottom: 10px; width: 95%; text-align:center; margin:auto;'><hr/><div name='btnContainer' style='float:right;text-align:right; padding:10px;'></div></div>");
//                    var $container = $(links[i].attr("href") + " " + "[name=btnContainer]");
//                    if (i > 0) {
//                        _generatePrevBtn($prev, $container);
//                    }
//
//                    if (i < length - 1) {
//                        var $next = links[i + 1];
//                        _generateNextBtn($next, $container);
//                    }
//
//                    if(opts.endActionEnabled){
//                        if (i == length - 1) {
//                            _generateSubmit($container);
//                        }
//                    }
//                    $prev = links[i];
//                    $container.parent().append("<div style='clear: both;'></div>");
//                }
//            });
//        }
//    };
//
//    $.fn.wizardTabs = function( method) {
//        if ( typeof method === 'object' || ! method ) {
//            return methods.init.apply( this, arguments );
//        } else {
//            $.error( 'Method ' +  method + ' does not exist on jQuery.wizardTabs' );
//        }
//    };
//
//    function _generateNextBtn($next, $container){
//        _generateButton($container , opts.defaultNextIcon, opts.nextLabel, function(){ $next.trigger("click"); });
//    }
//
//    function _generatePrevBtn($prev, $container){
//        _generateButton($container , opts.defaultPrevIcon, opts.prevLabel, function(){ $prev.trigger("click"); });
//    }
//
//    function _generateSubmit($container){
//        _generateButton($container , opts.defaultSubmitIcon, opts.submitLabel, opts.submitAction);
//    }
//
//    function _generateButton($container, iconClass, text, action){
//        var genId = "wizardBtn" + Math.floor(Math.random()*2048);
//        var $button = $("<div id='"+genId+"'>"+text+"</div>");
//        $button.button({icons:{primary: iconClass}}).click(function(){action();});
//        $container.append($button);
//    }
//
//    function _getMaxHeight($elem){
//        var max = 0;
//        $elem.children("div").each(function(){
//            var h = $(this).height();
//            max = h > max ? h : max;
//        });
//
//        return max + 150;
//    }
//
//})( jQuery );

function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
    highlightEndTag = "</font>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  
  return newText;
}


/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split(" ");
  }
  
  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
    if (warnOnFailure) {
      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    return false;
  }
  
  var bodyText = document.body.innerHTML;
  for (var i = 0; i < searchArray.length; i++) {
    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
  }
  
  document.body.innerHTML = bodyText;
  return true;
}


/*
 * This displays a dialog box that allows a user to enter their own
 * search terms to highlight on the page, and then passes the search
 * text or phrase to the highlightSearchTerms function. All parameters
 * are optional.
 */
function searchPrompt(defaultText, treatAsPhrase, textColor, bgColor)
{
  // This function prompts the user for any words that should
  // be highlighted on this web page
  if (!defaultText) {
    defaultText = "";
  }
  
  // we can optionally use our own highlight tag values
  if ((!textColor) || (!bgColor)) {
    highlightStartTag = "";
    highlightEndTag = "";
  } else {
    highlightStartTag = "<font style='color:" + textColor + "; background-color:" + bgColor + ";'>";
    highlightEndTag = "</font>";
  }
  
  if (treatAsPhrase) {
    promptText = "Please enter the phrase you'd like to search for:";
  } else {
    promptText = "Please enter the words you'd like to search for, separated by spaces:";
  }
  
  searchText = prompt(promptText, defaultText);

  if (!searchText)  {
    alert("No search terms were entered. Exiting function.");
    return false;
  }
  
  return highlightSearchTerms(searchText, treatAsPhrase, true, highlightStartTag, highlightEndTag);
}





