/* onBlur="formataString(this,'a')" */
function formataString (prInput ,prTipoFormatacao) {

	function formataPrimeiraMaiuscula(objeto) {
		var palavrasLivres = new Array ('de','da','do','das','des','dos','e');
		var ret = '';
		var string = objeto.value;
		var temp = new Array();
		temp = string.split(' ');
		for(var x = 0; x < temp.length; x++) {
			if (temp[x] == '') { continue; }
			var verificacao = Array.indexOf(palavrasLivres, temp[x].toLowerCase());
			if (x > 1) { ret += ' '; }
			if(verificacao == -1) {
				ret += primeiraLetraMaiuscula (temp[x])+' ';
			} else {
				ret += temp[x].toLowerCase()+' ';
			}
		}
		return ret;
	}
	function primeiraLetraMaiuscula(prString) {
		var string = prString.toLowerCase();
		str1 = string.substring(0,1);
		ret = string.replace(str1, str1.toUpperCase());
		return ret;
	}

	var prString = prInput.value;
	switch (prTipoFormatacao) {
		case 'a' : valorFormatado =  prString.toLowerCase(); break;
		case 'A' : valorFormatado =  prString.toUpperCase(); break;
		default  : valorFormatado =  formataPrimeiraMaiuscula (prInput); break;  
	}
	prInput.value = valorFormatado;
}

function checkReservaForm() {
	if	(document.reservaForm.data.value == '') {
		alert('Informe a data da reserva no formado DD/MM/AAAA!');
		document.reservaForm.data.focus();
		return false;
	}
	if	(document.reservaForm.reservadoPor.selectedIndex == 0) {
		alert('Informe o sócio da reserva!');
		document.reservaForm.reservadoPor.focus();
		return false;
	}
	return true;
}


function checkContatoForm() {
	if	(document.contatoForm.nome.value == '') {
		alert('Informe o seu nome!');
		document.contatoForm.nome.focus();
		return false;
	}
	if	(document.contatoForm.email.value == '') {
		alert('Informe o seu e-mail!');
		document.contatoForm.email.focus();
		return false;
	}
	if	(document.contatoForm.mensagem.value == '') {
		alert('Informe a mensagem!');
		document.contatoForm.mensagem.focus();
		return false;
	}
	return true;
}

function checkCadastroForm() {
	if	(document.cadastroForm.nome.value == '') {
		alert('Informe o seu nome!');
		document.cadastroForm.nome.focus();
		return false;
	}
	if	(document.cadastroForm.email.value == '') {
		alert('Informe o seu e-mail!');
		document.cadastroForm.email.focus();
		return false;
	}
	return true;
}

function checkInscricaoForm() {
	if	(document.inscricaoForm.cpf.value == '') {
		alert('Informe o CPF do piloto!');
		document.inscricaoForm.cpf.focus();
		return false;
	}
	if	(document.inscricaoForm.piloto.value == '') {
		alert('Informe o nome do piloto!');
		document.inscricaoForm.piloto.focus();
		return false;
	}
	if	(document.inscricaoForm.veiculo.selectedIndex == 0) {
		alert('Informe o veículo!');
		document.inscricaoForm.veiculo.focus();
		return false;
	}
	if	(document.inscricaoForm.placa.value == '') {
		alert('Informe a placa do veículo!');
		document.inscricaoForm.placa.focus();
		return false;
	}
	if	(document.inscricaoForm.cidade.value == '') {
		alert('Informe a cidade!');
		document.inscricaoForm.cidade.focus();
		return false;
	}
	if	(document.inscricaoForm.uf.value == '') {
		alert('Informe o estado!');
		document.inscricaoForm.uf.focus();
		return false;
	}
	if	(document.inscricaoForm.email.value == '') {
		alert('Informe o e-mail!');
		document.inscricaoForm.email.focus();
		return false;
	}
	return true;
}

function verificaCadastroCpf(prObjeto) {
	var params = jQuery('form').serialize();
	var tmp = new Array();
	var input = new Array();
	var nameInput = new Array();
	var valorInput = new Array();
	
	jQuery.ajax({
		url: "verificaCadastroCpf.ajax.php",
		data: params,
		type: "POST",
		success: function(msg){
			if (msg != ''){
				input = msg.split('|');
				for(x = 0; x < input.length; x ++){
					valorInput[x] = input[x].split('=')[1];
					nameInput[x] = input[x].split('=')[0];
				}
				if(jQuery('input[name=cpf]').val() == valorInput[1]){
					for(x = 0; x < input.length; x ++){
						jQuery('input[name='+nameInput[x]+']').val(valorInput[x]);
						if(nameInput[x] == 'veiculo' || nameInput[x] == 'uf'){
							jQuery('select[name='+nameInput[x]+'] option[value='+valorInput[x]+']').attr('selected','selected');
						}
					}
				}
			} else {
				jQuery('input[name=action]').val('ins');
			}
		}
	})
}

function retornaMsg(){
	jQuery(document).ready( function (){
		if(jQuery('div.msg').css('display') == 'none'){
			jQuery('div.msg').css({'-webkit-border-radius':'0px 0px 10px 10px','-moz-border-radius':'0px 0px 10px 10px','text-align':'center','padding':'10px','display':'block','position':'fixed','top':'0px','left':'38%','width':'300px','background-color':'#8D4F21','color':'#fff'}).show('1000').delay('2500').fadeOut('2500',function (){jQuery(this).remove();});
		}
		if(jQuery('form[name=msgBoleto]').attr('name') == 'msgBoleto'){
			document.forms['msgBoleto'].submit();
		}
	});
}
	function popUp(prUrl) {
		var newWindow = '';
		if (!newWindow.closed && newWindow.location) {
			newWindow.location.href = prUrl;
		} else {
			newWindow = window.open(prUrl,'BOLETO','height=600,width=800');
			if (!newWindow.opener){
				newWindow.opener = self;
			}
		}
		if (window.focus) {
			newWindow.focus()
		}
	}
