﻿
var nomeAPP = window.location.pathname;
nomeAPP = nomeAPP.substring(0, nomeAPP.indexOf("/", 1));


var input;

$(function() {
	
	$('#empCod').focus();	
    $("#empCod").focus(function(){
        input=$("#empSen").val();
    });
    $("#empCod").blur(function(){
        $("#empSen").val(input);
    });
   
    $(document).ready(function() {
        ajustaFonte();
        $("#empSenVisual").val("");
        $("#empSen").val("");
        funcoesTeclado();
        carregaErro();
        $("#empCod").focus();
        LimpaSenha();
        
        
		$('.tooltip').tooltip( {
			track : true,
			delay : 0,
			showURL : false,
			showBody : " - ",
			fade : 250
		});                
    });
   
});

function funcoesTeclado() {
	$(".linkTeclado").mouseup(function() {
		document.getElementById("empSenVisual").focus()
	}).mousedown(function() {
		$("#empSenVisual").val($("#empSenVisual").val() + "*");
		$("#empSen").val($("#empSen").val() + "|" + this.innerHTML);		
		input=$("#empSen").val();
		document.getElementById("empSenVisual").focus()
	}).keypress(function(e) {
		var botao = e.which;
		if (botao == 32) {
			$("#empSenVisual").val($("#empSenVisual").val() + "*");
			$("#empSen").val($("#empSen").val() + "|" + this.innerHTML)
		} else if (botao == 13) {
			ValidaForm()
		}
	})
}

function mudaVersao(versao) {	
	document.location = nomeAPP+ "/salvaVersaoSite?versaoSite="+ versao;	
}


function LimpaSenha() {
    $("#empSenVisual").val("");
    $("#empSen").val("")
    input="";
}
function ValidaForm() {	
	if (document.login.empSen.value == "") {
		alert('O Código e a Senha devem ser preenchidos', 'Atenção');
	} else {
		document.login.submit();
	}
}
function cadastrarComputador() {
	window.location = "preparaCadastroComputador";
}
function recarregaTeclado() {
	var url = "/paginas/include/tecladovirtual.jsp";
	url = nomeAPP + url;
	$.get(url, function(data) {
		$("#campo_senha").html(data);
		funcoesTeclado();
	});
}

function loadCSS(url) {
    var lnk = document.createElement('link');
    lnk.setAttribute('type', "text/css" );
    lnk.setAttribute('rel', "stylesheet" );
    lnk.setAttribute('href', url );
    document.getElementsByTagName("head").item(0).appendChild(lnk);
    
}

function bloqueiaTelaConteudo() {
		
	loadCSS(nomeAPP +"/skin/principal.css"); 
	
	var url = nomeAPP +"/paginas/include/ajudaLogin.jsp";	 	
	$.get(url, function(data) {	
		
		$("#bloqueiodetelaconteudo").html(data);
		
		$('#bloqueiodetela').show();
		$('#bloqueiodetelaconteudo').show();
		centralizarDiv($("#bloqueiodetelaconteudo"));
	});
	
	
	
}
function desbloqueiaTela() {
	$('#bloqueiodetela').hide();
	$('#bloqueiodetelaconteudo').hide();
	$('#bloqueiodetelaaviso').hide();
}
function carregaErro() {
	var erro = $("#mensagemAlertaLogin").html();
	if (erro.length > 0) {
		exibeMensagemAlerta();
		mensagemAlerta();
	}
}


function mensagemAlerta() {
    var y_fixo = -30;
    $("#tudo").scroll(function() {
        $("#mensagemAlertaLogin").animate( {
            top : y_fixo + $("#tudo").scrollTop() + "px"
        }, {
            duration : 500,
            queue : false
        })
    });
    $("#mensagemAlertaLogin").animate( {
        top : y_fixo + $("#tudo").scrollTop() + "px"
    }, {
        duration : 500,
        queue : false
    })
}

function exibeMensagemAlerta() {
	$("#mensagemAlertaLogin").fadeIn('1000');
}
function fechaMensagemAlerta() {
	$("#mensagemAlertaLogin").fadeOut('1000');
}
function ajustaFonte() {
	if (screen.width >= 1024) {
		$("#conteudoprincipal").css("font-size", "11px");
		try {
			vetFonte[0] = "11px";
			vetFonte[1] = "12px";
			vetFonte[2] = "14px";
			vetFonte[3] = "16px";
			vetFonte[4] = "18px"
		} catch (e) {
		}
	} else {
		$("#conteudoprincipal").css("font-size", "10px");
		try {
			vetFonte[0] = "10px";
			vetFonte[1] = "11px";
			vetFonte[2] = "12px";
			vetFonte[3] = "14px";
			vetFonte[4] = "16px"
		} catch (e) {
		}
	}
}
function centralizarDiv(div) {
	div.css('top', $(window).height() / 2 - div.height() / 2);
	div.css('left', $(window).width() / 2 - div.width() / 2);
}

