// copy address details into delivery address fields...
function copyAddressToDelivery()
{
	// rewrite this you lazy ****. 
	// note to self:
	// surely it took longer to type out that it would to write a nice loop (like above)
	$('#cust_del_title').attr('value', 		$('#cust_title').attr('value'));
	$('#cust_del_first_name').attr('value', $('#cust_first_name').attr('value'));
	$('#cust_del_last_name').attr('value', 	$('#cust_last_name').attr('value'));
	$('#cust_del_address1').attr('value', 	$('#cust_address1').attr('value'));
	$('#cust_del_address2').attr('value', 	$('#cust_address2').attr('value'));
	$('#cust_del_town').attr('value', 		$('#cust_town').attr('value'));
	$('#cust_del_county').attr('value', 	$('#cust_county').attr('value'));
	$('#cust_del_postcode').attr('value', 	$('#cust_postcode').attr('value'));
	$('#cust_del_country_id').attr('value', $('#cust_country_id').attr('value'));
	$('#cust_del_telephone').attr('value', 	$('#cust_telephone').attr('value'));
	$('#cust_del_mobile').attr('value', 	$('#cust_mobile').attr('value'));
	$('#cust_del_fax').attr('value', 		$('#cust_fax').attr('value'));
	$('#cust_del_email').attr('value', 		$('#cust_email').attr('value'));
	return false; 
}





// populate delivery address from previous address list
function populateDeliveryAddress(whichAddress)
{
	$.getJSON('/p/getDeliveryAddress.php?address_id=' + whichAddress, function(data)
	{
		var theForm = $('#customerRegistrationForm'); 
		for (var i=0; i<data.length; i++) 
		{ 
		    for ( key in data[i] )
		    { 
		            var value = eval('data[i].' + key); // the cheek ;)
		            key = key.replace('cust_', 'cust_del_');
		            $('#' + key, theForm).attr({value:value}); 
		    } 
		}
	});
	// lush!!!
}






function helpTip(title, content)
{
	$('#help').html('').append('<h4>' + title + '</h4>').append('<p>' + content + '</p>');
	$('#helpWrap').css({'top':'25%'}).fadeIn(500);
	$('#helpClose').click(function()
	{
		$('#helpWrap').fadeOut(100).css({'top':'-500px'});
	});
	return true;
}





function showIt(what)
{
	if ( $(what).css('display') == 'none' )
	{
		$(what).fadeIn(200);
	}
	return;
}
function hideIt(what)
{
	if ( $(what).css('display') != 'none' )
	{
		$(what).fadeOut(200);
	}
	return;
}



function stuLight(wtf)
{
	$(wtf)
	.animate({backgroundColor:'#EC008B', color:'#fff'}, 100)
	.animate({backgroundColor:'#fff', color:'#444'}, 100)
	.animate({backgroundColor:'#EC008B', color:'#fff'}, 100)
	.animate({backgroundColor:'#fff', color:'#444'}, 100)
	.animate({backgroundColor:'#EC008B', color:'#fff'}, 100)
	.animate({backgroundColor:'#fff', color:'#444'}, 1000);
	
	return wtf;
}









function checkIt()
{

	
	var c = document.getElementsByName('payment_option');
	var cok = false;
	for(i=0;i<c.length;i++)
	{
		if ( c[i].checked )
		{
			cok = true;
		}
	}	
	if ( cok == false )
	{
		alert('Please choose a payment option before continuing.');
		return false;
	}
	
	
	if($('#age18').attr('checked') != true)
	{
		alert('please confirm you are at lease 18 years old');
		return false;
	}
	
	if ( $('#cust_first_name').val() == '' )
	{
		alert('please enter your first name');
		return false;
	}

	if ( $('#cust_last_name').val() == '' )
	{
		alert('please enter your last name');
		return false;
	}

	if ( $('#cust_telephone').val() == '' )
	{
		alert('please enter your telephone number');
		return false;
	}

	if ( $('#cust_email').val() == '' )
	{
		alert('please enter your email address');
		return false;
	}
	
	if ( document.getElementById('agree') )
	{
		if ( !document.getElementById('agree').checked )
		{
			alert('You must agree to the terms and conditions before continuing.');
			return false;
		}
	}
	
}