// JavaScript Document

var LetrasComAcentos = "????????????????????????"
var LetrasSemAcentos = "AAAAAAEEEEIIIIOOOOOUUUUC"

function sendFile(jspPage) {
    W = 400;
    H = 200;
    posX = ((screen.width - W) / 2) - 5
    posY = ((screen.height - H) / 2) - 32
    window.open(jspPage,'sendFile','width='+W+',height='+H+',top='+posY+',left='+posX+',location=no,menubar=no,toolbar=no,status=no,scrollbars=yes');
}

function mostraSpan(span) {
	document.getElementById(span).style.display = "block";
}

function escondeSpan(span) {
	document.getElementById(span).style.display = "none";
}
// Altura, Largura, Top, Left -> integer
// Location, menuBar, toolBar, Status, scrollBar -> yes/no
function abrePopUp(Arquivo, Codigo1, Codigo2, Codigo3, Altura, Largura, Top, Left, Location, menuBar, toolBar, Status, scrollBars)
{
	sec = window.open(Arquivo+'?cod1='+Codigo1+'&cod2='+Codigo2+'&cod3='+Codigo3,"","width="+Altura+",height="+Largura+",top="+Top+",left="+Left+",location="+Location+",menubar="+menuBar+",toolbar="+toolBar+",status="+Status+",scrollbars="+scrollBars+"");
	sec.focus();
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  if (selObj.options[selObj.selectedIndex].value!="") {
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
  }
}

function tirarAscentos(palavra) {
	var valCampo = palavra;
	var i = 0;
	var j = 0;
	valCampo = valCampo.toUpperCase();
	  for (i = 0;  i < valCampo.length;  ++i) {
		for (j = 0;  j < LetrasComAcentos.length;  ++j) {
		  if (valCampo.charAt(i) == LetrasComAcentos.charAt(j)) {
			valCampo = valCampo.replace(valCampo.charAt(i), LetrasSemAcentos.charAt(j));
		  }
		}
	  }

	return valCampo;
}

//funcao que retira acentos e ? das descricoes
function criaCampoIndex(sThis) {
	var valCampo = sThis.value;
	var nomeCampo = sThis.name + "_Index";
	var i = 0;
	var j = 0;
	valCampo = valCampo.toUpperCase();
	  for (i = 0;  i < valCampo.length;  ++i) {
		for (j = 0;  j < LetrasComAcentos.length;  ++j) {
		  if (valCampo.charAt(i) == LetrasComAcentos.charAt(j)) {
			valCampo = valCampo.replace(valCampo.charAt(i), LetrasSemAcentos.charAt(j));
		  }
		}
	  }

	document.getElementById(nomeCampo).value = valCampo;
}

//Busca nome no ComboBox
function buscaRegistro(campoBusca, comboBox)
{
	if (document.getElementById(campoBusca).value.length != 0)
	{
		var i;
		var re = new RegExp("^" + document.getElementById(campoBusca).value, "i");
		re.compile;
		for (i = 0; i < document.getElementById(comboBox).length; i++) {
			if (re.test(document.getElementById(comboBox).item(i).text)) {
				document.getElementById(comboBox).selectedIndex = i;
				break;
			}
		}
	}
}

var idTimeOut;
var url;
var idIFrame;
function pesquisa(id, tipo, tabela, codTabela, labelTabela, tipoCod) {
	textoUp = document.getElementById(id+"_TextBox").value;
	textoUp = textoUp.toUpperCase();
	for (i = 0;  i < textoUp.length;  ++i) {
		for (j = 0;  j < LetrasComAcentos.length;  ++j) {
			if (textoUp.charAt(i) == LetrasComAcentos.charAt(j)) {
				textoUp = textoUp.replace(textoUp.charAt(i), LetrasSemAcentos.charAt(j));
			}
		}
	}
    idIFrame = id;
    url = "listBoxAjax.jsp?id="+id+"&tipo="+tipo+"&texto="+textoUp+"&tabela="+tabela+"&codTabela="+codTabela+"&labelTabela="+labelTabela+"&tipoCod="+tipoCod;
	clearTimeout(idTimeOut);
	idTimeOut = setTimeout("updateValores()",800);

	//document.getElementById(id+'_IFrame').src = "listBoxAjax.jsp?id="+id+"&tipo="+tipo+"&texto="+textoUp+"&tabela="+tabela+"&codTabela="+codTabela+"&labelTabela="+labelTabela+"&tipoCod="+tipoCod;
}

function updateValores() {
    document.getElementById(idIFrame+'_IFrame').src = url;
}

function exibe(id, w, h) {
	iframe = document.getElementById(id+'_IFrame');
	myElement = document.getElementById(id+'_tamanhoHidden');
	iframe.width = myElement.value;//w;
	iframe.height = h;
	iframe.style.top = document.getElementById(id+"_Div").style.top;
	iframe.style.left = document.getElementById(id+"_Div").style.left;
	iframe.style.display = 'block';
}

function esconde(id) {
	iframe = document.getElementById(id+'_IFrame');
	iframe.width = 0;
	iframe.height = 0;
	iframe.style.top = 0;
	iframe.style.left = 0;
	iframe.style.display = 'none';
}

function selecionarTodosCheckBox(obj, id, inicio, fim){
    for(i=inicio;i<=fim;i++){
        if(document.getElementById(id + i).checked != obj.checked) {
            document.getElementById(id + i).checked=obj.checked;
            somaListaChaveRegistro(document.getElementById(id + i).value);
         }
    }
}

function somaListaChaveRegistro(obj){   
    pos=document.getElementById("listRowSelected").value.indexOf("-" + obj + ";");
    if (pos ==-1){
      document.getElementById("listRowSelected").value+= "-" + obj + ";";
      document.getElementById("countRowSelected").value++;
    }
    else{ 
      document.getElementById("listRowSelected").value=document.getElementById("listRowSelected").value.substring(0,pos)+document.getElementById("listRowSelected").value.substring(pos+obj.length+2,document.getElementById("listRowSelected").value.length);
      document.getElementById("countRowSelected").value--;
    }
    //alert(document.getElementById("listRowSelected").value);
}

function detalharTodosRegistrosSelecionados(){
    if (document.getElementById("listRowSelected").value.length == 0){
        alert("Nenhum item foi selecionado!");
        return false;
   }
   document.getElementById("paginaHidden").value = "1";
   document.getElementById("acaoHidden").value = "listarDetalhes";
   document.getElementById("acaoAux").value = "inserir";
   submitForm();
}

function detalharRegistro(codDetalhe){
   document.getElementById("codDetalheHidden").value = codDetalhe;
   document.getElementById("acaoHidden").value = "listarDetalhe";
   submitForm();
}

function goToPage(page, acao){
    document.getElementById("acaoHidden").value = acao;
    document.getElementById("paginaHidden").value = page;
    submitForm();
}

function inserirTodosRegistrosSelecionados(){
    if (document.getElementById("listRowSelected").value.length == 0){
        alert("Nenhum item foi selecionado");
        return false;
   }
   document.getElementById("paginaHidden").value = "1";
   document.getElementById("acaoHidden").value = "inserirRegistros";
   myForm = document.forms[0];
   myForm.action = "estanteDigital.jsp";
   submitForm();
}

function inserirRegistro(codDetalhe){
   document.getElementById("codDetalheHidden").value = codDetalhe;
   document.getElementById("acaoHidden").value = "inserirRegistro";
   myForm = document.forms[0];
   myForm.action = "estanteDigital.jsp";
   submitForm();
}

function pop(html){
   window.open(html, "", "width=710, heigth=610");
}


