var gnt_select;
var gnt_radio;

function checkBrand(val){
    var myURI = new URI(decodedURL);
    myURI.setData('id_brand', document.id('filtro_brand').get('value'));
    myURI.go();
}

function checkAnnoDa(){
    var myURI = new URI(decodedURL);
    myURI.setData('timeline_da', document.id('anno_da').get('value'));
    myURI.go();
}

function checkAnnoA(){
    var myURI = new URI(decodedURL);
    myURI.setData('timeline_a', document.id('anno_a').get('value'));
    myURI.go();
    
}

function checkCat(val){
    var myURI = new URI(decodedURL);
    myURI.setData('id_categoria', document.id('filtro_categoria').get('value'));
    myURI.go();
}

function checkApprofondimento(val){
    var myURI = new URI(decodedURL);
    myURI.setData('id_approfondimento', document.id('filtro_approfondimento').get('value'));
    myURI.go();
}

function checkEvento(val){
    var myURI = new URI(decodedURL);
    myURI.setData('id_evento', document.id('filtro_evento').get('value'));
    myURI.go();
}

document.addEvent('domready', function(){

    gnt_select_marchio = new brigaSelect({
        id: 'filtro_brand',
        callback: checkBrand,
        additionalId: 'brand_cont',
		maxchars:28,
		minwidth:140
    });
    gnt_select_dal = new brigaSelect({
        id: 'anno_da',
        callback: checkAnnoDa,
        additionalId: 'anno_da_cont'
    });
    
    gnt_filtro_categoria = new brigaRadio({
        radioName: 'filtro_categoria',
        callback: checkCat
    });
    
    gnt_anno_a = new brigaSelect({
        id: 'anno_a',
        callback: checkAnnoA,
        additionalId: 'anno_a_cont'
    });
    
    gnt_filtro_approfondimento = new brigaSelect({
        id: 'filtro_approfondimento',
        callback: checkApprofondimento,
        additionalId: 'approfondimento_cont',
		maxchars:24
    });
    
    gnt_filtro_evento = new brigaSelect({
        id: 'filtro_evento',
        callback: checkEvento,
        additionalId: 'evento_cont',
		maxchars:30
    });
    
    
    document.id('btn_form_progetto').addEvent('click', function(ev){
        var myURI = new URI(decodedURL);
        myURI.clearData();

        myURI.setData('id_page', 'sezione2');
        myURI.setData('sezione_fe', 'sezione2');
        myURI.setData('page', 'fe_std');
        
		myURI.setData('f_nome', document.id('f_nome_txt').get('value'));
		
        myURI.go();
    });
    
    
    document.id('f_nome_txt').addEvent('keypress', function(evt){
        if (evt.key == 'enter') {
            var myURI = new URI(decodedURL);
              myURI.setData('id_page', 'sezione2');
        myURI.setData('sezione_fe', 'sezione2');
        myURI.setData('page', 'fe_std');
            myURI.setData('f_nome', document.id('f_nome_txt').get('value'));
            myURI.go();
        }
    });
    
    document.getElements('.data_sort').each(function(item, index){
        item.addEvent('click', function(ev){
        
            var event = new Event(ev);
            event.preventDefault();
            var sortDir = 0;
            if (item.hasClass('sel_su')) {
                sortDir = 1;
            }
            else {
                sortDir = 2;
            }
            
            var myURI = new URI(decodedURL);
            
            myURI.setData('sortField', 'anno');
            myURI.setData('sortDir', sortDir);
            myURI.go();
        });
    });
    
    
    
    document.getElements('.nome_sort').each(function(item, index){
        item.addEvent('click', function(ev){
        
            var event = new Event(ev);
            
            event.preventDefault();
            var sortDir = 0;
            if (item.hasClass('sel_su')) {
                sortDir = 1;
            }
            else {
                sortDir = 2;
            }
            
            var myURI = new URI(decodedURL);
            
            myURI.setData('sortField', 'nome');
            myURI.setData('sortDir', sortDir);
            myURI.go();
        });
    });
    
});

