﻿//document.onmousemove = on_MouseMove
var mouse_x = null;
var mouse_y = null;
var show_tooltip = false;
var mouse_out = null;



//alert('ciao');
/*
var data_dal = document.getElementById('ctl00_body_data_dal');
data_dal.attachEvent('onclick', 'alert("blabla")');
*/
//window.onunload(alert('CIAO'));

//function F_carica_imagine(obj, percorso)
//{
//    $('#' + obj.id).attr('src', percorso);
//}



function getWindowWidth() {
    var windowWidth = 0;
    if (typeof (window.innerWidth) == 'number') {
        windowWidth = window.innerWidth;
    }
    else {
        if (document.documentElement && document.documentElement.clientWidth) {
            windowWidth = document.documentElement.clientWidth;
        }
        else {
            if (document.body && document.body.clientWidth) {
                windowWidth = document.body.clientWidth;
            }
        }
    }
    return windowWidth;
}

function on_MouseMove(e) 
{

    var objTooltip = document.getElementById('tooltip');
    //Table_stagionalita.offsetWidth
	var tipo_browser = navigator.appName;
	var pos_x = 0;
	var pos_y = 0;
	if (tipo_browser == 'Netscape')
	{
		pos_x = parseInt(self.pageXOffset) + e.clientX + document.body.scrollLeft;
		pos_y = parseInt(self.pageYOffset) + e.clientY + document.body.scrollTop;
		pos_x = pos_x + 10;
		pos_y = pos_y + 20;
		if (objTooltip.offsetWidth + pos_x >= getWindowWidth()) 
		{
		    pos_x = getWindowWidth() - objTooltip.offsetWidth - 20;
		}
		pos_x = pos_x + "px";
		pos_y = pos_y + "px";
		//alert(pos_x + '\n' + getWindowWidth());
		
    }
	else
	{
		if (e.pageX) return e.pageX;
		else if (e.clientX)
			pos_x = e.clientX + (document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft);
		else return null;
		if (e.pageY) return e.pageY;
		else if (e.clientY)
			pos_y = e.clientY + (document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop);
		else return null;
		pos_x = pos_x + 10;
		pos_y = pos_y + 20;
		if (objTooltip.offsetWidth + pos_x >= getWindowWidth()) 
		{
		    pos_x = getWindowWidth() - objTooltip.offsetWidth - 20;
	    }
		//alert(pos_x + '\n' + getWindowWidth());
    }





    var element_tooltip = document.getElementById("tooltip")
    /*if (!e) var e = window.event;
    mouse_x = e.clientX;
    mouse_y = e.clientY;
    */
    mouse_x = pos_x;
    mouse_y = pos_y;
    //alert(mouse_x + '\t' + mouse_y);
    if(element_tooltip)
    {
        if(show_tooltip)
        {
            $('tooltip').setStyles(
            {   
                position:"absolute",
                top: mouse_y,
                left: mouse_x,
                visibility:'visible'
            });
            document.getElementById('tooltip').style.display = '';
        }
        else
        {
            document.getElementById('tooltip').style.display = 'none';
        /*
            $('tooltip').setStyles(
            {
                visibility:'hidden'
            });
        */
        }
    }
    return false;
}

function toolTip(var_display, ajax_url, set_className) {
    //alert('ciao');
    //alert(document.domain + '\n' + location.pathname);
    //alert(ajax_url);
    if (var_display == 'show') {
        mouse_out = true;
        show_tooltip = true;
        document.getElementById('tooltip').className = set_className;
        var myHTMLRequest = new Request.HTML({
            url: ajax_url,
            update: "tooltip",
            onComplete: function() {
                //if(!mouse_out){
                show_tooltip = true;
                //    }

            } 
        }).send();
    }
    else {
        mouse_out = false;
        show_tooltip = false;
        /*
        $('tooltip').setStyles(
        {
        visibility:'hidden'
        });
        */
        document.getElementById('tooltip').style.display = 'none';
    }
}

function isDate(p_Expression) {
    return !isNaN(new Date(p_Expression)); 	// <<--- this needs checking
}

function controlloDataInserita(http_path,text,text1,text2,id){
    document.getElementById("ctl00_body_" + id).value = document.getElementById("ctl00_body_" + id).value.replace(/-/g, "/");
    var element_input_data_dal = document.getElementById("ctl00_body_" + id);
    
    var errori = 0
    var errori_finale = 0
    
    if (element_input_data_dal.value == ""){
        errori_finale = 1;
        errori = 1;
        alert(text);
        return false;
    }
    
    
    var gg = ((element_input_data_dal.value).split("/"));
    var data = new Date(gg[2], gg[1] - 1, gg[0])
    
    if (!isDate(data)){
        errori_finale = 1;
        errori = 1;
        alert(text1);
        return false;
    }
    
    if (errori == 0){
        ary_dal = element_input_data_dal.value.split("/");
        date_dal = new Date(ary_dal[2], ary_dal[1] - 1, ary_dal[0]);
        
        date_now = new Date();
        date_now.setHours(0);
        date_now.setMinutes(0)
        date_now.setSeconds(0);
        date_now.setMilliseconds(0);
        
        if (date_dal < date_now) {
            errori_finale = 1;
            alert(text2);
            return false;
        }
    }
    
    if (errori_finale == 0){
        loading(http_path);
//        return true;
    }
}

function controlliDate(http_path) {

    var element_input_data_dal = document.getElementById("ctl00_body_data_dal");
    var element_input_data_al = document.getElementById("ctl00_body_data_al");
    var element_calendario_dal = document.getElementById("ctl00_body_img_calendar_dal");
    var element_calendario_al = document.getElementById("ctl00_body_img_calendar_al");
    var element_form = document.getElementById("aspnetForm")

    if ((element_form) && (element_input_data_dal) && (element_input_data_al)) {
        element_input_data_dal.onkeypress = function() {
            return false;
        }

        element_input_data_al.onkeypress = function() {
            return false;
        }

        element_form.onsubmit = function() {
            ary_dal = element_input_data_dal.value.split("/");
            ary_al = element_input_data_al.value.split("/");

            date_dal = new Date(ary_dal[2], ary_dal[1] - 1, ary_dal[0]);
            date_al = new Date(ary_al[2], ary_al[1] - 1, ary_al[0]);

            date_now = new Date();
            date_now.setHours(0);
            date_now.setMinutes(0)
            date_now.setSeconds(0);
            date_now.setMilliseconds(0);

            if ((date_dal >= date_al) || (date_dal < date_now)) {
                alert('il periodo impostato non è valido');
                return false;

            }
            else {
                setTimeout("UpdateImg('img_loading','" + http_path + "img/circle.gif')", 30);
                return true;
            }

        }
    }
}

function F_price_comma(type, obj) {

}

function F_propaga_prezzi(numero_bambino, trattamenti_counter) {

    var i, k, j;
    var textbox_precedente;
    var textbox_nuovo;
    /*
    for (i = numero_bambino-1; i <= numero_bambino; i++)
    {
    alert('i: ' + i);
    }
    */
    //document.getElementById('ctl00_right_Wizard_B2T1F2').value = document.getElementById('ctl00_right_Wizard_B1T1F2').value;
    //alert('numero_bambino: ' + numero_bambino + '\n' + 'trattamenti_counter: ' + trattamenti_counter + '\n' + 'fasce_eta_counter: ' + fasce_eta_counter)
    for (i = 1; i <= trattamenti_counter; i++) {
        for (k = 1; k <= 3; k++) {
            textbox_nuovo = document.getElementById('ctl00_right_Wizard_B' + numero_bambino + 'T' + i + 'F' + k);
            textbox_precedente = document.getElementById('ctl00_right_Wizard_B' + (numero_bambino - 1) + 'T' + i + 'F' + k);

            if (textbox_nuovo && textbox_precedente) {
                textbox_nuovo.value = textbox_precedente.value;
            }
            /*
            */
            //alert('ctl00_right_Wizard_B' + numero_bambino + 'T' + i + 'F' + k + '\n' + 'ctl00_right_Wizard_B' + (numero_bambino - 1) + 'T' + i + 'F' + k);
            //alert(document.getElementById('ctl00_right_Wizard_B' + numero_bambino + 'T' + i + 'F' + k).value + '\n' + document.getElementById('ctl00_right_Wizard_B' + (numero_bambino - 1) + 'T' + i + 'F' + k).value);
            //document.getElementById('ctl00_right_Wizard_B' + numero_bambino + 'T' + i + 'F' + k).value = document.getElementById('ctl00_right_Wizard_B' + (numero_bambino - 1) + 'T' + i + 'F' + k).value;
        }
    }

    //alert('numero_bambino: ' + numero_bambino + '\ntrattamenti_counter: ' + trattamenti_counter + '\nfasce_eta_counter: ' + fasce_eta_counter);
}

function F_price(type, obj, n_persons) {
    //alert(n_persons);
    var current_text_field;
    var other_text_field;
    var current_text_field_value;
    var other_text_field_value;
    var change_values = false;

    current_text_field = obj.id;
    current_text_field_value = obj.value.replace(',', '.');

    if (type == 'sist') {
        other_text_field = current_text_field.replace('sist', 'pers');
        if (IsNumeric(current_text_field_value)) {
            other_text_field_value = current_text_field_value / n_persons;
            change_values = true;
        }
    }
    if (type == 'pers') {
        other_text_field = current_text_field.replace('pers', 'sist');
        if (IsNumeric(current_text_field_value)) {
            other_text_field_value = current_text_field_value * n_persons;
            change_values = true;
        }
    }

    if (change_values == true) {
        other_text_field_value = other_text_field_value.toFixed(2);
        document.getElementById(other_text_field).value = other_text_field_value;
        document.getElementById(other_text_field).value = document.getElementById(other_text_field).value.replace('.', ',');
    }
    else {
        document.getElementById(current_text_field).value = '0,00';
        document.getElementById(other_text_field).value = '0,00';
    }
}

function IsNumeric(sText) {
    var ValidChars = "0123456789.";
    var IsNumber = true;
    var Char;
    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;
}

function F_engine_control() {
    //var giorni;
    var dal_value;
    var al_value;
    var book_period;

    dal_value = document.getElementById('ctl00_body_data_dal').value;
    al_value = document.getElementById('ctl00_body_data_al').value;
    book_period = parseInt(document.getElementById('ctl00_body_book_period').value);
    //alert(book_period);


    var dal_gg = dal_value.substr(0, 2);
    var dal_mm = dal_value.substr(3, 2) - 1;
    var dal_aaaa = dal_value.substr(6, 4);
    var dal = new Date(dal_aaaa, dal_mm, dal_gg);
    //alert(dal)

    var al_gg = al_value.substr(0, 2);
    var al_mm = al_value.substr(3, 2) - 1;
    var al_aaaa = al_value.substr(6, 4);
    var al = new Date(al_aaaa, al_mm, al_gg);



    //alert('dal: ' + isDate(dal) + '\n' + isDate(al));
    var current_date = new Date();
    if (isDate(dal) == false) {
        var current_gg = current_date.getDate();
        if (('' + current_gg).length == 1) {
            current_gg = '0' + current_gg;
        }

        var current_mm = current_date.getMonth();
        var current_mm_input = current_mm + 1;
        if (('' + current_mm).length == 1) {
            current_mm = '0' + current_mm;
        }
        if (('' + current_mm_input).length == 1) {
            current_mm_input = '0' + current_mm_input;
        }

        var current_aaaa = current_date.getFullYear();
        dal = new Date(current_aaaa, current_mm, current_gg);

        document.getElementById('ctl00_body_data_dal').value = current_gg + '/' + current_mm_input + '/' + current_aaaa;
    }
    if (isDate(al) == false) {
        var next_date = new Date();
        next_date = dateAdd("d", 1, dal);
        var next_gg = next_date.getDate();
        if (('' + next_gg).length == 1) {
            next_gg = '0' + next_gg;
        }

        var next_mm = next_date.getMonth();
        var next_mm_input = next_mm + 1;
        if (('' + next_mm).length == 1) {
            next_mm = '0' + next_mm;
        }
        if (('' + next_mm_input).length == 1) {
            next_mm_input = '0' + next_mm_input;
        }

        var next_aaaa = next_date.getFullYear();

        al = new Date(next_aaaa, next_mm, next_gg);
        document.getElementById('ctl00_body_data_al').value = next_gg + '/' + next_mm_input + '/' + next_aaaa;
    }



    if (dateDiff("d", dal, al) > 38) {
        var nuovo_al_gg = dateAdd("D", 38, dal).getDate(); ;
        var nuovo_al_mm = dateAdd("D", 38, dal).getMonth() + 1;
        var nuovo_al_yy = dateAdd("D", 38, dal).getFullYear();
        document.getElementById('ctl00_body_data_al').value = nuovo_al_gg + '/' + nuovo_al_mm + '/' + nuovo_al_yy;
    }


    //var weekday = 5;
    var i_weekday;
    var al_dopo = dal;
    var cambia_data = false;
    var conta_sabati = 0;
    var conta_domeniche = 0;
    //alert(al_dopo);
    while (conta_sabati < 1 + book_period / 7 && conta_domeniche < 1 + book_period / 7) {
        i_weekday = al_dopo.getUTCDay();

        if (i_weekday == 5) {
            conta_sabati = conta_sabati + 1;
            //alert('conta_sabati: ' + conta_sabati);
            //alert(al_dopo);
        }
        if (i_weekday == 6) {
            conta_domeniche = conta_domeniche + 1;
            //alert('conta_domeniche: ' + conta_domeniche);
        }

        if (conta_sabati < 1 + book_period / 7 && conta_domeniche < 1 + book_period / 7) {
            al_dopo = dateAdd("d", 1, al_dopo);
        }

    }


    //giorni = dateDiff("d", dal, al);
    if (dateDiff("d", al, al_dopo) > 0) {
        cambia_data = true;
    }
    if (cambia_data == true) {
        var al_dopo_gg = al_dopo.getDate();
        if (('' + al_dopo_gg).length == 1) {
            al_dopo_gg = '0' + al_dopo_gg;
        }

        var al_dopo_mm = al_dopo.getMonth() + 1;
        if (('' + al_dopo_mm).length == 1) {
            al_dopo_mm = '0' + al_dopo_mm;
        }

        var al_dopo_aaaa = al_dopo.getFullYear();

        document.getElementById('ctl00_body_data_al').value = al_dopo_gg + '/' + al_dopo_mm + '/' + al_dopo_aaaa;
    }

    return true;
}






function dateAdd(p_Interval, p_Number, p_Date) {
    if (!isDate(p_Date)) { return "invalid date: '" + p_Date + "'"; }
    if (isNaN(p_Number)) { return "invalid number: '" + p_Number + "'"; }

    //alert(p_Date);
    p_Number = new Number(p_Number);
    var dt = new Date(p_Date);
    switch (p_Interval.toLowerCase()) {
        case "yyyy": 
            {// year
                dt.setFullYear(dt.getFullYear() + p_Number);
                break;
            }
        case "q": 
            {		// quarter
                dt.setMonth(dt.getMonth() + (p_Number * 3));
                break;
            }
        case "m": 
            {		// month
                dt.setMonth(dt.getMonth() + p_Number);
                break;
            }
        case "y": 	// day of year
        case "d": 	// day
        case "w": 
            {		// weekday
                //alert(dt);
                dt.setDate(dt.getDate() + p_Number);
                //alert(dt);
                break;
            }
        case "ww": 
            {	// week of year
                dt.setDate(dt.getDate() + (p_Number * 7));
                break;
            }
        case "h": 
            {		// hour
                dt.setHours(dt.getHours() + p_Number);
                break;
            }
        case "n": 
            {		// minute
                dt.setMinutes(dt.getMinutes() + p_Number);
                break;
            }
        case "s": 
            {		// second
                dt.setSeconds(dt.getSeconds() + p_Number);
                break;
            }
        case "ms": 
            {		// second
                dt.setMilliseconds(dt.getMilliseconds() + p_Number);
                break;
            }
        default: 
            {
                return "invalid interval: '" + p_Interval + "'";
            }
    }

    //alert(dt);

    return dt;
}



function dateDiff(p_Interval, p_Date1, p_Date2, p_firstdayofweek, p_firstweekofyear) {
    if (!isDate(p_Date1)) { return "invalid date: '" + p_Date1 + "'"; }
    if (!isDate(p_Date2)) { return "invalid date: '" + p_Date2 + "'"; }
    var dt1 = new Date(p_Date1);
    var dt2 = new Date(p_Date2);

    // get ms between dates (UTC) and make into "difference" date
    var iDiffMS = dt2.valueOf() - dt1.valueOf();
    var dtDiff = new Date(iDiffMS);

    // calc various diffs
    var nYears = dt2.getUTCFullYear() - dt1.getUTCFullYear();
    var nMonths = dt2.getUTCMonth() - dt1.getUTCMonth() + (nYears != 0 ? nYears * 12 : 0);
    var nQuarters = parseInt(nMonths / 3); //<<-- different than VBScript, which watches rollover not completion

    var nMilliseconds = iDiffMS;
    var nSeconds = parseInt(iDiffMS / 1000);
    var nMinutes = parseInt(nSeconds / 60);
    var nHours = parseInt(nMinutes / 60);
    var nDays = parseInt(nHours / 24);
    var nWeeks = parseInt(nDays / 7);


    // return requested difference
    var iDiff = 0;
    switch (p_Interval.toLowerCase()) {
        case "yyyy": return nYears;
        case "q": return nQuarters;
        case "m": return nMonths;
        case "y": 		// day of year
        case "d": return nDays;
        case "w": return nDays;
        case "ww": return nWeeks; 	// week of year	// <-- inaccurate, WW should count calendar weeks (# of sundays) between
        case "h": return nHours;
        case "n": return nMinutes;
        case "s": return nSeconds;
        case "ms": return nMilliseconds; // millisecond	// <-- extension for JS, NOT available in VBScript
        default: return "invalid interval: '" + p_Interval + "'";
    }
}

function F_n_camere(value) {
    var i_camere;
    for (i_camere = parseInt(value) + 1; i_camere <= 3; i_camere++) {
        document.getElementById('camera_' + i_camere).style.display = 'none';
    }
    for (i_camere = 1; i_camere <= parseInt(value); i_camere++) {
        document.getElementById('camera_' + i_camere).style.display = '';
    }
}

//funzione conta caratteri
function contaCaratteri(id, span, numero) {
    var str = document.getElementById(id).value;
    var spanGenerale = document.getElementById(span);

    if (numero - str.length == -1) {
        document.getElementById(id).value = str.substring(0, str.length - 1);
    }
    spanGenerale.innerHTML = numero - str.length + " caratteri mancanti";

    if (numero - str.length < 0) {
        document.getElementById(id).value = str.substring(0, numero);
        spanGenerale.innerHTML = 0 + " caratteri mancanti";
    }
}


//per loading
function UpdateImg(ctrl, imgsrc) {
    var img = document.getElementById(ctrl);
    //document.getElementById('contenitoreGenerale').style.display = 'none';
    document.getElementById('div_loading').style.display = 'block';
    img.src = imgsrc;
    //alert(img.src);
}

function loading(http_path){
    setTimeout("UpdateImg('img_loading','" + http_path + "img/circle.gif')", 30);
    return true;
}

function F_page_layout() {
    //alert('ciao');
    var box_elenco_sistemazioni_width_calculate = 0
    var Table_stagionalita = document.getElementById('ctl00_right_Table_stagionalita');
    var box_elenco_sistemazioni = document.getElementById('ctl00_right_box_elenco_sistemazioni');
    var Table_cancellation_policy = document.getElementById('ctl00_right_Table_cancellation_policy');
    //var Table_pulsanti = document.getElementById('ctl00_right_Table_pulsanti');
    var lunghezza_elementi_prezzi = Table_stagionalita.offsetWidth + box_elenco_sistemazioni.offsetWidth + Table_cancellation_policy.offsetWidth; //  + Table_pulsanti.offsetWidth;
    var right = document.getElementById('right');
    //alert(lunghezza_elementi_prezzi + '|' + right.offsetWidth);

    //box_elenco_sistemazioni.style.width = '2000px';
    box_elenco_sistemazioni_width_calculate = right.offsetWidth - Table_stagionalita.offsetWidth - Table_cancellation_policy.offsetWidth; //  - Table_pulsanti.offsetWidth;
    box_elenco_sistemazioni.style.width = parseInt(box_elenco_sistemazioni_width_calculate - 50) + 'px';

    if (lunghezza_elementi_prezzi < right.offsetWidth) {
        box_elenco_sistemazioni.style.width = '';
    }
    //alert(box_elenco_sistemazioni.style.overflowX);
    //alert(lunghezza_elementi_prezzi + '|' + right.offsetWidth + '|' + box_elenco_sistemazioni_width_calculate);
}



function F_DropDownList_nome() {
    var nr_adulti;
    var DropDownList_nome = document.getElementById('ctl00_right_DropDownList_fisica_nome');
    var vani = DropDownList_nome.options[DropDownList_nome.selectedIndex].getAttribute('vani');
    var DropDownList_n_locali = document.getElementById('ctl00_right_DropDownList_locali');
    if (vani == -1) {
        //DropDownList_n_locali.selectedIndex = 0;
        DropDownList_n_locali.disabled = '';
    }
    else {
        DropDownList_n_locali.selectedIndex = vani;
        DropDownList_n_locali.disabled = 'true';
        //alert(vani);
    }
}

function checkDate(sender, args) {
    if (sender._selectedDate < new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate())) {
        alert("You cannot select a day earlier than today!");
        sender._selectedDate = new Date();
        sender._textbox.set_Value(sender._selectedDate.format(sender._format))
    }
}

function anteprima_thumbnail(element_id, ajax_url) {
    var myHTMLRequest = new Request.HTML({
        url: ajax_url,
        update: element_id,
        onComplete: function() {
            //if(!mouse_out){
            // show_tooltip = true;
            //    }

        }
    }).send();
}

//funzione per l'aggiornamento e il controllo degli errori delle date del periodo di vendita hotelita
function aggiornavalori() {

        var dal_giorno;
        var dal_mese;
        var dal_anno;
        var data_dal;
        var al_giorno;
        var al_mese;
        var al_anno;
        var data_al;
        var errore = false;
        var visualizza_span_errori = false;
        var storico;

        //righe della tabella delle date
        var righe = document.getElementById('ctl00_right_box_visualizzazione_dati').getElementsByTagName("tr");


        //copio i valori al_giorno=dal_giorno+1
        for (i = 0; i < righe.length - 2; i++) {
            storico = document.getElementById('ctl00_right_HiddenField_storico_' + i);
            if (storico.value == 0) {
                document.getElementById('ctl00_right_al_giorno_' + i).value = document.getElementById('ctl00_right_dal_giorno_' + (i + 1)).value;
                document.getElementById('ctl00_right_al_mese_' + i).value = document.getElementById('ctl00_right_dal_mese_' + (i + 1)).value;
            }
        }

        var nome_stagionalita
        for (i = 0; i < righe.length - 1; i++) {
            nome_stagionalita = document.getElementById('ctl00_right_nome_stagionalita_' + i);
            if (nome_stagionalita.value == "") {
                document.getElementById('span_errori').innerHTML = "<b>inserire nome stagionalita</b>";
                nome_stagionalita.style.borderColor = "red";
                errore = true;
                visualizza_span_errori = true;
            } else {
                nome_stagionalita.style.borderColor = "";
            }

            //visualizzo lo span di errore e disabilito il tasto
            if (visualizza_span_errori == true) {
                document.getElementById('span_errori').style.display = "";
                document.getElementById('ctl00_right_span_salvataggio_avvenuto').style.display = "none";
                //document.getElementById('ctl00_right_lkbSalvaTutto').setAttribute("onclick", "alert('controllare le date');return false;");
                document.getElementById('ctl00_right_lkbSalvaTutto').onclick = function() { alert('controllare le date'); return false; };
            } else {
                document.getElementById('span_errori').style.display = "none";
                //document.getElementById('ctl00_right_lkbSalvaTutto').setAttribute("onclick", "");
                document.getElementById('ctl00_right_lkbSalvaTutto').onclick = ""
            }
        }

        //CONTROLLO LE DATE VUOTE
        if (controlloDateVuote()) {
            errore = true;
        }

        //SE NON CI SONO DATE VUOTE CONTROLLO SE I NUMERI SONO DI TIPO DATA
        if (errore == false) {

            for (i = 0; i < righe.length - 1; i++) {

                dal_giorno = document.getElementById('ctl00_right_dal_giorno_' + i);
                dal_mese = document.getElementById('ctl00_right_dal_mese_' + i);
                dal_anno = document.getElementById('ctl00_right_dal_anno_' + i);
                data_dal = new Date(dal_anno.value, dal_mese.value - 1, dal_giorno.value);

                //controllo sul giorno
                if ((data_dal.getDate() != dal_giorno.value) && (dal_giorno.value != "")) {
                    document.getElementById('span_errori').innerHTML = "<b>controllare date</b>";
                    dal_giorno.style.backgroundColor = "#FF3F3F";
                    errore = true;
                    visualizza_span_errori = true;
                } else {
                    dal_giorno.style.backgroundColor = "";
                }

                //controllo sul mese
                if (((dal_mese.value < 1) || (dal_mese.value > 12)) && (dal_mese.value != "")) {
                    document.getElementById('span_errori').innerHTML = "<b>controllare date</b>";
                    dal_mese.style.backgroundColor = "#FF3F3F";
                    errore = true;
                    visualizza_span_errori = true;
                } else {
                    dal_mese.style.backgroundColor = "";
                }

                //se è l'ultima riga il controllo va fatto anche sul data_al
                if (i == righe.length - 2) {

                    al_giorno = document.getElementById('ctl00_right_al_giorno_' + i);
                    al_mese = document.getElementById('ctl00_right_al_mese_' + i);
                    al_anno = document.getElementById('ctl00_right_al_anno_' + i);
                    data_al = new Date(al_anno.value, al_mese.value - 1, al_giorno.value);

                    //controllo sul giorno
                    if ((data_al.getDate() != al_giorno.value) && (al_giorno.value != "")) {
                        document.getElementById('span_errori').innerHTML = "<b>controllare date</b>";
                        al_giorno.style.backgroundColor = "#FF3F3F";
                        errore = true;
                        visualizza_span_errori = true;
                    } else {
                        al_giorno.style.backgroundColor = "";
                    }

                    //controllo sul mese
                    if (((al_mese.value < 1) || (al_mese.value > 12)) && (al_mese.value != "")) {
                        document.getElementById('span_errori').innerHTML = "<b>controllare date</b>";
                        al_mese.style.backgroundColor = "#FF3F3F";
                        errore = true;
                        visualizza_span_errori = true;
                    } else {
                        al_mese.style.backgroundColor = "";
                    }
                }

            }
            //visualizzo lo span di errore e disabilito il tasto
            if (visualizza_span_errori == true) {
                document.getElementById('span_errori').style.display = "";
                document.getElementById('ctl00_right_span_salvataggio_avvenuto').style.display = "none";
                //document.getElementById('ctl00_right_lkbSalvaTutto').setAttribute("onclick", "alert('controllare le date');return false;");
                document.getElementById('ctl00_right_lkbSalvaTutto').onclick = function() { alert('controllare le date'); return false; };
            } else {
                document.getElementById('span_errori').style.display = "none";
                //document.getElementById('ctl00_right_lkbSalvaTutto').setAttribute("onclick", "");
                document.getElementById('ctl00_right_lkbSalvaTutto').onclick = ""
            }
        }

        //SE LE DATE SONO DIFFERENTI DAL WEEKDAY CHECK IN DO' ERRORE
        var weekday = document.getElementById('ctl00_right_hdWeekDayCheckIn').value;
        if (errore == false) {
            for (i = 0; i < righe.length - 1; i++) {

                dal_giorno = document.getElementById('ctl00_right_dal_giorno_' + i);
                dal_mese = document.getElementById('ctl00_right_dal_mese_' + i);
                dal_anno = document.getElementById('ctl00_right_dal_anno_' + i);
                data_dal = new Date(dal_anno.value, dal_mese.value - 1, dal_giorno.value);

                storico = document.getElementById('ctl00_right_HiddenField_storico_' + i);

                if (storico.value == 0) {

                    if (i == righe.length - 2) {
                        al_giorno = document.getElementById('ctl00_right_al_giorno_' + i);
                        al_mese = document.getElementById('ctl00_right_al_mese_' + i);
                        al_anno = document.getElementById('ctl00_right_al_anno_' + i);
                        data_al = new Date(al_anno.value, al_mese.value - 1, al_giorno.value);

                        if (data_al.getUTCDay() + 1 != weekday) {
                            if (weekday == 1)
                                document.getElementById('span_errori').innerHTML = "<b>il weekday check-in della struttura è di lunedì</b>";

                            if (weekday == 2)
                                document.getElementById('span_errori').innerHTML = "<b>il weekday check-in della struttura è di martedì</b>";

                            if (weekday == 3)
                                document.getElementById('span_errori').innerHTML = "<b>il weekday check-in della struttura è di mercoledì</b>";

                            if (weekday == 4)
                                document.getElementById('span_errori').innerHTML = "<b>il weekday check-in della struttura è di giovedì</b>";

                            if (weekday == 5)
                                document.getElementById('span_errori').innerHTML = "<b>il weekday check-in della struttura è di venerdì</b>";

                            if (weekday == 6)
                                document.getElementById('span_errori').innerHTML = "<b>il weekday check-in della struttura è di sabato</b>";

                            if (weekday == 7)
                                document.getElementById('span_errori').innerHTML = "<b>il weekday check-in della struttura è di domenica</b>";

                            al_giorno.style.backgroundColor = "#FF3F3F";
                            errore = true;
                            visualizza_span_errori = true;
                        }

                    }


                    if (data_dal.getUTCDay() + 1 != weekday) {
                        if (weekday == 1)
                            document.getElementById('span_errori').innerHTML = "<b>il weekday check-in della struttura è di lunedì</b>";

                        if (weekday == 2)
                            document.getElementById('span_errori').innerHTML = "<b>il weekday check-in della struttura è di martedì</b>";

                        if (weekday == 3)
                            document.getElementById('span_errori').innerHTML = "<b>il weekday check-in della struttura è di mercoledì</b>";

                        if (weekday == 4)
                            document.getElementById('span_errori').innerHTML = "<b>il weekday check-in della struttura è di giovedì</b>";

                        if (weekday == 5)
                            document.getElementById('span_errori').innerHTML = "<b>il weekday check-in della struttura è di venerdì</b>";

                        if (weekday == 6)
                            document.getElementById('span_errori').innerHTML = "<b>il weekday check-in della struttura è di sabato</b>";

                        if (weekday == 7)
                            document.getElementById('span_errori').innerHTML = "<b>il weekday check-in della struttura è di domenica</b>";

                        dal_giorno.style.backgroundColor = "#FF3F3F";
                        errore = true;
                        visualizza_span_errori = true;
                    }
                } else {
                    dal_giorno.style.backgroundColor = "#ECE9D8";
                    dal_giorno.disabled = false;
                    dal_mese.style.backgroundColor = "#ECE9D8";
                    dal_mese.disabled = false;
                }


            }
            //visualizzo lo span di errore e disabilito il tasto
            if (visualizza_span_errori == true) {
                document.getElementById('span_errori').style.display = "";
                document.getElementById('ctl00_right_span_salvataggio_avvenuto').style.display = "none";
                //document.getElementById('ctl00_right_lkbSalvaTutto').setAttribute("onclick", "alert('controllare le date');return false;");
                document.getElementById('ctl00_right_lkbSalvaTutto').onclick = function() { alert('controllare le date'); return false; };
            } else {
                document.getElementById('span_errori').style.display = "none";
                //document.getElementById('ctl00_right_lkbSalvaTutto').setAttribute("onclick", "");
                document.getElementById('ctl00_right_lkbSalvaTutto').onclick = ""
            }

        }

        //SE NON CI SONO ERRORI DI TIPO DATA CONTROLLO GLI ACCAVALLAMENTI
        if (errore == false) {
            //controlli date per accavallamento
            for (i = 0; i < righe.length - 2; i++) {
                dal_giorno = document.getElementById('ctl00_right_dal_giorno_' + i);
                dal_mese = document.getElementById('ctl00_right_dal_mese_' + i);
                dal_anno = document.getElementById('ctl00_right_dal_anno_' + i);
                data_dal = new Date(dal_anno.value, dal_mese.value - 1, dal_giorno.value);
                var dal_giorno_succ = document.getElementById('ctl00_right_dal_giorno_' + (i + 1));
                var dal_mese_succ = document.getElementById('ctl00_right_dal_mese_' + (i + 1));
                var dal_anno_succ = document.getElementById('ctl00_right_dal_anno_' + (i + 1));
                var data_dal_succ = new Date(dal_anno_succ.value, dal_mese_succ.value - 1, dal_giorno_succ.value);

                    if ((dal_giorno.value != "") && (dal_mese.value != "") && (dal_anno.value != "") && (dal_giorno_succ.value != "") && (dal_mese_succ.value != "") && (dal_anno_succ.value != "")) {

                        if (dateDiff("d", data_dal, data_dal_succ) <= 0) {
                            document.getElementById('span_errori').innerHTML = "<b>le date non sono consecutive</b>";
                            visualizza_span_errori = true;
                            dal_giorno_succ.style.backgroundColor = "#FF3F3F";
                            dal_mese_succ.style.backgroundColor = "#FF3F3F";
                            errore = true;
                        } else {
                            dal_giorno_succ.style.backgroundColor = "";
                            dal_mese_succ.style.backgroundColor = "";

                        }

                    }


                    //ultima riga controllo anche al
                    if (i == righe.length - 3) {
                        al_giorno = document.getElementById('ctl00_right_al_giorno_' + (i + 1));
                        al_mese = document.getElementById('ctl00_right_al_mese_' + (i + 1));
                        al_anno = document.getElementById('ctl00_right_al_anno_' + (i + 1));
                        data_al = new Date(al_anno.value, al_mese.value - 1, al_giorno.value);

                        if ((al_giorno.value != "") && (al_mese.value != "") && (al_anno.value != "") && (dal_giorno_succ.value != "") && (dal_mese_succ.value != "") && (dal_anno_succ.value != "")) {

                            if (dateDiff("d", data_dal_succ, data_al) <= 0) {
                                document.getElementById('span_errori').innerHTML = "<b>le date non sono consecutive</b>";
                                visualizza_span_errori = true;
                                al_giorno.style.backgroundColor = "#FF3F3F";
                                al_mese.style.backgroundColor = "#FF3F3F";
                                errore = true;
                            } else {
                                al_giorno.style.backgroundColor = "";
                                al_mese.style.backgroundColor = "";
                            }
                        }
                    }        
            }

            //visualizzo lo span di errore e disabilito il tasto
            if (visualizza_span_errori == true) {
                document.getElementById('span_errori').style.display = "";
                //document.getElementById('ctl00_right_span_salvataggio_avvenuto').style.display = "none";
                document.getElementById('ctl00_right_lkbSalvaTutto').setAttribute("onclick", "alert('controllare le date');return false;");
                document.getElementById('ctl00_right_lkbSalvaTutto').onclick = function() { alert('controllare le date'); return false; };
            } else {
                document.getElementById('span_errori').style.display = "none";
                //document.getElementById('ctl00_right_lkbSalvaTutto').setAttribute("onclick", "");
                document.getElementById('ctl00_right_lkbSalvaTutto').onclick = ""
            }
       }
    
}

function controllo_giorni(i) {
    var righe = document.getElementById('ctl00_right_box_visualizzazione_dati').getElementsByTagName("tr");
    var visualizza_span_errori = false
    var gg_PP
    var prezzo_PP
    var percentuale_PP
    var gg_LM
    var prezzo_LM
    var percentuale_LM

    var tipo_LM = document.getElementById('ctl00_right_ddl_modalita').value
    var tipo_PP = document.getElementById('ctl00_right_ddl_modalita_PP').value

    for (j = 0; j < righe.length - 1; j++) {

        gg_PP = document.getElementById('ctl00_right_gg_PP_' + j);
        if (tipo_PP == 0) {
            prezzo_PP = document.getElementById('ctl00_right_prezzo_PP_' + j);
        } else {
            prezzo_PP = document.getElementById('ctl00_right_percentuale_PP_' + j);
        }
        
        gg_LM = document.getElementById('ctl00_right_gg_LM_' + j);
        if (tipo_LM == 0) {
            prezzo_LM = document.getElementById('ctl00_right_prezzo_LM_' + j);
        } else {
            prezzo_LM = document.getElementById('ctl00_right_percentuale_LM_' + j);
        }
        
        if (gg_PP.value != "0") {
            if ((prezzo_PP.value == "0") || (prezzo_PP.value == "0.00") || (prezzo_PP.value == "0,00") || (prezzo_PP.value == "")) {
                document.getElementById('span_errori').innerHTML = "<b>inserire il prezzo o la percentuale da scalare per il prenota prima</b>";
                prezzo_PP.style.borderColor = "red";
                gg_PP.style.borderColor = "red";
                errore = true;
                visualizza_span_errori = true;
            } else {
                prezzo_PP.style.borderColor = "";
                gg_PP.style.borderColor = "";
            }
        } else {
            prezzo_PP.style.borderColor = "";
            gg_PP.style.borderColor = "";
        }


        if (gg_LM.value != 0) {
            if ((prezzo_LM.value == "0") || (prezzo_LM.value == "0.00") || (prezzo_LM.value == "0,00") || (prezzo_LM.value == "")) {
                document.getElementById('span_errori').innerHTML = "<b>inserire il prezzo o la percentuale da scalare per i last minute</b>";
                prezzo_LM.style.borderColor = "red";
                gg_LM.style.borderColor = "red";
                errore = true;
                visualizza_span_errori = true;
            } else {
                prezzo_LM.style.borderColor = "";
                gg_LM.style.borderColor = "";
            }
        } else {
            prezzo_LM.style.borderColor = "";
            gg_LM.style.borderColor = "";
        }
    }
    
    if (visualizza_span_errori == true) {
        document.getElementById('span_errori').style.display = "";
        document.getElementById('ctl00_right_lkbSalvaTutto').setAttribute("onclick", "alert('inserire il prezzo o la percentuale da scalare per i last minute e il prenota prima');return false;");
        document.getElementById('ctl00_right_lkbSalvaTutto').onclick = function(){ alert('inserire il prezzo o la percentuale da scalare per i last minute e il prenota prima');return false; };
    } else {
        document.getElementById('span_errori').style.display = "none";
        document.getElementById('ctl00_right_lkbSalvaTutto').onclick = ""
    }
}


//funzione per il controllo delle date vuote e date antecedenti oggi
function controlloDateVuote() {
    var dal_giorno;
    var dal_mese;
    var dal_anno;
    var al_giorno;
    var al_mese;
    var al_anno;
    var storico;
    
    //righe della tabella
    var righe = document.getElementById('ctl00_right_box_visualizzazione_dati').getElementsByTagName("tr");
    var controllo_spazi_vuoti = false;
    var controllo_data_anteriore = false;
    
    for (i = 0; i < righe.length - 1; i++) {
        //copio i valori
        dal_giorno = document.getElementById('ctl00_right_dal_giorno_' + i);
        dal_mese = document.getElementById('ctl00_right_dal_mese_' + i);
        dal_anno = document.getElementById('ctl00_right_dal_anno_' + i);
        storico = document.getElementById('ctl00_right_HiddenField_storico_' + i);
            
        if ((dal_giorno.value == "") || (dal_mese.value == "") || (dal_anno.value == "")) {
            controllo_spazi_vuoti = true;
            errore = true;
        }

        //ultima riga per data_al
        if (i == righe.length - 2) {
            al_giorno = document.getElementById('ctl00_right_al_giorno_' + i);
            al_mese = document.getElementById('ctl00_right_al_mese_' + i);
            al_anno = document.getElementById('ctl00_right_al_anno_' + i);

            if ((al_giorno.value == "") || (al_mese.value == "") || (al_anno.value == "")) {
                controllo_spazi_vuoti = true;
                errore = true;
            }
        }
//        if (storico.value == 0) {
//            var data_inserita = new Date (dal_anno.value, dal_mese.value - 1, dal_giorno.value);
//            today = new Date;
//            
//            
//            if (data_inserita < today) {
//                controllo_data_anteriore = true;
//                errore = true;
//            }
//        }
    }

    //disabilito tasto salva
    if (controllo_spazi_vuoti == true) {
        document.getElementById('span_errori').innerHTML = "<b>controllare date vuote</b>";
        document.getElementById('span_errori').style.display = "";
        //document.getElementById('ctl00_right_lkbSalvaTutto').setAttribute("onclick", "alert('controllare le date');return false;");
        document.getElementById('ctl00_right_lkbSalvaTutto').onclick = function(){ alert('controllare le date');return false; };
        document.getElementById('ctl00_right_span_salvataggio_avvenuto').style.display = "none";
        return true
    }

    //disabilito tasto salva
    if (controllo_data_anteriore == true) {
        document.getElementById('span_errori').innerHTML = "<b>data anteriore a quella corrente</b>";
        document.getElementById('span_errori').style.display = "";
        //document.getElementById('ctl00_right_lkbSalvaTutto').setAttribute("onclick", "alert('controllare le date');return false;");
        document.getElementById('ctl00_right_lkbSalvaTutto').onclick = function() { alert('controllare le date'); return false; };
        document.getElementById('ctl00_right_span_salvataggio_avvenuto').style.display = "none";
        return true
    }
    return false
    
      
}

function controllaStagionalitaPrecedenti(i){
    var nome_stagionalita = document.getElementById('ctl00_right_nome_stagionalita_' + i);
    var nome_stagionalita_precedente
    var contatore = i - 1 
    while (contatore != -1){
        nome_stagionalita_precedente = document.getElementById('ctl00_right_nome_stagionalita_' + contatore);
        if (nome_stagionalita.value == nome_stagionalita_precedente.value){
            document.getElementById('ctl00_right_prezzo_proprietario_' + i).value = document.getElementById('ctl00_right_prezzo_proprietario_' + contatore).value;
            document.getElementById('ctl00_right_prezzo_web_' + i).value = document.getElementById('ctl00_right_prezzo_web_' + contatore).value;
//            document.getElementById('ctl00_right_prezzo_LM_' + i).value = document.getElementById('ctl00_right_prezzo_LM_' + contatore).value;
//            document.getElementById('ctl00_right_percentuale_LM_' + i).value = document.getElementById('ctl00_right_percentuale_LM_' + contatore).value;
//            document.getElementById('ctl00_right_prezzo_PP_' + i).value = document.getElementById('ctl00_right_prezzo_PP_' + contatore).value;
//            document.getElementById('ctl00_right_percentuale_PP_' + i).value = document.getElementById('ctl00_right_percentuale_PP_' + contatore).value;
            return true;
        }
        
        
        contatore = contatore -1;
    }
}


//PER IL TOOLTIP DELLE CC
function info_data(e, id)
{
	if (document.getElementById(id))
	{
		if (document.getElementById(id).style.display == 'block')
		{
			document.getElementById(id).style.display = 'none';
		}
		else
		{
			document.getElementById(id).style.left = findPos(e, 'x', 0);
			document.getElementById(id).style.top = findPos(e, 'y', 0);
			document.getElementById(id).style.display = 'block';
		}
	}
}

function findPos(e, pos_type, move_val)
{
	var tipo_browser = navigator.appName;
	var pos_x = 0;
	var pos_y = 0;
	if (tipo_browser == 'Netscape')
	{
		pos_x = parseInt(self.pageXOffset) + e.clientX + document.body.scrollLeft;
		pos_y = parseInt(self.pageYOffset) + e.clientY + document.body.scrollTop;
		pos_x = pos_x + move_val;
		pos_y = pos_y + move_val;
		pos_x = pos_x + "px";
		pos_y = pos_y + "px";
	}
	else
	{
		if (e.pageX) return e.pageX;
		else if (e.clientX)
			pos_x = e.clientX + (document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft);
		else return null;
		if (e.pageY) return e.pageY;
		else if (e.clientY)
			pos_y = e.clientY + (document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop);
		else return null;
		pos_x = pos_x + move_val;
		pos_y = pos_y + move_val;
	}
	if (pos_type == 'x')
	{
		return pos_x;
	}
	else
	{
		return pos_y;
	}
}

// Creiamo funzioni per la selezione rapida del periodo di soggiorno dell'alloggio
// La prima funzione viene chiamata su onclick e salva negli hiddenField giorno_dal e room_id_dal
//function colora_celle_mousedown(id){

//    //coloro cella del colore dello stato scelto
//    document.getElementById("ctl00_right_" + id).style.backgroundColor="#ff3333";
//    //salviamo i dati della partenza del soggiorno negli hiddenField
//    ary_dal = id.split("_");
//    document.getElementById("ctl00_right_hfRoomId_dal").value = ary_dal[3];
//    document.getElementById("ctl00_right_hfGiorno_dal").value = ary_dal[4];
//}

//function colora_celle_mouseup(id){
//    ary_al = id.split("_");
//    
//    if ((ary_al[3] == document.getElementById("ctl00_right_hfRoomId_dal").value) && (dateDiff("d", document.getElementById("ctl00_right_hfGiorno_dal").value, ary_al[4])>=0)){
//        document.getElementById("ctl00_right_" + id).style.backgroundColor = "#ff3333";
//        
//        //Apro la finestra per l'inserimento dei dati della prenotazione
//        //document.getElementById("ctl00_right_box_prenotazione").style.display = 'block';
//        document.getElementById("ctl00_right_box_prenotazione").value = document.getElementById("ctl00_right_hfGiorno_dal").value;
//        document.getElementById("ctl00_right_box_prenotazione").value = ary_al[4];
//    } else {
//        alert("errore durante la selezione del periodo");
//    }
//    document.getElementById("ctl00_right_hfRoomId_dal").value = "";
//    document.getElementById("ctl00_right_hfGiorno_dal").value = "";
//}

//function colora_celle_mousemove(id){
//    ary_giorni = id.split("_");
//    //alert(document.getElementById("ctl00_right_hfRoomId_dal").value);
//    if ((document.getElementById("ctl00_right_hfRoomId_dal").value != "") && (document.getElementById("ctl00_right_hfGiorno_dal").value != "")){
//        if ((ary_giorni[3] == document.getElementById("ctl00_right_hfRoomId_dal").value) && (dateDiff("d", document.getElementById("ctl00_right_hfGiorno_dal").value, ary_giorni[4])>=0)){
//            document.getElementById("ctl00_right_" + id).style.backgroundColor = "#ff3333";
//        }
//    }
//}

function aggiornavaloriPrenotazione(){
    var acconto;
    var costo_prenotazione = document.getElementById("ctl00_right_txt_costo").value;
    var prezzo_agenzia = document.getElementById("ctl00_right_txt_prezzoAgenzia").value;
    var prezzo_traghetto = document.getElementById("ctl00_right_txtPrezzoTraghetto").value;
    if (costo_prenotazione != ""){
       acconto= ((costo_prenotazione.replace(",",".")*30)/100) + parseFloat(prezzo_agenzia.replace(",",".")) + parseFloat(prezzo_traghetto.replace(",","."));
       document.getElementById("ctl00_right_txt_totPrenotazione").value = parseFloat(costo_prenotazione.replace(",",".")) + parseFloat(prezzo_agenzia.replace(",",".")) + parseFloat(prezzo_traghetto.replace(",","."));
       document.getElementById("ctl00_right_txt_acconto").value = acconto.toFixed(2); //parsefloat(acconto).toFixed(2);
       document.getElementById("ctl00_right_txt_mancante").value = parseFloat((document.getElementById("ctl00_right_txt_totPrenotazione").value).replace(",",".")) - acconto;
    }
 }
 
 function aggiornavaloriPrenotazioneTraghetto(){
    var acconto;
    var costo_prenotazione = document.getElementById("ctl00_right_txt_costo").value;
    var prezzo_agenzia = document.getElementById("ctl00_right_txt_prezzoAgenzia").value;
    var prezzo_traghetto = document.getElementById("ctl00_right_txtPrezzoTraghetto").value;
    var totale_prenotazione;
    if (costo_prenotazione != ""){
       acconto=((costo_prenotazione.replace(",",".")*30)/100) + parseFloat(prezzo_agenzia.replace(",",".")) + parseFloat(prezzo_traghetto.replace(",","."));
       totale_prenotazione = parseFloat(costo_prenotazione.replace(",",".")) + parseFloat(prezzo_agenzia.replace(",",".")) + parseFloat(prezzo_traghetto.replace(",","."));
       document.getElementById("ctl00_right_txt_totPrenotazione").value = totale_prenotazione;
       document.getElementById("ctl00_right_txt_acconto").value = acconto.toFixed(2);
	   //alert(totale_prenotazione + ' ' + acconto + ' ' + totale_prenotazione - acconto);
       document.getElementById("ctl00_right_txt_mancante").value = totale_prenotazione - acconto;
    }
 }
 
function creaCalendarioLatoWeb(id_textbox,http_path) {
    var id = '#' + id_textbox;
    $(function() {
        $(id).datepicker({
            changeMonth: true,
            changeYear: true,
//            showOn: 'both',
//            buttonImageOnly: true, 
//            buttonImage: http_path + 'img/calendario/calendario.gif',
            yearRange: '-1:0',
            minDate: '',
            maxDate: null
        });
    });
}

function creaCalendarioLatoBackOffice(id_textbox) {
    var id = '#' + id_textbox;

    $(function() {
        $(id).datepicker({
            changeMonth: true,
            changeYear: true,
            yearRange:"-3:+2"
        });
    });
}


function loadingIconeDistanze(http_path,divId,divIdLoading,ImageId,imgsrc){
    //alert(ImageId);
    var img = document.getElementById(ImageId);
    document.getElementById(divId).style.display = 'none';
    document.getElementById(divIdLoading).style.display = 'block';
    img.src = imgsrc;
    
}

function prova(http_path,divId,building_id){
    //setTimeout("loadingIconeDistanze('" + http_path + "','" + divId + "','" + divIdLoading + "','" + ImageId + "','" + http_path + "img/circle.gif')",30);
    caricaIconeDistanze(http_path,divId,building_id);
}

function caricaIconeDistanze(http_path,divId,building_id){
$.ajax({
  url: http_path + "ajax/distanze.aspx?idStruttura=" + building_id,
  cache: false,
  success: function(html){

    $("#" + divId).html(html);
    $("#" + divId).css({'display' : ''});
  }
});
}

function compilaTipologiaStruttura(http_path,divId,building_id){
$.ajax({
  url: http_path + "ajax/tipologiaAlloggio.aspx?idStruttura=" + building_id,
  cache: false,
  success: function(html){
    $("#" + divId).html(html);
    $("#" + divId).css({'display' : ''});
  }
});
}

function compilaTabellaPrezzi(http_path,divId,building_id,dataInizio,numeroSettimane,Prezzo){
//alert(http_path + "ajax/PrezzoPrenotazione.aspx?idStruttura=" + building_id + "&dataInizio=" + dataInizio + "&nSettimane=" + numeroSettimane);
$.ajax({
  url: http_path + "ajax/PrezzoPrenotazione.aspx?idStruttura=" + building_id + "&dataInizio=" + dataInizio + "&nSettimane=" + numeroSettimane + "&prezzo=" + Prezzo ,
  cache: false,
  success: function(html){
    $("#" + divId).html(html);
    $("#" + divId).css({'display' : ''});
  }
});
}

function initFunction(){
    //alert('test');
}

function visualizzaPrenotazione(selezione,idHF,idtrCC,idtrDC,modPag){
    //alert(selezione + " " + idHF + " " + idtrCC + " " + idtrDC );
    if (selezione == 1)  {
        document.getElementById('ctl00_body_rbPrenotaVeloce').checked = true;
        //deseleziono check prenotazione telefonica
        document.getElementById('ctl00_body_rbPrenotaTelefono').checked = false;
        document.getElementById('ctl00_body_rbPrenotaTelefonoBonBan').checked = false;
        if (document.getElementById('ctl00_body_rbPrenotaTelefonoBolPost')) { document.getElementById('ctl00_body_rbPrenotaTelefonoBolPost').checked = false; }
        //-----------------------------------------
        document.getElementById(idHF).value = selezione;
        document.getElementById(idtrDC).style.display = '';
        document.getElementById(idtrCC).style.display = '';
        document.getElementById('tdCellulare').innerHTML = document.getElementById('tdCellulare').innerHTML.replace('*', '');
        document.getElementById('tdIndirProv').innerHTML = document.getElementById('tdIndirProv').innerHTML.replace('*', '');
        document.getElementById('tdCittaProv').innerHTML = document.getElementById('tdCittaProv').innerHTML.replace('*', '');
        document.getElementById('tdProvincia').innerHTML = document.getElementById('tdProvincia').innerHTML.replace('*', '');
        document.getElementById('tdCodAvPostale').innerHTML = document.getElementById('tdCodAvPostale').innerHTML.replace('*', '');
        document.getElementById('tdNazione').innerHTML = document.getElementById('tdNazione').innerHTML.replace('*', '');
        document.getElementById('tdCellulare').innerHTML = document.getElementById('tdCellulare').innerHTML + '*';
        document.getElementById('tdIndirProv').innerHTML = document.getElementById('tdIndirProv').innerHTML + '*';
        document.getElementById('tdCittaProv').innerHTML = document.getElementById('tdCittaProv').innerHTML + '*';
        document.getElementById('tdProvincia').innerHTML = document.getElementById('tdProvincia').innerHTML + '*';
        document.getElementById('tdCodAvPostale').innerHTML = document.getElementById('tdCodAvPostale').innerHTML + '*';
        document.getElementById('tdNazione').innerHTML = document.getElementById('tdNazione').innerHTML + '*';
        document.getElementById('tdSpecAnimali').innerHTML = document.getElementById('tdSpecAnimali').innerHTML.replace('*', '');
        document.getElementById('tdSpecAnimali').innerHTML = document.getElementById('tdSpecAnimali').innerHTML + '*';
        //document.getElementById('ctl00_body_trOraChiamata').style.display = 'none';
    } else {
        document.getElementById('ctl00_body_rbPrenotaVeloce').checked= false;
        if (modPag == 0) {
            document.getElementById('ctl00_body_rbPrenotaTelefono').checked = true;
        }
        if (modPag == 1) {
            document.getElementById('ctl00_body_rbPrenotaTelefonoBonBan').checked = true;
        }
        if (modPag == 4) {
            document.getElementById('ctl00_body_rbPrenotaTelefonoBolPost').checked = true;
        }
        document.getElementById(idHF).value = selezione;
        document.getElementById(idtrDC).style.display = '';
        document.getElementById(idtrCC).style.display = 'none';
        document.getElementById('tdCellulare').innerHTML = document.getElementById('tdCellulare').innerHTML.replace('*', '');
        document.getElementById('tdIndirProv').innerHTML = document.getElementById('tdIndirProv').innerHTML.replace('*', '');
        document.getElementById('tdCittaProv').innerHTML = document.getElementById('tdCittaProv').innerHTML.replace('*', '');
        document.getElementById('tdProvincia').innerHTML = document.getElementById('tdProvincia').innerHTML.replace('*', '');
        document.getElementById('tdCodAvPostale').innerHTML = document.getElementById('tdCodAvPostale').innerHTML.replace('*', '');
        document.getElementById('tdNazione').innerHTML = document.getElementById('tdNazione').innerHTML.replace('*', '');
        document.getElementById('tdSpecAnimali').innerHTML = document.getElementById('tdSpecAnimali').innerHTML.replace('*', '');
        //document.getElementById('ctl00_body_trOraChiamata').style.display = '';
    }
    document.getElementById('ctl00_body_hfModalitaPagamento').value = modPag;
    document.getElementById('ctl00_body_tblConfermaPrenotazione').style.display='';
    document.getElementById('ctl00_body_lnk_conferma_prenotazione').focus();
}

function visualizzaPrenotaRadio(selezione,modPag){
    //alert(selezione);
    if (selezione == 1){
        //deseleziono check prenotazione telefonica
        document.getElementById('ctl00_body_rbPrenotaTelefono').checked = false;
        document.getElementById('ctl00_body_rbPrenotaTelefonoBonBan').checked = false;
        document.getElementById('ctl00_body_rbPrenotaTelefonoBolPost').checked = false;
        //-----------------------------------------
        document.getElementById('ctl00_body_rbPrenotaVeloce').checked= true;
        document.getElementById('ctl00_body_hfSelezioneChiusura').value = selezione;
        document.getElementById('ctl00_body_hfModalitaPagamento').value = modPag;
        document.getElementById('ctl00_body_trDatiCliente').style.display = '';
        document.getElementById('ctl00_body_trCartaCredito').style.display = '';
        //document.getElementById('ctl00_body_trOraChiamata').style.display = 'none';
    } else {
        document.getElementById('ctl00_body_rbPrenotaVeloce').checked = false;
        if (modPag == 0) {
            document.getElementById('ctl00_body_rbPrenotaTelefono').checked = true;
        }
        if (modPag == 1) {
            document.getElementById('ctl00_body_rbPrenotaTelefonoBonBan').checked = true;
        }
        if (modPag == 4) {
            document.getElementById('ctl00_body_rbPrenotaTelefonoBolPost').checked = true;
        }
        document.getElementById('ctl00_body_hfSelezioneChiusura').value = selezione;
        document.getElementById('ctl00_body_hfModalitaPagamento').value = modPag;
        document.getElementById('ctl00_body_trDatiCliente').style.display = '';
        document.getElementById('ctl00_body_trCartaCredito').style.display = 'none';
        //document.getElementById('ctl00_body_trOraChiamata').style.display = '';
    }
    document.getElementById('ctl00_body_tblConfermaPrenotazione').style.display='';
}

function modificaProvincia(){
    if (document.getElementById('ctl00_body_ddl_nazione').value != "I") {
        document.getElementById('ctl00_body_ddl_provincia').value = "nessuna";
    }
}

function calcolaBambini(){
    var numeroBambini;

    if (document.getElementById('ctl00_body_numero_adulti').value != "") {
        if(document.getElementById('ctl00_body_numero_persone_alloggio').value != "") {
            numeroBambini=document.getElementById('ctl00_body_numero_persone_alloggio').value - document.getElementById('ctl00_body_numero_adulti').value;
            if (numeroBambini <= 4) {
                if (numeroBambini == 0){
                    document.getElementById('ctl00_body_numero_bambini').value = "";
                } else {
                    document.getElementById('ctl00_body_numero_bambini').value = numeroBambini;
                }
            } else {
                document.getElementById('ctl00_body_numero_bambini').value = 4;
            }
        }
    } else {
        document.getElementById('ctl00_body_numero_bambini').value = "";
    }
    
    document.getElementById('ctl00_body_tdLblAnni').style.display = 'none';
    document.getElementById('tdNumeroBambini').innerHTML = document.getElementById('tdNumeroBambini').innerHTML.replace('*','');
    document.getElementById('ctl00_body_txt_bambino1').style.display = 'none';
    document.getElementById('ctl00_body_txt_bambino2').style.display = 'none';
    document.getElementById('ctl00_body_txt_bambino3').style.display = 'none';
    document.getElementById('ctl00_body_txt_bambino4').style.display = 'none';
    
    if (document.getElementById('ctl00_body_numero_bambini').value != "") {
        document.getElementById('tdNumeroBambini').innerHTML = document.getElementById('tdNumeroBambini').innerHTML + '*';
        document.getElementById('ctl00_body_tdLblAnni').style.display = '';
        if (document.getElementById('ctl00_body_numero_bambini').value == 1) {
            document.getElementById('ctl00_body_txt_bambino1').style.display = '';
        }
        if (document.getElementById('ctl00_body_numero_bambini').value == 2) {
            document.getElementById('ctl00_body_txt_bambino1').style.display = '';
            document.getElementById('ctl00_body_txt_bambino2').style.display = '';
        }
        if (document.getElementById('ctl00_body_numero_bambini').value == 3) {
            document.getElementById('ctl00_body_txt_bambino1').style.display = '';
            document.getElementById('ctl00_body_txt_bambino2').style.display = '';
            document.getElementById('ctl00_body_txt_bambino3').style.display = '';
        }
        if (document.getElementById('ctl00_body_numero_bambini').value == 4) {
            document.getElementById('ctl00_body_txt_bambino1').style.display = '';
            document.getElementById('ctl00_body_txt_bambino2').style.display = '';
            document.getElementById('ctl00_body_txt_bambino3').style.display = '';
            document.getElementById('ctl00_body_txt_bambino4').style.display = '';
        }
    }
}

function apriTextBoxBambini(){
    document.getElementById('ctl00_body_tdLblAnni').style.display = 'none';
    document.getElementById('ctl00_body_txt_bambino1').style.display = 'none';
    document.getElementById('ctl00_body_txt_bambino2').style.display = 'none';
    document.getElementById('ctl00_body_txt_bambino3').style.display = 'none';
    document.getElementById('ctl00_body_txt_bambino4').style.display = 'none';
    //alert(document.getElementById('ctl00_body_numero_bambini').value);
    if (document.getElementById('ctl00_body_numero_bambini').value != "") {
        document.getElementById('ctl00_body_tdLblAnni').style.display = '';
        if (document.getElementById('ctl00_body_numero_bambini').value == 1) {
            document.getElementById('ctl00_body_txt_bambino1').style.display = '';
        }
        if (document.getElementById('ctl00_body_numero_bambini').value == 2) {
            document.getElementById('ctl00_body_txt_bambino1').style.display = '';
            document.getElementById('ctl00_body_txt_bambino2').style.display = '';
        }
        if (document.getElementById('ctl00_body_numero_bambini').value == 3) {
            document.getElementById('ctl00_body_txt_bambino1').style.display = '';
            document.getElementById('ctl00_body_txt_bambino2').style.display = '';
            document.getElementById('ctl00_body_txt_bambino3').style.display = '';
        }
        if (document.getElementById('ctl00_body_numero_bambini').value == 4) {
            document.getElementById('ctl00_body_txt_bambino1').style.display = '';
            document.getElementById('ctl00_body_txt_bambino2').style.display = '';
            document.getElementById('ctl00_body_txt_bambino3').style.display = '';
            document.getElementById('ctl00_body_txt_bambino4').style.display = '';
        }
    }
}

function visualizzaTagliaAnimali(){
    //alert(document.getElementById('ctl00_body_animali_si_no_0').value);
    if (document.getElementById('ctl00_body_animali_si_no_0').checked == true) {
        document.getElementById('ctl00_body_taglia_animali').style.display = '';       
    }
    if (document.getElementById('ctl00_body_animali_si_no_1').checked == true) {
        document.getElementById('ctl00_body_taglia_animali').style.display = 'none';
    }
}

function F_cerca_codice_compravendita(event) { if (event.keyCode == 13) { $("#ctl00_lkb_cerca").focus(); $("#ctl00_lkb_cerca").click(); __doPostBack('ctl00$lkb_cerca', ''); } }
function F_cerca_codice_affitti(event) { if (event.keyCode == 13) { $("#ctl00_lnkButtonAffitti").focus(); $("#ctl00_lnkButtonAffitti").click(); __doPostBack('ctl00$lnkButtonAffitti', ''); } }
//function F_cerca_codice_compravendita_home(event) { if (event.keyCode == 13) { document.getElementById('ctl00_body_lkb_cerca').focus(); document.getElementById('ctl00_body_lkb_cerca').click(); __doPostBack('ctl00$body$lkb_cerca', ''); } }
//function F_cerca_codice_affitti_home(event) { if (event.keyCode == 13) { document.getElementById('ctl00_body_lnkButtonAffitti').focus(); document.getElementById('ctl00_body_lnkButtonAffitti').click(); __doPostBack('ctl00$body$lnkButtonAffitti', ''); } }



// antonio - 25-02-2010 INIZIO Offuscare indirizzo mail con Javascript

function offuscaMail(user, domain, tld) {
    var mail;
    mail = '<a href="' + 'ma' + 'il' + 'to:' + user;
    mail += '&#64;' + domain + '.' + tld;
    mail += '">' + user + '&#64;' + domain + '.' + tld + '<' + '/a>';
    document.write(mail);
}

// nella pagina utilizzare offuscaMail('user','domain','tld');

// FINE Offuscare indirizzo mail con Javascript
