function bindModuleAreaParentWithClass( obj, className) {
	var match = new RegExp( '(^|\\s)' + className + '(\\s|$)');
	while ( obj && (!obj.className || !match.test( obj.className)))
		obj = obj.parentNode;
	return obj;
}

function bindModuleArea( li) {
	if ( typeof li == 'string')
		li = document.getElementById( li);
	requiredBind( li);
	var moduleList = bindModuleAreaParentWithClass( li, 'moduleList');
	if ( moduleList) {
		if ( moduleList.tagName == 'LI')
			moduleList = moduleList.parentNode;
		var buttons = moduleList.getElementsByTagName( 'a');
		var matches;
		for ( var b = 0; b < buttons.length; b++) {
			// Is it an up button
			if ( buttons[b].className && buttons[b].className.match( /(^|\s)up(\s|$)/)) {
				li = bindModuleAreaParentWithClass( buttons[b], 'moduleList');
				buttons[b].style.display = ( li.previousSibling ? 'inline' : 'none');
			}
			else if ( buttons[b].className && buttons[b].className.match( /(^|\s)down(\s|$)/)) {
				li = bindModuleAreaParentWithClass( buttons[b], 'moduleList');
				buttons[b].style.display = ( li.nextSibling ? 'inline' : 'none');
			}
			else if ( buttons[b].className && ( matches = buttons[b].className.match( /(^|\s)(\w+ModulesList)(\s|$)/))) {
				li = bindModuleAreaParentWithClass( buttons[b], 'moduleList');
				buttons[b].style.display = ( matches[2] != li.parentNode.id ? 'inline' : 'none');
			}
		}
	}
}
function showModuleContent( obj, uid) {
	try {
		var buttonArea = bindModuleAreaParentWithClass( obj, 'buttonRow');
		if ( buttonArea.showingContent) {
			buttonArea.showingContent.parentNode.removeChild( buttonArea.showingContent);
			buttonArea.showingContent = null;
		}
		else {
			var target = document.createElement( 'div');
			target.className = 'moduleContent';
			buttonArea.parentNode.insertBefore( target, buttonArea);
			buttonArea.showingContent = target;
			doAjax( '/fan-zone/classic-photos/u10?AJmenuid83detail=display&uid=' + uid, function() {
				var scriptExpr = "<script[^>]*>(.|\s|\n|\r)*?</" + "script>";
				target.innerHTML = xmlhttp.responseText.replace( new RegExp( scriptExpr, "img"), "");
				// Execute any JS returned
				var matches = xmlhttp.responseText.match( new RegExp( scriptExpr, "img"));
				// Flash javascript may really mess things up in the admin, so dont execute Javascription in the module area
				if ( false && matches) {
					var numMatches = matches.length;
					for (var i = 0; i < numMatches; i++) {
						var s = matches[i].replace(/<script[^>]*>[\s\r\n]*(<\!--)?|(-->)?[\s\r\n]*<\/script>/img, "");
						eval( s);
					}
				}
			});
		}
		while ( obj.firstChild)
			obj.removeChild( obj.firstChild);
		obj.appendChild( document.createTextNode( buttonArea.showingContent ? 'Hide' : 'Content'));
	}
	catch( error) {
		alert( error);
	}
	return false;
}
function hideShowModuleList( hideShow) {
	var obj = document.getElementById( 'addModules');
	if ( typeof hideShow == 'undefined')
		hideShow = obj.style.display == 'none';
	obj.style.display = hideShow ? 'block' : 'none';
}
function addModule( obj, addToListID) {
	try {
		var moduleType;
		if ( obj.tagName == 'SELECT') {
			moduleType = obj.options[ obj.selectedIndex].value;
			obj.selectedIndex = 0;
		}
		else // assume is a link, use classname as moduleType;
			moduleType = obj.className;
		
		var addToList = document.getElementById( addToListID);
		if ( addToList) {
			hideShowModuleList( false);
			var li = document.createElement( 'li');
			li.className = 'moduleList';
			li.appendChild( document.createTextNode( 'Loading...'));
			addToList.appendChild( li);
			doAjax( '/fan-zone/classic-photos/u10?AJmenuid83detail=edit&module=' + moduleType + '&position=' + addToList.id.replace( /ModulesList$/, ''), function() {
				li.innerHTML = xmlhttp.responseText;
				bindModuleArea( li);
			});
		}
	}
	catch( error) {
		alert( error);
	}
	return false;
}
function editModule( obj, uid) {
	try {
		var li = obj.parentNode;
		while ( li && li.nodeName != 'LI')
			li = li.parentNode;
		if ( li)
			doAjax( '/fan-zone/classic-photos/u10?AJmenuid83detail=edit&uid=' + uid, function() {
				li.innerHTML = xmlhttp.responseText;
				bindModuleArea( li);
			});
	}
	catch( error) {
		alert( error);
	}
	return false;
}
function saveModule( obj, uid) {
	try {
		var li = obj.parentNode;
		while ( li && li.nodeName != 'LI')
			li = li.parentNode;
		if ( li)
			doAjax( '/fan-zone/classic-photos/u10?AJmenuid83detail=save&uid=' + uid, function() {
				li.innerHTML = xmlhttp.responseText;
				bindModuleArea( li);
			}, tboxGetFormData( li));
	}
	catch( error) {
		alert( error);
	}
	return false;
}
function deleteModule( obj, uid) {
	try {
		var li = obj.parentNode;
		while ( li && li.nodeName != 'LI')
			li = li.parentNode;
		if ( li && confirm( 'Really delete this module and it\'s content?'))
			doAjax( '/fan-zone/classic-photos/u10?AJmenuid83detail=delete&uid=' + uid, function() {
				var parentNode = li.parentNode;
				parentNode.removeChild( li);
				li = null;
				bindModuleArea( parentNode);
			});
	}
	catch( error) {
		alert( error);
	}
	return false;
}
function movePositionModule( obj, uid, destPosition) {
	var dest = document.getElementById( destPosition + 'ModulesList');
	if ( dest) {
		obj = bindModuleAreaParentWithClass( obj, 'moduleList');
		var oldParent = obj.parentNode;
		doAjax( '/fan-zone/classic-photos/u10?AJmenuid83detail=moveposition&uid=' + uid + '&position=' + destPosition, function() {
			dest.appendChild( obj);
			bindModuleArea( oldParent);
			bindModuleArea( dest);
		});
	}
	return false;
}
function moveUpModule( obj, uid) {
	obj = bindModuleAreaParentWithClass( obj, 'moduleList');
	if ( obj.previousSibling) {
		obj.parentNode.insertBefore( obj, obj.previousSibling);
		doAjax( '/fan-zone/classic-photos/u10?AJmenuid83detail=moveup&uid=' + uid, function() {
			bindModuleArea( obj);
		});
	}
	return false;
}
function moveDownModule( obj, uid) {
	obj = bindModuleAreaParentWithClass( obj, 'moduleList');
	if ( obj.nextSibling) {
		if ( obj.nextSibling.nextSibling)
			obj.parentNode.insertBefore( obj, obj.nextSibling.nextSibling);
		else
			obj.parentNode.appendChild( obj);
		doAjax( '/fan-zone/classic-photos/u10?AJmenuid83detail=movedown&uid=' + uid, function() {
			bindModuleArea( obj);
		});
	}
	return false;
}
