function start() {
  top.mainFrame = top.frames[0].frames[0];
  top.submitFrame = top.frames[1];
  top.setEnvironment();
  top.mainFrame.start();
}

/*********** INICIALIZACOES GLOBAIS ***********/
top.xmlhttp = false;
try {
  top.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
  try {
    top.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch(e) {
    top.xmlhttp = false;
  }
}
if(!top.xmlhttp && typeof XMLHttpRequest != "undefined") {
  top.xmlhttp = new XMLHttpRequest();
}

top.showTR    = "table-row";
if(document.all) top.showTR = "block";

top.mainFrame = null;
top.submitFrame = null;
/********* FIM INICIALIZACOES GLOBAIS *********/

/*********** FUNCOES PARA CARREGAR LISTAS GENERICAS ***********/
top.loadLista = function(p, l, v, f, a) {
  top.xmlhttp.open("GET", p, a);
  top.xmlhttp.onreadystatechange = function() {
    if(top.xmlhttp.readyState == 4) {
      return top.pushToLista(l, v, f);
    }
  }
  top.xmlhttp.send(null);
  if(!a) {
    return top.pushToLista(l, v, f);
  }
}

top.pushToLista = function(l, v, f) {
  l.push(new Array());
  l[l.length-1].push(v);
  l[l.length-1].push(top.xmlhttp.responseText);
  f(v);
}
/********* FIM FUNCOES PARA CARREGAR LISTAS GENERICAS *********/

/*********** FUNCOES GENERICAS ***********/
/* Habilita ou desabilita a linha que contém os links para
 * continuar o cadastramento
 */
top.toggleForwardLink = function () {
  var fl = top.getObj("forwardLinkDiv", top.mainFrame);

  if(fl != null) {
    if(fl.style.display == "none") {
      fl.style.display = "inline";
    } else {
      fl.style.display = "none";
    }
  }
}

/* Habilita ou desabilita um grupo de campos de acordo com
 * a escolha de sim ou não.
 */
top.toggleGrupo = function (grupo, tipo) {
  var el, img;

  for(var i = 0; i < grupo.length; i++){
    img = top.getObj(grupo[i][1], top.mainFrame);
    if(img != null) {
      img.src="images/obrigat" + ((tipo == 0) ? "_1" : "") + ".gif";
    }

    el = grupo[i][0];
    if(el!=null){
      if(tipo == 0) { // false, não
        if(el.length && (el[0].type == "radio" || el[0].type == "checkbox")) {
          for(var j = 0; j < el.length; j++) {
            if(el[j].className.indexOf("disabled") == -1) {
              el[j].className += " disabled";
              el[j].checked = false;
            }
            el[j].disabled = true;
          }
        } else {
          switch(el.type) {
            case "text":
            case "textarea":
              el.value = "";
              break;
            case "select-one":
              el.selectedIndex = 0;
              break;
            case "select-multiple":
              el.selectedIndex = -1;
              break;
          }
          if(el.className.indexOf("disabled") == -1) {
            el.className += " disabled";
          }
          el.disabled = true;
        }
      } else { // true, sim
        var iDisabled;
        if(el.length && (el[0].type == "radio" || el[0].type == "checkbox")) {
          for(var j = 0; j < el.length; j++) {
            iDisabled = el[j].className.indexOf("disabled");
            if(iDisabled > -1) {
              el[j].className = el[j].className.substring(0, iDisabled) + el[j].className.substring(iDisabled + "disabled".length, el[j].className.length);
            }
            el[j].disabled = false;
          }
        } else {
          iDisabled = el.className.indexOf("disabled");
          if(iDisabled > -1) {
            el.className = el.className.substring(0, iDisabled) + el.className.substring(iDisabled + "disabled".length, el.className.length);
          }
          el.disabled = false;
        }
      }
    }
  }
}

/*Funções para carregar dados para alteração*/
top.fillDados = function(dados, form) {
  var campo;
  for(i = 1; i < dados.length; i++) {
    if(eval("form." + dados[i][0])) {
      if(eval("form." + dados[i][0] + ".type")) {
        campo = eval("form." + dados[i][0]);
        switch (campo.type) {
          case "text":
          case "hidden":
          case "textarea":
            campo.value = dados[i][1];
            break;
          case "select-one":
          case "select-multiple":
            top.marcaSelect(campo,dados[i][1]);
            break;
        }
      } else {
        if(eval("form." + dados[i][0] + "[0].type")) {
          campo = eval("form." + dados[i][0]);
          if(campo[0].type == "radio") {
            top.marcaRadio(campo, dados[i][1]);
          }
        }
      }
    }
  } 
}

top.marcaRadio = function(campo, valor) {
  for(m = 0; m < campo.length; m++) {
    if(campo[m].value == valor) {
      campo[m].checked = true;
      return;
    }
  }
}

top.marcaSelect = function(campo, valor) {
  for(m = 0; m < campo.length; m++) {
    if(campo[m].value == valor) {
      campo[m].selected = true;
      return;
    }
  }
}
/*FIM Funções para carregar dados para alteração*/
/********* FIM FUNCOES GENERICAS *********/

top.Central = function() {
  this.paginas = null;
  this.addPagina = function(pagina) {
    var pag = this.paginas;
    if(pag == null) {
      this.paginas = new top.Pagina(pagina);
      return;
    }
    while(pag.proxima != null) {
      pag = pag.proxima;
    }
    pag.proxima = new top.Pagina(pagina);
  }
 
  this.findPagina = function (nome) {
    var pag = this.paginas;
    while(pag.proxima != null) {
      if(pag.nome == nome) return pag;
      pag = pag.proxima;
    }
  }

  this.zeraPagina = function (nome) {
    this.findPagina(nome).html = "";
  }

  this.zeraTudo = function() {
    var pag = this.paginas;
    while(pag.proxima != null) {
      pag.html = "";
      pag = pag.proxima;
    }
  }

  this.preenche = function() {
    var pag = this.paginas;
    var ret = "0";
    while(pag != null) {
      if(pag.html == "") {
        ret += "," + pag.nome;
      } else {
        top.setInnerHTML(pag.nome, pag.html, top.mainFrame);
      }
      pag = pag.proxima;
    }
    return ret;
  }
}

top.Pagina = function(_nome) {
  this.nome = _nome;
  this.html = top.getInnerHTML(_nome, top.mainFrame);
  this.proxima = null;
}