function index(theForm)
{
    if (theForm.usuario.value == '' || theForm.senha.value == '')
    {
        alert('Acesso restrito!');
        theForm.usuario.value = '';
        theForm.senha.value = '';
        theForm.usuario.focus();
        return false;
    }
    if (theForm.usuario.value.indexOf(' ') != -1 || theForm.senha.value.indexOf(' ') != -1 || theForm.usuario.value.indexOf('\"') != -1 || theForm.senha.value.indexOf('\"') != -1 || theForm.usuario.value.indexOf('\'') != -1 || theForm.senha.value.indexOf('\'') != -1)
    {
        alert('Acesso restrito!');
        theForm.usuario.value = '';
        theForm.senha.value = '';
        theForm.usuario.focus();
        return false;
    }
    return true;
}
function minusculas(theElement)
{
	theElement.value = theElement.value.toLowerCase();
}
function mascaranumero(keypress)
{
	if (keypress > 47 && keypress < 58)
		return true;
	return false;
}
function mascaravalor(fld, milSep, decSep, e)
{
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;
	key = String.fromCharCode(whichCode);
	if (strCheck.indexOf(key) == -1) return false;
	len = fld.value.length;
	if (len < 14)
	{
		for(i = 0; i < len; i++)
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
		aux = '';
		for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
		aux += key;
		len = aux.length;
		if (len == 0) fld.value = '';
		if (len == 1) fld.value = '0'+ decSep + '0' + aux;
		if (len == 2) fld.value = '0'+ decSep + aux;
		if (len > 2)
		{
			aux2 = '';
			for (j = 0, i = len - 3; i >= 0; i--)
			{
				if (j == 3)
				{
					aux2 += milSep;
					j = 0;
				}
				aux2 += aux.charAt(i);
				j++;
			}
			fld.value = '';
			len2 = aux2.length;
			for (i = len2 - 1; i >= 0; i--)
				fld.value += aux2.charAt(i);
			fld.value += decSep + aux.substr(len - 2, len);
		}
		return false;
	}
	return false;
}
function mascaratelefone(keypress,theElement)
{
	campo = eval(theElement);
	separador1 = '(';
	separador2 = ')';
	separador3 = '-';
	conjunto1 = 0;
	conjunto2 = 3;
	conjunto3 = 8;
	if (keypress > 47 && keypress < 58)
	{
		if (campo.value.charAt(0) != '(')
			campo.value = '(' + campo.value
		if (campo.value.length == conjunto1)
			campo.value = campo.value + separador1;
		if (campo.value.length == conjunto2)
			campo.value = campo.value + separador2;
		if (campo.value.length == conjunto3)
			campo.value = campo.value + separador3;
		return true;
	}
	else
		return false;
}
function mascaradata(keypress,theElement)
{
	campo = eval(theElement);
	separador = '/';
	conjunto1 = 2;
	conjunto2 = 5;
	if (keypress > 47 && keypress < 58)
	{
		if (campo.value.length == conjunto1)
			campo.value = campo.value + separador;
		if (campo.value.length == conjunto2)
			campo.value = campo.value + separador;
		return true;
	}
	else
		return false;
}
function marcadesmarcatodos(theElement)
{
	var theForm = theElement.form;
	for (i = 0; i < theForm.length; i++)
	{
		if (theForm[i].type == 'checkbox' && !theForm[i].disabled & theForm[i].name != 'todos')
			theForm[i].checked = theElement.checked;
	}
}
function confirmaexclusao(theTextConfirm,theTextError,theForm)
{
    var encontrou = false;
	for (i = 0; i < theForm.length; i++)
	{
		if (theForm[i].type == 'checkbox' && !theForm[i].disabled & theForm[i].name != 'todos' && theForm[i].checked)
			encontrou = true;
	}
	if (encontrou)
	{
		if (confirm(theTextConfirm))
		    theForm.submit();
	}
	else
		alert(theTextError);
}
function mostraescondepanel(theField,panelID,valuenone)
{
	panel = eval('document.all.' + panelID + '.style;');
	if (theField.options[theField.selectedIndex].value == valuenone)
		panel.display = 'none';
	else
		panel.display = '';
}
function verificaemail(theElement)
{
	if (theElement.value == '')
	{
		alert('Digite o e-mail!');
		theElement.focus();
		return false;
	}
	else
	{
		prim = theElement.value.indexOf('@');
		if (prim < 2)
		{
			alert('O e-mail informado não parece estar correto!');
			theElement.focus();
			return false;
		}
		if (theElement.value.indexOf('@',prim + 1) != -1)
		{
			alert('O e-mail informado não parece estar correto!');
			theElement.focus();
			return false;
		}
		if (theElement.value.indexOf('.') < 1)
		{
			alert('O e-mail informado não parece estar correto!');
			theElement.focus();
			return false;
		}
		if (theElement.value.indexOf(' ') != -1)
		{
			alert('O e-mail informado não parece estar correto!');
			theElement.focus();
			return false;
		}
		if (theElement.value.indexOf(';') != -1)
		{
			alert('O e-mail informado não parece estar correto!');
			theElement.focus();
			return false;
		}
		if (theElement.value.indexOf('.@') != -1)
		{
			alert('O e-mail informado não parece estar correto!');
			theElement.focus();
			return false;
		}
		if (theElement.value.indexOf('@.') != -1)
		{
			alert('O e-mail informado não parece estar correto!');
			theElement.focus();
			return false;
		}
		if (theElement.value.indexOf('.com.br.') != -1)
		{
			alert('O e-mail informado não parece estar correto!');
			theElement.focus();
			return false;
		}
		if (theElement.value.indexOf('/') != -1)
		{
			alert('O e-mail informado não parece estar correto!');
			theElement.focus();
			return false;
		}
		if (theElement.value.indexOf('[') != -1)
		{
			alert('O e-mail informado não parece estar correto!');
			theElement.focus();
			return false;
		}
		if (theElement.value.indexOf(']') != -1)
		{
			alert('O e-mail informado não parece estar correto!');
			theElement.focus();
			return false;
		}
		if (theElement.value.indexOf('(') != -1)
		{
			alert('O e-mail informado não parece estar correto!');
			theElement.focus();
			return false;
		}
		if (theElement.value.indexOf(')') != -1)
		{
			alert('O e-mail informado não parece estar correto!');
			theElement.focus();
			return false;
		}
		if (theElement.value.indexOf('"') != -1)
		{
			alert('O e-mail informado não parece estar correto!');
			theElement.focus();
			return false;
		}
		if (theElement.value.indexOf('\'') != -1)
		{
			alert('O e-mail informado não parece estar correto!');
			theElement.focus();
			return false;
		}
		if (theElement.value.indexOf('..') != -1)
		{
			alert('O e-mail informado não parece estar correto!');
			theElement.focus();
			return false;
		}
	}
	return true;
}
function verificadata(theElement)
{
	var dia = parseInt(theElement.value.substring(0,2),10);
	var mes = parseInt(theElement.value.substring(3,5),10);
	var ano = parseInt(theElement.value.substring(6,10),10);
	data = new Date();
	if (dia <= 31 && mes <= 12 && ano >= 1900)
	{
		if (theElement.value.substring(0,1) == '0' && theElement.value.substring(1,2) != '0' || theElement.value.substring(0,1) != '0')
		{
			if (theElement.value.substring(2,3) == '/')
			{
				if (theElement.value.substring(3,4) == '0' && theElement.value.substring(4,5) != '0' || theElement.value.substring(3,4) != '0')
				{
					if (theElement.value.substring(5,6) == '/')
					{
						if (theElement.value.substring(6,7) == '0' || theElement.value.substring(6,7) == '' && theElement.value.substring(7,8) != '0')
						{
							alert('Verifique a data!');
							theElement.focus();
							return false;
						}
						if (mes == 2)
						{
							if ((dia > 0) && (dia <= 29))
							{
								if (dia == 29)
								{
									if ((ano % 4) != 0)
									{
										alert('Verifique a data!');
										theElement.focus();
										return false;
									}
								}
							}
							else
							{
								alert('Verifique a data!');
								theElement.focus();
								return false; 
							}
						}
						if ((mes == 4) || (mes == 6) || (mes == 9) || (mes == 11))
						{
							if (!((dia > 0 ) && (dia <= 30)))
							{
								alert('Verifique a data!');
								theElement.focus();
								return false;
							}
						}
						if ((mes == 1) || (mes == 3) || (mes == 5) || (mes ==7) || (mes == 8) || (mes == 10) || (mes == 12))
						{
							if (!((dia > 0) && (dia <= 31)))
							{
								alert('Verifique a data!');
								theElement.focus();
								return false;
							}
						}
					}
					else
					{
						alert('Verifique a data!');
						theElement.focus();
						return false;
					}
				}
				else
				{
					alert('Verifique a data!');
					theElement.focus();
					return false;
				}
			}
			else
			{
				alert('Verifique a data!');
				theElement.focus();
				return false;
			}
		}
		else
		{
			alert('Verifique a data!');
			theElement.focus();
			return false;
		}
	}
	else
	{
		alert('Verifique a data!');
		theElement.focus();
		return false;
	}
	return true;
}
function filtradatas(theForm)
{
	if (theForm.datade.value != '')
		if (!verificadata(theForm.datade))
			return false;
	if (theForm.dataate.value != '')
		if (!verificadata(theForm.dataate))
			return false;
	return true;
}
function dados(theForm)
{
	if (theForm.telefone.value == '')
	{
		alert('Digite o telefone!');
		theForm.telefone.focus();
		return false;
	}
	if (theForm.telefone.value.length != 13)
	{
		alert('Verifique o telefone!');
		theForm.telefone.focus();
		return false;
	}
	if (!verificaemail(theForm.email))
	    return false;
	if (theForm.usuario.value == '')
	{
		alert('Digite o login!');
		theForm.usuario.focus();
		return false;
	}
	if (theForm.usuario.value.length < 5)
	{
		alert('Escolha um login com pelo menos 5 caracteres!');
		theForm.usuario.value = '';
		theForm.usuario.focus();
		return false;
	}
	if (theForm.usuario.value.indexOf(' ') != -1)
	{
		alert('O login não permite a inclusão de espaços!');
		theForm.usuario.value = '';
		theForm.usuario.focus();
		return false;
	}
	if (theForm.usuario.value.indexOf('\"') != -1)
	{
		alert('O login não permite a inclusão de aspas!');
		theForm.usuario.value = '';
		theForm.usuario.focus();
		return false;
	}
	if (theForm.usuario.value.indexOf('\'') != -1)
	{
		alert('O login não permite a inclusão de aspas!');
		theForm.usuario.value = '';
		theForm.usuario.focus();
		return false;
	}
	if (theForm.senha1.value == '')
	{
		alert('Digite a senha!');
		theForm.senha1.focus();
		return false;
	}
	if (theForm.senha1.value.length < 5)
	{
		alert('Escolha uma senha com pelo menos 5 caracteres!');
		theForm.senha1.value = '';
		theForm.senha1.focus();
		return false;
	}
	if (theForm.senha1.value.indexOf(' ') != -1)
	{
		alert('A senha não permite a inclusão de espaços!');
		theForm.senha1.value = '';
		theForm.senha1.focus();
		return false;
	}
	if (theForm.senha1.value.indexOf('\"') != -1)
	{
		alert('A senha não permite a inclusão de aspas!');
		theForm.senha1.value = '';
		theForm.senha1.focus();
		return false;
	}
	if (theForm.senha1.value.indexOf('\'') != -1)
	{
		alert('A senha não permite a inclusão de aspas!');
		theForm.senha1.value = '';
		theForm.senha1.focus();
		return false;
	}
	if (theForm.senha2.value == '')
	{
		alert('Confirme a senha!');
		theForm.senha2.focus();
		return false;
	}
	if (theForm.senha1.value != theForm.senha2.value)
	{
		alert('Verifique a senha!');
		theForm.senha1.value = '';
		theForm.senha2.value = '';
		theForm.senha1.focus();
		return false;
	}
	return true;
}
function usuarios(theForm)
{
    if (theForm.nome.value == '')
	{
		alert('Digite o nome!');
		theForm.nome.focus();
		return false;
	}
	if (!dados(theForm))
		return false;
    return true;
}
function usuariosper(theForm)
{
	if (theForm.perfil_id.selectedIndex == -1)
	{
		alert("Selecione o perfil!");
		theForm.perfil_id.focus();
		return false;
	}
	return true;
}
function usuariosmod(theForm)
{
	return pesquisa(theForm);
}
function pesquisa(theForm)
{
	if (theForm.modelo_id.selectedIndex == -1)
	{
		alert("Selecione o modelo!");
		theForm.modelo_id.focus();
		return false;
	}
	return true;
}
function modelos(theForm)
{
	if (theForm.modelo.value == '')
	{
		alert('Digite o modelo!');
		theForm.modelo.focus();
		return false;
	}
	return true;
}
function modeloscam(theForm)
{
	if (theForm.campo.value == '')
	{
		alert('Digite o campo!');
		theForm.campo.focus();
		return false;
	}
	if (theForm.tipodado_id.selectedIndex == -1)
	{
		alert("Selecione o tipo de dado!");
		theForm.tipodado_id.focus();
		return false;
	}
	if (theForm.condicao.selectedIndex == -1)
	{
		alert("Selecione a condição!");
		theForm.condicao.focus();
		return false;
	}
	if (theForm.tipodado_id.value != '1' && theForm.tipodado_id.value != '2' && theForm.tipodado_id.value != '4' && theForm.condicao.value != '0' && theForm.condicao.value != '2')
	{
		alert("Apenas os tipos de dado DATA, NÚMERO e VALOR podem ter PESQUISA POR INTERVALO!");
		theForm.condicao.focus();
		return false;
	}
	return true;
}
function tipos(theForm)
{
	if (theForm.tipodado.value == '')
	{
		alert('Digite o tipo de dado!');
		theForm.tipodado.focus();
		return false;
	}
	if (theForm.primitivo.selectedIndex == -1)
	{
		alert("Selecione o tipo de dado primitivo!");
		theForm.primitivo.focus();
		return false;
	}
	if (theForm.primitivo.selectedIndex == 0)
	{
		if (theForm.tipodado_id_enum.selectedIndex == -1)
		{
			alert("Selecione o tipo de dado da lista!");
			theForm.tipodado_id_enum.focus();
			return false;
		}
	}
	return true;
}
function tiposcam(theForm)
{
	if (theForm.campoarray.value == '')
	{
		alert('Digite o campo!');
		theForm.campoarray.focus();
		return false;
	}
	if (theForm.tipodado_id.selectedIndex == -1)
	{
		alert("Selecione o tipo de dado!");
		theForm.tipodado_id.focus();
		return false;
	}
	return true;
}
function tiposite(theForm)
{
	if (theForm.conteudo.value == '')
	{
		alert('Digite o conteúdo!');
		theForm.conteudo.focus();
		return false;
	}
	return true;
}
function documentos(theForm)
{
	if (theForm.controleautomatico.value == '0')
	{
		if (theForm.controle.value == '')
		{
			alert('Digite o código de controle!');
			theForm.controle.focus();
			return false;
		}
	}
	if (theForm.modelo_id.selectedIndex == -1)
	{
		alert('Selecione o modelo!');
		theForm.modelo_id.focus();
		return false;
	}
	if (theForm.fisicoedigital.value == '1')
	{
		if (theForm.imagem.selectedIndex == -1)
		{
			alert('Selecione o tipo de arquivo!');
			theForm.imagem.focus();
			return false;
		}
	}
	if (theForm.imagem.value == '1')
	{
		if (theForm.localizacao.value == '')
		{
			alert('Digite a localização física do arquivo!');
			theForm.localizacao.focus();
			return false;
		}
	}
	if (theForm.computador_id.selectedIndex == -1)
	{
		alert('Selecione o servidor!');
		theForm.computador_id.focus();
		return false;
	}
	return true;
}
function documentosind(theForm)
{
	validartipo = parseInt(theForm.validartipo.value);
	switch (validartipo)
	{
		case 1:
			if (theForm.campo.value == '')
			{
				alert('Verifique a indexação!');
				theForm.campo.focus();
				return false;
			}
			else
				if (!verificadata(theForm.campo))
					return false;
			break;
		case 2:
			if (theForm.campo.value == '')
			{
				alert('Verifique a indexação!');
				theForm.campo.focus();
				return false;
			}
			break;
		case 3:
			if (theForm.campo.value == '')
			{
				alert('Verifique a indexação!');
				theForm.campo.focus();
				return false;
			}
			break;
		case 4:
			if (theForm.campo.value == '')
			{
				alert('Verifique a indexação!');
				theForm.campo.focus();
				return false;
			}
			break;
		case 5:
			if (theForm.campo.selectedIndex == -1)
			{
				alert('Verifique a indexação!');
				theForm.campo.focus();
				return false;
			}
			break;
		default:
			validartipoarray = parseInt(theForm.validartipoarray.value);
			switch (validartipoarray)
			{
				case 1:
					if (theForm.campo1.value == '')
					{
						alert('Verifique a indexação!');
						theForm.campo1.focus();
						return false;
					}
					else
						if (!verificadata(theForm.campo1))
							return false;
					break;
				case 2:
					if (theForm.campo1.value == '')
					{
						alert('Verifique a indexação!');
						theForm.campo1.focus();
						return false;
					}
					break;
				case 3:
					if (theForm.campo1.value == '')
					{
						alert('Verifique a indexação!');
						theForm.campo1.focus();
						return false;
					}
					break;
				case 4:
					if (theForm.campo1.value == '')
					{
						alert('Verifique a indexação!');
						theForm.campo1.focus();
						return false;
					}
					break;
				default:
					if (theForm.campo1.selectedIndex == -1)
					{
						alert('Verifique a indexação!');
						theForm.campo1.focus();
						return false;
					}
					break;
			}
			break;
	}
	return true;
}
