function valida_form(s){
	temp = s.elements.length;//loop em todos os elementos do formulário
	for (i=0; i < temp; i++){
		//pega o nome da variável cujo número no elements é igual a i
		if (s.elements[i].type == "text"){
			if (s.elements[i].value == ""){
				s.elements[i].focus();
				alert('Por favor, preencha o campo selecionado !!');
				return false;
			}
		}
	}
	return true;
}

function valida_newsenha(s){
	temp = s.elements.length;//loop em todos os elementos do formulário
	for (i=0; i < temp; i++){
		//pega o nome da variável cujo número no elements é igual a i
		if (s.elements[i].type == "password"){
			if (s.elements[i].value == ""){
				s.elements[i].focus();
				alert('Por favor, preencha o campo selecionado !!');
				return false;
			}
		}
	}
	if (s.novasenha.value!=s.cnovasenha.value){
		alert('Nova senha diferente da confirmação.');
		s.novasenha.focus();	
		return false;
	}
		
	return true;
}
	
function high(which2){
	theobject=which2;
	highlighting=setInterval("highlightit(theobject)",50);
}

function low(which2){
	clearInterval(highlighting);
	if (which2.style.MozOpacity)
		which2.style.MozOpacity=0.3;
	else if (which2.filters)
		which2.filters.alpha.opacity=30;
}

function highlightit(cur2){
	if (cur2.style.MozOpacity<1)
		cur2.style.MozOpacity=parseFloat(cur2.style.MozOpacity)+0.1;
	else if (cur2.filters&&cur2.filters.alpha.opacity<100)
		cur2.filters.alpha.opacity+=10;
	else if (window.highlighting)
		clearInterval(highlighting);
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {
  	if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    	document.MM_pgW=innerWidth; 
		document.MM_pgH=innerHeight; 
		onresize=MM_reloadPage; 
	}
  }
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) 
  	location.reload();
}
MM_reloadPage(true);

function mClk(src) {
	if(event.srcElement.tagName=='TD'){
		src.children.tags('A')[0].click();
	}
}

function mOvr(src,clrOver) {
  if (!src.contains(event.fromElement)) {
    src.style.cursor = 'hand';
    src.bgColor = clrOver;
  }
}

function mOut(src,clrIn) {
  if (!src.contains(event.toElement)) {
    src.style.cursor = 'default';
    src.bgColor = clrIn;
  }
}

function validaemail(){
  if ( !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(cadastrocadastro.Cad_Email.value))) { 
    alert("Favor informar um email válido."); 
    document.cadastrocadastro.Cad_Email.focus();
    return false; 
  }
} 

function valida_email(campo){
	var boolobrigatorio;
	boolobrigatorio = false;
	if (verifica_padrao(campo)){
		if (campo.name.substring(4,6) == '1_'){
			//Se verdadeiro significa que o e-mail é obrigatório
			boolobrigatorio = true;
		}
		if (boolobrigatorio == true | campo.value.length != 0){	
			if (!/^([a-zA-Z0-9]+([_\-\.]{0,1}[a-zA-Z0-9]{1,})*)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,6}|[0-9]{1,3})(\]?)$/.test(campo.value)) {
				alert('Formato do e-mail está incorreto !!');
				campo.focus();
				return false;
			}
		}
	}
	return true;
}

function validalogin(){
  if (!document.loginsistema.login.value) {  	
 	alert("Favor digitar seu Login"); 
    document.loginsistema.login.focus(); 
    return false; 
  }
  else if (!document.loginsistema.senha.value) {  	
  	alert("Favor digitar sua Senha"); 
    document.loginsistema.senha.focus(); 
    return false; 
  }
  else return true; 
}
 
function SelecionaTodas(checked) {
    len = document.modeloslista.elements.length;
    var i = 0;
    for(i = 0; i < len; i++) {
        document.modeloslista.elements[i].checked = checked;
    }
}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
}

function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
		if(arr[index] == ele)
			found = true;
		else index++;
	return found;
}

function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
	if (input.form[i] == input) 
		index = i;
	else i++;
	return index;
}

function ano(){
  if (event.keyCode < 47 || event.keyCode > 57) {
    alert("Caracter inválido para o ano!") ;
	event.returnValue = false;
  } 
}


function valor(){
  if (event.keyCode == 44 ) {
    alert("Não use vírgula (,) !") ;
	event.returnValue = false;
  } 
  else if (event.keyCode == 46 ) {
    alert("Não use ponto (.) !") ;
	event.returnValue = false;
  } 
  else if (event.keyCode < 45 || event.keyCode > 57) {
    alert("Caracter inválido para valor!") ;
	event.returnValue = false;
  } 
}

// confrima exclusao de Arquivos
function Excluir(endereco, msg){
  if (confirm(msg))  {
    window.location = endereco;
  }
}

function integridade(msg){
  alert(msg);
}

function validaselect(){
  if (document.loginseleciona.login.value == "0") {  	
  		alert("Favor selecionar um Nome") 
    	document.loginseleciona.login.focus() 
    return false; 
  }
  else return true; 
}
 
function validabusca(){
  if (!document.busca.palavra.value) {  	
  	alert("Favor digitar palavra pra busca") 
    document.busca.palavra.focus() 
    return false; 
  }
  else return true; 
}

function validatrocasenha(){
  if (!document.trocasenha.Usu_SenhaNova.value) {  	
  	alert("Favor digitar sua nova senha") 
    document.trocasenha.Usu_SenhaNova.focus() 
    return false; 
  }
  else if (!document.trocasenha.ConfirmaSenha.value) {  	
  	alert("Favor digitar sua a confirmação da senha") 
    document.trocasenha.ConfirmaSenha.focus() 
    return false; 
  }
  else if (document.trocasenha.Usu_SenhaNova.value != document.trocasenha.ConfirmaSenha.value) {  	
  	alert("A confirmação da senha não confere com a nova senha, favor digitá-la novamente") 
    document.trocasenha.ConfirmaSenha.focus() 
    return false; 
  }
  else return true; 
}

