//----Anderson Souza----------
//----funções de teclado------
//----------------------------
function MudaCampoEnter(event)
{
    Tecla = event.which;
    if(Tecla == null)
        Tecla = event.keyCode;
    if (Tecla == 13)
    {
		objPrimeiro = null
		objAtual = null
		objProximo = null
		for (x=0 ; x<=document.forms[0].elements.length - 1; x++)
		{
			if ((document.forms[0].elements[x].type == "text" && document.forms[0].elements[x].readOnly == false) || document.forms[0].elements[x].type == "password" || (document.forms[0].elements[x].type == "select-one" && document.forms[0].elements[x].disabled == false) || document.forms[0].elements[x].type == "textarea" || document.forms[0].elements[x].type == "checkbox" || document.forms[0].elements[x].type == "button") {
				if (objPrimeiro == null) {
					objPrimeiro = document.forms[0].elements[x];
				}
				if (objAtual != null) {
					objProximo = document.forms[0].elements[x];
					break;
				}
				if (event.srcElement.name == document.forms[0].elements[x].name) {
					objAtual = document.forms[0].elements[x];
				}
			}
		}
        event.keyCode = 0;
		if (objProximo != null) {
	        objProximo.focus();
	    }
	    else
	    {
	        objPrimeiro.focus();
	    }
    }
}
function Numerico(event)
{
  var Tecla = window.event.keyCode;
  event.cancelBubble = true;
  if((Tecla > 47 && Tecla < 58))
    event.returnValue = true;
  else
    event.returnValue = false;
}
function NumericoMSG(event)
{
  var Tecla = window.event.keyCode;
  event.cancelBubble = true;
  if((Tecla > 47 && Tecla < 58))
    event.returnValue = true;
  else
  {
    event.returnValue = false;
    alert('Campo numérico, informe somente números');
  }
}
function NumericoReal(event, Campo)
{
    Tecla = event.which;
    if(Tecla == null)
        Tecla = event.keyCode;
	if ((Tecla > 47 && Tecla < 58) || (Tecla == 44 && Campo.value.indexOf(",") == -1) || Tecla == 8)
		event.returnValue = true;
	else
		event.returnValue = false;
}
function IsEnter(event)
{
    Tecla = event.which;
    if(Tecla == null)
        Tecla = event.keyCode;
    if (Tecla == 13)
return true;
}
//limita a quantidade de caracteres a ser digitada em um obj texto ou textarea
function LimitaTamanho(descricao, total)
{
    eval('a = document.frm.'+descricao+'.value');
    if (a.length > total)
    	eval('document.frm.'+descricao+'.value = document.frm.'+descricao+'.value.substring(0,'+total+')');
    eval('a = document.frm.'+descricao+'.value');
}
//-----------------------------------------------------
//-----------------------------------------------------
/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;
        /**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   integer  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;
    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }
    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }
    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3
    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }
    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4
    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5
    return true;
} // end of the 'setPointer()' function
//-----------------------------------------------------
function abre(url,name,w,h)
{
    window.open(url,name,"width=" +w+ ",height=" + h +",scrollbars=no,toolbar=no");
}
function abrepopup(url,name,w,h)
{
    window.open(url,name,"width=" +w+ ",height=" + h +",scrollbars=yes,toolbar=no");
}
function novo_registro(url) {
   self.location = url;
}
function pesquisa(url) {
   self.location = url;
}
function FormataMascaraHora(obj, evento)
{
	var tecla = evento.keyCode;
        var tammax = 5;
        var pos = 2;
	vr = obj.value;
	vr = vr.replace( ":", "" );
	vr = vr.replace( " ", "" );
	tam = vr.length ;
	if (tam < tammax && tecla != 8) tam = vr.length + 1;
        if (tam < tammax)
	{
		if ( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
		{
			if ( tam <= 2 ) obj.value = vr;
			if ( tam > (pos+1) && tam <= tammax ) obj.value = vr.substr( 0, tam - pos ) + ':' + vr.substr( tam - pos, tam );
			else if ( tam == 3 ) obj.value = vr.substr( 0, 2 ) + ':' + vr.substr( 2, 1 );
		}
	}
}
function FormataMascaraData(obj,evento)
{
	var tecla = evento.keyCode;
	vr = obj.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;
	if ( tecla != 9 && tecla != 8 )
	{
		if ( tam > 2 && tam < 5 )
			obj.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			obj.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
	}
}
function MudaFoco (campo,tammax,evento)
{
	var tecla = evento.keyCode;
	vr = document.frm[campo].value;
	if( tecla == 109 || tecla == 188 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108 )
	{
		document.frm[campo].value = vr.substr( 0, vr.length - 1 );
	}
	else
	{
	 	vr = vr.replace( "-", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( ":", "" );
	 	tam = vr.length;	
	 	if (tecla != 0 && tecla != 9 && tecla != 16 )
		{
			if ( tam == tammax )
			{
				document.frm[campo+1].focus();
			}
		}
	}
}
//--------------------------------
//Anderson Souza - 18/05/04
//validar entrada de datas
//--------------------------------
function FormataData(Campo)
{
		var Tecla = window.event.keyCode;
		event.cancelBubble = true;
		// Ctrl, Alt, Shift, Home, End, Insert, Delete, PageUp, PageDown, Left Arrow, Right Arrow, Up Arrow, Down Arrow, BackSpace
		if (Tecla != 8 && (Tecla < 33 || Tecla > 40) && Tecla != 45 && Tecla != 46 && (Tecla < 16 || Tecla > 18))
		{
			tam = Campo.value.length;
			str = "";
			for(x = 0;x <= tam;x++){
				if(Campo.value.substring(x,x+1) != '/'){
					str += Campo.value.substring(x,x+1);
				}
			}
			aux = "";
			var TesteBarra = true;
			if (Campo.value.substring(0,1) == '/' || Campo.value.substring(1,2) == '/' || Campo.value.substring(3,4) == '/' || Campo.value.substring(4,5) == '/')
				TesteBarra = false;
			if (TesteBarra)
			{
				s = str.substring(0,2);
				aux = aux + str.substring(0,2);
				if((s.length >= 2))
					aux = aux + "/";
				s = str.substring(2,4);
				aux = aux + s;
				if((s.length >= 2))
					aux = aux + "/";
				aux = aux + str.substring(4,8);
				if (Campo.value.length == 10)
					if (!fIsDate(Campo.value))
					{
						Campo.value = ""
						alert('Data Inválida!')
					}
					else
						Campo.value = aux;
				else
					Campo.value = aux;
			}
		}
}
function fIsDate(strData) {
var blnIsDate = true;
var Dia = "";
var Mes = "";
var Ano = "";
var Sep1 = "";
var Sep2 = "";
	if (strData.length == 10) {
		Dia = strData.substring(0, 2);
		Mes = strData.substring(3, 5);
		Ano = strData.substring(6, 10);
		Sep1 = strData.substring(2, 3);
		Sep2 = strData.substring(5, 6);
		if (isNaN(parseFloat(Ano)) == true || parseFloat(Ano) < 1){
			blnIsDate = false;
		}
		else
		{
			if (Sep1 != "/" || Sep2 != "/") {
				blnIsDate = false;
			}
			else
			{
				if (isNaN(parseFloat(Mes)) == true || parseFloat(Mes) < 1 || parseFloat(Mes) > 12){
					blnIsDate = false;
				}
				else
				{
					if (parseFloat(Mes) == 2) {
						if ((parseFloat(Ano)) / 4 == parseInt(parseFloat(Ano) / 4)) {
							if (parseFloat(Dia) < 1 || parseFloat(Dia) > 29) {
								blnIsDate = false;
							}
						}
						else
						{
							if (parseFloat(Dia) < 1 || parseFloat(Dia) > 28) {
								blnIsDate = false;
							}
						}
					}
					else
					{
						if (parseFloat(Mes) == 4 || parseFloat(Mes) == 6 || parseFloat(Mes) == 9 || parseFloat(Mes) == 11) {
							if (parseFloat(Dia) < 1 || parseFloat(Dia) > 30) {
								blnIsDate = false;
							}
						}
						else
						{
							if (parseFloat(Mes) == 1 || parseFloat(Mes) == 3 || parseFloat(Mes) == 5 || parseFloat(Mes) == 7 || parseFloat(Mes) == 8 || parseFloat(Mes) == 10 || parseFloat(Mes) == 12) {
								if (parseFloat(Dia) < 1 || parseFloat(Dia) > 31) {
									blnIsDate = false;
								}
							}
						}
					}
				}
			}
		}
	}
	else
	{
		blnIsDate = false;
	}
	return blnIsDate;
}
function ValidaData(campo)
{
	if (campo.value != "")
	{
		if (fIsDate(campo.value) && campo.value.length == 10)
		{
			return true;
		}
		else
		{
			alert('Data inválida!')
			campo.value = ""
			campo.focus();
			return false;
		}
	}
}
//----------------------------------------------------------------
function marca_todos(obj2, objorigem)
{
  var i;
  var obj = document.all.item(obj2);
  try
  {
      if (obj.length == null)
          obj.checked = objorigem.checked;
      else
      {
          for(i=0;i<obj.length;i++)
          {
              obj[i].checked = objorigem.checked;
          }
      }
  }
  catch(e){}
}
function marca_todos2(obj2, objorigem)
{
  var i;
  var obj = document.all.item(obj2);
  if (obj.length == null)
      obj.checked = objorigem.checked;
  else
  {
      for(i=0;i<obj.length;i++)
      {
          obj[i].checked = objorigem.checked;
      }
  }
}
function marca_todos3(obj2, objorigem)
{
  var i;
  var obj = document.all.item(obj2);
  if (obj.length == null)
      obj.checked = objorigem.checked;
  else
  {
      for(i=0;i<obj.length;i++)
      {
          obj[i].checked = objorigem.checked;
      }
  }
}

function pesquisar()
{
   document.frm2.submit();
}

function submitFormDelecao()
{
   if (confirm('Apagar registro?'))
   {
	  try{ selecionarValores()} catch(e){};
	  document.frm.pAcao.value = "DELECAO";
      document.frm.submit();
   }
}



function MM_openBrWindow(theURL,winName,features)
{ //v2.0
  window.open(theURL,winName,features);
}

function submitForm()
{
   document.frm.submit();
}

function submitForm2()
{
  document.frm2.submit();
}

function textCounter(field, countfield, maxlimit)
{
    if (field.value.length > maxlimit) // if too long...trim it!
        field.value = field.value.substring(0, maxlimit);
        // otherwise, update 'characters left' counter
    else
        countfield.value = maxlimit - field.value.length;
}
function AddOpcao(pValor,pRotulo)
{
	document.frm.pValor.length++;
	document.frm.pValor.options[document.frm.pValor.length -1].value = pValor;
	document.frm.pValor.options[document.frm.pValor.length -1].text = pRotulo;
}
function RemoveroOpcao(pNome)
{
    var obj;
    var qtd = 0;
    var indice;
	var i;
	var vet = new Array();
    obj = document.all.item(pNome);
    qtd = obj.length;
	indice = obj.selectedIndex;
	function T(cod,valor,excluir)
	{
	    this.cod = cod;
	    this.valor = valor;
	    this.excluir = excluir;
	}
	if (indice > -1)
	{
		for(i=0;i<qtd;i++)
		{
		    if (obj[i].selected == false)
				vet[i] = new T(obj[i].value,obj[i].text,0);
		    else
		        vet[i] = new T(obj[i].value,obj[i].text,1);
		}
		obj.length = 0;
		for(i=0;i<vet.length;i++)
		{
			if (vet[i].excluir == 0)
			{
				obj.length++;
				obj.options[obj.length -1].value = vet[i].cod;
				obj.options[obj.length -1].text = vet[i].valor;
			}
		}
	}
}
function Ordena(campo,ordem)
{
	document.frm.pCampo.value = campo;
	document.frm.pOrdem.value = ordem;
    document.frm.pAcao.value = 'pesquisar';
    document.frm.submit();
}
function checkAll(nome)
{
	var obj = document.all.item(nome);
	var qtd = obj.length;
	var i;
	if (qtd == null)
	    if (obj.checked)
	        obj.checked = false;
	    else
	        obj.checked = true;
	else
	{
		for(i=0;i<qtd;i++)
			if (obj[i].checked)
			    obj[i].checked = false;
			else
			    obj[i].checked = true;
	}
}
function Excluir(pNome,frmname)
{
  if (frmname == "" || frmname == undefined) frmname = "frm2";
	var obj = document.all.item(pNome);
	var i;
	var qtd;
	var marcado = false;
	var cont = 0;
	if (obj.length == null)
	{
	    if (obj.checked)
		{
			if (confirm('Excluir o registro selecionado?'))
                        submitFormExcluirLista('excluir', frmname);
		}
	}
	else
	{
		qtd = obj.length;
		for(i=0;i<qtd;i++)
		{
		    if (obj[i].checked)
		    {
		        marcado = true;
            			cont++;
		    }
		}
		if (marcado)
		{
			if (cont > 1)
			{
                        if (confirm('Excluir os registros selecionados?'))
                        	submitFormExcluirLista('excluir', frmname);
			}
			else
			{
                        if (confirm('Excluir o registro selecionado?'))
                        	submitFormExcluirLista('excluir', frmname);
			}
		}
	}
}
function submitFormExcluirLista(pAcao, frmname)
{
  if (frmname == "" || frmname == undefined) frmname = "frm2";
	eval("document."+frmname+".pAcao.value = pAcao;");
	eval("document."+frmname+".submit();");
}
function limpaChecks(nome)
{
	var obj = document.all(nome);
	var qtd = obj.length;
   	var i;
   	for (i=0;i<qtd;i++)
   	{
   	    obj[i].checked = false;
   	}
}
function exibeSubMenuCampos(id)
{
	var obj1 = 'submenu'+id;
	var obj2 = 'span'+id;
	if (document.all[obj1].style.display=="block")
	{
		document.all[obj1].style.display="none";
		document.all[obj2].value = "none";
	}
	else
	{
		document.all[obj1].style.display="block";
		document.all[obj2].value = "block";
	}
}

function abrir_pop(url, nome, wd, ht, scrolla)
{
  if (!wd) wd = 600;
  if (!ht) ht = 300;
  if (!scrolla) scrolla = 'yes';
  var w = wd;
  var h = ht;
  var wlft = (screen.width  - w) / 2;
  var wtop = (screen.height - h) / 2;
  var wind = window.open(url, nome, 'height='+h+',width='+w+',location=no,menubar=no,resizable=no,scrollbars='+scrolla+',status=no,titlebar=no,toolbar=no,left='+wlft+',top='+wtop);
  wind.opener = window;
  wind.focus();
  return wind;
}

function abrir_calendario(url) { return abrir_pop(url, 'calendario', 200, 142, 'no'); }

function numberFormat(val, decimais, naocompleta) {
  var tmp_str = "";
  var str     = "" + val;
  var sinal   = "";
  str = str.replace(".", ",");
  if(str.indexOf("-") != -1) {
    sinal = "-";
    str = str.substr(1);
  }
  var pos_fim   = (str.indexOf(",") == -1 ? str.length - 1 : str.indexOf(",")-1);
  var casas_dec = (str.indexOf(",") == -1 ? 0 : str.length - str.indexOf(",")-1);;
  var pos_ini   = (str.substr(0,pos_fim).length % 3)+1;
  var tmp_str2  = (pos_fim < str.length-1 ? str.substr(pos_fim+1) : "");
  if(pos_ini) {
    tmp_str += str.substr(0,pos_ini);
  } else {
    tmp_str += str.substr(0,3);
    pos_ini += 3;
  }
  for(i=pos_ini;i<pos_fim;i+=3) {
    tmp_str += "." + str.substr(i,3);
  }
  //tmp_str2 -> parte decimal do numero
  if(tmp_str2.length > 0) {
    if(tmp_str2.length > decimais)
      tmp_str2 = tmp_str2.substr(0, decimais+1);
    tmp_str += tmp_str2;
  }
  if(casas_dec == 0 && decimais > 0) {
    tmp_str += ",";
  }
  while(casas_dec < decimais) {
    tmp_str += "0";
    casas_dec ++;
  }
  str = sinal + tmp_str;
  return str;
}
//*
function mascaraFloat(objeto, inteiros, decimais) 
{
  var campo = eval(objeto);
  var caracteres = '0123456789,' + (campo.value.length==0 ? '-' : '');
  var str = campo.value;
  var negativo = str.charAt(0) == '-';
  var pos_ini, pos_fim;
  var tmp_str = "";
  try
  {
    if (browser() == 'IE')
    {
      var c = String.fromCharCode(event.keyCode);
    }
    else
    {
      var evento = arguments.callee.caller.arguments[0];
      if (evento.which == 8 || evento.which == 0) return false;
      var c = String.fromCharCode(evento.which);
    }
    if(c == "." || c == "^" || c == "$" || c == "|") throw e;
    if (caracteres.search(c)==-1)
    {
      if (browser() == 'IE')
      {
        event.returnValue = false;
      }
      else
      {
        if (evento.which == 8 || evento.which == 0) return false;
        evento.preventDefault(true);
      }
      return;
    }
  }
  catch(e)
  {
    if (browser() == 'IE')
    {
      event.returnValue = false;
    }
    else
    {
      if (evento.which == 8 || evento.which == 0) return false;
      evento.preventDefault(true);
    }
    return;
  }
  if(negativo) str = str.substr(1);
  while(str.indexOf('.') != -1)
  {
    str = str.substr(0, str.indexOf('.')) + str.substr(str.indexOf('.') + 1);
  }
  if(str.indexOf(",") == -1 && str.length >= inteiros)
  {
    str = str.substr(0,inteiros) + "," + str.substr(inteiros);
  }
  if(str.indexOf(',') != -1) {
    if(c == "," || str.length - str.indexOf(',') > decimais)
    {
      if (browser() == 'IE')
      {
        event.returnValue = false;
      }
      else
      {
        if (evento.which == 8 || evento.which == 0) return false;
        evento.preventDefault(true);
      }
      return;
    }
  }
  if(c == ",") {
    if(!str.length || str.indexOf(',') != "-1")
    {
      if (browser() == 'IE')
      {
        event.returnValue = false;
      }
      else
      {
        if (evento.which == 8 || evento.which == 0) return false;
        evento.preventDefault(true);
      }
      return;
    }
  }
  pos_fim = (str.indexOf(",") == -1 ? (str.length) : str.indexOf(",")-1);
  pos_ini = (str.substr(0,pos_fim).length % 3)+1;
  if(pos_ini)
  {
    tmp_str += str.substr(0,pos_ini);
  }
  else
  {
    tmp_str += str.substr(0,3);
    pos_ini += 3;
  }
  for(i=pos_ini;i<pos_fim;i+=3)
  {
    tmp_str += "." + str.substr(i,3);
  }
  if(pos_fim < str.length-1)
  {
    tmp_str += str.substr(pos_fim+1);
  }
  campo.value = (negativo ? '-' : '') + tmp_str;
}
function mascaraData(objeto)
{
  campo = eval(objeto);
  try {
    caracteres = '0123456789';
    if (browser() == 'IE')
    {
      var c = String.fromCharCode(event.keyCode);
    }
    else
    {
      var evento = arguments.callee.caller.arguments[0];
      if (evento.which == 8 || evento.which == 0) return false;
      campo = evento.target;
      var c = String.fromCharCode(evento.which);
    }
    if (campo.value.length > 9) throw e;
    if(c == "." || c == "^" || c == "$" || c == "|") throw e;
    if(caracteres.search(c)!=-1)
    {
      if((campo.value.length == 1)||(campo.value.length == 4)) {
        campo.value = campo.value + c + '/';
        if(browser() == 'IE')
        {
          event.returnValue = false;
        }
        else
        {
          if (evento.which == 8 || evento.which == 0) return false;
          evento.preventDefault(true);
        }
        return;
      } else if((campo.value.length == 2)||(campo.value.length == 5)) {
        campo.value = campo.value + '/' + c;
        if(browser() == 'IE')
        {
          event.returnValue = false;
        }
        else
        {
          if (evento.which == 8 || evento.which == 0) return false;
          evento.preventDefault(true);
        }
        return;
      }
    }
  } catch(e) {
    if(browser() == 'IE')
    {
      event.returnValue = false;
    }
    else
    {
      if (evento.which == 8 || evento.which == 0) return false;
      evento.preventDefault(true);
    }
    return;
  }
}
// COMPLETADATA (campo)
// Esta rotina completa a data de um campo.
// Por exemplo:
// Se no campo tem o valor 1, a função completa com 01/<mes_atual>/<ano_atual>
// campo - É o campo que deve ser completado
function completaData(campo) {
  if(campo.value != "") {
    var vetdata = campo.value.split("/");
    var objDate = new Date();
    var mymes = objDate.getMonth()+1;
    mymes = (mymes < 10) ? "0"+mymes : mymes;
    var myano = objDate.getFullYear();
    switch(vetdata.length) {
      case 1:
        if(vetdata[0].length > 2) {
          campo.value = "";
          return;
        }
        if(vetdata[0].length == 1)
          vetdata[0] = "0" + vetdata[0];
        campo.value = vetdata[0]+"/"+mymes+"/"+myano;
        break;
      case 2:
        if(vetdata[0].length > 2 || vetdata[1].length > 2) {
          campo.value = "";
          return;
        }
        if(vetdata[0].length == 1)
          vetdata[0] = "0" + vetdata[0];
        if(vetdata[1].length == 1)
          vetdata[1] = "0" + vetdata[1];
        if(vetdata[1].length == 0)
          vetdata[1] = mymes;
        campo.value = vetdata[0]+"/"+vetdata[1]+"/"+myano;
        break;
      case 3:
        if(vetdata[0].length > 2 || vetdata[1].length > 2) {
          campo.value = "";
          return;
        }
        if(vetdata[0].length == 1)
          vetdata[0] = "0" + vetdata[0];
        if(vetdata[1].length == 1)
          vetdata[1] = "0" + vetdata[1];
        if(vetdata[1].length == 0)
          vetdata[1] = mymes;
        if(vetdata[2].length == 0)
          vetdata[2] = myano;
        if(vetdata[2].length == 1)
          vetdata[2] = "200"+vetdata[2];
        if(vetdata[2].length == 2) {
          if(vetdata[2] > 50) {
            vetdata[2] = "19" + vetdata[2];
          } else {
            vetdata[2] = "20" + vetdata[2];
          }
        }
        if(vetdata[2].length == 3) {
          if(vetdata[2] > 500) {
            vetdata[2] = "1"+vetdata[2];
          } else {
            vetdata[2] = "2"+vetdata[2];
          }
        }
        campo.value = vetdata[0]+"/"+vetdata[1]+"/"+vetdata[2];
        break;
      default:
        campo.value = "";
        break;
    }
  }
}
/*
  COMPLETAFLOATVALOR (obj, decimais, campo)
  Esta função serve para completar os dados de um campo
  numérico. Exemplo:
  completaFloatValor(meucampo, 5, meucampo);
  meucampo.value terá o valor "1,20000"
  obj      - Objeto que contem o valor a ser formatado
  decimais - número de casas depois da vírgula
  campo    - campo que terá seu conteúdo formatado
*/
function completaFloat(obj,decimais) {
  var sinal = "";
  var campo = obj;
  var val = obj.value;
  if(val.indexOf("-") != -1) {
    sinal = "-";
    val = val.substr(1);
  }
  if(val != "") {
    while(val.indexOf(".") != -1)
      val = val.replace(".","");
    val = val.replace(",",".");
    var check = /^\d+\.?\d*$/;
    if(!check.test(val)) {
      val = "";
      return false;
    }
    if(val.indexOf(".") == "-1") {
      if(decimais > 0) {
        val += ".";
        for(var i=0; i < decimais; i++)
          val += "0";
	  }
    } else {
      for(var i=0; i < decimais; i++)
        if(val.substr(val.indexOf(".")+1).length == i)
          for(var j=i;j<decimais;j++)
            val += "0";
	}
    try {
      campo.value = val;
      formataFloat(campo,decimais,1);
      campo.value = sinal + campo.value;
    } catch(e) {}
    val = numberFormat(val,decimais,1);
    val = sinal + val;
    obj.value = val;
  }
} // */
function mascaraInteger(objeto,posicoes)
{
  campo   = eval (objeto);
  tamanho = eval (posicoes);
  var negativo = (campo.value.charAt(0) == '-');
  if (negativo) tamanho++;
  caracteres = '01234567890-';
  try
  {
    if (browser() == 'IE')
    {
      var c = String.fromCharCode(event.keyCode);
    }
    else
    {
      var evento = arguments.callee.caller.arguments[0];
      if (evento.which == 8 || evento.which == 0) return false;
      var c = String.fromCharCode(evento.which);
    }
    if(c == "." || c == "^" || c == "$" || c == "|") throw e;
    if((caracteres.search(c)!=-1) && campo.value.length < tamanho) {
      campo.value = campo.value;
    }
    else
    {
      if (browser() == 'IE')
      {
        event.returnValue = false;
      }
      else
      {
        if (evento.which == 8 || evento.which == 0) return false;
        evento.preventDefault(true);
      }
      return;
    }
  }
  catch(e)
  {
    if (browser() == 'IE')
    {
      event.returnValue = false;
    }
    else
    {
      if (evento.which == 8 || evento.which == 0) return false;
      evento.preventDefault(true);
    }
    return;
  }
}
function converteNotacaoNumero(str)
{
  var tmp = str;
  if(!isFloat(tmp)) {
    return 0;
  }
  while(tmp != "" && tmp.indexOf(".") != -1) {
    tmp = tmp.replace(".","");
  }
  tmp = tmp.replace(",",".");
  while(tmp != "" && tmp.charAt(0) == '0') {
    if(tmp.length > 1 && tmp.charAt(1) != '.') {
      tmp = tmp.substring(1);
    }
    else break;
  }
  if(tmp != "") {
    return eval(tmp);
  }
  return 0;
}
function formataFloat(objeto, decimais, naocompleta) {
  var tmp_str = "";
  var campo = eval(objeto);
  var sinal = "";
  campo.value = numberFormat(campo.value, decimais);
  //chama qdo ta na completafloat
  if(!naocompleta) completaFloat(campo,decimais);
}
//recebe um valor em javascript e transforma em brasileiro
function numberFormat(val, decimais, naocompleta) {
  var tmp_str = "";
  var str     = "" + val;
  var sinal   = "";
  str = str.replace(".", ",");
  if(str.indexOf("-") != -1) {
    sinal = "-";
    str = str.substr(1);
  }
  var pos_fim   = (str.indexOf(",") == -1 ? str.length - 1 : str.indexOf(",")-1);
  var casas_dec = (str.indexOf(",") == -1 ? 0 : str.length - str.indexOf(",")-1);;
  var pos_ini   = (str.substr(0,pos_fim).length % 3)+1;
  var tmp_str2  = (pos_fim < str.length-1 ? str.substr(pos_fim+1) : "");
  if(pos_ini) {
    tmp_str += str.substr(0,pos_ini);
  } else {
    tmp_str += str.substr(0,3);
    pos_ini += 3;
  }
  for(i=pos_ini;i<pos_fim;i+=3) {
    tmp_str += "." + str.substr(i,3);
  }
  //tmp_str2 -> parte decimal do numero
  if(tmp_str2.length > 0) {
    if(tmp_str2.length > decimais)
      tmp_str2 = tmp_str2.substr(0, decimais+1);
    tmp_str += tmp_str2;
  }
  if(casas_dec == 0 && decimais > 0) {
    tmp_str += ",";
  }
  while(casas_dec < decimais) {
    tmp_str += "0";
    casas_dec ++;
  }
  str = sinal + tmp_str;
  return str;
}
function isFloat(valor) {
  var check = /^(((\+|\-)?\d{1,3}(\.)(\d{3,3}\.)*(\d{3,3})+(,\d+)?)|((\+|\-)?\d{1,3}(,\d+)?))$/;
  return check.test(valor);
}
function browser()
{
  var isNav4, isNav, isIE;
  if (parseInt(navigator.appVersion.charAt(0)) >= 4) 
  {
    isNav = (navigator.appName=="Netscape") ? true : false;
    isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
  }
  if (navigator.appName=="Netscape") {
    isNav4 = (parseInt(navigator.appVersion.charAt(0))==4);
  }
  return ((isNav4||isNav) ? "NS" : "IE");
}
function AbreFrame(frame)
{
	var obj = document.getElementById(frame);
	if (obj.style.display == 'none')
		obj.style.display = 'block';
	else
		obj.style.display = 'none';
}
function selecionarValores(id)
{
	var i;
	var qtd;
	var obj = document.getElementById(id);
	qtd = obj.length;
	for(i=0;i<qtd;i++)
	{
	    obj[i].selected = true;
	}
}
/**
  	Função que mostra/esconde um objeto div conforme valor passado
  	pEstado e pResposta são objetos do form
	Usado nas telas pop de alterar proposta
	@param obj1 objeto do tipo select
*/
function mostraResposta(obj1)
{
	var estado;
	if (obj1.selectedIndex == 1)
		estado = 'block';
	else
	    estado = 'none';
	document.getElementById("tr_resp").style.display = estado;
	document.frm.pEstado.value = estado;
	document.frm.pResposta.focus();
}
function voltar(pImovel_id)
{
  document.frm4.pImovel_id.value = pImovel_id;
  document.frm4.submit();
}

// Usado na parte de Inclusão de Lançamento (cadastro multiplo para imoveis)
function redirecionaLink(comando, link)
{
  if (comando == 'avancar')
  {
    document.frm.submit();
    document.location.href=link;
  }
  else
  {
    if (comando == 'voltar')
    {
      document.frm.submit();
      document.location.href=link;
    }
  }
}

