
function album_getPhotos(album_id, div) {
	getData('http://'+location.host+'/admin/cog.php/albums/editAlbum/'+album_id, div);
		var a = document.getElementById('sortSaveBtn');
		if (a) 
			a.style.visibility = 'hidden';
		var b = document.getElementById('sortLetBtn');
		if (b) 
			b.style.visibility = "visible";	
}
function savePhoto(photoID){
	// Get the vars
	var c = document.getElementById('photoAlt_'+photoID);
	if (!c) alert('no alt');
	var d = document.getElementById('photoCopy_'+photoID);
	if (!d) alert('no copy');
	
	var q = 'http://'+location.host+'/admin/cog.php/albums/savePhoto';
	var p = 'image_id='+photoID+'&image_alt='+escape(c.value)+'&image_copyright='+ escape(d.value);
	
	
	postData(q, p, 'photoEdit'+photoID);
}		
function savePhotoNoAlbum(photoID){
	// Get the vars
	var a = document.getElementById('photoCaption_'+photoID);
	if (!a) alert('no caption');
	var b = document.getElementById('photoName_'+photoID);
	if (!b) alert('no name');
	var c = document.getElementById('photoAlt_'+photoID);
	if (!c) alert('no alt');
	var d = document.getElementById('photoCopy_'+photoID);
	if (!d) alert('no copy');
	
	var q = sprintf('http://'+location.host+'/core/cog.php?page=photos&op=save&photo_id=%d',photoID );
	var p = 'caption='+escape(a.value)+'&name='+escape(b.value)+'&alt='+escape(c.value)+'&copyright='+ escape(d.value);
	
	
	postData(q, p, 'photoEdit'+photoID);
}		

function savePhotoOrder(album_id,list,prefix){
	var q = sprintf('http://'+location.host+'/admin/cog.php/albums/saveOrder/%d',album_id);
	var p = 'list='+escape(list)+'&prefix='+escape(prefix);
	postData(q, p, 'album_photos');
	
		var a = document.getElementById('sortSaveBtn');
		if (a) 
			a.style.visibility = 'hidden';
		var b = document.getElementById('sortLetBtn');
		if (b) 
			b.style.visibility = "visible";	

}
	var dragsort = ToolMan.dragsort()
	var junkdrawer = ToolMan.junkdrawer()

function initSort(list) {

		dragsort.makeListSortable(document.getElementById(list),
				saveOrder)
		document.getElementById(list).className += " draggable";	
				
		var a = document.getElementById('sortSaveBtn');
		if (a) 
			a.style.visibility = 'visible';
		var b = document.getElementById('sortLetBtn');
		if (b) 
			b.style.visibility = "hidden";
		

}


function saveOrder(item) {
	var group = item.toolManDragGroup
	var list = group.element.parentNode
	var id = list.getAttribute("id")
	if (id == null) return
	group.register('dragend', function() {
		ToolMan.cookies().set("list-" + id, 
				junkdrawer.serializeList(list), 365)
	})
}