var activeDiv = "";
function startLoading() {
  Element.show('mainAreaLoading');
  Element.hide('mainAreaInternal');
}
function finishLoading() {
  //Element.show('mainAreaInternal');
  setTimeout("Element.toggle('mainAreaLoading');", 1000);
  setTimeout("Element.show('mainAreaInternal');", 1000);
  setTimeout("loadSidebar();", 1000);
}

function startLoadingPage(div) {
  Element.show(div+'Loading');
  Element.hide(div);
}
function finishLoadingPage() {
  setTimeout("Element.toggle('" + activeDiv + "Loading');", 1000);
  setTimeout("Element.show('" + activeDiv + "');", 1000);
}
function finishLoadingPageNoSleep() {
  setTimeout("Element.toggle('" + activeDiv + "Loading');", 000);
  setTimeout("Element.show('" + activeDiv + "');", 000);
}


function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
	  for (var i=0; i<buttonGroup.length; i++) {
		 if (buttonGroup[i].checked) {
			return buttonGroup[i].value;
		 }
	  }
   } else {
	  if (buttonGroup.checked) { return buttonGroup[0].value; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return "";
} // Ends the "getSelectedRadio" function

function loadContent() {
	startLoading();
	var argv = loadContent.arguments;
	var argc = argv.length;
	var params = "";
	for (var i = 1; i < argc; i++) {
		params += "&arg" + i + "=" + argv[i];
	}
	new Ajax.Updater('mainAreaInternal', 'rpc.php', {
		method: 'post', 
		postBody:'content='+ argv[0] + params  + '&index_ok=true', 
		onComplete: finishLoading
	});
	}

function loadPage() {
	var argv = loadPage.arguments;
	var argc = argv.length;
	var params = "";
	activeDiv = argv[0];
	for (var i = 1; i < argc-1; i++) {
		params += "&arg" + i+ "=" + argv[i+1];
	}
	startLoadingPage(argv[0]);
	new Ajax.Updater(argv[0], argv[1], {
		method: 'post', 
		postBody: 'index_ok=true' + params,
		onComplete: finishLoadingPage
	});
}

function loadPageNoSleep() {
	var argv = loadPageNoSleep.arguments;
	var argc = argv.length;
	var params = "";
	activeDiv = argv[0];
	for (var i = 1; i < argc-1; i++) {
		params += "&arg" + i+ "=" + argv[i+1];
	}
	startLoadingPage(argv[0]);
	new Ajax.Updater(argv[0], argv[1], {
		method: 'post', 
		postBody: 'index_ok=true' + params,
		onComplete: finishLoadingPageNoSleep
	});
}

function loadSidebar() {
	new Ajax.Updater('navigation', 'sidebar.php', {method: 'post', postBody:'content=1'});
}