//DROP-MENU
$(document).ready(function() {
	
	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}


	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 500, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#topnav li .sub").css({'opacity':'0'});
	$("ul#topnav li").hoverIntent(config);



});



//CARREGA SIMULAÇÃO DE FINANCIAMENTO
//<![CDATA[
$(document).ready(function(){
		var iconCarregando = $('<img src="images/mini.gif" class="icon" /> <span class="destaque">Carregando. Por favor aguarde...</span>');
	$('#form_um').submit(function(e) {
	e.preventDefault();
	$('#insere_aqui').empty();
	var serializeDados = $('#form_um').serializeArray();
	$('#insere_aqui').css('display', 'block');
	$.ajax({
			url: 'financiamento_simula_resultado.php', 
			dataType: 'html',
			type: 'POST',
			timeout: 5000,
			data: serializeDados,
			beforeSend: function(){
			$('#insere_aqui').html(iconCarregando);
			},
			complete: function() {
			$(iconCarregando).remove();
			},
			success: function(data, textStatus) {
				$('#insere_aqui').html('<p>' + data + '</p>');
			},
			error: function(xhr,er) {
				$('#insere_aqui').html('<p class="destaque">Lamento! Ocorreu um erro. Por favor tente mais tarde.')
			}		
		});
	});	
})
// ]]>


function abreFotos(url){
    janela=window.open(url,'fotodetalhe','width=700,height=570,top=0,left=0,resizable=no,status=no,scrollbars=yes')
}





function open_window(url) 
{
mywin = window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=420,height=320');
}

function popup(caminho,nome,largura,altura,rolagem) {
	var esquerda = (screen.width - largura) / 2;
	var cima = (screen.height - altura) / 2 -50;
	window.open(caminho,nome,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + rolagem + ',resizable=no,copyhistory=no,top=' + cima + ',left=' + esquerda + ',width=' + largura + ',height=' + altura);
}



function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function validar(Form) {
	var invalid, s;
	invalid = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	var s;
// inicio de verificacao
 	if (Form.YourName.value.length == 0) {
		alert("Nome!");
		Form.YourName.focus();
	        return false;	}
	
	     				
		if (Form.YourEmail.value.length == 0) {
    		alert("O Email!");
    		Form.YourEmail.focus();
    		return false;	}

					
		if( document.Form.YourEmail.value.length < 5 || document.Form.YourEmail.value.indexOf("@") < 0 || document.Form.YourEmail.value.indexOf(".") < 0 ) 
	{
			alert("E-mail inválido !");
   			Form.YourEmail.focus();
			return (false);

	}
		
		
		if (Form.YourTel.value.length == 0) {
		alert("TELEFONE!");
		Form.YourTel.focus();
	        return false;	}
		
		
		if (Form.assunto.value.length == 0) {
		alert("Assunto!");
		Form.assunto.focus();
	        return false;	}
		
		
		if (Form.comments.value.length == 0) {
		alert("MENSAGEM!");
		Form.comments.focus();
	        return false;	}
		
		
     return true;
}

function ValidarSolicitacao(Form) {
	var invalid, s;
	invalid = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	var s;
// inicio de verificacao
 	if (Form.Nome.value.length == 0) {
		alert("Informe seu Nome!");
		Form.Nome.focus();
	        return false;	}
			
	
	
	   if (Form.Cidade.value.length == 0) {
		alert("Informe sua Cidade!");
		Form.Cidade.focus();
	        return false;	}
	
	   
	   if(Form.estado.value=="")
			{
				alert('Selecione seu Estado!');
				Form.estado.focus();
				return false;
			}
	   
	   
	   
	  if (Form.Email.value.length == 0) {
    		alert("Informe O Email!");
    		Form.Email.focus();
    		return false;	}

					
	 if( document.Form.Email.value.length < 5 || document.Form.Email.value.indexOf("@") < 0 || document.Form.Email.value.indexOf(".") < 0 ) 
	{
			alert("E-mail inválido !");
   			Form.Email.focus();
			return (false);

	}
		
		
	 if (Form.ddd.value.length == 0) {
		alert("Informe o DDD!");
		Form.ddd.focus();
	        return false;	}
			
	 if (Form.Tel.value.length == 0) {
		alert("Informe o Telefone!");
		Form.Tel.focus();
	        return false;	}
		
		
     return true;
}
