  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";
  };
  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;
    }
  };
	var options_xmlArtisti = {
		script:"/autosuggest-GetArtisti.aspx?",
		varname:"input",
		cache:false,
		json: false,
		minchars:1,
		delay:100,
		callback: function (obj) {document.getElementById("searchArtista").value = obj.value;}		
	};
	var as_xmlArtisti;
	var options_xmlDove = {
		script:"/autosuggest-GetUbicazioneArtista.aspx?",
		varname:"input",
		cache:false,
		json: false,
		minchars:1,
		delay:100,
		callback: function (obj) {document.getElementById("searchDove").value = obj.value;}		
	};
	var as_xmlDove;

  function Init(){
    as_xmlArtisti = new bsn.AutoSuggest("searchArtista", options_xmlArtisti);
    as_xmlDove = new bsn.AutoSuggest("searchDove", options_xmlDove);
    refreshCMSUtenti();
  };

  function jsGetCookies(name) { 
    var bikky = document.cookie;
    var index = bikky.indexOf(name + "=");
    if (index == -1) return null;
    index = bikky.indexOf("=", index) + 1; 
    var endstr = bikky.indexOf(";", index);
    if (endstr == -1){ endstr = bikky.length;}; 
    return unescape(bikky.substring(index, endstr));
  };	
    
  function jsSetCookies(sCookies,sTxt){
  	document.cookie=sCookies + "=" + sTxt + ";path=/;";
  };
  
  function exitUser(){
    jsSetCookies("Utenti_Ky" , "");
		jsSetCookies("Utenti_Email" , "");
		jsSetCookies("Utenti_Password" , "");
		refreshCMSUtenti();
  };
  
  function refreshCMSUtenti(){
    if ((jsGetCookies("arteantica")==null) || (jsGetCookies("arteantica")=='')){
      document.getElementById("Utenti").innerHTML="<a href=\"/accesso-arte-antica.htm\" class=\"nero\">Accedi</a>";
      document.getElementById("Registrati").style.display="";
    }else{
      document.getElementById("Utenti").innerHTML="<a href=\"#\" class=\"nero\">" + jsGetCookies("arteantica") + "</a> <a href=\"/logout.aspx\"><img src=\"/arte-antica-images/logout.gif\" title=\"Esci\" border=\"0\"/></a>";
      //document.getElementById("Registrati").style.display="none";
    }
  };
  
  function changeNazione(){
    if (document.getElementById("nazione").value!=105){
      document.getElementById("trprovincia").style.display="none";
      document.getElementById("trcomune").style.display="none";
    }else{
      document.getElementById("trprovincia").style.display="";
      document.getElementById("trcomune").style.display="";
    }
  }
  
  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 tipoUtente(intTipo){
    switch (intTipo){
      case 1:
        document.getElementById("trragsoc").style.display="";
        document.getElementById("trpiva").style.display="";
        document.getElementById("trcodfisc").style.display="";
        break;
      case 2:
        document.getElementById("trragsoc").style.display="";
        document.getElementById("trpiva").style.display="";
        document.getElementById("trcodfisc").style.display="";
        break;
      case 3:
        document.getElementById("trragsoc").style.display="";
        document.getElementById("trpiva").style.display="";
        document.getElementById("trcodfisc").style.display="";
        break;
      case 4:
        document.getElementById("trragsoc").style.display="";
        document.getElementById("trpiva").style.display="";
        document.getElementById("trcodfisc").style.display="";
        break;
      case 5:
        document.getElementById("trragsoc").style.display="none";
        document.getElementById("trpiva").style.display="none";
        document.getElementById("trcodfisc").style.display="none";
        break;
      case 6:
        document.getElementById("trragsoc").style.display="none";
        document.getElementById("trpiva").style.display="none";
        document.getElementById("trcodfisc").style.display="none";
        break;
      case 7:
        document.getElementById("trragsoc").style.display="";
        document.getElementById("trpiva").style.display="";
        document.getElementById("trcodfisc").style.display="";
        break;
      case 8:
        document.getElementById("trragsoc").style.display="none";
        document.getElementById("trpiva").style.display="none";
        document.getElementById("trcodfisc").style.display="none";
        break;
    }
  }
  
  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_validateForm() { //v4.0
    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=MM_findObj(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 valido.\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+' e\' obbligatorio.\n'; }
    } if (errors) alert('Attenzione:\n'+errors);
    document.MM_returnValue = (errors == '');
  }
