$(document).ready(function(){
$(function() {
	//$("#mini a").click(function() {
		// $("#mini a").addClass("off");
		// $("#mini a").removeClass("on");
		// $(this).addClass("on");
		// $(this).removeClass("off");
	//});
	
	$("#listaCores a").click(function() {
		$("#listaCores a").removeClass("on");
		$(this).addClass("on");
	});
	
	$("#tabsOpt a").click(function() {
		$("#tabsOpt a").removeClass("on");
		$(this).addClass("on");	
	});
	$("#tabsOpt a#tab1").click(function() {
		$("#abasProd #aba2").hide();
		$("#abasProd #aba1").show();
    });
    $("#tabsOpt a#tab2").click(function() {
		$("#abasProd #aba1").hide();
		$("#abasProd #aba2").show();
    });
	
});

});





$(function() {
	var options =
	{
		zoomWidth: 280,
		zoomHeight: 381
	};
	$(".jqzoom").jqzoom(options); 
//	$(".jqzoom").jqzoom();
});



/* usado na troca de fotos media e alta para o div de zoom do produto */
function trocarZoom(vaPosicao, vaAlta, vaBaixa) {

    // trocar a foto de alta.
    document.getElementById('imageviewerlink').href = vaAlta;
    // trocar a foto de media.
    document.getElementById('imageviewerfoto').src = vaBaixa;

    if (null != document.getElementById('fmtz1'))
        document.getElementById('fmtz1').className = "off";

    if (null != document.getElementById('fmtz2'))
        document.getElementById('fmtz2').className = "off";

    if (null != document.getElementById('fmtz3'))
        document.getElementById('fmtz3').className = "off";

    if (null != document.getElementById('fmtz4'))
        document.getElementById('fmtz4').className = "off";
        
    document.getElementById('fmtz' + vaPosicao).className = "on";
}



/* usado quando clico na foto da cor */
function trocarCor(vaProduto, vaCor, vaCorNome) {

    // chamar o ajax para recuperar os dados.
    wsLoadData('zoom','GET','/ws/wsProdutos.asmx/zoomLista?idCor='+vaCor+'&idProduto='+vaProduto);

    // campo hidden com a nova cor.
    document.getElementById('ctl00_ContentPlaceHolder1_wucProdutoDetalhe1_hfIdCor').value = vaCor;

    // nome da cor.
    document.getElementById('divCorNome').innerHTML = '<p><strong>Cor: </strong>' + vaCorNome + '</p>';

}


/* a volta da chamada ajax */
function trocarCorVolta(dados) {

    // alert(dados);

    var novoArray = dados.split("##__##");
    document.getElementById('loadImg').innerHTML = novoArray[0];
    document.getElementById('mini').innerHTML = novoArray[1];

    var options =
	{
	    zoomWidth: 280,
	    zoomHeight: 381
	};
    $(".jqzoom").jqzoom(options);


    // chamar o ajax para recuperar os dados da combo de tamanhos.
    var vaCor = document.getElementById('ctl00_ContentPlaceHolder1_wucProdutoDetalhe1_hfIdCor').value;
    var vaProduto = document.getElementById('ctl00_ContentPlaceHolder1_wucProdutoDetalhe1_hfIdProduto').value;

    // trocar a combo de tamanhos.
    wsLoadData('tamanho', 'GET', '/ws/wsProdutos.asmx/tamanhos?idCor=' + vaCor + '&idProduto=' + vaProduto);
    // trocar o combina cor.    
    // wsLoadData('combina', 'GET', '/ws/wsProdutos.asmx/combinaCom?idCor=' + vaCor + '&idProduto=' + vaProduto);

}


/* a volta da chamada ajax */
function tamanhoVolta(dados) {

    // alert(dados);

    // controle da tela com o combo box de tamanhos.
    var vlElemento = document.getElementById('ctl00_ContentPlaceHolder1_wucProdutoDetalhe1_ddTamanho');

    // limpar a combo.
    vlElemento.options.length = 0;

    var intLoop;
    var strArrRow = new Array();
    strArrRow = dados.split('#');
    var umTamanho = new Array();

    // antes de inserir os tamanhos verificar e inserir a opção "selecione".
    // se tiver mais de 1 item na combo de tamanho, colocar a opção chamada "selecione".
    if (strArrRow.length > 1) {
        var novoitem = document.createElement('option');
        novoitem.text = 'Selecione';
        try {
            vlElemento.add(novoitem, null);
        }
        catch (ex) {
            vlElemento.add(novoitem);
        }
    }
    
    for (intLoop = 0; intLoop < strArrRow.length - 1; intLoop++) {

        umTamanho = strArrRow[intLoop].split(';');
        var y = document.createElement('option');
        y.value = umTamanho[0];
        y.text = umTamanho[1];

        try {
            vlElemento.add(y, null);
        }
        catch (ex) {
            vlElemento.add(y);
        }
    }

    // colocar no campo hidden o novo valor da combo.
    comboParaHiddenTamanho();

    // chamar o ajax para recuperar os dados do ComibaCom
    var vaCor = document.getElementById('ctl00_ContentPlaceHolder1_wucProdutoDetalhe1_hfIdCor').value;
    var vaProduto = document.getElementById('ctl00_ContentPlaceHolder1_wucProdutoDetalhe1_hfIdProduto').value;
    // trocar o combina cor.    
    wsLoadData('combina', 'GET', '/ws/wsProdutos.asmx/combinaCom?idCor=' + vaCor + '&idProduto=' + vaProduto);
    
}


/* a volta da chamada ajax */
function combinaComVolta(dados) {

    // alert(dados);

    // controle da tela com o conteudo da combinação.
    var vlElemento = document.getElementById('ctl00_ContentPlaceHolder1_wucProdutoCombinacaoSugerida1_pnlCombinacao');

    // verificar se não recebemos conteudo?
    if (dados == '0') {
        document.getElementById('ulCombinaCom').innerHTML = '';
        vlElemento.style.display = "none";
    }
    else {
        document.getElementById('ulCombinaCom').innerHTML = dados;
        vlElemento.style.display = "block";
    }

}






/* colocar no campo hidden o valor selecionado na combo de tamanho*/
function comboParaHiddenTamanho() {

    var combo = document.getElementById('ctl00_ContentPlaceHolder1_wucProdutoDetalhe1_ddTamanho');
    var cmpEscondido = document.getElementById('ctl00_ContentPlaceHolder1_wucProdutoDetalhe1_hfIdTamanho');
    cmpEscondido.value = combo.options[combo.selectedIndex].value;
    
}


/* testar se a combo de tamanho foi selecionada antes de incluir na sacola */
function testarTamanho() {

    var combo = document.getElementById('ctl00_ContentPlaceHolder1_wucProdutoDetalhe1_ddTamanho');
    // alert(combo.options[combo.selectedIndex].value);

    if (combo.options[combo.selectedIndex].value == '') {
        alert('Selecione um tamanho para o produto.');
        combo.focus();
        return false;
    }
    return true;
}



/* usado para inserir o produto na sacola */
function incluirSacola() {

    // validar se tamanho foi escolhido ?
    if (testarTamanho()) {

        var vlIdProduto = document.getElementById('ctl00_ContentPlaceHolder1_wucProdutoDetalhe1_hfIdProduto').value;
        var vlIdCor = document.getElementById('ctl00_ContentPlaceHolder1_wucProdutoDetalhe1_hfIdCor').value;
        var vlPreco_BR = document.getElementById('ctl00_ContentPlaceHolder1_wucProdutoDetalhe1_hfPreco_BR').value;
        var vlPreco_RJ = document.getElementById('ctl00_ContentPlaceHolder1_wucProdutoDetalhe1_hfPreco_RJ').value;
        var vlIdTamanho = document.getElementById('ctl00_ContentPlaceHolder1_wucProdutoDetalhe1_hfIdTamanho').value;

        // chamar o ajax para recuperar os dados.
        wsLoadData('sacola', 'GET', '/ws/wsProdutos.asmx/incluirSacola?idCor=' + vlIdCor + '&idProduto=' + vlIdProduto + '&idTamanho=' + vlIdTamanho + '&preco_BR=' + vlPreco_BR + '&preco_RJ=' + vlPreco_RJ);
        return true;
    }
    return false;

}


/* a volta da chamada ajax */
function incluirSacolaVolta(dados) {

    // alert(dados);
    var novoArray = dados.split("##__##");

    // var controleMsg = document.getElementById('divProdMsg');
    // controleMsg.style.display = "none";

    var controleInd = document.getElementById('prodIndisp');
    controleInd.style.display = "none";

    var spanmsg = document.getElementById('ctl00_ContentPlaceHolder1_wucProdutoDetalhe1_lblSacola');
    if (spanmsg != null)
        spanmsg.style.display = "none";
        

    // exibir caixa de mensagem.
    if (novoArray[0] == '1' || novoArray[0] == '3') {
        // controleMsg.style.display = "block";
        // controleMsg.innerHTML = novoArray[1];
        // alert(novoArray[1]);
        }

    // exibir caixa de produto indisponivel.
    if (novoArray[0] == '2') {
        controleInd.style.display = "block";
    }
}




/* abre o pop-up de medidas. */
function abreMedidas(vaIdProduto) {

    var vlIdProduto = document.getElementById('ctl00_ContentPlaceHolder1_wucProdutoDetalhe1_hfIdProduto').value;
    window.open('/medidas.aspx?p=' + vlIdProduto, '', 'width=730,height=600,top=100,left=100');

}




function testarTam() {
    // alert('hahah');
    
    if (confirm('deseja realmente fazer ?'))
        return true
    else
        return false
        
}

