
function Validar(objForm)
{
	var i, qtdeElementos;
	var bolValidar = true;
	
	qtdeElementos = objForm.elements.length;

	for (i=0; i<qtdeElementos; i++){
		var tamanho, titulo, isObrigatorio;
		titulo = objForm.elements[i].title
		tamanho = objForm.elements[i].value.length;
		isObrigatorio = objForm.elements[i].name.substr(3,1);

		if ((tamanho < 1) && (isObrigatorio == 'T'))
		{
			alert("O campo "+titulo+" não foi preenchido.");
			bolValidar = false;
		}
	}
	
	return bolValidar;
}

function new_ajax_get(div,valor)
{
	var carrega = document.getElementById(div);
	carrega.innerHTML = "Carregando...";
	var aspd = new AJAX();
	aspd.url = valor;
	aspd.processaresultado = function (recebe){
							var docu = document.getElementById(div);		
							docu.innerHTML = recebe;
						}
	aspd.conectar();
}

function showhide(id){
	if (document.getElementById)
	{
		obj = document.getElementById(id);
		if (obj.style.display == "none")
		{
		  obj.style.display = "";
		}
		else
		{
		  obj.style.display = "none";
		}
	}
}

function submitonce(theform)
{
	if (document.all||document.getElementById)
	{
		for (i=0;i<theform.length;i++)
		{
			var tempobj=theform.elements[i]
			if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
			{
			tempobj.disabled=true
			}
		}
		setTimeout('alert("O Formulario ja foi enviado")',2000)
	}
	else
	{
		alert("O Formulario ja foi enviado")
	}
	return false
}
// THIAGO
function trocarCorCampoListagem(tipo, obj)
{
	if (tipo == 'on')
	{
		obj.className = 'listagem_campos_over';
	}
	else
	{
		obj.className = 'listagem_campos';
	}
}

var strClasseLinhaListagem;
function trocarLinhaListagem(tipo, obj)
{
	if (tipo == 'on')
	{
		strClasseLinhaListagem = obj.className;
		obj.className = 'listagem_linha_over';
	}
	else
	{
		obj.className = strClasseLinhaListagem;
	}
}

try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}

function ajaxGet(url, element){
    //Abre a conexão
    xmlhttp.open("GET",url,true);
    //Função para tratamento do retorno
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4){
            //Mostra o HTML recebido
            retorno=unescape(xmlhttp.responseText.replace(/\+/g," "))
            document.getElementById(element).innerHTML=retorno
        }
    }
    //Executa
    xmlhttp.send(null)
}

function ajaxPost(url, element, form){
    //Abre a conexão
    xmlhttp.open("POST",url,true);
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;');

    //Função para tratamento do retorno
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4){
            //Mostra o HTML recebido
            retorno=unescape(xmlhttp.responseText.replace(/\+/g," "))
            document.getElementById(element).innerHTML=retorno
        }
    }
    //Executa
    xmlhttp.send(form)
}

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

function addOption(theSel, theText, theValue)
{
  var newOpt = new Option(theText, theValue);
  var selLength = theSel.length;
  theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex)
{ 
  var selLength = theSel.length;
  if(selLength>0)
  {
    theSel.options[theIndex] = null;
  }
}

function moveOptions(theSelFrom, theSelTo)
{
  
  var selLength = theSelFrom.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;
  
  var i;
  
  // Find the selected Options in reverse order
  // and delete them from the 'from' Select.
  for(i=selLength-1; i>=0; i--)
  {
    if(theSelFrom.options[i].selected)
    {
      selectedText[selectedCount] = theSelFrom.options[i].text;
      selectedValues[selectedCount] = theSelFrom.options[i].value;
      deleteOption(theSelFrom, i);
      selectedCount++;
    }
  }
  
  // Add the selected text/values in reverse order.
  // This will add the Options to the 'to' Select
  // in the same order as they were in the 'from' Select.
  for(i=selectedCount-1; i>=0; i--)
  {
    addOption(theSelTo, selectedText[i], selectedValues[i]);
  }
  
  if(NS4) history.go(0);
}

function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}

function Numero(tec){
    if ((tec >= 48) && (tec <= 57)){return true}else{return false}}
