/********************************************************************************/
//	script2.js																	//
// 		Desenvolvido por Thiago Andrade [ thiago AT thiagoandrade.eti.br ]		//
/********************************************************************************/


//FUNÇÕES ASSOCIADAS A TELA DE ASSOCIACAO DE PERMISSOES DE USUARIO////////////////
	function desmarcausers(){
		//document.forms[0].reset();
		i=0;
		while(document.main.coduser[i]){
			document.main.coduser[i].checked = false; 		
			i++; 
		}
	}	
	
	function marcausers(){
		//document.forms[0].reset();
		i=0;
		while(document.main.coduser[i]){
			document.main.coduser[i].checked = true; 		
			i++; 
		}
	}	
	
	
	function BloquearFireFox(){
		 if(!document.all){		   
		    alert('Favor Utilizar apenas o Internet Explorer!');
	        document.location = '/main.php';
		 }
		 
		 
	  }
	
	function preencheform(){
		//document.forms[0].reset();
		i=0;
		while(document.main.actionid[i]){
			document.main.actionid[i].checked = true; 		
			i++; 
		}
		i=0;
		while(document.main.moduleid[i]){
			document.main.moduleid[i].checked = true;
			i++; 
		}		
	}	
	
	function marcamodule(actionid){
		nova = actionid.split(",");
		i = nova[0];
		document.main.moduleid[i-1].checked = true;
	}	
	
	function selectmodule(moduleid){	
		pos = moduleid-1;		
		if(document.main.moduleid[pos].checked == false){
			i=0;		
			while(document.main.actionid[i])
			{			
				arr = document.main.actionid[i].value;
				actionid = arr.split(",");	
				if(moduleid == actionid[0])
				{
					document.main.actionid[i].checked = false; 	
				}	
				i++; 
			}	
		}else{
			i=0;		
			while(document.main.actionid[i])
			{			
				arr = document.main.actionid[i].value;
				actionid = arr.split(",");	
				if(moduleid == actionid[0])
				{
					document.main.actionid[i].checked = true; 	
				}	
				i++; 
			}			
		}	
	}
//////////////////////////////////////////////////////////////////////////////////		



//FUNÇÃO ASSOCIADA A TELA DE RELATÓRIO DE INSTALAÇÕES/////////////////////////////
function validaForm() {

	var codigo                  = document.getElementById('codigo');
	var nome                    = document.getElementById('nome');
	var estado                  = document.getElementById('estado');
	var cidade                  = document.getElementById('codcidade');
	var bairro                  = document.getElementById('codbairro');
	var datainicial     = document.getElementById('datainicial');
	var datafinal       = document.getElementById('datafinal');
	
	var statusinstalacao        = document.getElementById('status');
	var msg = "";


	
	if (statusinstalacao.value == "" ){
		if(datainicial.value == "" || datafinal.value == ""){
			msg += "- Os campos Data Inicial e Data Final de Data de cadastro devem ser preenchidos corretamente. \\n";		
			datainicial.style.borderColor = "red";
			datafinal.style.borderColor = "red";
		}
	}

	
	if (statusinstalacao.value == 3 || statusinstalacao.value == 5  ){		
		if(datainicial.value == "" || datafinal.value == ""){
			msg += "- Os campos Data Inicial e Data Final de Data de cancelamento devem ser preenchidos corretamente. \\n";		
			datainicial.style.borderColor = "red";
			datafinal.style.borderColor = "red";		
		}
	}
	
	if (statusinstalacao.value == 2 ){
		if(datainicial.value == "" || datafinal.value == ""){
			msg += "- Os campos Data Inicial e Data Final de Data de ativação devem ser preenchidos corretamente. \\n";		
			datainicial.style.borderColor = "red";
			datafinal.style.borderColor = "red";
		}
	}
	
	
	if ( msg != '' ){
		//alert(msg);
		window.showModalDialog("/ssi/modelos/alert.php?msg="+msg ,"avisoPadrao","center:yes;dialogWidth:450px;dialogheight=500px;status=no;");
		return false;
	}
	
}
///////////////////////////////////////////////////////////////////////////////////
function formatadata(campo, proximo){
		//alert(proximo);
		separador = '/'; 
		conjunto1 = 2;
		conjunto2 = 5;
		if (campo.value.length == conjunto1){
			campo.value = campo.value + separador;
		}
		if (campo.value.length == conjunto2){
			campo.value = campo.value + separador;	
		}
		if (campo.value.length == 10){	
			setTimeout(""+proximo+".focus();", 1);
		}
}


function ChangeDisplay(id){
	obj = document.getElementById(id)
	if (obj.style.display == '' ){
		obj.style.display = 'none';
	}else{
			obj.style.display = '';
	}
}


function showinfosessao(sid){
		window.open('/ssi/consultarsessao/infosessao.php?SID='+sid,'InfoSessao','toolbar=no,location=no,menubar=no, status=yes, scrollbars=yes width=450 height=300 screenX=100 screenY=100 left=100 top=100 status=yes');
	}


function ipModal(objIP, wlan, bridge){
	if (wlan=='' || wlan==0){
		alert('Selecione uma rede!');
		return false;
	}
  	ret = window.showModalDialog("/modules/node/ipv4iface/freeleases.php?codwlan="+wlan+"&bridge="+bridge,"ipModal","center:yes;dialogWidth:300px;dialogheight=500px;status=no;");
    if ( ret ){ 
		a = ret.split(":");
		objIP.value = a[0];
	}
}

function selall(form){
	for (i=0;i<form.elements.length;i++){
		if (form.elements[i].type.toLowerCase()=='checkbox')
			form.elements[i].checked = !form.elements[i].checked;
	}
}

function popup(url, w, h, name, extra){
	wpos = (screen.availWidth-w)/2;
	hpos = (screen.availHeight-h)/2;
	if (extra)
		extra = ','+extra;
	window.open(url, name,'width='+w+',height='+h+',left='+wpos+',top='+hpos+extra);
}


function validaMascara(val, mask){
	if ( val.length != mask.length )
		return false;
	
	aMask = mask.split('');
	aVal = val.split('');
	for (i=0;i<mask.length;i++){
		if ( validastring(aVal[i],"0123456789") != validastring(aMask[i],"0123456789") )
			return false
	}
	
	return true;
}


/**********************************************************************************************
*  	FUNÇÕES PARA A VALIDAÇÃO DE STRINGS
**********************************************************************************************/
function validastring(src, strValidos){
	var s = src.split('');
	if ( src == '' ){
		return false;
	}
	for ( var i=0; i<s.length ; i++ ){
		if ( strValidos.indexOf(s[i])<0 ){
			return false;
		}
	}
	return true;
}

function validaint( objCampo ){
	if (objCampo.mandatory){
		a = validastring( objCampo.value, "0123456789" );
		return a;
	}else{
		if (objCampo.minimo){
			return objCampo.value==''  || (validastring( objCampo.value, "0123456789" ) && objCampo.value.length >= objCampo.minimo );
		}else{
			return validastring( objCampo.value, "0123456789" ) ||  objCampo.value=='';
		}
	}
}









function validacpf(s){ 
        var i; 
        var c = s.substr(0,9); 
        var dv = s.substr(9,2); 
        var d1 = 0; 
        for (i = 0; i < 9; i++) 
        { 
            d1 += c.charAt(i)*(10-i); 
        } 
            if (d1 == 0){ 
                return false; 
            } 
        d1 = 11 - (d1 % 11); 
        if (d1 > 9) d1 = 0; 
        if (dv.charAt(0) != d1) 
        { 
            return false; 
        } 

        d1 *= 2; 
        for (i = 0; i < 9; i++) 
        { 
            d1 += c.charAt(i)*(11-i); 
        } 
        d1 = 11 - (d1 % 11); 
        if (d1 > 9) d1 = 0; 
        if (dv.charAt(1) != d1) 
        { 
            return false; 
        } 
		return true;

} 





/********************************************************************************
	function sel( obj, val )
		seleciona o valor indicado por val no objeto
		utilizado em campos do tipo radio e select
*********************************************************************************/
function sel(obj, val){
	if ( obj ){
		if ( obj.type ){
			//tratamento para select	
			//alert( obj.name );
			for (var i=0; i<obj.length;i++){
				if (obj.options[i].value==val){
					//obj.selectedIndex = i;
					obj.options[i].selected = true;
					if (obj.onchange){
						obj.onchange();
					}
					return true;
				}
			}
		}else{
			//tratamento para radio
			if (obj.length){
				for (var i=0; i<obj.length;i++){
					if (obj[i].value == val){
						obj[i].checked = true;
					}
				}
			}
		}
	}else{
		alert('O objeto não existe!\\nObjeto referenciado: '+obj);
	}
}



/**********************************************************************************************
*  	FUNÇÕES PARA A FORMATAÇÃO DE TEXTO EM CAMPOS
**********************************************************************************************/

/**********************************************************************************************
	function MASK
		aplica ao campo OBJ a máscara definida por MASC
**********************************************************************************************/
function MASK(masc, key, obj){
	if ( masc.length > obj.value.length ){
		//ação pra valores numéricos
		if (validastring( masc.substr(obj.value.length, 1), '0123456789' ) ) {
			//checa o valor digitado
			if ( key>=48 && key<=57 ){
				//valores numéricos
				if ( !validastring( masc.substr(obj.value.length+1, 1), '0123456789' ) ){
					obj.value += String.fromCharCode(key) + masc.substr(obj.value.length+1, 1);
					if ( obj.value.length == masc.length ){
						//alert();
						nextCampo( obj );
						return false;
					}
					
					return false;
				}
			}else{
				return false;
			}
		}else{
			//if ( !validastring( String.fromCharCode(key), '0123456789abcdefghijklmnopqrstuvxyzw' ) )
				if ( !validastring( masc.substr(obj.value.length+1, 1), '0123456789abcdefghijklmnopqrstuvxyzw' ) ){
						obj.value += String.fromCharCode(key) + masc.substr(obj.value.length+1, 1);
						if ( obj.value.length == masc.length ){
							//alert();
							nextCampo( obj );
							return false;
						}
						
						return false;
				}
			//else{
				//return false;
			//}
		}
	}else{
		nextCampo( obj );
		return false;
	}
}

function nextCampo(obj){
		for ( i=0; i<obj.form.length; i++ ){
			if ( obj.form.elements[i].name == obj.name ){
				//alert(obj.form.elements[i+1].name);
				//while(obj.form.elements[i+1].type.toLowerCase() != "text" && obj.form.elements[i+1].type.toLowerCase() != "submit"){
					i++;
				//}
				obj.form.elements[i].focus();
				break;
			}
		}
}


// funções antigas //




function checaForm(form){
	var msg = "";
	result = "";
	for (var i=0; i<form.elements.length;i++){
		objCampo = form.elements[i];
		//if ( objCampo.mandatory == "true" ){
			if (objCampo.tipo && objCampo.disabled==false){
				//alert(objCampo.tipo)
				eval( "result = valida" + objCampo.tipo.toUpperCase() + "( objCampo )");
				if ( !result ){
					if (objCampo.minimo && objCampo.mandatory ){
						msg += "- O campo " + objCampo.desc + " deve possuir no mínimo "+objCampo.minimo+" caracteres.\\n";
						objCampo.style.borderColor = "red";
					}else{
						msg += "- O campo " + objCampo.desc + " deve ser preenchido corretamente.\\n"
						objCampo.style.borderColor = "red";
						
					}
				}else{
					objCampo.style.borderColor = "black";
				}
			}
		//}
		if (objCampo.type.toLowerCase()=="password"){
			if ( objCampo.ref){
				var ref = eval("form."+objCampo.ref);
				if ( ref ){
					if (ref.value != objCampo.value ){
						msg += "- A senha e sua Confirmação devem ser iguais.\\n";
						
					}
				}
			}
		}
	}
	if ( msg != '' ){
		//alert('Ocorreram os seguintes erros ao enviar o formulário:\\n\\n' + msg + '\\nPreencha os campos corretamente e tente novamente.');
		window.showModalDialog("/ssi/modelos/alert.php?msg="+msg ,"avisoPadrao","center:yes;dialogWidth:450px;dialogheight=500px;status=no;");
		return false;
	}
}

function validaCNPJ(obj){
	 cnpj = limpaint(obj.value);
	 
      var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais; 
      digitos_iguais = 1; 
      if (cnpj.length < 14 && cnpj.length < 15) 
            return false; 
      for (i = 0; i < cnpj.length - 1; i++) 
            if (cnpj.charAt(i) != cnpj.charAt(i + 1)) 
                  { 
                  digitos_iguais = 0; 
                  break; 
                  } 
      if (!digitos_iguais) 
            { 
            tamanho = cnpj.length - 2 
            numeros = cnpj.substring(0,tamanho); 
            digitos = cnpj.substring(tamanho); 
            soma = 0; 
            pos = tamanho - 7; 
            for (i = tamanho; i >= 1; i--) 
                  { 
                  soma += numeros.charAt(tamanho - i) * pos--; 
                  if (pos < 2) 
                        pos = 9; 
                  } 
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11; 
            if (resultado != digitos.charAt(0)) 
                  return false; 
            tamanho = tamanho + 1; 
            numeros = cnpj.substring(0,tamanho); 
            soma = 0; 
            pos = tamanho - 7; 
            for (i = tamanho; i >= 1; i--) 
                  { 
                  soma += numeros.charAt(tamanho - i) * pos--; 
                  if (pos < 2) 
                        pos = 9; 
                  } 
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11; 
            if (resultado != digitos.charAt(1)) 
                  return false; 
            return true; 
            } 
      else 
            return false; 
      
}
function validaCPF(obj){
	return validacpf(limpaint(obj.value));
}

function validaCNPJCPF(obj){
	switch(obj.value.length){
		case 14: return validaCPF(obj);
			break;
		case 18: return validaCNPJ(obj);
			break;
	}
	/*
	if (obj.value.length==14){
		return validacpf(obj);
	}elseif(obj.value.length==18){
		return validaCNPJ(obj);
	}else{
		return false;
	}*/
}
	
function validaCEP(obj){
	return validaMascara(obj.value, '35900-000');
}

function validaHORA(obj){
	return validaMascara(obj.value, '00:00');
}
function validaMOEDA(obj){
	if (obj.value.length>0 ){
		return true
	}else{
		return false
	}
}

function validaTEXTO( objCampo ){
	if ( objCampo.minimo ){
		if ( objCampo.value.length < objCampo.minimo || objCampo.value == ''){
			return false;
		}else{
			return true;
		}
	}else{
		if ( objCampo.value == '' && objCampo.mandatory ){
			return false;
		}
	}
	return true;
}

function validaSOTEXTO( objCampo ){
	var txt = "abcdefghijklmnopqrstuvxyzw";
	txt += txt.toUpperCase();
	
	if ( objCampo.minimo ){
		if ( objCampo.minimo > objCampo.value.length ){
			return false;
		}
	}
	if (objCampo.mandatory){
		return ( validastring( objCampo.value, txt ) );
	}else{
		return ( validastring( objCampo.value, txt ) ) || objCampo.value=='';
	}
}

function validastring(src, strValidos){
	var s = src.split('');
	if ( src == '' ){
		return false;
	}
	for ( var i=0; i<s.length ; i++ ){
		if ( strValidos.indexOf(s[i])<0 ){
			return false;
		}
	}
	return true;
}



function validaINT( objCampo ){
	if (objCampo.mandatory){
		a = validastring( objCampo.value, "0123456789" );
		return a;
	}else{
		if (objCampo.minimo){
			return objCampo.value==''  || (validastring( objCampo.value, "0123456789" ) && objCampo.value.length >= objCampo.minimo );
		}else{
			return validastring( objCampo.value, "0123456789" ) ||  objCampo.value=='';
		}
	}
}

function limpaint(s){
	var a = s.split('');
	var r = "";
	for (var i=0;i<a.length; i++){
		if (validastring(a[i],"0123456789")){
			r += a[i];
		}
	}
	return r;
}


function validaTELEFONE( objCampo ){
	s = limpaint(objCampo.value);
	if (objCampo.mandatory == true || objCampo.value != '' ){
		if (s.length == 10){
			return validaMascara(objCampo.value, '33 3333-3333');
			
			//return true;
		}else{
			return false;
		}
	}else{return true;}
}

function validaDATA( objCampo ){
	//if ( objCampo.mandatory )
	if (objCampo.mandatory.toUpperCase()=='TRUE' || objCampo.value!=''){
		var val = objCampo.value.split('');
		if ( val.length == 10){
			if (validastring( val[0], "0123456789" )){
				if (validastring( val[1], "0123456789" )){
					if (validastring( val[2], "/" )){
						if (validastring( val[3], "0123456789" )){
							if (validastring( val[4], "0123456789" )){
								if (validastring( val[5], "/" )){
									if (validastring( val[6], "12" )){
										if (validastring( val[7], "0123456789" )){
											if(validastring( val[8], "0123456789" )){
												if (validastring( val[9], "0123456789" )){
													val = objCampo.value.split('/');
													if (val[0]<=31 && val[1]<=12){
														return true;
													}else{
														return false
													}
													
												}else{return false;}
											}else{return false;}
										}else{return false;}
									}else{return false;}
								}else{return false;}
							}else{return false;}
						}else{return false;}
					}else{return false;}
				}else{return false;}
			}else{return false;}
		}else{return false;}
	}else{
		return true;
	}
}

function validaCGCCPF( objCampo ){
	return true;
}

function validaEMAIL( objCampo ){
	if (objCampo.mandatory || objCampo.value != ''){
		var s = objCampo.value.split('');
		var arroba = 0;
		var ponto = 0;
		for (var i=0; i<s.length; i++){
			if (s[i]=="@"){
				arroba = i;
			}else{
				if (s[i]=="." && arroba>0 && (i-arroba>1) && i<s.length-1){
					return true;
				}
			}
		}
		return false;
	}else{
		return true;
	}
}


function maiusculo(obj){
	obj.value = obj.value.toUpperCase();
}

function foco(){
	if (document.forms.length){
		if(document.forms[0].elements.length){
			for (i=0;i<document.forms[0].length;i++)
				if (document.forms[0].elements[i].type=="text" && !document.forms[0].elements[i].disabled){
					setTimeout("document.forms[0].elements["+i+"].focus();", 1);
					return
				}
			
		}
	}
}


function Mascara (formato, keypress, campo){
	

	// CEP
	if (formato=='CEP'){
		if (keypress > 57 || keypress<48)
		return false;
		separador = '-'; 
		conjunto1 = 5;
		maximo = 9
		if (campo.value.length == conjunto1){
			campo.value = campo.value + separador;
		}else{
			if (campo.value.length==maximo)
				return false;
		}
	}
	
	if ( formato == 'CNPJ' ){
		if (keypress > 57 || keypress<48)
		return false;
		//000.886.201/0001-38
		conjunto1 = conjunto2 = conjunto3 = 3;
		if ( campo.value.length ==conjunto1 ||  campo.value.length ==conjunto1+conjunto2+1 ){
			campo.value = campo.value + '.';
		}else{
			if ( campo.value.length ==conjunto1+conjunto2+conjunto3+2 ){
				campo.value = campo.value + '/';
			}else{
				if ( campo.value.length ==16 ){
					campo.value = campo.value + '-';
				}else{
					if ( campo.value.length == 19 ){
						return false
					}
				}
			}
		}
		

	}
	
	// DATA
	if (formato=='DATA'){
		if (keypress > 57 || keypress<48)
		return false;
		separador = '/'; 
		conjunto1 = 2;
		conjunto2 = 5;
		if (campo.value.length == conjunto1){
			campo.value = campo.value + separador;
		}
		if (campo.value.length == conjunto2){
			campo.value = campo.value + separador;
		}
	}
	// TELEFONE
	if (formato=='TELEFONE'){
		if (keypress > 57 || keypress<48)
		return false;
		separador = '-'; 
		conjunto1 = 2;
		conjunto2 = 7
		maximo = 12
		if (campo.value.length == conjunto1){
			campo.value = campo.value + ' ';
		}else{
			if (campo.value.length == conjunto2){
				campo.value += separador;
			}else{
				if (campo.value.length == maximo)
					return false
			}
		}
	}
	//CPF
	if (formato == 'CPF'){
		if (keypress > 57 || keypress<48)
		return false;
		if( campo.value.length == 3 || campo.value.length == 7 ){
			campo.value += '.'
		}else{
			if ( campo.value.length == 11 ){
				campo.value += '-'
			}else{
				if ( campo.value.length > 13){
					return false
				}
			}
		}
	}
}

function exitdata(obj){
	if (obj.comp){
		comp = obj.comp;
	}else{
		comp = '19';
	}
	if (obj){
		if (obj.value.length==8){
			aData = obj.value.split('/');
			if (aData.length==3){
				obj.value = aData[0] + '/' + aData[1] + '/'+comp+aData[2];
			}
		}
	}
}
function moeda_exit(obj){
	a = obj.value.split(',');
	if (obj.value.length==0){
		obj.value="0,00";
		return
	}
	if(a.length==1){
		obj.value += ',00';
	}else{
		if (a[1].length==1){
			obj.value += '0';
		}else{
			if (a[1].length==0){
				obj.value+='00';
			}
		}
	}
}

function int_press(keypress){
	if ( !(keypress <= 57 && keypress>=48) ){
		return false
	}
}

function moeda_press(keypress, campo){
	if ((keypress <= 57 && keypress>=48) || keypress == 44){
		if (keypress==44){
			a = campo.value.split(',');
			if (a.length>1){
				return false;
			}
		}
	}else{
		return false
	}
}

function FORMATASPAN(){
	a = document.getElementsByTagName('span');
	for ( var cont=0;cont<a.length;cont++){
		a[cont].innerHTML = (_format(a[cont].innerHTML, a[cont].str));
		
	}
	
}	

function _tipo(s){
	var validos = 'abcdefghijklmnopqrstuvsyzw0123456789';
	if (validos.indexOf(s)>-1){
		return true;
	}else{
		return false;
	}
}

function _format(str, format){
	return str;
	var aFormat = format.split('');
	var aStr = str.split('');
	var result ='';
	idxStr = 0;
	idxFormat = 0;
	while(idxFormat<aFormat.length || idxStr<aStr.length){
		if (aFormat.length>idxFormat){
			if (_tipo(aStr[idxStr]) &&  _tipo(aFormat[idxFormat])){
				result += ''+aStr[idxStr];
				idxStr++;
				idxFormat++;
			}else{
				result += ''+aFormat[idxFormat];
				idxFormat++;
			}
		}else{
			result += ''+aStr[idxStr];
			idxStr++;
		}
		
	}
	
	return result;
}


function checkboxdbval(obj){
	if(obj && obj.dbval){
		if (obj.dbval==obj.value){
			
			obj.checked = true;
			
		}
	}
}

function radiodbval(obj){
	if(obj && obj.dbval){
		if(obj.value==obj.dbval){
			obj.checked = true;
		}
		
	}
}

	

function LOADER(){
	foco();
	FORMATASPAN();
	for (i=0;i<document.forms.length;i++){
		if (document.forms[i].onsubmit==null){
			if (document.forms[i].beforesubmit){
				document.forms[i].onsubmit = new Function("teste2 = "+document.forms[i].beforesubmit+"; teste1 = checaForm(document.forms["+i+"]);if (teste1==false || teste2==false){ return false; }else{return true;}");
			}else{
				document.forms[i].onsubmit = new Function("return checaForm(document.forms["+i+"])");
			}
			
			
			
			for (j=0;j<document.forms[i].length;j++){
				switch(document.forms[i].elements[j].type){
					case 'checkbox': checkboxdbval(document.forms[i].elements[j]);
						break;
					case 'radio':radiodbval(document.forms[i].elements[j]);
						break;
				}
				
				if(document.forms[i].elements[j].tipo)
				switch(document.forms[i].elements[j].tipo.toLowerCase()){
					case "data":
						document.forms[i].elements[j].onkeypress = new Function("return MASK('99/99/9999', window.event.keyCode, document.forms["+i+"].elements["+j+"]);");
						document.forms[i].elements[j].maxLength="10";
						
						if (document.forms[i].elements[j].onblur == ''){
							document.forms[i].elements[j].onblur = new Function("exitdata(document.forms["+i+"].elements["+j+"]);");
							alert(document.forms[i].elements[j].onblur);
						}
						document.forms[i].elements[j].size = "12";
					break;
					
					case "moeda":
						document.forms[i].elements[j].onkeypress = new Function("return moeda_press(window.event.keyCode, document.forms["+i+"].elements["+j+"]);");
						if ( ! document.forms[i].elements[j].onblur )
						document.forms[i].elements[j].onblur = new Function("moeda_exit(document.forms["+i+"].elements["+j+"]);");
						document.forms[i].elements[j].style.textAlign='right';
					break;
					
					case "int":
						document.forms[i].elements[j].onkeypress = new Function("return int_press(window.event.keyCode)");
						document.forms[i].elements[j].style.textAlign='right';
					break;
					
					case "cnpjcpf":
						document.forms[i].elements[j].onkeypress = new Function("return MASK('"+document.forms[i].elements[j].mascara+"', window.event.keyCode, document.forms["+i+"].elements["+j+"]);");
					break;

				}
				
				if ( document.forms[i].elements[j].mascara ){
					document.forms[i].elements[j].onkeypress = new Function("return MASK('"+document.forms[i].elements[j].mascara+"', window.event.keyCode, document.forms["+i+"].elements["+j+"]);");
				}else{
					if (document.forms[i].elements[j].type == 'checkbox'){
						checkboxdbval(document.forms[i].elements[j].type);
					}
				}
				if (document.forms[i].elements[j].def){
					sel(document.forms[i].elements[j], document.forms[i].elements[j].def);
				}
				
					
			}
		}
	}
}

function setmask(obj, mascara){
	obj.onkeypress = null;
	obj.onkeypress = new Function("return MASK('"+mascara+"', window.event.keyCode, document."+obj.form.name+"."+obj.name+");");
}
document.onLoad = LOADER();
