function proximo(elem, elem2,v){
	if(document.getElementById(elem2).value!=""){
		document.getElementById(elem).focus();
	}else{
		document.getElementById(elem2).focus();
	}
	//alert(mascara(v,soNumeros));
}
function verificaFormDesbloqueio(){
	if(navigator.appName=="Microsoft Internet Explorer"){
		var d = document.DivDesbloqueio.childNodes;
		Erros = "";
		for(i=0;i<d.length-1;i++){
			if(d[i].childNodes[0].tagName=="INPUT"){
				if(d[i].childNodes[0].value==""){
					Erros += d[i].childNodes[0].alt+" - obrigatório\n";
				}
			}
		}
		if(Erros!=""){
			alert(Erros);
			return false;
		}else{
			return true;
		}
		
	}
}
var mes = "";
var ano = "";
function verificaNumeros(campoverificado, proximocampo){
if(campoverificado.value.charCodeAt(0)>=48 && campoverificado.value.charCodeAt(0)<=58){
	document.getElementById(proximocampo).focus();
}else{
	//alert('válidos apenas números');
	campoverificado.value = "";
	campoverificado.focus();
}
//alert(mes);
}
function verificaMes(){
mes=document.getElementById('MES1').value+""+document.getElementById('MES2').value;
mes = eval(mes);
if(mes>=1 && mes<=12){
	document.getElementById('ano1').focus();
}else{
	alert('digite um Mês válido')
	document.getElementById('MES1').value = "";
	document.getElementById('MES2').value = "";
	document.getElementById('MES1').focus();
}
}
function verificaAno(){
ano=document.getElementById('ano1').value+""+document.getElementById('ano2').value+""+document.getElementById('ano3').value+""+document.getElementById('ano4').value;
ano = eval(ano);
if(ano>=2000 && ano<=2150){
	document.getElementById('cpf1').focus();
}else{
	alert('digite um ano maior que 2000 válido')
	document.getElementById('ano1').value = "";
	document.getElementById('ano2').value = "";
	document.getElementById('ano3').value = "";
	document.getElementById('ano4').value = "";
	document.getElementById('ano1').focus();
}
}
var dia = "";
function verificaDiaNasc(){
dia=document.getElementById('DIANASC1').value+""+document.getElementById('DIANASC2').value;
dia = eval(dia);
if(dia>=1 && dia<=31){
	document.getElementById('MESNASC1').focus();
}else{
	alert('digite um dia válido')
	document.getElementById('DIANASC1').value = "";
	document.getElementById('DIANASC2').value = "";
	document.getElementById('DIANASC1').focus();
}
}
function verificaMesNasc(){
mes=document.getElementById('MESNASC1').value+""+document.getElementById('MESNASC2').value;
mes = eval(mes);
if(mes>=1 && mes<=12){
	document.getElementById('anoNASC1').focus();
}else{
	alert('digite um Mês válido')
	document.getElementById('MESNASC1').value = "";
	document.getElementById('MESNASC2').value = "";
	document.getElementById('MESNASC1').focus();
}
}
function verificaAnoNasc(){
ano=document.getElementById('anoNASC1').value+""+document.getElementById('anoNASC2').value+""+document.getElementById('anoNASC3').value+""+document.getElementById('anoNASC4').value;
ano = eval(ano);
if(ano>=1900 && ano<=2008){
	document.getElementById('BTN_OK').focus();
}else{
	alert('digite um data válida')
	document.getElementById('anoNASC1').value = "";
	document.getElementById('anoNASC2').value = "";
	document.getElementById('anoNASC3').value = "";
	document.getElementById('anoNASC4').value = "";
	document.getElementById('anoNASC1').focus();
}
}


function fechaFloaterDesbloqueio(){
		d=document.getElementById("apDivDesbloqueio");
		d.style.visibility="hidden";
		limpaDesbloqueio();
}
function abreFloaterDesbloqueio(){
	d=document.getElementById("apDivDesbloqueio");
	d.style.visibility="visible";
	document.getElementById("campo1d").focus();
	limpaDesbloqueio();
}
function limpaDesbloqueio(){
	if(navigator.appName=="Microsoft Internet Explorer"){
		var d = document.DivDesbloqueio.childNodes;
		for(i=0;i<d.length-1;i++){
			if(d[i].childNodes[0].tagName=="INPUT"){
				d[i].childNodes[0].value="";
			}
		}
	}
}

//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function switchDiv(strDivName,bolVisible)	{
  var d = document;
  var ie = d.all;
  var ns = d.layer;
  var by = d.getElementById;
  var brw = (d.getElementById) ? 'dom' : (d.all) ? 'ie' : 'old';

  function GetObj(id, get_style) {
    var obj = (brw=='dom') ? d.getElementById(id) : (brw=='ie')? d.all[id] : '' ;
    return get_style ? obj.style : obj;
  }

  if (!bolVisible) {
    GetObj(strDivName,1).visibility = "hidden";
  }
  else {
    GetObj(strDivName,1).visibility = "visible";
  }
  return;
}
//----------------------------------------------------------------------------------------


//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function preencheSelect(select_um, select_dois) {
  for (var i = 0; i < select_um.options.length; i++) {
    select_dois.options[i] = new Option(select_um.options[i].text);
    select_dois.options[i].value = select_um.options[i].value;
  }
}
//----------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function tirarZerosEsquerda(STR) {
  var sAux = '';
  STR = new String(STR);
  var i = 0;
  while (i < STR.length ) {
    if ((STR.charAt(i)!='.') && (STR.charAt(i)!=',')) {
      sAux += STR.charAt(i);
    }
    i++
  }
  STR = new String(sAux);
  sAux = '';
  i = 0;
  while (i < STR.length ) {
    if (STR.charAt(i) != '0') {
      sAux = STR.substring(i,STR.length)
      i = STR.length;
    }
    i++;
  }
  return sAux;
}
//----------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------- 
function formatarValor(obj, teclapres) {
  var decimal, inteiro;
  var i, count;
  STR = new String(obj.value + String.fromCharCode(teclapres.keyCode));
  teclapres.keyCode = 0;

  STR = tirarZerosEsquerda(STR);
  inteiro = '';
  
  if (STR.length == 1) {
    inteiro = '0';
    decimal = '0' + STR;
  }
  else {
    if (STR.length == 2) {
      inteiro = '0';
      decimal = STR;
    }
    else {
      decimal = STR.substring(STR.length-2, STR.length);
      i = 3;
      count = 0;
      while (i <= STR.length) {
        if (count == 3) {
          inteiro = '.' + inteiro;
          count = 0;
        }
        inteiro = STR.charAt(STR.length-i) + inteiro;
        count++;
        i++;
      }
    }
  }
  if (inteiro == '') {
    inteiro = '0';
  }
  if (decimal == '') {
    decimal = '00';
  }
  obj.value = inteiro+','+decimal;
  //return inteiro+','+decimal;
}
//----------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------

function ValidaPeriodoData(obj1,obj2,periodo_max) {
  var data1 = obj1.value;
  var data2 = obj2.value;
  
  ValidaData(obj1);
  ValidaData(obj2);

  data_aux = data1.split('/');
  data_ini = new Date(data_aux[1] +'/'+ data_aux[0] +'/'+ data_aux[2]);
  data_aux = data2.split('/');
  data_fim = new Date(data_aux[1] +'/'+ data_aux[0] +'/'+ data_aux[2]);
  
  if (data_fim < data_ini) {
   alert('A data final deve ser maior que a data inicial!');
   return false;
  }
  
  if (((Date.parse(data_fim) - Date.parse(data_ini)) / 86400000) > periodo_max) {
   alert('Intervalo máximo de '+periodo_max+' dias!');
   return false;
   } else {
       if (!((ValidaData(obj1)) && (ValidaData(obj2)))) {
	     return false;
       } else {
	     return true;
        }
   }
  
}										

function ValidaData(obj) {
     if (obj.value != "") {
         hoje = new Date();
         anoAtual = hoje.getFullYear();
         barras = obj.value.split("/");
         dia = barras[0];
         mes = barras[1];
         ano = barras[2];
         resultado = Valida_Data(dia,mes,ano);
         if (!resultado) {
              alert("Data invalida!");
              obj.value = "";
              obj.focus();
              return false;
         } else {
		      return true;
	     }
     }
  
/*	
     if (obj.value != "") {
         hoje = new Date();
         anoAtual = hoje.getFullYear();
         barras = obj.value.split("/");
         dia = barras[0];
         mes = barras[1];
         ano = barras[2];
         resultado = (!isNaN(dia) && (dia > 0) && (dia < 32)) && (!isNaN(mes) && (mes > 0) && (mes < 13)) && (!isNaN(ano) && (ano.length == 4) && (ano <= anoAtual && ano >= 1900));
         if (!resultado) {
              alert("Formato de data invalido!");
              obj.value = "";
              obj.focus();
              return false;
         }
     }
*/	 
}
//----------------------------------------------------------------------------------------
function Valida_Data(dia,mes,ano)
	{	//Funcionalidade:	Valida a Data retornando True se for uma Data 
		//					válida e False se não for.
		//					Antes de se usar esta função deve-se garantir que os parâmetros
		//					passados sejam numéricos e inteiros.
		// PARÂMETROS: 
		//		Dia = Dia da Data(caracteres numericos), 
		//		Mes = Mes da Data(caracteres numericos), 
		//		Ano = Ano da Data(caracteres numericos)
		
		var v_dia;
		var v_mes;
		var v_ano;
		v_dia = dia;
		v_mes = mes;
		v_ano = ano;
		
		if (v_dia.length < 2)
		{
			return(false);
		}
		
		if (v_mes.length < 2)
		{
			return(false);
		}
		
		if (v_ano.length < 4)
		{
			return(false);
		}
			
		if (((v_ano < 1900) || (v_ano > 2079)) && (v_ano.length != 0))
		{
			return(false);
		}

		if (v_dia > 31 || v_dia < 1)
		{
			return(false);
		}
		
		if (v_mes > 12 || v_mes < 1)
		{
			return(false);
		}
		
		if (v_dia == "31") 
		{
			if ((v_mes == "04") || (v_mes == "06") || (v_mes == "09") || (v_mes == "11"))
			{
				return(false);
			}
		}
	
		//Validação de Ano Bissexto
		if (v_mes == "02")
		{
			if (!(v_ano%4)) 
			{
				if (v_dia > 29)
				{
					return(false);
				}
			}
			else if (v_dia > 28)
			{
				return(false);
			}
		}
		
		//o -if- abaixo testa se algum campo foi preenchido e outro deixado em branco deixando a data incompleta

		if (((v_dia != "") || (v_mes != "") || (v_ano != "")) && ((v_dia == "") || (v_mes == "") || (v_ano == "")))
		{
			return(false);
		}
		
		return(true);
	}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function AbrePagina(perfil, tamx, tamy, yn) {
  window.open(perfil,"","resizable=no,toolbar=no,status=no,menubar=no,top="+((screen.availHeight - tamy) * 0.5)+",left="+((screen.availWidth - tamx) * 0.5)+",scrollbars=" + yn + ",width=" + tamx + ",height=" + tamy)
}
//----------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function voltar(flag) {
  if (flag == 1) {
    window.location.href('../default.asp');
  }
  else if (flag == 2) {
    window.location.href('default.asp');
  }
  else {
    window.history.back();
  }
}
//----------------------------------------------------------------------------------------


//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
	
	if(document.all) { // Internet Explorer
		nTecla = evtKeyPress.keyCode; }
		else if(document.layers) { // Nestcape
		nTecla = evtKeyPress.which;
	}
	
	sValue = objForm[strField].value;
	// Limpa todos os caracteres de formatação que
	// já estiverem no campo.
	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( " ", "" );
	sValue = sValue.toString().replace( " ", "" );
/*	
	if(sValue.toSttring().charAt(0)=="0"){
		sMask = "9999 999 999";
	}
	*/
	/*if(sValue.length==0 && nTecla==48){
		sMask = "9999 999 999";
	}else{
		if(sValue.charAt(0)==0){
			sMask = "9999 999 999";
		}
	}*/
	//alert(sMask);
	fldLen = sValue.length;
	mskLen = sMask.length;

	i = 0;
	nCount = 0;
	sCod = "";
	mskLen = fldLen;

	while (i <= mskLen) {
		bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
		bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

		if (bolMask) {
			sCod += sMask.charAt(i);
			mskLen++; 
		} else {
			sCod += sValue.charAt(nCount);
			nCount++;
		}
		i++;
	}

	objForm[strField].value = sCod;

	if (nTecla != 8) { // backspace
		if (sMask.charAt(i-1) == "9") { // apenas números...
			return ((nTecla > 47) && (nTecla < 58)); 
		} /* números de 0 a 9 */ else { // qualquer caracter...
			return true;
		} 
	} else {
		return true;
	}
}
//----------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function ValidaTel(edt) {
  if ((edt.value.length != 0) && (edt.value.length < 13)) {
    edt.value = "";
    edt.focus();
    alert('Número de telefone inválido. \n Ex.:(27)2121-0000');
  }
}
function ValidaTelZeroOitocentos(edt){
	if ((edt.value.length != 0) && (edt.value.length < 13)) {
	    edt.value = "";
	    edt.focus();
	    alert('Número de telefone inválido. \n Ex.:0800 123 4567');
	}
}
//----------------------------------------------------------------------------------------


//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function valida_form(frm) {
  msg = "";
  with (frm) {
	for(i=0; i < elements.length; i++) {
	  thiselm = elements[i];
	  if (thiselm.id.substr(0,8) == "NOT_NULL") {
	    if (((thiselm.name.substr(0,3) == 'EDT') || (thiselm.name.substr(0,3) == 'BOX') || (thiselm.name.substr(0,3) == 'AUX')) && (thiselm.value == "") || ((thiselm.name.substr(0,3) == 'CHK') && (!thiselm.checked))) {
		  if (msg == "") {
		    msg+= "Campos obrigatórios:\n"
		  }
          msg+= "    - "+ thiselm.id.substr(9,thiselm.id.length) +";\n";
        }
	  }
    }
  }
  if (msg != "") {
    alert(msg);
	return false;
  }
  else {
    return true;
  }
}
//----------------------------------------------------------------------------------------


//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function abrirFormPopup(form, features, windowName) {
  if (!windowName)
    windowName = 'formTarget' + (new Date().getTime());
  form.target = windowName;
  open ('', windowName, features);
}
//----------------------------------------------------------------------------------------


//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function validaExclusaoContratante(form) {
  if (form.CBX_CD_EMPRESA.value!=0) {
    
    var mensagem = '';
    if ((form.CBX_CD_EMPRESA.value.charAt(0)<'0') || (form.CBX_CD_EMPRESA.value.charAt(0)>'9')) {

      if (form.CBX_CD_EMPRESA.value.charAt(0)=='S') { 
        mensagem = 'ATENÇÃO\nExistem cartões ';
        if (form.CBX_CD_EMPRESA.value.charAt(1)=='S') 
          mensagem += 'e pedidos de cartões ';
        
        mensagem += 'associados a esta empresa contratante\n';
        mensagem += 'Se excluída a contratante, os ítens associados serão desassociados automaticamente\n\n'
      }
      else if (form.CBX_CD_EMPRESA.value.charAt(1)=='S') {
        mensagem += 'ATENÇÃO\nExistem pedidos de cartões ';

        mensagem += 'associados a esta empresa contratante\n';
        mensagem += 'Se excluída a contratante, os ítens associados serão desassociados automaticamente\n\n';
      }
    }
 
    mensagem += 'Deseja realmente excluir?';
    if (confirm(mensagem)) { 
      return true;
    } 
    else {
      return false;
    }
  } 
  else {
    alert('Selecione uma empresa para excluir'); 
    return false;
  }
}
//----------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function valida_dados_boleto(form) {
    
    var Vl_Com_Enc = new Number(form.HID_VL_COM_ENCARGOS.value.replace(',','.'));
    var Vl_Sem_Enc = new Number(form.HID_VL_SEM_ENCARGOS.value.replace(',','.'));
    var Vl_Rec     = new Number(form.EDT_VL_AUTORIZACAO.value.replace(',','.'));
    
    if ((Vl_Rec.NaN) || (Vl_Rec==0)) {
      alert('Digite o valor recebido');
      return false;
    }

    if (Vl_Rec > Vl_Com_Enc) {
      alert('Valor recebido maior do que o valor da dívida');
      return false;
    }

    if (Vl_Rec < Vl_Com_Enc) {
      alert('Valor recebido menor do que o pgto. com encargos');
      return false;
    }
    
    var resp = confirm('Confirma o recebimento do carnê de R$ '+Vl_Rec.toString()+' ?');
    if (resp) {
      return true;
    } else {
      return false;
    }
}
//----------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function insere_contas_HID(elemhid, elemcheck) {
	if (elemcheck.checked == true) {
		if (elemhid.value == "")
			elemhid.value += elemcheck.value;
		else
			elemhid.value += (","+elemcheck.value);
	}
	else {
		listastr = elemhid.value;
		indice = listastr.indexOf(elemcheck.value);

		if (indice != -1) {
			if (indice == 0) {
				if (listastr != elemcheck.value)
					listastr = listastr.replace((elemcheck.value+","),"");
				else
					listastr = "";
			}
			else
				listastr = listastr.replace((","+elemcheck.value),"");

			//indice_virg = listastr.indexOf(",");
			//if (listastr == elemcheck.value) {
			//	alert("passou aqui !!");
			//	listastr = listastr.replace(elemcheck.value,"");
			//	listastr = "";
			//}

			elemhid.value = listastr;
		}
	}
}
//----------------------------------------------------------------------------------------














