//################################################################
// TCA Informática LTDA -- [SCOPI] ###############################
// Desenvolvido por Josemar Davi Luedke (TCA Informática) ########
// Data: 12/02/2009 Proíbido qualquer copia deste codigo #########
//################################################################


function carregando(id,texto){
			if (texto == 'carregando...'){
		document.getElementById(id).innerHTML=texto+ " <img border=0 src='images/load.gif'>";
	}
	else {
		document.getElementById(id).innerHTML=texto;
	}
}
function autentica(pagina,idform){
	_getAjax(pagina,document.getElementById(idform));
}
function noNumbers(e, bloq) {
	var tecla=new Number();
	var e = e || event;
	var k = e.keyCode || e.which;
	if (!k > 47 && k < 58) {
		window.event.keyCode = 0;
	}
	if (k==13) { 
				if (ValUser() == false) {
					carregando('texto_erro', 'Digite um Usuario valido, M&iacute;nimo 3 caracteres.');
					carregando('msgLogin', '<img src=images/error.png align=bottom>');
					document.getElementById('login').focus();
					return false;
				}
				else if (ValPass() == false) {
					carregando('texto_erro', 'Digite uma senha valida');
					carregando('msgSenha', '<img src=images/error.png align=bottom>')
					document.getElementById('senha').focus();
					return false;
					}
				else if (document.getElementById('int').value.length < 4) {
					carregando('texto_erro', 'Digite uma Institui&ccedil;&atilde;o valida, M&iacute;nimo 4 caracteres.');
					carregando('msgInst', '<img src=images/error.png align=bottom>')
					document.getElementById('int').focus();
					return false;
					}
				else {
					carregando('msgInst', '<img src=images/yes.png align=bottom>');
					carregando('texto_erro', ' ')
					carregando('texto_erro', 'carregando...');
					autentica('system/login.php', 'formlogin');
					}	
	 }
	if (bloq == 's') {
		if (window.event) {
			tecla = e.keyCode;
		}
		else 
			if (e.which) {
				tecla = e.which;
			}
			else {
				return true;
			}
		if (((tecla < 48) || (tecla > 57)) && (tecla != 8)) {
			return false;
		}
	} else if(bloq == 'n') {}

}
function ValUser(){
		if (document.getElementById('login').value.length <  3){
			carregando('texto_erro','Digite um Usuario valido, M&iacute;nimo 3 caracteres.');
			carregando('msgLogin','<img src=images/error.png align=bottom>');
			document.getElementById('login').focus();
			return false;
		}
		else {
			carregando('texto_erro',' ')
			carregando('msgLogin','<img src=images/yes.png align=bottom>');
			return true;
		}
}
function ValPass(){
		if (document.getElementById('senha').value.length < 2){
			carregando('texto_erro','Digite uma senha valida');
			carregando('msgSenha','<img src=images/error.png align=bottom>')
			document.getElementById('senha').focus();
			return false;
		}
		else {
			carregando('texto_erro',' ')
			carregando('msgSenha','<img src=images/yes.png align=bottom>');
			return true;
		}
}
function ValInst() {
		if (document.getElementById('int').value.length < 4){
			carregando('texto_erro','Digite uma Institui&ccedil;&atilde;o valida, M&iacute;nimo 4 caracteres.');
			carregando('msgInst','<img src=images/error.png align=bottom>')
			document.getElementById('int').focus();
			return false;
		}
		else {
			carregando('msgInst','<img src=images/yes.png align=bottom>');
			carregando('texto_erro',' ')
			return true;
		}
}
function ValFormLogin() {
		if (ValUser() == false) {
			carregando('texto_erro','Digite um Usuario valido, M&iacute;nimo 3 caracteres.');
			carregando('msgLogin','<img src=images/error.png align=bottom>');
			document.getElementById('login').focus();
			return false;
		}	
		else if(ValPass() == false) {
			carregando('texto_erro','Digite uma senha valida');
			carregando('msgSenha','<img src=images/error.png align=bottom>')
			document.getElementById('senha').focus();
			return false;
		} else if (document.getElementById('int').value.length < 4){
			carregando('texto_erro','Digite uma Institui&ccedil;&atilde;o valida, M&iacute;nimo 4 caracteres.');
			carregando('msgInst','<img src=images/error.png align=bottom>')
			document.getElementById('int').focus();
			return false;
		} else {
			carregando('msgInst','<img src=images/yes.png align=bottom>');
			carregando('texto_erro',' ')
			carregando('texto_erro','carregando...');autentica('system/login.php','formlogin');
			return true;
			}	
}