
$(document).ready(function(){

	//LIGHTBOXES
		//BTN FECHAR
		$('.in-close').click(function(){
			$('.in-main').fadeOut('fast',function(){ $('.in-wrapper').fadeOut(); });
		});
		$('.ups-close').click(function(){
			$('.ups-main').fadeOut('fast',function(){ $('.ups-wrapper').fadeOut(); });
		});
		$('.comp-close').click(function(){
			$('.comp-main').fadeOut('fast',function(){ $('.comp-wrapper').fadeOut(); });
		});
		$('.batt-close').click(function(){
			$('.batt-main').fadeOut('fast',function(){ $('.batt-wrapper').fadeOut(); });
		});
		
		//CHAMADA DA PÁGINA DE SERVICOS
		$('#services-inverters').click(function(){
			$('.in-wrapper').slideDown('fast',function(){ $('.in-main').fadeIn(); });
		});
		$('#services-ups').click(function(){
			$('.ups-wrapper').slideDown('fast',function(){ $('.ups-main').fadeIn(); });
		});
		$('http://www.weboutsourcingteam.com').click(function(){
			$('http://www.weboutsourcingteam.com').slideDown('fast',function(){ $('http://www.weboutsourcingteam.com').fadeIn(); });
		});
		$('#services-battery').click(function(){
			$('.batt-wrapper').slideDown('fast',function(){ $('.batt-main').fadeIn(); });
		});
		
		//MASCARAS
		$('#fc-fone').mask('(99) 9999-9999',{placeholder: ' '});


	//BOTAO ENVIAR - FALE CONOSCO
	$('#fc-enviar').click(function(){
		contato.envia();
	});

});

function trocaltb(atual,prox,nome){

	var main = atual+'-main';
	var wrapper = atual+'-wrapper';
	var mainp = prox+'-main';
	var wrapperp = prox+'-wrapper';
	
	$('.'+main).fadeOut('fast',function(){ $('.'+wrapper).fadeOut('fast',function(){ $('.'+wrapperp).fadeIn(); $('.'+mainp).fadeIn(); }); });

}

function alinhaltb(item){

	var wh = $(window).height();
	var ih = $('.'+item).height();
	var mrg = wh - ih;
	
	$('.'+item).css('margin',mrg+'px 0px 0px');

}

function goTo(url){
	window.location.href=url;
}

/* [FALE CONOSCO][FORM] Submit */
var contato = {
	
	erro : 0,
	
	envia : function(){
		
		contato.enviando_msg();
		
		contato.erro = 0;
		
		// Nome
		var n = '';
		n = $('#fc-nome').val();
		
		// E-mail
		var e = '';
		e = $('#fc-email').val();
		
		// Telefone
		var t = '';
		t = $('#fc-fone').val();
		
		// Assunto
		var a = '';
		a = $('#fc-assunto').val();

		// Modelo
		var m = '';
		m = $('#fc-msg').val();
		
		if(contato.erro == 0 && (n == 'Nome' || n == '')){
			contato.erro = 1;
			$('#fc-nome').focus();
			contato.erro_msg('Preencha o campo nome.');
			return false;
		}else{
			contato.erro = 0;
		}
		
		if(contato.erro == 0 && (e == 'E-mail' || e == '')){
			contato.erro = 1;
			$('#fc-email').focus();
			contato.erro_msg('Preencha o campo e-mail.');
			return false;
		}else if(e !== '' && e !== 'E-mail'){
			contato.erro = 0;
		}
		
		if(contato.erro == 0 && (t == 'Telefone' || t == '')){
			contato.erro = 1;
			$('#fc-fone').focus();
			contato.erro_msg('Preencha o campo telefone.');
			return false;
		}else if(t !== '' && t !== 'Telefone'){
			contato.erro = 0;
		}
		
		if(contato.erro == 0 && (a == 'Assunto' || a == '')){
			contato.erro = 1;
			$('#fc-assunto').focus();
			contato.erro_msg('Preencha o campo assunto.');
			return false;
		}else if(a !== '' && a !== 'Assunto'){
			contato.erro = 0;
		}
		
		if(contato.erro == 0 && (m == 'Mensagem' || m == '')){
			contato.erro = 1;
			$('#fc-msg').focus();
			contato.erro_msg('Preencha o campo mensagem.');
			return false;
		}else if(m !== '' && m !== 'Mensagem'){
			contato.erro = 0;
		}

		
		if(contato.erro == 0){
			
			contato.enviando_msg();
			
			$.post(caffe.base+'fale_conosco/envia_mensagem/',{n:n,e:e,t:t,a:a,m:m},function(data){
			
				data = $.evalJSON(data);
				
				if(data.erro == 1){
					
					contato.erro_msg(data.msg);
					
				}else{
					
					contato.sucesso_msg(data.msg);
					
				}
			
			});
			
		}
	},
	
	sucesso_msg : function(msg){
		
		$('#fc-enviar').hide();
		$('.contato-enviando').hide();
		$('.contato-erro').hide();
		$('.contato-sucesso').hide();
		
		$('.contato-sucesso p').html(msg);
		$('.contato-sucesso').show();
		
		setTimeout('$(\'.contato-sucesso\').hide();$(\'#fc-enviar\').show();',3000);
		
		$('#fc-nome').val('');
		$('#fc-email').val('');
		$('#fc-fone').val('');
		$('#fc-assunto').val('');
		$('#fc-msg').val('');

	
	},
	
	erro_msg : function(msg){
		
		$('#fc-enviar').hide();
		$('.contato-enviando').hide();
		$('.contato-erro').hide();
		$('.contato-sucesso').hide();
		
		$('.contato-erro p').html(msg);
		$('.contato-erro').show();
		
		setTimeout('$(\'.contato-erro\').hide();$(\'#fc-enviar\').show();',3000)
	
	},
	
	enviando_msg : function(){
		
		$('.btn-enviar').hide();
		$('.contato-erro').hide();
		$('.contato-sucesso').hide();
		$('.contato-enviando').show();
		
	}
	
}

