sections = new Array();
sections["General"] = new Array("BandBio");
sections["News"] = new Array("Date", "Title", "Story");
sections["Shows"] = new Array("Date", "Time", "Venue", "Location", "Notes");
sections["Members"] = new Array("FirstName", "LastName", "Instrument", "Email", "Bio");
sections["Pictures"] = new Array("Name", "Description");
sections["Albums"] = new Array("Name", "Date", "Description");
sections["Tracks"] = new Array("Title", "TrackNo");
sections["GeneralContact"] = new Array("Booking");
sections["GeneralLinks"] = new Array("OtherLinks");

function save(section, id){

	if (section == "GeneralContact") {
		sections["General"] = sections["GeneralContact"];
		section = "General";
	} else if (section == "GeneralLinks") {
		sections["General"] = sections["GeneralLinks"];
		section = "General";
	}
	
	var query = "action=update&section=" + section + "&id=" + id;
	
	for (var i = 0; i < sections[section].length; i++) {
		query += "&" + sections[section][i] + "=" + document.getElementById(sections[section][i]+":"+id).value;
		Element.extend(document.getElementById(sections[section][i]+":"+id)).removeClassName('changed');
	}
	
	
	var success	= function(t){saveComplete(t);}
	var failure	= function(t){failure(t);}

	var update = new Ajax.Request("update.php", {method:'post', postBody:query, onSuccess:success, onFailure:failure});
}

function saveComplete(t){
	alert("Successfully Saved");
}

function del(section, id){
	var answer = confirm ("Are you sure you want to delete this record?")
	if (answer) {
		Element.hide(section + ":" + id);
	
		var query = "action=delete&section=" + section + "&id=" + id;

		var success	= function(t){delComplete(t);}
		var failure	= function(t){failure(t);}

		var del = new Ajax.Request("update.php", {method:'post', postBody:query, onSuccess:success, onFailure:failure});
	}
}	

function delComplete(t){
	//alert(t.responseText);
}

function add(section, page, albumid){
	var query = "action=add&section=" + section;

	if (section == "Tracks") query += "&albumID=" + albumid;
	
	var success	= function(t){addComplete(page, t);}
	var failure	= function(t){failure(t);}
	
	var add = new Ajax.Request("update.php", {method:'post', postBody:query, onSuccess:success, onFailure:failure});
}	

function addComplete(page, t){
	window.location = "default.htm?" + page;
}

function failure(t){
	alert("The operation failed");
}

function addEmail(){
	var query = "action=addEmail&email=" + document.getElementById("email").value;

	var success	= function(t){emailComplete(t);}
	var failure	= function(t){failure(t);}

	var update = new Ajax.Request("update.php", {method:'post', postBody:query, onSuccess:success, onFailure:failure});
}

function emailComplete(t){
	document.getElementById("listMessage").innerHTML = t.responseText;
}


function logout(page){
	window.location = "includes/logout.php?page=" + page;
}

function showChanges(obj){
	Element.extend(obj).addClassName('changed');
}