
/* Função não aceitar somente números */
var r={
	'special':/[\W]/g,
	'quotes':/['\''&'\"']/g,
	'notnumbers':/[^\d]/g
}
function valid(o,w){
	o.value = o.value.replace(r[w],'');
}

//Função que exibe o campo de CPF para inserir um novo participante
function exibeCampoCpf(){
	document.getElementById('trNovo').style.display = 'none';
	document.getElementById('trCpf').style.display = 'inline';
}


/*INICIALIZAÇÃO DA PÁGINA*/
window.onload = function(){
	attachExibeCidade();
}

/* CADASTRO DE PARTICIPANTE - ESCLOHE CIDADE DE ACORDO COM O ESTADO SELECIONADO*/
function attachExibeCidade(cidade){

	var form = document.forms[0];
	if (form.cidade_hidden){
		var uf = form.uf;
		
		uf.onchange = function(){
			exibeCidade(uf.options[uf.selectedIndex].value);
		}
		exibeCidade(null);
		
	}
}

function exibeCidade(est){
	var form = document.forms[0];
	var cidade = form.cidade_hidden.value;
	var estado = form.uf;
	var uf;
	
	//alert('UF: ' + estado.value +  ' - Cid: ' + cidade.value);
	//alert('EST: ' + est);
	if (est == null){
		uf = estado.options[estado.selectedIndex].value;
	} else {
		uf = est;
	}
	if (uf.length==2){
		//custom loading
		var load = document.createElement("img");
		load.src = "images/cidades_loader.gif";
		estado.parentNode.appendChild(load);
		
		var ajax = new Request();
	
		var callback = function(str){
			document.getElementById("span_cidade").innerHTML = str;
			estado.parentNode.removeChild(estado.parentNode.getElementsByTagName("img")[0]);
		}
		ajax.doGet("RequestMunicipos.do?estado="+uf+"&cidade="+cidade, callback, "text");
	}
}

//Exibe ou oculta os campo Letra, no cadastro de obra ao clicar
function escolheFocoMusical(foco){
	if(foco == "cancao"){
		document.getElementById('imgCancao').src = "img/bt/btCancao.jpg";
		document.getElementById('imgInstrumental').src = "img/bt/btInstrumentalPressed.jpg";
		document.getElementById('focoMusicalId').value = "cancao";
		document.getElementById('trLetra').style.display = '';
	}else{
		document.getElementById('imgInstrumental').src = "img/bt/btInstrumental.jpg";
		document.getElementById('imgCancao').src = "img/bt/btCancaoPressed.jpg";
		document.getElementById('focoMusicalId').value = "instrumental";
		document.getElementById('trLetra').style.display = 'none';
	}
}

//Exibe ou oculta os campo Letra, no cadastro de obra ao abrir a tela
function inicializaFocoMusical(foco){
	if(foco == "cancao"){
		document.getElementById('imgCancao').src = "img/bt/btCancao.jpg";
		document.getElementById('imgInstrumental').src = "img/bt/btInstrumentalPressed.jpg";
		document.getElementById('focoMusicalId').value = "cancao";
		document.getElementById('trLetra').style.display = '';
	}else if(foco == "instrumental"){
		document.getElementById('imgCancao').src = "img/bt/btCancaoPressed.jpg";
		document.getElementById('imgInstrumental').src = "img/bt/btInstrumental.jpg";
		document.getElementById('focoMusicalId').value = "instrumental";
		document.getElementById('trLetra').style.display = 'none';
	}else{
		document.getElementById('focoMusicalId').value = "cancao";
	}
}

//Exibe ou oculta os campo Letra, no cadastro de obra ao clicar
function exibeBandaDeApoio(valor){
	if(valor == "S"){
		document.getElementById('instrumentos').style.display = '';
	}else{
		document.getElementById('instrumentos').style.display = 'none';
	}
}

//Exibe ou oculta os campo Letra, no cadastro de obra ao abrir a tela
function inicializaBandaDeApoio(valor){
	if(valor == "S"){
		document.getElementById('instrumentos').style.display = '';
	}else{
		document.getElementById('instrumentos').style.display = 'none';
	}
}

//Verifica se os dois campos de upload de arquivos estão preenchidos
function valida() {
	var nomeMp3 = document.getElementById('uploadMp3').value;
	var nomePartitura = document.getElementById('uploadPartitura').value;
	
	if ((nomeMp3 != "") && (nomePartitura != "")){
		if (verificaExtensao(nomeMp3) && verificaExtensao(nomePartitura) && (verificaExtensaoMusica(nomeMp3))){
			if ((nomeMp3 != nomePartitura)){
				document.getElementById('loading').style.display = 'block';
				document.formArquivo.submit();
			}else {
				alert('Prencha com arquivos diferentes.');
			}
		}
	} else{
		alert('Prencha os dois campos.');
	}
}


function exibeImgLoad() {
	document.getElementById('loading').style.display = 'block';
}

//Valida os tipos de extensão dos arquivos de upload
function verificaExtensao(campo) {   
    var validos = /(exe|bat|sh|batch|dll)/;   
    var ext = campo.substring(campo.length-3,campo.length);
    ext = ext.toLowerCase();
    if ( validos.test( ext ) ) {
        alert ('Arquivo com extensão não permitida: ' + ext);
        return false;   
    }   
    return true;   
}
//Verifica se no campo expecifico está com o tipo de arquivo especifico
function verificaExtensaoMusica(campo) {   
	//return !!$('#uploadMp3').val().indexOf('.mp3') > -1; 
    var validos = /(mp3|wma)/;   
    var ext = campo.substring(campo.length-3,campo.length);
    ext = ext.toLowerCase();
    if ( !validos.test( ext ) ) {
        alert ('Arquivo de Música com extensão não permitida: ' + ext);
        return false;   
    }   
    return true;   
}

//Verifica se no campo expecifico está com o tipo de arquivo especifico
function verificaExtensaoPartitura(campo) {   
    var validos = /(exe|bat|sh)/;   
    var ext = campo.substring(campo.length-3,campo.length);
    ext = ext.toLowerCase();
    if (validos.test( ext ) ) {
        alert ('Arquivo de Partitura com extensão não permitida: ' + ext);
        return false;   
    }   
    return true;   
}

//Exibe ou oculta uma div qualquer passando como parametro o id da mesma
function exibeOcultaDiv(idDiv){
	if(document.getElementById(idDiv).style.display == 'none'){
		document.getElementById(idDiv).style.display = '';
	}else{
		document.getElementById(idDiv).style.display = 'none';
	}
}

//Exibe ou oculta uma div qualquer passando como parametro o id da mesma
function exibeOcultaBandaApoio(){
	if(document.getElementById('disposicaoPalco').style.display == 'none'){
		document.getElementById('disposicaoPalco').style.display = '';
		document.getElementById('gerDadosInscricao').style.display = 'none';
	}
}

function excluirParticipante(cpf){
	if(confirm("Deseja realmente excluir o participante?")){
		document.location="UsuarioAction.do?operacao=excluir&cpfPart=" + cpf; 
	}
}