//powered by webfix solucoes virtuais 

// -> not for kiddies (:

$(document).ready(function() {
	$('#copAcima').click(copiaAe)
	$('#frmInsc').click(SubmitAe)
   	$('#dv_Treinamentos')
	.cycle({ 
		fx:     'turnDown', 
		speed:  'slow',
		timeout: 5000
	});

	$('#s4').after('<div id="nav">')
	.cycle({ 
		fx:     'fade', 
		speed:  'slow',
		timeout: 5000, 
		pager:  '#nav' 
	});
	$("a[rel^='lightbox']").slimbox({/* customizar.. */}, null, function(el) {
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	});
	var b = $('#hidPagina').val();
	if (b == '') {
		$('#mycarousel').jcarousel({
			auto: 2,
			wrap: 'last',
			initCallback: mycarousel_initCallback
		});
	}
	try {
		xPgto();		
		$("#tabs").tabs();
	
	//	$("#cpfcnpj").mask("999.999.999-99");
		$("#cep").mask("99.999-999");
		$("#cep2").mask("99.999-999");
		$("#contato_telefone").mask("(99) 9999-9999");
	}
	catch(ex) {
		// fezes
	}

});
var retorno;
var mpg_popup;
window.name="loja";
function fabrewin()	{
	mpg_popup = window.open("", "mpg_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,screenX=0,screenY=0,left=0,top=0,width=800,height=600");
//	window.location="redirecionaCBP.php";
	return false;
}
function xcep() {
//	alert('cep');
	cep = $('#cep').val();
		$.ajax(
			{
				type: "POST",
				url: "buscacep.php",
				data: "cep=" + cep,
	
				beforeSend: function() {
					$('#pesquisaCep').html('Buscando...');
				},
				success: function(txt) {
					$('#pesquisaCep').html('&nbsp;');
					var quebra = txt.split("@")
					$('#uf').val(quebra[3].toUpperCase());
					$('#cidade').val(quebra[2]);
					$('#bairro').val(quebra[1]);
					$('#rua').val(quebra[0]);
				},
				error: function(txt) {
					alert('erro ao buscar o cep');
				}
			}
		);
	return false;
}

function SubmitAe() {
	$('#btnProsseguir').disabled = true;
}
function copiaAe() {
	$('#cep2').val($('#cep').val());
	$('#uf2').val($('#uf').val());
	$('#cidade2').val($('#cidade').val());
	$('#bairro2').val($('#bairro').val());
	$('#rua2').val($('#rua').val());
	$('#num2').val($('#num').val());
	$('#complemento2').val($('#complemento').val());
}
function mycarousel_initCallback(carousel) {
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function MeMostra(q)  {
	$('.resCli').hide('fast');
	$('#'+q).show('slow');
}
function confirmar(label,url) {
	var pergunta = confirm(label)
	if (pergunta) { window.location = url; }
}

function xPessoa() {
	var b = $('#pessoa').val()
	if (b == "F") { $('#aPessoa').html('Nome'); $('#dPessoa').html('CPF'); }
	else { $('#aPessoa').html('Razão Social'); $('#dPessoa').html('CNPJ'); }
}
function xPgto() {
	var ParcelaVisa = $("input[name='visaParcela']:checked").val();

	var tipo = $('input[name=rdoTipo]:checked').val();
	
	var formaBoleto = $('input[name=rdoFormaBoleto]:checked').val();	
	var formaDebito = $('input[name=rdoFormaDebito]:checked').val();	
	var ParcelaMaster = $('input[name=MasterParcela]:checked').val();
	
//	alert(ParcelaVisa);
//	alert(formaBoleto);
	if (tipo == "b") { 
		$('#dvBoleto').slideDown(); 
		
		$('#dvDebito').slideUp(); 		
		$('#dvVisa').slideUp(); 
		$('#dvMaster').slideUp();

		
		if (formaBoleto == "" || formaBoleto == undefined) { $('#btnConcluir').attr("disabled", "disabled");  }
		else { $('#btnConcluir').attr("disabled", ""); }
		
	}
	else if (tipo == "d") {
		$('#dvDebito').slideDown();
		
		$('#dvBoleto').slideUp(); 
		$('#dvVisa').slideUp(); 
		$('#dvMaster').slideUp(); 
				
		if (formaDebito == "" || formaDebito == undefined) { $('#btnConcluir').attr("disabled", "disabled"); }
		else { $('#btnConcluir').attr("disabled", ""); }
		
	}
	else if (tipo == "c") { 
		$('#dvVisa').slideDown(); 
		
		$('#dvBoleto').slideUp(); 
		$('#dvDebito').slideUp(); 
		$('#dvMaster').slideUp(); 
		if (ParcelaVisa == "" || ParcelaVisa == undefined) { $('#btnConcluir').attr("disabled", "disabled"); }
		else { $('#btnConcluir').attr("disabled", ""); }
	}

	else if (tipo == "m") { 
		$('#dvMaster').slideDown(); 
		
		$('#dvBoleto').slideUp(); 
		$('#dvDebito').slideUp(); 
		$('#dvVisa').slideUp(); 		

		if (ParcelaMaster == "" || ParcelaMaster == undefined) { $('#btnConcluir').attr("disabled", "disabled"); }
		else { $('#btnConcluir').attr("disabled", ""); }

	}

//	alert(forma);
}
