﻿//CORES E TAMANHOS 3.0

//Cores
Cor = function(self) {
    iniciaTamanhos();
    self.onmouseover = function () {
        if (self.className != 'selecionado') {
            self.className = 'over';
        }
    }
    self.onmouseout = function () {
        if (self.className != 'selecionado') {
            self.className = '';
        }
    }
    self.onclick = function () {
        if (self.className != 'selecionado') {
            deselecionaCores();
            iniciaTamanhos();
            self.className = 'selecionado';
        }
    }
    function deselecionaCores() {
        for (j=0; j<cores.length; j++) {
            cores[j].className='';
        }
    }
    function iniciaTamanhos() {
        mon = self.id.replace("c-","")
        tam = document.getElementById("t"+mon);
        for (f=0; f<tam.childNodes.length; f++) {
            if (tam.childNodes[f].id!="nmTam") {
                Tamanho(tam.childNodes[f]);
                tam.childNodes[f].className='';
            }
        }
    } 
}

//Tamanhos
Tamanho = function(self) {
    self.onmouseover = function () {
        if (self.className != 'selecionado') {
            self.className = 'over';
        }
    }
    self.onmouseout = function () {
        if (self.className != 'selecionado') {
            self.className = '';
        }
    }
    self.onclick = function () {
        if (self.className != 'selecionado') {
            deselecionaTamanhos();
            self.className = 'selecionado';
        }
    }
    function deselecionaTamanhos() {
        lista = self.parentNode;
        for (g=0; g<lista.childNodes.length; g++) {
            lista.childNodes[g].className='';
        }
    }
}

//Inicia o estoque
iniciaEstoque = function () {
    est = document.getElementById("estoque");
    cores = est.childNodes;
    for (i=0; i<cores.length; i++) {
        if (cores[i].tagName == "LI") {
            if (cores[i].id != "nmCor") {
                Cor(cores[i]);
            }
        }
    }
}

//Coloca o produto no carrinho de compras
comprarProduto = function (produto) {
    est = document.getElementById("estoque");
    quant = document.getElementById("txtqtd");
    cores = est.childNodes;
    boolCor = false;
    boolTamanho = false;
    for (i=0; i<cores.length; i++) {
        if (cores[i].className == "selecionado") {
            boolCor = true;
            corSelecionada = cores[i].id.replace("c-","");      
            tam = document.getElementById("t"+corSelecionada);
            for (f=0; f<tam.childNodes.length; f++) {
                if (tam.childNodes[f].className == "selecionado") {
                    boolTamanho = true;
                    tamanhoSelecionado = tam.childNodes[f].id.split("-");
                    tamanhoSelecionado = tamanhoSelecionado[2];
                }
            }
        }
    }
    if (!boolCor) {
        alert("Selecione uma cor.");
    }else {
        if (!boolTamanho) {
            alert("Selecione um tamanho.")
        }else {
            document.location="detalhe.aspx?comprando=" + quant.value + "&produto=" + produto + "&cId=" + corSelecionada + "&tId=" + tamanhoSelecionado;
            return;
        }
    }
}

function MandaCompra(produto, comando) {
quant = document.getElementById("txtqtd");
document.location="compra.aspx?comando=" + comando + "&acao=0&intprodID=" + produto +  "&intQuant=" + quant.value + "&estoque=0";
return;





}
