// JavaScript Document
var tipo;
var marca;
var forma;
var prezzo;
var ulmarca;
var trig_marca;
var trigger_onclick_bk;
var trig_prezzo;
var bg_disabled = '#DDD url(/static/img_root/bg_select.gif) no-repeat scroll 99% 50%';
var bg_enabled = '#FFF url(/static/img_root/bg_select.gif) no-repeat scroll 99% 50%';

function initSearch() {
    tipo = document.getElementById('tipologia');
    marca = document.getElementById('marca');
    prezzo = document.getElementById('prezzo');
    forma = document.getElementById('forma');
    if (prezzo != null) {
        trig_prezzo = getElementsByClassName(prezzo.parentNode, 'a', 'trigger')[0];
    } else {
        document.getElementById('form').style.display = 'inline';
        document.getElementById('accessible_form').style.display = 'none';
    }
    ulmarca = marca.parentNode.getElementsByTagName('ul')[0];
    trig_marca = document.getElementById('marca').parentNode.getElementsByTagName('a')[0];
    trig_forma = document.getElementById('forma').parentNode.getElementsByTagName('a')[0];
    trigger_onclick_bk = trig_marca.onclick;
    switchMarca();
}

function switchMarca() {
    switch(document.getElementById('tipologia').value) {
        case '1687': 
            //telefonini
            if (trig_marca != null && trig_prezzo != null) {
                trig_marca.style.background = bg_enabled;
                trig_prezzo.style.background = bg_enabled;
                trig_forma.style.background = bg_enabled;
                trig_forma.onclick = trigger_onclick_bk;
                trig_marca.onclick = trigger_onclick_bk;
                trig_prezzo.onclick = trigger_onclick_bk;
                document.getElementById('musiradi').disabled = '';
                document.getElementById('fotohire').disabled = '';
                document.getElementById('hsdpa').disabled = '';
                document.getElementById('bluetoot').disabled = '';
                document.getElementById('umts').disabled = '';
                document.getElementById('gps').disabled = '';
                document.getElementById('dvbh').disabled = '';
            }
            var allLI = ulmarca.getElementsByTagName('li');
            var totLI = allLI.length;
            for (var i = 0; i < totLI; i++) {
                if (allLI[i].className == 'telefonini' || allLI[i].className == 'telefonini smartphone') {
                    allLI[i].style.display = 'inline';
                } else if (allLI[i].className != '') {
                    allLI[i].style.display = 'none';
                    allLI[i].margin = '0';
                    allLI[i].padding = '0';
                }
            }
            break;
        case '1700':
            //Smartphone
            if (trig_marca != null && trig_prezzo != null) {
                trig_marca.style.background = bg_enabled;
                trig_prezzo.style.background = bg_enabled;
                trig_forma.style.background = bg_enabled;
                trig_forma.onclick = trigger_onclick_bk;
                trig_marca.onclick = trigger_onclick_bk;
                trig_prezzo.onclick = trigger_onclick_bk;
                document.getElementById('musiradi').disabled = '';
                document.getElementById('fotohire').disabled = '';
                document.getElementById('bluetoot').disabled = '';
                document.getElementById('umts').disabled = '';
                document.getElementById('gps').disabled = '';
                document.getElementById('dvbh').disabled = '';
                document.getElementById('hsdpa').disabled = '';
            }
            var allLI = ulmarca.getElementsByTagName('li');
            var totLI = allLI.length;
            for (var i = 0; i < totLI; i++) {
                if (allLI[i].className == 'smartphone' || allLI[i].className == 'telefonini smartphone') {
                    allLI[i].style.display = 'inline';
                } else if (allLI[i].className != '') {
                    allLI[i].style.display = 'none';
                }
            }
            break;
        case '1694':
            //PC Card
            if (trig_marca != null && trig_prezzo != null) {
                trig_marca.style.background = bg_disabled;
                trig_prezzo.style.background = bg_disabled;
                trig_forma.style.background = bg_disabled;
                trig_forma.onclick = function() { return false; this.blur(); };
                trig_marca.onclick = function() { return false; this.blur(); };
                trig_prezzo.onclick = function() { return false; this.blur(); };
                document.getElementById('musiradi').disabled = 'disabled';
                document.getElementById('fotohire').disabled = 'disabled';
                document.getElementById('umts').disabled = 'disabled';
                document.getElementById('gps').disabled = 'disabled';
                document.getElementById('dvbh').disabled = 'disabled';
                document.getElementById('hsdpa').disabled = '';
                document.getElementById('bluetoot').disabled = 'disabled';
            } else {
                var allLI = ulmarca.getElementsByTagName('li');
                var totLI = allLI.length;
                for (var i = 0; i < totLI; i++) {
                    if (allLI[i].className == 'pccard' || allLI[i].className == 'telefonini pccard') {
                        allLI[i].style.display = 'inline';
                    } else if (allLI[i].className != '') {
                        allLI[i].style.display = 'none';
                    }
                }
            }
            
            break;
        case '35513':
            if (trig_marca != null && trig_prezzo != null) {
                trig_marca.style.background = bg_disabled;
                trig_prezzo.style.background = bg_disabled;
                trig_forma.style.background = bg_disabled;
                trig_forma.onclick = function() { return false; this.blur(); };
                trig_marca.onclick = function() { return false; this.blur(); };
                trig_prezzo.onclick = function() { return false; this.blur(); };
                document.getElementById('musiradi').disabled = 'disabled';
                document.getElementById('fotohire').disabled = 'disabled';
                document.getElementById('umts').disabled = 'disabled';
                document.getElementById('gps').disabled = 'disabled';
                document.getElementById('dvbh').disabled = 'disabled';
                document.getElementById('bluetoot').disabled = 'disabled';
                document.getElementById('hsdpa').disabled = 'disabled';
            }
            break;
        case '1698':
            if (trig_marca != null && trig_prezzo != null) {
                trig_marca.style.background = bg_disabled;
                trig_prezzo.style.background = bg_disabled;
                trig_forma.style.background = bg_disabled;
                trig_forma.onclick = function() { return false; this.blur(); };
                trig_marca.onclick = function() { return false; this.blur(); };
                trig_prezzo.onclick = function() { return false; this.blur(); };
                document.getElementById('musiradi').disabled = 'disabled';
                document.getElementById('fotohire').disabled = 'disabled';
                document.getElementById('umts').disabled = 'disabled';
                document.getElementById('gps').disabled = 'disabled';
                document.getElementById('dvbh').disabled = 'disabled';
                document.getElementById('bluetoot').disabled = 'disabled';
                document.getElementById('hsdpa').disabled = 'disabled';
            } else {
                var allLI = ulmarca.getElementsByTagName('li');
                var totLI = allLI.length;
                for (var i = 0; i < totLI; i++) {
                    if (allLI[i].className == 'timutils' || allLI[i].className == 'telefonini timutils') {
                        allLI[i].style.display = 'inline';
                    } else if (allLI[i].className != '') {
                        allLI[i].style.display = 'none';
                    }
                }
            }
            break;
    }
}



function checkInps(x) {
    var allInps = x.getElementsByTagName('input');
    for (var i = 0; i < allInps.length; i++) {
        if (allInps[i].value == 0) {
            allInps[i].disabled = 'disabled';
        }
    }
    if (trig_marca.onclick != trigger_onclick_bk) {
        marca.disabled = 'disabled';
    }
    if (trig_prezzo.onclick != trigger_onclick_bk) {
        prezzo.disabled = 'disabled';
    }
    if (trig_forma.onclick != trigger_onclick_bk) {
        forma.disabled = 'disabled';
    }
}