﻿// JavaScript Document

$(document).ready(function(){
						   $("a[rel='buscar']").click(function(){
															   
															   $("#frmbusca").submit();
															   
															   });
						   
						  /* var sidebarheight = $("#sidebar").height();
						   var conteudoheight = $("div.conteudo").height();
						   
						   var mgbanner = -(sidebarheight + 38);
						   
						   if (conteudoheight > sidebarheight) {
							    $("#sidebar").css({ 'height': (conteudoheight + 77) });
						   } else {
							   $("div.conteudo").css({ 'height': (sidebarheight - 77) });
						   }
						   
						   
						   
						   $(".banner").css({ 'margin-top': mgbanner });*/
						   
						   $("div.row input, div.row textarea").focusin(function(){
																				 if( $(this).val() == '' ||
																					$(this).val() == 'NOME'||
																					$(this).val() == 'E-MAIL'||
																					$(this).val() == 'DDD'||
																					$(this).val() == 'TELEFONE'||
																					$(this).val() == 'BAIRRO'||
																					$(this).val() == 'CIDADE'||
																					$(this).val() == 'ESTADO'||
																					$(this).val() == 'PAÍS'||
																					$(this).val() == 'MENSAGEM' ) {
																				 $(this).val('');
																				 
																				 }
																				 
																				 });
						   
						   $("div.row input, div.row textarea").focusout(function(){
																				 if( $(this).val() == '' ||
																					$(this).val() == 'NOME'||
																					$(this).val() == 'E-MAIL'||
																					$(this).val() == 'DDD'||
																					$(this).val() == 'TELEFONE'||
																					$(this).val() == 'BAIRRO'||
																					$(this).val() == 'CIDADE'||
																					$(this).val() == 'ESTADO'||
																					$(this).val() == 'PAÍS'||
																					$(this).val() == 'MENSAGEM' ) {
																				 $(this).val($(this).attr('id').toUpperCase());
																				 
																				 if($(this).attr('id') == 'pais') {
																					 
																					  $(this).val('PAÍS');
																				 }
																				 
																				 }
																				 
																				 });
						   
						   $("a[rel='envia_contato']").click(function(){
																	  nome = $("#nome").val();
																	  email = $("#e-mail").val();
																	  ddd = $("#ddd").val();
																	  telefone = $("#telefone").val();
																	  bairro = $("#bairro").val();
																	  ddd = $("#ddd").val();
																	  bairro = $("#bairro").val();
																	  cidade = $("#cidade").val();
																	  estado = $("#estado").val();
																	  pais = $("#pais").val();
																	  mensagem = $("#mensagem").val();
																	  
																	  parte1 = email.indexOf("@");
																	  parte2 = email.indexOf(".");
																	  parte3 = email.length;
																	  
																	  if(nome.length < 2 || nome == 'NOME' ) {
																			alert('Nome inválido');
																			$("#nome").focus();
																		} else if(! (parte1 >= 3 && parte2 >= 6 && parte3 >= 9) ) {
																			alert('E-mail inválido');
																			$("#e-mail").focus();
																		} else if(ddd.length < 1 || isNaN(ddd)) {
																			alert('DDD inválido');
																			$("#ddd").focus();
																		} else if(telefone.length < 8 || isNaN(telefone)) {
																			alert('Telefone inválido');
																			$("#telefone").focus();
																		} else if(bairro.length < 2 || bairro == 'BAIRRO' ) {
																			alert('Bairro inválido');
																			$("#bairro").focus();
																		} else if(cidade.length < 2 || cidade == 'CIDADE' ) {
																			alert('Cidade inválida');
																			$("#cidade").focus();
																		} else if(estado.length < 1 || estado == 'ESTADO' ) {
																			alert('Estado inválido');
																			$("#estado").focus();
																		} else if(pais.length < 2 || pais == 'PAÍS' ) {
																			alert('País inválido');
																			$("#pais").focus();
																		} else if(mensagem.length < 3 || mensagem == 'MENSAGEM' ) {
																			alert('Mensagem inválida');
																			$("#mensagem").focus();
																		} else {
																			$("#frm_contato").submit();
																		}
																	  
																	  
																	  
																	  
																	  
																	  });
						   
						   document.getElementById('frm_contato').reset();
						   
						   $("a[rel='contato']").click(function(){
															   
															   $('html,body').animate({scrollTop: $("#frm_contato").offset().top},500,function(){
																																			   $("#nome").focus();
																																			   });
															   
															   });
						   
						  
						   
						   
						   });
