/**
 * interface.js
 * Controla alguns elementos da página principal/interna.
 * @author Glauco Morais
 * @version 1.0.2
 */

/**
 * Valida o formulário de contato e ouvidoria
 * @param {Object} form O elemento FORM a ser validado.
 */
function validaContato( form )
{
	with( form )
	{
		for( i = 0; i < elements.length; i++ )
		{
			switch( elements[i].name )
			{
				case "nome":
					if( elements[i].value == "" )
					{
						alert( "Por favor, escreva o seu nome" );
						return false;
					}
					break;
				case "email":
					if( elements[i].value == "" )
					{
						alert( "Por favor, escreva o seu e-mail" );
						return false;
					}
					break;
				case "mensagem":
					if( elements[i].value == "" )
					{
						alert( "Por favor, escreva uma mensagem" );
						return false;
					}
					break;
			}
		}
	}
	return true;
}

//Atrela uma função ao evento window.onLoad
adicionarEvento( window, "onload", function(){
	//Transforma o elemento form_login em uma caixa de diálogo
	$('#form_login').dialog(
		{
			autoOpen:false,
			modal: true,
			draggable: false,
			resizable: false,
			title: "Área Restrita",
			width: 320,
			height: 175
		}
	);
	
	//Atrela uma função ao evento onclick do link de id "acesso_painel"	
	adicionarEvento( document.getElementById( "acesso_painel" ), "onclick", function()
	{
		$('#form_login').dialog("open");
	});
	
	//Atrela uma função ao evento onclick do botão de id "lg_cancelar"
	adicionarEvento( document.getElementById( "lg_cancelar" ), "onclick", function()
	{
		$('#form_login').dialog("close");
	});
	
	var oFormRH = document.getElementById( "form_rh" );
	if( existe( oFormRH ) )
	{
		var aAtributosRH = Array(
			{tipo: TEXTO, obrigatorio: true},	//Nome
			{tipo: EMAIL, obrigatorio: true},	//Email
			{tipo: TEXTO, obrigatorio: false},	//Messenger
			{tipo: TEXTO, obrigatorio: false},	//Skype
			{tipo: INTEIRO, obrigatorio: true},	//DDD Residencial
			{tipo: INTEIRO, obrigatorio: true},	//Telefone Residencial
			{tipo: INTEIRO, obrigatorio: false},//Celular
			{tipo: INTEIRO, obrigatorio: false},//DDD Comercial
			{tipo: INTEIRO, obrigatorio: false},//Telefone Comercial
			{tipo: INTEIRO, obrigatorio: false},//Ramal
			{tipo: TEXTO, obrigatorio: true},	//Endereço
			{tipo: TEXTO, obrigatorio: false},	//Bairro
			{tipo: TEXTO, obrigatorio: true},	//Cidade
			{tipo: SELECAO, obrigatorio: true},	//Estado
			{tipo: INTEIRO, obrigatorio: true},	//CEP
			{tipo: SELECAO, obrigatorio: true},	//Zona
			{tipo: DATA, obrigatorio: false},	//Data de Nascimento
			{tipo: TEXTO, obrigatorio: false},	//Estado Civil
			{tipo: SELECAO, obrigatorio: false},//Sexo
			{tipo: CPF, obrigatorio: true},		//CPF
			{tipo: INTEIRO, obrigatorio: false},//RG
			{tipo: TEXTO, obrigatorio: false},	//Órgão Emissor
			
			/* Formação acadêmica */
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			
			/* Idiomas */
			{tipo: SELECAO, obrigatorio: false},
			{tipo: SELECAO, obrigatorio: false},
			{tipo: SELECAO, obrigatorio: false},
			{tipo: SELECAO, obrigatorio: false},
			
			/* Informática */
			{tipo: SELECAO, obrigatorio: false},
			{tipo: SELECAO, obrigatorio: false},
			{tipo: SELECAO, obrigatorio: false},
			{tipo: SELECAO, obrigatorio: false},
			
			/* Experiência Profissional */
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			{tipo: MONETARIO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			{tipo: MONETARIO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			
			{tipo: SELECAO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
						
			/* */
			{tipo: SELECAO, obrigatorio: false},
			{tipo: SELECAO, obrigatorio: false},
			{tipo: SELECAO, obrigatorio: false},
			{tipo: SELECAO, obrigatorio: false},
			
			/* */
			{tipo: SELECAO, obrigatorio: false},
			
			/* */
			{tipo: SELECAO, obrigatorio: false},
			
			/* */
			{tipo: SELECAO, obrigatorio: false},
			{tipo: TEXTO, obrigatorio: false},
			
			/* */
			{tipo: SELECAO, obrigatorio: false},
			
			/* */
			{tipo: TEXTO, obrigatorio: false},
			
			/* */
			{tipo: TEXTO, obrigatorio: false},
			
			/* */
			{tipo: TEXTO, obrigatorio: false}
						
		);
		oFormRH = new Formulario( oFormRH, aAtributosRH, INSERT );
		var oErros = document.getElementById( "erros" );
		var oEnviarRH = document.getElementById( "enviar_rh" );
		if( existe( oEnviarRH ) )
		{
			oEnviarRH.onclick = function()
			{
				oErros.innerHTML = "Validando...";
				if( oFormRH.validar() )
				{
					oErros.innerHTML = "Enviando...";
					oFormRH.enviar( "form_rh.php", "",
						function( resposta )
						{
							if( parseInt( resposta.texto ) == 3200 )
								alert( "Currículo Enviado!" );
							oErros.innerHTML = "Currículo Enviado!";
						}
					);
				}
				else
				{
					alert( "Verifique os campos destacados" );
					oErros.innerHTML = "Verfique os campos destacados.";
				}	
			}
		}
	}
});