
function validaBusca(){
  var nomeNumAtleta = document.getElementById('q');

  if (nomeNumAtleta.value.length == 0 || nomeNumAtleta.value == 'Busca por nome ou camisa') {
	window.alert('Informe o nome e sobrenome ou o número da camisa!');
  	nomeNumAtleta.focus();
  	return false;
  }

  var reDigits = /^\d+$/;
  if (!reDigits.test(nomeNumAtleta.value)) {
  	
	if (nomeNumAtleta.value.length < 2) {
		window.alert('Você precisa informar o nome completo!');
    	nomeNumAtleta.focus();
    	return false;
  	} else {
		
		var arr = nomeNumAtleta.value.split(' ');
		if (arr.length < 2) {
			window.alert('Você precisa informar o nome completo!');
	    	nomeNumAtleta.focus();
	    	return false;
		} else {
		
			if (arr[0] == '' || arr[1] == '') {
				window.alert('Nome inválido!');
		    	nomeNumAtleta.focus();
		    	return false;
			} else {
				if (arr[0].length < 2 || arr[1].length < 2) {
					window.alert('Nome inválido!');
			    	nomeNumAtleta.focus();
			    	return false;
				}
				return true;
			}
		}
		return true;
  	}
  }
  return true;
}

/* 12/09/2011
 * utilizado em eventos/index no box "Busca por número" e na busca geral no topo do site
*/
function buscaAtletaNome(url, field, valueDefault) {
	var str = document.getElementById(field);
	if (str.value.length < 4 || str.value == valueDefault) {
		window.alert('mínimo de quatro caracteres para a busca!');
        str.focus();
	} else {
        window.location.href = url + '/eventos/busca-atleta/' + encodeURI(str.value);
    }
}

/* 12/09/2011
 * utilizado apenas em eventos/index no box "Busca por número"
*/
function buscaAtletaNumero(url) {
	var numero = document.getElementById('paramAtletaCamisa');
	if (numero.value.length < 1) {
		window.alert('informe o número da camisa!');
        numero.focus();
	} else {
        window.location.href = url + '/fotos/busca-camisa/' + numero.value;
    }
}

/* 12/09/2011
 * utilizado apenas em eventos/visualiza no box "Busca por nome"
*/
function buscaAtletaNomePorEvento(url) {
	var atleta = document.getElementById('paramAtletaNome');
	var evento = document.getElementById('paramAtletaNomeIdEvento');
	if (atleta.value.length < 4) {
		window.alert('mínimo de quatro caracteres para a busca!');
        atleta.focus();
	} else {
        window.location.href = url + '/eventos/busca-atleta/' + encodeURI(atleta.value) + '/' + evento.value;
    }
}

/* 12/09/2011
 * utilizado apenas em eventos/visualiza no box "Busca por número"
*/
function buscaAtletaNumeroPorEvento(url) {
	var numero = document.getElementById('paramAtletaCamisa');
	var evento = document.getElementById('paramAtletaCamisaIdEvento');
	if (numero.value.length < 1) {
		window.alert('informe o número da camisa!');
        numero.focus();
	} else {
        window.location.href = url + '/fotos/busca-camisa/' + numero.value + '/' + evento.value;
    }
}

/* 23/09/2011
 * utilizado apenas em eventos/index no box "Buscar Evento"
*/
function buscaEvento(url) {
	var evento = document.getElementById('paramEvento');
	if (evento.value.length < 1) {
		window.alert('digite o nome do evento!');
        evento.focus();
	} else {
        window.location.href = url + '/eventos/' + encodeURI(evento.value);
    }
}
