// Find all fbc profile pic images and remove their title and alt tags.
	
var clear_names_interval	=	500;
var clear_names_start		=	new Date().getTime();
var clear_names_duration	=	30000;	// 30 seconds


var clearNames	=	setInterval(function() {
	$(".FB_profile_pic").each(function() {		
		$(this).attr("title", "Avatar");
		$(this).attr("alt", "Avatar");
	});
	
	if(new Date().getTime() - clear_names_start > clear_names_duration) {clearInterval(clearNames);}
}, clear_names_interval);
	
$(document).ready(function() {
	$('#searchform').validate();
	$('#mailing_list').validate();
	$('#mailboxform').validate();
	//asteriskify();	
});

// Clean up and correctly format the postcode.
function cleanUpPostcode(postcode) {
	postcode = postcode.trim(postcode);
	postcode = postcode.split(' ').join('');
  if (postcode.length < 6) return false; 

	postcode = postcode.toUpperCase();
	var ptrn = /^(BT\d{1,2}\s?\d\w\w)$/;
	if (postcode.match(ptrn)) { // It's a valid-looking NI postcode.
		var walk = postcode.slice(-3);
		postcode = postcode.replace(walk, ' ' + walk);
		return postcode;
	}
	return false;
}

// Automagically highlight required fields with an asterisk.
function asteriskify(){
	$.each($('form'),function(){
		var formId=this.id;
		if(formId && formId != "searchform" && formId != "politicianform"){
			var count_required=0;
			$.each($("#"+formId+" :input"),function(){
				if($(this).hasClass('required')){
					$("label[for='"+this.id+"']").prepend('<span class="req">*</span> ');
					if(++count_required==1){
						$("#"+formId).append('<div class="has_required_fields">(<span class="req">*</span> denotes a required field)</div>');
					}
				}
			});
		}
	});
}

function asteriskify_in_div(id) {

	var mydiv	=	$("#"+ id);

	if(!mydiv) {
		return false;
	}


	// Find all required form inputs within this div and asteriskify them
	$("#"+ id +" form").each(function() {
		var formId	=	this.id;
		var count_required=0;

		$(this).find(":input").each(function() {
			if($(this).hasClass("required")) {
				$(mydiv).find("#"+ formId +" label[for='"+ this.id +"']").each(function() {
					$(this).prepend('<span class="req">*</span> ');
				});
				if(++count_required==1){
					$("#"+formId).append('<div class="has_required_fields">(<span class="req">*</span> denotes a required field)</div>');
				}
			}
		});
	});

} // asteriskify_in_div

