/* home / programacao :hover */

function destaques_focused(liobj)
{
  liobj.find('img').hide();
  liobj.find('span.description').show();
  liobj.find('a').addClass('focused');
  liobj.find('img').addClass('focused');
  liobj.find('span.dest_box').addClass('dest_box-focused');
  liobj.find('strong.summary').addClass('summary-focused');
  liobj.find('span.resume').addClass('resume-focused');
  liobj.find('span.dtstart').addClass('dtstart-focused');
  liobj.find('span.location').addClass('location-focused');
  liobj.find('span.description').addClass('description-focused');
}

function destaques_unfocused(liobj)
{
  liobj.find('img').show();
  liobj.find('span.description').hide();
  liobj.find('a').removeClass('focused');
  liobj.find('img').removeClass('focused');
  liobj.find('span.dest_box').removeClass('dest_box-focused');
  liobj.find('strong.summary').removeClass('summary-focused');
  liobj.find('span.resume').removeClass('resume-focused');
  liobj.find('span.dtstart').removeClass('dtstart-focused');
  liobj.find('span.location').removeClass('location-focused');
  liobj.find('span.description').removeClass('description-focused');
}

$(document).ready(function()
{
    $("#destaques").find('li').each(function()
    {
        $(this).mouseenter(function()
        {
          destaques_focused($(this));
        });
        $(this).mouseleave(function()
        {
          destaques_unfocused($(this));
        });
    });
});

window.onbeforeunload = function ()
{
    $("#destaques").find('li').each(function()
    {
        destaques_unfocused($(this));
    });
}


/** old fashioned functions **/

function mark_program_generic_attribute_for_destroy(element){
	$(element).next('.should_destroy').value = 1;
	$(element).up('.attribute_item').hide();
}

function mark_program_generic_attribute_for_destroy_now(element){
	$(element).up('.attribute_item').remove();
}

function mailcheck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}
	if (str.indexOf(at,(lat+1))!=-1){
    	return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	}
	if (str.indexOf(dot,(lat+2))==-1){
		return false
	}
	if (str.indexOf(" ")!=-1){
		return false
	}
	return true					
}


function validacpf(s){
 
	var i;
	 	 
	var c = s.substr(0,9);
	 
	var dv = s.substr(9,2);
	 
	var d1 = 0;
	 
	for (i = 0; i < 9; i++)
	 
	{
	 
	d1 += c.charAt(i)*(10-i);
	 
	}
	 
	if (d1 == 0){
	 
	 
	return false;
	 
	}
	 
	d1 = 11 - (d1 % 11);
	 
	if (d1 > 9) d1 = 0;
	 
	if (dv.charAt(0) != d1)
	 
	{ 
	 
	return false;
	 
	}
	 
	 
	d1 *= 2;
	 
	for (i = 0; i < 9; i++)
	 
	{
	 
	d1 += c.charAt(i)*(11-i);
	 
	}
	 
	d1 = 11 - (d1 % 11);
	 
	if (d1 > 9) d1 = 0;
	 
	if (dv.charAt(1) != d1)	 
	{	 
	return false;	 
	}	 
	return true; 
}

function check_contact_form(){ 
	name = $('#form_nome').val();
	email = $("#form_email").val();
	assunto = $("#form_assunto").val();
	message = $("#form_mensagem").val();
	if(name.length < 2 || name == "+ nome"){
		alert("prencha o campo nome");
		return false;
	}
	if(!mailcheck(email)){
		alert("digite um endereço de email válido");
		return false;
	}
	if(assunto.length < 2 || assunto == "+ assunto"){
		alert("prencha o campo assunto");
		return false;
	}	
	if(message.length < 2 || message == "+ mensagem"){
		alert("prencha o campo mensagem");
		return false;
	}
}

function check_basic_form(){ 
	email = $("#basic_email").val();
	if(!mailcheck(email)){
		alert("digite um endereço de email válido");
		return false;
	}	
}

function check_complete_form(){ 
	value = $("#user_name").val();
	if(value.length < 2){
		alert("digite seu nome");
		return false;
	}
	value = $("#user_endereco_residencial").val();
	if(value.length < 2){
		alert("digite seu endereço - residencial");
		return false;
	}
	value = $("#user_bairro_residencial").val();
	if(value.length < 2){
		alert("digite seu bairro - residencial");
		return false;
	}
	value = $("#user_cidade_residencial").val();
	if(value.length < 2){
		alert("digite sua cidade - residencial");
		return false;
	}
	value = $("#user_uf_residencial").val();
	if(value.length < 2){
		alert("digite seu estado - residencial");
		return false;
	}
	value = $("#user_cep_residencial").val();
	if(value.length < 8){
		alert("digite seu cep - residencial");
		return false;
	}
	value = $("#user_phone_1_number").val();
	if(value.length < 8){
		alert("digite seu telefone 1");
		return false;
	}
	value = $("#user_phone_1_kind").val();
	if(value == ""){
		alert("escolha o tipo de telefone 1");
		return false;
	}
	value = $("#user_phone_2_number").val();
	if(value.length < 8){
		alert("digite seu telefone 2");
		return false;
	}
	value = $("#user_phone_2_kind").val();
	if(value == ""){
		alert("escolha o tipo de telefone 2");
		return false;
	}
	value = $("#user_email").val();
	if(!mailcheck(value)){
		alert("digite um endereço de email válido");
		return false;
	}
	value = $("#user_deseja_receber").val();
	value = $("#user_homepage").val();
	if(value.length < 10){
		alert("digite sua homepage");
		return false;
	}
	value = $("#user_atividade_profissional").val();
	if(value.length < 2){
		alert("digite sua atividade profissional");
		return false;
	}
	value = $("#user_empresa").val();
	if(value.length < 2){
		alert("digite sua empresa");
		return false;
	}
	value = $("#user_endereco_comercial").val();
	if(value.length < 2){
		alert("digite seu endereço - comercial");
		return false;
	}
	value = $("#user_bairro_comercial").val();
	if(value.length < 2){
		alert("digite seu bairro - comercial");
		return false;
	}
	value = $("#user_cidade_comercial").val();
	if(value.length < 2){
		alert("digite sua cidade - comercial");
		return false;
	}
	value = $("#user_uf_comercial").val();
	if(value.length < 2){
		alert("digite seu estado - comercial");
		return false;
	}
	value = $("#user_cep_comercial").val();
	if(value.length < 8){
		alert("digite seu cep - comercial");
		return false;
	}
	value = $("#user_cargo_na_empresa").val();
	if(value.length < 2){
		alert("digite seu cargo na empresa");
		return false;
	}
	value = $("#user_area_atuacao_da_empresa").val();
	if(value.length < 2){
		alert("digite a área de atuação de sua empresa");
		return false;
	}
}



function check_midiateca_form(){ 
	value = $("#medialibrary_user_name").val();
	if(value.length < 2){
		alert("digite seu nome");
		return false;
	}
	value = $("#medialibrary_user_nasc_dia").val();
	if(value < 1 || value > 31){
		alert("digite o dia do seu nascimento");
		return false;
	}
	value = $("#medialibrary_user_nasc_mes").val();
	if(value < 1 || value > 12){
		alert("digite o mês do seu nascimento");
		return false;
	}
	value = $("#medialibrary_user_nasc_ano").val();
	if(value < 1900 || value > 2009){
		alert("digite o ano do seu nascimento");
		return false;
	}
	value = $("#medialibrary_user_sexo").val();
	if(value != "masculino" && value != "feminino"){
		alert("escolha seu sexo");
		return false;
	}
	value = $("#medialibrary_user_cpf").val();
	if(!validacpf(value)){
		alert("CPF inválido - apenas números");
		return false;
	}
	value = $("#medialibrary_user_ddd_fixo").val();
	if(value.length < 2){
		alert("digite o ddd do seu telefone fixo");
		return false;
	}
	value = $("#medialibrary_user_phone_fixo").val();
	if(value.length < 8){
		alert("digite o seu telefone fixo");
		return false;
	}
	value = $("#medialibrary_user_ddd_celular").val();
	if(value.length < 2){
		alert("digite o ddd do seu celular");
		return false;
	}
	value = $("#medialibrary_user_phone_celular").val();
	if(value.length < 8){
		alert("digite o seu celular");
		return false;
	}
	value = $("#medialibrary_user_end_residencial").val();
	if(value.length < 8){
		alert("digite o seu endereço");
		return false;
	}	
	value = $("#medialibrary_user_end_residencial_numero").val();
	if(value.length < 2){
		alert("digite o número do seu endereço");
		return false;
	}
	value = $("#medialibrary_user_end_residencial_bairro").val();
	if(value.length < 2){
		alert("digite seu bairro");
		return false;
	}
	value = $("#medialibrary_user_end_residencial_cidade").val();
	if(value.length < 2){
		alert("digite sua cidade");
		return false;
	}
	value = $("#medialibrary_user_end_residencial_estado").val();
	if(value.length < 2){
		alert("digite seu estado");
		return false;
	}
	value = $("#medialibrary_user_end_residencial_cep").val();
	if(value.length < 8){
		alert("digite seu cep");
		return false;
	}
	value = $("#medialibrary_user_email").val();
	if(!mailcheck(value)){
		alert("digite um endereço de email válido");
		return false;
	}
	value = $("#medialibrary_user_necessidades_especiais").val();
	value = $("#medialibrary_user_cuidados_especiais").val();
	value = $("#medialibrary_user_nacionalidade").val();
	if(value.length < 2){
		alert("digite sua nacionalidade");
		return false;
	}
	value = $("#medialibrary_user_pais").val();
	if(value.length < 2){
		alert("escolha país");
		return false;
	}
	pais = $("#medialibrary_user_pais").val();
	if(pais != "Brasil"){
		value = $("#medialibrary_user_passaporte").val();
		if(value.length < 10){
			alert("Não brasileiros - obrigatório prencher o número do passaporte");
			return false;
		}	
	}	
	value = $("#medialibrary_user_atividades").val();
	if(value.length < 2){
		alert("descreva as atividades que você realiza");
		return false;
	}
	return false;	
}

function check_programacao_form(){
	value = $("#program_user_name").val();
	if(value.length < 2){
		alert("digite seu nome");
		return false;
	}
	value = $("#program_user_nasc_dia").val();
	if(value < 1 || value > 31){
		alert("digite o dia do seu nascimento");
		return false;
	}
	value = $("#program_user_nasc_mes").val();
	if(value < 1 || value > 12){
		alert("digite o mês do seu nascimento");
		return false;
	}
	value = $("#program_user_nasc_ano").val();
	if(value < 1900 || value > 2009){
		alert("digite o ano do seu nascimento");
		return false;
	}
	value = $("#program_user_sexo").val();
	if(value != "masculino" && value != "feminino"){
		alert("escolha seu sexo");
		return false;
	}
	value = $("#program_user_cpf").val();
	if(!validacpf(value)){
		alert("CPF inválido - apenas números");
		return false;
	}
	value = $("#program_user_ddd_fixo").val();
	if(value.length < 2){
		alert("digite o ddd do seu telefone fixo");
		return false;
	}
	value = $("#program_user_phone_fixo").val();
	if(value.length < 8){
		alert("digite o seu telefone fixo");
		return false;
	}
	value = $("#program_user_ddd_celular").val();
	if(value.length < 2){
		alert("digite o ddd do seu celular");
		return false;
	}
	value = $("#program_user_phone_celular").val();
	if(value.length < 8){
		alert("digite o seu celular");
		return false;
	}
	value = $("#program_user_end_residencial").val();
	if(value.length < 8){
		alert("digite o seu endereço");
		return false;
	}	
	value = $("#program_user_end_residencial_numero").val();
	if(value.length < 2){
		alert("digite o número do seu endereço");
		return false;
	}
	value = $("#program_user_end_residencial_bairro").val();
	if(value.length < 2){
		alert("digite seu bairro");
		return false;
	}
	value = $("#program_user_end_residencial_cidade").val();
	if(value.length < 2){
		alert("digite sua cidade");
		return false;
	}
	value = $("#program_user_end_residencial_estado").val();
	if(value.length < 2){
		alert("digite seu estado");
		return false;
	}
	value = $("#program_user_end_residencial_cep").val();
	if(value.length < 8){
		alert("digite seu cep");
		return false;
	}
	value = $("#program_user_email").val();
	if(!mailcheck(value)){
		alert("digite um endereço de email válido");
		return false;
	}
	value = $("#program_user_necessidades_especiais").val();
	value = $("#program_user_cuidados_especiais").val();
	value = $("#program_user_interesses").val();
	if(value.length < 2){
		alert("digite seus interesses");
		return false;
	}
	value = $("#program_user_nacionalidade").val();
	if(value.length < 2){
		alert("digite sua nacionalidade");
		return false;
	}
	value = $("#program_user_pais").val();
	if(value.length < 2){
		alert("escolha país");
		return false;
	}
	pais = $("#program_user_pais").val();
	if(pais != "Brasil"){
		value = $("#program_user_passaporte").val();
		if(value.length < 10){
			alert("Não brasileiros - obrigatório prencher o número do passaporte");
			return false;
		}	
	}
	value = $("#program_user_instituicao").val();
	if(value.length < 2){
		alert("digite sua instituição");
		return false;
	}
	value = $("#program_user_cargo").val();
	if(value.length < 2){
		alert("digite seu cargo");
		return false;
	}
	value = $("#program_user_unidade_de_trabalho").val();
	if(value.length < 2){
		alert("digite sua unidade de trabalho");
		return false;
	}
	value = $("#program_user_atividades").val();
	if(value.length < 2){
		alert("digite suas atividades");
		return false;
	}		
}


