
var objCheckout = function() {
	
	var RADIO_ON_CLASS = 'large-radio large-radio-on',
	    RADIO_OFF_CLASS = 'large-radio';
	    
	var gift_control = 'gift-controls-email';
	
	return {
		
		init:function() {
		},
		
		toggleLoginControls:function(strOn,strOff) {
			document.getElementById(strOn + '-label').className = RADIO_ON_CLASS;
			document.getElementById(strOff + '-label').className = RADIO_OFF_CLASS;
			document.getElementById(strOn + '-customer').style.display = 'block';
			document.getElementById(strOff + '-customer').style.display = 'none';
		},
		
		toggleReviewPrePayControls:function() {
			document.getElementById('prepay-label').className = RADIO_ON_CLASS;
			// document.getElementById('gift-label').className = RADIO_OFF_CLASS;
			document.getElementById('booking-label').className = RADIO_OFF_CLASS;
			// document.getElementById('gift-controls').style.display = 'none';
			// document.getElementById('gift-controls-email').style.display = 'none';
			// document.getElementById('gift-controls-post').style.display = 'none';
			document.getElementById('booking-controls').style.display = 'none';
		},
		
		toggleReviewGiftControls:function() {
			document.getElementById('prepay-label').className = RADIO_OFF_CLASS;
			document.getElementById('gift-label').className = RADIO_ON_CLASS;
			document.getElementById('booking-label').className = RADIO_OFF_CLASS;
			document.getElementById('gift-controls').style.display = 'block';
			if (gift_control == 'gift-controls-email') this.toggleReviewGiftEmailControls();
			if (gift_control == 'gift-controls-post') this.toggleReviewGiftPostControls();
			document.getElementById('booking-controls').style.display = 'none';
		},
		
		toggleReviewBookingControls:function() {
			document.getElementById('prepay-label').className = RADIO_OFF_CLASS;
			// document.getElementById('gift-label').className = RADIO_OFF_CLASS;
			document.getElementById('booking-label').className = RADIO_ON_CLASS;
			// document.getElementById('gift-controls').style.display = 'none';
			// document.getElementById('gift-controls-email').style.display = 'none';
			// document.getElementById('gift-controls-post').style.display = 'none';
			document.getElementById('booking-controls').style.display = 'block';
		},
		
		toggleReviewGiftEmailControls:function() {
			gift_control = 'gift-controls-email';
			document.getElementById('email-label').className = RADIO_ON_CLASS;
			document.getElementById('post-label').className = RADIO_OFF_CLASS;
			document.getElementById('gift-controls-email').style.display = 'block';
			document.getElementById('gift-controls-post').style.display = 'none';
		},
		
		toggleReviewGiftPostControls:function() {
			gift_control = 'gift-controls-post';
			document.getElementById('email-label').className = RADIO_OFF_CLASS;
			document.getElementById('post-label').className = RADIO_ON_CLASS;
			document.getElementById('gift-controls-email').style.display = 'none';
			document.getElementById('gift-controls-post').style.display = 'block';
		},
		
		toggleVoucherType:function( selectedElement ) {
			switch ( selectedElement ) {
				case 'flatRate':
					document.getElementById('flatRate-label').className = 'large-radio large-radio-on';
					document.getElementById('treatment-label').className = 'large-radio';
					
					document.getElementById('vouchers').style.display = 'block';
					document.getElementById('packagesContainer').style.display = 'none';
					break;
				
				case 'treatment':
					document.getElementById('flatRate-label').className = 'large-radio';
					document.getElementById('treatment-label').className = 'large-radio large-radio-on';
					
					document.getElementById('vouchers').style.display = 'none';
					document.getElementById('packagesContainer').style.display = 'block';
					break;
				
				default:
					alert('fail');
			}
		},
		
		toggleCVC2Hint:function() {
			var elDiv = document.getElementById('cvv2Explain');
			elDiv.style.display = (elDiv.style.display=='none') ? 'block' : 'none';
		},
		
		populateProducts:function() {
			var arr = arrPackages[Forms.Select.getSelectedValues('packages')],
			    elDiv = document.getElementById('pricing'),
			    elSel = document.getElementById('products');
			
			if( typeof(arr) == 'undefined' ) {
				elSel.style.display = 'block';
				Forms.Select.purge('products');
				Forms.Select.populate('products', ['-- no products available --']);
				elSel.disabled = true;
			}else{
				elSel.disabled = false;
				elSel.style.display = 'block';
				Forms.Select.purge('products');
				if (arr.length>1) {
					Forms.Select.populate('products', arr);
				}else{
					Forms.Select.purge('products');
					Forms.Select.populate('products', ['-- no products available --']);
					elSel.disabled = true;
				}
			}
			elDiv.innerHTML = '';
			elDiv.style.display = 'none';
		},
		
		populateProductOptions:function( mode ) {
			if(!mode) var mode = 1;
			var arr = arrProducts[Forms.Select.getSelectedValues('products')],
			    elDiv = document.getElementById('pricing'),
			    strCode = '<p><strong>Choose duration:</strong></p>';
			for (var i = 0; i < arr.length; i++) {
				strCode += '<div class="left"><div class="large duration">' + arr[i][1] + '</div><form action="/purchase.cfm" method="get"><input type="hidden" name="mode" value="'+mode+'" class="hidden" /><input type="hidden" name="pid" value="' + Forms.Select.getSelectedValues('products') + '" class="hidden" /><input type="hidden" name="oid" value="' + arr[i][0] + '"  class="hidden" /><input type="submit" name="cart" value="Add" class="small-button right" style="margin-right:14px;" /></form></div>';
			}
			elDiv.innerHTML = strCode;
			elDiv.style.display = 'block';
		},
		
		addVoucher:function( selectedVoucherId ) {
			switch ( selectedVoucherId ) {
				// Arbitrary value
				case 'x':
					break;
				// Any set value
				default:
					document.getElementById('pricing').innerHTML = '<form name="voucherAdd" action="/purchase.cfm" method="get"><input type="hidden" name="mode" value="2" class="hidden" /><input type="hidden" name="pid" value="' + selectedVoucherId + '" class="hidden" /><input type="hidden" name="cart" value="Add" /></form>';
					document.forms['voucherAdd'].submit();
			}
		}
		
	}
	
}();

objCheckout.init();

