/* POE CLASSES LAST E FIRST */
$(function() {
	$('.firstLast li:last').addClass('last');
	$('.firstLast li:first').addClass('first');
	
	$('#menuDepartamento li:last').addClass('last');
})

$(function() {
	//$('#menuDepartamento li:last-child').css('background-image','none');
})

$(function(){			
	$('select#selectBusca').selectmenu({style:'dropdown', width: 142});
    //$('select#marcaId').selectmenu({style:'dropdown', width: 168});
			
	$('select#selectBusca').selectmenu({
		icons: [
			{find: '.script', icon: 'ui-icon-script'},
			{find: '.image', icon: 'ui-icon-image'}
		]
	});
});

/*$(function() {
	$(".li-main").mouseover(function(){
		$(".blocoSubmenu", this).show();
	}).mouseout(function() {
		$(".blocoSubmenu", this).hide();
	})
});*/


$(function(){	

	/* Esconde todos os conteudos das abas e exibe somente o primeiro */
	$("#conteudoAbas div[id ^='aba']").css({display: "none"});
	$("#conteudoAbas div[id ^='aba']:first").css({display: "block"});
	$("#abas li:first").addClass("on");

	/* Coloca a classe 'on' e mostra o conte�do da aba */
	$("#abas li").click(function(){
		$("#abas li").removeClass("on");
		$(this).addClass("on");
		var posicaoAbaSelecionada = $("#abas li").index(this);	
		$("#conteudoAbas div[id ^='aba']").hide().eq(posicaoAbaSelecionada).show();
	});
});

/* POE ODD E EVEN  NA TABELA DE A VISTA */
$(function(){
	$("#tabVista tr:nth-child(2n+1)").addClass('odd');
});

/* APARECE A CAIXA DE CEP PARA PRAZO DE ENTREGA */
$(function() {
	$('.linkPrazo').click(function() {
		$('#caixaCep').fadeIn();
	})		   
})

/* FECHA A CAIXA DE CEP */
$(function() {
	$('#fechaCep').click(function() {
		$('#caixaCep').fadeOut();
	})		   
})


/* ====== Site Geral - Caixa Login ======= */
$(document).ready(function(){
/*		$('#btnFecharSaudacao').click(function() {
		$('#login a').removeClass('selected');
		$('#janelaLogin').fadeOut();
		$(this).fadeOut();
	})*/
/*	$('.btnLoginAbre').toggle(
		function() {
			$(this).addClass("selected");
			$('#janelaLogin').fadeIn();
		},
  		function () {
    		$(this).removeClass("selected");
			$('#janelaLogin').fadeOut();
  		}
	)*/

$('.btnLoginAbre').toggle(
	function() {
		$('#janelaLoginGeral').fadeIn();
	},
	function() {
		$('#janelaLoginGeral').fadeOut();
	}
);

$('.fechaLogin').click(function() {
	$('#janelaLoginGeral').fadeOut();
});


$('.linkParaAvaliacao').toggle(
	function() {
		$('#janelaLoginAvalia').fadeIn();
	},
	function() {
		$('#janelaLoginAvalia').fadeOut();
	}
)

$('.fechaLogin2').click(function() {
	$('#janelaLoginAvalia').fadeOut();
});



});









//funcao para chamar o avaliacao do produto
//e necessario o arquivo 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 e a posicao da avaliacao selecionada, ela esta 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.');
    }
}


// Frase frete padrão se não tiver frete
$(function(){	
	if ($("#boxFrete span .gratuito").html() == null) {
		$("#boxFrete span.cheio").hide();
		$("#boxFrete span.semFrete").show();
	}
	else {
		$("#boxFrete span.cheio").show();
		$("#boxFrete span.semFrete").hide();
	}
	
	if ($("#boxFrete span .valorFrete:contains('R$')")) {
		$("#boxFrete span.cheio").show();
		$("#boxFrete span.semFrete").hide();
	}
	else {
		$("#boxFrete span.cheio").hide();
		$("#boxFrete span.semFrete").show();
	}
	
	if ($("#boxFrete span.cheio").html() == "") {
		$("#boxFrete span.cheio").hide();
		$("#boxFrete span.semFrete").show();
	}
	else {
		$("#boxFrete span.cheio").show();
		$("#boxFrete span.semFrete").hide();
	}
});

/* ====== Site Geral - Avise-me ======= */
function verificaCampoAviseme(campo,status){
	if (status == 0) {
		if (campo.value == campo.alt) {
			campo.value = "";
		}
	}
	else {
		if(campo.value == ""){
			campo.value = campo.alt;
		}
	}
};

function aviseme(codigo_barra,prod_id){
    var dominio = document.domain;
	var loja = document.frmLoja.loja.value;
    var email = document.getElementById('aviseProduto'+codigo_barra).value;
    var programa = 'http://'+dominio+'/cgi-bin/avisemecd.pl';
    var urlParams = 'loja='+loja;
    urlParams   += '&pedido='+ document.frmLoja.pedido.value;
    urlParams   += '&produto=' + prod_id;
    urlParams   += '&codigo_barra=' + codigo_barra;
    urlParams   += '&email=' + email;
     $.ajax({
        type:"POST",
        url:programa,
        data:urlParams,
        cache: false,
        beforeSend: function(data) {
            data.setRequestHeader('Content-length', 'urlParams.length');
        },      
        success:function(resp){
            if(resp == 'ok'){
                document.getElementById('respostaAvise'+codigo_barra).innerHTML = 'E-mail foi cadastrado com sucesso';
                document.getElementById('respostaAvise'+codigo_barra).style.color = "#7ABA1B";
                document.getElementById('respostaAvise'+codigo_barra).style.fontWeight = 'bold';
            }else{
                document.getElementById('respostaAvise'+codigo_barra).innerHTML = resp;
                document.getElementById('respostaAvise'+codigo_barra).style.color = "#CE2320";
                document.getElementById('respostaAvise'+codigo_barra).style.fontWeight = 'bold';
            }
        }
     });
}

//inclui campo informativo
function preencheSelectCampoInfo(valor){
	var campo = valor.split('|');
	var i;
	for (i=0; i < campo.length; i++){
		$("#campo_informativo").append("<option value='" + campo[i] + "'>" + campo[i] + "</option>");
	}
}

$(document).ready(function() {
	$('div[id*="btnExcCar_"] input[value="cancelar"]').click(function() {
		$(this).parent().fadeOut();
	});
	
	$('body').click(function() {
		$('div[id*="btnExcCar_"]').hide();
	});
	
	if ($('#IDFrmLoja input[name="qtd"]').val() == '') {
		$('#IDFrmLoja input[name="qtd"]').val('1');
	}
});


/* Função para hora dinamica */
function UR_Start() 
{
	UR_Nu = new Date;
	UR_Indhold = showFilled(UR_Nu.getHours()) + ":" + showFilled(UR_Nu.getMinutes()) + ":" + showFilled(UR_Nu.getSeconds());
	document.getElementById("ur").innerHTML = UR_Indhold;
	setTimeout("UR_Start()",1000);
}
function showFilled(Value) 
{
	return (Value > 9) ? "" + Value : "0" + Value;
}


//======================================================================================================================

// Funcao do cabecalho, onde tem a data

//======================================================================================================================

function upclock(){

	var hoje   = new Date();

	var hrs = hoje.getHours();

	var min = hoje.getMinutes();

	var sec = hoje.getSeconds();

	var col = ":";

	var spc = " ";

	var barra = "/";

	var tco = "-";

	var meses  = new Array("01","02","03","04","05","06","07","08","09","10","11","12");

	var nomeMes = new Array("01","02","03","04","05","06","07","08","09","10","11","12");

	var diadasemana = new Array("Domingo","Segunda-Feira","Ter?a-Feira","Quarta-Feira","Quinta-Feira","Sexta-Feira","S?bado");

	var mes    = meses[hoje.getMonth()];

	var ano    = (hoje.getYear() + 0);

	if (ano < 1000)ano += 1900;

	var semana = diadasemana[hoje.getDay()];

	var dia    = hoje.getDate();

	//if (hrs  <= "23") var daytime = "Boa noite";

	//if (hrs  <= "18") var daytime = "Boa tarde";

	//if (hrs  <= "12") var daytime = "Bom dia";

	if (min   <= "9")  min = "0"+min;

	if (dia   <= "9")  dia = "0"+dia;

	if (sec   <= "9")  sec = "0"+sec;

	var mesExp;

	for (x=0;x<=meses.length;x++){

		if(mes==meses[x]){

			mesExp = nomeMes[x];

		}

	}





	document.getElementById('data_hora').innerHTML = "Dia: "+dia+barra+mesExp+barra+ano+spc+ "\<span\>Hora:" +spc+hrs+col+min+col+sec+ "\<\/span\>";

}



