function isWhole(tstValue)
{
   var i=0;
   var str=""+tstValue;
   var l=str.length;
   var c=str.charAt(i++);


   if (c=='+') c=str.charAt(i++);
   while ((c>='0') && (c<='9') && (i<l)) {
      c=str.charAt(i++);
   }
   return ((i==l) && (c>='0') && (c<='9'));
}

// test: isInteger
function isInteger(tstValue)
{
   var i=0;
   var str=""+tstValue;
   var l=str.length;
   var c=str.charAt(i++);

   if ((c=='+')||(c=='-')) c=str.charAt(i++);
   while ((c>='0') && (c<='9') && (i<l)) {
      c=str.charAt(i++);
   }
   return ((i==l) && (c>='0') && (c<='9'));
}

// test: isNumeric (float or integer)
function isNumeric(tstValue)
{
   var i=0;
   var str=""+tstValue;
   var l=str.length;
   var c=str.charAt(i++);
   var Ok="0123456789., ";

   while ((c==' ') && (i<l)) {
      c=str.charAt(i++);
   }
   if (i==l) return (Ok.indexOf(c)>=0);
   if ((c=='+')||(c=='-')) c=str.charAt(i++);
   while ((Ok.indexOf(c)>=0) && (i<l)) {
      c=str.charAt(i++);
   }
   if (i==l) return (Ok.indexOf(c)>=0);
   if ((c=='e')||(c=='E')) {
      c=str.charAt(i++);
      while ((c==' ') && (i<l)) {
         c=str.charAt(i++);
      }
      if (i==l) return true;
      if ((c=='+')||(c=='-')) c=str.charAt(i++);
      if (Ok.indexOf(c)<0) return false;
      while ((((c>='0')&&(c<='9'))||(c==' ')) && (i<l)) {
         c=str.charAt(i++);
      }
      return ((i==l) && (((c>='0')&&(c<='9'))||(c==' ')));
   }
   else
      return false;
}

// check values for all columns
function doCheck()
{
//   alert("do Check");
   var fieldValue;
   var msg;

   for(var field in _Row) with (_Row[field])
   {
      fieldValue = getValue();
//	  fieldValue = fieldValue.replace(/ /gi, "");
//	  alert("Campo: " + field + " Valor: " + fieldValue );
//	  alert( field + " do Check X" + fieldValue + "X " + isMandatory);
      // if column is mandatory verify there is a value
      if (isMandatory)
         if ((fieldValue=="")||(fieldValue==null)||(fieldValue=="null"))
         {
            alert(name + " deve ser informado(a).");
            focus();
            return false;
         }
      // check field value with field's check function...
      if ((fieldValue!="")&&(fieldValue!=null)&&(fieldValue!="null")&&(fieldValue!=initialValue))
      {
         msg = check(fieldValue);
         if (msg != "")
         {
            alert("Valor incorreto para '" + name + "': " + msg);
            focus();
            return false;
         }
      }
   }
   return true;
}

// confirm execucao ?
function exec_confirm()
{
   return confirm($texto);
}

// confirm deletion ?
function deleteConfirm()
{
   return confirm("Confirma a Exclusão do Registro?");
}

function doInsert()
{
   if (doCheck())
      return submitOperation("insert");
   return false
}

// update record
function doUpdate()
{
   if (doCheck())
      return submitOperation("update");
   return false
}


// executa programa
function doExecuta()
{
    if (exec_confirm())
       return SubmitOperation("select");
    return false;
}
// delete record
function doDelete()
{
   if (deleteConfirm())
 //     if (doCheckKey())
         return submitOperation("delete");
   return false;
}

// Escape illegal characters in http page parameter values
function doEscape(sValue)
{
   // JavaScript doesnt seem to escape the same way than the submit
   //  method of Browsers/html-Servers:
   // For Browsers:  "+ " ---Submit---=> "%2B+" --Server--=> "+ ". Ok.
   // In JavaScript: "+ " --escape()--=> "+%20" --Server--=> "  ". NOT OK !
   var i, j, c;
   var sRet = "";

   if (sValue == null) return null;
   sValue = "" + sValue;
   for (i=0; i<sValue.length; i++)
   {
      c = sValue.charAt(i);
      if ((c >= "0" && c <= "9") ||
          (c >= "a" && c <= "z") ||
          (c >= "A" && c <= "Z"))
         sRet += c;
      else if (c=="+")
         sRet += "%2B";
      else
         sRet += escape(c);
   }

   return sRet;
}

function submitOperation(operation)
{
//   alert("submit Operation");
   var newLocation;
   var changed = "";
   var fieldValue;
   var acao = "0";

   newLocation = processador + "?";

   for (var field in _Row) {
//		alert( field);
      fieldValue = _Row[field].getValue();
//  		alert( fieldValue );
//	  alert("submit Operation, Campo: "  field + " = " + fieldValue);
//	  alert("Campo:" + field + " Atual: " + fieldValue + " Inicial: " + _Row[field].initialValue);
//	  if (field=="tipo") {
//		  alert("Campo:" + field + " Value: " + fieldValue + " tipo[0]: " + document.fm_pessoa.tipo[0].checked);
//	  }

      if (_Row[field].isPrimaryKey)
         newLocation += "&'" + field + "'=" + doEscape(fieldValue);
      else
         if (fieldValue != _Row[field].initialValue)
//            changed += "&'" + field + "'=" + doEscape(fieldValue);
            changed += "&" + field + "=" + doEscape(fieldValue);

   }
//  alert( "Aqui c " + operation);

   if (operation=="delete") {
		changed = "";
//    alert("submit Operation delete");
//		_Hid["requisicao"].fieldValue = "3";
		acao="3";
   }
   else if (operation=="update") {
      if (changed == "") {
         alert("Não existem alterações para serem gravadas.");
         return false;
      }
	acao="2";
   }
  else if (operation=="insert") {
	acao="1";
   }
   if (operation=="select") {
      changed = "";
      return false;
   }
   for (var field2 in _Hid) {
      fieldValue = _Hid[field2].fieldValue;
      changed += "&" + field2 + "=" + doEscape(fieldValue);
   }
//   alert(changed + " de novo");

//   alert("Aqui " + newLocation + changed + "&acao="+acao);

//   parent.workarea.location = newLocation + changed;
   parent.location = newLocation + changed + "&acao="+acao;
   return true;
}

// BODY OnLoad event...
function onBodyLoad()
{
//	alert("Aqui!");
   // fill form controls with data

//   fillForm();

   // BODY created and loading => unlock toolbar
//   top.ToolbarLocked = false;

   // Try to give focus to first updatable field
   // (asume browser's JavaScript "for(... in ...)" loop
   //  takes objects in creation-order)
   for (var field in _Row) with (_Row[field]) {
//		alert("Aqui: " + field );	
//		if (field=="cd_cidade") {
//			continue;
//		}	
//      if ((!isPrimaryKey) || (Action=="insert")) {
         if (focus())
            break;
//      }
   }
}

// build the _Row object (empty)...
function makeObject() {}

var _Row = new makeObject();

function _Row_addField(
  sFieldCode,   // Object name
  setValueFunc, // Function that assign field value   => .setValue(...);
  getValueFunc, // Function that read field value     => .getValue();
  focusFunc,    // Function that gives focus to field => .focus();
  checkFunc,    // Function that check validity       => .check(...);
  sName,        // Column name for display       => .name
  sDefault,     // The default initial value     => .initialValue
  sISPK,        // != "" if column belongs to PK => .isPrimaryKey
  sISMandatory, // != "" if column is mandatory  => .isMandatory
  sHint         // The hint to display           => .hint
 )
{
   _Row[sFieldCode] = new makeObject();

   _Row[sFieldCode].setValue = setValueFunc;
   _Row[sFieldCode].getValue = getValueFunc;
   _Row[sFieldCode].focus    = focusFunc;
   _Row[sFieldCode].check    = checkFunc;
   _Row[sFieldCode].name         = sName;
   _Row[sFieldCode].initialValue = sDefault;
   _Row[sFieldCode].isPrimaryKey = (sISPK!="");
   _Row[sFieldCode].isMandatory  = ((sISMandatory!="")||(sISPK!=""));
   _Row[sFieldCode].hint         = sHint;
}

function FormataValorOLD(formulario,campo,tammax,teclapres) {

	var tecla = teclapres.keyCode;
//		alert("aqui " + document.forms[formulario][campo].value );
	vr = document.forms[formulario][campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		document.forms[formulario][campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
	}		
	
}

function FormataValor(formulario,campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
//	vr = document.form[campo].value;
	vr = document.forms[formulario][campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length + 1;
	if (tecla == 9){	tam = tam - 1 ; }
//
//	if (this.select==false) {
//		alert('Sim');
//	}
//
	if ( tecla != 8 && tecla != 46 && tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 || tecla == 9) {
//	if ( tecla == 8 || tecla == 46 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		document.forms[formulario][campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
	}		
}

function FormataValor8(formulario,campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
//	vr = document.form[campo].value;
	vr = document.forms[formulario][campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length + 1;
	if (tecla == 9){	tam = tam - 1 ; }
	if ( tecla != 8 && tecla != 46 && tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 || tecla == 9) {
		if ( tam <= 8 ){ 
	 		document.forms[formulario][campo].value = vr ; }
	 	if ( (tam > 8) && (tam <= 11) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 8 ) + ',' + vr.substr( tam - 8, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 16) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + ',' + vr.substr( tam - 8, tam ) ; }
	}		
}

function FormataDataOLD(formulario,campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.forms[formulario][campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document.forms[formulario][campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document.forms[formulario][campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
}

function FormataDataHora(formulario,campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.forms[formulario][campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );

	vr = vr.replace( ":", "" );
	vr = vr.replace( ":", "" );
	vr = vr.replace( ":", "" );
	vr = vr.replace( " ", "" );

	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 && tecla != 46 ) {
		if ( tam > 2 && tam < 5 )
			document.forms[formulario][campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document.forms[formulario][campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
		if ( tam >= 10 && tam <= 12 )
			document.forms[formulario][campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ) + ' ' + vr.substr( 8, 2 ) + ":" + vr.substr( 10, 2 ); 
		if ( tam >= 13 && tam <= 16 )
			document.forms[formulario][campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ) + ' ' + vr.substr( 8, 2 ) + ":" + vr.substr( 10, 2 ) + ":" + vr.substr( 12, 2 ); 
	}
}

function FormataHora(formulario,campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.forms[formulario][campo].value;
	vr = vr.replace( ":", "" );
	vr = vr.replace( ":", "" );
	vr = vr.replace( ":", "" );
	vr = vr.replace( " ", "" );

	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document.forms[formulario][campo].value = vr.substr( 0, tam - 2  ) + ':' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 8 )
			document.forms[formulario][campo].value = vr.substr( 0, 2 ) + ':' + vr.substr( 2, 2 ) + ':' + vr.substr( 4, 2 );
	}
}

function FormataData(formulario,campo,teclapres) {
	var tecla = teclapres.keyCode;
//	alert(tecla);
	vr = document.forms[formulario][campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 && tecla != 46 ) {
		if ( tam > 2 && tam < 5 )
			document.forms[formulario][campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document.forms[formulario][campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
	}
}

function FormataMesAno(formulario,campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.forms[formulario][campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;
	if ( tecla != 9 && tecla != 8 && tecla != 46 ) {
		if ( tam > 2 && tam < 7 )
			document.forms[formulario][campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, tam ); }
}

function FormataPercentual(formulario,campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.forms[formulario][campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 3 ){ 
	 		document.forms[formulario][campo].value = vr ; }
	 	if ( (tam > 3) && (tam <= 6) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 3 ) + ',' + vr.substr( tam - 3, tam ) ; }
	}		
	
}

function FormataCpf(formulario,campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.forms[formulario][campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		document.forms[formulario][campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ;}
	}		
}

function FormataCgc(formulario,campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.forms[formulario][campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		document.forms[formulario][campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 6) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 7) && (tam <= 9) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 6 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 10) && (tam <= 12) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 13) && (tam <= 14) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ;}
	}		
}

function FormataTelefone(formulario,campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.forms[formulario][campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		document.forms[formulario][campo].value = vr ; }
	 	if ( (tam > 4) ){
	 		document.forms[formulario][campo].value = vr.substr( 0, tam - 4 ) + '-' + vr.substr( tam - 4, tam ) ; }
	}		
}

function SetHelp(txt) { help.innerText = txt ; }


var janela;
//this.name = 't300';
this.name = 'normal';
function pesquisa(titulo,destino) {
	popup = window.open(destino,titulo,'toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes,dependent=yes,width=550,height=380');
	self.janela=popup;
}

function pesquisa1(titulo,destino) {
	campo_volta = titulo.substring(8);
	l_frame=document.getElementById('limbo2');
//	alert(self.name + ' ' + self.id);
//	alert(destino);
//	elemento=document.getElementById("limbo");
//	alert(elemento.name);
//	parent.frames["limbo2"].location.href=destino;
//	l_frame.location.href=destino;
	l_frame.src=destino;
//	alert(l_frame.src);
//	parent.frames[1].location.href=destino;
//	popup = window.open(destino,titulo,'toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes,dependent=yes,width=250,height=100');
//	self.janela=popup;
//	parent.frames["leitor"].document.forms["fm_leitor"].pessoa_cd_pessoa.value
}

function f_transmite(formulario)
{
	document.forms[formulario].submit();
	document.forms[formulario].vl_unitario.focus();
}
