// JavaScript Document

$(function(){
// Redimencionamento do box carrossel com resolução da tela
(function($){
$.verificaLarguraTd = function(){
  var larguraTd = $("#tdMiolo").width();
  var larguraTdHome = ($("#centroHome").width()) - 20; // o 20 é a margin do div
  
  $("#listaHome").width(larguraTdHome);
  $("#carrosselHome").width(larguraTdHome);
  $("#listaHome").css("display","block");
  
  $("#listaRelacionados").width(larguraTd);
  $("#carrosselPassos").width(larguraTd);
  $("#listaRelacionados").css("display","block");
}
})(jQuery);

//chamada da funcao verificaLarguraTd no carragamento da pagina
$.verificaLarguraTd();
$(window).resize(function(){
  $.verificaLarguraTd();
});

/* var totalLi = $("#produtos li").length;
var ultimaLinha = totalLi - 5;
$("#produtos li:gt(" + ultimaLinha + ")").css("borderBottom","none"); */
});

// Abrir login
function abrirLogin() {
    $("div#janelaLoginTopo").show("fast");
}
function fecharLogin() {
    $("div#janelaLoginTopo").hide("fast");
}

//funcao para chamar o avaliacao do produto
//e necessário os arquivos ui.stars.js


function avaliacao(){
    var parametros = new Array();
    var vt;
    var http = criaHTTPObject();
    
    var dominio = document.domain;

    var programa = 'http://'+dominio+'/cgi-bin/loja.pl';
    parametros['loja'] = document.formDetalhe.loja.value;
    parametros['acao'] = 'avaliacao';
    parametros['prod_id'] = document.formDetalhe.prod_id.value;
    parametros['pedido'] = document.frmLoja.pedido.value;
    
    vt = document.getElementById('formDetalhe').getElementsByTagName('input');

	//rate é a posicão da avaliaçao selecionada, ela está com hidden
    for (i=0; i < vt.length; i++){
        if (vt[i].name == 'rate'){
            parametros['rate'] = vt[i].value;
            break;
        }
    }
    chamaProcedimentoRemoto(http,programa,parametros,'verAvaliacao','');
}

//funcao de retorno da funcao avaliacao
function verAvaliacao(retorno){
	var i,hashValores;

    if (retorno){
        hashValores = eval('({'+retorno+'})');

        if (hashValores['MSG']){
            document.getElementById('msgAvaliacao').innerHTML = hashValores['MSG'];
        }

    }else{
        document.getElementById('msgAvaliacao').innerHTML = "-";
    }
    return;
}

function SubmeteLoginAvalia() {
    var email = document.formDetalhe.emailAval.value.trim();
    var senha = document.formDetalhe.senhaAval.value.trim();

    if (email != '') {
        if (senha != '') {
            if (! ValidaEmail(email)) {
                alert('Email inválido.');
                return;
            }

            dominio = document.domain;

            window.location="http://"+dominio+"/cgi-bin/loja.pl?acao=LOGIN&pedido="+ document.formDetalhe.pedido.value + "&email=" + email + "&senha=" + senha + "&loja=" + document.formDetalhe.loja.value + "&url_redirecionar=AVALIACAO&prod_id=" + document.formDetalhe.prod_id.value + "&dep=" + document.formDetalhe.dep.value + "&secao=" + document.formDetalhe.secao.value;
            //document.formDetalhe.submit();
        } else {
            alert('Digite sua senha.');
        }
    } else {
        alert('Digite seu e-mail para login.');
    }
}

// Video
function escondeVideo(status){
	if (document.getElementById('colVideo')) {
		if (status) {
			document.getElementById('colVideo').style.display = "block";
		}
		else {
			document.getElementById('colVideo').style.display = "none";
		}
	}
}
