﻿var mouse_x = null;
var mouse_y = null;
var show_tooltip = false;
var mouse_out = null;

function on_MouseMove(e) 
{
    //alert('ciao');
	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;
		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 + 10;
		pos_y = pos_y + 20;
	}





    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(
            {
                top: mouse_y,
                left: mouse_x,
                visibility:'visible'
            });
        }
        else
        {
            $('tooltip').setStyles(
            {
                visibility:'hidden'
            });
        }
    }
    
    return false;
}

function toolTip(var_display, ajax_url)
{
    //alert('ciao');
    //alert(document.domain + '\n' + location.pathname);
    if(var_display == 'show')
    {
        mouse_out = true;
        show_tooltip = true;
        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'
        });

    }
}



function controlliDate()
{
    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
            {
                return true;
            }
                    
        }
    }
}

function F_contingente_prezzi(value, http_path, curr_page, alias_id)
{
    //alert(value);
    if (value == '')
    {
        location.href = http_path + 'building/manage_prices.aspx?alias_id=' + alias_id
    }
    else
    {
        location.href = http_path + 'building/' + curr_page + '?alias_id=' + alias_id + '&contingente_prezzi=' + value
    }
}

//function calcolo_altezza(){
//var windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
//document.getElementById("content_middle").style.height= (parseInt(windowHeight))+'px';
//alert((parseInt(windowHeight))+'px');
//}
function visualizza_prodotti(prodottogruppoID, segmentoID, prodottoID, lingua) {
    $('#div_elencoSegmenti').css("display", "none");
    $('#table_dettaglioSegmento').css("display", "");
    
    if (lingua == '') {
        lingua = 'it';
    }

    $('#flash_grande_e_icona').remove();
    $('#segmento_grande_e_icona').remove();
    $('#loading_grande_e_icona').css("visibility", "visible");



    $.getJSON("ajax/AjaxProdotti.aspx?", { gru: prodottogruppoID, seg: segmentoID, pro: prodottoID, lin: lingua }, function (data) {

        
        $('#div-ProdottoFlashContainer').append(data.flash);
        $('#span_codOtherProdotto').html(data.altroProdotto.codice);
        //$('#img_small_otherProdotto').attr("src", "GetThumbnailImage.aspx?Width=100&Height=100&FileName=" + data.altroProdotto.imgUrl + "").css("border-color", data.altroProdotto.borderColor);
        $('#img_small_otherProdotto').attr("src", "ImageThumbnail.ashx?path=" + data.altroProdotto.imgUrl + "&m=1&r=3&h=100&w=100").css("border-color", data.altroProdotto.borderColor);
        $('#img_small_otherProdotto').unbind('click').click(function () {
            visualizza_prodotti(prodottogruppoID, segmentoID, data.altroProdotto.id, lingua);
        });

        $('span[id$="lbl_codice"]').html(data.prodotto.codice);

        $('span[id$="lbl_descrizione"]').html(data.prodotto.descrizione.replace(/§§§/gi, String.fromCharCode(13)));
        $('#div-container-frase').css("background-image", "url('" + data.prodotto.imgUrlFrase + "')");



        $('#loading_grande_e_icona').css("visibility", "hidden");

    });
   
      
}
