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;
var options_xml = 
	{
		script:"autosuggest-GetComuni_2008.aspx?",
		varname:"input",
		cache:false,
		json: false,
		minchars:1,
		delay:50,
		callback: function (obj) {
                       document.getElementById("provincia").value = obj.id;
                       //ricercaProvincia();
                    }		
	};
	var as_xml;

//********************************************** 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 pippo;



    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
	as_xml = new bsn.AutoSuggest('provincia', options_xml);
	// carico la provincia selezionata
	//caricaProvincia();
	// 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 caricaProvincia() {
      var sHTML;
      var listField;
      var strWHERE;
      var strXML;
      var strProvinciaSQL;
      listField = document.getElementById("provincia");
      //alert("-->" + listField);
      listField.length = 0;
      strProvinciaSQL = strProvincia.replace(" ", "");
      strXML = "<db><rs><st>frk_Read<\/st><tb>Province_Vw<\/tb><ky>Province_Ky<\/ky><whr><\/whr><ord>Province_Provincia<\/ord><fields>Province_Ky,Province_Codice,Province_Provincia,Province_Rewrite_Url<\/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, "Province_Provincia"));
          listField.options[len].text = getElementValue(e, "Province_Provincia");
          if ((strProvincia != "") && (strProvincia.toLowerCase() == getElementValue(e, "Province_Rewrite").toLowerCase())) {
              pippo=listField.options[len]
			  alert (pippo);
          }
      }
      
  };


function caricapro(provi){
	var sHTML;
    var listField;
    var strWHERE;
    var strXML;
    var strProvinciaSQL;
    strProvinciaSQL=document.getElementById("provincia").value.replace("'","''");
    strWHERE="Comunirewrite= '" + provi + "'";
	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_Rewrite<\/fields><\/rs><\/db>";
    strXML=jsHttpPost("/frk/db/SQLServer/frkStoreExecute.asp",strXML);
    var xmldoc=XMLDoc(strXML);
    var db = xmldoc.getElementsByTagName("rs");
    var e = db[0];
    pippo = fnKy(getElementValue(e,"Province_Rewrite"));
  };
  
function caricaComuniValProp(){
	var sHTML;
    var listField;
    var strWHERE;
    var strXML;
    var strProvinciaSQL;
    listField=document.getElementById("Comune");
    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_Comune"));
      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+1];
      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="TipoDescrizione= '" + 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>TipoDescrizione,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_Descrizione"));
      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);
  };

function autocompila()
// toglie gli spazi all'inizio e fine e sostituisce i caratteri che non sono a-z A-Z 0-9
{
	var provinciaTrimm = document.getElementById("provincia").value.replace(/[^a-z A-Z 0-9 \s]+/g,'').toLowerCase();
	provinciaTrimm = provinciaTrimm.replace(/\s+/g,'');
	/*
	while (provinciaTrimm.substring(0,1) == ' '){
        provinciaTrimm = provinciaTrimm.substring(1, provinciaTrimm.length);
    }
    while (provinciaTrimm.substring(provinciaTrimm.length-1, provinciaTrimm.length) == ' '){
        provinciaTrimm = provinciaTrimm.substring(0,provinciaTrimm.length-1);
    }*/
	//document.getElementById("rewCitta").value = provinciaTrimm;
}

// Funzione che blocca il tasto enter se il campo e' vuoto	
function BloccaEnter(e)
{   

//parte per IE
if(e.keyCode == 13)
 {

  e.cancelBubble = true;
  e.returnValue = false;
 }

//parte per Firefox
  if(e.which == 13)
 {

  e.stopPropagation();
  e.preventDefault();
 }
}


  
function bottoneCerca() {
	
	
   // var strdominio3 = document.getElementById("dominio3").value;

    if ((document.getElementById("provincia").value != '') && (document.getElementById("provincia").value != undefined)) {
        var strProvincia = document.getElementById("provincia").value.replace(/[^a-z A-Z 0-9 \s]+/g, '').toLowerCase();
        strProvincia = strProvincia.replace(/\s+/g, '').replace('à', 'a').replace('è', 'e').replace('ì', 'i').replace('ù', 'u').replace('é', 'e');
    }
	else {
        var strProvincia = "milano";
    }
    
        var strComune = "tutti-i-comuni";

    if (document.getElementById("categoria1").selected == true) {
        var strCategoria = document.getElementById("categoria1").value.replace(/[^a-z A-Z 0-9 \s]+/g, '').toLowerCase();
        strCategoria = strCategoria.replace(/\s+/g, '').replace('à', 'a').replace('è', 'e').replace('ì', 'i').replace('ù', 'u').replace('é', 'e');
        //alert ("cat-->" + strCategoria);
    }
    if (document.getElementById("categoria2").selected == true) {
        var strCategoria = document.getElementById("categoria2").value.replace(/[^a-z A-Z 0-9 \s]+/g, '').toLowerCase();
        strCategoria = strCategoria.replace(/\s+/g, '').replace('à', 'a').replace('è', 'e').replace('ì', 'i').replace('ù', 'u').replace('é', 'e');
    }
    if (document.getElementById("categoria3").selected == true) {
        var strCategoria = document.getElementById("categoria3").value.replace(/[^a-z A-Z 0-9 \s]+/g, '').toLowerCase();
        strCategoria = strCategoria.replace(/\s+/g, '').replace('à', 'a').replace('è', 'e').replace('ì', 'i').replace('ù', 'u').replace('é', 'e');
    }
    if (document.getElementById("categoria4").selected == true) {
        var strCategoria = document.getElementById("categoria4").value.replace(/[^a-z A-Z 0-9 \s]+/g, '').toLowerCase();
        strCategoria = strCategoria.replace(/\s+/g, '').replace('à', 'a').replace('è', 'e').replace('ì', 'i').replace('ù', 'u').replace('é', 'e');
    }
    if (document.getElementById("categoria5").selected == true) {
        var strCategoria = document.getElementById("categoria5").value.replace(/[^a-z A-Z 0-9 \s]+/g, '').toLowerCase();
        strCategoria = strCategoria.replace(/\s+/g, '').replace('à', 'a').replace('è', 'e').replace('ì', 'i').replace('ù', 'u').replace('é', 'e');
    }
    if (document.getElementById("categoria6").selected == true) {
        var strCategoria = document.getElementById("categoria6").value.replace(/[^a-z A-Z 0-9 \s]+/g, '').toLowerCase();
        strCategoria = strCategoria.replace(/\s+/g, '').replace('à', 'a').replace('è', 'e').replace('ì', 'i').replace('ù', 'u').replace('é', 'e');
    }
    if (document.getElementById("contratto2").checked == true) {
        var strContratto = "Vendita";
    }
    if (document.getElementById("contratto1").checked == true) {
        var strContratto = "Affitto";
    }
    if (document.getElementById("contratto3").checked == true) {
        var strContratto = "Asta";
    }

   
        var strTipologia = "tutte-le-tipologie";
        var strSottotipologia = "tutte-le-sottotipologie";
        var strPrezzoMin = "0";
        var strPrezzoMax = "999999999";    
        if ((document.getElementById("locali").value != '') && (document.getElementById("locali").value != undefined)) {
        var strLocali = document.getElementById("locali").value;
        strLocali = "Camere-" + strLocali;
    }
    else {
        var strLocali = "Camere-qualsiasi";
    }
        var strPrestigio = "NoPrestigio";
        var strTurismo = "NoCasaVacanza";

    if ((document.getElementById("CodAnnuncio").value != '') && (document.getElementById("CodAnnuncio").value != undefined)) {

        var strAnnuncio = document.getElementById("CodAnnuncio").value.replace('/', '__');
		
    }
    else {
        var strAnnuncio = "No_Codice";
    }
    
	
	
	
	
    var strUrlFinale;
    
    if ((document.getElementById("CodAnnuncio").value != '') && (document.getElementById("CodAnnuncio").value != undefined) && (document.getElementById("provincia").value == '') ) {

        strUrlFinale = "http://" + strProvincia + ".retecasa.it/tutti-i-comuni/tutte-le-categorie/tutte-le-tipologie/tutte-le-sottotipologie/Vendita-Affitto-Asta/0-999999999/Camere-qualsiasi/NoPrestigio-NoCasaVacanza/" + strAnnuncio + "/No-Ordine/1.html";
        //alert(strUrlFinale)
        window.location.href = strUrlFinale;
    }
    else {
		
		if((strProvincia=="milano")||(strProvincia=="bergamo")||(strProvincia=="agrigento")||(strProvincia=="alessandria")||(strProvincia=="ancona")||(strProvincia=="aosta")||(strProvincia=="ascolipiceno")||(strProvincia=="laquila")||(strProvincia=="arezzo")||(strProvincia=="asti")||(strProvincia=="avellino")||(strProvincia=="bari")||(strProvincia=="biella")||(strProvincia=="belluno")||(strProvincia=="benevento")||(strProvincia=="bologna")||(strProvincia=="brindisi")||(strProvincia=="brescia")||(strProvincia=="bolzano")||(strProvincia=="cagliari")||(strProvincia=="campobasso")||(strProvincia=="caserta")||(strProvincia=="chieti")||(strProvincia=="caltanissetta")||(strProvincia=="cuneo")||(strProvincia=="como")||(strProvincia=="cremona")||(strProvincia=="cosenza")||(strProvincia=="catania")||(strProvincia=="catanzaro")||(strProvincia=="enna")||(strProvincia=="ferrara")||(strProvincia=="foggia")||(strProvincia=="firenze")||(strProvincia=="forlicesena")||(strProvincia=="frosinone")||(strProvincia=="genova")||(strProvincia=="gorizia")||(strProvincia=="grosseto")||(strProvincia=="imperia")||(strProvincia=="isernia")||(strProvincia=="crotone")||(strProvincia=="lecco")||(strProvincia=="lecce")||(strProvincia=="livorno")||(strProvincia=="lodi")||(strProvincia=="latina")||(strProvincia=="lucca")||(strProvincia=="macerata")||(strProvincia=="messina")||(strProvincia=="mantova")||(strProvincia=="modena")||(strProvincia=="massacarrara")||(strProvincia=="matera")||(strProvincia=="napoli")||(strProvincia=="novara")||(strProvincia=="nuoro")||(strProvincia=="oristano")||(strProvincia=="palermo")||(strProvincia=="piacenza")||(strProvincia=="padova")||(strProvincia=="pescara")||(strProvincia=="perugia")||(strProvincia=="pisa")||(strProvincia=="pordenone")||(strProvincia=="prato")||(strProvincia=="parma")||(strProvincia=="pesarourbino")||(strProvincia=="pistoia")||(strProvincia=="pavia")||(strProvincia=="potenza")||(strProvincia=="ravenna")||(strProvincia=="reggiocalabria")||(strProvincia=="reggioemilia")||(strProvincia=="ragusa")||(strProvincia=="rieti")||(strProvincia=="roma")||(strProvincia=="rimini")||(strProvincia=="rovigo")||(strProvincia=="salerno")||(strProvincia=="siena")||(strProvincia=="sondrio")||(strProvincia=="laspezia")||(strProvincia=="siracusa")||(strProvincia=="sassari")||(strProvincia=="savona")||(strProvincia=="taranto")||(strProvincia=="teramo")||(strProvincia=="trento")||(strProvincia=="torino")||(strProvincia=="trapani")||(strProvincia=="trieste")||(strProvincia=="treviso")||(strProvincia=="udine")||(strProvincia=="varese")||(strProvincia=="verbanocusioossola")||(strProvincia=="vercelli")||(strProvincia=="venezia")||(strProvincia=="vicenza")||(strProvincia=="verona")||(strProvincia=="viterbo")||(strProvincia=="vibovalentia")||(strProvincia=="carboniaiglesias")||(strProvincia=="mediocampidano")||(strProvincia=="terni")||(strProvincia=="olbiatempio")||(strProvincia=="barlettaandriatrani")||(strProvincia=="ogliastra")||(strProvincia=="fermo")||(strProvincia=="monzaebrianza")||(strProvincia=="olbiatempio")){
			
			
        
			strUrlFinale = "http://" + strProvincia + ".retecasa.it/" + strProvincia + "/" + strCategoria + "/" + strTipologia + "/" + strSottotipologia + "/" + strContratto + "/" + strPrezzoMin + "-" + strPrezzoMax + "/" + strLocali + "/" + strPrestigio + "-" + strTurismo + "/No_Codice/No-Ordine/1.html";
			if(strProvincia == ""){
				//alert(strUrlFinale)
			window.location.href = "http://www.retecasa.it/error-404.aspx";
			}
		else{
       // alert(strUrlFinale)
        window.location.href = strUrlFinale;
		}
			}
		else{

			caricapro(strProvincia);
			
       strUrlFinale = "http://" + pippo +".retecasa.it/" + strProvincia + "/" + strCategoria + "/" + strTipologia + "/" + strSottotipologia + "/" + strContratto + "/" + strPrezzoMin + "-" + strPrezzoMax + "/" + strLocali + "/" + strPrestigio + "-" + strTurismo + "/No_Codice/No-Ordine/1.html";
		}
		
        if(pippo == ""){
			window.location.href = "http://www.retecasa.it/error-404.aspx";
			}
		else{
        //alert(strUrlFinale)
        window.location.href = strUrlFinale;
		}

    }

}