/***********************************************************************
 Funcao que susbtituir um carater por outro em uma string
 Parametros : str --> string completa 
              vlr1 --> caracter a ser retirado
			  vlr2 --> caracter a ser incluido em substituição ao anterior
************************************************************************/							  
function replace(str,vlr1,vlr2){
  txtatua = str;
  txtant = '';
  while (txtant!=txtatua){
    txtant = txtatua;
    txtatua = txtatua.replace(vlr1,vlr2);	
  }
  return txtatua;
}

/***********************************************************************
 Funcao que adiciona dias a uma data
 Parametros : data --> data inicial no formato dd/mm/yyyy , se for vazia usa a data atual
************************************************************************/							  

function fn_ultima_data_mes(data)
{
	if (data == "" || data == "undefined"){
	  data_atual = new Date();
	}else{
	  date_parte = data.split("/");
      data_atual = new Date(date_parte[2],date_parte[1],date_parte[0]);		   
	}
	mes_atual = data_atual.getMonth() +1;
	switch(mes_atual){
	case 2:data_atual.setDate(29);
		   if (data_atual.getDate() != 29)
				data_atual.setDate(28);
   		   break;
	case 1:
	  data_atual.setDate(31);
	break;
	case 3:
	  data_atual.setDate(31);
	break;
	case 5:
	  data_atual.setDate(31);
	break;
	case 7:
	  data_atual.setDate(31);
	break;
	case 8:
	  data_atual.setDate(31);
	break; 
	case 10:
	  data_atual.setDate(31);
	break; 
	case 12:
	  data_atual.setDate(31);
	break;
	case 4:
	  data_atual.setDate(30);
	break;
	case 6:
	  data_atual.setDate(30);
	break;
	case 9:
	  data_atual.setDate(30);
	break;
	case 11:
	  data_atual.setDate(30);
	break;
	}
	
	if ((data_atual.getDate()) >=10){
		dia = (data_atual.getDate());
	}else{
		dia = "0" + (data_atual.getDate());
	}
	
	if ((mes_atual) < 10){
		mes_atual = "0" + mes_atual;
	}
return dia + "/" + mes_atual + "/" + data_atual.getFullYear();
}


/***********************************************************************
 Funcao que adiciona dias a uma data
 Parametros : data --> data inicial no formato dd/mm/yyyy , se for vazia usa a data atual
              incremento --> numero de dias a incrementar
************************************************************************/							  
function addDate(data,incremento)
{
	var dia,mes,ano,data_atual, date_parte
	
	if (data == "") { 
  	  data_atual = new Date();	
	}else{
	  date_parte = data.split("/");
      data_atual = new Date(date_parte[2],date_parte[1],date_parte[0]);		 
    }
	if ((data_atual.getDate() + incremento) >=10){
		dia = (data_atual.getDate() + incremento);
	}else{
		dia = "0" + (data_atual.getDate() + incremento);
	}
	if ((data_atual.getMonth()+1) >=10){
		mes = (data_atual.getMonth()+1);
	}else{
		mes = "0" + (data_atual.getMonth()+1);
	}
	ano = data_atual.getFullYear();
	return dia + "/" + mes + "/" + ano
}


/***********************************************************************
Funcao que limita a quantidade maxima de caracteres digitados num campo
 Parametros : linhas --> id das linhas da tabela
************************************************************************/							  


function tam_max(field){
	if(field.value.length >255)
		return false;
}



/**************************************************************
 Funcao para esconder ou mostrar as linhas de uma tabela
 Parametros : linhas --> id das linhas da tabela
*************************************************************/							  

   function ExpandeLinha(target)
  {       
	  if (target.length != null){
        event.srcElement.src=(target[0].style.display=='none') ? 'images/menumenos.gif' : 'images/menucruz.gif';	  
  	    for ( var pos = 0 ; pos < target.length ; pos++ )
	    {  
	      target[pos].style.display=(target[pos].style.display=='none') ? 'inline' : 'none';
	    } 
	  }else{
        event.srcElement.src=(target.style.display=='none') ? 'images/menumenos.gif' : 'images/menucruz.gif';	  
        target.style.display=(target.style.display=='none') ? 'inline' : 'none';
	  }
  }
  
function mask_mes_ano(field){
  var numero = new Array ();
  var str = field.value.replace("/","")
  
	//permite o backspace
	if (event.keyCode  == 13){
		numero.pop();
		return true;   
	}
	
	//coloca / no vetor, se o cara digitar na posicao correta
	if ((str.length == 2) && (event.keyCode == 47)){
		numero.push("/");	    	
		return true;		
	}
		
	//testa se é um numero de 0 a 9
	if ((event.keyCode  < 48) || (event.keyCode  > 57)){  
		field.focus();     
		return false
	}   		


	//coloca toda a string num vetor	
	for (i=0; i<str.length; i++){
		numero.push(str.substring(i, i+1));
		if (i == 1)
			numero.push("/");	    
	}

field.value = numero.join("");
return true;
}






/**************************************************************
 Funcao que Abre um popup convencional
 Parametros : theURL --> Url que ira abrir
                     winName --> nome de janela
			   features --> caracteristicas da janela, tamanho, altura, etc
*************************************************************/							  
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



/**************************************************************
 Funcao que Abre um popup modal
 Parametros : theURL --> Url que ira abrir
                     winName --> nome de janela
			   features --> caracteristicas da janela, tamanho, altura, etc
*************************************************************/							  
function MM_openModal(theURL,winName,features) { //v2.0
   rv =  window.showModalDialog(theURL,winName,features);
   return rv;
}


/**************************************************************
 Funcao que Verifica se um campo eh numerico (positivo)
 Parametros : field --> Nome do campo
                     msg   --> mensagems que será exibida se houver erro

*************************************************************/							  
function isNumber(field,msg){

  data = field.value;   

   //testa infinitos numeros sem virgula
   var r1 = new RegExp("^([0-9]+)$");

   //testa infinitos numeros com virgula
   var r2 = new RegExp("^([0-9]+\\,[0-9]{0,2})$");

   //testa numero com pontos e virgulas
   var r3 = new RegExp("^[0-9]{1,3}(\\.[0-9]{3})*(\\,[0-9]{0,2}){0,1}$");

 //  return((r1.test(data)) || (r2.test(data)) || (r3.test(data)) )
      
   if ( ((r1.test(data)) || (r2.test(data)) || (r3.test(data))) == true) 
      return true;
   else{
      alert(msg);
	field.focus();  
      return false;	
   }	

}


/**************************************************************
 Funcao que Verifica se um campo eh inteiro
 Parametros : field --> Nome do campo
                     msg   --> mensagems que será exibida se houver erro

*************************************************************/							  
function isInteiro(objNum,msg) {
   data = objNum.value;   
   var numStr = "0123456789";
   var thisChar;
   var counter = 0;
   for (var i=0; i<data.length; i++){
       thisChar = data.substring(i, i+1);
       if (numStr.indexOf(thisChar) != -1)
           counter++;
   }
   if (counter == data.length){
      return(true);
   }else{
		alert(msg);
		objNum.focus();		
	  	return false;
   }
	return true;
}


/**************************************************************
 Funcao que Verifica se um campo eh vazio
 Parametros : field --> Nome do campo
                     msg   --> mensagems que será exibida se houver erro

*************************************************************/							  

function isVazio(field,msg){
   var thisChar;
   var counter = 0;
   var str;
    str = field.value
    if ( str == "" ) {
            if (typeof(msg) != "undefined"){ 
		   alert(msg)
		   field.focus()
		}   
		return true;
    }

    for (var i=0; i<str.length; i++){
       thisChar = str.substring(i, i+1);
       if (thisChar == " ")
           counter++;
   }

   if (counter == str.length){
       if (typeof(msg) != "undefined"){
	    alert(msg);
          field.focus();		
	 }   
      return true;
   }
   
    return false;	
}

/**************************************************************
 Funcao que Verifica se um campo eh zero
 Parametros : field --> Nome do campo
                     mensagem   --> mensagems que será exibida se houver erro

*************************************************************/							  
function isZero(field,msg){
    str = field.value
    if  ( str == 0) {
		 if (typeof(msg) != "undefined"){ 
		 	alert(msg)
		   	field.focus()
		 }
		return true;
	}
    return false;	
}


/**************************************************************
 Funcao que Verifica  se é ou naum um email valido
 Parametros : str --> Email

*************************************************************/							  
function isEmail(str) {
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}



/**************************************************************
 Funcao que monta uma mascara para data
 Parametros : field --> objeto do form de data (campo de data)

*************************************************************/							  
function maskdata(field,teclapres){

  var caracter = teclapres.keyCode;
  
  if (caracter  == 13)
    return true;
  
  if (((field.value.length == 2) || (field.value.length == 5)) && (caracter == 47))
     field.value = field.value + '/';
 
  if ((caracter  < 48) || (caracter  > 57)){  
     field.focus();     
     return false
  }
  else{
        if (  ((field.value.length == 2) || (field.value.length == 5))  && (caracter != 8)  )
 	      field.value = field.value + '/';
  }
  
 
return true;
}


/**************************************************************
 Funcao que testa uma mascara passada.
 Parametros : codigo --> o objeto que se quer testar.
			   mascara --> mascara usando a barra como separador.
           			                      utiliza formato 99/99/999 para valores numericos
							    e aaa/aa/aaaa/aa para valores alpha

*************************************************************/							  

function mask_generica(codigo,mascara){
  str = mascara;
  fim = str.length;
  valor = codigo.value;
  posicao = valor.length -1;
  tipo = str.charAt(posicao);
  
  if ((tipo == "a") || (tipo == "A")){
     if ((valor.charCodeAt(posicao) >= 48) && (valor.charCodeAt(posicao) <= 57) ||
		(valor.charCodeAt(posicao) >= 65) && (valor.charCodeAt(posicao) <= 90) ||
		(valor.charCodeAt(posicao) >= 97) && (valor.charCodeAt(posicao) <= 122)) {
		tipo = str.charAt(posicao+1);
             cont = posicao + 1;
		while ((tipo!="a") && (tipo!="A") && (tipo!="9") && (tipo!="") ) {
			codigo.value=codigo.value+tipo;
                    cont = cont + 1;
 		       tipo = str.charAt(cont);
		}
	 } else { 
		codigo.value = codigo.value.substr(0,posicao);
	 }
  } else {
	if (tipo == "9") {
		if ((valor.charCodeAt(posicao) >= 48) && (valor.charCodeAt(posicao) <= 57)) {
			tipo = str.charAt(posicao+1);
            cont = posicao + 1;
			while ((tipo!="a") && (tipo!="A") && (tipo!="9") && (tipo!="")) {
				codigo.value=codigo.value+tipo;
                           cont = cont + 1;
 	   	              tipo = str.charAt(cont);
			}
		} else { 
			codigo.value = codigo.value.substr(0,posicao);
		}
	} else {
        	tipo = str.charAt(posicao+1);
            cont = posicao + 1;
			while ((tipo!="a") && (tipo!="A") && (tipo!="9") && (tipo!="")) {
				codigo.value=codigo.value+tipo;
                           cont = cont + 1;
 	   	              tipo = str.charAt(cont);
			}
	}
  }
  codigo.value = codigo.value.substr(0,fim - 1) ;
  return true;
}



/**************************************************************
 Funcao que verifica se uma data eh válida no formato dd/mm/aaa
 Parametros : objdata --> objeto do form de data (campo de data)

*************************************************************/							  

function isDate(objdata){
	if ((objdata.value.length < 10) || (objdata.value.length == "")) {
		alert("Formato inválido. Formato indicado: dd/mm/aaaa. Ex: 01/01/2002");
		objdata.focus();
		return false;
	}
	dia = objdata.value.substr(0,2);
	mes = objdata.value.substr(3,2);
	ano = objdata.value.substr(6,4);
    if   ((isNaN(parseInt(dia)) || isNaN(parseInt(mes)) ||
    isNaN(parseInt(ano))) ||
		(ano < 1900 || ano > 9999) ||
        (mes < 1 || mes > 12) ||
        (dia < 1 || dia > 31) ||
        (mes == 2 && dia > 28 && (ano % 4 != 0)) ||
        (mes == 2 && dia > 29 && (ano % 4 == 0)) ||
        (dia > 30 && (mes == 4 || mes == 6 || mes == 9 || mes == 11))) {
			alert("Data inválida! Informe uma data válida.");
			objdata.focus();
			return false;
    }else {
            return true;
    }
}

/**************************************************************
 Funcao que verifica se uma data eh válida no formato dd/mm/aaa
 Parametros : objdata --> objeto do form de data (campo de data)

*************************************************************/							  

function isDateMesAno(objdata){
	if ((objdata.value.length < 7) || (objdata.value.length == "")) {
		alert("Formato inválido. Formato indicado: mm/aaaa. Ex: 01/2002");
		objdata.focus();
		return false;
	}
	mes = objdata.value.substr(0,2);
	ano = objdata.value.substr(3,4);

    if   ( isNaN(parseInt(mes)) || isNaN(parseInt(ano))  || (ano < 1900 || ano > 9999) || (mes < 1 || mes > 12) )
    {
		alert("Data inválida! Informe uma data válida.");
		objdata.focus();
		return false;
    }else {
            return true;
    }
}




/**************************************************************
 Funcao que valida a data inicial com a final.
 Parametros : tx_dt_ini - objeto data inicial
			  tx_dt_fim - objeto data final
*************************************************************/		

//FUNCAO QUE TESTA SE A DATA INICIAL É MENOR QUE A DATA FINAL

function compara_data(tx_dt_ini,tx_dt_fim, msg){
  var dia, mes, ano
  
  if (isDate(tx_dt_ini)){	   

	dia = tx_dt_ini.value.substr(0,2);
	mes = tx_dt_ini.value.substr(3,2);
    ano = tx_dt_ini.value.substr(6,4);
		
	var dtinicial = new Date(ano + "/" + mes + "/" + dia);
		
   }	
   else
     return false;	
	 	 

  if (isDate(tx_dt_fim)){	   

	dia = tx_dt_fim.value.substr(0,2);
	mes = tx_dt_fim.value.substr(3,2);
    ano = tx_dt_fim.value.substr(6,4);
		
	var dtfinal = new Date(ano + "/" + mes + "/" + dia);
		
   }	
   else 
     return false;	
	 

   if (dtinicial > dtfinal){
    if (typeof(msg) != "undefined")
     alert(msg);
    else 	 
     alert("Data final deve ser maior que Data Inicial.");
    tx_dt_fim.focus();	 
    return false;
 }
return true;
}


/**************************************************************
 Funcao que valida CPF e CGC com máscara 
 
 Parametros : frm - nome do formulario
			  acao - acao (INCLUIR/EXCLUIR/CONSULTAR/etc..)

*************************************************************/							  

function valida_CPF_mascara(tx_cpf,msg){

	if(!isVazio(tx_cpf)){
		var cpf 
		
		cpf = tx_cpf.value
		
		cpf = cpf.replace(/\./g,"");
		cpf = cpf.replace("/","");
		cpf = cpf.replace(/-/g,"");
				
		if (!valida_cpf(cpf, msg)){
			tx_cpf.focus();
			return false;
		}
	}
	return true;
}



/**************************************************************
 Funcao que valida CPF e CGC
 
 Parametros : frm - nome do formulario
			  acao - acao (INCLUIR/EXCLUIR/CONSULTAR/etc..)

*************************************************************/							  
// funcao de validacao de cgc & cpf
var cpf_;
cpf_ = new Array(10);
cpf_[0]="11111111111";
cpf_[1]="22222222222";
cpf_[2]="33333333333";
cpf_[3]="44444444444";
cpf_[4]="55555555555";
cpf_[5]="66666666666";
cpf_[6]="77777777777";
cpf_[7]="88888888888";
cpf_[8]="99999999999";
cpf_[9]="00000000000";

//********* valida cpf
function valida_cpf(msCPF_CGC, msMSG){
	if ((msCPF_CGC.length != 14) && (msCPF_CGC.length !=11)){
		alert(msMSG);
		return false;
	}

	if ((!(modulo(msCPF_CGC.substring(0,msCPF_CGC.length - 2)).toString()+modulo(msCPF_CGC.substring(0,msCPF_CGC.length - 1)).toString() == msCPF_CGC.substring(msCPF_CGC.length - 2,msCPF_CGC.length))) && (modulo_cic(msCPF_CGC.substring(0,msCPF_CGC.length - 2)) + "" + modulo_cic(msCPF_CGC.substring(0,msCPF_CGC.length - 1)) != msCPF_CGC.substring(msCPF_CGC.length - 2,msCPF_CGC.length))){
		alert(msMSG);
		return false;
	}
	return true;
}

function modulo(msCPF_CGC){
	soma=0;
	ind=2;

	for(pos=msCPF_CGC.length-1;pos>-1;pos=pos-1){
		soma = soma + (parseInt(msCPF_CGC.charAt(pos)) * ind);
		ind++;

		if(msCPF_CGC.length>11){
			if(ind>9) ind=2;
        }
	}

	resto = soma - (Math.floor(soma / 11) * 11);

	if(resto < 2){
		return 0;
	}
	else{
		return (11 - resto);
	}
}
function modulo_cic(msCPF_CGC){
   	soma=0;
	ind=2;

	for(pos=msCPF_CGC.length-1;pos>-1;pos=pos-1){
		 soma = soma + (parseInt(msCPF_CGC.charAt(pos)) * ind);
		 ind++;

		 if(msCPF_CGC.length>11){
		    if(ind>9) ind=2;
		 }
	}

	resto = soma - (Math.floor(soma / 11) * 11);

	if(resto < 2){
		return 0;
	}
	else{
		return 11 - resto;
	}
}


function validacaoParam(tx_cpf)
{
	if (tx_cpf.value==""){
		alert("Preencha o campo 'CPF'.");
		tx_cpf.focus();
		return false;
	}
	else if (tx_cpf.value.length<11)
	{
		if(isNaN(tx_cpf.value))
		{
			alert("CPF deverá conter apenas números.");
			return false;
		}
		var tot = 11-tx_cpf.value.length;
		var comp1="";
		for (i=1;i<=tot;i++)
		{
			comp1+="0";
		}
		comp1+=comp;
		if(!checa(comp1, "CPF Inválido."))
		{
			//tx_cpf.value="";
			tx_cpf.focus();
			return false;
		}
		//document.form.submit();
	}else if (tx_cpf.value.length>=11)
	{
		if(isNaN(tx_cpf.value))
		{
			alert("CPF deverá conter apenas números.");
			return false;
		}
		var comp = tx_cpf.value;
	var sString = "-/.";
		for(i=0;i<sString.length;i++)
		{
			if (comp.indexOf(sString.substring(i))!=-1)
			{
				alert("fez replace");
				comp = comp.replace(indexOf(i),1);
			}
		}
		alert("comp  "+comp);
		for (var i=0;i<=cpf_.length;i++)
		{
			if (comp.indexOf(cpf_[i])!=-1){
				alert("CPF Inválido.");
				tx_cpf.focus();
				return false;
				}
		}

		if(!checa(tx_cpf.value, "CPF Inválido."))
		{
			//tx_cpf.value="";
			tx_cpf.focus();
			return false;
		}
	}
}

/**************************************************************
 Funcao que Insere um item num combo aberto
 Parametros : src -> objeto
			  cor -> cor
			  strTxt -> 
			  tipo_cursor -> tipo do cursor
*************************************************************/							  

function insereItemCombo( origem,  destino )
  {
      if (origem.selectedIndex >= 0 ){
	  
	  existe = false;
      for ( lnx = 0 ;  lnx < destino.length && !existe ; lnx++ )
	  {
	      if ( destino.options[ lnx ].value == origem.value ) 
		  {
		     existe = true;
   	         alert( "Transportadora já Associada !! " );
		     //return false;
			 
		  }
	  }
	  
      if (!existe) {
	  destino.length =  destino.length + 1;
	  destino.options[ destino.length -1 ].value = origem.value;
	  destino.options[ destino.length -1 ].text = origem.options[ origem.selectedIndex ].text
	  }
	  }	  
  }
  
/**************************************************************
 Funcao que remove item do Combo aberto
 Parametros : src -> objeto
			  cor -> cor
			  strTxt -> 
			  tipo_cursor -> tipo do cursor
*************************************************************/							  
  
  
  function removeItemCombo( campo ) 
  {
		
      if ( campo.selectedIndex >= 0 )
         campo.options[ campo.selectedIndex ] = null;
				  
  }

/**************************************************************
 Funcao que remove todos os itens do Combo aberto
 Parametros : src -> objeto
			  cor -> cor
			  strTxt -> 
			  tipo_cursor -> tipo do cursor
*************************************************************/							  
  
  
  function removeTodosItensCombo( campo ) 
  {
		
      campo.length = 0;
				  
  }
  
  
/**************************************************************
 Funcao que Insere um item num combo aberto
 Parametros : src -> objeto
			  cor -> cor
			  strTxt -> 
			  tipo_cursor -> tipo do cursor
*************************************************************/							  

function insereTodosItensCombo( origem,  destino )
  {
        
	  existe = false;
       
	  destino.length =  origem.length;
	  for ( lnx = 0 ;  lnx < origem.length  ; lnx++ )
	  {
	  destino.options[ lnx ].value = origem[ lnx  ].value;
	  destino.options[ lnx ].text = origem.options[ lnx ].text;
	  }
  }
/**************************************************************
 Funcao que converter letras minusculas para maiusculas
 Parametros : objeto textfield
*************************************************************/		
function minusculo_to_maiusculo(campo)
{
	if(event.keyCode >= 65 && event.keyCode <= 90) 
		campo.value =(campo.value).toUpperCase()
}
	
/**************************************************************
 Funcao que formata num numero para que o mesmo possa
 ser incluido numa operação matemática
 Parametros : campo.value
*************************************************************/		
function formata_numero(numero)
{
	
	vetor = numero.split(".");
	str = "";
	for(i=0;i<vetor.length;i++)
	{
		str = str + vetor[i];	
	
	}
	str.replace(",",".");
	return str.replace(",","."); 
	

}


/**************************************************************
 Funcao que dado um numero, ele coloca a mascara para o formato
 999.999,999
 Parametros : objeto textfield.value
*************************************************************/		
function mask_soma(numero)
{

	strNumero = numero.toString();
	ind =0;
	str = "";
	if (strNumero == strNumero.split("."))
	{
		while (strNumero != "")
		{
			vetor[ind] = strNumero.slice(strNumero.length-3);
			strNumero = strNumero.slice(0,strNumero.length-3);
			ind = ind +1;	
		}
		for (i=vetor.length;i>0;i--)
		{
			if (i == 1)
			{
				str = str + vetor[i-1] + ",000";
			}
			else
			{
				str = str + vetor[i-1] + ".";
			}
	
		}
		
	}
	else
	{
		strNumero = strNumero.split(".");
		while (strNumero[0] != "")
		{
			vetor[ind] = strNumero[0].slice(strNumero[0].length-3);
			strNumero[0] = strNumero[0].slice(0,strNumero[0].length-3);
			ind = ind +1;	
		}
		for (i=vetor.length;i>0;i--)
		{
			if (i == 1)
			{
				str = str + vetor[i-1] + ",";
			}
			else
			{
				str = str + vetor[i-1] + ".";
			}
	
		}
	
		switch(strNumero[1].length)
		{
		case 2: str = str + strNumero[1]+"0";
				break;
		case 1: str = str + strNumero[1]+"00"
				break;
		}
	}
return str;

}

/****************************************************************
	Essa função deverá ser altera para atender as necessidades da página em questão. 
***************************************************************/

function ModalWindow( pagina, formelement, campo, titulo)
{  	
	if (formelement==""){
		janela = abreJanelaModal(pagina, titulo, 200, 230, -1, -1, campo);
	}
	else{
		var data;
		if (!isDate(campo)) {
		 return false;
		}		
		data=formelement.split("/");
		janela = abreJanelaModal(""+pagina+"?diam="+data[0]+"&mesa="+data[1]+"&anoa="+data[2]+"", titulo, 200, 230, -1, -1, campo);
	}
}  

/*******************************************************************
Parâmetros:

	pPagina: 	Nome da página que será aberta na janela Modal
	pnmJanela: 	Nome da janela
	pLargura: 	Largura da janela
	pAltura: 	Altura da janela
	pTopo: 		Distância em relação ao topo
	pEsquerda: 	Distância em relação a lateral esquerda

obs: Caso os valores de pTopo e pEsquerda sejam passados com valor "-1", sua posição na tela será centralizada
*/
function abreJanelaModal( pPagina, pnmJanela, pLargura, pAltura, pTopo, pEsquerda, campo){
    var ltxtaux;
	if ( ( pAltura == -1 ) || ( pEsquerda == -1 ) ) 
		ltxtaux = ";center:1";
	else   
		ltxtaux = ";dialogTop:"+pTopo+"px;dialogLeft:"+pEsquerda+"px"; 
//		window.open(pPagina)
		rvalor=  window.showModalDialog( pPagina, pnmJanela, "dialogWidth:"+pLargura+"px;dialogHeight:"+pAltura+"px;scroll:0;help:0;status:0"+ltxtaux );
	if ((rvalor!="")&&(rvalor!=null)){
		campo.value =rvalor;
	}
}

function Incluir(p_tela,p_param){

  if (p_param ==  null){
	p_param= ""
  }
  parent.location.href="ap_cad_"+p_tela+".asp?acao=Incluir"+p_param;
}

function Alterar(p_tela,p_param){
  parent.location.href="ap_cad_"+p_tela+".asp?acao=Alterar&"+p_param;
}

function Excluir(p_tela,p_param){
  parent.location.href="ap_cad_"+p_tela+".asp?acao=Excluir&"+p_param;
}
function Consultar(p_tela,p_param){
  parent.location.href="ap_cad_"+p_tela+".asp?acao=Consultar&"+p_param;

}

function Acao_janela(p_tela,p_acao, p_param,p_larg, p_alt){
  rvalor=  window.showModalDialog("ap_cad_"+p_tela+".asp?acao="+p_acao+"&"+p_param, "Fase", "dialogWidth:"+p_larg+"px;dialogHeight:"+p_alt+"px;scroll:0;help:0;status:0;center:1");
//window.open("ap_cad_"+p_tela+".asp?acao="+p_acao+"&"+p_param, "Fase", "dialogWidth:"+p_larg+"px;dialogHeight:"+p_alt+"px;scroll:0;help:0;status:0;center:1");
  window.location.href=window.location.href;
}

function abrirNoticia(p_codigo){
  oForm.id_noticia.value = p_codigo
  oForm.submit();
}
function soNumero(field,evento){

  var caracter = evento.keyCode;
  
  if (caracter  == 13)
    return true;
 
  if ((caracter  < 48) || (caracter  > 57)){  
//     field.focus(); 
     return false
  }
  return true;
}

