﻿var arrBigCities = new Array("milano", "roma", "napoli", "torino");

var ga = new StdAnalytics();
ga.From = "QuickSearch";
ga.Init();


function IsBigCity(area){
	return arrBigCities.find(area);
}

function PreFind() {
    if (Verifica()) {
        var ID = Number(document.getElementById("ctl00_MasterContentPlaceHolder_txtCity").value);
        if (!ID) {
            setGAControls(); 
            ga.setGACookie(); 
        }
        
        return true;
    }
    
    return false;
}

function delCookies() {
    delCookie("StdGA");
    delCookie("RefineGA");
    delCookie("RefineGAData");
}

function setGAControls() {
    var city = document.getElementById("ctl00_MasterContentPlaceHolder_txtCity").value;
    var minPrice = document.getElementById(lbMinPrice).options[document.getElementById(lbMinPrice).selectedIndex].value;
    var maxPrice = document.getElementById(lbMaxPrice).options[document.getElementById(lbMaxPrice).selectedIndex].text;
    var minMQ = document.getElementById(lbMinMq).options[document.getElementById(lbMinMq).selectedIndex].value;
    var maxMQ = document.getElementById(lbMaxMq).options[document.getElementById(lbMaxMq).selectedIndex].text;
    var HT = document.getElementById(lbHouseTipology).options[document.getElementById(lbHouseTipology).selectedIndex].value;
    
    if (city != "Località / Cod. Annuncio" || city != "")
    {
        ga.Locality = city;
        if (IsBigCity(city.toLowerCase()))
            ga.City = city;
    }

    if (minPrice != "0" || maxPrice != "nessun limite")
        ga.Price = "1";
    else
        ga.Price = "0";

    if (minMQ != "0" || maxMQ != "nessun limite")
        ga.MQ = "1";
    else
        ga.MQ = "0";
        
    if (HT != "")
        ga.Type = "1";
    else
        ga.Type = "0";
}

//Opt=1 apre; Opt=0 chiude
function ShowHideElement(ElementName,Opt)
{
    if (ElementName =="")
    {
        return;
    }
    
    if (Opt==0)
    {
        document.getElementById(ElementName).style.display='none';
        return;
    }
    
    switch (ElementName)
    {
        case 'seo':
            document.getElementById('seo').style.display='block';
            document.getElementById('cloud').style.display='none';
            break;
            
        case 'cloud':
            document.getElementById('seo').style.display='none';
            document.getElementById('cloud').style.display='block';
            break;
    }
}

function SetArea(nazione,regione){
    var query = parseQueryString(location.search);
    var ContractType = "VE";
    var BuildingType = "RES";
    
    if (query["ContractType"])
        ContractType = query["ContractType"];
        
    if (query["BuildingType"])
        BuildingType = query["BuildingType"];
        
    window.location.href="/AdvancedSearch.aspx?ContractType=" + ContractType +"&BuildingType=" + BuildingType + "&n="+ nazione + "&r=" + regione + "&gaFrom=Mappa";
    return false;
}

function pulisci(val) 
{ 
	if (val.value=="Località / Cod. Annuncio") val.value='';
}

function caricadefault(val) 
{ 
	if (val.value=='') val.value="Località / Cod. Annuncio";
}

function Verifica()
{
    var city = document.getElementById("ctl00_MasterContentPlaceHolder_txtCity");
    if (city.value == "Località / Cod. Annuncio" || city.value == "")
    {
        document.getElementById("CityError").className = document.getElementById("CityError").className.split(' ')[0];
        return false;
    }
    
    return true;
}

function trapEnter(e){
    e = e || window.event;
    var code = e.keyCode || e.which;                    
    if(code == 13){
        if (PreFind()) {
            location.href = document.getElementById("ctl00_MasterContentPlaceHolder_btnFind").href;
            cancelEvent(e);
            return false;
        } 
        else {
            cancelEvent(e);
            return false;
        }
     }else{
        return true;
     }
}