// JavaScript Document

var box;
var box2;

function handleHttpResponse()
{
  if (http.readyState == 4) {
    document.getElementById(box).innerHTML = http.responseText;
  }
}

function handleHttpResponse2()
{	
  if (http2.readyState == 4) {	  
	document.getElementById(box2).innerHTML = http2.responseText;
  }
}

function handleHttpResponse3()
{	
  if (http3.readyState == 4) {	  
	document.getElementById(box3).innerHTML = http3.responseText;
  }
}

function executaAjax(parametro, valor, idlocal)
{
	if(parametro == 0)
	{
		return false;
	}
	http = getHTTPObject();
	box = idlocal;
	http.open("GET", valor, true);
	document.getElementById(idlocal).innerHTML = '<div style="width: 100%; height: 200px; padding-top: 150px; text-align:center; float: left;"><img src="img/loadinfo_grande.gif" align="absmiddle"></div>';
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
}
function executaAjax2(parametro, valor, idlocal)
{
	if(parametro == 0)
	{
		return false;
	}
	
	http2 = getHTTPObject();
	box2 = idlocal;
	http2.open("GET", valor, true);	
	document.getElementById(idlocal).innerHTML = '<div style="width: 100%; text-align:center; float: left;"></div>';
	
	http2.onreadystatechange = handleHttpResponse2;
	 
	http2.send(null);
	
}
function executaAjax3(parametro, valor, idlocal)
{
	if(parametro == 0)
	{
		return false;
	}
	
	http3 = getHTTPObject();
	box3 = idlocal;
	http3.open("GET", valor, true);	
	document.getElementById(idlocal).innerHTML = '<div style="width: 100%; padding-top: 50px; text-align:center; float: left;"><img src="img/loadinfo_medio.gif" align="absmiddle"></div>';
	
	http3.onreadystatechange = handleHttpResponse3;
	 
	http3.send(null);
	
}

function getHTTPObject() 
{
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }

  }
  return xmlhttp;
}
var http = getHTTPObject();

function validarForm(form)
{
	var form;
	var elementosForm = new Array();
	var elementosFormSelect = new Array();
	var arrayCamposVazios = new Array();
	var elementosFormTextarea = new Array();
	var string;
	elementosForm = document.forms[form].getElementsByTagName('input');	
	for(var i = 0; i < elementosForm.length; i++)
	{
		if(elementosForm[i].alt.substr(0, 1) != '*')
		{			
			if(elementosForm[i].value.length == 0)
			{
				arrayCamposVazios.push(elementosForm[i].alt);
			}
		}
	}
	
	elementosFormSelect = document.forms[form].getElementsByTagName('select');	 
	for(var i = 0; i < elementosFormSelect.length; i++)
	{		
		if(elementosFormSelect[i].value == '')
		{
			arrayCamposVazios.push(elementosFormSelect[i].title);
		}
	}
	
	elementosFormTextarea = document.forms[form].getElementsByTagName('textarea');	 
	for(var i = 0; i < elementosFormTextarea.length; i++)
	{		
		if(elementosFormTextarea[i].value == '')
		{
			arrayCamposVazios.push(elementosFormTextarea[i].title);
		}
	}
	
	if(arrayCamposVazios.length > 0)
	{
		string = 'Para prosseguir é necessário o preenchimento dos seguintes campos: <br /><br /><ul>';
		for(var i = 0; i < arrayCamposVazios.length; i++)
		{
			string += '<li>'+arrayCamposVazios[i]+'</li>';
		}
		string += '</ul>';
		invocaDialog(1, 'Campos de preenchimento obrigatório', string);
		return false;
	}
	else
	{
		return true;
	}	
}

function mostrarById(identificador,div,nLinks)
{		
	var divDestino = div;
	var numeroLinks = nLinks;
	var idPadrao = identificador;
					
	var arrayDiv = new Array(numeroLinks);
	
	for (y=0;y<numeroLinks;y++)
	{
		arrayDiv[y] = idPadrao + (y+1);
	}
	
	for (i=0;i<numeroLinks;i++)
	{		
		if(arrayDiv[i] == divDestino)
		{
			if (document.getElementById(arrayDiv[i]).className == 'displayVisible')
			{
				return false;
			}
			else
			{
				document.getElementById(arrayDiv[i]).className = 'displayVisible';
			}
		}
		else
		{
			document.getElementById(arrayDiv[i]).className = 'displayNone';
		}
	}
}

