var initForm = function(){

	$('form#form-contato').submit(function(){
		return validaFormContato();
		/*if(validaFormContato()){
			var data = $(this).serialize();
			$.post('envia-contato.php', data, function(retorno){
				if(retorno == 'ok'){
					alert('Obrigado pelo seu contato!');
					$('#form-contato input, #form-contato textarea').each(function(){
						$(this).val($(this).attr('title'));
					});
				}
				else{
					alert('Ocorreu um erro ao tentar enviar o seu contato. \nPor favor tente novamente mais tarde.');
				}
			});
		}
		return false;*/
	});

	$('#form-contato input[name=nome]').focus(function(){
		if($(this).val() == $(this).attr('title')){
			$(this).val('');
		}
	}).blur(function(){
		if($(this).val() == ''){
			$(this).val($(this).attr('title'));
		}
	});
	
	$('#form-contato input[name=email]').focus(function(){
		if($(this).val() == $(this).attr('title')){
			$(this).val('');
		}
	}).blur(function(){
		if($(this).val() == ''){
			$(this).val($(this).attr('title'));
		}
	});
	
	$('#form-contato input[name=telefone]').focus(function(){
		if($(this).val() == $(this).attr('title')){
			$(this).val('');
		}
	}).blur(function(){
		if($(this).val() == ''){
			$(this).val($(this).attr('title'));
		}
	});
	
	$('#form-contato input[name=cidade_estado]').focus(function(){
		if($(this).val() == $(this).attr('title')){
			$(this).val('');
		}
	}).blur(function(){
		if($(this).val() == ''){
			$(this).val($(this).attr('title'));
		}
	});
	
	$('#form-contato textarea').focus(function(){
		if($(this).val() == $(this).attr('title')){
			$(this).val('');
		}
	}).blur(function(){
		if($(this).val() == ''){
			$(this).val($(this).attr('title'));
		}
	});
}
var validaFormContato = function(){
	var erro = 0;
	$('#form-contato .required').each(function(){
		if(($(this).val() == $(this).attr('title')) || $(this).val() == ''){
			erro++;
		}
	});
	if(erro){
		alert('Preencha corretamente todos os dados para prosseguir.');
		return false;
	}
	return true;
}


var initNews = function(){
	$('form#form-news').submit(function(){
		if(validaFormNews()){
			var data = $(this).serialize();
			$.post('cadastro-newsletter.php', data, function(retorno){
				alert('Obrigado pelo seu cadastro!');
				$('#form-news input').each(function(){
					$(this).val($(this).attr('title'));
				});
			});
		}
		return false;
	});
	$('#form-news input[name=nome]').focus(function(){
		if($(this).val() == $(this).attr('title')){
			$(this).val('');
		}
	}).blur(function(){
		if($(this).val() == ''){
			$(this).val($(this).attr('title'));
		}
	});
	$('#form-news input[name=email]').focus(function(){
		if($(this).val() == $(this).attr('title')){
			$(this).val('');
		}
	}).blur(function(){
		if($(this).val() == ''){
			$(this).val($(this).attr('title'));
		}
	});
}
var validaFormNews = function(){
	var erro = 0;
	$('#form-news .required').each(function(){
		if(($(this).val() == $(this).attr('title')) || $(this).val() == ''){
			erro++;
		}
	});
	if(erro){
		alert('Preencha corretamente todos os dados para prosseguir.');
		return false;
	}
	return true;
}

$(document).ready(function(){

	if(document.getElementById('banner-home-flash')){
		$('#banner-home-flash').flash({
			src: 'media/swf/banner-home.swf',
			width: 667,
			height: 500,
			wmode: 'transparent'
		});
	}

	initNews();
	initForm();
	
	if(document.getElementById('page-kits')){
		$('#modelos-abrir .viewport').jCarouselLite({
		    btnNext: "#modelos-abrir .next",
		    btnPrev: "#modelos-abrir .prev",
		    circular: false,
		    visible: 5
		});
		
		$('#modelos-correr .viewport').jCarouselLite({
		    btnNext: "#modelos-correr .next",
		    btnPrev: "#modelos-correr .prev",
		    circular: false,
		    visible: 4
		});
    }
    
    if(document.getElementById('page-esquadrias') || document.getElementById('page-kits')){
    	$('a.zoom').fancybox();
    }
    
	$('a.manuais-inst').click(function(){
        window.open($(this).attr('href'), 'popup-manual', 'scrollbars=yes,width=800,height=500')
        return false
    });
});

