
$(function() {
	init();
	$('#repeatType').change();
});

// init
// ---------------------------------------------------------- //
function init() {
	//set default options. all are on by default so toggle the one you want to hide
	$('#repeatType').change(function() {
		if ($('#repeatType').val() == "0") {
			showSingleOptions();
		} else {
			showRepeatOptions();
		}
	});
	
	$('#discountType').change(function() {
		if ($('#discountType').val() == "1") {
			showDollarDiscount();
		} else {
			showPercentDiscount();
		}
	});
	
	resetDiscountType();
	
	
	/*     reg page */
	$('#copyFromAbove').click(function() {
		$('#bownerName').val($('#name').val());
		$('#baddress').val($('#address').val());		
		$('#bcity').val($('#city').val());
		$('#bstate').val($('#state').val());
		$('#bzip').val($('#zip').val());
		return false;
	});
};


function showRepeatOptions() {
	hideSingleOptions();
	$('#repeatStartDate').parent().show();
	$('#repeatStartDate').parent().next().show();
	$('#repeatEndDate').parent().show();
	$('#repeatEndDate').parent().next().show();
	$('#repeatStartTimeHours').parent().show();
	$('#repeatStartTimeHours').parent().next().show();
	$('#repeatEndTimeHours').parent().show();
	$('#repeatEndTimeHours').parent().next().show();
}

function hideRepeatOptions() {
	$('#repeatStartDate').parent().hide();
	$('#repeatStartDate').parent().next().hide();
	$('#repeatEndDate').parent().hide();
	$('#repeatEndDate').parent().next().hide();
	$('#repeatStartTimeHours').parent().hide();
	$('#repeatStartTimeHours').parent().next().hide();
	$('#repeatEndTimeHours').parent().hide();
	$('#repeatEndTimeHours').parent().next().hide();
	
	$('#repeatStartDate').val("");
	$('#repeatEndDate').val("");
	$('#repeatStartTimeHours').val("1");
	$('#repeatEndTimeHours').val("1");
}

function showSingleOptions() {
	hideRepeatOptions();
	$('#startDateDate').parent().show();
	$('#startDateDate').parent().next().show();
	$('#endDateDate').parent().show();
	$('#endDateDate').parent().next().show();
}

function hideSingleOptions() {
	$('#startDateDate').parent().hide();
	$('#startDateDate').parent().next().hide();
	$('#endDateDate').parent().hide();
	$('#endDateDate').parent().next().hide();
	$('#endDateDate').val("");
	$('#startDateDate').val("");
}


//----------------------------
// for the dicountType toggle on coupons
//----------------------------
function showDollarDiscount() {
    $("#percentDiscount").parent().hide();
	$("#dollarDiscount").parent().show();
}

function showPercentDiscount() {
    $("#percentDiscount").parent().show();
	$("#dollarDiscount").parent().hide();
}

function resetDiscountType() {
	$("#dollarDiscount").parent().hide();
	$("#percentDiscount").parent().hide();
	
	if ($("#discountType").val() == 1) {
		showDollarDiscount();
	} else if ($("#discountType").val() == 2) {
		showPercentDiscount();
	}
}
