$(document).ready(function(){


	$("#full_terms").hide();

	var toggleVal = 0;
	
	$("#read_t_and_cs").bind("click",function(){
		 if (toggleVal == 0) {
		 	toggleVal = 1;
		 	$("#full_terms").slideDown();
		 	$("#read_t_and_cs").html("Hide full terms and conditions");
		 } else {
		 	toggleVal = 0;
		 	$("#full_terms").slideUp();
		 	$("#read_t_and_cs").html("Read full terms and conditions");
		 }
		 
		 return false;
	});




	$(".report_offensive").bind("click",function(){
		
		$("#q248584_q1").val($(this).attr("title"));
		$("#form_email_248584_submit").click();
	});
	
	$(".comment_instance blockquote p").each(function(){
		$(this).html($(this).html().replace(/[\r\n]+/g, "</p><p>"));
	});

$('#comment_listing').insertBefore('#comment_form');

/* 
$("#comments_list_blank").load("/what_you_can_do/campaigning/sectionpage_assets/short_comment_list/_nocache",function(){

	$(".report_offensive").bind("click",function(){
		
		$("#q248584_q1").val($(this).attr("title"));
		$("#form_email_248584_submit").click();
	});
	
	$(".comment_instance blockquote p").each(function(){
		$(this).html($(this).html().replace(/[\r\n]+/g, "</p><p>"));
	});

}); */



$("#additionalcontentcol_deign").remove();
	
	$("#nonjs_names").html("<div class=\"grey_wrap\"><input type=\"text\" name=\"fullName\" id=\"fullName\" value=\"Your name\"/><input type=\"hidden\" id=\"join_first_name\" name=\"fn\" value=\"\" /><input type=\"hidden\" id=\"join_last_name\"  name=\"ln\" value=\"\" /></div>");
		
	warningBox = "<div id=\"offensive_confirmation\"><p>Thanks &ndash; Shelter&rsquo;s moderators will check the content of this comment.</p></div>";
	reportedComment = $("#reported_comment").html(); 
	
	$("#mpemail_postcode").focus(function(){
		if ($(this).val() == "Enter your postcode") {
			$(this).val("");
		}
	});
	
	$("#mpemail_postcode").blur(function(){
		if ($(this).val() == "") {
			$(this).val("Enter your postcode");
		}
	});
	
	$("#fullName").focus(function(){
		if ($(this).val() == "Your name") {
			$(this).val("");
		}
	});
	
	$("#fullName").blur(function(){
		if ($(this).val() == "") {
			$(this).val("Your name");
		}
	});
	
	$("#join_email").focus(function(){
		if ($(this).val() == "Email address") {
			$(this).val("");
		}
	});
	
	$("#join_email").blur(function(){
		if ($(this).val() == "") {
			$(this).val("Email address");
		}
	});
	
	
	
	
	
	$("#join_us_widget form").submit(function(){
		
		var fullNameText = $("#fullName").val().split(" ");
		
		$("#join_first_name").val(fullNameText[0]);
		
		var fullLastname = "";
		
		for (i=1;i<(fullNameText.length);i++) {
			fullLastname = fullLastname + fullNameText[i];
		}
		return true;
		
	});
	
	
	
	
	if (jQuery.trim(reportedComment) !="") {
		$("#reported_comment").remove();
		$("#hi_cam_comments").before(warningBox);		
		
		$.ajax({
		type: "GET",
			url: "/what_you_can_do/campaigning/sectionpage_assets/report_as_offensive/",
			cache: false,
			success: function(html){
				
				$("#report_offensive_form").html(html);
				$("#form_email_248584").attr("action","/what_you_can_do/campaigning/_nocache");
			},
			error: function(){
			}
		});
		
	}
	
	

});
