  var strBrowser=navigator.appName;
  if (navigator.userAgent.toLowerCase().indexOf("applewebkit/")!= -1){
    strBrowser="wk";
  }else if (strBrowser=='Microsoft Internet Explorer'){
    strBrowser="ie";
  }else if (strBrowser=='Konqueror'){
    strBrowser="ko";
  }else{
    strBrowser="ff";
  };
	var options_xml = {
		script:"/autosuggest-GetRicambiVeicoliCategorie.aspx?",
		varname:"input",
		cache:false,
		json: false,
		minchars:1,
		delay:100,
		callback: function (obj) {document.getElementById("testoricerca").value = obj.id;}		
	};
	var as_xml;

  function validaForm() {
    if (document.getElementById){
      var i,p,q,nm,test,num,min,max,errors='',args=validaForm.arguments;
      for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
        if (val) { nm=val.name; if ((val=val.value)!="") {
          if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
            if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve contenere un indirizzo e-mail.\n';
          } else if (test!='R') { num = parseFloat(val);
            if (isNaN(val)) errors+='- '+nm+' deve contenere un numero.\n';
            if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
              min=test.substring(8,p); max=test.substring(p+1);
              if (num<min || max<num) errors+='- '+nm+' deve contenere un numero tra '+min+' e '+max+'.\n';
        } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' e\' obbligatorio.\n'; }
      } if (errors) alert('Attenzione:\n'+errors);
      return (errors == '');
  } }
  function caricaBanner() {
	  var ul = $$("#vertical_carousel .container ul").first();
    ul.update(strCarousel);    
    new UI.Carousel("vertical_carousel", {direction:"vertical",nbVisible:5});
  }

  function Init(){
    as_xml = new bsn.AutoSuggest('testoricerca', options_xml);
    caricaBanner()
    caricamodelliricerca();
    if (document.getElementById("VeicoliMarca_Kyricerca").value!=undefined && document.getElementById("VeicoliModello_Kyricerca").length<2){
      ldModelliRichiedi();
    }
  };

  function InitRicerca(){
    if (intMarcaCurrent!=0 && intMarcaCurrent!=undefined){
      document.getElementById("VeicoliMarca_Kyricerca").value=intMarcaCurrent;
      document.getElementById("marca").value=intMarcaCurrent;
      ldModelliRicerca();
      ldModelliRichiedi();
    }
    if (intModelloCurrent!=0 && intModelloCurrent!=undefined){
      caricamodelliricerca();
      document.getElementById("VeicoliModello_Kyricerca").value=intModelloCurrent;
      document.getElementById("modello").value=intModelloCurrent;
    }
    if (intCategoriaCurrent!=0 && intCategoriaCurrent!=undefined){
      document.getElementById("RicambiVeicoliCategorie_Ky").value=intCategoriaCurrent;
      document.getElementById("RicambiVeicoliCategorie_Kyricerca").value=intCategoriaCurrent;
    }  
    if (strRicerca!="" && strRicerca!=undefined){
      document.getElementById("strRicerca").value=strRicerca;
    }  
  };
  
  function getElementValue(xmlDoc, strName){
      if (strBrowser=='ie'){
        try{ 
          return xmlDoc.getElementsByTagName(strName).item(0).text;
        }catch(e){
          return "";
        }
      }else if ((strBrowser=='ko') || (strBrowser=='wk')){
        try{ 
          return xmlDoc.getElementsByTagName(strName).item(0).firstChild.nodeValue;
        }catch(e){
          return "";
        }
      }else{
        try{ 
          return xmlDoc.getElementsByTagName(strName)[0].textContent;
        }catch(e){
          return "";
        }
      }
  };
  function XMLDoc(strXML){
    if (document.implementation.createDocument){ 
      var parser = new DOMParser(); 
      var xmldoc = parser.parseFromString(strXML, "text/xml"); 
    }
    else if (window.ActiveXObject) { 
      var xmldoc = new ActiveXObject("Microsoft.XMLDOM");   
      //xmldoc.async=false;
      xmldoc.loadXML(strXML);                                     
    }
    return xmldoc;
  };
  function fnKy(nV){
    return nV.replace(".", "");
  };
  function jsHttpPost(sUrl, strXML){
    var xmlhttp=false;
    var sR;
    sR='';
    try{
		  try {
			  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		  } catch (e) {
			  try {
			    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			  } catch (e) {}
		  }
    }catch (e) {
      xmlhttp = false;
    }
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') { //firefox e altri
      xmlhttp = new XMLHttpRequest();
      xmlhttp.open("POST", sUrl,false);
      xmlhttp.send(strXML);
      sR=xmlhttp.responseText;
      return sR;
    }
    else{                                                 //internet explorer
      xmlhttp.open("POST", sUrl,false);
      xmlhttp.send(strXML); 
      return xmlhttp.ResponseText;
    }
  };
  
  function caricamodelliricerca(){
    var sHTML;
    var listField;
    var strWHERE;
    var strXML;

    if (document.getElementById("VeicoliMarca_Kyricerca").value.length>0){
      listField=document.getElementById("VeicoliModello_Kyricerca");
      listField.length=0;
      strWHERE="VeicoliMarca_Ky=" + document.getElementById("VeicoliMarca_Kyricerca").value;
      strXML="<db><rs><st>frk_Read<\/st><tb>VeicoliModello<\/tb><ky>VeicoliModello_Ky<\/ky><whr>" + strWHERE + "<\/whr><ord>VeicoliModello_Descrizione<\/ord><fields>VeicoliModello_Ky,VeicoliModello_Descrizione<\/fields><\/rs><\/db>";
      strXML=jsHttpPost("/frk/db/SQLServer/frkStoreExecute.asp",strXML);
      var xmldoc=XMLDoc(strXML);
      var db = xmldoc.getElementsByTagName("rs");
      var len = listField.length++; 
      listField.options[len].value = '';
      listField.options[len].text = 'Qualsiasi'; 
      for(var i = 0; i < db.length; i++) {
        var len = listField.length++; 
        var e = db[i];
        listField.options[len].value = fnKy(getElementValue(e,"VeicoliModello_Ky"));
        listField.options[len].text = getElementValue(e,"VeicoliModello_Descrizione");
      }
    }
  };  
  function caricamodelli(){
    var sHTML;
    var listField;
    var strWHERE;
    var strXML;
    
    if (document.getElementById("VeicoliMarca_Ky").value.length>0){
      listField=document.getElementById("VeicoliModello_Ky");
      listField.length=0;
      strWHERE="VeicoliMarca_Ky=" + document.getElementById("VeicoliMarca_Ky").value;
      strXML="<db><rs><st>frk_Read<\/st><tb>VeicoliModello<\/tb><ky>VeicoliModello_Ky<\/ky><whr>" + strWHERE + "<\/whr><ord>VeicoliModello_Descrizione<\/ord><fields>VeicoliModello_Ky,VeicoliModello_Descrizione<\/fields><\/rs><\/db>";
      strXML=jsHttpPost("/frk/db/SQLServer/frkStoreExecute.asp",strXML);
      var xmldoc=XMLDoc(strXML);
      var db = xmldoc.getElementsByTagName("rs");
      var len = listField.length++; 
      listField.options[len].value = '';
      listField.options[len].text = 'Qualsiasi'; 
      for(var i = 0; i < db.length; i++) {
        var len = listField.length++; 
        var e = db[i];
        listField.options[len].value = fnKy(getElementValue(e,"VeicoliModello_Ky"));
        listField.options[len].text = getElementValue(e,"VeicoliModello_Descrizione");
      }
    }
  };  
  function ldModelliRicerca(){
    var sHTML;
    var listField;
    var strWHERE;
    var strXML;
  
    listField=document.getElementById("VeicoliModello_Kyricerca");
    listField.options.length = 0;
	  if (document.getElementById("VeicoliMarca_Kyricerca").value!=""){
        strWHERE="VeicoliMarca_Ky=" + document.getElementById("VeicoliMarca_Kyricerca").value;
        strXML="<db><rs><st>frk_Read</st><tb>VeicoliModello</tb><ky>VeicoliModello_Ky</ky><whr>" + strWHERE + "</whr><ord>VeicoliModello_Descrizione</ord></rs></db>";
        strXML=jsHttpPost("/frk/db/SQLServer/frkStoreExecute.asp",strXML);
        var xmldoc=XMLDoc(strXML);
        var db = xmldoc.getElementsByTagName("rs");
        intLen=db.length;
        var len = listField.length++; 
        listField.options[0].value = "";
        listField.options[0].text = "";
        for(var i = 0; i < intLen; i++) {
          var len = listField.length++; 
          var e = db[i];
          listField.options[len].value = fnKy(getElementValue(e,"VeicoliModello_Ky"));
          listField.options[len].text = getElementValue(e,"VeicoliModello_Descrizione");
        }
    }  
  };
  function ldModelliRichiedi(){
    var sHTML;
    var listField;
    var strWHERE;
    var strXML;
  
    listField=document.getElementById("modello");
    listField.options.length = 0;
	  if (document.getElementById("marca").value!=""){
        strWHERE="VeicoliMarca_Ky=" + document.getElementById("marca").value;
        strXML="<db><rs><st>frk_Read</st><tb>VeicoliModello</tb><ky>VeicoliModello_Ky</ky><whr>" + strWHERE + "</whr><ord>VeicoliModello_Descrizione</ord></rs></db>";
        strXML=jsHttpPost("/frk/db/SQLServer/frkStoreExecute.asp",strXML);
        var xmldoc=XMLDoc(strXML);
        var db = xmldoc.getElementsByTagName("rs");
        intLen=db.length;
        var len = listField.length++; 
        listField.options[0].value = "";
        listField.options[0].text = "";
        for(var i = 0; i < intLen; i++) {
          var len = listField.length++; 
          var e = db[i];
          listField.options[len].value = fnKy(getElementValue(e,"VeicoliModello_Ky"));
          listField.options[len].text = getElementValue(e,"VeicoliModello_Descrizione");
        }
    }  
  };

  function inviaRichiesta(){
    var strNome=document.formRichiedi.nome.value;
    var strProvincia=document.formRichiedi.provincia.value;
    var strEmail=document.formRichiedi.email.value;
    var strMarca=document.formRichiedi.marca.value;
    var strModello=document.formRichiedi.modello.value;
    var strAnno=document.formRichiedi.anno.value;
    var strCodice=document.formRichiedi.codice.value;
    var strDisclaimer=document.formRichiedi.disclaimer[0].checked;
    var strPrivacy=document.formRichiedi.privacy[0].checked;
    var strTipologia=document.formRichiedi.RicambiVeicoliCategorie_Ky.value;
  	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  	var check;
  	
    check=true;
	 if ((strNome == "") || (strNome == "undefined")){
     	alert("Attenzione! Il campo NOME o riferimento e' obbligatorio");
      document.formRichiedi.nome.focus();
			check="false";
      return false;
    }
    if ((strProvincia == "") || (strProvincia == "undefined")){
     	alert("Attenzione! Il campo PROVINCIA e' obbligatorio");
      document.formRichiedi.provincia.focus();
			check="false";
      return false;
    }
  	if ((strEmail == "") || (strEmail == "undefined")){
      alert("Inserire un indirizzo Email corretto.");
      document.formRichiedi.email.focus();
  		check=false;
    }else{
      if (!email_reg_exp.test(strEmail)) {
      	alert("Inserire un indirizzo Email corretto.");
        document.formRichiedi.email();
				check=false;
    	}
    }
    if ((strMarca == "") || (strMarca == "undefined")){
     	alert("Attenzione! Il campo MARCA e' obbligatorio");
      document.formRichiedi.marca.focus();
  		check=false;
      return false;
    }
    if ((strModello == "") || (strModello == "undefined")){
     	alert("Attenzione! Il campo MODELLO e' obbligatorio");
      document.formRichiedi.modello.focus();
  		check=false;
      return false;
    }
		if ((strAnno == "") || (strAnno == "undefined")){
     	alert("Attenzione! Il campo ANNO e' obbligatorio");
      document.formRichiedi.anno.focus();
  		check=false;
      return false;
    }
    if ((strCodice == "") || (strCodice == "undefined")){
     	alert("Attenzione! Il campo codice di controllo e' obbligatorio");
      document.formRichiedi.marca.focus();
  		check=false;
      return false;
    }
    if ((strTipologia == "") || (strTipologia == "undefined")){
     	alert("Attenzione! Compila la tipologia correttamente per risposte precise e veloci");
      document.formRichiedi.RicambiVeicoliCategorie_Ky.focus();
  		check=false;
      return false;
    }
    if (strPrivacy == false){
     	alert("Attenzione! E' necessario dare il consenso dei dati e accettare le condizioni del sito");
  		check=false;
      return false;
    }
    if (strDisclaimer == false){
     	alert("Attenzione! E' necessario dare il consenso dei dati e accettare le condizioni del sito");
  		check=false;
      return false;
    }
    if (check==true) {
      document.formRichiedi.action="/form/form-richiedi-ricambio.aspx";
			document.formRichiedi.target="_parent";
			document.formRichiedi.submit();
  	}  
  }
  
  function contattaVenditore(){
    var strNome=document.formRichiedi.nome.value;
    var strEmail=document.formRichiedi.email.value;
    var strDisclaimer=document.formRichiedi.disclaimer[0].checked;
    var strPrivacy=document.formRichiedi.privacy[0].checked;
  	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  	var check;
  	
    check=true;
	 if ((strNome == "") || (strNome == "undefined")){
     	alert("Attenzione! Il campo NOME o riferimento e' obbligatorio");
      document.formRichiedi.nome.focus();
			check="false";
      return false;
    }
  	if ((strEmail == "") || (strEmail == "undefined")){
      alert("Inserire un indirizzo Email corretto.");
      document.formRichiedi.email.focus();
  		check=false;
    }else{
      if (!email_reg_exp.test(strEmail)) {
      	alert("Inserire un indirizzo Email corretto.");
        document.formRichiedi.email();
				check=false;
    	}
    }
    if (strPrivacy == false){
     	alert("Attenzione! E' necessario dare il consenso dei dati e accettare le condizioni del sito");
  		check=false;
      return false;
    }
    if (strDisclaimer == false){
     	alert("Attenzione! E' necessario dare il consenso dei dati e accettare le condizioni del sito");
  		check=false;
      return false;
    }
    if (check==true) {
      document.formRichiedi.action="/form/form-contatti-venditore.aspx";
			document.formRichiedi.target="_parent";
			document.formRichiedi.submit();
  	}  
  }  
  
  function inviaAdesione(){
  	var check=true;

  	check=validaForm('ragsoc','','R','piva','','RisNum','telefono','','R','indirizzo','','R','email','','RisEmail','password','','R','codice','','RisNum');
    if (check==true) {
      document.formAdesione.action="/form/form-registrazione-ricambi-auto.aspx";
			document.formAdesione.target="_parent";
			document.formAdesione.submit();
  	}  
  }
  function ldComuni(){
    var sHTML;
    var listField;
    var strWHERE;
    var strXML;
  
    listField=document.getElementById("comunevenditore");
    listField.options.length = 0;
	  if (document.getElementById("provinciavenditore").value!=""){
        strWHERE="Province_Ky=" + document.getElementById("provinciavenditore").value;
        strXML="<db><rs><st>frk_Read</st><tb>Comuni</tb><ky>Comuni_Ky</ky><whr>" + strWHERE + "</whr><ord>Comuni_Comune</ord></rs></db>";
        strXML=jsHttpPost("frk/db/SQLServer/frkStoreExecute.asp",strXML);
        var xmldoc=XMLDoc(strXML);
        var db = xmldoc.getElementsByTagName("rs");
        intLen=db.length;
        var len = listField.length++; 
        listField.options[0].value = "";
        listField.options[0].text = "";
        for(var i = 0; i < intLen; i++) {
          var len = listField.length++; 
          var e = db[i];
          listField.options[len].value = fnKy(getElementValue(e,"Comune_Ky"));
          listField.options[len].text = getElementValue(e,"Comuni_Comune");
        }
    }  
  }
  function inviaContatti(){
          if (validaForm('nome','','R','cognome','','R','indirizzo','','R','cap','','RisNum','citta','','R','provincia','','R','telefono','','R','email','','RisEmail')==true){
            document.formContatti.submit();
          }
        }
  function MM_validateForm() { //v4.0
    if (document.getElementById){
      var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
      for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
        if (val) { nm=val.name; if ((val=val.value)!="") {
          if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
            if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
          } else if (test!='R') { num = parseFloat(val);
            if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
            if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
              min=test.substring(8,p); max=test.substring(p+1);
              if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
        } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
      } if (errors) alert('The following error(s) occurred:\n'+errors);
      document.MM_returnValue = (errors == '');
  } }

  function apriFinestraContatti(){
    var strContent;
    strContent="<div style=\"line-height:30px\" align=\"center\"><br /><font color=\"#eb0000\" size=\"5\"><b>ATTENZIONE!</b></font><br /><br /><font color=\"#000000\" size=\"4\">Non utilizzare questo modulo per richiedere ricambi o parti di ricambio ma l'apposito modulo richiedi ricambio in <a href=\"/\">home page</a>.</font></div>";
    CSS.preloadImages();
    new UI.Window({width: 600, height: 300,theme: "alphacube", shadow: true,show: Element.appear,hide: Element.fade }).center().setContent(strContent).show();
  }
  function caricaMappa(address) {
    if (GBrowserIsCompatible()) {
      var map = new GMap2(document.getElementById("google_map"));
      map.setCenter(new GLatLng(47, 19), 3); 
      map.setMapType(G_HYBRID_MAP);
      map.setUIToDefault();
      map.enableRotation();
      var geocoder = new GClientGeocoder();
      geocoder.getLatLng(
        address,
        function(point) {
          if (!point) {
            alert(address + " non trovato");
          } else {
            map.setCenter(point, 14);
            var marker = new GMarker(point);
            map.addOverlay(marker);
          }
        }
      );
      }       
  };
  function tipoUtente(intTipo){
    switch (intTipo){
      case 1:
        document.getElementById("trragsoc").style.display="none";
        document.getElementById("trpiva").style.display="none";
        document.getElementById("trcodfisc").style.display="none";
        break;
      case 2:
        document.getElementById("trragsoc").style.display="";
        document.getElementById("trpiva").style.display="";
        document.getElementById("trcodfisc").style.display="";
        break;
    }
  }
  
  function visualizzaInfoRicambio(){
    if ((document.getElementById("RicambiVeicoliCategorie_Ky").value==83) || (document.getElementById("RicambiVeicoliCategorie_Ky").value==121)){
      Lightview.show({ href: '/infolibretto.htm', rel: 'iframe', options: { width: 840, height: 350 }});
    } 
   }