var cnt = 1;
var total = 0;
var campos=new Array();

function insertItem(){
    var div = document.createElement("div");
    div.id = cnt;
    div.innerHTML = "<div class=\"divInput\" name=\"upload" + cnt + "\" id=\"upload" + cnt + "\"><label for=\"input_file\">Arquivo: &nbsp;&nbsp;</label><input type=\"file\" name=\"arquivo[]\" id=\"" + cnt + "\" value=\"adicionar\" class=\"inputFile\"> <a href=\"javascript:removeItem('" +cnt+ "');\"><img src=\"_imagens/botao_excluir.gif\" alt=\"\" border=\"0\" /></a></div>";
    //div.innerHTML = '<input type="text" name="input[]" id="'+cnt+'" /><a href="javascript:removeItem('+cnt+');"> remover</a>';
    document.getElementById('itens').appendChild(div);
    cnt++;
}

function removeItem(id){
    document.getElementById('itens').removeChild(document.getElementById(id));
}

/*##############################################################################################################################*/

function insereGol(){
    var div = document.createElement("div");
    div.id = cnt;
    div.innerHTML = "<div class=\"divInput\"><label for=\"label_atleta\" id=\"id_label_atleta\">Atleta:</label><select name=\"atleta_fez_gol[]\" id=\"id_atleta_fez_gol[]\" class=\"inputB\">" + document.form_gols.opts_value_atletas.value + "</select> <input type=\"checkbox\" name=\"gol_adversario[]\" id=\"id_gol_adversario[]\" value=\"S\" /> <a href=\"javascript:removeGol('" +cnt+ "');\"><img src=\"_imagens/botao_excluir.gif\" alt=\"Excluir este gol!\" border=\"0\" /></a></div><div class=\"divInput\"><label for=\"label_atleta\" id=\"id_label_atleta\">Minuto:</label><input type=\"text\" name=\"gol_marcado[]\" id=\"id_gol_marcado[]\" class=\"inputA\" value=\"\" style=\"width:30px;\" /><span style=\"font-weight:bold;\">Tempo:</span><select name=\"tempo_fez_gol[]\" id=\"id_tempo_fez_gol[]\" class=\"inputB\"><option value=\"1\">1º Tempo</option><option value=\"2\">2º Tempo</option></select></div><div class=\"divInput\"><label for=\"label_atleta\" id=\"id_label_atleta\">Obs:</label><textarea name=\"obs_gerais_gol_marcado[]\" id=\"id_obs_gerais_gol_marcado[]\" class=\"inputTextArea\" cols=\"52\" rows=\"1\" style=\"height:40px;\"></textarea></div><br />";
	
    document.getElementById('conteudo_gols').appendChild(div);
    cnt++;
}

function removeGol(id){
    document.getElementById('conteudo_gols').removeChild(document.getElementById(id));
}

/*##############################################################################################################################*/

function insereProg(){

    var soma_prog = 1;

    cnt_prog = Number(document.form_prog.quantasprog.value);
    if((cnt_prog == 0) || (cnt_prog == "")){
 	cnt_prog = Number(soma_prog);
    } else {
	cnt_prog += Number(soma_prog);
    }	

    var div = document.createElement("div");
    div.id = cnt_prog;
    div.innerHTML = "<div class=\"divInput\" style=\"padding-bottom:4px;\"><label for=\"label_hora_prog\" id=\"id_label_hora_prog\">Hora:</label><input type=\"text\" name=\"hora_prog[]\" maxlength=\"5\" onkeypress=\"permite_digitar(this,':0123456789')\" id=\"id_hora_prog[]\" class=\"inputB\" /> <a href=\"javascript:removeProg('" +cnt_prog+ "');\"><img src=\"_imagens/botao_excluir.gif\" alt=\"Excluir programação!\" border=\"0\" /></a></div><div class=\"divInput\"><label for=\"label_desc\" id=\"id_label_dec\">Descrição:</label><input type=\"text\" name=\"desc_prog[]\" id=\"id_desc_prog[]\" class=\"inputB\" style=\"width:350px;\" /></div>";
	
    document.getElementById('conteudo_prog').appendChild(div);
    document.form_prog.quantasprog.value = Number(cnt_prog);
    cnt_prog++;
}

function removeProg(id){
    document.getElementById('conteudo_prog').removeChild(document.getElementById(id));
}

/*########################## FUNÇÕES JAVASCRIPT EXCLUSIVAS DA TELA DE CADASTRO DE CONTRATO ##############################*/
var cnt_cotas;
var total_cotas = 0;
var soma_cotas = 1;
var campos_cotas=new Array();
var varComboListCota = "";

function insertItemCotas(){
	cnt_cotas = Number(document.form.total_cotas.value);
	if((cnt_cotas == 0) || (cnt_cotas == "")){
		cnt_cotas = Number(soma_cotas);
	} else {
		cnt_cotas += Number(soma_cotas);
	}
	
   var div = document.createElement("div");
   div.id = cnt_cotas;
   div.innerHTML = "<div class=\"divInput\" id=\"" + cnt_cotas + "\" name=\"cota" + cnt_cotas + "\" style=\"width:650px;\"><label style=\"width: 228px; padding-right: 2px;\" for=\"input_cota\">Cota" + cnt_cotas + ":</label><select style=\"width: 70px;\" name=\"opcao_cota[]\" id=\"opt_cota" + cnt_cotas + "\" class=\"inputB\" onchange=\"habilita_cota_clube(this.value,'clb_cota" + cnt_cotas + "')\"><option value=\"\">Selecione aqui -&gt;</option><option value=\"1\">CAP</option><option value=\"2\">JOGADOR</option><option value=\"3\">PROCURADOR</option><option value=\"4\">CLUBE</option><option value=\"5\">PARCEIRO</option></select>&nbsp;<input maxlength=\"5\" size=\"5\" class=\"inputA\" style=\"width:45px\" name=\"porcentagem_cota[]\" type=\"text\">%&nbsp;<div id=\"div_clb_cota" + cnt_cotas + "\" style=\"width:95px;display:inline;\"><select style=\"width: 80px;\" name=\"prop_cota[]\" id=\"clb_cota" + cnt_cotas + "\" class=\"inputB\"><option value=\"\">================== CLUBES ==================</option></select></div>&nbsp;<a href=\"javascript:removeItemCotas('" + cnt_cotas + "');\"><img src=\"_imagens/botao_excluir.gif\" alt=\"\" border=\"0\" /></a></div>";

   document.getElementById('itens_cotas').appendChild(div);
   document.form.quantascotas.value = Number(document.form.total_cotas.value) + Number(soma_cotas);
   document.form.total_cotas.value = Number(document.form.total_cotas.value) + Number(soma_cotas);

}

function removeItemCotas(id){
	cnt_cotas = Number(document.form.total_cotas.value);
      document.getElementById('itens_cotas').removeChild(document.getElementById(id));
	document.form.quantascotas.value = Number(cnt_cotas) - Number(soma_cotas);
	document.form.total_cotas.value = Number(cnt_cotas) - Number(soma_cotas);
}

function habilita_cota_clube(tipo,id_combo){		
	try {
		if (tipo >= 4 ) {			
			var url = new Array();
			url[4] = "listagem_clubes_combo.php?last_atleta=" + document.form.last_atleta.value;
			url[5] = "listagem_parceiros_combo.php?last_atleta=" + document.form.last_atleta.value;
			var oHTTPRequest = new create_XMLHTTP(); 
			oHTTPRequest.open("post", url[tipo], true);
			oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					document.getElementById("div_"+id_combo).innerHTML = DecodeURL(oHTTPRequest.responseText);
				} else {
					if (document.getElementById(id_combo).options[0].text=="carregando.")
						document.getElementById(id_combo).options[0].text = "carregando..";
					else if (document.getElementById(id_combo).options[0].text == "carregando..")
						document.getElementById(id_combo).options[0].text = "carregando...";
					else
						document.getElementById(id_combo).options[0].text = "carregando.";
				}
			}
			oHTTPRequest.send("tipo=" + tipo);
		}
	} catch(e) { alert(e); }
}

function carrega_beneficiarios_dir_feder_outros(tipo,id_combo,opt_selected){
	try {
		if (tipo >= 4 ) {			
			var url = new Array();
			url[4] = "lista_clubes_combo_cessao_dir_feder_outros.php?last_atleta=" + document.form.last_atleta.value + "&opcao_selecionar=" + opt_selected;
			url[5] = "lista_parceiros_combo_cessao_dir_feder_outros.php?last_atleta=" + document.form.last_atleta.value + "&opcao_selecionar=" + opt_selected;
			var oHTTPRequest = new create_XMLHTTP(); 
			oHTTPRequest.open("post", url[tipo], true);
			oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					document.getElementById("div_"+id_combo).innerHTML = DecodeURL(oHTTPRequest.responseText);
				}
			}

			oHTTPRequest.send("tipo=" + tipo);
		}
	} catch(e) { alert(e); }
}
	
function remuneracao_total(){
	var dir_imagem = 0;
	var valor_salario = 0;
	var result = 0;
	dir_imagem = document.form.Vlr_direito_imagem.value;
	valor_salario = document.form.Vlr_salario.value;

	dir_imagem.replace(",",".");
	dir_imagem = dir_imagem.replace("R$","");
	dir_imagem = dir_imagem.replace("U$$","");
	dir_imagem = dir_imagem.replace("U$","");	
	dir_imagem = dir_imagem.replace(".", "" );
	dir_imagem = Trim(dir_imagem);

	valor_salario.replace(",",".");
	valor_salario = valor_salario.replace("R$","");
	valor_salario = valor_salario.replace("U$$","");
	valor_salario = valor_salario.replace("U$","");	
	valor_salario = valor_salario.replace(".", "" );
	valor_salario = Trim(valor_salario);
	result = Number(valor_salario) + Number(dir_imagem);
	document.form.r_total.value = "";
	document.form.r_total.value = result;
}

function limite_compra(){
	if(document.form.check_dt_limite_opt_compra.checked == false){
		document.form.dt_limite_compra.disabled = true;
	} else {
		document.form.dt_limite_compra.disabled = false;
	}
}

function prorro_contrato(){

	if(document.form.check_prorrogacao_contrato_opt.checked == false){
		document.form.dt_prorrogacao_contrato.disabled = true;
	} else {
		document.form.dt_prorrogacao_contrato.disabled = false;
	}
}

function renovacao_contrato(){
	if(document.form.check_renovacao_contrato_opt.checked == false){
		document.form.dt_renovacao_contrato.disabled = true;
	} else {
		document.form.dt_renovacao_contrato.disabled = false;
	}
}

function pendencia_jurid(opt_cmb){
	if(opt_cmb == 2){
		document.getElementById('id_textarea_juridico').disabled = true;
	} else {
		document.getElementById('id_textarea_juridico').disabled = false;
	}
}
/*####################### FIM - FUNÇÕES JAVASCRIPT EXCLUSIVAS DA TELA DE CADASTRO DE CONTRATO ##########################*/

function create_XMLHTTP() {
	try {
		var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
		var xmlhttp = false;
		for (var i=0; i < arrSignatures.length; i++) {
			try {
				var oRequest = new ActiveXObject(arrSignatures[i]);
				xmlhttp = oRequest;
				break;
			} catch (oError) {
			}
		}
		if(!xmlhttp && typeof XMLHttpRequest != 'undefined'){
			//PARA O FIREFOX
			xmlhttp = new XMLHttpRequest();
		}
			
		return xmlhttp;
	} catch(e){ alert(e); }
}

function DecodeURL(psEncodeString) {
  var lsRegExp = /\+/g;
  return unescape(String(psEncodeString).replace(lsRegExp, " "));
}

function autenticar_usuario(){
	f = document.form_login;
	if(f.usuario.value == ""){
		alert('É necessário informar o seu usuário de acesso para autenticar no sistema !');
		f.login.focus();
		return false;
	}
	if(f.senha.value == ""){
		alert('É necessário informar a sua senha de acesso para autenticar no sistema !');
		f.senha.focus();
		return false;
	}
	f.action="index.php";
	f.submit();
	return true;
}

function teclaEnterAutenticarUsuario(event){
	var charCode = (navigator.appName == "Netscape") ? event.which : event.keyCode;
	if (charCode == 13) {
		autenticar_usuario();
	}
}

function permite_digitar(campo,digitos){
	var digits=digitos
	var campo_temp
	for (var i=0;i<campo.value.length;i++){
	  campo_temp=campo.value.substring(i,i+1)
	  if (digits.indexOf(campo_temp)==-1){
	     campo.value = campo.value.substring(0,i);
	     break;
	   }
	}
}

function FormataData(Campo,teclapres) {
	var mydata = ''; 
	mydata = Campo.value; 

	if (mydata.length == 2){  
		mydata = mydata + '/'; 
		Campo.value = mydata; 
	} 
	
	if (mydata.length == 5){ 
		mydata = mydata + '/'; 
		Campo.value = mydata; 
	} 
	if (mydata.length >= 10){ 
		verifica_data(Campo); 
	} 
}

function FormataReais(fld, milSep, decSep, e){ 

	var sep = 0; 

	var key = ''; 

	var i = j = 0; 

	var len = len2 = 0; 

	var strCheck = '0123456789'; 

	var aux = aux2 = ''; 

	var whichCode = (window.Event) ? e.which : e.keyCode; 

	if (whichCode == 13) return true; 

		key = String.fromCharCode(whichCode);// Valor para o código da Chave 

	if (strCheck.indexOf(key) == -1) return false; // Chave inválida 

		len = fld.value.length; 

	for(i = 0; i < len; i++) 

		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break; 

		aux = ''; 

	for(; i < len; i++) 

		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i); 

		aux += key; 

	len = aux.length; 

	if (len == 0) fld.value = ''; 

	if (len == 1) fld.value = '0'+ decSep + '0' + aux; 

	if (len == 2) fld.value = '0'+ decSep + aux; 

	if (len > 2) { 

		aux2 = ''; 

		for (j = 0, i = len - 3; i >= 0; i--) { 

			if (j == 3) { 

				aux2 += milSep; 

				j = 0; 

			} 

			aux2 += aux.charAt(i); 

			j++; 
	
		} 

		fld.value = ''; 

		len2 = aux2.length; 

		for (i = len2 - 1; i >= 0; i--) 

			fld.value += aux2.charAt(i); 

			fld.value += decSep + aux.substr(len - 2, len); 

	} 

	return false; 

}

function exclui_arquivo_atleta(id){
	var agree=confirm("Confirma a exclusão permanente deste arquivo ?");
	if(agree){
		f = document.form;
		f.target="";
		f.action="exclui_arquivo_atleta.php?id_arquivo=" + id;
		f.submit();
	}
}

function submit_form_dados_pessoais(acao_form){
	f = document.form;
	f.target="";
	f.action="?acao=" + acao_form;
	
	if(f.nome_atleta.value==""){
		alert('É obrigatório informar o nome do atleta !');
		f.nome_atleta.focus();
		return false;
	}

	if(f.apelido_atleta.value==""){
		alert('É obrigatório informar o apelido do atleta !');
		f.apelido_atleta.focus();
		return false;
	}

	if(f.condicao.value==""){
		alert('É obrigatório informar a condição de atividade do atleta !');
		f.condicao.focus();
		return false;
	}

	if(f.dt_adm.value==""){
		alert('É obrigatório informar o data de admissão do atleta !');
		f.dt_adm.focus();
		return false;
	}
}

function submit_form_cadastro(nome_form,target,acao_form){
	formulario = nome_form;
	formulario.target = target;
	formulario.action = acao_form;
}

function submit_form(nome_form,target,acao_form){
	formulario = nome_form;
	formulario.target = target;
	formulario.action = acao_form;
	formulario.submit();
}

function seleciona_todos_select(id_nome_cmpo,nome_form,target,acao_form){
	var tamanho = document.getElementById(id_nome_cmpo).length;
	for(i=0;i<tamanho;i++){
		document.getElementById(id_nome_cmpo).options[i].selected=true;
	}
	//alert(nome_form + ' - ' + target + ' - ' + acao_form);
	submit_form(nome_form,target,acao_form);
}

function submit_excluir(nome_form,target,acao_form){
	var agree=confirm("Confirma a exclusão permanente deste registro ?");
	if(agree){
		formulario = nome_form;
		formulario.target = target;
		formulario.action = acao_form;
		formulario.submit();
	}
}

function confirma_excluir(acao_form){
	var agree=confirm("Confirma a exclusão permanente deste registro ?");
	if(agree){
		window.location.href=acao_form;
	}
}

function editar_atleta_selecionado(id){
	f = document.form;
	f.target="";
	f.action="form_cad_atleta_dados_pessoais.php?acao=editar&idatleta=" + id;
	f.submit();
}
function excluir_atleta_selecionado(id){
	var agree=confirm("Confirma a exclusão permanente deste registro ?");
	if(agree){
		f = document.form;
		f.target="";
		f.action="?acao=excluir&idatleta=" + id;
		f.submit();
	}
}

function curriculo_atleta(id_atleta){
	window.open('curriculo_atleta.php?pk=' + id_atleta,'curriculo','menubar=no,location=no,resizable=yes,toolbar=no,status=yes,scrollbars=yes,width=760,height=400');
}

function scout_atleta(id_atleta){
	window.open('scout_atleta.php?acao=editar&pk=' + id_atleta,'scout','menubar=no,location=no,resizable=yes,toolbar=no,status=yes,scrollbars=yes,width=760,height=400');
}

function FormataCNPJ(Campo) {
	var mycnpj = ''; 
	mycnpj = Campo.value;

	if (mycnpj.length == 2){
		mycnpj = mycnpj + '.';
		Campo.value = mycnpj;
	} 
	if (mycnpj.length == 6){
		mycnpj = mycnpj + '.';
		Campo.value = mycnpj;
	} 
	if (mycnpj.length == 10){ 
		mycnpj = mycnpj + '/'; 
		Campo.value = mycnpj; 
	}
	if (mycnpj.length == 15){ 
		mycnpj = mycnpj + '-'; 
		Campo.value = mycnpj; 
	} 
}

function vincula_video_ao_jogador(id_video,id_jogador,nome_campo){
	
	try {
		if(document.getElementById('id_'+nome_campo).checked==true){
			url = "executa_vinculo_video_jogador.php?ativar_video=yes&nome_cp=" + nome_campo + "&cod_video=" + id_video + "&cod_jogador=" + id_jogador;
		} else {
			url = "executa_vinculo_video_jogador.php?ativar_video=no&nome_cp=" + nome_campo + "&cod_video=" + id_video + "&cod_jogador=" + id_jogador;
		}
		var oHTTPRequest = new create_XMLHTTP();
		oHTTPRequest.open("post", url, true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				retorno_texto = DecodeURL(oHTTPRequest.responseText);
				if(document.getElementById('id_'+nome_campo).checked==true){
					if(retorno_texto == "ok"){
						alert('Video vinculado ao atleta !');
					} else {
						alert('Erro !');
					}
				} else {
					if(retorno_texto == "ok"){
						alert('Video desvinculado do atleta !');
					} else {
						alert('Erro !');
					}
				}

				if(retorno_texto == "opcao_invalida"){
					alert('Opção inválida !');
				}
			}
		}
		oHTTPRequest.send(null);
	} catch(e) { alert(e); }
}


function vincula_scout_ao_jogador(param_codigo){
	
	try {
		if(document.getElementById('id_scout'+param_codigo).checked==true){
			url = "executa_vinculo_scout_jogador.php?ativar_scout=yes&cod_scout=" + param_codigo;
		} else {
			url = "executa_vinculo_scout_jogador.php?ativar_scout=no&cod_scout=" + param_codigo;
		}

		//alert(url);

		var oHTTPRequest = new create_XMLHTTP();
		oHTTPRequest.open("post", url, true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				retorno_texto = DecodeURL(oHTTPRequest.responseText);
				if(document.getElementById('id_scout'+param_codigo).checked==true){
					if(retorno_texto == "ok"){
						alert('Scout System vinculado ao atleta !');
					} else {
						alert('Erro 1 !');
					}
				} else {
					if(retorno_texto == "ok"){
						alert('Scout System desvinculado do atleta !');
					} else {
						alert('Erro 2 !');
					}
				}

				if(retorno_texto == "opcao_invalida"){
					alert('Opção inválida !');
				}
			}
		}
		oHTTPRequest.send(null);
	} catch(e) { alert(e); }
}


function atualiza_grupo_scout_jogador(id_atleta,id_grupo){
	
	try {
		url = "executa_vinculo_grupo_scout_jogador.php?cod_jogador=" + id_atleta + "&cod_grupo=" + id_grupo;

		var oHTTPRequest = new create_XMLHTTP();
		oHTTPRequest.open("post", url, true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				retorno_texto = DecodeURL(oHTTPRequest.responseText);
				if(retorno_texto == "ok"){
					alert('Grupo cadastrado com sucesso !');
				} else {
					alert('Erro !');
				}

				if(retorno_texto == "opcao_invalida"){
					alert('Opção inválida !');
				}
			}
		}
		oHTTPRequest.send(null);
	} catch(e) { alert(e); }
}


//INÍCIO
/*FUNÇÃO QUE CADASTRA PROGRAMAÇÕES DE REAJUSTE SALARIAL*/

var cont = 1;
var cont_interno_prog = 1;
var qtde_reaj_sal_edicao = 0;
var SomaCota = 1;
cont_interno_qtde_divs_reaj_prog = 1;

function InsereNovoReajProg(){

    cont = Number(document.form.qtde_total_cotas.value);
    if((cont == 0) || (cont == "")){
    	cont = Number(SomaCota);
    } else {
	cont += Number(SomaCota);
    }

    qtde_reaj_sal_edicao = Number(document.form.cont_qtde_reaj_prog.value);
    if(qtde_reaj_sal_edicao > 0){
    	cont_interno_prog = qtde_reaj_sal_edicao + Number(SomaCota);
	cont_interno_qtde_divs_reaj_prog = qtde_reaj_sal_edicao + Number(SomaCota);
    }

    var div = document.createElement("div");
    div.id = cont;
    div.innerHTML = "<div class=\"divInput\" style=\"width:640px;\" name=\"reajuste_" + cont + "\" id=\"id_reajuste_" + cont + "\"><label for=\"input_reajuste" + cont + "\" style=\"width:230px;\">Reajuste Programado:</label><select name=\"combo_moeda_reajuste_" + cont + "\" id=\"id_combo_moeda_" + cont + "\" style=\"width:45px;\" class=\"inputB\"><option value=\"\">-></option><option value=\"2\">U$$</option><option value=\"3\">EUR</option><option value=\"1\" selected>R$</option></select><input type=\"text\" name=\"vlr_reajuste_prog" + cont + "\" id=\"id_vlr_reaj_prog" + cont + "\" class=\"inputA\" onkeypress=\"return(FormataReais(this,'.',',',event));\" style=\"width:100px;\" /><input type=\"text\" name=\"data_reajuste" + cont + "\" id=\"id_data_reaj_prog" + cont + "\" class=\"inputA\" style=\"width:85px\" readonly=\"true\" /><a href=\"javascript:void(0)\"><img border=\"0\" src=\"_imagens/imgcal.gif\" onclick=\"displayCalendar(document.form.data_reajuste" + cont + ",'dd/mm/yyyy',this);\"></a>&nbsp;&nbsp;<a href=\"javascript:removeReajProg('" +cont+ "');\"><img src=\"_imagens/botao_excluir.gif\" border=\"0\" alt=\"\" /></a></div>";
    document.getElementById('itens_reaj_prog').appendChild(div);
    document.form.cont_qtde_reaj_prog.value = cont_interno_qtde_divs_reaj_prog;
    document.form.qtde_total_cotas.value = Number(cont);
    cont++;
    cont_interno_prog++;
    cont_interno_qtde_divs_reaj_prog++;
}

function removeReajProg(id){ //FUNÇÃO PARA REMOVER OS DIVS DA FUNÇÃO DE CADASTRAR REAJUSTE SALARIAL
    cont_interno_prog--;
    document.getElementById('itens_reaj_prog').removeChild(document.getElementById(id));
}

//FIM DA FUNÇÃO QUE CADASTRA PROGRAMAÇÕES DE REAJUSTE SALARIAL*/


//INÍCIO
/*FUNÇÃO QUE CADASTRA PROGRAMAÇÕES DE REAJUSTE SALARIAL NA OPÇÃO*/

var cont_interno_opt = 1;
var cont_interno_qtde_divs_reaj_opt = 1;
var qtde_reaj_opt_edicao = 0;
function InsereNovoReajOpt(){

    cont = Number(document.form.qtde_total_cotas.value);
    if((cont == 0) || (cont == "")){
    	cont = Number(SomaCota);
    } else {
	cont += Number(SomaCota);
    }
	
    qtde_reaj_opt_edicao = Number(document.form.cont_qtde_reaj_opt.value);
    if(qtde_reaj_opt_edicao > 0){
    	cont_interno_opt = qtde_reaj_opt_edicao + Number(SomaCota);
	cont_interno_qtde_divs_reaj_opt = qtde_reaj_opt_edicao + Number(SomaCota);
    }

    var div = document.createElement("div");
    div.id = cont;
    div.innerHTML = "<div class=\"divInput\" style=\"width:640px;\" name=\"reajuste_opt" + cont + "\" id=\"id_reajuste_opt" + cont + "\"><label for=\"input_reajuste_opt" + cont + "\" style=\"width:230px;\">Reajuste na Opção:</label><select name=\"combo_moeda_reajuste_opt" + cont + "\" id=\"id_combo_moeda_" + cont + "\" style=\"width:45px;\" class=\"inputB\"><option value=\"\">-></option><option value=\"2\">U$$</option><option value=\"3\">EUR</option><option value=\"1\" selected>R$</option></select><input type=\"text\" name=\"vlr_reajuste_opt" + cont + "\" id=\"id_vlr_reaj_opt" + cont + "\" class=\"inputA\" onkeypress=\"return(FormataReais(this,'.',',',event));\" style=\"width:100px;\" /><input type=\"text\" name=\"data_reajuste_opt" + cont + "\" id=\"id_data_reaj_opt" + cont + "\" class=\"inputA\" style=\"width:85px\" readonly=\"true\" /><a href=\"javascript:void(0)\"><img border=\"0\" src=\"_imagens/imgcal.gif\" onclick=\"displayCalendar(document.form.data_reajuste_opt" + cont + ",'dd/mm/yyyy',this);\"></a>&nbsp;&nbsp;<a href=\"javascript:removeReajOpt('" +cont+ "');\"><img src=\"_imagens/botao_excluir.gif\" border=\"0\" alt=\"\" /></a></div>";
    document.getElementById('itens_reaj_opt').appendChild(div);
    document.form.cont_qtde_reaj_opt.value = cont_interno_qtde_divs_reaj_opt;
    document.form.qtde_total_cotas.value = Number(cont);
    cont++;
    cont_interno_opt++;
    cont_interno_qtde_divs_reaj_opt++;
}

function removeReajOpt(id){ //REMOVE DIVS DA PROGRAMAÇÃO DE REAJUSTE NA OPÇÃO
    document.getElementById('itens_reaj_opt').removeChild(document.getElementById(id));
    cont_interno_opt--;
}

//FIM DA FUNÇÃO QUE CADASTRA PROGRAMAÇÕES DE REAJUSTE SALARIAL NA OPÇÃO*/


/*######################################################################################################################*/

//INÍCIO
/*FUNÇÃO QUE CADASTRA PROGRAMAÇÕES DE PGTO PARCELADO DAS BONIFICAÇÕES DO ATLETA*/

var cont_interno_bonif = 1;
var cont_interno_qtde_divs_bonif = 1;
var qtde_reaj_bonif = 0;
function InsereNovaParcBonif(){

    cont = Number(document.form.qtde_total_cotas.value);
    if((cont == 0) || (cont == "")){
    	cont = Number(SomaCota);
    } else {
	cont += Number(SomaCota);
    }
	
    qtde_reaj_bonif = Number(document.form.cont_qtde_bonif.value);
    if(qtde_reaj_opt_edicao > 0){
    	cont_interno_bonif = qtde_reaj_opt_edicao + Number(SomaCota);
	cont_interno_qtde_divs_bonif = qtde_reaj_bonif + Number(SomaCota);
    }

    var div = document.createElement("div");
    div.id = cont;
    div.innerHTML = "<div class=\"divInput\" style=\"width:640px;\" name=\"div_parc_bonif" + cont + "\" id=\"id_div_parc_bonif" + cont + "\"><label for=\"input_label_parc_bonif" + cont + "\" style=\"width:230px;\">&nbsp;</label><select name=\"combo_moeda_parc_bonif" + cont + "\" id=\"id_combo_moeda_" + cont + "\" style=\"width:45px;\" class=\"inputB\"><option value=\"\">-></option><option value=\"2\">U$$</option><option value=\"3\">EUR</option><option value=\"1\" selected>R$</option></select><input type=\"text\" name=\"vlr_parc_bonif" + cont + "\" id=\"id_text_parc_bonif" + cont + "\" class=\"inputA\" onkeypress=\"return(FormataReais(this,'.',',',event));\" style=\"width:100px;\" /><input type=\"text\" name=\"dt_pgto_parc_bonif" + cont + "\" id=\"id_text_dt_parc_bonif" + cont + "\" class=\"inputA\" style=\"width:85px\" readonly=\"true\" /><a href=\"javascript:void(0)\"><img border=\"0\" src=\"_imagens/imgcal.gif\" onclick=\"displayCalendar(document.form.dt_pgto_parc_bonif" + cont + ",'dd/mm/yyyy',this);\"></a>&nbsp;&nbsp;<a href=\"javascript:removeParcBonificacao('" +cont+ "');\"><img src=\"_imagens/botao_excluir.gif\" border=\"0\" alt=\"\" /></a></div>";
    document.getElementById('itens_parc_bonif').appendChild(div);
    document.form.cont_qtde_bonif.value = cont_interno_qtde_divs_bonif;
    document.form.qtde_total_cotas.value = Number(cont);
    cont++;
    cont_interno_bonif++;
    cont_interno_qtde_divs_bonif++;
}

function removeParcBonificacao(id){ //REMOVE DIVS DA PROGRAMAÇÃO DE REAJUSTE NA OPÇÃO
    cont_interno_bonif--;
    document.getElementById('itens_parc_bonif').removeChild(document.getElementById(id));
}

//FIM DA FUNÇÃO QUE CADASTRA AS PARCELAS DO PGTO DAS BONIFICAÇÕES*/


function calcula_dir_fed_contr_transf_def(){
	var cemporcento = 100;
	var vlr_cessao_vendido = document.form.dir_federativos_vendido.value;
	if(vlr_cessao_vendido <= 100){
		residual = cemporcento - vlr_cessao_vendido;
		document.form.dir_federativos_residual.value = residual.toFixed(2);
	} else {
		alert('Valor inválido !');
		document.form.dir_federativos_vendido.value= "";
		document.form.dir_federativos_vendido.focus();
		return false;
	}
}

function envia_form_pesq_prep_desp(){
	condicao_opt_checked = false;
	var condicao_opt_checked = document.form.tp_teste_indiv_colet[0].checked;
	if(condicao_opt_checked == false){
		condicao_opt_checked = document.form.tp_teste_indiv_colet[1].checked;
	} else {
		condicao_opt_checked = document.form.tp_teste_indiv_colet[0].checked;
	}

	if((document.form.nome_exame.value != "") && (condicao_opt_checked == true)){
		formulario = form;
		formulario.target = "window_prep_desportiva";
		formulario.action = "result_pesq_atleta_main_tela_prep_desp.php";
		formulario.submit();
	}
}

function carrega_atletas_enc_prep_dep(str_nome_apelido,selecionar_atleta){
	try {
		var url= "lista_atletas_encon_combo_prep_desp.php?str_atleta=" + str_nome_apelido + "&select_atleta=" + selecionar_atleta;
		var oHTTPRequest = new create_XMLHTTP(); 
		oHTTPRequest.open("post", url, true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				document.getElementById("id_div_atletas_encont").innerHTML = DecodeURL(oHTTPRequest.responseText);
			}
		}

		oHTTPRequest.send(null);

	} catch(e) { 
		alert(e); 
	}

}

function atualiza_perna_dominante(str_dominancia,codigo_atleta){
	try {
		var url= "atualiza_perna_dominante.php?str_perna=" + str_dominancia + "&id_atleta=" + codigo_atleta;
		var oHTTPRequest = new create_XMLHTTP(); 
		oHTTPRequest.open("post", url, true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				alert(DecodeURL(oHTTPRequest.responseText));
			}
		}

		oHTTPRequest.send(null);

	} catch(e) { 
		alert(e); 
	}
}

function atualiza_peso_altura(codigo_atleta){
	if(document.form.atualizacao_automatica_peso_altura.checked == true){
		try {
			var url= "atualiza_peso_altura.php?id_atleta=" + codigo_atleta;
			var oHTTPRequest = new create_XMLHTTP(); 
			oHTTPRequest.open("post", url, true);
			oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					var Msg_PHP = DecodeURL(oHTTPRequest.responseText);
					array_Msg = Msg_PHP.split(";");					
					alert(array_Msg[1]);					
				}
			}

			oHTTPRequest.send(null);
	
		} catch(e) { 
			alert(e); 
		}
	}
}

// Função de trocar itens de lista para lista


function TrocaList(MenuOrigem, MenuDestino){
    var arrMenuOrigem = new Array();
    var arrMenuDestino = new Array();
    var arrLookup = new Array();
    var i;
    for (i = 0; i < MenuDestino.options.length; i++){
        arrLookup[MenuDestino.options[i].text] = MenuDestino.options[i].value;
        arrMenuDestino[i] = MenuDestino.options[i].text;
    }
    var fLength = 0;
    var tLength = arrMenuDestino.length;
    for(i = 0; i < MenuOrigem.options.length; i++){
        arrLookup[MenuOrigem.options[i].text] = MenuOrigem.options[i].value;
        if (MenuOrigem.options[i].selected && MenuOrigem.options[i].value != ""){
            arrMenuDestino[tLength] = MenuOrigem.options[i].text;
            tLength++;
        }
        else{
            arrMenuOrigem[fLength] = MenuOrigem.options[i].text;
            fLength++;
        }
    }
    arrMenuOrigem.sort();
    arrMenuDestino.sort();
    MenuOrigem.length = 0;
    MenuDestino.length = 0;
    var c;
    for(c = 0; c < arrMenuOrigem.length; c++){
        var no = new Option();
        no.value = arrLookup[arrMenuOrigem[c]];
        no.text = arrMenuOrigem[c];
        MenuOrigem[c] = no;
    }
    for(c = 0; c < arrMenuDestino.length; c++){
        var no = new Option();
        no.value = arrLookup[arrMenuDestino[c]];
        no.text = arrMenuDestino[c];
        MenuDestino[c] = no;
   }
}
	function abrePopUp(caminho,largura,altura,rolagem){
	nm_janela = 'popUp';
	w = largura;
	h = altura;
	rol = rolagem;
	largura = screen.width;
	altura = screen.height;
	XX = (largura-w)/2;
	YY = (altura-h)/2;
	janela = window.open(caminho, nm_janela, 'width='+w+', height='+h+', left='+XX+', top='+YY+'menubar=no, toolbar=no,status=no,scrollbars='+rol+',');
	janela.focus(); 
	}
