//funções para segurança e consistência das informações em formulários

//Máscara para CNPJ
function FormataCNPJ(Campo, teclapres){

	var tecla = teclapres.keyCode;

	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1 ;

	
	if (tecla != 9 && tecla != 8){
		if (tam > 2 && tam < 6)
			Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
		if (tam >= 6 && tam < 9)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
		if (tam >= 9 && tam < 13)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
		if (tam >= 13 && tam < 15)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
		}
}

//Máscara para CPF 
function FormataCPF(pForm,pCampo,pTamMax,pPos1,pPos2,pPosTraco,pTeclaPres){
 var wTecla, wVr, wTam;
 
       // alert(pForm[pCampo].value);
  
 wTecla = pTeclaPres.keyCode;
 wVr = pForm[pCampo].value;
 wVr = wVr.toString().replace( "-", "" );
 wVr = wVr.toString().replace( ".", "" );
 wVr = wVr.toString().replace( ".", "" );
 wVr = wVr.toString().replace( "/", "" );
 wTam = wVr.length ;

 if (wTam < pTamMax && wTecla != 8) { 
    wTam = wVr.length + 1 ; 
 }

 if (wTecla == 8 ) { 
    wTam = wTam - 1 ; 
 }
   
 if ( wTecla == 8 || wTecla == 88 || wTecla >= 48 && wTecla <= 57 || wTecla >= 96 && wTecla <= 105 ){
  if ( wTam <= 2 ){
    pForm[pCampo].value = wVr ;
  }
  if (wTam > pPosTraco && wTam <= pTamMax) {
        wVr = wVr.substr(0, wTam - pPosTraco) + '-' + wVr.substr(wTam - pPosTraco, wTam);
  }
  if ( wTam == pTamMax){
        wVr = wVr.substr( 0, wTam - pPos1 ) + '.' + wVr.substr(wTam - pPos1, 3) + '.' + wVr.substr(wTam - pPos2, wTam);
  }
  pForm[pCampo].value = wVr;
 
 }

}

//Máscara para campos tipo data
function FormataData(Campo,teclapres) 
{
var tecla = teclapres.keyCode;
vr = document.form[Campo].value;
vr = vr.replace( ".", "" );
vr = vr.replace( "/", "" );
vr = vr.replace( "/", "" );
tam = vr.length + 1;
if( tecla != 9 && tecla != 8 )
{
if( tam > 2 && tam < 5 )
document.form[Campo].value = vr.substr( 0, tam - 2 ) + '/' + vr.substr( tam - 2, tam );
if( tam >= 5 && tam <= 10 )
document.form[Campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );
}
}

/////////////////////////////////////////////////////////////////
function FormataHora(Campo, teclapres){
	var tecla = teclapres.keyCode;
	
	var vr = new String(Campo.value);
	vr = vr.replace(":", "");
	vr = vr.replace(":", "");

	tam = vr.length + 1;
	
	if (tecla != 9 && tecla != 8){
		if (tam > 2 && tam < 5)
			Campo.value = vr.substr(0, 2) + ':' + vr.substr(2, tam);
		if (tam >= 5 && tam < 9)
			Campo.value = vr.substr(0,2) + ':' + vr.substr(2,2) + ':' + vr.substr(4,2);
		}
	}
/////////////////////////////////////////////////////////////////


//Instrução de chamada no <input>:
//onkeypress="FormataData('Campo',event)"

//Máscara de data para campos DATA (dd/mm/yyyy) teste

function Mascara(formato, keypress, objeto) 
{ 
campo = eval (objeto); 
if (formato=='DATA') 
{ 
caracteres = '01234567890'; 
separacoes = 1; 
separacao1 = '/'; 
conjuntos = 3; 
conjunto1 = 2; 
conjunto2 = 5; 
if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < 
(conjunto1 + conjunto2 + 1)) 
{ 
if (campo.value.length == conjunto1) 
campo.value = campo.value + separacao1; 
if (campo.value.length == conjunto2) 
campo.value = campo.value + separacao1; 

} 
else 
campo.value = campo.value; 
} 

if (formato=='MESANO') 
{ 
caracteres = '01234567890'; 
separacoes = 1; 
separacao1 = '/'; 
conjuntos = 2; 
conjunto1 = 2; 
conjunto2 = 4; 
if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < 
(conjunto1 + conjunto2 + 1)) 
{ 
if (campo.value.length == conjunto1) 
campo.value = campo.value + separacao1; 
} 
else 
event.returnValue = false; 
} 
}

//adicona remove linhas para funcionarios do seguro
// Last updated 2005-10-25
function addRowToTable()
{
  var tbl = document.getElementById('tblSample');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  
  if (iteration > 4){
		alert("Caro(a) usuário(a). Quando o número de acompanhantes ultrapassar 04(quatro) envie lista com os dados via fax (91-3323-0112). Obrigado")	
	return false;
	}
  
  // left cell
  var cellLeft = row.insertCell(0);
  var textNode = document.createTextNode(iteration);
  cellLeft.appendChild(textNode);
  
  // right cell
  var cellRight = row.insertCell(1);
  var el = document.createElement('input');
  el.setAttribute('type', 'text');
  el.setAttribute('name', 'FuncionarioSegurado_' + iteration);
  el.setAttribute('id', 'txtRow' + iteration);
  el.setAttribute('size', '20');
  /*el.onkeypress = keyPressTest;*/
  cellRight.appendChild(el);
  
  // right cell
  var cellRight = row.insertCell(2);
  var el = document.createElement('input');
  el.setAttribute('type', 'text');
  el.setAttribute('name', 'cpf_func_' + iteration);
  el.setAttribute('id', 'txtRow' + iteration);
  el.setAttribute('size', '10');
  /*el.onkeypress = keyPressTest;*/  
  cellRight.appendChild(el);
  
  // right cell
  var cellRight = row.insertCell(3);
  var el = document.createElement('input');
  el.setAttribute('type', 'text');
  el.setAttribute('name', 'ctps_func_' + iteration);
  el.setAttribute('id', 'txtRow' + iteration);
  el.setAttribute('size', '10');
  /*el.onkeypress = keyPressTest;*/
  cellRight.appendChild(el);
  
  // right cell
  ///var cellRight = row.insertCell(4);
  ///var el = document.createElement('input');
  ///el.setAttribute('type', 'text');
  ///el.setAttribute('name', 'dtnasc_func_' + iteration);
  ///el.setAttribute('id', 'txtRow' + iteration);
  ///el.setAttribute('size', '10');
  /*el.onkeypress = keyPressTest;*/
  ///cellRight.appendChild(el);
  
  // right cell
  var cellRight = row.insertCell(4);
  var el = document.createElement('input');
  el.setAttribute('type', 'text');
  el.setAttribute('name', 'dtadm_func_' + iteration);
  el.setAttribute('id', 'txtRow' + iteration);
  el.setAttribute('size', '2');
  /*el.onkeypress = keyPressTest;*/
  cellRight.appendChild(el);
  
  // select cell
  /*desativado server para criar os outros objetos da tabela
  var cellRightSel = row.insertCell(2);
  var sel = document.createElement('select');
  sel.setAttribute('name', 'selRow' + iteration);
  sel.options[0] = new Option('text zero', 'value0');
  sel.options[1] = new Option('text one', 'value1');
  cellRightSel.appendChild(sel);*/
}
function keyPressTest(e, obj)
{
  var validateChkb = document.getElementById('chkValidateOnKeyPress');
  if (validateChkb.checked) {
    var displayObj = document.getElementById('spanOutput');
    var key;
    if(window.event) {
      key = window.event.keyCode; 
    }
    else if(e.which) {
      key = e.which;
    }
    var objId;
    if (obj != null) {
      objId = obj.id;
    } else {
      objId = this.id;
    }
    displayObj.innerHTML = objId + ' : ' + String.fromCharCode(key);
  }
}
function removeRowFromTable()
{
  var tbl = document.getElementById('tblSample');
  var lastRow = tbl.rows.length;
  if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}
function openInNewWindow(frm)
{
  // open a blank window
  var aWindow = window.open('', 'TableAddRowNewWindow',
   'scrollbars=yes,menubar=yes,resizable=yes,toolbar=no,width=400,height=400');
   
  // set the target to the blank window
  frm.target = 'TableAddRowNewWindow';
  
  // submit
  frm.submit();
}
function validateRow(frm)
{
  var chkb = document.getElementById('chkValidate');
  if (chkb.checked) {
    var tbl = document.getElementById('tblSample');
    var lastRow = tbl.rows.length - 1;
    var i;
    for (i=1; i<=lastRow; i++) {
      var aRow = document.getElementById('txtRow' + i);
      if (aRow.value.length <= 0) {
        alert('O campo Nome Funcionario em "Lista de Seguro" ' + i + ' não pode estar em branco');
        return;
      }
    }
  }
  openInNewWindow(frm);
}
//fim

//organiza os dias na data de acordo com o ano e mes selecionado

<!-- Original:  Ben McFarlin (mcfarlin@netscape.net) -->
<!-- Web Site:  http://sites.netscape.net/mcfarlin -->
//Inicio
function populate(objForm,selectIndex) {
timeA = new Date(objForm.year.options[objForm.year.selectedIndex].text, objForm.month.options[objForm.month.selectedIndex].value,1);
timeDifference = timeA - 86400000;
timeB = new Date(timeDifference);
var daysInMonth = timeB.getDate();
for (var i = 0; i < objForm.day.length; i++) {
objForm.day.options[0] = null;
}
for (var i = 0; i < daysInMonth; i++) {
objForm.day.options[i] = new Option(i+1);
}
document.f1.day.options[0].selected = true;
}
function getYears() {

// You can easily customize what years can be used
var years = new Array(1997,1998,1999,2000,2001,2005)

for (var i = 0; i < document.f1.year.length; i++) {
document.f1.year.options[0] = null;
}
timeC = new Date();
currYear = timeC.getFullYear();
for (var i = 0; i < years.length; i++) {
document.f1.year.options[i] = new Option(years[i]);
}
document.f1.year.options[2].selected=true;
}
window.onLoad = getYears;
//Fim


//Valida CPF e CNPJ
function TESTA(CNUMB,CTYPE)
{
  if(Verify(CNUMB, CTYPE))
  {
    alert(CTYPE+" válido!");
  }
  else
  {
    alert(CTYPE+" inválido!");
  }
  return;
}

function ClearStr(str, char)
{
  while((cx=str.indexOf(char))!=-1)
  {		
    str = str.substring(0,cx)+str.substring(cx+1);
  }
  return(str);
}

function ParseNumb(c)
{
  c=ClearStr(c,'-');
  c=ClearStr(c,'/');
  c=ClearStr(c,',');
  c=ClearStr(c,'.');
  c=ClearStr(c,'(');
  c=ClearStr(c,')');
  c=ClearStr(c,' ');
  if((parseFloat(c) / c != 1))
  {
    if(parseFloat(c) * c == 0)
    {
      return(c);
    }
    else
    {
      return(0);
    }
  }
  else
  {
    return(c);
  }
}

function Verify(CNUMB,CTYPE)
{
  CNUMB=ParseNumb(CNUMB)
  if(CNUMB == 0)
  {
    return(false);
  }
  else
  {
    g=CNUMB.length-2;
    if(TestDigit(CNUMB,CTYPE,g))
    {
      g=CNUMB.length-1;
      if(TestDigit(CNUMB,CTYPE,g))
      {	
        return(true);
      }
      else
      {
        return(false);
      }
    }
    else
    {
      return(false);
    }
  }
}

function TestDigit(CNUMB,CTYPE,g)
{
  var dig=0;
  var ind=2;
  for(f=g;f>0;f--)
  {
    dig+=parseInt(CNUMB.charAt(f-1))*ind;
    if (CTYPE=='CNPJ')
    { if(ind>8) {ind=2} else {ind++} }
    else
    { ind++ }
  }
  dig%=11;
  if(dig<2)
  {
    dig=0;
  }
  else
  {
    dig=11-dig;
  }
  if(dig!=parseInt(CNUMB.charAt(g)))
  {
    return(false);
  }
  else
  {
    return(true);
  }
}
//fim

//função bloqueia números somente texto
function onKeyPressBlockNumbers(e)
{
	var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);
	reg = /\d/;
	return !reg.test(keychar);
}

//função que libera somente números no campo do form
function extractNumber(obj, decimalPlaces, allowNegative)
{
	var temp = obj.value;
	
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	obj.value = temp;
}
function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}
// fim


// desabilita habilita campo nome terceirizado quando selecionado o checkbox "TERCEIRIZADO"
function disable(disableIt)
{
	document.frmFiliacao.nome_terc.value="";
	document.frmFiliacao.nome_terc.disabled = disableIt;
}
function enableField()
{
    document.frmFiliacao.nome_terc.disabled=false;
    document.frmFiliacao.nome_terc.value="NOME EMPRESA";
}

// não deixa dois checkbox ficarem selecionados
//para mao-de-obra
function maodeobracheckbox(check,n) 

{

for (i=0;i<2;i++) {

if (check)

{

document.frmFiliacao.chbxmo[i].checked=false;

}

}

document.frmFiliacao.chbxmo[n-1].checked=true;

}
//para seguro de vida sindico
function segurosindico(check,n) 

{

for (i=0;i<2;i++) {

if (check)

{

document.frmFiliacao.chbxsegsind[i].checked=false;

}

}

document.frmFiliacao.chbxsegsind[n-1].checked=true;

}
//para seguro funcionarios
function segurofuncionario(check,n) 

{

for (i=0;i<2;i++) {

if (check)

{

document.frmFiliacao.chbxsegfunc[i].checked=false;

}

}

document.frmFiliacao.chbxsegfunc[n-1].checked=true;

}
//fim


//Checa campos obrigatórios do formulário de filiação
function CheckForm () { 

	//Initialise variables
	var errorMsg = "";

	//Check for a nome do condominio
	if (document.frmFiliacao.nome_condominio.value == ""){
		errorMsg += "\n\tNome Condomínio\t- Entre como o Nome do Condomínio";	
	}
	
	//Check for a CNPJ
	if (document.frmFiliacao.CNPJ.value == ""){
		errorMsg += "\n\tCNPJ \t\t- Entre com o NºCNPJ do Condomínio";
	}
	
	//checa CNPJ VALIDO
	if(Verify(document.forms[0].CNPJ.value, 'CNPJ'))
  	{
    	errorMsg += "";
  	}
  	else
  	{
	    errorMsg += "\n\tCNPJ \t\t- Nº DO CNPJ Inválido";
  	}
	
	//Check for a Endereço
	if (document.frmFiliacao.endereco.value == ""){
		errorMsg += "\n\tEndereço\t\t- Entre com o Endereço do Condomínio";
	}
	
	//Check for Perímetro
	if (document.frmFiliacao.perimetro.value == ""){
		errorMsg += "\n\tPerímetro\t\t- Entre com o Perímetro do Condomínio";
	}
	
	//Check for Cidade
	if (document.frmFiliacao.cidade.value == ""){
		errorMsg += "\n\tCidade \t\t- Entre com a Cidade";
	}
	
	//Check for CEP
	if (document.frmFiliacao.cep.value == ""){
		errorMsg += "\n\tCEP \t\t- Entre com o CEP";
	}
	
	//Check for Bairro
	if (document.frmFiliacao.bairro.value == ""){
		errorMsg += "\n\tBairro \t\t- Entre com o Bairro";
	}
	
	//Check for Tel Cond
	//if (document.frmFiliacao.tel_cond.value == ""){
	//	errorMsg += "\n\tTel Cond \t\t- Entre com Nº Tel. Condomínio";
	//}
	
	//Check for a Nome do Sindico
	if (document.frmFiliacao.nome_sindico.value == ""){
		errorMsg += "\n\tNome Síndico \t- Entre com o Nome do(a) Síndico(a)";
	}
	
	//Check for data nascimento sindico
	if (document.frmFiliacao.sindico_dt_nasc.value == ""){
		errorMsg += "\n\tDt Nasc. Síndico \t- Entre com a data de Nascimento do(a) Sindico(a)";
	}
	
	//Check for an e-mail address and that it is valid
	if ((document.frmFiliacao.email_sindico.value == "") || (document.frmFiliacao.email_sindico.value.length > 0 && (document.frmFiliacao.email_sindico.value.indexOf("@",0) == - 1 || document.frmFiliacao.email_sindico.value.indexOf(".",0) == - 1))) { 
		errorMsg += "\n\tE-mail do Síndico \t- Entre com um E-mail de Contato";
	}
	
	//Check for a CPF
	if (document.frmFiliacao.CPF.value == ""){
		errorMsg += "\n\tCPF  \t\t- Entre com o NºCPF";
	}
	
	//checa CPF
	if(Verify(document.forms[0].CPF.value, 'CPF'))
  	{
    	errorMsg += "";
  	}
  	else
  	{
	    errorMsg += "\n\tCPF \t\t- Nº do CPF Inválido";
  	}
	
	//Check for a Num Apto Sindico
	if (document.frmFiliacao.sindico_num_apto.value == ""){
		errorMsg += "\n\tNº Apto/Casa \t- Entre com o NºApto/Casa do Síndico";
	}
					
	//If there is aproblem with the form then display an error
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Caro(a) Síndico(a), foram encontrados erros no preenchimento de seu formulário.\n";
		msg += "Por favor, corrija os erros e envie novamente o formulário. Obrigado.\n";
		msg += "______________________________________________________________\n\n";
		msg += "Os Seguintes Campos precisam ser corrigidos: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}


function opc1(){
if (document.form.tipo1.checked=true)
{
	document.form.tipo3.checked=false;
	document.form.outros.focus();
	document.form.tipo1.value="SIM"
	}
}

function opc2(){
if (document.form.tipo2.checked=true)
{
	document.form.tipo3.checked=false;
	document.form.outros.focus();
	document.form.tipo2.value="SIM"
	}
}

function opc3(){
if (document.form.tipo3.checked=true)
{
	document.form.tipo1.checked=false;
	document.form.tipo2.checked=false;
	document.form.outros.focus();
	document.form.tipo1.value="NAO"
	document.form.tipo2.value="NAO"
	document.form.tipo3.value="SIM"
	
	}
}

function tipoc(){
if (document.form.tipo_transp_chegada.value="CARRO")
{
	document.form.empresa_chegada.disabled=true;
	document.form.empresa_chegada.value="CONDUÇÃO PRÓPRIA";
	}
if (document.form.tipo_transp_chegada.value="AVIAO")
{
	document.form.empresa_chegada.disabled=false;
	document.form.empresa_chegada.value="INFORME O NOME DA EMPRESA";
	}
if (document.form.tipo_transp_chegada.value="ONIBUS")
{
	document.form.empresa_chegada.disabled=false;
	document.form.empresa_chegada.value="INFORME O NOME DA EMPRESA";
	}
}

function tipor(){
if (document.form.tipo_transp_retorno.value="CARRO")
{
	document.form.empresa_retorno.disabled=true;
	document.form.empresa_retorno.value="CONDUÇÃO PRÓPRIA";
	}
}

/*** 
* Descrição.: formata um campo do formulário de 
* acordo com a máscara informada... 
* Parâmetros: - objForm (o Objeto Form) 
* - strField (string contendo o nome 
* do textbox) 
* - sMask (mascara que define o 
* formato que o dado será apresentado, 
* usando o algarismo "9" para 
* definir números e o símbolo "!" para 
* qualquer caracter... 
* - evtKeyPress (evento) 
* Uso.......: <input type="textbox" 
* name="xxx"..... 
* onkeypress="return txtBoxFormat(document.rcfDownload, 'str_cep', '99999-999', event);"> 
* Observação: As máscaras podem ser representadas como os exemplos abaixo: 
* CEP -> 99.999-999 
* CPF -> 999.999.999-99 
* CNPJ -> 99.999.999/9999-99 
* Data -> 99/99/9999 
* Tel Resid -> (99) 999-9999 
* Tel Cel -> (99) 9999-9999 
* Processo -> 99.999999999/999-99 
* C/C -> 999999-! 
* E por aí vai... 
***/

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( " ", "" );
sValue = sValue.toString().replace( " ", "" );
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) == "/")|| (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;
}
}
//Fim da Função Máscaras Gerais
