﻿function collapseMenu(s) {
	var td = s;
	var d = td.getElementsByTagName("div").item(0);

	td.className = "menuNormalSup"

	if (d != null)
		d.className = "menuNormalSup";
}

function expandMenu(s) {
	var td = s;
	var d = td.getElementsByTagName("div").item(0);

	td.className = "menuNormalSup";

	if (d != null)
		d.className = "menuHover";
}

function getQuerystring(key, default_)
{
	if (default_ == null) default_ = "";
	key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
	var qs = regex.exec(window.location.href);
	if (qs == null)
		return default_;
	else
		return qs[1];
}

function TecladoVirtual_BloqueioAoDigitar()
{
	alert('Use o teclado virtual ao lado para digitar sua senha');
	return false;
}

function TecladoVirtual_Limpar(campo, hidden)
{
	//$("input[id$='" + hidden + "']").attr({ value: '' });
	//$('.teclado_campoDigitacao').attr({ value: '' });

	$("input[id$='" + hidden + "']").attr({ value: '' });
	$("#" + campo + "").attr({ value: '' });
}

function TecladoVirtual_CliqueBotao(campo, hidden, hash, areaTeclado)
{
	var txt = $get(campo);
	var area = $get(areaTeclado);
	if ($(txt).attr('value').length < 6)
	{
		var values = $(txt).attr('value') + '0';
		$(txt).attr({ value: values });
		
		if($(txt).attr('value').length > 0)
		{
			var valueHidden = $("input[id$='" + hidden + "']").attr('value');
			valueHidden += '[NOVO_HASH]' + hash;
			
			$("input[id$='" + hidden + "']").attr({ value: valueHidden }); 
		}
		else
			$("input[id$='" + hidden + "']").attr({ value: hash }); 

		$(area).css({ visibility: 'hidden' });
		setTimeout('$("#' + area.id  + '").css({ visibility: \'visible\' });', 500);
	}
}

function TecladoVirtual_AplicarEventos(fieldID, hiddenField)
{
	$(".teclado_imgTeclado").attr({ onclick: '' });
	$(".teclado_imgTeclado").unbind();
	$('.teclado_imgTeclado').each(function()
	{
		var hash = $(this).attr('numberHash');
		$(this).click(function()
		{
			TecladoVirtual_CliqueBotao(fieldID, hiddenField, hash, $('.tecladoVirtualArea').attr('id'));
			return false;
		});
	});

	$(".botaoLimparTecladoVirtual").attr({ onclick: '' });
	$('.botaoLimparTecladoVirtual').unbind();
	$('.botaoLimparTecladoVirtual').click(function()
	{
		TecladoVirtual_Limpar(fieldID, hiddenField);
		return false;
	});
}

function mostraPopUpOver(nome) {
	var estado = document.getElementById(nome).style.display;

	document.getElementById(nome).style.display = "block";
}

function mostraPopUpOut(nome) {
	var estado = document.getElementById(nome).style.display;

	document.getElementById(nome).style.display = "none";
}

function ApenasNumeros(e) {

    navegador = /msie/i.test(navigator.userAgent);

    if (navegador)
        var tecla = event.keyCode;
    else var tecla = e.which;

    if (tecla > 47 && tecla < 58) // numeros de 0 a 9
        return true;
    else {
        if (tecla != 8) // backspace
            return false;
        else
            return true;
    }
}


//////////////////////////////////////////////////////
/**********Valida CPF*************/
function ValidarCPF(cpf)
{
	var i;
	var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
	if (!filtro.test(cpf))
	{
		return false;
	}

	cpf = remove(cpf, ".");
	cpf = remove(cpf, "-");

	if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
	  cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
	  cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
	  cpf == "88888888888" || cpf == "99999999999")
	{
		return false;
	}

	soma = 0;
	for (i = 0; i < 9; i++)
		soma += parseInt(cpf.charAt(i)) * (10 - i);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(cpf.charAt(9)))
	{
		return false;
	}
	soma = 0;
	for (i = 0; i < 10; i++)
		soma += parseInt(cpf.charAt(i)) * (11 - i);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(cpf.charAt(10)))
	{
		return false;
	}
	return true;
}

function remove(str, sub)
{
	i = str.indexOf(sub);
	r = "";
	if (i == -1) return str;
	r += str.substring(0, i) + remove(str.substring(i + sub.length), sub);
	return r;
}