$(function(){
	$('input.textinput, textarea.textinput').focus(function() {
		$(this).removeClass('textinput').addClass('textinputhover');
	}).blur(function() {
		$(this).removeClass('textinputhover').addClass('textinput');
	});

	// Search Default Text
	var product_search_text = 'Keywords or product code';

	$('#productSearch #Name').focus(function() {
		if ($(this).val() == product_search_text) $(this).val('');
	}).blur(function() {
		if ($(this).val() == '') $(this).val(product_search_text);
	}).blur();


	// Subscribe Default Text
	var product_search_text = 'Email Address';

	$('#subscribe #Email').focus(function() {
		if ($(this).val() == product_search_text) $(this).val('');
	}).blur(function() {
		if ($(this).val() == '') $(this).val(product_search_text);
	}).blur();


	// Donation Amount Functions
	var custom_amount_text = 'ENTER OTHER AMOUNT';

	$('form input#custom_donation_amount').focus(function() {
		if ($(this).val() == custom_amount_text) $(this).val('');
	}).blur(function() {
		if ($(this).val() != '') {
			$('a.donationAmount').removeClass('donationAmountDown');
			$(this).addClass('donationAmountDown');
			$('form input#donation_amount').val(ParseAmount($(this).val()));
		} else {
			$(this).val(custom_amount_text);

			if ($(this).is('.donationAmountDown')) {
				$(this).removeClass('donationAmountDown');
				$('form input#donation_amount').val('');
			}
		}
	});

	$('a.donationAmount').click(function() {
		$('a.donationAmount').removeClass('donationAmountDown');
		$(this).addClass('donationAmountDown');
		$('form input#custom_donation_amount').removeClass('donationAmountDown').val(custom_amount_text);
		$('form input#donation_amount').val(ParseAmount($(this).attr('href')));
		return false;
	});
});

function ParseAmount(number, decimal_places) {
	// Strip out any non numeric characters (but leave decimal point)
	number = Number(number.toString().replace(/[^0-9\.]/gi, ''));
	
	// Check Decimal Place (2 DP by default)
	decimal_places = parseInt(decimal_places);
	decimal_places = (!isNaN(decimal_places)) ? decimal_places : 2;
	
	return number.toFixed(decimal_places);
}
