	function ShowSubMenuOptions() {

		var obj2 = document.getElementById("sublevel");

		obj2.className = "showopt";

	}

	

	function HideSubMenuOptions() {

		var obj2 = document.getElementById("sublevel");

		obj2.className = "hiddenopt";

	}
	
	function ShowTopMenuOptions() {

		var obj2 = document.getElementById("toplevel");

		obj2.className = "showopt";

	}

	

	function HideTopMenuOptions() {

		var obj2 = document.getElementById("toplevel");

		obj2.className = "hiddenopt";

	}

	

	function ToggleMenuOpts(thisobj) {

		var obj = thisobj;
		
				if (obj.value == "submenu"){
					
					ShowSubMenuOptions();
					HideTopMenuOptions();
				}
				else if (obj.value == "toplevel"){
					ShowTopMenuOptions();
					HideSubMenuOptions();
				}
				else if (obj.value == "unlinked"){
					HideTopMenuOptions();
					HideSubMenuOptions();
				}

	}
	
	// Confirm delete
function askOK()
{
    if (confirm('Are you sure you want to delete this item?')) return true;
    else return false;
}

function askOKdownload()
{
    if (confirm('Are you sure you want to delete the selected downloads?')) return true;
    else return false;
}

function askOKtest()
{
    if (confirm('Are you sure you want to delete the selected testimonials?')) return true;
    else return false;
}

function askOKcat()
{
    if (confirm('Are you sure you want to delete this category?\nPlease ensure there are no products in this category or they will be lost!')) return true;
    else return false;
}

function askOKrow()
{
    if (confirm('Are you sure you want to delete this row?')) return true;
    else return false;
}

	// Confirm delete
function removeCheck()
{
    if (confirm('Are you sure you want to remove this development?')) return true;
    else return false;
}

	// Confirm delete
function removeUser()
{
    if (confirm('Are you sure you want to delete this user?')) return true;
    else return false;
}

function createRequestObject() {
	var ro;
	var browser = navigator.appName;
	if (browser == "Microsoft Internet Explorer"){
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else {
		ro = new XMLHttpRequest();
	}
	return ro;
}

var http = createRequestObject();

function makeRequest(){
	http.open('get', 'http://'+window.location.hostname+'/admin/module_tablebuilder/rpc.php/example.xml');
	
	http.onreadystatechange = processResponse;
	http.send(null);
}

function sndReq(action) {
	http.open('get', 'http://'+window.location.hostname+'/admin/module_tablebuilder/rpc.php?action='+action);
 
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function sndFileReq(action) {
	http.open('get', 'http://'+window.location.hostname+'/admin/module_proddownloads/rpc.php?action='+action);
 
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function addOpt(){
	if (document.getElementById('select_type').value != ""){
		action = document.getElementById('select_type').value;
	}
	else{
		action = document.getElementById('other').value;
	}
	action= URLEncode(action);
	sndReq(action);
	document.getElementById('other').value = "";
}

function addFiles(){
	action = "file";
	//action= URLEncode(action);
	sndFileReq(action);
}

function delFiles(){
	action = "<del>";
	//action= URLEncode(action);
	sndFileReq(action);
}

function delOpts(){
	action = "<del>";
	sndReq(action);
	document.getElementById('mytext').value = "";
}

function chkTableName(){
	if (document.getElementById('tablename').value == ""){
		alert("You have not given this table a product group name!");
		return false;
	}
	return true;
}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
        }
    }
}

function checkupload(){
	
	title = document.getElementById('title').value;
	upload = document.getElementById('upload').value;
	
	if (title == "" || upload == ""){
		alert("You must upload a file and give it a title!");
		return false;
	}
	
	return true;	
}

function setOther(){
	document.getElementById('select_type').options[0].selected = true;
}

// ====================================================================
//       URLEncode and URLDecode functions
//
// Copyright Albion Research Ltd. 2002
// http://www.albionresearch.com/
//
// You may copy these functions providing that 
// (a) you leave this copyright notice intact, and 
// (b) if you use these functions on a publicly accessible
//     web site you include a credit somewhere on the web site 
//     with a link back to http://www.albionresarch.com/
//
// If you find or fix any bugs, please let us know at albionresearch.com
//
// SpecialThanks to Neelesh Thakur for being the first to
// report a bug in URLDecode() - now fixed 2003-02-19.
// ====================================================================
function URLEncode(text )
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()€";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = text;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	//document.URLForm.F2.value = encoded;
	return encoded;
};

function URLDecode(text)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = text;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   //document.URLForm.F1.value = plaintext;
   return text;
};

function closeAndReload(){
	//Close popup and refresh parent.
	window.opener.location.href=window.opener.location.href;
	window.close();
}

function addPage(section){
	window.open('../dialogs/add_page.php?sec=' + section, 'add_page', 'width=300,height=300,status=1,resizeable=1');
}

function reorderPages(section){
	window.open('../dialogs/reorder_section.php?sec=' + section, 'reorder_section', 'width=300,height=300,status=1,resizeable=1');
}