﻿var msgAltraArea = ""
var isFirstLoading = true;
function search_code() {
    var panel = document.getElementById("panel_serach_code")
    if (panel.style.display == "block") {
        panel.style.display = "none";
    }
    else {
        panel.style.display = "block";
    }
}
function val_date(source, arguments) {
    var result = true;
    var cmbDataDa=document.getElementById("ctl00_ContentPlaceHolder1_ricerca1_cmbDa");
    var cmbDurata=document.getElementById("ctl00_ContentPlaceHolder1_ricerca1_cmbDurata");
    if (cmbDataDa.selectedIndex > 0) {
        if (cmbDurata.selectedIndex <= 0) {
            alert(ric_msg_durata);
            result = false;
        }
    }
    else {
        if (cmbDurata.selectedIndex > 0) {
            alert(ric_msg_data);
            result = false;
        }
    }
    arguments.IsValid = result
}
function val_date_properties(source, arguments) {
    var result = true;
    var cmbDataDa = document.getElementById("ctl00_ContentPlaceHolder1_ricerca_properties1_cmbDa");
    var cmbDurata = document.getElementById("ctl00_ContentPlaceHolder1_ricerca_properties1_cmbDurata");
    if (cmbDataDa.selectedIndex > 0) {
        if (cmbDurata.selectedIndex <= 0) {
            alert(ric_msg_durata);
            result = false;
        }
    }
    else {
        if (cmbDurata.selectedIndex > 0) {
            alert(ric_msg_data);
            result = false;
        }
    }
    arguments.IsValid = result
}

/*  MAP */

function sel_area(cod1, cod2, cod3) {
    if (cod1 != null)
        selComboAreaValue(document.getElementById(id_selmap1), cod1);
    else
        document.getElementById(id_selmap1).selectedIndex = 0;
    if (cod2 != null)
        selComboAreaValue(document.getElementById(id_selmap2), cod2);
    else
        document.getElementById(id_selmap2).selectedIndex = 0;
    if (cod3 != null)
        selComboAreaValue(document.getElementById(id_selmap3), cod3);
    else
        document.getElementById(id_selmap3).selectedIndex = 0;
    //document.location="/properties"+path_lingua+".aspx?query=s&area="+cod
    //alert(document.getElementById(id_selmap1).options.length)
}
function selComboAreaValue(combo, value) {
    for (var i = 0; i < combo.options.length; i++) {
        if (combo.options[i].value == value) {
            combo.selectedIndex = i;
            return
        }
    }
}

function sel_area_end(cod) {
    // Produzione
    if(document.location.toString().toLowerCase().indexOf("/cottagestocastles.com_")<0)
        document.location = "/properties" + path_lingua + ".aspx?query=s&area="+cod   
    else
        document.location = "/cottagestocastles.com_/properties" + path_lingua + ".aspx?query=s&area=" + cod
}
function sel_area_combo() {
    var cod = "";
    if (document.getElementById(id_selmap1).selectedIndex > 0) {
        cod = cod + document.getElementById(id_selmap1).options[document.getElementById(id_selmap1).selectedIndex].value;
        if (isFirstLoading)
            document.getElementById(id_selmap2).style.display = "block"
        else {
            if (document.getElementById(id_selmap2).style.display == "none")
                if (window.confirm(msgAltraArea))
                    document.getElementById(id_selmap2).style.display = "block"
            }
    }
    if (document.getElementById(id_selmap2).selectedIndex > 0) {
        if((","+cod+",").indexOf(","+document.getElementById(id_selmap2).options[document.getElementById(id_selmap2).selectedIndex].value+",")<0){
            if (cod != "")
                cod=cod+","
            cod = cod + document.getElementById(id_selmap2).options[document.getElementById(id_selmap2).selectedIndex].value;
            if (isFirstLoading)
                document.getElementById(id_selmap3).style.display = "block"
            else {
                if (document.getElementById(id_selmap3).style.display == "none")
                    if (window.confirm(msgAltraArea))
                        document.getElementById(id_selmap3).style.display = "block"
                }
        }
    }
    if (document.getElementById(id_selmap3).selectedIndex > 0) {
        if (("," + cod + ",").indexOf("," + document.getElementById(id_selmap3).options[document.getElementById(id_selmap3).selectedIndex].value + ",") < 0) {
            if (cod != "")
                cod = cod + ","
            cod = cod + document.getElementById(id_selmap3).options[document.getElementById(id_selmap3).selectedIndex].value;
        }
    }
    var flash_obj = leggiSWF("cartina")
    if(flash_obj)
        flash_obj.selection(cod);
    isFirstLoading = false;
}
function sel_area_combo_properties() {
    if (document.getElementById(id_selmap1).selectedIndex > 0) {
        if (document.getElementById(id_selmap2).style.display == "none")
            if (window.confirm(msgAltraArea))
                document.getElementById(id_selmap2).style.display = "block"
    }
    if (document.getElementById(id_selmap2).selectedIndex > 0) {
        if (document.getElementById(id_selmap3).style.display == "none")
            if (window.confirm(msgAltraArea))
                document.getElementById(id_selmap3).style.display = "block"
        }
}

function sel_area_combo_old(cod) {
    var mappa = document.getElementById("cartina")
    switch (cod) {
        case '01':
            mappa.GotoFrame(17)
            break;
        case '02':
            mappa.GotoFrame(13)
            break;
        case '03':
            mappa.GotoFrame(11)
            break;
        case '04':
            mappa.GotoFrame(10)
            break;
        case '05':
            mappa.GotoFrame(9)
            break;
        case '06':
            mappa.GotoFrame(7)
            break;
        case '07':
            mappa.GotoFrame(8)
            break;
        case '08':
            mappa.GotoFrame(4)
            break;
        case '09':
            mappa.GotoFrame(3)
            break;
        case '10':
            mappa.GotoFrame(20)
            break;
        case '11':
            mappa.GotoFrame(5)
            break;
        case '12':
            mappa.GotoFrame(1)
            break;
        case '13':
            mappa.GotoFrame(18)
            break;
        default:
            mappa.GotoFrame(0)
            break;
    }
}

function leggiSWF(nome) {
/*
    if (navigator.appName.indexOf("Microsoft") != -1)
    { return window[nome]; }
    else
    { return document[nome]; }*/
    return document.getElementById(nome);
}
