/// Javascript function to sort unordered lists ////////////////////////////////////////////////

function sortUnorderedList(ul, sortDescending) {  
	if(typeof ul == "string")
		ul = document.getElementById(ul);  
	// Idiot-proof, remove if you want  
	if(!ul) {    
		alert("The UL object is null!");    
		return;  
	}  
	// Get the list items and setup an array for sorting
	var lis = ul.getElementsByTagName("LI");
	var vals = [];
	// Populate the array
	for(var i = 0, l = lis.length; i < l; i++)
		vals.push(lis[i].innerHTML);
	// Sort it
	vals.sort();
	// Sometimes you gotta DESC
	if(sortDescending)
		vals.reverse();
	// Change the list on the page
	for(var i = 0, l = lis.length; i < l; i++)
		lis[i].innerHTML = vals[i];
}


/// Used to hide elements ///////////////////////////////////////////////////////////////////
var clicks = new Array();
function showhide(varID) {
		if (typeof clicks[varID] == 'undefined'){
			document.getElementById(varID).style.display = 'block';
			clicks[varID] = 1
		} else if (clicks[varID] == 0){
			document.getElementById(varID).style.display = 'block';
			clicks[varID] = 1
		} else {
			document.getElementById(varID).style.display = 'none';
			clicks[varID] = 0
		}		
}

/// Javascript function to use for setting max length of a text area. //////////////////////// 
/// N.B.: Dosen't work if copy & paste used! Found at: http://psacake.com/web/js.asp /////////

function imposeMaxLength(Object, MaxLen) {
	return (Object.value.length <= MaxLen);
}

/// Gallery show/hide functions //////////////////////////////////////////////////////////////

function clearinfo()  {
	document.addphoto.newgallery.value = ''
}
     
function newgaltext()  {
	if (document.addphoto.addgallery.value == '999') {
		document.getElementById('newspan').style.display = 'block';
		document.addphoto.newgallery.value = 'Enter name for new gallery';
	} else {
		document.getElementById('newspan').style.display = 'none';
		document.addphoto.newgallery.value = '';
	}
}

function editclearinfo()  {
	document.addphoto.newgallery.value = ''
}
     
function editgaltext()  {
	if (document.editphoto.newgallery.value == '999') {
		document.getElementById('newspan').style.display = 'block';
		document.editphoto.newgallery.value = 'Enter name for new gallery';
	} else {
		document.getElementById('newspan').style.display = 'none';
		document.editphoto.newgallery.value = '';
	}
}

