/*

	funções globais Javascript
 	Criado por Davi Ferreira
	Última modificação 25/08/2007

*/

// timer para o timeout do javascript
var msgTimer = '';

// função simples para exibir resposta de erro ou confirmação
var msgTopo = function(txt,classe,tempo) {
	// limpa timeout
	clearTimeout(msgTimer);
	// exibe msg
	if (classe == 'erro') {
		$('#msg-topo').removeClass('msg');
	} else {
		$('#msg-topo').removeClass('erro');
	}
	$('#msg-topo').addClass(classe);
	$('#msg-topo').html('<ul>'+txt+'</ul>');
	$('#msg-topo').slideDown();
	msgTimer = setTimeout("$('#msg-topo').slideUp();", tempo);
}; // fim msgTopo


/*

	E-COMMERCE

*/

  function AdicionarProdutoCarrinho(id) {
     xajax_AdicionarProdutoCarrinho(id,1,'_en');
  }

  function AumentarProdutoCarrinho(id) {
     xajax_AumentarProdutoCarrinho(id);
  }

  function DiminuirProdutoCarrinho(id) {
     xajax_DiminuirProdutoCarrinho(id);
  }

  function CalcularFrete(id) {
     xajax_CalcularFretePorCep( xajax.getFormValues('f_frete',true) ,'_en');
  }

  function CalculaFreteInter(vlr) {
	xajax_CalculaFreteInter(vlr);
  }


  function PreCadastro() {
     xajax_PreCadastro(xajax.getFormValues('f_nao_cadastrado',true),'_en');
  }

  function FinalizarPedido() {
  	//criar validação no campo CEP se está diferente de nulo. Assim impede a finalização do pedido sem cep digitado. Com isso, não terá risco de finalizar o pedido com o mesmo valor da sessão anterior.

     xajax_FinalizarPedido('_en');
  }

  function FinalizarPedidoFinal(forma_pgto, avista) {
	 $('#OptFormaPag').val(forma_pgto);
	 var parcelas = true;
	 if (avista != 1) {
		 parcelas = false;
		$('.forma-pagamento').each(function(){
			if ($(this).is(':checked')) {
				parcelas = true;
			}
		});
	 }

	 if (!parcelas) {
		 msgTopo('<li>Select a spread payment option.</li>', 'erro', 5000);
		 //return false;
	 } else {
	 	xajax_FinalizarPedidoFinal( xajax.getFormValues('FrmFinalizar',true) ,'_en');
	 }

  }

  function EsqueciSenha() {
     xajax_EsqueciSenha(xajax.getFormValues('f_cadastrado',true),'_en');
  }

  function EfetuarLogin() {
    xajax_Login(xajax.getFormValues('f_cadastrado',true),'_en');
  }

  function DesmarcarTodos(formulario) {
	Qnt = document.getElementById(formulario).elements.length;

    for (var i=0; i<Qnt; i++) {
		document.getElementById(formulario).elements[i].checked = false;
	}
  }

  function ExibirLancamentos() {
     obj1 = document.getElementById('CmbLancamento');

	 if(obj1.value != '') {
	    window.location.href = './index.php?lang=_en&idcolecao=1&data_lancamento=' + obj1.value ;
	 }
  }

  function trocaPais(idPais){
  	if(idPais == '76'){
  		$("#CmbEstado").attr("disabled","");
  		$("#CmbCidade").attr("disabled","");
  		$("#label_cep").html("*CEP:");
  	}else{
  		$("#CmbEstado").attr("disabled","disabled");
  		$("#CmbCidade").attr("disabled","disabled");
  		$("#label_cep").html("*ZIP Code:");
  	}
  }

// timer para o timeout do javascript
var msgTimer = '';

  // função simples para exibir resposta de erro ou confirmação
var msgTopo = function(txt,classe,tempo) {
	// limpa timeout
	clearTimeout(msgTimer);
	// exibe msg
	if (classe == 'erro') {
		$('#msg-topo').removeClass('msg');
	} else {
		$('#msg-topo').removeClass('erro');
	}
	$('#overlay').show();
	$('#msg-topo').addClass(classe);
	$('#msg-topo').html('<ul>'+txt+'</ul><p style="text-align: center; padding-top: 7px"><a href="javascript:;" onclick="hideMsgTopo();" style="color:#000">clique para fechar</a></p>');
	$('#msg-topo').slideDown();
	msgTimer = setTimeout("$('#msg-topo').slideUp();$('#overlay').hide();", tempo);
}; // fim msgTopo

var hideMsgTopo = function() {
	clearTimeout(msgTimer);
	$('#overlay').hide();
	$('#msg-topo').hide();
};

var buscaCep = function() {
	if ($(this).val().length > 8) {
		xajax_BuscaCepAjax($(this).val(),'_en');
	}
};
