﻿
//******************************** CARRELLO
var mytime;
var mytime2;
var mytime3;

function VisualizzaAddRemove(strDes)
{
    clearTimeout(mytime);
    mytime=setTimeout("DivVisibile('" + strDes + "')",500);   
}
function DivVisibile(strDescrizione)
{
    $('AddCartDiv').innerHTML = strDescrizione;
    $('AddCartDiv').setStyle('position','fixed');
    $('AddCartDiv').setStyle('z-index','15000');
    $('AddCartDiv').setStyle('top','0px');
    $('AddCartDiv').setStyle('left','0px');
    
    $('AddCartDiv').setStyle('width','100%');
    $('AddCartDiv').setStyle('height','25px');
    
    
    var myEffect = new Fx.Morph('AddCartDiv', {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
    
    myEffect.start({
        'background-color': ['#000000','#680103'],
        'color': ['#000000','#FFFFFF'],
        'opacity': [0,1]
    });
    
    clearTimeout(mytime2);
    mytime2=setTimeout('DivInvisibile()',8000)
}
function DivInvisibile()
{
    var myEffect2 = new Fx.Morph('AddCartDiv', {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
    
    myEffect2.start({
        'background-color': ['#680103','#000000'],
        'color': ['#FFFFFF','#000000'],
        'opacity': [1,0]
    });
}
function ScriviHiddenQTA(e,idHiddenQTA, idTxtQTA)
{
    alert($(idTxtQTA).text);
    $(idHiddenQTA).value = $(idTxtQTA).text;
}

function PulisciRicerca()
{
    var objRic = $$('.cssRicerca');
    
    for (var i=0;i<objRic.length;i++)
    {
        objRic[i].value = '';
    }
}

function ActivateAlertDiv(visstring, elem, msg)
{
     var adiv = $get(elem);
     adiv.style.visibility = visstring;
     
     adiv.style.top = String((screen.height / 2) + 100) + 'px';
     adiv.style.left = String(screen.width / 2) + 'px';
     
     adiv.innerHTML = '<img alt="" src="ajax-loader.gif" /><br><font face="Book Antiqua">' + msg + '</font>'; 
}


    



function IdOggetto(args) 
{
    var elem = args;

    ElementoID = "";
    ElementoID = String(elem.id);

    var OggettiSplit = new Array();
    OggettiSplit = ElementoID.split("_");

    ElementoID = String(OggettiSplit[OggettiSplit.length - 1]);
    
    //OGGETTO CHE HA GENERATO IL POSTBACK
    objPostbackSend = ElementoID;
    return ElementoID;
};



window.addEvent('domready', function() 
{    
        
        
    
    
    function TestoSelezionato() 
    {
	    return $try(
		    function() { 
		            return window.getSelection(); 
		        },
		    function() { 
		            return document.getSelection(); 
		        },
		    function() { 
	            var selection = document.selection && document.selection.createRange();
			    if(selection.text) 
			    { 
			        return selection.text; 
                }
			    return false;
                }
        ) || false;
    };

    function GestisciSelezioneTesto(){
        if ($('divRisultati_ricerca'))
        {
            $('divRisultati_ricerca').addEvent('mouseup',function(e) {
                if (!e.rightClick)
                {
                    selection = TestoSelezionato();
                    if(selection && (selection = new String(selection).replace(/^\s+|\s+$/g,'')) && selection.length > 2) {
                        
                        $('divSelezioneRicerca').setStyles({ 
                            top: e.page.y - 20,
                            left: e.page.x + 13
                        }).tween('opacity','1');
                        
                        
                        $('divSelezioneRicerca').removeEvent('click');
                        $('divSelezioneRicerca').addEvent('click',function(){
                            var testoRicerca=selection;
                            testoRicerca=testoRicerca.replace(',',' ');
                            testoRicerca=testoRicerca.replace('.',' ');
                            testoRicerca=testoRicerca.replace('%',' ');
                            location.href='Catalogo.aspx?ex=Ricerca_' + selection;
                        });
                        //.inject($('divSelezioneRicerca'));
                        
                        DivVisibile('<b>CERCA:</b> ' +  String(selection).substring(0,100));
                        
                        clearTimeout(mytime3);
                        mytime3 = setTimeout(function(){
                            var myEffect_RisultatiRicerca = new Fx.Morph('divSelezioneRicerca', {duration: '200', transition: Fx.Transitions.Sine.easeOut});
                            myEffect_RisultatiRicerca.start({
                                'opacity': '0'
                            });
                        },8000);
                        
                    }
                }
            });
            $('divSelezioneRicerca').addEvent('mouseover',function(){
                clearTimeout(mytime3);
            });
            $('divSelezioneRicerca').addEvent('mouseout',function(){
                mytime3 = setTimeout(function(){
                    var myEffect_RisultatiRicerca = new Fx.Morph('divSelezioneRicerca', {duration: '200', transition: Fx.Transitions.Sine.easeOut});
                    myEffect_RisultatiRicerca.start({
                        'opacity': '0'
                    });
                },8000);
            });
        }
    };

    //INIT SELEZIONE TESTO
    $('divSelezioneRicerca').setStyle('opacity','0');
    $('divSelezioneRicerca').setStyle('display','inline-block');
    $('divSelezioneRicerca').setStyle('visibility','hidden');
    GestisciSelezioneTesto();
    
    var objPostbackSend = '';
        
    var ElementoID = '';
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
        
    function BeginRequestHandler(sender, args) 
    {
        //OGGETTO CHE HA GENERATO IL POSTBACK ASINCRONO
        var idObjPostBack = IdOggetto(args.get_postBackElement());
        //FUNZIONI PRE POSTBACK ASINCRONO
        //alert(idObjPostBack);
        
        
        
        var elem = args.get_postBackElement();
        ElementoID="";
        ElementoID = String(elem.id);
        var OggettiSplit = new Array();
        OggettiSplit = ElementoID.split("_");
        
        ElementoID = String(OggettiSplit[OggettiSplit.length-1]);
        
        
        
        if (ElementoID == 'LnkBtnIndietroPG' || 
            ElementoID == 'LnkBtnAvantiPG' || 
            ElementoID == 'linkbtn0' || 
            ElementoID == 'linkbtn1' || 
            ElementoID == 'linkbtn2' || 
            ElementoID == 'linkbtn3' || 
            ElementoID == 'linkbtn4' || 
            ElementoID == 'linkbtn5' || 
            ElementoID == 'linkbtn6' || 
            ElementoID == 'linkbtn7' || 
            ElementoID == 'linkbtn8' || 
            ElementoID == 'linkbtn9' || 
            ElementoID == 'linkbtn10')
        {
            
            //window.location.href='#SU';
        }
        if (ElementoID != 'ButtonLogin')
        {
            $('WindowRicerca').setStyle('visibility','hidden');
            $('WindowRicerca').setStyle('display','none');
            $('WindowLogin').setStyle('visibility','hidden');
            $('WindowLogin').setStyle('display','none');
            $('WindowContatti').setStyle('visibility','hidden');
            $('WindowContatti').setStyle('display','none');
        }
        
        ActivateAlertDiv('visible', 'AlertDiv', 'Attendere...');
        
    };

    function EndRequestHandler(sender, args) 
    {
        //OGGETTO CHE HA GENERATO IL POSTBACK ASINCRONO
        var idObjPostBack = objPostbackSend;
        
        //FUNZIONI POST POSTBACK ASINCRONO
        //alert(idObjPostBack);
        
        
            
        var Stringa = String;
        Stringa = String(ElementoID);

        if ((Stringa.indexOf("AvantiPG") != -1 && Stringa.indexOf("UP") == -1) ||
            (Stringa.indexOf("IndietroPG") != -1 && Stringa.indexOf("UP") == -1) ||
            (Stringa.indexOf("linkbtn") != -1 && Stringa.indexOf("UP") == -1)) {
            window.scrollTo(0, 0);
        }
            
//                    if (Stringa.indexOf("AvantiPG") != -1 ||
//                        Stringa.indexOf("IDFIG") != -1 ||
//                        Stringa.indexOf("IndietroM") != -1 ||
//                        Stringa.indexOf("AvantiM") != -1) {
//                        ElementoID = ElementoID;
//                    }
//                    else
//                    {
//                        window.scrollTo(0,0);
//                        //window.location.href='#SU';
//                    }


        ActivateAlertDiv('hidden', 'AlertDiv', '');
            
        function ActivateAlertDiv(visstring, elem, msg)
        {
             var adiv = $get(elem);
             adiv.style.visibility = visstring;
             
             adiv.style.top = String((screen.height / 2) + 100) + 'px';
             adiv.style.left = String(screen.width / 2) + 'px';
             
             adiv.innerHTML = '<img alt="" src="ajax-loader.gif" /><br><font face="Book Antiqua">' + msg + '</font>'; 
        };
        
        function ScriviHiddenQTA(e,idHiddenQTA, idTxtQTA)
        {
            alert($(idTxtQTA).text);
            $(idHiddenQTA).value = $(idTxtQTA).text;
        };
        
        GestisciSelezioneTesto();
        
    };
    
    
});





