/**
 * CartHelper class to help with some of our custom functionality that requires javascript
 * 
 * @author Deric
 * @version 1.0
 */
var CartHelper = {
	/**
	 * Copy billing fields to the respective shipping fields
	 * 
	 * @returns void
	 */
	CopyBillingToShipping: function(elem) {
		// Go through each billing element and copy it over
		$.each(
			$("*").children("input,select"),
			function(idx, e) {
				// See if it's bad
				var re = /^Billing_([a-zA-Z0-9_]+)$/;
				var m = e.id.match(re);
				if (m && m[1].substr(-5) != 'Error') {
					// If it's checked copy over and disable
					if (elem.checked) {
						$('#Shipping_' + m[1]).attr('value', e.value);
						$('#Shipping_' + m[1]).attr('readonly', true);
					}
					
					// If it's unchecked, re-enable
					else {
						$('#Shipping_' + m[1]).attr('readonly', false);
					}
				}
			}
		);
	},
	
	/**
	 * Handle country changing and showing or hiding province field
	 * 
	 * @returns void
	 */
	CountryChanged: function(val) {
		if ($('#' + val + '_Country').attr('value') == 'US') {
			$('#' + val + '_State_Container').show();
			$('#' + val + '_Province_Container').hide();
		}
		else {
			$('#' + val + '_State_Container').hide();
			$('#' + val + '_Province_Container').show();
		}
	}
}
