var ol_fgcolor = "#f4f4f4";
var ol_bgcolor = "#D98B25";
var ol_textcolor = "#000000";
var ol_capcolor = "#ffffff";
var ol_textfont = "Verdana,Arial,Helvetica";
var ol_captionfont = "Verdana,Arial,Helvetica";
var ol_textsize = "1";
var ol_captionsize = "1";
var ol_width = "190";
var ol_border = "1";
var ol_capicon = "";
var ol_offsety = -25;
var strBrowser=navigator.appName;

//********************************************** ARRAY TIPOLOGIE   ************************************************************************
// 1 - Abitativo
var tipologieResidenziali = new Array('1','Appartamento','11','Cantiere','4','Casa colonica','5','Casa indipendente','2','Indipendente','12','Mansarda','10','Palazzina/Stabile','6','Posto letto','7','Rustico','9','Semindipendente','3','Villa','8','Villetta');

// 2 - Negozi uffici
var tipologieCommerciali = new Array('23','Commerciale','22','Direzionale','20','Fondo/Negozio','21','Laboratorio','24','Laboratorio Art.');

// 4 -Capannone/Deposito
var tipologieCapannone = new Array('15','Capannone','18','Commerciale','19','Deposito','17','Industriale','16','Laboratorio');

// 3 - Attivita' commerciale
var tipologieAttivita = new Array('13','Dettaglio','14','Ingrosso');

// 5 - Terreno/Fondo
var tipologieTerreni = new Array('28','Agricolo','29','Edificabile','30','Industriale');

// 6 - Garage
var tipologieGarage = new Array('25','Box','26','Garage','27','Posto Auto');

//********************************************** FINE ARRAY ************************************************************************
var intCategoriaSelezionata=1;

var strProvincia="Milano";

    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 jsSetCookies(sCookies,sTxt){
  	document.cookie=sCookies + "=" + sTxt + ";path=/;";
  };
  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 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 apriSottomenu(strId){
    if (document.getElementById(strId).style.display=='none'){
      document.getElementById(strId).style.display='';
    }
    else{
      document.getElementById(strId).style.display='none';
    }
  };
  
  // su caricamento
  function Init(){
  
	  // setta invisibile in flash di attesa invio
    document.getElementById("indicatore").style.display="none";
     // lista prezzi bassi affitto
	if (document.getElementById("contratto1").checked==true){
        aggiorna_contratto(1);
    }
     // lista prezzi alti Vendita
    if (document.getElementById("contratto2").checked==true){
		aggiorna_contratto(2);
	}
     // lista prezzi bassi Asta
    if (document.getElementById("contratto3").checked==true){
		aggiorna_contratto(2);
	}
	// carica i comuni della select
	caricaComuni();
	
	// carica le tipologie della select
    caricaTipologie(true);   
  };
 
  function Init2(){
/*  
	  // setta invisibile in flash di attesa invio
    document.getElementById("indicatore").style.display="none";
     // lista prezzi bassi affitto
	if (document.getElementById("contratto1").checked==true){
        aggiorna_contratto(1);
    }
     // lista prezzi alti Vendita
    if (document.getElementById("contratto2").checked==true){
		aggiorna_contratto(2);
	}
     // lista prezzi bassi Asta
    if (document.getElementById("contratto3").checked==true){
		aggiorna_contratto(2);
	}
	*/
	// carica i comuni della select
	caricaComuniValProp();
	
	// carica le tipologie della select
    caricaTipologie(true);   
  };

function caricaComuni(){
	var sHTML;
    var listField;
    var strWHERE;
    var strXML;
    var strProvinciaSQL;
    listField=document.getElementById("Comuni_Ky");
    listField.length=0;
    strProvinciaSQL=document.getElementById("provincia").value.replace("'","''");
    strWHERE="Province_Provincia= '" + strProvinciaSQL + "'";
	strXML="<db><rs><st>frk_Read<\/st><tb>Comuni_Vw<\/tb><ky>Comuni_Ky<\/ky><whr>" + strWHERE + "<\/whr><ord>Comuni_Comune<\/ord><fields>Province_Codice,Comuni_Ky,Comuni_Comune,Province_Provincia<\/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,"Comuni_Ky"));
      listField.options[len].text = getElementValue(e,"Comuni_Comune");
	  
    }
  };
  
function caricaComuniValProp(){
	var sHTML;
    var listField;
    var strWHERE;
    var strXML;
    var strProvinciaSQL;
    listField=document.getElementById("Comuni_Ky");
    listField.length=0;
    strProvinciaSQL=document.getElementById("provincia").value.replace("'","''");
    strWHERE="Province_Provincia= '" + strProvinciaSQL + "'";
	strXML="<db><rs><st>frk_Read<\/st><tb>Comuni_Vw<\/tb><ky>Comuni_Ky<\/ky><whr>" + strWHERE + "<\/whr><ord>Comuni_Comune<\/ord><fields>Province_Codice,Comuni_Ky,Comuni_Comune,Province_Provincia<\/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 = 'Scegli'; 
    for(var i = 0; i < db.length; i++) {
      var len = listField.length++; 
      var e = db[i];
      listField.options[len].value = fnKy(getElementValue(e,"Comuni_Ky"));
      listField.options[len].text = getElementValue(e,"Comuni_Comune");
	  
    }
  };
  
 function caricaZona(){
    var sHTML;
    var listField;
    var strWHERE;
    var strXML;
    
    listField=document.getElementById("zona");
    //listField.options.length = 0;
    listField.length = 0;
    strWHERE="Comuni_Ky='" + document.getElementById("Comuni_Ky").value + "'";
    strXML="<db><rs><st>frk_Read<\/st><tb>ImmobiliZona_Vw<\/tb><ky>ImmobiliZona_Ky<\/ky><whr>" + strWHERE + "<\/whr><ord>ImmobiliZona_Descrizione<\/ord><\/rs><\/db>";
    strXML=jsHttpPost("/frk/db/SQLServer/frkStoreExecute.asp",strXML);
    if (document.implementation.createDocument){ 
      var parser = new DOMParser(); 
      xmldoc = parser.parseFromString(strXML, "text/xml"); 
    }
    else if (window.ActiveXObject) { 
        var xmldoc = new ActiveXObject("Microsoft.XMLDOM");   
        xmldoc.loadXML(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 = getElementValue(e,"ImmobiliZona_Descrizione");
      listField.options[len].text = getElementValue(e,"ImmobiliZona_Descrizione");
	  
    }
    
  };
//-----------------------------------------------------------
// usato nel file proponi-casa
  function aggiorna_agenzia(){
    var sHTML;
    var listField;
    var strWHERE;
    var strXML;
    
    listField=document.getElementById("agenzia");
    //listField.options.length = 0;
    listField.length = 0;
    strWHERE="Anagrafiche_CmnKy=" + document.getElementById("Comuni_Ky").value + "";
    strXML="<db><rs><st>frk_Read<\/st><tb>Anagrafiche_Agenzie_Vw<\/tb><ky>Anagrafiche_Ky<\/ky><whr>" + strWHERE + "<\/whr><ord>Anagrafiche_RagSoc<\/ord><fields>Anagrafiche_Email,Anagrafiche_RagSoc,Anagrafiche_Ky<\/fields><\/rs><\/db>";
    strXML=jsHttpPost("/frk/db/SQLServer/frkStoreExecute.asp",strXML);
    if (document.implementation.createDocument){ 
      var parser = new DOMParser(); 
      xmldoc = parser.parseFromString(strXML, "text/xml"); 
    }
    else if (window.ActiveXObject) { 
        var xmldoc = new ActiveXObject("Microsoft.XMLDOM");   
        xmldoc.loadXML(strXML);                                     
    }
    var db = xmldoc.getElementsByTagName("rs");
    var len = listField.length++; 
	if (db.length >0)
	{
    listField.options[len].value = '';
    listField.options[len].text = 'Seleziona un agenzia';
	for(var i = 0; i < db.length; i++) 
	{
      var len = listField.length++; 
      var e = db[i];
	  listField.options[len].value = getElementValue(e,"Anagrafiche_Email");
      listField.options[len].text = getElementValue(e,"Anagrafiche_RagSoc");
    }
	}
	else
	{
    listField.options[len].value = 'supporto@retecasa.it';
    listField.options[len].text = 'Retecasa Sede Centrale';
	}
  };
  
//-----------------------------------------------------------
  function caricaTipologie(fTutte){
    var sHTML;
    var strWHERE;
    var strFROM;
    var strXML;

    var listField;
    var ArraySelezionato;
    switch (intCategoriaSelezionata){
      case 1:
        ArraySelezionato=tipologieResidenziali;
        ArraySelezionato.length=tipologieResidenziali.length;
        break;
      case 2:
        ArraySelezionato=tipologieCommerciali;
        ArraySelezionato.length=tipologieCommerciali.length;
        break;
      case 3:
        ArraySelezionato=tipologieAttivita;
        ArraySelezionato.length=tipologieAttivita.length;
        break;
      case 4:
        ArraySelezionato=tipologieCapannone;
        ArraySelezionato.length=tipologieCapannone.length;
        break;
      case 5:
        ArraySelezionato=tipologieTerreni;
        ArraySelezionato.length=tipologieTerreni.length;
        break;
      case 6:
        ArraySelezionato=tipologieGarage;
        ArraySelezionato.length=tipologieGarage.length;
        break;
    
    }
    listField=document.getElementById("tipologia");
    listField.options.length = 0;
    var len = listField.length++; 
    listField.options[len].value = '';
    listField.options[len].text = 'Qualsiasi';  
    for(var i = 0; i < ArraySelezionato.length/2; i++) {
      var len = listField.length++; 
      listField.options[len].value = ArraySelezionato[i*2];
      listField.options[len].text = ArraySelezionato[i*2+1];
    }
  };
// SottoTipologie--------------------------------  
 function caricaSottoTipo(){
	var sHTML;
    var listField;
    var strWHERE;
    var strXML;
    var strSottoTipologiaSQL;
    listField=document.getElementById("sottotipologia");
    listField.length=0;
    strSottoTipologiaSQL=document.getElementById("tipologia").value;
    strWHERE="Tipologia_Ky= " + strSottoTipologiaSQL;
    strXML="<db><rs><st>frk_Read<\/st><tb>ImmobiliSottoTipologia_Gruppo_Vw<\/tb><ky>ImmobiliSottotipologia_Ky<\/ky><whr>" + strWHERE + "<\/whr><ord>ImmobiliSottotipologia_Descrizione<\/ord><fields>Tipologia_Ky,ImmobiliSottotipologia_Ky,ImmobiliSottotipologia_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,"ImmobiliSottotipologia_Ky"));
      listField.options[len].text = getElementValue(e,"ImmobiliSottotipologia_Descrizione");
	  
    }
  };
//-------------------------------------------------
function aggiorna_categoria(intCategoria){
    intImmobiliArea_Ky=intCategoria;
    intCategoriaSelezionata=intCategoria;
    caricaTipologie(true);
  };

  function aggiorna_provincia(){
    caricaTipologie(true);
  };
  
  function aggiorna_comune(){
  };
  	
  function aggiorna_contratto(intContratto){
    var listField;
	var listField2;
	if (intContratto==1){
	  listField=document.getElementById("prezzo");
      listField.options.length = 0;
      listField.options.length = 10;
      listField.options[0].value = '0';
      listField.options[0].text = '0';  
      listField.options[1].value = '300';
      listField.options[1].text = '300';  
      listField.options[2].value = '400';
      listField.options[2].text = '400';  
      listField.options[3].value = '500';
      listField.options[3].text = '500';  
      listField.options[4].value = '600';
      listField.options[4].text = '600';  
      listField.options[5].value = '700';
      listField.options[5].text = '700';  
      listField.options[6].value = '800';
      listField.options[6].text = '800';  
      listField.options[7].value = '1000';
      listField.options[7].text = '1000'; 
      listField.options[8].value = '1500';
      listField.options[8].text = '1500';  
      listField.options[9].value = '99999999999';
      listField.options[9].text = 'Oltre';  
	  // modifica da qui
	  listField2=document.getElementById("prezzo2");
      listField2.options.length = 0;
      listField2.options.length = 11;
      listField2.options[0].value = '99999999999';
      listField2.options[0].text = 'Qualunque';  
      listField2.options[1].value = '300';
      listField2.options[1].text = '300';  
      listField2.options[2].value = '400';
      listField2.options[2].text = '400';  
      listField2.options[3].value = '500';
      listField2.options[3].text = '500';  
      listField2.options[4].value = '600';
      listField2.options[4].text = '600';  
      listField2.options[5].value = '700';
      listField2.options[5].text = '700';  
      listField2.options[6].value = '800';
      listField2.options[6].text = '800';  
      listField2.options[7].value = '900';
      listField2.options[7].text = '900';  
      listField2.options[8].value = '1000';
      listField2.options[8].text = '1000';  
      listField2.options[9].value = '1500';
      listField2.options[9].text = '1500';  
	  listField2.options[10].value = '99999999999';
      listField2.options[10].text = 'Oltre'; 
	  // a qui
    }else{
      // Se e' IN AFFITTO mostra i campi con prezzo basso 
      listField=document.getElementById("prezzo");
      listField.options.length = 0;
      listField.options.length = 8;
      listField.options[0].value = '0';
      listField.options[0].text = '0'; 
      listField.options[1].value = '50000';
      listField.options[1].text = '50.000'; 
      listField.options[2].value = '100000';
      listField.options[2].text = '100.000';  
      listField.options[3].value = '150000';
      listField.options[3].text = '150.000';  
      listField.options[4].value = '200000';
      listField.options[4].text = '200.000';  
      listField.options[5].value = '300000';
      listField.options[5].text = '300.000';  
      listField.options[6].value = '500000';
      listField.options[6].text = '500.000';  
      listField.options[7].value = '9999999';
      listField.options[7].text = 'Oltre';  
	  //modifica da qui
	  listField2=document.getElementById("prezzo2");
      listField2.options.length = 0;
      listField2.options.length = 8;
      listField2.options[0].value = '999999999';  
	  listField2.options[0].text = 'Qualunque';  
	  listField2.options[1].value = '50000';
      listField2.options[1].text = '50.000';  
	  listField2.options[2].value = '100000';
      listField2.options[2].text = '100.000';  
      listField2.options[3].value = '150000';
      listField2.options[3].text = '150.000';  
      listField2.options[4].value = '200000';
      listField2.options[4].text = '200.000';  
      listField2.options[5].value = '300000';
      listField2.options[5].text = '300.000';  
      listField2.options[6].value = '500000';
      listField2.options[6].text = '500.000';  
      listField2.options[7].value = '9999999';
      listField2.options[7].text = 'Oltre';
	  //a qui
    }
  };
  
  function submit_finale(){
  var strHTML;
    strHTML="<center><img src=\"/images/progress-big.gif\"></center>";
    document.getElementById("indicatore").style.display="";
    document.localita_italiane.action="/elenco-immobili.aspx";
  	document.localita_italiane.target="_parent";
  	document.localita_italiane.submit();
  };
  

  function mostra_caption(numero){
  	var captions = new Array();
  	captions[0] = ["Agenzie Immobiliari in vetrina", "Sono quelle che aggiornano frequentemente i propri annunci e inseriscono le fotografie degli immobili."];
  	captions[1] = ["Attenzione!!", "La categoria Commerciale contiene anche attivit… e terreni"];
  	captions[2] = ["Attenzione!!", "Se cerchi case vacanza in vendita cerca sulla categoria residenziali"];
  	return overlib(captions[numero][1],CAPTION,captions[numero][0]);
  };  

  function MM_openBrWindow(theURL,winName,features) { //v2.0
    window.open(theURL,winName,features);
  };

  

