function valida_login() {
    Form = document.admin;

    if (Form.usuario.value.length == 0) {
        alert("Por favor, informe o usuário !");
        Form.usuario.focus();
        return false;
    }

    if (Form.senha.value.length == 0) {
        alert("Por favor, informe a senha !");
        Form.senha.focus();
        return false;
    }

    return true;
}

function clickCategory(CatIDStr){
	
	var txtObj = document.all("t_" + CatIDStr);
	var imgObj = document.all("i_" + CatIDStr);

	if(txtObj.style.display == 'none'){
		txtObj.style.display = '';
		imgObj.src = '<%=sDir%>images/node_minus.gif';
	}else{
		txtObj.style.display = 'none';
		imgObj.src = '<%=sDir%>images/node_plus.gif';
	}
}

function F_Edit(pPagina, pId, pNivel, pNivelPai){
	
	oForm = eval('document.frm_cadastro');
	
	oForm.action					= pPagina;
	oForm.func.value				= '1';
	oForm.id.value					= pId;
	oForm.id_nivel.value			= pNivel;
	if(pNivelPai != ''){
		oForm.id_nivel_pai.value	= pNivelPai;
	}
	
	oForm.submit();
	
}

function F_Novo(pPagina, pId, pNivel){
	
	oForm = eval('document.frm_cadastro');
	
	oForm.action			= pPagina;
	oForm.func.value		= '1';
	oForm.id.value			= pId;
	oForm.id_nivel.value	= pNivel;
	
	oForm.submit();
	
}

function F_Back(pPagina, pNivel){

	oForm = eval('document.frm_cadastro');
	
	oForm.action				= pPagina;
	oForm.func.value			= '0';
	if(pNivel != ''){
		oForm.id_nivel.value	= pNivel;
	}
	oForm.submit();
}

function F_BackUpload(pPagina, pNivel){

	oForm = eval('document.frm_idioma');
	
	oForm.action				= pPagina;
	oForm.func.value			= '0';
	if(pNivel != ''){
		oForm.id_nivel.value	= pNivel;
	}
	oForm.submit();
}

function F_Menu(pPagina, pId, pNivel){

	oForm = eval('document.frm_menu');
	
	oForm.action			= pPagina;
	oForm.cd_pagina.value	= pId;
	oForm.id_nivel.value	= pNivel;

	oForm.submit();
}

// Função para verificar se o campo do formulário está vazio
function isEmpty(s){
	
	return ((s == null) || (s.length == 0));
}

// Função para verificar se o campo do formulário possui valor inteiro válido
function isNum(entra){
	
	var str = entra;
	
	for(var i=0;i<str.length;i++){
		var ch = str.substring(i, i + 1);      
		if((ch < "0" || "9" < ch)&&(ch != ".")){
			return false;
		}
	}
	return true;
}

// Função para verificar se o campo do formulário possui valor ponto flutuante válido
function isCurr(entra){
	
	var str = replace(entra,',','.');
	
	for(var i=0;i<str.length;i++){
		var ch = str.substring(i, i + 1);      

		if(ch != "."){
			if(ch < "0" || "9" < ch ){
				return false;         
			}
		}
	}
	
	return true;   
}

//
function checkField(sStr, sChars){
	
	var j=0;
	var bRetVal = true;
	
	while(j < sChars.length){
		if(sStr.indexOf( sChars.substr(j,1) ) >= 0){
	 		bRetVal = false;
	 		break;
		}
		j++
	}
 
	return bRetVal;
}

// Funções para validação dos campos DATE
nome_mes = new Array();
nome_mes[1]="Jan";
nome_mes[2]="Feb";
nome_mes[3]="Mar";
nome_mes[4]="Apr";
nome_mes[5]="May";
nome_mes[6]="Jun";
nome_mes[7]="Jul";
nome_mes[8]="Aug";
nome_mes[9]="Sep";
nome_mes[10]="Oct";
nome_mes[11]="Nov";
nome_mes[12]="Dec";

function checkDate(campo){
	var data = campo.value;

 	if(!checkField( data, "<|>@#$%&*!+- ()?[]{}~^´`,.\"_=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZáéíóúãõàüäëöïñçÁÉÍÓÚÃÕÀÜÄËÖÏÑÇ\\" )){
		return false;
	}
	
	 var myDayStr = data.substr(0,2);
	 var myMonthStr = nome_mes[Math.abs(data.substr(3,2))];
	 var myYearStr = data.substr(6,4);
	 var myDateStr = myDayStr + " " + myMonthStr + " " + myYearStr;
	 var myDate = new Date( myDateStr );
	 var myDate_string = myDate.toUTCString();
	 var myDate_array = myDate_string.split(" ");

	// Array myDate_array:
	// Indices:
	// 0 - Dia da semana
	// 1 - Dia do mes (numero)
	// 2 - Nome do mes (Jan, Fev, etc)
	// 3 - Ano
	// 4 - Hora
	// 5 - Constante "UTC"

	if((myDate_array[2] != myMonthStr ) || ( Math.abs(data.substr(3,2) ) < 1 || Math.abs(data.substr(3,2) ) > 12)){
		return false;
 	}else{
 		if((myDayStr == "") || (myMonthStr == "") || (myYearStr == "")){
			return false;
		}else{
			return true;
		}
 	}
}

function completa_data_cadastro(pName){
	
	var bInput;
	var b, n;
	
	b = new Date();
	bInput = eval('document.frm_cadastro.'+pName);
	
	if(event.keyCode == 32){		
		if(b.getDate() < 10){
			bInput.value = '0' + b.getDate() + '/';
		}else{
			bInput.value = b.getDate() + '/';
		}
		
		if (b.getMonth() < 10){
			bInput.value = bInput.value + '0' + (b.getMonth() + 1) + '/';
		}else{
			bInput.value = bInput.value + (b.getMonth() + 1) + '/'
		}
	}
}
