function numeros(event)
{
    if (event.keyCode) {
        if (event.keyCode < 44 || event.keyCode > 58) {
            return false;
        } else {
            return true;
        }
    } else {
        if (event.which < 44 || event.which > 58) {
            return false;
        } else {
            return true;
        }
    }
}

// Abre o pop-up de Relacionamento de Matrias no CMS
function popupJanela(url, nome, altura, largura) {
	x = (screen.width  - largura) / 2;
	y = (screen.height - altura)  / 2;
	window.open(url,nome,'left=' + x + ',top=' + y + ',height=' + altura + ',width=' + largura + ',menubar=no,location=no,resizable=yes,scrollbars=yes,status=no,titlebar=yes,toolbar=no');
}

function alertaEmail(obj){ 
	var str = obj.value; 
	
	if (str != '' && !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str))){ 
		alert("Por favor, insira um email valido!"); 
		obj.focus();
		obj.select();
		return false; 
	} else {
		return true;
	}
}

function setaData(comboDia,comboMes,comboAno){
	data = new Date();
	
	dia  = new String(data.getDate());
	if(dia.length == 1) { dia = '0' + dia; }
	
	mes  = new String(data.getMonth() + 1);
	if(mes.length == 1) { mes = '0' + mes; }
	
	ano  = new String(data.getFullYear());
	
	eval('document.form.' +  comboDia + '.value = "' + dia + '";'); 
	eval('document.form.' +  comboMes + '.value = "' + mes + '";');
	eval('document.form.' +  comboAno + '.value = "' + ano + '";');
}

function setaHora(comboHora,comboMinuto){
	data   = new Date();
	
	hora   = new String(data.getHours());
	if(hora.length   == 1) { hora   = '0' + hora;   }
	
	minuto = new String(data.getMinutes());
	if(minuto.length == 1) { minuto = '0' + minuto; }
	
	
	eval('document.form.' +  comboHora   + '.value = "' + hora   + '";'); 
	eval('document.form.' +  comboMinuto + '.value = "' + minuto + '";');
}

var obData	= new Date();
var focoDia = new String(obData.getDate());
var focoMes = new String(obData.getMonth() + 1);
var focoAno = new String(obData.getFullYear());

function focusData(campo) {
	focoDia = eval('document.form.' + campo + '_dia.value;');
	focoMes = eval('document.form.' + campo + '_mes.value;');
	focoAno = eval('document.form.' + campo + '_ano.value;');
}

function verificaData(campo) {
	dia = eval('document.form.' + campo + '_dia.value;');
	mes = eval('document.form.' + campo + '_mes.value;');
	ano = eval('document.form.' + campo + '_ano.value;');
	controle = true;
	
	switch(mes) {
		case '2':
			ano = ano % 4;
			if (ano > 0) { // se no for ano bissexto
				if (dia >= 29) { controle = false; }
			} else {
				if (dia >= 30) { controle = false; }			
			}
		break;

		case '4':
		case '6':
		case '9':
		case '11':
			if (dia == 31) { controle = false; }
		break;
	}
	
	if(controle === false) {
		alert('A data selecionada no  vlida!');
		eval('document.form.' + campo + '_dia.value = ' + focoDia);
		eval('document.form.' + campo + '_mes.value = ' + focoMes);
		eval('document.form.' + campo + '_ano.value = ' + focoAno);
		return false;
	} else { return true; }
}

function verificaCNPJ( sender ) {
	var temp
	var cont
	var dg1
	var dg1_1
	var dg2
	var dg2_2
	var sValue
	var digits="0123456789"

	sValue = sender.value;

	// Limpa todos os caracteres de formatao que ja 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( " ", "" );
	
	for (var i=0;i<sValue.length;i++){
		temp=sValue.substring(i,i+1);
		
		if (digits.indexOf(temp)==-1){
			alert("Por Favor, o Campo CNPJ deve ser preenchido apenas com numeros!");
			sender.focus();
			return;
		}
	}
	
	cont=0;
	
	for (var i = 0; i < sValue.length; i++) {
		temp=sValue.substring(i,i+1);
		cont=cont+1;
	}
	
	if (cont!=0) {
		if (cont!=14) {
			alert("Numero de CPNJ Invalido");
			sender.focus();
		}
		else {
			cont=1;
			dg1=0;
			dg2=0;
			
			for (var i=0;i<sValue.length;i++){
				temp = Math.abs( sValue.substring(i,i+1) );

				if (cont==1)
						dg1=dg1+Math.abs(temp*5);

				if (cont==2)
					dg1=dg1+Math.abs(temp*4);
				
				if (cont==3)
					dg1=dg1+Math.abs(temp*3);
				
				if (cont==4)
					dg1=dg1+Math.abs(temp*2);

				if (cont==5)
					dg1=dg1+Math.abs(temp*9);
				
				if (cont==6)
					dg1=dg1+Math.abs(temp*8);
				
				if (cont==7)
					dg1=dg1+Math.abs(temp*7);
				
				if (cont==8)
					dg1=dg1+Math.abs(temp*6);

				if (cont==9)
					dg1=dg1+Math.abs(temp*5);
					
				if (cont==10)
					dg1=dg1+Math.abs(temp*4);
				
				if (cont==11)
					dg1=dg1+Math.abs(temp*3);
				
				if (cont==12)
					dg1=dg1+Math.abs(temp*2);
					
				if (cont==13)
					dg1_1=temp;
				
				if (cont==14)
					dg2_2=temp;
				
				cont=cont+1;
			}

			dg1=11-(dg1-((Math.floor(dg1/11))*11))

			if (dg1==10 || dg1==11)
				dg1=0;

			if (dg1!=dg1_1){
				alert("Numero de CPNJ Invalido");
				sender.focus();
			}
			else {
				cont=1;

				for (var i=0;i<sValue.length;i++){
					temp=Math.abs(sValue.substring(i,i+1));
					
					if (cont==1)
						dg2=dg2+Math.abs(temp*6);
					if (cont==2)
						dg2=dg2+Math.abs(temp*5);
					if (cont==3)
						dg2=dg2+Math.abs(temp*4);
					if (cont==4)
						dg2=dg2+Math.abs(temp*3);
					if (cont==5)
						dg2=dg2+Math.abs(temp*2);
					if (cont==6)
						dg2=dg2+Math.abs(temp*9);
					if (cont==7)
						dg2=dg2+Math.abs(temp*8);
					if (cont==8)
						dg2=dg2+Math.abs(temp*7);
					if (cont==9)
						dg2=dg2+Math.abs(temp*6);
					if (cont==10)
						dg2=dg2+Math.abs(temp*5);
					if (cont==11)
						dg2=dg2+Math.abs(temp*4);
					if (cont==12)
						dg2=dg2+Math.abs(temp*3);
					if (cont==13)
						dg2=dg2+Math.abs(temp*2);

					cont=cont+1;
				}
				
				dg2=11-(dg2-((Math.floor(dg2/11))*11));
				
				if (dg2==10 || dg2==11)
					dg2=0;
				
				if (dg2!=dg2_2) {
					alert("Numero de CPNJ Invalido");
					sender.focus();
				}
			}
		}
	}
}

function verificaCPF( sender ){
	var conf=0
	var temp
	var temp1
	var cont
	var dg1
	var dg1_1
	var dg2
	var dg2_2
	var sValue
	var digits="0123456789"
	
	sValue = sender.value;

	// Limpa todos os caracteres de formatao que ja 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( " ", "" );
      
	for (var i = 0; i < sValue.length; i++) {
		temp1=temp
		temp=sValue.substring(i,i+1)
		
		if (temp==temp1){
			conf=conf+1
		}
    
		if (digits.indexOf(temp)==-1){
			alert("Por Favor, o Campo CPF deve ser preenchido apenas com numeros!")
      sender.focus()
      return
		}
	}

	if (conf==10){
		alert("Numero do CPF Invalido")
		sender.focus()
		return
	}

	cont=0

	for (var i=0;i<sValue.length;i++){
		temp=sValue.substring(i,i+1)
		cont=cont+1
	}

	if (cont!=0){
		if (cont!=11){
			alert("Numero do CPF Invalido")
			sender.focus()
			return
		}
    else {
			cont=1
			dg1=0
			dg2=0
			
			for (var i=0;i<sValue.length;i++){
				temp=Math.abs(sValue.substring(i,i+1))
        
				if (cont==1) {
					dg1=dg1+Math.abs(temp*10)
				}
               
				if (cont==2) {
					dg1=dg1+Math.abs(temp*9)
				}

				if (cont==3) {
					dg1=dg1+Math.abs(temp*8)
				}

				if (cont==4) {
					dg1=dg1+Math.abs(temp*7)
				}

				if (cont==5) {
					dg1=dg1+Math.abs(temp*6)
				}

				if (cont==6) {
					dg1=dg1+Math.abs(temp*5)
				}

				if (cont==7) {
					dg1=dg1+Math.abs(temp*4)
				}

				if (cont==8) {
					dg1=dg1+Math.abs(temp*3)
				}

				if (cont==9){
					dg1=dg1+Math.abs(temp*2)
				}

				if (cont==10) {
					dg1_1=temp
				}
					
				if (cont==11) {
					dg2_2=temp
				}
				
				cont=cont+1
			}

			dg1=11-(dg1-((Math.floor(dg1/11))*11))

			if (dg1==10 || dg1==11) {
				dg1=0
			}

			if (dg1!=dg1_1) {
				alert("Numero do CPF Invalido")
				sender.focus()
				return
			}
			else {
				cont=1

				for (var i=0;i<sValue.length;i++) {
					temp=Math.abs(sValue.substring(i,i+1))

					if (cont==1){
						dg2=dg2+Math.abs(temp*11)
					}

					if (cont==2){
						dg2=dg2+Math.abs(temp*10)
					}

					if (cont==3){
						dg2=dg2+Math.abs(temp*9)
					}

					if (cont==4){
						dg2=dg2+Math.abs(temp*8)
					}

					if (cont==5){
						dg2=dg2+Math.abs(temp*7)
					}

					if (cont==6){
						dg2=dg2+Math.abs(temp*6)
					}

					if (cont==7){
						dg2=dg2+Math.abs(temp*5)
					}

					if (cont==8){
						dg2=dg2+Math.abs(temp*4)
					}

					if (cont==9){
						dg2=dg2+Math.abs(temp*3)
					}

					if (cont==10){
						 dg2=dg2+Math.abs(temp*2)
					}
					
					cont=cont+1
				}
        
				dg2=11-(dg2-((Math.floor(dg2/11))*11))
        
				if (dg2==10 || dg2==11){
        	dg2=0
				}
        
				if (dg2!=dg2_2) {
					alert("Numero do CPF Invalido")
					sender.focus()
					return
				}
			}
		}
	}
}

function fnPaginacaoItemMT(strNome,strIndice) {
	eval('var strTotal = MT_' + strNome + '_total;');		// Busca o valor do total de pÃÂ¡ginas para o ID indicado
	eval('MT_' + strNome + '_index = ' + strIndice + ';');	// Seta a pÃÂ¡gina atual para o ID indicado
	
	if(document.getElementById('imgMultitext')) {
		if(strIndice != 1) {
			document.getElementById('imgMultitext').style.display = 'none';
		} else {
			document.getElementById('imgMultitext').style.display = 'block';
		}
	}
	
	if(document.getElementById('lk_preview')) {
		if(strIndice == 1) {
			document.getElementById('lk_preview').style.display = 'none';
		} else {
			document.getElementById('lk_preview').style.display = 'block';
		}
	}
	
	if(document.getElementById('lk_next')) {
		if(strIndice == strTotal) {
			document.getElementById('lk_next').style.display = 'none';
		} else {
			document.getElementById('lk_next').style.display = 'block';
		}
	}
	
	for(i = 1; i <= strTotal; i++) {
		var strValor = 'MT_' + strNome + '_' + i;
		document.getElementById(strValor).style.display = 'none';
	}
	
	var strValor = 'MT_' + strNome + '_' + strIndice;
	document.getElementById(strValor).style.display = 'block';
	window.scrollTo(0,0);
}

function fnPaginacaoMT(strNome,strValor) {
	eval('var strTotal = MT_' + strNome + '_total;');	// Busca o valor do total de pÃÂ¡ginas para o ID indicado
	eval('var strTemp  = MT_' + strNome + '_index;');	// Busca o valor da pÃÂ¡gina atual para o ID indicado
	switch(strValor) {
		case 1:	// AvanÃÂ§ar
			if(strTemp < strTotal) {
				strTemp = (strTemp + 1);
			}
		break;
		
		case 0:	// Voltar
			if(strTemp > 1) {
				strTemp = (strTemp - 1);
			}
		break;
		
		default:
		break;
	}
	fnPaginacaoItemMT(strNome,strTemp);
}

function fnSintaxeURL(objeto) {
	if(objeto.value.indexOf('http://') < 0 && objeto.value != '') {
		objeto.value = 'http://' + objeto.value;
	} else if(objeto.value == 'http://') {
		objeto.value = '';	
	}
}