$(document).ready(function(){
	$('#top_link').click(function () { 
	  window.scrollTo(0,0);
	  return false;
	});
	
	$('.target').attr('target','_blank')
	
	$('#nav ul > li').hover(function(){
	  $(this).find('div').show();
	  $(this).find('.nav_img').addClass('over');
	},function(){
	  $(this).find('div').hide();
	  $(this).find('.nav_img').removeClass('over');
	});
	
	$('#nav p').hover(function(){
	  $(this).find('span').show();
	  $(this).find('.nav_img').addClass('over');
	},function(){
	  $(this).find('span').hide();
	  $(this).find('.nav_img').removeClass('over');
	});
	
	if ($.browser.safari) {
		$('textarea').css('resize', 'none');
		$('input.text').css('resize', 'none');
	}
	
	$('.list_faqs li').click(function(){
		$(this).toggleClass('active');
		if($(this).hasClass('active')){
			$(this).find('div').slideDown('fast');
		}
		else{
			$(this).find('div').slideUp('fast');
		}
	});

	$(".populate").populate();
	
	$('#btn-partern-form').click(function(){
		sendForm($(this).parents("form").attr("id"));
	});
	
	$('#btn-researcher-form').click(function(){
		sendForm($(this).parents("form").attr("id"));
	});
	
	$('#btn-verification-form').click(function(){
		sendForm($(this).parents("form").attr("id"));
	});
	$('#btn-newsletter-form').click(function(){
		if(checkFormFields($(this).parents("form").attr("id"),1,1,'#000000','#F1F1F1')){
			$(this).parents("form").addAjaxLoader();
			$(this).parents("form").submit();
		}
	});
	$('#btn-white-paper-form').click(function(){
		if(checkFormFields($(this).parents("form").attr("id"),1,1,'#000000','#F1F1F1')){
			$(this).parents("form").addAjaxLoader();
			$(this).parents("form").submit();
		}
	});
	
	$("label[for='counties']").each(function(){
		$(this).parents("dl").find(":checkbox").click(function(){
			var title = $(this).attr("value");
			var value = $("#types_of_searches_group").val();
			value = value.replace(","+title,"").replace(title,"");
			if(this.checked){
				value += (value!=''?',':'')+title;
				
			}
			if($(this).attr("id")=="counties_other"){
				$("#counties_other_text").removeClass("required");
				if(this.checked){
					$("#counties_other_text").parent().removeClass("no_display");
					$("#counties_other_text").addClass("required");
					
				}
				else{
					$("#counties_other_text").parent().addClass("no_display");
					$("#counties_other_text").trigger("click");
				}
			}
			$("#types_of_searches_group").val(value);
			if(value!=''){
				$("#types_of_searches_group").trigger("change");
			}
			
		});
	});
	
	$("label[for='conduct_search']").each(function(){
	
		$(this).parents("span").find(":radio").click(function(){
			
			var title = $(this).attr("value");
			var value = "";
			if(this.checked){
				value = (value!=''?',':'')+title;
			}
			$("#do_you_conduct_search_group").val(value);
			if(value!=''){
				$("#do_you_conduct_search_group").trigger("change");
			}
		});
	});
	
});
