// handles delete of all db objects
// params: table name, url to redirect to
// returns: none
function db_delete(table_name, url) {
	// display the confirm box
	var confirm_delete = confirm('Are you sure you want to delete this ' + table_name + '?');

	// if it is confirmed go to this url
	if (confirm_delete)
		location.replace('/admin/'+url);

}


// opens the shopping cart
// params: none
// returns: none
function openCart() {
	var url="/dialogs/view_cart.php";

	window.open(url, 'shopping_cart', 'scrollbars=no,resizable=yes,toolbar=no,width=425,height=425');
}


// opens the play media dialog
// params: file_id
// returns: none
function openPlayMedia(file_id) {
	var url="/dialogs/play_media.php?id="+file_id;

	window.open(url, 'play_media', 'scrollbars=no,resizable=yes,toolbar=no,width=300,height=150');
}


// opens the delete file dialog
// params: file_id
// returns: none
function openFileDelete(file_id) {
	var url="/dialogs/delete_file.php?id="+file_id;

	window.open(url, 'delete_file', 'scrollbars=no,resizable=yes,toolbar=no,width=300,height=150');
}


// opens the add file dialog
// params: table to assoc to, id to assoc to
// returns: none
function openFileAdd(assoc_table, assoc_id) {
	var url="/dialogs/add_file.php?assoc_table="+assoc_table+"&assoc_id="+assoc_id;

	window.open(url, 'add_file', 'scrollbars=no,resizable=yes,toolbar=no,width=300,height=250');
}


// opens the download audio dialog
// params: none
// returns: none
function openDownloadAudio() {
	var url="/dialogs/download_audio.php";

	window.open(url, 'download_audio', 'scrollbars=no,resizable=yes,toolbar=no,width=300,height=250');
}



// opens the edit personal information window
// params: "personal", or "billing"
// returns: none
function openEditInformation(infoType) {
	var url;

	if (infoType == "personal")
		 url = "/dialogs/edit_personal_info.php";
	else if (infoType == "billing")
		 url = "/dialogs/edit_billing_info.php";
		
	window.open(url, 'edit_info', 'scrollbars=no,resizable=yes,toolbar=no,width=400,height=400');
}


// Changes the shipping information to be the same as the billing
// params: none
// returns: none
function changeShippingInfo() {
	// check if it has been checked
	var checkBox = document.billing.same_as_billing

	if (checkBox.checked == true) {
		// make the shipping same as the billing
		document.billing.x_ship_to_first_name.value = document.billing.x_first_name.value;
		document.billing.x_ship_to_last_name.value = document.billing.x_last_name.value;
		document.billing.x_ship_to_address.value = document.billing.x_address.value;
		document.billing.x_ship_to_city.value = document.billing.x_city.value;
		document.billing.x_ship_to_state.value = document.billing.x_state.value;
		document.billing.x_ship_to_zip.value = document.billing.x_zip.value;
		document.billing.x_ship_to_country.value = document.billing.x_country.value;

	} else {
		// clear the form
		document.billing.x_ship_to_first_name.value = ""; 
		document.billing.x_ship_to_last_name.value = "";
		document.billing.x_ship_to_address.value = "";
		document.billing.x_ship_to_city.value = "";
		document.billing.x_ship_to_state.value = "";
		document.billing.x_ship_to_zip.value = "";
		document.billing.x_ship_to_country.value = "";

	}
}
