$(document).ready( function(){
	//Bug fix
	if ( $.browser.safari ){
		$("#boxInstitucional .boxCenter p").css('float','none');
	}
	
	$("#headerRight").css("position","relative");
	$("#mainContentRight").css("position","relative");
	$("#rightColumn").css("position","relative");
	$("#search").focus( function(){
	  ( $(this).val() == 'buscar' ) ? $(this).val('') : null;
	});
	$("#search").blur( function(){
	  ( $(this).val() == '' ) ? $(this).val('buscar') : null;
	});
	if ( $('#mainContentRight').height() > $('#mainContentLeft').height() )
		$('#mainContentLeft').height( $('#mainContentRight').height() );
	if ( $('#mainContentLeft').height() > $('#mainContentRight').height() )
		$('#mainContentRight').height( $('#mainContentLeft').height() );
		
	// Menu de Produtos 
	$("#boxAllProdutos ul li ul").addClass("none");
	$("#boxAllProdutos ul li.productsSelected ul").removeClass("none");
	$("#boxAllProdutos ul li:has(ul)").click( function(){
		 if ( $(this).hasClass("productsSelected") ){
			 return false;
		 }else{
			$("#boxAllProdutos ul li.productsSelected").removeClass("productsSelected");
			$("#boxAllProdutos ul li ul:visible").slideUp("fast" );
			$(this).addClass("productsSelected").children().slideDown("fast");
		 }
	});
	
	// Faqs 
	$("#boxFaqs li span").addClass("none");
	$("#boxFaqs li.faqsSelected span").removeClass("none");
	$("#boxFaqs li strong").click( function(){
		if ( $(this).parent().hasClass("faqsSelected") ){
			return false;
		} else {
			$("#boxFaqs li.faqsSelected").removeClass("faqsSelected");
			$("#boxFaqs li span").slideUp("fast");
			$(this).parent().addClass("faqsSelected");
			$(this).next().next().slideDown("fast");
		}
	});
	
	$(".enviaPergunta").toggle(function(){
	
	$("#faqFormDiv").slideDown("slow");
	
	},function(){
		
		$("#faqFormDiv").slideUp("slow");
		});
	
	/* Mascaras dos inputs */
	$(".telefone").mask("(99)9999-9999");
	$(".cnpj").mask("99.999.999/9999-99");
	$(".cep").mask("99999-999");
	$(".data").mask("99/99/9999");
	$("form input[title=Site]").focus( function(){
		if ( $(this).val() == '' )
			$(this).attr("value","http://");
	});
	$("form input[title=Site]").blur( function(){
		if ( $(this).attr("value") == 'http://' )
			$(this).attr("value","");
	} );
	
	/* Validaçao dos formulários */
	/*
	$("form[name=distribuidor]").submit( function(){ //return validateForm()
		
		var result = (validateForm(distribuidor) ) ? true : false;
		if ( !result ) return false;
		
	});
	
	$("form[name=contato]").submit( function(){
		var result = ( validateForm('contato') ) ? true : false;
		if ( !result ) return false;
		else $('#contatoFormStatus').html('Enviando o formulário...');
	});
	
	$("form[name=contatoComercial]").submit( function(){
		var result = ( validateForm('contatoComercial') ) ? true : false;
		if ( !result ) return false;
		else $('#contatoComercialFormStatus').html('Enviando o formulário...');
	});
	$("form[name=trabalheConosco]").submit( function(){
		var result = ( validateForm('trabalheConosco') ) ? true : false;
		if ( !result ) return false;
		//else $('#contatoComercialFormStatus').html('Enviando o formulário...');
	});
	$("form[name=newsForm]").submit( function(){
		var result = ( validateForm('newsForm') ) ? true : false;
		if ( !result ) return false;
		//else $('#contatoComercialFormStatus').html('Enviando o formulário...');
	});
	$("form[name=faqForm]").submit( function(){
		var result = ( validateForm('faqForm') ) ? true : false;
		if ( !result ) return false;
		//else $('#contatoComercialFormStatus').html('Enviando o formulário...');
	});
	*/
	///////////////////////////////////////////////////////////rta mac os////////////////////////////
	if(navigator.userAgent.indexOf('Mac') != -1){
	$('#newsletter_img').css('margin','-24px 0 0 10px');
	$('#caveDuRoi').css('width','173px');
	}
	
	
	//////////////////////////////////////////////////////////maps input///////////////////////////////
	$('#op1').click(function(){
		$('#op').val('1');
	});
	$('#op2').click(function(){
		$('#op').val('2');
	});
	$('#op3').click(function(){
		$('#op').val('3');
	});
	
	
	
	
});

function validaBusca(){
		var campo = document.getElementById('search').value;
		if(campo.length <3){
			alert('<a href="javascript:hideAlert();"><img src="delrey/light/lb_delrey_busca2.jpg" /></a>','');
			return false;
		}
		else if(campo == 'buscar'){
			alert('<a href="javascript:hideAlert();"><img src="delrey/light/lb_delrey_busca1.jpg" /></a>','');
			return false;
			}
		else{
			return true;
			}
		
	}

function enviarPost( id , url , div ){
	var form = $('#'+id).serialize();
	$.post( url , form, function (data){
		$('#'+div).html(data);						  
	});
}
function carregarUrl(url,target){
	$("#"+target+"").load(url);
};
function openRoute(){
	$("#findContentLeft").fadeOut('fast');
	$("#findContentRightRoute").fadeIn('fast');
	}
function closeRoute(){
	
	$("#findContentRightRoute").fadeOut('fast');
	$("#findContentLeft").fadeIn('fast');
	}

/*function contato(){
	
	nome = document.getElementById("nome").value;
	email = document.getElementById("email").value;
	msg = document.getElementById("msg").value;	

	
	if(nome==""){
	return false;
	}else if(email==""){
	return false;
	}else if(msg==""){
	return false;
	}else{ 
	return true;
	}
}*/



/*function distribuidor(){
	
	razao = document.getElementById("nome").value;
	cnpj = document.getElementById("cnpj").value;
	//tipo
	telefone = document.getElementById("telefone").value;
	pais = document.getElementById("pais").value;
	endereco = document.getElementById("endereco").value;
	bairro = document.getElementById("bairro").value;
	//cidade = document.getElementById("cidade").value;
	//estado = document.getElementById("estado").value;
	cep = document.getElementById("cep").value;	
	nome = document.getElementById("nome").value;
	email = document.getElementById("email").value;


	
	if(razao==""){
	return false;
	}else if(cnpj==""){
	return false;
	}else if(telefone==""){
	return false;
	}else if(pais==""){
	return false;
	}else if(endereco==""){
	return false;
	}else if(cep==""){
	return false;
	}else if(nome==""){
	return false;
	}else if(email==""){
	return false;
	}else{ 
	alert('ok')
	return true;
	}
}*/


