// JavaScript Document

function openAjax() {

var ajax;

try{
    ajax = new XMLHttpRequest();
}
catch(ee){
    try{
        ajax = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            ajax = new ActiveXObject("Microsoft.XMLHTTP");
        }
		catch(E){
            ajax = false;
        }
    }
}
return ajax;
}


function mostraDiv(div) {

document.getElementById(div).style.visibility="visible";
	
}

function ocultaDiv(div) {

document.getElementById(div).style.visibility="hidden";
	
}



function carregaArquivo(file, div, id) {

	var ajax = openAjax();
	idOpcao  = document.getElementById(div);
	ocultaDiv('divProjetos');
	
	ajax.open("GET", file, true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	ajax.onreadystatechange = function() {
	
	if(ajax.readyState == 1) {
	  
		mostraDiv('divStatus');
		
	}
	
	if(ajax.readyState == 4 ) {
	
		 if(ajax.status == 200 ) {


		  	var numero = 0;
			while (numero <= 15) {
				
				document.getElementById(numero).style.background="none";
				numero++;
				
			}
	  		
			document.getElementById(id).style.background="#BCE360";
			


			var resultado = ajax.responseText; 
			
			idOpcao.innerHTML = resultado;
			
				if (file == "includeCentro.asp") {
					
					parceiros();
						
				}
			
			ocultaDiv("divStatus");
			
		
		 } else {
		 
		 	idOpcao.innerHTML = "Ops, ocorreu um erro. Recarregue a página pressionando a tecla F5.";
			ocultaDiv("divStatus");
						 
		 }
		 
		 
	} 
	
	}
	
	ajax.send(null);
	
}





function carregaPublicador(file, div, id) {

	var ajax = openAjax();
	idOpcao  = document.getElementById(div);
	
	ajax.open("GET", file, true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	ajax.onreadystatechange = function() {
	
	if(ajax.readyState == 1) {
	  
		mostraDiv('divStatus');
		
	}
	
	if(ajax.readyState == 4 ) {
	
		 if(ajax.status == 200 ) {


		  	var numero = 0;
			while (numero <= 15) {
				
				document.getElementById(numero).style.background="none";
				numero++;
				
			}
	  		
			document.getElementById(id).style.background="#BCE360";
			


			var resultado = ajax.responseText; 
			
			idOpcao.innerHTML = resultado;
			ocultaDiv("divStatus");
			
		
		 } else {
		 
		 	idOpcao.innerHTML = "Ops, ocorreu um erro. Recarregue a página pressionando a tecla F5.";
			ocultaDiv("divStatus");
						 
		 }
		 
		 
	} 
	
	}
	
	ajax.send(null);
	
}




function carregaApresentacao(id, div) {

	
	mostraDiv('divStatus');
	
	var ajax = openAjax();
	idOpcao  = document.getElementById(div);
	idOpcao.style.visibility="visible";
	
	ajax.open("GET", "apresentaProjetos.asp?id=" + id, true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	ajax.onreadystatechange = function() {
	
	if(ajax.readyState == 1) {
	  
		idOpcao.innerHTML = "Aguarde, carregando informações...";
		
	}
	
	if(ajax.readyState == 4 ) {
	
		 if(ajax.status == 200 ) {


			var resultado = ajax.responseText; 
			idOpcao.innerHTML = resultado;
			ocultaDiv("divStatus");
			
		
		 } else {
		 
		 	idOpcao.innerHTML = "Erro ao carregar o arquivo !!!";
						 
		 }
		 
		 
	} 
	
	}
	
	ajax.send(null);
	
}





function carregaAgenda(id, div) {

	
	mostraDiv('divStatus');
	
	var ajax = openAjax();
	idOpcao  = document.getElementById(div);
	idOpcao.style.visibility="visible";
	
	ajax.open("GET", "apresentaAgenda.asp?id=" + id, true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	ajax.onreadystatechange = function() {
	
	if(ajax.readyState == 1) {
	  
		idOpcao.innerHTML = "Aguarde, carregando informações...";
		
	}
	
	if(ajax.readyState == 4 ) {
	
		 if(ajax.status == 200 ) {


			var resultado = ajax.responseText; 
			idOpcao.innerHTML = resultado;
			ocultaDiv("divStatus");
			
		
		 } else {
		 
		 	idOpcao.innerHTML = "Erro ao carregar o arquivo !!!";
						 
		 }
		 
		 
	} 
	
	}
	
	ajax.send(null);
	
}





function parceiros() {


	var ajax = openAjax();
	idOpcao  = document.getElementById("carregaParceiros");
	
	ajax.open("GET", "includeParceiros.asp", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	ajax.onreadystatechange = function() {
	
	if(ajax.readyState == 4 ) {
	
		 if(ajax.status == 200 ) {
		 
			var resultado = ajax.responseText; 
			idOpcao.innerHTML = resultado;

			
		
		 }
		 
	  } 
	
	}
	
	ajax.send(null);
	
}






function exclui(tabela, id) {

	if (confirm("Deseja excluir o registro ??")) {
	
		window.location='?acao=excluir&tabela=' + tabela + '&id=' + id;
	
	} else {
	
		return false;
	
	}

}




function ehNumerico(teclapres){
   if((teclapres.keyCode >= 48 && teclapres.keyCode <= 57) || (teclapres.keyCode >= 96 && teclapres.keyCode <= 105))
      return true;
   else
      return false;   
}

function ehNumericoPlus(teclapres){
   if (ehNumerico(teclapres) || teclapres.keyCode == 8 ||
       teclapres.keyCode == 37 || teclapres.keyCode == 39 ||
       teclapres.keyCode == 46 || teclapres.keyCode == 9)
      return true;
   else
      return false;   		
}


function FormataData(campo, tammax, teclapres) {
    
    if (!ehNumericoPlus(teclapres)) {
	   teclapres.returnValue = false;
	   return;  
	}   
			
	var tecla = teclapres.keyCode;
	vr = campo.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			campo.value = vr.substr( 0, tam - 2  ) + '-' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			campo.value = vr.substr( 0, 2 ) + '-' + vr.substr( 2, 2 ) + '-' + vr.substr( 4, 4 ); 
	}
	
	
}


function popup(nomePag) {

var WinSizeHor = 650;
var WinSizeVert = 450;

posHoriz = parseInt((screen.availWidth / 2) - parseInt(WinSizeHor / 2))
posVert = parseInt((screen.availHeight / 2) - parseInt(WinSizeVert / 2))

eval("win = window.open('" + nomePag + "', '' ,config='height=" + WinSizeVert + ",width=" + WinSizeHor + ",scrollbars=yes, statusbar=no, left=" + posHoriz + ", top=" + posVert + "')");
win.focus();

}
