/*
	Used to dynamically change images on the site.
*/
function terere_changeimage(image, url)
{
	image.src = url;
}


/*
	Creates an "are you sure?" dialogue.
*/
function terere_areyousure_link(message, link)
{
	if (confirm(message))
	{
		document.location = link;
	}
	
	return false;
}


/*
	Updates the page location.
*/
function terere_location(new_location)
{
	document.location = new_location;
	
	return false;
}


/*
	Opens a URL in a new window.
*/
function terere_show_external_resource(url, width, height)
{
	window.open(url,'','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width='+width+',height='+height);
	
	return false;
}


/*
	Called on the card payment form upon submission.
*/
function terere_account_card_submit()
{
	var warning_message = '';

	if (document.getElementById('page_account_card_form_amount').value == '')
	{
		warning_message = 'Please enter the amount that you wish to pay.';
	}
	if (document.getElementById('page_account_card_card_selection').value == 'ignore')
	{
		warning_message = 'Please select a card or enter new card details.';
	}
	if (document.getElementById('page_account_card_card_selection').value == 'new')
	{
		if (document.getElementById('page_account_card_form_card_type').value == '')
			warning_message = 'Please select a card type.';
		if (document.getElementById('page_account_card_form_card_name').value == '')
			warning_message = 'Please enter the name as it appears on the front of your card.';
		if (document.getElementById('page_account_card_form_card_number').value == '')
			warning_message = 'Please enter the your full card number.';
		if (document.getElementById('page_account_card_form_card_cvv').value == '')
			warning_message = 'Please enter your card security digits (either the last three numbers on the back of your card or four numbers printed on the front.)';
		if (document.getElementById('page_account_card_address_selection').value == 'ignore')
			warning_message = 'Please select a billing address or enter new billing address details.';
	}
	
	if (warning_message != '')
	{
		alert(warning_message);
		return false;
	}
	else
	{
		return true;
	}
}


/*
	Called on the card payment form when a card type is selected.
*/
function terere_account_card_type(selected_type)
{
	var card_values = Array('VISA', 'MC', 'MAESTRO', 'AMEX');
	
	for (var i = 0; i < card_values.length; i++)
	{
		if (document.getElementById('page_account_card_type_'+card_values[i]))
			document.getElementById('page_account_card_type_'+card_values[i]).setAttribute('class', 'page_account_card_cardtype_off');
	}

	document.getElementById('page_account_card_type_'+selected_type).setAttribute('class', 'page_account_card_cardtype_on');
	document.getElementById('page_account_card_form_card_type').value = selected_type;
	
	return false;
}


/*
	Called on the card payment form upon card selection.
*/
function terere_account_card_select_card()
{
	if (document.getElementById('page_account_card_card_selection').value == 'new')
	{
		document.getElementById('page_account_card_card_details').style.display = 'block';
	}
	else
	{
		document.getElementById('page_account_card_card_details').style.display = 'none';
	}
		
	terere_account_card_select_address();
		
	return false;
}


/*
	Called on the card payment form upon address selection.
*/
function terere_account_card_select_address()
{
	if (document.getElementById('page_account_card_card_selection').value == 'new')
	{
		if (document.getElementById('page_account_card_address_selection').value == 'new')
		{
			document.getElementById('page_account_card_address_details').style.display = 'block';
		}
		else
		{
			document.getElementById('page_account_card_address_details').style.display = 'none';
		}		
	}
	else
	{
		document.getElementById('page_account_card_address_details').style.display = 'none';
	}
	
	return false;
}

