$(document).ready(function() {
	// create our dialog for setting the ccbill id
	$("#ccbIdDlg").dialog({
		autoOpen: false,
		dialogClass: "ccbIdDlg",
		height: 70,
		hide: 'scale',
		modal: true,
		position: ['center', 'top'],
		resizable: false,
		show: 'slide',
		title: "Set Your CCBill ID",
		width: 400,
		beforeclose: function(e, ui) {
			if ($("#ccbill_id").val() == '') {
				alert('You must set your ccbill id');
				return false;
			}
		}
	});
	
	// show the dialog or show the bar w/ the current affil id depending on if we have an id or not
	if ($('#ccbill_id').val() == '') {
		$("#ccbIdDlg").dialog("open");
	} else {
		$("#currentCCBId").show();
	}
	
	// let our code now the form is being submitted via ajax
	// setup the form used to set the ccbill id to be submitted w/ ajax and the callback that's fired when successfully submitted
	$("#ccbillIdForm").ajaxForm(function() {
		// set ccbill id
		$("#ccbill_id").val($("#ccbill_id_entry").val());
		
		// they must set an id
		if ($("#ccbill_id").val() == '') {
			alert('You must set your ccbill id!');
		} else {
			// refresh the page if they set an id
			location.href=location.href;
		}
	}).submit(function() {
		$("#ccbIdDo").val("set_ccbill_id_ajax");
	});
	
	// make the change link pop the dialog
	$("#setCCBIdLink").click(function(e) {
		$("#ccbIdDlg").dialog("open");
		
		e.preventDefault();
	});
});

