


var isNav4, isIE4
  if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
     isNav4 = (navigator.appName == "Netscape") ? ((parseInt(navigator.appVersion.substring(0,1)) <= 4) ? true : false) : false
     isIE4 = (navigator.appName.indexOf("Microsoft") != -1) ? true : false
  }

OP = ((ind1 = navigator.userAgent.indexOf("Opera")) > -1) ? true : false;
punto = (OP) ? navigator.userAgent.indexOf(".",ind1):0;
OP5 = (OP && parseInt(navigator.userAgent.substr(punto-1)) == 5) ? true : false;
OP6 = (OP && parseInt(navigator.userAgent.substr(punto-1)) == 6) ? true : false;
IE = ((ind2 = navigator.appVersion.indexOf("MSIE")) > -1 && !OP) ? true : false;
IE4 = (IE && parseInt(navigator.appVersion.substr(ind2+5)) == 4) ? true : false;
IE5 = (IE && parseInt(navigator.appVersion.substr(ind2+5)) == 5) ? true : false;
IE6 = (IE && parseInt(navigator.appVersion.substr(ind2+5)) == 6) ? true : false;
NN = (navigator.appName.indexOf("Netscape")>-1) ? true : false;
NN4 = (NN && parseInt(navigator.appVersion)==4) ? true : false;
NN6 = (NN && parseInt(navigator.appVersion)>4) ? true : false;
GE = (navigator.userAgent.toLowerCase().indexOf("gecko")>-1) ? true : false;




function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

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;
}


//funzione per "nascondere" un layer
function hideLayers() {
  //compatibilità: Netscape 6.x, Explorer 5 e 6, Opera 5 e 6, Mozilla
  a = hideLayers.arguments;
  for (i=0;i<a.length;i++) {
    if (document.getElementById(a[i])) {
      //document.getElementById(a[i]).style.visibility="hidden";
      document.getElementById(a[i]).style.display="none";
    }
  }
}

//rende visibile un layer
function showLayers() {
  //compatibilità: Netscape 6.x, Explorer 5 e 6, Opera 5 e 6, Mozilla
  a = showLayers.arguments;
  for (i=0;i<a.length;i++) {
    if (document.getElementById(a[i])) {
      //document.getElementById(a[i]).style.visibility="visible";
      document.getElementById(a[i]).style.display="block";
    }
  }
}

function trimString(sInString) {
  var sInString2 = sInString;
  sInString2=sInString2.replace( /^\s+/g, "" );// strip leading
  return sInString2.replace( /\s+$/g, "" );// strip trailing
}





// [DOC]: definito in jform.js
//function checkNumber(val, skipAlert)
//{
//}



function calcolaCF(page,campo,w,h){
  var p=page+'?campo='+campo;
  window.open(p,'calcolaCF','scrollbars=yes,resizable=yes,width='+w+',height='+h+',toolbar=no');
}


function ConsigliaAmico(idSezione,idSezioneRif){
   var page='ConsigliaAmico.jsp?idSezione='+idSezione+'&amp;idSezioneRif='+idSezioneRif;
   window.open(page,'consamico','scrollbars=yes,resizable=yes,width=380,height=400,toolbar=no');
}

function cerca(form, id, error, defaultMsg) {

	var textToSearch = trimString(document.getElementById(id).value);

	if (textToSearch == '' || (defaultMsg && textToSearch == defaultMsg))
	{
		alert(error);
		
		return false;
	} 
	else 
	{
		document.forms[form].action = 'RisultatiRicerca.jsp?testo=' + textToSearch;
	
		//document.forms[form].submit();
		return true;
	}
}

function cercaAvanzata(form,id,error) {

  if (trimString(document.getElementById(id).value) == '' ) {
     alert(error);
     
     return false;
  } else {
     if(!document.getElementById('prodAv').checked &&
         !document.getElementById('infoAv').checked){
       alert('Devi scegliere se effettuare una ricerca tra i nostri PRODOTTI\no tra i nostri ARTICOLI / INFORMAZIONI');
       
       return false;
     } else {
       //document.forms[form].submit();
       
       return true;
     }
  }
}

function popup(idSezione,w,h){
  var page='Popup.jsp?idSezione='+idSezione;
  window.open(page,'popup','scrollbars=yes,resizable=yes,width='+w+',height='+h+',toolbar=no');
}

function apriFinestra(page,w,h){
  window.open(page,'popup','scrollbars=yes,resizable=yes,width='+w+',height='+h+',toolbar=no');
}

function isEmail(idcampo) {
  var campo = document.getElementById(idcampo);
  var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  var val = campo.value;

  var ok = val.search(email_reg_exp);
  Filtro1 = /^([a-zA-Z0-9_\.\-\@])+$/;
  Filtro2 = /^((.)+\.)+(.)+$/;
  if( ok == -1 && val != "" ) {

   if (val.search("@") == -1) {
         alert("ATTENZIONE !!! - Indirizzo di e-mail non corretto\n\n( l'indirizzo deve contenere il simbolo @ )");
         campo.focus();
         return false;
   }
   if (val.search(" ") != -1) {
       alert("ATTENZIONE !!! - Indirizzo di e-mail non corretto\n\n( non devono essere presenti spazi )");
       campo.focus();
       return false;
   }

   s=val.substring(val.indexOf("@")+1);
   if (!Filtro2.test(s)) {
         alert("ATTENZIONE !!! - Indirizzo di e-mail non corretto\n\n(l'indirizzo deve terminare con '.IT', '.COM.',...)");
         campo.focus();
        return false;
   }
   alert("ATTENZIONE !!! - Indirizzo di e-mail non corretto\n\n( sono presenti caratteri non consentiti )");
   campo.focus();
   return false;

  } else return true;
}

 function iscrizioneNewsletter(form){
    if(document.forms[form].nemail.value==""  || document.forms[form].nemail.value == null){
      alert('Inserire il proprio indirizzo email!');
      return false;
    } else {
     if(isEmail('nemail')){
         // document.forms[form].submit();
         return true;
        } else return false;
    }
 }

 function check_invio(evt,form) {

    var theKey
     if (isNav4) {
        theKey = evt.which
     } else {
        if (isIE4) {
           theKey = window.event.keyCode
        }
     }

        if (theKey == 13)  {
                iscrizioneNewsletter(form);
                return false;
        } else {
                return window.event.keyCode
        }
}

function aggiornaRicerca(val,testo){
  if(document.forms['ric_avanzata']!=null){
      document.getElementById('testoA').value=testo;
      document.cookie="ultimaricerca="+val;
      if(val=='informazioni') {
        document.getElementById('infoAv').checked=true;
      }  else {
       document.getElementById('prodAv').checked=true;
      }

    } else {
      if(document.forms['homeric']!=null){
       document.getElementById('testo').value=testo;
       document.cookie="ultimaricerca="+val;
      }
    }
}

//aggiunge una option alla select passata come argomento
function addItem(idsel,optval,opttxt) {
  mysel = document.getElementById(idsel)
  var trovato=false;
  for (var i=0;i<mysel.options.length;i++) {
    if (mysel.options[i].value==optval) {
      trovato=true;
      break;
    }
  }
  if(!trovato) mysel.options[mysel.length] = new Option(opttxt,optval);
}

//rimuove un elemento (selezionato) alla select passata come parametro
function removeItem(idsel,optval,opttxt) {
  //optval: val della option da cancellare
  //opttxt: testo della option da cancellare
  //se non passiamo i 2 parametri cancella la option selezionata

  mysel = document.getElementById(idsel)
  if (mysel.length<=0)
    return;

  if (optval) {
    for(var i=0;i<mysel.options.length;i++){
      if(mysel.options[i].value==optval){
        mysel.options[i]=null;
      }
    }
  } else {
    var ind = mysel.selectedIndex;
    if (ind!=-1)
      mysel.options[ind]=null;
  }

}


function getRadioValue(radioName, formId) {

	var oForm = formId ? document.forms[formId] : document.forms[0];
	var oRadio = oForm.elements[radioName];

	for (var i = 0; i < oRadio.length; i++)
	{
		if (oRadio[i].checked)
		{
			return oRadio[i].value;
		}
	}

	return '';
}


/**************************************/

function orderByPrezzo(theForm) {
	submitForm(theForm);
}

function submitForm(theForm) {
	theForm.submit();
}
