$(document).ready(function(){
})

/*
.produtos li:hover{
	background:#1d363e;
	color:#fff;
}
*/

function trocar_categoria(id,arquivo){
	$('#carregando').fadeIn();
	$('.produtos li').css('background','none');
	$('.produtos li').css('color','#666');	
	$('.produtos li a').css('background','none');
	$('.produtos li a').css('color','#666');	
	$('.link_'+id).css('background','#1d363e');
	$('.link_'+id).css('color','#fff');
	$.ajax({
		url: arquivo, 
		dataType: 'html',
		data: {id : id},
		type: 'POST',
		success: function(data, textStatus) {
			$('#colunaDireita').html(data);
		},
		error: function(xhr,er) {
			$('#colunaDireita').html('<p>Error ' + xhr.status + ' - ' + xhr.statusText + '<br />Tipo de erro: ' + er +'</p>'+'<a href="javascript:fechar(\'#resposta\');" title="Fechar"><img src="img/fechar.gif" alt="Fechar" border="0" id="fechar"></a>');
			$('#colunaDireita').fadeIn();
		},
		complete: function(){
			$('#carregando').fadeOut();
		}
	});
}

function acrescentar(tipo,pesquisa,quantidade,arquivo,categoria){
	$('#carregando').fadeIn();
	$.ajax({
		url: arquivo, 
		dataType: 'html',
		data: {tipo : tipo , like : pesquisa, quantidade : quantidade, id : categoria},
		type: 'POST',
		success: function(data, textStatus) {
			$('#carregando').fadeOut();
			$('#colunaDireita').html(data);
		},
		error: function(xhr,er) {
			$('#colunaDireita').html('<p>Error ' + xhr.status + ' - ' + xhr.statusText + '<br />Tipo de erro: ' + er +'</p>'+'<a href="javascript:fechar(\'#resposta\');" title="Fechar"><img src="img/fechar.gif" alt="Fechar" border="0" id="fechar"></a>');
			$('#colunaDireita').fadeIn();
		},
		complete: function(){
		}
	});
}

function procurar(campo,arquivo){
	var valor = $('#'+campo).val();
	if(valor.length==0 || valor.length < 3){
		$('#receber_pesquisa_produtos').hide();
	}else{
		$.ajax({
			url: arquivo, 
			dataType: 'html',
			data: {valor : valor},
			type: 'POST',
			success: function(data, textStatus) {
				$('#receber_pesquisa_produtos').html(data);
			},
			error: function(xhr,er) {
				$('#colunaDireita').html('<p>Error ' + xhr.status + ' - ' + xhr.statusText + '<br />Tipo de erro: ' + er +'</p>'+'<a href="javascript:fechar(\'#resposta\');" title="Fechar"><img src="img/fechar.gif" alt="Fechar" border="0" id="fechar"></a>');
				$('#colunaDireita').fadeIn();
			},
			complete: function(){
				$('#receber_pesquisa_produtos').css('display','block');
			}
		});
	}
}

function pesquisar(campo,redirecionamento){
	var valor = $('#'+campo).val();
	window.location = redirecionamento+'produtos/procurar/'+valor;
}

function carrinho(arquivo,id){
	$.ajax({
		url: arquivo, 
		dataType: 'html',
		data: {id : id},
		type: 'POST',
		success: function(data, textStatus) {
			$('#receber_carrinho').html(data);
			window.location = '/carrinho.html';
		},
		error: function(xhr,er) {
			$('#colunaDireita').html('<p>Error ' + xhr.status + ' - ' + xhr.statusText + '<br />Tipo de erro: ' + er +'</p>'+'<a href="javascript:fechar(\'#resposta\');" title="Fechar"><img src="img/fechar.gif" alt="Fechar" border="0" id="fechar"></a>');
			$('#colunaDireita').fadeIn();
		},
		complete: function(){
			$('#receber_carrinho').css('display','block');
		}
	});
}

function enviar_carrinho(arquivo,form){
	$('#versao_carrinho').hide();//receber_carrinho
	var serializeDados = $('#'+form).serializeArray();
	$.ajax({
		url: arquivo, 
		dataType: 'html',
		data: serializeDados,
		type: 'POST',
		success: function(data, textStatus) {
			$('#receber_carrinho').html(data);//receber_carrinho
			$('#receber_carrinho').show();//receber_carrinho
		},
		error: function(xhr,er) {
			$('#receber_'+div).html('<p>Error ' + xhr.status + ' - ' + xhr.statusText + '<br />Tipo de erro: ' + er +'</p>'+'<a href="javascript:fechar(\'#resposta\');" title="Fechar"><img src="img/fechar.gif" alt="Fechar" border="0" id="fechar"></a>');
			$('#receber_'+div).fadeIn();
		},
		complete: function(){
			$('#botao_'+div).attr('value',escrito_no_botao);
			if(arquivo=='menu/02002_incluir_post.php' || arquivo=='usuario/03002_post_incluir.php'){
				$('#menu .conteudo').load('inc/menu.php');
			}
		}
	});//*/

}

function post(arquivo,form){
	$('#recebe_resposta').html('<img src="img/load.gif" border="0" id="facebook">');
	$('#resposta').show();
	var escrito_no_botao = $('#enviar').attr('value');
	$('#enviar').attr('value','Enviando...');
	var serializeDados = $('#'+form).serializeArray();
	$.ajax({
		url: arquivo, 
		dataType: 'html',
		data: serializeDados,
		type: 'POST',
		success: function(data, textStatus) {
			var retorno = data.split('|',2);
			if(retorno[0].length >=  1){
				if(retorno[0]=='I'){
					$('#'+form)[0].reset();
					$('#resposta').hide();
					$('#recebe_resposta').html(retorno[1]);
				}else{
					if(form=='formulario_contato'){
						alert(retorno[1]);
						$('#resposta').hide();
						$('#recebe_resposta').hide();
					}else{
						$('#recebe_resposta').html(retorno[1]);
					}
				}
			}
		},
		error: function(xhr,er) {
			$('#receber_'+div).html('<p>Error ' + xhr.status + ' - ' + xhr.statusText + '<br />Tipo de erro: ' + er +'</p>'+'<a href="javascript:fechar(\'#resposta\');" title="Fechar"><img src="img/fechar.gif" alt="Fechar" border="0" id="fechar"></a>');
			$('#receber_'+div).fadeIn();
		},
		complete: function(){
			$('#resposta').show();
			$('#enviar').attr('value',escrito_no_botao);
		}
	});//*/
};

function abrir(div){
	$('#'+div).toggle()
}

function enviar_resposta(arquivo,form){
	if (confirm("Certeza que deseja atualizar essa cotacao?")){  

	$('#recebe_resposta').html('<img src="img/load.gif" border="0" id="facebook">');
	//$('#resposta').show();
	var escrito_no_botao = $('#enviar').attr('value');
	$('#enviar').attr('value','Enviando...');
	var serializeDados = $('#'+form).serializeArray();
	$.ajax({
		url: arquivo, 
		dataType: 'html',
		data: serializeDados,
		type: 'POST',
		success: function(data, textStatus) {
			var mensagem = ($('#mensagens').html());
			var retorno = data.split('|',2);
			if(retorno[0].length >=  1){
				if(retorno[0]=='I'){
					$('#'+form)[0].reset();
					$('#recebe_resposta').html('');
					$('#mensagens').html('<div class="linha">'+retorno[1]+'</div>'+mensagem);
				}else{
					$('#recebe_resposta').html(retorno[1]);
					$('#recebe_resposta').show();
				}
			}
		},
		error: function(xhr,er) {
			$('#receber_'+div).html('<p>Error ' + xhr.status + ' - ' + xhr.statusText + '<br />Tipo de erro: ' + er +'</p>'+'<a href="javascript:fechar(\'#resposta\');" title="Fechar"><img src="img/fechar.gif" alt="Fechar" border="0" id="fechar"></a>');
			$('#receber_'+div).fadeIn();
		},
		complete: function(){
			//$('#resposta').show();
			//$('#recebe_resposta').fadeOut();
			$('#enviar').attr('value',escrito_no_botao);
		}
	});//*/

	}
}

function atualizar_cotacao(arquivo,valor,id){
	/*alert(arquivo);
	alert(valor);
	alert(id);*/
	//$('#listar').html('<p><strong>Não há produto no carrinho. <a href="produtos/">Clique aqui para cotar</a></strong></p>');
	$.ajax({
		url: arquivo, 
		dataType: 'html',
		data: {valor:valor,id:id},
		type: 'POST',
		success: function(data, textStatus) {
			//$('#listar').html(data);
		},
		error: function(xhr,er) {
		},
		complete: function(){
			///$('#listar').html('');
			window.location = "dados-cadastrais.html"
		}
	});//*/	
}
