var siteUrl;
var partner;

function pulisci(val) 
{ 
	if (val.value=="Località / Cod Annuncio"){
		val.value='';
	}
}

function caricadefault(val) 
{ 
	if (val.value==''){
		val.value="Località / Cod Annuncio";
	}
}

function actTo(val, openType,formName)
{
	var id=val.value;
	getBaseUrl();
	
	if (isNaN(id)==false)
	{
	    if (openType==1 || openType==0 || openType=='')
	    {
	    window.open(siteUrl + "/immobili/" + id + ".html");
	    }
	    else
	    {
		window.location.href = siteUrl + "/immobili/" + id + ".html";
		}
	}
	else
	{
		document.getElementById(formName).submit();
	}
}


// ------------------------------------------------------------- //
function gotoResults()
{
    getCurrentValues();
}

function gotoAdvancedSearch(country,region)
{
    var link;
    getCurrentValues();
    getBaseUrl();
	
    link = siteUrl + "/AdvancedSearch.aspx?ContractType=" + contractType + "&BuildingType=" + buildingType;
    if (country != "")
        link+= "&n=" + country;
    if (region != "")
        link+="&r=" + region;
    
	link+= "&partner=" + partner;
	
    window.open(link);
}

function gotoAdvancedSearchByProvince(country,region)
{
    getCurrentValues();
	getBaseUrl();

    window.open(siteUrl + "/AdvancedSearch.aspx?ContractType=" + contractType + "&BuildingType=" + buildingType + "&n=" + country + "&r=" + region + "&partner=" + partner);
}

function gotoAdvancedSearchByCity(country,region,city)
{
    getCurrentValues();
	getBaseUrl();

    window.open(siteUrl + "/AdvancedSearch.aspx?ContractType=" + contractType + "&BuildingType=" + buildingType + "&n=" + country + "&r=" + region + "&c=" + city + "&partner=" + partner);
}

function gotoTrovacase(partner,pageName)
{
    getCurrentValues();
	getBaseUrl();

    window.open(siteUrl + "/trovacase.aspx?from=" + partner + "&Causale=" + contractType + "&TipoImmobile=" + buildingType + "&partner=" + partner + "&url=/" + pageName + "%3Fcausale=" + contractType + "%26tipo=" + buildingType);
}

function getBaseUrl()
{

	partner=document.getElementById("partner").value;
	
	switch (partner)
	{
	case "virgilio":
	siteUrl="http://casait.case.virgilio.it";
	break;
	
	case "tiscali":
	siteUrl="http://tiscali.casa.it";
	break;
	
	case "blogonomy":
	siteUrl="http://casa.blogonomy.it";
	break;	
	
	default:
	siteUrl="http://www.casa.it";
	break
	}
	
}

function getCurrentValues()
{

    //Prezzo minimo
    if (document.getElementById("Pm") != null)
        minPrice=document.getElementById("Pm").value;
    
    //Prezzo massimo
    if (document.getElementById("Px") != null)
        maxPrice=document.getElementById("Px").value;
    
    //Metri quadri minimo
    if (document.getElementById("Mm") != null)
        minMQ=document.getElementById("Mm").value;

    //Metri quadri massimo        
    if (document.getElementById("Mx") != null)
        maxMQ=document.getElementById("Mx").value;
    
    // Causale
    if (document.getElementsByName('ContractType').length != 0)
    {
        var cType=document.getElementsByName('ContractType');
        if (cType.length==2)
        {
            for (i=0; i<cType.length;i++) {
                if (cType[i].checked==true)
                    contractType=cType[i].value;
            }
        }
        else
            contractType=cType[0].value;
    }

    // Tipo Immobile
    if (document.getElementsByName('BuildingType').length != 0)
    {
        var bType=document.getElementsByName('BuildingType');
		
        if (bType.length==3)
        {
            for (i=0; i<bType.length;i++) {
                if (bType[i].checked==true)
                    buildingType=bType[i].value;
            }
        }
        else
            buildingType=bType[0].value;
    }             
    
    // Tipologia
    if (document.getElementById("PropertyType") != null)
	try 
	{
		houseTypology=document.getElementById("PropertyType").options[document.getElementById("PropertyType").selectedIndex].text
    }
	catch(err)
	{
	}
	
	//    houseTypology=document.getElementById("PropertyType").value;
    
}
