﻿Pneus = {
    displayBuscador: '',

    showBuscador: function () {
        E('fieldsetBuscador').style.display = Pneus.displayBuscador;
        if (Pneus.displayBuscador == '')
            Pneus.displayBuscador = 'none';
        else
            Pneus.displayBuscador = '';
    },

    fillDropModel: function (idBrand) {
        if (idBrand != 0) {
            var service = new Buscador.BuscadorService();
            E('dropModel').options.length = 1;
            E('dropVersion').options.length = 1;
            E('dropVersionYear').options.length = 1;
            service.GetModelsByBrand(idBrand, function (data) {
                var models = JSON.parse(data);
                for (var i in models) {
                    var opt = document.createElement("option");
                    opt.value = models[i].id;
                    opt.text = models[i].model;
                    E('dropModel').options.add(opt);
                }
            }, null, null);
        } else {
            E('dropModel').options.length = 1;
            E('dropVersion').options.length = 1;
            E('dropVersionYear').options.length = 1;
        }
    },

    fillDropVersion: function (idModel) {
        if (idModel != 0) {
            var service = new Buscador.BuscadorService();
            E('dropVersion').options.length = 1;
            E('dropVersionYear').options.length = 1;
            service.GetVersionsByModel(idModel, function (data) {
                var versions = JSON.parse(data);
                for (var i in versions) {
                    var opt = document.createElement("option");
                    opt.value = versions[i].version;
                    opt.text = versions[i].version;
                    E('dropVersion').options.add(opt);
                }
            }, null, null);
        } else {
            E('dropVersion').options.length = 1;
            E('dropVersionYear').options.length = 1;
        }
    },

    GetVersionsByModelAndVersion: function (version) {
        if (idModel != 0) {
            var service = new Buscador.BuscadorService();
            E('dropVersionYear').options.length = 1;
            var idModel = E('dropModel').value;
            service.GetVersionsByModelAndVersion(idModel, version, function (data) {
                var versionsYear = JSON.parse(data);
                for (var i in versionsYear) {
                    var opt = document.createElement("option");
                    opt.value = versionsYear[i].year;
                    opt.text = versionsYear[i].year;
                    E('dropVersionYear').options.add(opt);
                }
            }, null, null);
        } else {
            E('dropVersionYear').options.length = 1;
        }
    },

    PostBuscador: function () {
         //ctl00_dropBrand
        if(E('ctl00_ContentPlaceHolder1_dropBrand'))
           var marca = E('ctl00_ContentPlaceHolder1_dropBrand').options[E('ctl00_ContentPlaceHolder1_dropBrand').selectedIndex].text;
        else
           var marca = E('ctl00_dropBrand').options[E('ctl00_dropBrand').selectedIndex].text;
        var model = E('dropModel').options[E('dropModel').selectedIndex].text;
        var version = E('dropVersion').value;
        var year = E('dropVersionYear').value;
        if (marca != 'Marca' && model != 'dropModel' && version != '' && year != '0') {
           tracker('/buscar');
            window.location = '/Buscador/' + marca + '/' + model + '/' + version + '/' + year;
        }
    },

    thumb: 0,

    ChangeMedia: function (i, media) {
        E('ProductDetailThumbs' + Pneus.thumb).className = '';
        Pneus.thumb = i;
        E('ProductDetailThumbs' + Pneus.thumb).className = 'atv';
        E('ctl00_ContentPlaceHolder1_ulProductDetailMedia').src = media;
    },

    tab: 'ctl00_ContentPlaceHolder1_divProductDetailFeatures',

    ChangeTab: function (tab) {
        E('li' + Pneus.tab).className = '';
        E(Pneus.tab).style.display = 'none';
        Pneus.tab = tab;
        E('li' + Pneus.tab).className = 'atv';
        E(Pneus.tab).style.display = '';
     },

     TrackerTab : function(menu){
        tracker_event('detalhes', menu, E('ctl00_ContentPlaceHolder1_bigProductDetailModel').innerHTML);
     },
    pneuLayer : 'Rodagem',

    ChangePneuLayer: function (l) {
        E('divLayerPneu'+Pneus.pneuLayer).style.display = 'none';
        E('spanLayerPneu'+Pneus.pneuLayer).className = E('spanLayerPneu'+Pneus.pneuLayer).className.toString().replace(' atv','');
        Pneus.pneuLayer = l;
        E('divLayerPneu'+Pneus.pneuLayer).style.display = '';
        E('spanLayerPneu'+Pneus.pneuLayer).className = E('spanLayerPneu'+Pneus.pneuLayer).className.toString() + ' atv';
    }







}
