var toCheckout = new Class({
	showLoginForm: function() {
		$('to_checkout_address_login_form').setStyle('display', 'block');
		$('to_checkout_address_with_account_form').setStyle('display', 'none');
		$('to_checkout_address_without_account_form').setStyle('display', 'none');
	},
	
	showWithAccountForm: function() {
		$('to_checkout_address_login_form').setStyle('display', 'none');
		$('to_checkout_address_with_account_form').setStyle('display', 'block');
		$('to_checkout_address_without_account_form').setStyle('display', 'none');
	},
	
	showWithoutAccountForm: function() {
		$('to_checkout_address_login_form').setStyle('display', 'none');
		$('to_checkout_address_with_account_form').setStyle('display', 'none');
		$('to_checkout_address_without_account_form').setStyle('display', 'block');
	},
	
	toggleDeliveryForm: function(target, radio) {
		if (radio.value == 'same') {
			$('to_checkout_'+target+'_diff_form').setStyle('display', 'none');
		} else {
			$('to_checkout_'+target+'_diff_form').setStyle('display', 'block');
		}
	},

	toggleDebitForm: function(radio) {
		if (radio.value == 'debit') {
			$('to_checkout_forms_debit').setStyle('display', 'block');
		} else {
			$('to_checkout_forms_debit').setStyle('display', 'none');
		}
	},

	displayForm: function(type) {
		$('to_checkout_address_'+type).setStyle('display', 'none');
		$('to_checkout_address_'+type+'_form').setStyle('display', 'block');
	},

	changeForm: function(type) {
		$('to_checkout_address_'+type).setStyle('display', 'block');
		$('to_checkout_address_'+type+'_form').setStyle('display', 'none');
		$('to_checkout_address_'+type+'_changed').value = 1;
	},

	cancelForm: function(type, display) {
		if (typeof(display) == 'undefined') display = 'block'
		$('to_checkout_address_'+type).setStyle('display', display);
		$('to_checkout_address_'+type+'_form').setStyle('display', 'none');
	},
	
	redirectTo: function(url) {
		window.location = url;
	}
});

window.addEvent('domready', function() {
	toCheckoutObject = new toCheckout();

		// display user data forms depending of selection
	/*
	$$('.to_form_general').each(function(item, index) {
		if (item.checked == true) {
			switch (item.value) {
				//case 'login':
				//	toCheckoutObject.showLoginForm();
				//	break;
				//case 'withAccount':
				//	toCheckoutObject.showWithAccountForm();
				//	break;
				case 'withoutAccount':
					toCheckoutObject.showWithoutAccountForm();
					break;
			}
		}
	});
	*/
	$$('.to_checkout_delivery_form_select').each(function(item, index) {
		if (item.checked == true) {
			toCheckoutObject.toggleDeliveryForm('withoutAccount', item);
		}
	});

		// display debit form if selected
	if ($('overview_payment_debit')) {
		if ($('overview_payment_debit').checked == true) {
			$('to_checkout_forms_debit').setStyle('display', 'block');
		} else {
			$('to_checkout_forms_debit').setStyle('display', 'none');
		}
	}
	
	$$('.to_checkout_delivery_form_select').each(function(item, index) {
		if (item.value == 'diff' && item.checked == true) {
			$('to_checkout_'+item.id+'_form').setStyle('display', 'block');
		}
	});
});

