$().ready(function(){
	$('#sub-menu').hide();
	
	$('a.swf').media();
	
	$('#mais-mod').click(function(){
		$('#sub-menu').css('height', 'auto');
	});
	
	//########## campo busca #############################	
	$('#input-busca').focus(function(){
		if( $(this).val() == 'Procurar na ACES' )
			$(this).val('');
		$(this).css('color', '#333');
	});
	
	$('#input-busca').blur(function(){
		if( $(this).val() == '' )
		{
			$(this).val('Procurar na ACES');
			$(this).css('color', '#CCC');
		}
	});
	
	
	//############## sub menu ###########
	$('.link-modalidades, #sub-menu').hover(function(){
		$('#sub-menu').show();
		$('.link-modalidades').addClass('link-atual');
	}, function(){
		$('#sub-menu').hide();
		$('.link-modalidades').removeClass('link-atual');
	});	
		
});


/*********** change competição ***********/
function changeLocal(url)
{
	window.location.href = url;
}


/************ abrir janela ************/
function openWindow( url, w, h )
{
	var x = (window.screen.width / 2) - (w/2);
	var y = (window.screen.height / 2) - (h/2) -30;
	window.open(url, "jWindow", "width="+w+", height="+h+", top="+y+", left="+x+", scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no");
}


/********* validação contato ***********/
function ajax_contato( url_ )
	{
		var n = $('#nome').val();
		var e = $('#email').val();
		var t = $('#telefone').val();
		var a = $('#assunto').val();
		var s = $('#setor').val();
		var m = $('#mensagem').val();
		
		$('#form-contato input[type=text], #form-contato textarea').css('border-color', '#999');
		$('.error').html('&nbsp;');
		
			if( n == '' )
			{
				$('.error').html('Preencha o campo Nome');
				$('#nome').css('border-color', '#F00');
				$('#nome').focus();
			}
			else if( e == '' || e.length < 6 || e.indexOf('@') == -1 )
			{
				$('.error').html('Digite um email válido');
				$('#email').css('border-color', '#F00');
				$('#email').focus();
			}
			else if( a == '' )
			{
				$('.error').html('Preencha o campo Assunto');
				$('#assunto').css('border-color', '#F00');
				$('#assunto').focus();
			}
			else if( s == 0 )
			{
				$('.error').html('Selecione o Setor');
				$('#setor').css('border-color', '#F00');
				$('#setor').focus();
			}
			else if( m == '' )
			{
				$('.error').html('Digite uma mensagem');
				$('#mensagem').css('border-color', '#F00');
				$('#mensagem').focus();
			}
				
			else
			{	
				$.ajax({
					   url: url_,
					   type: 'POST',
					   data: ({nome:n, email:e, telefone:t, assunto:a, setor:s, mensagem:m}),
					   success: function(msg){
						 if( n != "" && e != "" && m != "" )
						 {
							$('.error').html( msg );
							document.getElementById('form-contato').reset();					
						 }
					   }
				   });
			}
	}
	
	
/************** ajax enquete **************/
function ajax_enquete( url_enquete )
{
	var voto = $('#home-enquete label input:checked').val();
	var url = url_enquete+"?voto="+voto;
	
	$('#erro-enquete').html('');
	
	if( voto == '' || voto == 0 || ( voto*1 != voto ) )
	{
		$('#erro-enquete').html('Selecione uma opção.');
	}
	else
	{		
		openWindow(url, 600, 400);
	}
}

