<!--
/***********************************************
* Script para abrir janelas dos mapas de Seplan
***********************************************/


	function JanelaMapa(newURL,winName) {
	window.open(newURL,winName,'width=680,height=547,top=0,left=0,toolbar=no,resizable=0,scrollbars=yes');
	}

/***********************************************
           Script para abrir janelas
***********************************************/

function janela( pageToLoad, winName, width, height, center, barra) {
	xposition=0;
	yposition=0;
	if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
		xposition = (screen.width - width) / 2;
		yposition = (screen.height - height) / 2;
	}
	args = "width=" + width + ","
	+ "height=" + height + ","
	+ "location=0,"
	+ "menubar=0,"
	+ "resizable=0,"
	+ "scrollbars=" + barra + ","
	+ "status=0,"
	+ "titlebar=0,"
	+ "toolbar=0,"
	+ "hotkeys=0,"
	+ "z-lock=1," //Netscape Only
	+ "screenx=" + xposition + "," //Netscape Only
	+ "screeny=" + yposition + "," //Netscape Only
	+ "left=" + xposition + "," //Internet Explore Only
	+ "top=" + yposition; //Internet Explore Only
	window.open( pageToLoad,winName,args );
}


/***********************************************
    Script para habilitar o menu para o IE
***********************************************/

function IEHoverPseudo() {
  var navItems = getElementsByClass("menuparent",null,"LI");
  for (var i=0; i<navItems.length; i++) {
    navItems[i].onmouseover = function() { this.className += " over"; }
    navItems[i].onmouseout = function() { this.className = "menuparent"; }
  }
}
window.onload = IEHoverPseudo;

function populaComboBox(objetoSelect,opcaoPadrao,valor,itens) {
  objetoSelect.options.length = 1;
  objetoSelect.options[0] = new Option(opcaoPadrao, "");
  for (var indice in itens) {
    if (valor == itens[indice][0]) {
      objetoSelect.options[parseInt(indice)+1] =
      new Option(itens[indice][1], itens[indice][0], true);
      objetoSelect.options[parseInt(indice)+1].selected = true;
    } else {
      objetoSelect.options[parseInt(indice)+1] =
      new Option(itens[indice][1], itens[indice][0]);
    }
  }
}

function incluirDocumentoAudio(tabela, documentos, codigoDocumento, codigoFaixa) {
  var tabela = document.getElementById(tabela);
  var ultimaLinha = tabela.rows.length;

  // Adiciona cabeçalho se for a primeira linha
  if (ultimaLinha == 0) {
    // Cria linha
    var linha = tabela.insertRow(ultimaLinha);

    // Coluna de documentos
    var texto = document.createTextNode('TÍTULO');
    var colunaDocumento = linha.insertCell(0);
    colunaDocumento.className = 'titulogrid';
    colunaDocumento.valign = 'top';
    colunaDocumento.appendChild(texto);

    // Coluna do código da faixa
    var texto = document.createTextNode('FAIXA');
    var colunaFaixa = linha.insertCell(1);
    colunaFaixa.className = 'titulogrid';
    colunaFaixa.valign = 'top';
    colunaFaixa.appendChild(texto);

    // Coluna do botão de remoção do DocumentoAudio
    var colunaBotao = linha.insertCell(2);
  }

  var ultimaLinha = tabela.rows.length;

  // Cria linha
  var linha = tabela.insertRow(ultimaLinha);

  // Coluna de documentos
  var documento = document.createElement('select');
  documento.name = 'codigoDocumento[]';
  documento.className = 'form1';
  populaComboBox(documento,"Selecione um documento...",codigoDocumento,documentos);
  var colunaDocumento = linha.insertCell(0);
  colunaDocumento.appendChild(documento);

  // Coluna do código da faixa
  var faixa = document.createElement('input');
  faixa.name = 'codigoFaixa[]';
  faixa.type = 'text';
  faixa.size = 4;
  faixa.maxLength = 4;
  faixa.className = 'form1';
  faixa.style.textTransform = 'uppercase';
  if (codigoFaixa) { faixa.value = codigoFaixa; }
  var colunaFaixa = linha.insertCell(1);
  colunaFaixa.appendChild(faixa);

  // Coluna do botão de remoção do DocumentoAudio
  var botao = document.createElement('input');
  botao.type = 'button';
  botao.value = 'Desassociar';
  botao.className = 'botao1';
  botao.onclick = function() {
    if (this.parentNode.parentNode.parentNode.getElementsByTagName('tr').length == 2) {
      this.parentNode.parentNode.parentNode.removeChild (
        this.parentNode.parentNode.parentNode.getElementsByTagName('tr').item(0)
      );
    }
    this.parentNode.parentNode.parentNode.removeChild( this.parentNode.parentNode );
    return false;
  };
  var colunaBotao = linha.insertCell(2);
  colunaBotao.appendChild(botao);

}

function XMLHTTPRequest() {
  try { return new XMLHttpRequest(); }
  catch(ee) {
    if (window.ActiveXObject) {
      var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
      for (var i = 0; i < prefixes.length; i++) {
        try { return new ActiveXObject(prefixes[i] + ".XmlHttp"); }
        catch(E) { return false; } // doesn't support
      } // for
    } // if
  } // catch
} // function

function carregaCidadesAjax(form, objeto, filtro, valorSelecionado) {
  var carregando = document.getElementById("carregando");
  if (carregando != null) {
    carregando.style.left = 400;
    carregando.style.top = 450;
  }
  var ajax = XMLHTTPRequest();
  ajax.open("GET", "../ajax/Cidades.php?filtro=" + filtro, true);
  ajax.onreadystatechange = function() {
    if (ajax.readyState == 1) {
      if (carregando != null) {
        carregando.style.display = "block";
      }
    }
    if (ajax.readyState == 4) {
      if (carregando != null) {
        carregando.style.display = "none";
      }
      var response = unescape(ajax.responseText);
      rows = response.split("#");
      document.forms[form].elements[objeto].options.length = 1;
      for (i = 0; i < rows.length; i++) {
        rowInfo = rows[i].split(":");
        if (rowInfo[0])
          if (rowInfo[0] == valorSelecionado) {
            document.forms[form].elements[objeto].options[i+1] =
            new Option(rowInfo[1], rowInfo[0], true);
            document.forms[form].elements[objeto].options[i+1].selected = true;
          } else {
            document.forms[form].elements[objeto].options[i+1] =
            new Option(rowInfo[1], rowInfo[0]);
          }
        else break;
      } // for
    } // if
  } // ajax.onreadystatechange = function()
  ajax.send(null);
  return true;
} // function

/***********************************************
    Script para procurar por objetos de
    uma determinada classe
***********************************************/

function getElementsByClass(searchClass,node,tag) {
  var classElements = new Array();
  if ( node == null )
    node = document;
  if ( tag == null )
    tag = '*';
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
    if ( pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}

//-->
