var xmlHttp;

function gid(element) {
	return getElementById(element);
}

function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}

function ajax(pagina,div,names,values) {
createXMLHttpRequest();
xmlHttp.onreadystatechange = function () {
if(xmlHttp.readyState==1){ document.getElementById(div).innerHTML= "<img src='http://www.ecaderno.com/indicator.gif' width='16' height='16' alt='carregando...'>";}	
else 
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
document.getElementById(div).innerHTML = xmlHttp.responseText;

}
}
}
var value;
value=values.split(",");
var name;
name=names.split(",");

var gets="";

for (var i=0;i<name.length;i++)
{ gets=gets+name[i]+"="+value[i]+"&";}

gets=gets+"get=get";

xmlHttp.open("get", pagina + ".php?" + gets, true);
xmlHttp.send(null);
}

///////////


function ajaxPost(pagina,div,campos) {
createXMLHttpRequest();
xmlHttp.onreadystatechange = function () {
if(xmlHttp.readyState==1){ document.getElementById(div).innerHTML= "<img src='indicator.gif'>";}	
else 
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
document.getElementById(div).innerHTML = xmlHttp.responseText;

}
}
}

var campo;
campo=campos.split(",");

var par="post=post";

for (var i=0;i<campo.length;i++)
{ par=par+"&"+campo[i]+"="+encodeURI( document.getElementById(campo[i]).value ); }

xmlHttp.open("post", pagina + ".php", true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", par.length);
xmlHttp.setRequestHeader('Content-Type', "application/x-www-form-urlencoded; charset=utf-8");
xmlHttp.send(par);
}



function validaFormAuto(form)
{
  for (i=0;i<form.length;i++)
{
  if (form[i].value == "")
  {
    if (form[i].id.length > 0)
      {
        var nome = form[i].name.substring(1,form[i].name.length);
        var ident = form[i].id;
        alert("Preencha o campo " + ident + ".");
        form[i].focus();
        return false
      }
    }
  }
return true
}

function hide(div_id) {
	var div_id;
	document.getElementById(div_id).style.display='none';
}

function show(div_id) {
	var div_id;
	document.getElementById(div_id).style.display='block';
}

function desabilita(campos) {
	var campo;
	campo=campos.split(",");
	
	for (var i=0;i<campo.length;i++)
	{ 
	var div_id=campo[i];
	document.getElementById(div_id).disabled=true;
	}
}

function habilita(campos) {
	var campo;
	campo=campos.split(",");
	
	for (var i=0;i<campo.length;i++)
	{ 
	var div=campo[i];
	document.getElementById(div).disabled=false;
	}
}

function checkEmptyNames(campos,nomes)
{
	var campo;
	var divid;
	campo=campos.split(",");
	
	if (nomes!=null)
	{nome=nomes.split(",");}
	else
	{nome=campo;}
	
	for (var i=0;i<campo.length;i++)
	{ 
	divid=campo[i];
	if (document.getElementById(divid).value=='')
	{
		alert('Insira '+nome[i]+'.');
		document.getElementById(divid).focus();
		return false;
		}
	}
	
  return true
}

function limpa(ident,valor) {
    var valor
	var ident
	var campo=document.getElementById(ident).value;
	
	if (campo==valor)
	{document.getElementById(ident).value="";}
	
}

function mostra(ident,valor) {
 	var valor
	var ident
	var campo=document.getElementById(ident).value;
	
	if (campo=="")
	{document.getElementById(ident).value=valor; }
}

function fill(ident,valor) {
	var ident;
	var valor;
	
	if (valor!="" && document.getElementById(ident))
	{document.getElementById(ident).value=valor;}

	}
