


function loading(){
	$('#loading-area').css("width","100px");
	$('#loading-area').css("margin-left","-40px");
	$('#message-area-inner').html('Carregando...');
    $('#loading-area').show();
}

function pageLoad(hash){
	if (hash) {
		url = hash.split('/');
		var pag = url[0]+'.php';
		if(pag == 'index.php') pag = 'calendar.php';
		if(pag == 'estrategias.php') pag = 'calendar.php';
		if(pag == 'indicadores.php') pag = 'calendar.php';
		if(pag == 'projetos.php') pag = 'calendar.php';
		if(pag == 'grupos.php') pag = 'calendar.php';
		if(pag == 'usuarios.php') pag = 'calendar.php';
		if(pag == 'relatorios.php') pag = 'calendar.php';
		if(pag == 'ajuda.php') pag = 'calendar.php';
		if(url[1] == null){
			var get = '';
		}else{
			var get  = url[1];
					if(url.length > 2){
						for(i = 2; i < url.length; i++){
							get += '&'+url[i];
						}
					}
		}
		$.ajax({
			type: 'GET',
			url: pag,
			data: get,
			cache: false,

			beforeSend: function(){
				loading();
				$('#context').html('');
			},
			success: function(txt){
				$('#loading-area').hide();
				$('#context').html(txt);
			},
			error: function(){
				$('#loading-area').hide();
				$('#loading-area').css("width","300px");
				$('#loading-area').css("margin-left","-142px");
				$('#message-area-inner').html('Houve um erro na aquisi&ccedil;&atilde;o da p&aacute;gina solicitada!');
			    $('#loading-area').show();
			}
		});
	}
}







function showLevel(show,img){
	var ie=navigator.appName.toLowerCase().indexOf("microsoft")>=0;
	var tabela = document.getElementById(show);
	var menosmais = document.getElementById(img);
	if (tabela.style.display == "none") {
		tabela.style.display = (ie)? "block" : "table-row";
		document.getElementById(img).style.background = 'url(imagens/bg/aba_in.jpg)';
		if (img != null) { menosmais.src = "imagens/menos.gif"; }
	} else {
		tabela.style.display = "none";
		document.getElementById(img).style.background = 'url(imagens/bg/aba_out.jpg)';
		if (img != null) { menosmais.style.background = 'url(imagens/bg/aba_in.jpg'; }
	}
}
function showLevelAba(show,img){
	var ie=navigator.appName.toLowerCase().indexOf("microsoft")>=0;
	var tabela = document.getElementById(show);
	if (tabela.style.display == "none") {
		tabela.style.display = (ie)? "block" : "table-row";
		document.getElementById(img).style.background = 'url(imagens/bg/aba_in.jpg)';
	} else {
		tabela.style.display = "none";
		document.getElementById(img).style.background = 'url(imagens/bg/aba_out.jpg)';
	}
}

function bloquearLetra(e){
	if(e.charCode == 45) return true;
	var e = e || event;

	if (window.event) {
			tecla = e.keyCode;
		}
		else 
			if (e.which) {
				tecla = e.which;
			}
			else {
				return true;
			}
		if (((tecla < 48) || (tecla > 57)) && (tecla != 8) && (tecla != 44)) {
			return false;
		}
}

function escondeDiv (id, img) { 
	tamanho =  id.length;
	for(i=0 ; i<tamanho ; i++) {
		document.getElementById(id[i]).style.display = "none";	
		var img = id[i]+'Bg';
		document.getElementById(img).style.background = 'url(imagens/bg/aba_out.jpg)';
	}

}


//ROLLOVER ROLLOUT das tabelas:
function rollOver (elemento) {
	elemento.style.backgroundColor='#7FB2E5';
}

function rollOut (elemento) {
	elemento.style.backgroundColor='';
}

function valida_filtro() {
	if (document.formfiltros.buscaAvancada.value.length <=4 && document.formfiltros.buscaAvancada.value.length != 0)
	{
		alert("Busca deve conter mais de 4 caracteres.");
		document.formfiltros.buscaAvancada.focus();
		return false;
	}
	return true;
}

function selectColumn(tableId, colNum) {
	var table = document.getElementById(tableId);
	var r = 0;
	var rEnd = table.rows.length;
	var row;
	var cell;
	var radio;
	//alert("#"+rEnd+"#");
	
	if (colNum >= 0 && colNum < table.rows[0].cells.length) {
		for (r; r < rEnd; r++) {
			row = table.rows[r];
			//alert("#"+row+"#");
			cell = row.cells[colNum];
			radio = cell.getElementsByTagName("input");
			if (radio.length) {
				radio[0].checked = true;
			}
		}
	radio = cell = row = table = null;
	}
}



function addGrupo(){
	var itemselected = document.forms[0].grupo.selectedIndex;
	var grupo = document.forms[0].grupo.options[itemselected];
	
	// Aqui cria o option, pega o value e o text do option selecionado no primeiro.. e escreve no segundo
	troca = document.createElement("option");
	document.forms[0].grupo_usuario.appendChild(troca);
	troca.value = grupo.value;
	troca.text = grupo.text;
	
	//Essa linha remove a opção selecionada do menu um
	document.forms[0].grupo.remove(itemselected);
}

function statusProjetos(url) {
	janela_largura_x = 425;
	janela_altura_y = 475;
	posx = (window.screen.width/2)-(janela_largura_x/2);
	posy = (window.screen.height/2)-(janela_altura_y/2);
	window.open('statusProjetos.php?url='+url,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left='+posx+',top='+posy+',width='+janela_largura_x+',height='+janela_altura_y);
}
function statusGraficos(url) {
	janela_largura_x = 425;
	janela_altura_y = 475;
	posx = (window.screen.width/2)-(janela_largura_x/2);
	posy = (window.screen.height/2)-(janela_altura_y/2);
	window.open('statusGraficos.php?url='+url,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left='+posx+',top='+posy+',width='+janela_largura_x+',height='+janela_altura_y);
}
function viewGrafico(url) {
	janela_largura_x = 650;
	janela_altura_y = 650;
	posx = (window.screen.width/2)-(janela_largura_x/2);
	posy = (window.screen.height/2)-(janela_altura_y/2);
	window.open('view_grafico.php?'+url,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left='+posx+',top='+posy+',width='+janela_largura_x+',height='+janela_altura_y);
}

function Enviar() {
	document.getElementById('Enviar').disabled = true; 
	document.getElementById('Enviar').value = 'Aguarde...';
}
function BtEnviar() {
	document.getElementById('Enviar').disabled = true; 
	document.getElementById('Enviar').value = 'Aguarde...';
}
function delGrupo(){
	var itemselected = document.forms[0].grupo_usuario.selectedIndex;
	if (itemselected != -1) {
		var grupo_usuario = document.forms[0].grupo_usuario.options[itemselected];
		
		// Aqui cria o option, pega o value do option selecionado no primeiro.. e escreve no segundo 
		troca = document.createElement("option");
		document.forms[0].grupo.appendChild(troca);
		troca.text = grupo_usuario.text;
		troca.value = grupo_usuario.value;
		
		//Essa linha remove a opção selecionada do menu um
		document.forms[0].grupo_usuario.remove(itemselected);
	}
}

	function MarcaTodosSelect(quem) {
        var selecionados = document.getElementById(quem);
        for(i=0; i<=selecionados.length-1; i++){
			  selecionados.options[i].selected = true;
        }
	}	


function addUser(){
	var itemselected = document.forms[0].grupo.selectedIndex;
	if (itemselected != -1) {
		var grupo = document.forms[0].grupo.options[itemselected];
		
		// Aqui cria o option, pega o value e o text do option selecionado no primeiro.. e escreve no segundo
		troca = document.createElement("option");
		document.forms[0].grupo_usuario.appendChild(troca);
		troca.value = grupo.value;
		troca.text = grupo.text;
		
		//Essa linha remove a opção selecionada do menu um
		document.forms[0].grupo.remove(itemselected);
	}
}

function delUser(){
	var itemselected = document.forms[0].grupo_usuario.selectedIndex;
	if (itemselected != -1) {
		var grupo_usuario = document.forms[0].grupo_usuario.options[itemselected];
		
		// Aqui cria o option, pega o value do option selecionado no primeiro.. e escreve no segundo 
		troca = document.createElement("option");
		document.forms[0].grupo.appendChild(troca);
		troca.text = grupo_usuario.text;
		troca.value = grupo_usuario.value;
		
		//Essa linha remove a opção selecionada do menu um
		document.forms[0].grupo_usuario.remove(itemselected);
	}
}


function addUserProjetos(){
	var itemselected = document.forms[0].user.selectedIndex;
	if (itemselected != -1) {
		var user = document.forms[0].user.options[itemselected];
		
		// Aqui cria o option, pega o value do option selecionado no primeiro.. e escreve no segundo 
		troca = document.createElement("option");
		document.forms[0].usuarios.appendChild(troca);
		troca.text = user.text;
		troca.value = user.value;
		
		//Essa linha remove a opção selecionada do menu um
		document.forms[0].user.remove(itemselected);
	}
}

function delUserProjetos(){
	var itemselected = document.forms[0].usuarios.selectedIndex;
	if (itemselected != -1) {
		var usuarios = document.forms[0].usuarios.options[itemselected];
		
		// Aqui cria o option, pega o value e o text do option selecionado no primeiro.. e escreve no segundo
		troca = document.createElement("option");
		document.forms[0].user.appendChild(troca);
		troca.value = usuarios.value;
		troca.text = usuarios.text;
		
		//Essa linha remove a opção selecionada do menu um
		document.forms[0].usuarios.remove(itemselected);
	}
}

function addUserProjetosAll(){
	MarcaTodosSelect('user');
	var quantos = document.getElementById('user').options.length;
		for(i=0; i < quantos; i++){
			
				var itemselected = document.forms[0].user.selectedIndex;
				var user = document.forms[0].user.options[itemselected];
				
				// Aqui cria o option, pega o value do option selecionado no primeiro.. e escreve no segundo 
				troca = document.createElement("option");
				document.forms[0].usuarios.appendChild(troca);
				troca.text = user.text;
				troca.value = user.value;
				
				//Essa linha remove a opção selecionada do menu um
				document.forms[0].user.remove(itemselected);
		}
	

}

function delUserProjetosAll(){
	MarcaTodosSelect('usuarios');
	var quantos = document.getElementById('usuarios').options.length;
    
	    for (i = 0; i < quantos; i++) {
			
			var itemselected = document.forms[0].usuarios.selectedIndex;
			var usuarios = document.forms[0].usuarios.options[itemselected];
			
			// Aqui cria o option, pega o value e o text do option selecionado no primeiro.. e escreve no segundo
			troca = document.createElement("option");
			document.forms[0].user.appendChild(troca);
			troca.value = usuarios.value;
			troca.text = usuarios.text;
			
			//Essa linha remove a opção selecionada do menu um
			document.forms[0].usuarios.remove(itemselected);
		}
}


function validaEmail(id){
		email = document.getElementById(id);
		string_mail = email.value; // string onde sera feita a procura
		letra1 = "@"; // letra para buscar
		letra2 = "."; // letra para buscar
		pos1 = string_mail.indexOf(letra1);
		pos2 = string_mail.indexOf(letra2);
		if ((email.value.length < 6) || (pos1 < 1) || (pos2 < 1) || (pos1 == email.value.length - 1) || (pos2 == email.value.length - 1)) {
			document.getElementById('msgEmail').innerHTML='&nbsp;<img src=imagens/icon/erro_peq.png align=bottom>';
			alert("Por favor, informe um e-mail correto.");
			email.focus();
			return false;
		} else{
			document.getElementById('msgEmail').innerHTML='&nbsp;<img src=imagens/icon/yes.png align=bottom>';
			return true;
		}
	}
	
	
function validarForm (campo) { //campo tem as IDs dos campos obrigatorios
	tamanho =  campo.length;

	for(i=0 ; i<tamanho ; i++) {
		if(document.getElementById(campo[i]).value=='' || document.getElementById(campo[i]).value==null) {
			alert("Preencha o campo "+  campo[i]);
			document.getElementById(campo[i]).focus(); 
			
			return false;
			
		}
	}
	
	document.getElementById("Enviar").disabled = true;
	document.getElementById("Enviar").value = "Aguarde..."	
}

function excluir() {
  var x = confirm("Tem certeza que deseja excluir?");
  return x;
}

function excluirGrupo(){
  var x = confirm("Existem usuários cadastrados para este grupo! Você tem certeza que deseja excluir?");
  return x;
}

function excluirProjeto(){
  var x = confirm("Esta operação implicará na exclusão de todo o conteúdo do projeto. Você tem certeza que deseja excluir?");
  return x;
}

function VereficaUserExist(){
	document.getElementById('msgUser').innerHTML='<img border=0 src=imagens/icon/load.gif width="13px"  align=bottom>';
	oAjax('userExist.php','fromUsuarios');
}	

function VerifAcoes(quem, id){
	oAjax('VerifAcoes.php?quem='+quem+'&id='+id,'fromProjetos');
}





function BuscaUsers(id,acao,idProjeto){

		//document.getElementById('user').innerHTML = '';
/*		var selecionados = document.getElementById('user');
        for(i=0; i<=selecionados.length; i++){
			 selecionados.options[i] = null;
        }	*/	
		var id3 = 0;
	    selecionados = document.getElementById('usuarios');
        for(i=0; i<=selecionados.length-1; i++){
			 id3 += ','+selecionados[i].value;
        }		
	oAjax('BuscaUsers.php?id='+id+'&acao='+acao+'&idProjeto='+idProjeto+'&usuarios='+id3,'fromProjetos');
}
function VereficaColorExist(id){
	oAjax('colorExist.php?id='+id,'fromGraficos');
}	
function validarFormTitulo(id){
	nome = document.getElementById(id);
	if(nome.value == '' || nome.value == 'NOVO ITEM'){
		alert('Preencha o campo Título.');
		nome.focus();
		return false;
	}		
	document.getElementById("Enviar").disabled = true;
	document.getElementById("Enviar").value = "Aguarde..."		
}

function validarFormTituloMessage(id,message){
	nome = document.getElementById(id);
	if(nome.value == '' || nome.value == 'NOVO ITEM'){
		alert('Preencha o campo '+message);
		nome.focus();
		return false;
	}		
	document.getElementById("Enviar").disabled = true;
	document.getElementById("Enviar").value = "Aguarde..."		
}

function validarFormGraficoEtapa_2(){
	nome = document.getElementById('titulo');
	cor = document.getElementById('rgb');
	if(nome.value == '' || nome.value == 'NOVO ITEM'){
		alert('Preencha o campo título.');
		nome.focus();
		return false;

	}
	if(cor.value == ''){
		alert('É necessario escolher uma cor');
		return false;
	}		
	document.getElementById("Enviar").disabled = true;
	document.getElementById("Enviar").value = "Aguarde..."		
}

function ValNome(){
	nome = document.getElementById("nome");
	if(nome.value == ''){
		document.getElementById('msgNome').innerHTML='&nbsp;<img src=imagens/icon/erro_peq.png align=bottom>';
		alert('Preencha o campo nome.');
		nome.focus();
		return false;
	}else{
		document.getElementById('msgNome').innerHTML='&nbsp;<img src=imagens/icon/yes.png align=bottom>';
	}
		
}

function ValUsuario(){
	usuario = document.getElementById("usuario");
	if (usuario.value == '') {
		document.getElementById('msgUser').innerHTML = '&nbsp;<img src=imagens/icon/erro_peq.png align=bottom>';
		alert('Preencha o campo Usuário.');
		usuario.focus();
		return false;
	}
	else {
		
		if (usuario.value.length < 3) {
			document.getElementById('msgUser').innerHTML = '&nbsp;<img src=imagens/icon/erro_peq.png align=bottom>';
			alert('O campo Usuário deve ter no minimo 3 caracters.');
			usuario.focus();
			return false;
		}
		else {
			document.getElementById('msgUser').innerHTML = '&nbsp;<img src=imagens/icon/yes.png align=bottom>';
		}
	}

}

function ValSenha(newSenha){
	senha = document.getElementById("senha");
	senha2 = document.getElementById("senha2");
	
	if (newSenha == 'SIM' || senha.value != '') {
		if ((senha.value != senha2.value)) {
			document.getElementById('msgSenha').innerHTML = '&nbsp;<img src=imagens/icon/erro_peq.png align=bottom>';
			document.getElementById('msgSenha2').innerHTML = '&nbsp;<img src=imagens/icon/erro_peq.png align=bottom>';
			alert('As senhas digitadas não conferem.');
			senha.value = null;
			senha2.value = null;
			senha.focus();
			return false;
		}
		else {
			document.getElementById('msgSenha').innerHTML = '&nbsp;<img src=imagens/icon/yes.png align=bottom>';
			document.getElementById('msgSenha2').innerHTML = '&nbsp;<img src=imagens/icon/yes.png align=bottom>';
		}
		if (senha.value == '' || senha2.value == '') {
			document.getElementById('msgSenha').innerHTML = '&nbsp;<img src=imagens/icon/erro_peq.png align=bottom>';
			document.getElementById('msgSenha2').innerHTML = '&nbsp;<img src=imagens/icon/erro_peq.png align=bottom>';
			alert('Preencha o campo senha.')
			senha.focus();
			return false;
		}
		else {
			document.getElementById('msgSenha').innerHTML = '&nbsp;<img src=imagens/icon/yes.png align=bottom>';
			document.getElementById('msgSenha2').innerHTML = '&nbsp;<img src=imagens/icon/yes.png align=bottom>';
		}
		if (senha.value.length < 2) {
			document.getElementById('msgSenha').innerHTML = '&nbsp;<img src=imagens/icon/erro_peq.png align=bottom>';
			document.getElementById('msgSenha2').innerHTML = '&nbsp;<img src=imagens/icon/erro_peq.png align=bottom>';
			alert('O campo senha deve ter no minimo 2 caracters.');
			senha.focus();
			return false;
		}
		else {
			document.getElementById('msgSenha').innerHTML = '&nbsp;<img src=imagens/icon/yes.png align=bottom>';
			document.getElementById('msgSenha2').innerHTML = '&nbsp;<img src=imagens/icon/yes.png align=bottom>';
		}
	}
}
function ValidaFromUsuario(newSenha){
	nome = document.getElementById("nome");
	if (nome.value == '') {
		document.getElementById('msgNome').innerHTML = '&nbsp;<img src=imagens/icon/erro_peq.png align=bottom>';
		alert('Preencha o campo nome.');
		nome.focus();
		return false;
	}
	else {
		document.getElementById('msgNome').innerHTML = '&nbsp;<img src=imagens/icon/yes.png align=bottom>';
	}
	usuario = document.getElementById("usuario");
	if (usuario.value == '') {
		document.getElementById('msgUser').innerHTML = '&nbsp;<img src=imagens/icon/erro_peq.png align=bottom>';
		alert('Preencha o campo Usuário.');
		usuario.focus();
		return false;
	}
	else {
	
		if (usuario.value.length < 3) {
			document.getElementById('msgUser').innerHTML = '&nbsp;<img src=imagens/icon/erro_peq.png align=bottom>';
			alert('O campo Usuário deve ter no minimo 3 caracters.');
			usuario.focus();
			return false;
		}
		else {
			document.getElementById('msgUser').innerHTML = '&nbsp;<img src=imagens/icon/yes.png align=bottom>';
		}
	}
	senha = document.getElementById("senha");
	senha2 = document.getElementById("senha2");
	
	if (newSenha == 'SIM' || senha.value != '') {
		if ((senha.value != senha2.value)) {
			document.getElementById('msgSenha').innerHTML = '&nbsp;<img src=imagens/icon/erro_peq.png align=bottom>';
			document.getElementById('msgSenha2').innerHTML = '&nbsp;<img src=imagens/icon/erro_peq.png align=bottom>';
			alert('As senhas digitadas não conferem.');
			senha.value = null;
			senha2.value = null;
			senha.focus();
			return false;
		}
		else {
			document.getElementById('msgSenha').innerHTML = '&nbsp;<img src=imagens/icon/yes.png align=bottom>';
			document.getElementById('msgSenha2').innerHTML = '&nbsp;<img src=imagens/icon/yes.png align=bottom>';
		}
		if (senha.value == '' || senha2.value == '') {
			document.getElementById('msgSenha').innerHTML = '&nbsp;<img src=imagens/icon/erro_peq.png align=bottom>';
			document.getElementById('msgSenha2').innerHTML = '&nbsp;<img src=imagens/icon/erro_peq.png align=bottom>';
			alert('Preencha o campo senha.')
			senha.focus();
			return false;
		}
		else {
			document.getElementById('msgSenha').innerHTML = '&nbsp;<img src=imagens/icon/yes.png align=bottom>';
			document.getElementById('msgSenha2').innerHTML = '&nbsp;<img src=imagens/icon/yes.png align=bottom>';
		}
		if (senha.value.length < 2) {
			document.getElementById('msgSenha').innerHTML = '&nbsp;<img src=imagens/icon/erro_peq.png align=bottom>';
			document.getElementById('msgSenha2').innerHTML = '&nbsp;<img src=imagens/icon/erro_peq.png align=bottom>';
			alert('O campo senha deve ter no minimo 2 caracters.');
			senha.focus();
			return false;
		}
		else {
			document.getElementById('msgSenha').innerHTML = '&nbsp;<img src=imagens/icon/yes.png align=bottom>';
			document.getElementById('msgSenha2').innerHTML = '&nbsp;<img src=imagens/icon/yes.png align=bottom>';
		}
	}
	return validaEmail('email');
	document.getElementById('Enviar').disabled = true; 
	document.getElementById('Enviar').value = 'Aguarde...';
	return true;
}



function moveitem(itemselected,where,objeto,itemlock) {
	objselect = document.getElementById(objeto);
	if (itemselected >= 0) {
		if (objselect.options[itemselected].value == itemlock) {
			if (where == "up") {
				if (itemselected > 0) {
					itemaux_value = objselect.options[itemselected].value;
					itemaux_text = objselect.options[itemselected].text;
					objselect.options[itemselected].value = objselect.options[itemselected-1].value;
					objselect.options[itemselected].text = objselect.options[itemselected-1].text;
					objselect.options[itemselected-1].value = itemaux_value;
					objselect.options[itemselected-1].text = itemaux_text;
					objselect.selectedIndex=itemselected-1;
					document.forms[0].posnovoitem.value = parseFloat(document.forms[0].posnovoitem.value)-1;
				}
			}
			if (where == "down") {
				if (itemselected < objselect.length-1) {
					itemaux_value = objselect.options[itemselected].value;
					itemaux_text = objselect.options[itemselected].text;
					objselect.options[itemselected].value = objselect.options[itemselected+1].value;
					objselect.options[itemselected].text = objselect.options[itemselected+1].text;
					objselect.options[itemselected+1].value = itemaux_value;
					objselect.options[itemselected+1].text = itemaux_text;
					objselect.selectedIndex=itemselected+1;
					document.forms[0].posnovoitem.value = parseFloat(document.forms[0].posnovoitem.value)+1;
				}
			}
			strpos = "";
			totalitens = objselect.length;
			for (i=0;i<totalitens;i++) {
				strpos = strpos+objselect.options[i].value+";"
			}
			document.forms[0].positens.value = strpos;
		}
	}
}
function enviatitulo(Objtitulo) {
	if (Objtitulo.value.length < 1) {
		Objtitulo.value = "";
	}
	var Objordem = document.getElementById("ordem");
	if (Objordem != null) {
		document.forms[0].ordem.options[document.forms[0].ordem.selectedIndex].text = '-> '+Objtitulo.value;
	}
}
function checktitulo(Objtitulo) {
	if (Objtitulo.value == "" ) {
		Objtitulo.value = "";
	}
}

function formataMoeda_1_casas(campo, separador_milhar, separador_decimal, tecla) {
	if(tecla.charCode == 45) return true;
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '-0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? tecla.which : tecla.keyCode;
	if (whichCode == 13) return true; // Tecla Enter
	if (whichCode == 8) return true; // Tecla Delete
	if (whichCode == 0) return true;
	if (campo.value.length > 14) return false;
	key = String.fromCharCode(whichCode); // Pegando o valor digitado
	if (strCheck.indexOf(key) == -1) return false; // Valor inválido (não inteiro)
	len = campo.value.length;
	for(i = 0; i < len; i++)
	if ((campo.value.charAt(i) != '0') && (campo.value.charAt(i) != separador_decimal)) break;
	aux = '';
	for(; i < len; i++)
	if (strCheck.indexOf(campo.value.charAt(i))!=-1) aux += campo.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) campo.value = '';
	if (len == 1) campo.value = '0'+ separador_decimal + aux;

	if (len > 1) {
		aux2 = '';
		for (j = 0, i = len - 2; i >= 0; i--) {
			if (j == 2) {
				aux2 += separador_milhar;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		campo.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
		campo.value += aux2.charAt(i);
		campo.value += separador_decimal + aux.substr(len - 1, len);
	}
	return false;
}

// 2 casas decimais
function formataMoeda(campo, separador_milhar, separador_decimal, tecla) {
	if(tecla.charCode == 45) return true;
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '-0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? tecla.which : tecla.keyCode;
	if (whichCode == 13) return true; // Tecla Enter
	if (whichCode == 8) return true; // Tecla Delete
	if (whichCode == 0) return true;
	if (campo.value.length > 14) return false;
	key = String.fromCharCode(whichCode); // Pegando o valor digitado
	if (strCheck.indexOf(key) == -1) return false; // Valor inválido (não inteiro)
	len = campo.value.length;
	for(i = 0; i < len; i++)
	if ((campo.value.charAt(i) != '0') && (campo.value.charAt(i) != separador_decimal)) break;
	aux = '';
	for (; i < len; i++) 
		if (strCheck.indexOf(campo.value.charAt(i)) != -1)
			aux += campo.value.charAt(i);

	aux += key;
	len = aux.length;
	if (len == 0) campo.value = '';
	if (len == 1) campo.value = '0'+ separador_decimal + '0' + aux;
	if (len == 2) campo.value = '0'+ separador_decimal + aux;

	if (len > 2) {
		aux2 = '';
		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += separador_milhar;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		campo.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
		campo.value += aux2.charAt(i);
		campo.value += separador_decimal + aux.substr(len - 2, len);
	}
	return false;
}

function formataMoeda_3_casas(campo, separador_milhar, separador_decimal, tecla) {
	if(tecla.charCode == 45) return true;
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '-0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? tecla.which : tecla.keyCode;
	if (whichCode == 13) return true; // Tecla Enter
	if (whichCode == 8) return true; // Tecla Delete
	if (whichCode == 0) return true;
	if (campo.value.length > 14) return false;
	key = String.fromCharCode(whichCode); // Pegando o valor digitado
	if (strCheck.indexOf(key) == -1) return false; // Valor inválido (não inteiro)
	len = campo.value.length;
	for(i = 0; i < len; i++)
	if ((campo.value.charAt(i) != '0') && (campo.value.charAt(i) != separador_decimal)) break;
	aux = '';
	for(; i < len; i++)
	if (strCheck.indexOf(campo.value.charAt(i))!=-1) aux += campo.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) campo.value = '';
	if (len == 1) campo.value = '0'+ separador_decimal + '00' + aux;
	if (len == 2) campo.value = '0'+ separador_decimal + '0' + aux;
	if (len == 3) campo.value = '0'+ separador_decimal + aux;

	if (len > 3) {
		aux2 = '';
		for (j = 0, i = len - 4; i >= 0; i--) {
			if (j == 4) {
				aux2 += separador_milhar;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		campo.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
		campo.value += aux2.charAt(i);
		campo.value += separador_decimal + aux.substr(len - 3, len);
	}
	return false;
}


function formataMoeda_4_casas(campo, separador_milhar, separador_decimal, tecla) {
	if(tecla.charCode == 45) return true;
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '-0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? tecla.which : tecla.keyCode;
	if (whichCode == 13) return true; // Tecla Enter
	if (whichCode == 8) return true; // Tecla Delete
	if (whichCode == 0) return true;
	if (campo.value.length > 14) return false;
	key = String.fromCharCode(whichCode); // Pegando o valor digitado
	if (strCheck.indexOf(key) == -1) return false; // Valor inválido (não inteiro)
	len = campo.value.length;
	for(i = 0; i < len; i++)
	if ((campo.value.charAt(i) != '0') && (campo.value.charAt(i) != separador_decimal)) break;
	aux = '';
	for(; i < len; i++)
	if (strCheck.indexOf(campo.value.charAt(i))!=-1) aux += campo.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) campo.value = '';
	if (len == 1) campo.value = '0'+ separador_decimal + '000' + aux;
	if (len == 2) campo.value = '0'+ separador_decimal + '00' + aux;
	if (len == 3) campo.value = '0'+ separador_decimal + '0' + aux;
	if (len == 4) campo.value = '0'+ separador_decimal + aux;

	if (len > 4) {
		aux2 = '';
		for (j = 0, i = len - 5; i >= 0; i--) {
			if (j == 5) {
				aux2 += separador_milhar;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		campo.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
		campo.value += aux2.charAt(i);
		campo.value += separador_decimal + aux.substr(len - 4, len);
	}
	return false;
}

function Verifica_Hora(quem){ 
	hrs = (document.getElementById(quem).value.substring(0,2)); 
	min = (document.getElementById(quem).value.substring(3,5)); 
				   
	estado = ""; 
	if ((hrs < 00 ) || (hrs > 23) || ( min < 00) ||( min > 59)){ 
		estado = "errada"; 
	} 
				   
	if (document.getElementById(quem).value == "") { 
		estado = "errada"; 
	} 
	
	if (estado == "errada") { 
		alert("Hora inválida!"); 
		document.getElementById(quem).focus(); 
	} 
} 

function Mascara_Hora(hora,quem){ 
	var hora01 = ''; 
	hora01 = hora01 + hora; 
	if (hora01.length == 2){ 
		hora01 = hora01 + ':'; 
		document.getElementById(quem).value = hora01; 
	} 
	if (hora01.length == 5){ 
		Verifica_Hora(quem); 
	} 
} 
function AddItem(ObjLista){
	if (ObjLista.length < 10) {
		with(document.form_addcat) {
			string_mail = email.value; // string onde sera feita a procura
			letra1 = "@"; // letra para buscar
			letra2 = "."; // letra para buscar
			pos1 = string_mail.indexOf(letra1);
			pos2 = string_mail.indexOf(letra2);
			if ((email.value.length < 6) || (pos1 < 1) || (pos2 < 1) || (pos1==email.value.length-1) || (pos2==email.value.length-1)){
				alert("Por favor, informe um e-mail correto.");
				email.focus();
			}
			else {
				VarItem = email.value;
				i = ObjLista.options.length;
				ObjLista.options[i] = new Option(VarItem,VarItem);
				email.value = "";
				ConcatItens(ObjLista);
			}
		}
	}
	else {
		alert("Limite de e-mails atingido: 10");
	} 
}

function RemoveItem(ObjLista){
	if (ObjLista.options.length >= 1) {
		var i = ObjLista.selectedIndex;
		if (i > -1) {
			if (confirm("Deseja excluir o item selecionado?")){
				

				ObjLista.remove(i);
				ConcatItens(ObjLista);
			}
		}
		else {
			alert("Nenhum item foi selecionado!");
		}
	}
	else {
		alert("Não existem itens para serem excluídos!");
	}
}
function ConcatItens(ObjLista) {
	i = ObjLista.options.length;
	with(document.form_addcat){
		enviarpara.value = "";
		for (x=0;x<i;x++) {
			if(x == i-1) {
				enviarpara.value=enviarpara.value+ObjLista.options[x].value+"";
			}
			else {
				enviarpara.value=enviarpara.value+ObjLista.options[x].value+",";
			}
		}
		//alert(document.form_addcat.enviarpara.value);
	}
	document.getElementById("limite").innerHTML = x;
}

function ValDataInicioRelacaoProjeto(prevInicio,quem){
					
	dataInicio_value = document.getElementById(quem).value;
	if (dataInicio_value  != ''){
		if (dataInicio_value == '--') {
		}
		else {
			dia = dataInicio_value.substr(0, 2);
			mes = dataInicio_value.substr(3, 2);
			ano = dataInicio_value.substr(6, 4);
			
			dataInicio = ano + '-' + mes + '-' + dia;
			if (dataInicio < prevInicio) {
				alert('Desculpe mas a data da ação não confere com a data de previsão de inicio do projeto');
				document.getElementById(quem).value = '';
				document.getElementById(quem).focus();
				return false;
			}
			else {
				return true;
			}
		}
	}
}
function ValDataFimRelacaoProjeto(prevFim, quem){

		dataFim_value = document.getElementById(quem).value;
		
		if (dataFim_value != '') {
					if (dataFim_value == '--') {
					}
					else {
						dia = dataFim_value.substr(0, 2);
						mes = dataFim_value.substr(3, 2);
						ano = dataFim_value.substr(6, 4);
						dataFim = ano + '-' + mes + '-' + dia;
						
						if (dataFim > prevFim) {
							alert('Desculpe mas a data da ação não confere com a data de previsão de fim do projeto');
							document.getElementById(quem).value = '';
							document.getElementById(quem).focus();
							return false;
						}
						else {
							return true;
						}
					}
		}
}

function valPrevDataFim(){
	
	prevDataFim_value = document.getElementById('prevDataFim').value;
	prevDataInicio_value = document.getElementById('prevDataInicio').value;

	dia = prevDataInicio_value.substr(0,2);
	mes = prevDataInicio_value.substr(3,2);
	ano = prevDataInicio_value.substr(6,4); 	
	pervDataInicio = ano+'-'+mes+'-'+dia;	
	
	dia = prevDataFim_value.substr(0,2);
	mes = prevDataFim_value.substr(3,2);
	ano = prevDataFim_value.substr(6,4); 	
	pervDataFim = ano+'-'+mes+'-'+dia;
	
	if(pervDataFim < pervDataInicio){
		alert('A previsão de fim deve ser inferior a da previsão de inicio.');
		document.getElementById('prevDataFim').value = '';
		document.getElementById('prevDataFim').focus;
	}
	
} 

function valDataFim(){
	
	DataFim_value = document.getElementById('dataFim').value;
	DataInicio_value = document.getElementById('dataInicio').value;

	dia = DataInicio_value.substr(0,2);
	mes = DataInicio_value.substr(3,2);
	ano = DataInicio_value.substr(6,4); 	
	DataInicio = ano+'-'+mes+'-'+dia;	
	
	dia = DataFim_value.substr(0,2);
	mes = DataFim_value.substr(3,2);
	ano = DataFim_value.substr(6,4); 	
	DataFim = ano+'-'+mes+'-'+dia;
	
	if(DataFim < DataInicio){
		alert('A data de fim deve ser inferior a da data de inicio.');
		document.getElementById('dataFim').value = '';
		document.getElementById('dataFim').focus;
	}
	
} 


function completarComMeses(){
	document.getElementById('titulo1').value = 'Janeiro';
	document.getElementById('titulo2').value = 'Fevereiro';
	document.getElementById('titulo3').value = 'Março';
	document.getElementById('titulo4').value = 'Abril';
	document.getElementById('titulo5').value = 'Maio';
	document.getElementById('titulo6').value = 'Junho';
	document.getElementById('titulo7').value = 'Julho';
	document.getElementById('titulo8').value = 'Agosto';
	document.getElementById('titulo9').value = 'Setembro';
	document.getElementById('titulo10').value = 'Outubro';
	document.getElementById('titulo11').value = 'Novembro';
	document.getElementById('titulo12').value = 'Dezembro';
}


function validaDiaAtualizar(quem){

	switch (quem) {
		case "0":
			document.getElementById('inicioTXT').style.display = 'none';
		break;
		case "1":
			document.getElementById('inicioTXT').style.display = 'inline';
			document.getElementById('nameInicio').innerHTML = 'da Semana';
		break;
		case "2":
			document.getElementById('inicioTXT').style.display = 'inline';
			document.getElementById('nameInicio').innerHTML = 'da Quinzena';	
		break;
		case "3":
			document.getElementById('inicioTXT').style.display = 'inline';
			document.getElementById('nameInicio').innerHTML = 'do Mes';
		break;
		case "4":
			document.getElementById('inicioTXT').style.display = 'inline';
			document.getElementById('nameInicio').innerHTML = 'do Semestre';
		break;
		case "5":
			document.getElementById('inicioTXT').style.display = 'inline';
			document.getElementById('nameInicio').innerHTML = 'do Ano';
		break;

	}
	
	return true;	
}

function exibirTotalGraficos(quem){
	if(quem == 'M'){
		document.getElementById('exibir').innerHTML = 'o Total';
	}
	if(quem == 'T'){
		document.getElementById('exibir').innerHTML = 'a M&eacute;dia';
	}	
			
}

function valSubAcoesFases(){
	sub = document.getElementById('sub').value;
	

	
	if(sub != 'null'){
		document.getElementById('fase').disabled = true;
	}else if(sub == 'null'){
		document.getElementById('fase').disabled = false;
	}
	
}
function valFrequencia(valor){
	
	if(valor == 1){
		document.getElementById('aviso_projetoinicio').checked = false;
		document.getElementById('aviso_projetofim').checked = false;
		document.getElementById('aviso_acaoinicio').checked = false;
		document.getElementById('aviso_acaofim').checked = false;
		document.getElementById('aviso_grafico').checked = false;
	}
}

function SelecionePerspectiva(){
	if (document.getElementById('perspectiva').value == 0) {
		alert('Selecione uma perspectiva.');
		return false;
	}
}

function ValidaFromTemas(){
	if(SelecionePerspectiva() == false) return false;
	if(validarFormTitulo('titulo') == false) return false;
	Enviar();	
}
function SelecioneTema(){
	if (document.getElementById('estrategia').value == 0) {
		alert('Selecione um tema.');
		return false;
	}
}

function ValidaFromObjetivos(){
	if(SelecioneTema() == false) return false;
	if(validarFormTitulo('titulo') == false) return false;
	Enviar();	
};








function validaFormAcoes(prevDataInicio,dataInicio,prevDataFim,dataFim){
	
	nome = document.getElementById('titulo');
	if(nome.value == ''){
		alert('Preencha o campo Título.');
		nome.focus();
		return false;
	}		
		
//<?php echo $row_projetos['prevdatainicio']; ?>
//prevdatainicio
if(ValDataInicioRelacaoProjeto(''+prevDataInicio+'','prevDataInicio') == false){
		return false;
	}
//<?php echo $row_projetos['prevdatainicio']; ?>
//datainicio
if(ValDataInicioRelacaoProjeto(''+dataInicio+'','dataInicio') == false){
		return false;
	}
//<?php echo $row_projetos['prevdatafim']; ?>
//prevdatafim
if(ValDataFimRelacaoProjeto(''+prevDataFim+'','prevDataFim') == false){
		return false;
	}
//<?php echo $row_projetos['prevdatafim']; ?>
//dataFim
if(ValDataFimRelacaoProjeto(''+dataFim+'','dataFim') == false){
		return false;
	}


	document.getElementById("Enviar").disabled = true;
	document.getElementById("Enviar").value = "Aguarde..."		

}

function carregando(id, texto){
		document.getElementById(id).innerHTML=texto;
}
function oAjax(pagina,idform){
	_getAjax(pagina,document.getElementById(idform));
}
function VerificaData(digData) {
    var bissexto = 0;
    var data = digData; 
    var tam = data.length;
    if (tam == 10){
        var dia = data.substr(0,2)
        var mes = data.substr(3,2)
        var ano = data.substr(6,4)
        if ((ano > 1900)||(ano < 2100)){
            switch (mes) {
                case '01':
                case '03':
                case '05':
                case '07':
                case '08':
                case '10':
                case '12':
                    if  (dia <= 31){
                            return true;
                    }
                    break
                case '04':              
                case '06':
                case '09':
                case '11':
                    if  (dia <= 30){
                            return true;
                    }
                    break
                case '02':
                    /* Validando ano Bissexto / fevereiro / dia */ 
                    if ((ano % 4 == 0) || (ano % 100 == 0) || (ano % 400 == 0)){ 
                    	bissexto = 1; 
                    } 
                    if ((bissexto == 1) && (dia <= 29)){ 
                    	return true;                             
                    } 
                    if ((bissexto != 1) && (dia <= 28)){ 
                    	return true; 
                    }                       
                    break
            }
        }
    }       
    alert("A data "+data+" é inválida!");
    return false;
}

