// JavaScript Document

	// Função única que fará a transação
function getEndereco() {
			// Se o campo CEP não estiver vazio
			if($.trim($("#cep").val()) != ""){
				$.getScript("http://cep.republicavirtual.com.br/web_cep.php?formato=javascript&cep="+$("#cep").val(), function(){
					// o getScript dá um eval no script, então é só ler!
					//Se o resultado for igual a 1
			  		if(resultadoCEP["resultado"]){
						// troca o valor dos elementos
						$("#endereco").val(unescape(resultadoCEP["tipo_logradouro"])+": "+unescape(resultadoCEP["logradouro"]));
						$("#bairro").val(unescape(resultadoCEP["bairro"]));
						$("#cidade").val(unescape(resultadoCEP["cidade"]));
						$("#uf").val(unescape(resultadoCEP["uf"]));
					}else{
						alert("Endereço não encontrado");
					}
				});
			}
	}


function getEndereco_com() {
			// Se o campo CEP não estiver vazio
			if($.trim($("#cep_com").val()) != ""){
				$.getScript("http://cep.republicavirtual.com.br/web_cep.php?formato=javascript&cep="+$("#cep_com").val(), function(){
					// o getScript dá um eval no script, então é só ler!
					//Se o resultado for igual a 1
			  		if(resultadoCEP["resultado"]){
						// troca o valor dos elementos
						$("#endereco_com").val(unescape(resultadoCEP["tipo_logradouro"])+": "+unescape(resultadoCEP["logradouro"]));
						$("#bairro_com").val(unescape(resultadoCEP["bairro"]));
						$("#cidade_com").val(unescape(resultadoCEP["cidade"]));
						$("#estado_com").val(unescape(resultadoCEP["uf"]));
					}else{
						alert("Endereço não encontrado");
					}
				});
			}
	}


//function submitform1()
//{
//	$.ajax({ // create an AJAX call...		
//	    url: "newsletter.php",
//	    type: "POST",
//	    data: $("#form1").serialize(),
//		success: function(response) { // on success..
//			//alert ('sucesso');
//			$('#principal').html(response); // update the DIV
//		},
//	    error: function(){
//			alert('erro');
//		}
//	});
//  
//}
//
//
//
//function submitform2()
//{
////  document.form2.submit();
//		$.ajax({ // create an AJAX call...
//	    url: "listagem_tipo_leiloes.html",
//	    type: "POST",
//	    data: $("#form2").serialize(),
//		success: function(response) { // on success..
//			//alert ('sucesso');
//			$('#principal').html(response); // update the DIV
//		},
//	    error: function(){
//			alert('erro');
//		}
//	});
//}

function EnviaCadastro_pf() {

	var retorno = CheckForm(document.cadastro_pf);

	if (retorno) {
		$.ajax({ // create an AJAX call...
			url: "cadastro_1.php",
			type: "POST",
			data: $("#cadastro_pf").serialize(),
			success: function(response) { // on success..
				//alert ('sucesso');
				$('#conteudo').html(response); // update the DIV
			},
			error: function(){
				alert('erro');
			}
		});
	}	
}

function EnviaCadastro_pj() {
	var retorno = CheckForm(document.cadastro_pj);
	alert (retorno);
	if (retorno) {
		$.ajax({ // create an AJAX call...
			//url: "cadastro_1falso.php",
			url: "cadastro_1.php",
			type: "POST",
			data: $("#cadastro_pj").serialize(),
			success: function(response) { // on success..
				//alert ('sucesso');
				$('#conteudo').html(response); // update the DIV
			},
			error: function(){
				alert('erro');
			}
		});
	}
}




function abre(){
document.getElementById('transparente').style.visibility = 'visible';	
$('#caixa_login').load('caixa_login.html');
document.getElementById('caixa_login').style.display = 'block';
document.getElementById('caixa_login').style.left = ( screen.width - 768 ) / 2+"px";
document.getElementById('caixa_login').style.top = ( screen.height - 768 ) / 2+"px";
}
function fecha(){
	
if ((document.form_login.login.value == '') || (document.form_login.senha.value == '')) {
	alert('Precisa preencher os campos');
}
else {
	document.form_login.submit();
	document.getElementById('caixa_login').style.display = 'none';
	document.getElementById('transparente').style.visibility = 'hidden';
}
}

function fecha2(){
	
	document.getElementById('caixa_login').style.display = 'none';
	document.getElementById('transparente').style.visibility = 'hidden';
}


function CheckForm(Obj){

//alert(Obj.pagina[0].checked);
//alert(Obj.pagina[1].checked);

	if (Obj.aceito.checked == false){
		alert('É necessário aceitar os termos do cadastro');
		Obj.aceito.focus();
		return false;
	}
	if ((Obj.pagina[0].checked == false) && (Obj.pagina[1].checked == false)){
		alert("Escolha o tipo de cadastro: físico ou jurídico");
		Obj.pagina[0].focus();
		return false;
	}

	if (Obj.pagina[0].checked == true) {
		requisicao('cadastro_pf.html');
	}
	else {
		requisicao('cadastro_pj.html');
	}
}


function theRotator() {
	//Set the opacity of all images to 0
	$('div.rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div.rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	
	setInterval('rotate()',6000);
	
}

function rotate() {	
	//Get the first image
	var current = ($('div.rotator ul li.show')?  $('div.rotator ul li.show') : $('div.rotator ul li:first'));
	var current2 = current;

    if ( current.length == 0 ) current = $('div.rotator ul li:first');

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.rotator ul li:first') :current.next()) : $('div.rotator ul li:first'));
	
	//Un-comment the 3 lines below to get the images in random order
	
	//var sibs = current.siblings();
    //var rndNum = Math.floor(Math.random() * sibs.length );
    //var next = $( sibs[ rndNum ] );
			

	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);


	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');

	
};



$(document).ready(function() {		
	//Load the slideshow
	theRotator();
	$('div.rotator').fadeIn(1000);
    $('div.rotator ul li').fadeIn(1000); // tweek for IE

});
