//------------------------------------------
function AlternaDiv(div1, div2) {

if(document.getElementById(div1).style.display == "none"){
		document.getElementById(div1).style.display = "";
		document.getElementById(div2).style.display = "none";
	}else{
		document.getElementById(div1).style.display = "none";
		document.getElementById(div2).style.display = "";
	}
}


function ExecAjax(valor, dest, TrocaTexto) {


  try {
	 ajax = new ActiveXObject("Microsoft.XMLHTTP");
  } 
  catch(e) {
	 try {
		ajax = new ActiveXObject("Msxml2.XMLHTTP");
	 }
	 catch(ex) {
		try {
		   ajax = new XMLHttpRequest();
		}
		catch(exc) {
		   alert("Esse browser não tem recursos para uso do Ajax");
		   ajax = null;
		}
	 }
  }
  if(ajax) {
	 
	 idOpcao  = document.getElementById("opcoes");
	 Div      = document.getElementById("DivCarregando");
	 //idOpcao.style.zIndex  = 100;
	 ajax.open("POST", dest, true);

	 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
	 
	 ajax.onreadystatechange = function() {
		if(ajax.readyState == 1) {

		Div.innerHTML = "<table align='center' cellpadding='2' cellspacing='1'>";
		Div.innerHTML = Div.innerHTML + " <tr>";
		Div.innerHTML = Div.innerHTML + "   <td align='center'>";
		Div.innerHTML = Div.innerHTML + " 		<img src='images/load.gif' width=32 height=32  align=absmiddle>";
		Div.innerHTML = Div.innerHTML + " 		&nbsp;&nbsp; Aguarde. Carregando...</td>";
		Div.innerHTML = Div.innerHTML + " </tr>";
		Div.innerHTML = Div.innerHTML + "</table>";
		Div.className = "DivCarregando";  

		}
		if(ajax.readyState == 4 ) {

			  idOpcao.style.visibility = "visible"; //Mostra a DIV caso esteja ocultada
			  idOpcao.innerHTML = ajax.responseText ;
			  Div.innerHTML = "";   
			  Div.className = "";  
			  if (TrocaTexto == 1 ) {
			  AlternaDiv ("EnviaRequisicao", "MostraRequisicao");
			  }
			   
		}
	 }

	 var params = "varID="+valor;
	 ajax.send(params);
  }
}


//---------------------------------------------------------------


function ExecAjaxClose() {
	 idOpcao  = document.getElementById("opcoes");
	 idOpcao.style.visibility  = "hidden";

}


//----------------- POPUP


function ExecPopUpAjax(valor, dest, w , h) {


  try {
	 ajax = new ActiveXObject("Microsoft.XMLHTTP");
  } 
  catch(e) {
	 try {
		ajax = new ActiveXObject("Msxml2.XMLHTTP");
	 }
	 catch(ex) {
		try {
		   ajax = new XMLHttpRequest();
		}
		catch(exc) {
		   alert("Esse browser não tem recursos para uso do Ajax");
		   ajax = null;
		}
	 }
  }
  if(ajax) {
	 
	 prin  = document.getElementById("principal");
	 Face  = document.getElementById("divPopup");
	 Texto = document.getElementById("divPopupConteudo");
	 Div   = document.getElementById("DivCarregando");
	 //idOpcao.style.zIndex  = 100;
	 ajax.open("POST", dest, true);

	 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
	 
	 ajax.onreadystatechange = function() {
		if(ajax.readyState == 1) {

		Div.innerHTML = "<table align='center' cellpadding='2' cellspacing='1'>";
		Div.innerHTML = Div.innerHTML + " <tr>";
		Div.innerHTML = Div.innerHTML + "   <td align='center'>";
		Div.innerHTML = Div.innerHTML + " 		<img src='images/load.gif' width=32 height=32  align=absmiddle>";
		Div.innerHTML = Div.innerHTML + " 		&nbsp;&nbsp; Aguarde. Carregando...</td>";
		Div.innerHTML = Div.innerHTML + " </tr>";
		Div.innerHTML = Div.innerHTML + "</table>";
		Div.className = "DivCarregando";  

		}
		if(ajax.readyState == 4 ) {

			  
			  Texto.style.width 	 = w;
			  Texto.style.height 	 = h;

			  Face.style.width 	= prin.offsetWidth ;
			  Face.style.height = prin.offsetHeight;

			  
			  if (w != 'auto') {
			  Texto.style.marginLeft = - (w / 2) ;
			  }
			  if (h != 'auto') {
			  Texto.style.marginTop  = - (h / 2);
			  }
			  
			  Texto.style.top  = (prin.offsetHeight / 2 );
			  Texto.style.left = '50%';

				Face.style.visibility  = "visible"; //Mostra a DIV caso esteja ocultada
			  Texto.style.visibility = "visible"; //Mostra a DIV caso esteja ocultada

			Texto.innerHTML = ajax.responseText ;
			  Div.innerHTML   = "";   
			  Div.className   = "";  
			 // AlternaDiv ("divConteudo", "divPopup");
			   
		}
	 }

	 var params = "varID="+valor;
	 ajax.send(params);
  }
}

function ExecPopUpAjaxClose() {
	 Face   = document.getElementById("divPopup");
	 Texto  = document.getElementById("divPopupConteudo");
	 Face.style.visibility  = "hidden";
	 Texto.style.visibility = "hidden"; 

}

