
function abreJanela(pagina,nome,propriedades){
	window.open(pagina,nome,propriedades);
}


function abrePopup(url,popWidth,popHeight){
      GP_AdvOpenWindow(url,'jan','fullscreen=no,toolbar=no,location=no,status=yes,menubar=no,scrollbars=auto,resizable=no',popWidth,popHeight,'center','ignoreLink','',0,'')
}

function GP_AdvOpenWindow(theURL,winName,features,popWidth,popHeight,winAlign,ignorelink,alwaysOnTop,autoCloseTime,borderless) { //v2.0
  var leftPos=0,topPos=0,autoCloseTimeoutHandle, ontopIntervalHandle, w = 480, h = 340;  
  if (popWidth > 0) features += (features.length > 0 ? ',' : '') + 'width=' + popWidth;
  if (popHeight > 0) features += (features.length > 0 ? ',' : '') + 'height=' + popHeight;
  if (winAlign && winAlign != "" && popWidth > 0 && popHeight > 0) {
    if (document.all || document.layers || document.getElementById) {w = screen.availWidth; h = screen.availHeight;}
		if (winAlign.indexOf("center") != -1) {topPos = (h-popHeight)/2;leftPos = (w-popWidth)/2;}
		if (winAlign.indexOf("bottom") != -1) topPos = h-popHeight; if (winAlign.indexOf("right") != -1) leftPos = w-popWidth; 
		if (winAlign.indexOf("left") != -1) leftPos = 0; if (winAlign.indexOf("top") != -1) topPos = 0; 						
    features += (features.length > 0 ? ',' : '') + 'top=' + topPos+',left='+leftPos;}
  if (document.all && borderless && borderless != "" && features.indexOf("fullscreen") != -1) features+=",fullscreen=1";
  if (window["popupWindow"] == null) window["popupWindow"] = new Array();
  var wp = popupWindow.length;
  popupWindow[wp] = window.open(theURL,winName,features);
  if (popupWindow[wp].opener == null) popupWindow[wp].opener = self;  
  if (document.all || document.layers || document.getElementById) {
    if (borderless && borderless != "") {popupWindow[wp].resizeTo(popWidth,popHeight); popupWindow[wp].moveTo(leftPos, topPos);}
    if (alwaysOnTop && alwaysOnTop != "") {
    	ontopIntervalHandle = popupWindow[wp].setInterval("window.focus();", 50);
    	popupWindow[wp].document.body.onload = function() {window.setInterval("window.focus();", 50);}; }
    if (autoCloseTime && autoCloseTime > 0) {
    	popupWindow[wp].document.body.onbeforeunload = function() {
  			if (autoCloseTimeoutHandle) window.clearInterval(autoCloseTimeoutHandle);
    		window.onbeforeunload = null;	}  
   		autoCloseTimeoutHandle = window.setTimeout("popupWindow["+wp+"].close()", autoCloseTime * 1000); }
  	window.onbeforeunload = function() {for (var i=0;i<popupWindow.length;i++) popupWindow[i].close();}; }   
  document.MM_returnValue = (ignorelink && ignorelink != "") ? false : true;
}


function textCounterMsg( field, maxlimit, fieldMessage ) {
 if(fieldMessage){
  	fieldMessage.value=parseInt(maxlimit-field.value.length);
  }
  if ( field.value.length > maxlimit ){ 
    alert('Número máximo de caracteres: '+maxlimit);
    field.value = field.value.substring( 0, maxlimit); 
    if(fieldMessage){
	  fieldMessage.value=parseInt(maxlimit-field.value.length);
	}
    field.focus(); 
    return false;
  }        
}

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;	
}

function onlyNumber()
{
  if ((event.keyCode<48)||(event.keyCode>57))  
     return false;
}

function fn_monta_inteiro( valor ){
	var tam     = valor.length;
   	var qtd     =  tam / 3 ;
   	var posicao = 0;
   	for ( lnx = 1 ; ( lnx < qtd ) ; lnx++){
	  	valor = valor.substring( 0, valor.length - (( 3 * lnx )+posicao) ) + '.' + valor.substring( valor.length - (( 3 * lnx ) + posicao++) );
   	} 
   	return valor;
}

function delMascara( strValue ){
	var objRegExp = new RegExp( "\\.", "g" ); 
 	return strValue.replace(objRegExp,'');
}

function addMascara( strValue ) 
{
   strValue = delMascara( strValue );

   // Inicio da Mudanca na Mascara 15/05/2003
   lnegativo = "";
   if ( strValue.length > 1 )
   {
      if ( strValue.substring(0,1) == '-' )        
      {           
	     lnegativo = "-";                               
         strValue = strValue.substring( 1 );     
	  }                                          
   }
   // Final da Mudanca na Mascara 15/05/2003
   
   if ( strValue.indexOf( ',' ) != -1  )
      {
	      valor = strValue.substring( 0, strValue.indexOf( ',' )  );
		  fraca = strValue.substring( strValue.indexOf( ',' )  );
	   }	  
	else   
	   {
	     valor = strValue;
		 fraca = "";
	    }	
		
    if (( fraca != "" ) && ( valor == "" )) 
	   valor = "0";
	   
	// strValue  = fn_monta_inteiro( valor ) + fraca;	        // Mudanca na Mascara 15/05/2003  
	strValue  = lnegativo + fn_monta_inteiro( valor ) + fraca;  // Mudanca na Mascara 15/05/2003  
	
  return strValue;
}

/* M?scara para campos numpericos */
function formataMoeda( campo, tammax, decimal, teclapres){
	
	var vr        = new String( delMascara( campo.value ) );  
	var tecla     = 0;
	var maxint    = tammax - decimal;
	var isvirg    = false;
	var qtddig    = 0;
	var qtdint    = 0;
	var selecao   = null;
	var isselecao = false;
	var virgsele  = false;

	
	if ( navigator.appName=="Netscape" ){
	   tecla     = teclapres.which;
       //selecao   = document.getSelection();	   

	}else{
		tecla     = teclapres.keyCode;
       	selecao   = document.selection.createRange().duplicate();
	}
    /************************************************************************
       	         Verifica a Existencia de selecao neste campo 	
    ************************************************************************/
	if ( navigator.appName!="Netscape" ){
      	if ( selecao.text != "" ){
    	 	if ( selecao.parentElement().name == campo.name ){
	        	isselecao = true;
	        	if ( selecao.text.indexOf( ',' ) != -1 ) 
	           		virgsele = true; 
			}
	 	}   
	}	 

	// Pressionado o Back-Space
	if ( tecla == 8 ) 
	   return true; 

	   
	if ( selecao != null ) 
	{
	   ltamsele = selecao.text.length;
	}   
	else
	{
	   ltamsele = 0;	
	}

	// Inicio da Mudanca na Mascara 15/05/2003   
    if ( ( vr.length == 0 ) || ( campo.value.length == ltamsele ) )
	{
	
	   if ( tecla == 45 )
	   {
	      return true;
	   }
	}
    // Inicio da Mudanca na Mascara 15/05/2003
	
	// Se ja existe virgula no texto pega as qtd de inteiro e decimal se nao existe coloca zero
    if ( vr.indexOf( ',' )  != -1)  
    {
       isvirg = true;
       qtddig = vr.length - vr.indexOf( ',' ) -1 ;
       qtdint = vr.indexOf( ',' );
	}
	else
	{
   	   qtdint  = vr.length ;
	}
	// Se a qtd digitada for menor que o tamanho do campo ou houver selecao ele aceita 
	if ( ( vr.length <= tammax ) || ( isselecao ) )	
	{

	    if ( ( tecla == 44 ) && ( decimal != 0 ) ) 
		{
	       // Se ja existe uma virgula e a tecla pressionada e virgula ou existe uma virgula na selecao 
   	       if ( ( isvirg ) && ( virgsele ) )		   
		      return true;
			  
		   if ( ( !isvirg ) || ( virgsele ) )	  
		      return true;
		
		   return false;	  
		}
	    if ( ( tecla >= 48 ) && ( tecla <= 57 ) )
		{
		   if ( ( isvirg ) && ( qtddig >= decimal ) && ( !virgsele ) )
		      return false;


		   if ( ( ( isvirg ) && ( qtddig <= decimal ) ) || ( isselecao ) )
		      return true;
			  
		   if ( ( ( !isvirg ) && ( qtdint < maxint ) ) || ( isselecao ) )
		      return true;
			  
			  
  		   return false;
		}
		
		return false;
				   
	}
	else 
	{
	   return false;
	}

	
}	

function fn_MostraMascara( campo, tecla )
{

   // Acrescentou na Mudanca na Mascara 15/05/2003 
   // ( ( tecla.keyCode == 45 ) || ( tecla.keyCode == 109 ) ) )

   if ( (tecla.keyCode==8) || ( ( tecla.keyCode >= 48 ) && ( tecla.keyCode <= 57 )) || 
      ( ( tecla.keyCode >= 96 ) && ( tecla.keyCode <= 105 )) ||
      ( tecla.keyCode == 44 ) || ( ( tecla.keyCode == 45 ) || ( tecla.keyCode == 109 ) ) || ( tecla.keyCode == 46 ) )
   { 
	 campo.value = addMascara( campo.value ) ;
   }  
	return true;
}

//mascara de data
function maskdata(field){
	if ((event.keyCode<47)||(event.keyCode>57))  
    	return false;
  
  	if ( ( (field.value.length == 2) || (field.value.length == 5)) && (event.keyCode != 47))
    	field.value = field.value + '/';
}

/**************************************************************
ESTA FUNÇÃO AJUSTA O ANO 
*************************************************************/							  
function ajusta_dt(obj){
	var dia, mes, ano, novoano;
 	var dt,tamano;
  	var tamstr = obj.value.length;

  	if (tamstr == 8) tamano = 2

   	dia = obj.value.substr(0,2);
	mes = obj.value.substr(3,2);
   	ano = obj.value.substr(6,tamano);

	if (tamstr == 8){
		novoano = "20" + ano;
		obj.value = dia + "/" + mes + "/" + novoano;
		return true;
	}
}

//FUNCAO QUE TESTA SE A DATA INICIAL É MENOR QUE A DATA FINAL
function compara_data(tx_dt_ini,tx_dt_fim){
	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)
    	return false;
	
	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("Data inválida. Formato indicado: dd/mm/aaaa");
		objdata.focus();
		return false;
	}
	dia = objdata.value.substr(0,2);
	mes = objdata.value.substr(3,2);
	ano = objdata.value.substr(6,4);

 	if ( (dia.charAt(0)=='/')||(dia.charAt(1)=='/')||
    	(mes.charAt(0)=='/')||(mes.charAt(1)=='/') ){
			alert("Data inválida! Informe uma data válida.");
      		objdata.focus();
      		return false;
    }
	for (i=0;i<4;i++){
   		if (ano.charAt(i)=='/'){
 			alert("Data inválida! Informe uma data válida.");
 			objdata.focus();
 			return false;
   		}
	}
    
    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;
    }
}

/**************************************************************
ESTA FUNÇÃO AJUSTA UM CAMPO HORA COM HORA E MINUTO
*************************************************************/							  
function maskhora(field){
	if ((event.keyCode<47)||(event.keyCode>57))  
    	return false;

  	if (field.value.length == 2)
    	field.value = field.value + ':';
}

/**************************************************************
ESTA FUNCAO VALIDA A HORA E O MINUTO DIGITADO
*************************************************************/							  
function verificaHora(field){
	var hora, minuto;
	
	hora = field.value.substr(0,2);
	minuto = field.value.substr(3,2);
	
	if (field.value != ''){
		if ( (field.value.length < 5) || (field.value.length > 5) ){
			alert('Informe a hora no formato xx:xx.');
			field.focus();
			return false
		}
		if ( (hora < 0) || (hora > 24) ){
			alert('A hora deve ser informada entre 00 e 24.');
			field.focus();
			return false
		}
		if ( (minuto < 0) || (minuto > 59) ){
			alert('Os minutos devem ser informados entre 00 e 59.');
			field.focus();
			return false
		}
	}
}

//FUNCAO QUE compara duas horas no formato HH:MM
function compara_hora(tx_hr_ini,tx_hr_fim){
	var hora_ini, minuto_ini, hora_fim, minuto_fim
  
	hora_ini = tx_hr_ini.value.substr(0,2);
	minuto_ini = tx_hr_ini.value.substr(3,2);

  	hora_fim = tx_hr_fim.value.substr(0,2);
	minuto_fim = tx_hr_fim.value.substr(3,2);
	//alert(hora_fim);
	//alert(hora_ini);
	//alert(hora_fim < hora_ini);
	//alert(hora_fim == hora_ini);
   	if (hora_fim < hora_ini)
		return false;
	else{
		if (hora_fim == hora_ini){
			if (minuto_fim <= minuto_ini)
				return false;
		}
	}
	
	return true;
}
/**************************************************************
coloca todo o texto em maiusculo
*************************************************************/							  
function fn_maiuscula(obj){
	obj.value = obj.value.toUpperCase();
}

function valida_email(obj){
	if(obj.value.indexOf("@")==-1 || obj.value.indexOf(".")==-1){ 
		alert("O campo email não está preenchido corretamente."); 
		obj.focus(); 
		return false; 
	} 
	return true;
}

// retorna falso se a data final for maior que a data atual
function checa_data_menor(tx_dt_hoje,tx_dt_fim){
  var dia, mes, ano
	dia = tx_dt_hoje.substr(0,2);
	mes = tx_dt_hoje.substr(3,2);
    ano = tx_dt_hoje.substr(6,4);

	var dthoje = new Date(ano + "/" + mes + "/" + dia); 	 

	dia = tx_dt_fim.substr(0,2);
	mes = tx_dt_fim.substr(3,2);
    ano = tx_dt_fim.substr(6,4);
		
	var dtfinal = new Date(ano + "/" + mes + "/" + dia);

   if (dthoje <= dtfinal) return false;

  
	return true;
}

function checa_data_menor2(tx_dt_hoje,tx_dt_fim){
  var dia, mes, ano
	dia = tx_dt_hoje.substr(0,2);
	mes = tx_dt_hoje.substr(3,2);
    ano = tx_dt_hoje.substr(6,4);

	var dthoje = new Date(ano + "/" + mes + "/" + dia);
	

	dia = tx_dt_fim.substr(0,2);
	mes = tx_dt_fim.substr(3,2);
    ano = tx_dt_fim.substr(6,4);
		
	var dtfinal = new Date(ano + "/" + mes + "/" + dia);
		

   if (dthoje < dtfinal) return false;

  
	return true;
}

function checa_data_maior(tx_dt_hoje,tx_dt_fim){
  var dia, mes, ano
	dia = tx_dt_hoje.substr(0,2);
	mes = tx_dt_hoje.substr(3,2);
    ano = tx_dt_hoje.substr(6,4);
		
	var dthoje = new Date(ano + "/" + mes + "/" + dia);

	dia = tx_dt_fim.substr(0,2);
	mes = tx_dt_fim.substr(3,2);
    ano = tx_dt_fim.substr(6,4);

	var dtfinal = new Date(ano + "/" + mes + "/" + dia);

	//modificação para a tela de liberação de terceiros
   if (dthoje > dtfinal) return false;
	return true;
}

function fn_passa_itens( p_objorigem, p_objdestino, p_fltodos )
   { 	 
		inicio = p_objorigem.length - 1;
		final  = 0;

	// se tem algum item selecionado
	if ( inicio >= 0 )
	{
	    // percorre combo de origem passando para o destino
		for ( x = inicio; x >= final; x-- )
	   	{	 
			if(p_fltodos==0){
		    	if (p_objorigem.options[x].selected){
       				p_objdestino.length  = p_objdestino.length + 1;
       				p_objdestino.options[p_objdestino.length - 1].text  = p_objorigem.options[ x ].text;
       				p_objdestino.options[p_objdestino.length - 1].value = p_objorigem.options[ x ].value;
					p_objdestino.options[p_objdestino.length - 1].selected = true;
        			p_objorigem.options[ x ] = null;
				}
			}	
			else {
				p_objdestino.length  = p_objdestino.length + 1;
   				p_objdestino.options[p_objdestino.length - 1].text  = p_objorigem.options[ x ].text;
   				p_objdestino.options[p_objdestino.length - 1].value = p_objorigem.options[ x ].value;
				p_objdestino.options[p_objdestino.length - 1].selected = true;
       			p_objorigem.options[ x ] = null;
			}
		}
	}	
  } 
function fn_nr_dia(d1,d2)
{
	var vetDate1, vetDate2;
	var oneDay = 1000 * 60 * 60 * 24;
	
	
	var data1 = new Date();
  	var data2 = new Date();

	vetDate1 = d1.split('/');
  	vetDate2 = d2.split('/');

	data1.setDate(vetDate1[0]);
  	data2.setDate(vetDate2[0]);
  	data1.setMonth(vetDate1[1]-1);
  	data2.setMonth(vetDate2[1]-1);
  	data1.setFullYear(vetDate1[2]);  
  	data2.setFullYear(vetDate2[2]);

	return Math.floor((data2.getTime()-data1.getTime())/oneDay);
} 

function Show()
{
     x = event.clientX + document.body.scrollLeft; 
     y = event.clientY + document.body.scrollTop + 35;
     Popup.style.display="block"; // mostra o pop-up
     Popup.style.left = x; // esquerda
     Popup.style.top = y; // topo
}
// Esconde o pop-up quando o mouse eh movido para fora do Link
function Hide()
{
     Popup.style.display="none"; // esconde
} 
