
/*

	Text Input Clearer - jQuery plug-in
	
	

	-----------------------------------------------------------------------------------------------------------------------------

*/

(function($){



$.fn.FormTextClearer = function(options)
{
	
	var o = jQuery.extend({//Default values
		blurSuccess: function(){},
		blurFail: function(){}
	},options);	
	
	function getVal(obj)//Get value of an input box or text area
	{
		if(!$(obj)[0].tagName)return null;
		switch($(obj)[0].tagName.toLowerCase())
		{
			case 'input':
				return ($(obj).val() && $(obj).val().length > 0) ? jQuery.trim($(obj).val().toLowerCase()) : null;
				break;
			case 'textarea':
				var sText = ($(obj).text() && $(obj).text().length > 0) ? jQuery.trim($(obj).text().toLowerCase()) : null;
				var sVal = ($(obj).val() && $(obj).val().length > 0) ? jQuery.trim($(obj).val().toLowerCase()) : null;
				return (sVal || sText || null);
				break;
			default:
				return null;
		}
	}
	
	function setVal(obj,sVal)//Set value of an input box or text area
	{
		if(!$(obj)[0].tagName)return null;
		switch($(obj)[0].tagName.toLowerCase())
		{
			case 'input':
				$(obj).val(sVal);
				break;
			case 'textarea':
				$(obj).text(sVal);
				$(obj).val(sVal);
				break;
			default:
		}
	}
	
	return this.each(function(){//Loop through each parent element
		
		var defaultValue = ($(this).attr('rel') && $(this).attr('rel').length > 0) ? jQuery.trim($(this).attr('rel').toLowerCase()) : null;
		
		$(this).click(function(){//click event
			var curValue = getVal(this);
			if((defaultValue && curValue) && (defaultValue == curValue))setVal(this,'');
		}).focus(function(){//focus event
			var curValue = getVal(this);
			if((defaultValue && curValue) && (defaultValue == curValue))setVal(this,'');
		}).blur(function(){
			var curValue = getVal(this);
			if(!curValue)
			{
				setVal(this,$(this).attr('rel'));
				jQuery.proxy(o.blurFail,this)();
			} else {
				jQuery.proxy(o.blurSuccess,this)();
			}
		});
		
		if($(this)[0].tagName.toLowerCase() == 'textarea')
		{
			$(this).val($(this).text());	
		}
	});
	
	
};
		  
})(jQuery);




/*

	BC Form Validator - jQuery plug-in
	
	
	PARAMETERS:
	
	form_elements: [{ 
						e_query: jQuery Selector (Selector for the form's element tag. It must be relative to the form element)
						e_type:  String[text,email] (String type for inputs of text type)
						error_message: String (Error message to be displayed in case the element's value is NOT valid)
	               }] Array of object literals
	
	-----------------------------------------------------------------------------------------------------------------------------

*/

(function($){



$.fn.BCFormValidator = function(options)
{
	
	var o = jQuery.extend({//Default values
		form_elements: new Array()
	},options);	
	
	function isValidStr(str)//Check if a parameter is a valid string
	{
		if(typeof str != 'string')return null;
		if($.trim(str).length == 0)return null;
		return true;
	}
	
	function validateInput(obj)//Validates an input element
	{
		if(!$(obj).val())return null;
		if(!isValidStr($(obj).val()))return null;
	}
	
	return this.each(function(){//Loop through each parent element
	
		
		
	});
	
	
};
		  
})(jQuery);



$(document).ready(function(){
						   
//Input fields

//Enquiry form inputs

if(jQuery.fn.FormTextClearer)
{
	var clearerArray = new Array();
	
	var siteSearch = ['#site-search .txt'];
	jQuery.merge(clearerArray,siteSearch);
	var careers = ['#careers-form .txt','#careers-form textarea'];
	jQuery.merge(clearerArray,careers);
	var threeColsForm = ['.three-cols-form .txt','.three-cols-form #CaptchaV2'];
	jQuery.merge(clearerArray,threeColsForm);
	var contactForm = ['.contact-form .txt', '.contact-form textarea'];
	jQuery.merge(clearerArray,contactForm);
	var aimsLoginForm = ['#SZUsername'];
	jQuery.merge(clearerArray,aimsLoginForm);
	
	var reports = ['#CAT_Custom_16364','#CAT_Custom_16365','#CAT_Custom_16366','#CAT_Custom_16367','#CAT_Custom_3498','#CAT_Custom_34300','#CAT_Custom_34301','#CAT_Custom_34302','#CAT_Custom_34305','#CAT_Custom_34306','#CAT_Custom_34325','#CAT_Custom_34346','#CAT_Custom_3500','#CAT_Custom_3501','#CAT_Custom_3504','#CAT_Custom_53355','#CAT_Custom_5929','#CAT_Custom_5932','#CAT_Custom_81581'];
	jQuery.merge(clearerArray,reports);
	
	$(clearerArray.join(',')).FormTextClearer({
		blurSuccess: function(){
			$(this).css({
				'font-style': 'normal',
				color: '#686D6F'
			});
		},
		blurFail: function(){
			$(this).css({
				'font-style': 'italic',
				color: '#92979A'
			});
			}
	});
} 



//Search form validator

$('#site-search form').submit(function($e){
	var sVal = $(this).find('input[type=text]').val();
	var sRel = $(this).find('input[type=text]').attr('rel');
	if(!sVal || (sRel && sRel == sVal))
	{
		$e.preventDefault();
		alert('You must enter a valid search term.');
	}
});

//Home page slideshow
if ($('#home-slideshow').val() != null)
$('#home-slideshow').cycle({	//Cycle images on slideshow //fx:     'scrollUp',	// choose your transition type, ex: fade, scrollUp, shuffle, etc...
	fx: 'custom', 
	timeout: 5000,
	speed:	 2000,
	height:  242,
	fit:	 1,
	cssBefore: { left: 940 }, 
	animIn:  { left: 0 }, 
  	animOut: { left: -940 }
});

	
//AIMs login message in header

if($('#site-login .username').text())$('#site-login .message').css('display','block');


//Anouncements truncation



$('#news-announcements .extract').each(function(){
		
		var sText = $(this).text();
		if(sText.length > 200)
		{
			sText = sText.substr(0,200);
			sText = sText.substr(0,sText.lastIndexOf(' '));
			$(this).html('<p>' + sText + '...</p>');	
		}
		
});	





//Announcements home page

$('#home-latest-news li').each(function($key,$value){
	if($key > 4)
	{
		$(this).css('display','none');	
	}
});


//Update date in annoucements

$('#news-announcements li,#home-latest-news li,#career-announcements li').each(function(){
	var sDate = $(this).find('.date').text().replace(/\-+/gi,' ');
	$(this).find('.date').text(sDate);											  
});

$('.article-date').find('strong').each(function(){//Update date in announcements detail page
	var sDate = $(this).text().replace(/\-+/gi,' ');
	$(this).text(sDate);											   
});

//Search results - remove breadcrumbs

if($('.search-results').length > 0)$('.breadcrumbs').html('');



});
















