//########################################################################
//
// UNITED CMS
//
// JS AJAX Response functions
//
//########################################################################

function ajaxHandler()
{ };

ajaxHandler.prototype = {
		
		handle : function (obj, num, loadin, callback)
		{
			// TODO: Set GUIDs...
			// extGUID = "0F878AC8-375F-11DD-A9D3-B5D955D89593";
			// if otherwise, set consts.AJAXCore to something else!
			// extGUID of extensions will need to be provided - an Extensions JS Object?
			var d = new Date();
			var ed = d.getTime();
			this.t = d.getTime();
			var path = obj.base + "response.php";
			store['loadin'] = loadin;
			if (document.getElementById(loadin))
			{
				if ($(loadin).clientWidth && getStyle(document.getElementById(loadin), "padding-right"))
				{
					$(loadin).style.width = (document.getElementById(loadin).clientWidth - getStyle(document.getElementById(loadin), "padding-right").split("px")[0] - getStyle(document.getElementById(loadin), "padding-left").split("px")[0]) + "px";
				}
				if ($(loadin).clientHeight && getStyle(document.getElementById(loadin), "padding-top"))
				{
					$(loadin).style.height = (document.getElementById(loadin).clientHeight - getStyle(document.getElementById(loadin), "padding-top").split("px")[0] - getStyle(document.getElementById(loadin), "padding-bottom").split("px")[0]) + "px";
				}				
				else
				{
					$(loadin).style.height = $(loadin).offsetHeight;
					$(loadin).style.width = $(loadin).offsetWidth - 20;
				}
				document.getElementById(loadin).innerHTML = "<div class='loadingText' id='loading'>Loading...</div>";
			}
			else
			{
				log ("ID: " + loadin + " not found. Proceeding.");
			}
			args = [num, loadin, ed];
			assoc = ["code", "loadin", "d"];
		

			//log ("IID: " + obj['iid']);
			for (var arg in obj)
			{
				if (arg != "base" && obj[arg] != null && obj[arg] != "")
				{
					if (typeof (obj[arg]) == "object")
					{				
						for (var innerarg in obj[arg])
						{
							if (innerarg != "addPiids" && arg != 'loadin')
							{
								if (typeof (obj[arg][innerarg]) == "object" && obj[arg][innerarg]['iid'] == obj['iid'])
								{
									for (var inner2arg in obj[arg][innerarg])
									{
										args.push (obj[arg][innerarg][inner2arg]);
										assoc.push (inner2arg);
									}
								}
								else
								{
									args.push (obj[arg][innerarg]);
									assoc.push (arg + "-" + innerarg);
								}
							}
						}
					}
					else
					{
						args.push (obj[arg]);
						assoc.push (arg);
					}
				}
			}
			this.request (args, assoc, path, callback);
		},
		
		request : function (args, assoc, path, callback)
		{
			var d = new Date();
			//log (d.getTime() - this.t);
			// TODO having this GUID here is useless; needs to be generated from PHP
			GUID = "99a956b0-3b05-11dd-ae16-0800200c9a66";
			http = this.createXHRObject();
			http.handlerObj = this;
			http.onreadystatechange = this.ORSC;
			http.open ('POST', path, true);
			var postvars = "";
			var clientvars = [];
			for(var i = 0; i < args.length; i++)
			{
				clientvars[args[i]] = assoc[i];
				postvars += encodeURIComponent(assoc[i]) + '=' + encodeURIComponent(args[i]) + '&';
			}		
			postvars = "verify=" + GUID + "&" + postvars.substr(0, postvars.length - 1);
			http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
			http.setRequestHeader("Content-length", postvars.length);
			http.setRequestHeader("Connection", "close");
			//log ("Request Start" + (d.getTime() - this.t))
			log(path + "?" + postvars);
			http.send(postvars);
			log ("Request in Progress" + (d.getTime() - this.t));
		},

		
		createXHRObject : function ()
		{
    	var ro;
			if (XMLHttpRequest)
			{
				return new XMLHttpRequest();
			}
			else
	    {
    	  return new ActiveXObject('Microsoft.XMLHTTP');
    	}
			log ("Error making AJAX call");
			return "Error making AJAX Call";
		},
		
		clientResponse : function (data)
		{
			arh = new ajaxResponseHandler();
			arh.pr(data.rv, data);			
		},
		
		respondToCall : function (calleddata)
		{
			var d = new Date();
			if (calleddata.substring(0,10) == "SPECIALRV9")
			{
				arh = new ajaxResponseHandler();
				log ('woah there dudes');
				data = Array();
				data.loosedata = calleddata.substring(10);
				arh.rv(9, data);
				log ('end');
			}
			//log ("Data Received [2]: " + calleddata + (d.getTime() - this.t));
			if (JSON.parse (calleddata))
			{
				data = JSON.parse (calleddata);
				arh = new ajaxResponseHandler();
				if (data.error < 5)
				{
					arh.rv(data.rv, data);
					if (data.createEvent)
					{
						for (eventInstance in data.createEvent)
						{
							if (data.eventTrigger && data.eventTrigger[eventInstance + data.createEvent[eventInstance]])
							{
								eventT = data.eventTrigger[eventInstance + data.createEvent[eventInstance]];
							}
							else
							{
								eventT = "click";
							}
							if (data.eventLoadIn && data.eventLoadIn[eventInstance + data.createEvent[eventInstance]])
							{
								loadin = data.eventLoadIn[eventInstance + data.createEvent[eventInstance]];
							}
							else
							{
								loadin = "";
							}
							if (data.eventParams && data.eventParams[eventInstance + data.createEvent[eventInstance]])
							{
								params = data.eventParams[eventInstance + data.createEvent[eventInstance]];
							}
							else
							{
								params = [];
							}
							if (data.eventGrabValues)
							{
								grabValues = getGrabValues(data.eventGrabValues[eventInstance + data.createEvent[eventInstance]]);
							}
							else
							{
								grabValues = [];
							}
							e.addEvent ($(eventInstance), eventT, function(ev) { ajaxCall(e, ev, data.createEvent[eventInstance], loadin, params, grabValues); } );
						}
					}
				}
				else if (data.error == 6)
				{
					arh.error6 (data);
				}
				else
				{
					log ("Return Code Error. (No error code)")
				}
				// log (data.call);
				// here we are calling a function to add events
				if (data.rv == 4 && data.callData && !data.eventException)
				{
					window['hm']['addTextBoxEditorHandlers_g'](data.callData, data);
				}
				else if (data.rv == 5 && data.callData && !data.eventException)
				{
					window['hm']['addTextAreaEditorHandlers_g'](data.callData, data);
				}
				else if (data.rv == 3 && data.permdata && !data.replace)
				{
					window['hm']['addPermissionBoxHandler'](data);
				}
				else if (data.rv == 6 && data.newitem)
				{
					items[data.iid] = new itemStore(['piid'], [data.piid]);
					window['hm']['addItemHandler'](data.iid);
					window['hm']['addItemToolboxHandler'](data.iid, 2, data.piid);
				}
				else if (data.rv == 9)
				{
					if (data.others)
					{
						window['hm']['addReturnToPageHandler'](data.hide, data.others);
					}
					else
					{
						window['hm']['addReturnToPageHandler'](data.hide);
					}
					if (data.permdata && !data.replace)
					{
						window['hm']['addSitePermissionsHandler'](data);
					}
					else if (data.userlist)
					{
						window['hm']['addAddUserHandler']();
						window['hm']['addEditUserElementHandler']();
						window['hm']['addChangeUserRoleHandler'](data.userlist);
						window['hm']['addUserActionHandler'](data.userlist);						 
					}
				}
				else if (data.rv == 2 && data.code == 110002)
				{
					window['hm']['addLogInHandler']();
				}
				if (data.call && data.callData)
				{
					if(data.call.indexOf(".") > -1)
					{
						functobj = data.call.split(".");
						window[functobj[0]][functobj[1]](data.callData);
					}
					else
					{
						window[data.call](data.callData);
					}

				}
			}
			else
			{
				log ("Data connection error.");
			}
		},
			
		ORSC : function ()
		{
			//log ("AT: " + http.readyState + " " + http.status);
			if (http.readyState == 4 && http.status == 200)
			{
				//log("Data Received: " + http.responseText);
				this.handlerObj.respondToCall (http.responseText);
			}
			else if (http.readyState == 4)
			{
				alert("Code " + http.status + " error.");
			}
	
			return;
		}
	};


function ajaxResponseHandler()
{ };

ajaxResponseHandler.prototype = {
		
		rv1 : function (data)
		{
			window.location.reload();
		},
		
		rv2 : function (data)
		{
			for (id in data.insertin)
			{
				if (data.insertflags && data.insertflags[id] && data.insertflags[id].indexOf('m') > -1)
				{
					var regEx = new RegExp ('\\n', 'gi');
					data.insertin[id] = data.insertin[id].replace(regEx, '<br>');
				}
				//log ('new' + data.insertin[id]);
				$(id).innerHTML = data.insertin[id];
				$(id).style.width = 'auto';
				$(id).style.height = 'auto';
			}
		},
		
		rv3 : function (data)
		{
			if (data.hide && document.getElementById(data.hide))
			{
				$(data.hide).style.visibility = 'hidden';
			}
			var unique = data.code + data.key;
			if (data.replace && data.replace == 1)
			{
				var newbodyitemdiv = $('boxbody');   
				newbodyitemdiv.innerHTML = "";
				//log ('box' + data.code + data.key);
				//removeEl ('box' + data.code + data.key);
			}
			else
			{					
				if (data.box == null)
				{
					data.box = new Object();
					data.box['title'] = "Untitled Box";
				}
				
				var d = document.createElement("div");
				d.id = 'box' + unique;
				d.className = 'popupmessage';
				data.boxId = d.id;

		
				document.body.appendChild(d);
				
				var top = document.createElement("div");
				top.id = 'msgtop' + unique;
				top.className = 'toplevel';
				top.innerHTML = data.box.title;
				d.appendChild(top);
				
				var closex = document.createElement("a");
				closex.className = 'closex';
				closex.innerHTML = "X";
				closex.href = '#';
				closex.id = 'x' + unique;
				top.appendChild(closex);
				
				hm.addMsgBoxXHandler(data);
	
				var newbodyitemdiv = document.createElement('div');    
				newbodyitemdiv.setAttribute('class','body c');
				newbodyitemdiv.setAttribute('className','body c');
				newbodyitemdiv.setAttribute('style','background: white;');
				newbodyitemdiv.setAttribute('id', 'boxbody');
			}    
			// TODO: handle error messages!
			
			data.grabValues = [];
			
			if(data.form)
			{
				for(name in data.form)
				{		
					if (data.form[name].type == 0)
					{
						var txt = document.createElement('span');
						txt.innerHTML = data.form[name].text;
						newbodyitemdiv.appendChild(txt);
						newbodyitemdiv.appendChild(document.createElement('br'));
						newbodyitemdiv.appendChild(document.createElement('br'));
					}
					else if (data.form[name].type == 1)
					{
						var intxt = document.createElement('input');
						intxt.id = name + data.code;
						data.grabValues.push(name + data.code);
						intxt.name = name + data.code;
						if (data.form[name].value)
						{
							intxt.value = data.form[name].value;
						}
						newbodyitemdiv.appendChild(document.createTextNode(data.form[name].text + " "));
						newbodyitemdiv.appendChild(intxt);
						if (data.form[name].note)
						{
							notetext = document.createElement('span');
							notetext.innerHTML = data.form[name].note;
							notetext.style.fontSize = ".9em";
							notetext.style.fontStyle = "italic";
							newbodyitemdiv.appendChild(document.createTextNode("   "));
							newbodyitemdiv.appendChild(notetext);
						}
						newbodyitemdiv.appendChild(document.createElement('br'));
						newbodyitemdiv.appendChild(document.createElement('br'));
					}
					else if (data.form[name].type == 2)
					{
						var inarea = document.createElement('textarea');
						inarea.id = name + data.code;
						data.grabValues.push(name + data.code);
						inarea.name = name + data.code;
						inarea.rows = 5;
						inarea.cols = 60;
						if (data.form[name].value)
						{
							inarea.innerHTML = data.form[name].value;
						}
						newbodyitemdiv.appendChild(document.createTextNode(data.form[name].text + " "));
						newbodyitemdiv.appendChild(document.createElement('br'));
						newbodyitemdiv.appendChild(inarea);
						newbodyitemdiv.appendChild(document.createElement('br'));
					}
					else if (data.form[name].type == 3)
					{
						var menu = document.createElement('select');
						menu.id = name + data.code;
						data.grabValues.push(name + data.code);
						menu.name = name + data.code;
						for (opti in data.form[name].options)
						{
							menu.options[menu.options.length] = new Option(data.form[name].options[opti], opti)
						}
						newbodyitemdiv.appendChild(document.createTextNode(data.form[name].text + " "));
						newbodyitemdiv.appendChild(menu);
						newbodyitemdiv.appendChild(document.createElement('br'));
						newbodyitemdiv.appendChild(document.createElement('br'));
					}
				}
			}
			else if (data.permdata)
			{
				var tables = makePermTable(data);
				newbodyitemdiv.appendChild(document.createTextNode("Permissions for this " + data.datatype + ":"));
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(tables[0]);
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(tables[1]);
			}
			else if (data.fulldata)
			{
				newbodyitemdiv.innerHTML = data.fulldata;
			}
			
			if (data.passing)
			{
				store.passing = data.passing;
			}

			if (data.replace && data.replace == 1)
			{
			}
			else
			{
				d.appendChild(newbodyitemdiv);
			
			
				if (data.box && data.box.submitButton && data.box.submitButton.text != "OK")
				{
					var subin = document.createElement('input');
					subin.id = 'closebutton' + unique;
					subin.className = 'closebutton';
					subin.type = 'submit';
					subin.value = data.box.submitButton.text;				
					d.appendChild(subin);
					if (data.replacecall == true)
					{ }
					else
					{
						hm.addMsgBoxSubmitHandlers(data);
					}
				}
				else if (data.box && data.box.submitButton && data.box.submitButton.text == "OK")
				{
					var subin2 = document.createElement('input');
					subin2.id = 'cancelbutton' + unique;
					subin2.className = 'closebutton';
					subin2.type = 'button';
					subin2.value = 'OK';
					d.appendChild(subin2);
					hm.addMsgBoxCloseHandler(data);
				}
				else
				{
					var subin3 = document.createElement('input');
					subin3.id = 'cancelbutton' + unique;
					subin3.className = 'closebutton';
					subin3.type = 'button';
					subin3.value = 'OK';
					d.appendChild(subin3);
					hm.addMsgBoxCloseHandler(data);
				}
				
				if (data.box.cancelButton)
				{
					var cancel = document.createElement('input');
					cancel.id = 'cancelbutton' + unique;
					cancel.className = 'closebutton cancelbutton';
					cancel.type = 'button';
					cancel.value = data.box.cancelButton.text;
					d.appendChild(cancel);
					hm.addMsgBoxCloseHandler(data);
				}
				
				if (data.customcall && data.replacecall)
				{
					hm.addMsgBoxExtraSubmitHandlers(data);
				}
				
			}
			
		},
		
		rv4 : function (data)
		{
			for (innerid in data.insertin)
			{
				id = innerid;
				log (id);
			}					
			document.getElementById(id).innerHTML = "";
			//log ("ID: " + id);

			data['fillform'] = document.createElement('form');
			data['fillform'].name = "form" + id;
			
			data['fillform']['input'] = document.createElement('input');
			data['fillform']['input'].type = 'text';
			data['fillform']['input'].id = 'text' + id;
			data['fillform']['input'].value = unescape(data.insertin[id].replace(/&#x(....);/g,"%u$1"));
			data['fillform']['input'].size = data.insertin[id].length + 2;
			data['fillform']['input'].maxlength = 250;
			
			data['fillform']['savebutton'] = document.createElement('input');
			data['fillform']['savebutton'].type = 'button';
			data['fillform']['savebutton'].value = "Save";
			data['fillform']['savebutton'].id = 'savebutton' + id;
			
			data['fillform']['cancelbutton'] = document.createElement('input');
			data['fillform']['cancelbutton'].type = 'button';
			data['fillform']['cancelbutton'].value = "Cancel";
			data['fillform']['cancelbutton'].id = 'cancelbutton' + id;			
			
			data['fillform'].appendChild(data['fillform']['input']);
			data['fillform'].appendChild(data['fillform']['savebutton']);
			data['fillform'].appendChild(data['fillform']['cancelbutton']);
			
			for (var i = 0; i < document.getElementById(id).childNodes.length; i++)
			{
				document.getElementById(id).removeChild(document.getElementById(id).childNodes[i]);
			}
			document.getElementById(id).appendChild(data['fillform']);
			
			document.getElementById('text' + id).focus();
		},
		
		rv5 : function (data)
		{
			for (innerid in data.insertin)
			{
				id = innerid;
				log (id);
			}		
			if (data.insertflags && data.insertflags[id] && data.insertflags[id].indexOf('m') > -1)
			{
				var regEx = new RegExp ('<br>', 'gi');
				data.insertin[id] = data.insertin[id].replace(regEx, '\n');
			}
			document.getElementById(id).innerHTML = "";
			lines = data.insertin[id].split("\n");
			linelength = lines.length + 1;
			for (line in lines)
			{
				innerline = (line / 80) + .5;
				linelength += innerline;
			}

			log ("ID: " + id);
			data['fillform'] = document.createElement('form');
			data['fillform'].name = "form" + id;

			data['fillform']['textarea'] = document.createElement('textarea');
			data['fillform']['textarea'].id = 'text' + id;
			data['fillform']['textarea'].value = unescape(data.insertin[id].replace(/&#x(....);/g,"%u$1"));
			if (lines.length > 1)
			{
				data['fillform']['textarea'].rows = lines.length;
			}
			else
			{
				document.getElementById(id).style.height = "80px";
				data['fillform']['textarea'].rows = 2;
			}
			data['fillform']['textarea'].style.width = "98%";
		//	data['fillform']['textarea'].style.height = "100%";
			data['fillform']['textarea'].style.fontFamily = 'calibri, arial, sans-serif';
			
			data['fillform']['savebutton'] = document.createElement('input');
			data['fillform']['savebutton'].type = 'button';
			data['fillform']['savebutton'].value = "Save";
			data['fillform']['savebutton'].id = 'savebutton' + id;
			
			data['fillform']['cancelbutton'] = document.createElement('input');
			data['fillform']['cancelbutton'].type = 'button';
			data['fillform']['cancelbutton'].value = "Cancel";
			data['fillform']['cancelbutton'].id = 'cancelbutton' + id;			
			
			data['fillform'].appendChild(data['fillform']['savebutton']);
			data['fillform'].appendChild(data['fillform']['cancelbutton']);		
			data['fillform'].appendChild(data['fillform']['textarea']);
			
			for (var i = 0; i < document.getElementById(id).childNodes.length; i++)
			{
				document.getElementById(id).removeChild(document.getElementById(id).childNodes[i]);
			}
			
			document.getElementById(id).appendChild(data['fillform']);
			
			document.getElementById('text' + id).focus();
		},
		
		rv6 : function (data)
		{
			colid = data.col + data.cols;
			
			newitem = document.createElement('div');
			newitem.id = 'item' + data.iid;
			newitem.className = 'item';
			newitem.innerHTML = data.newitem;

			var i = 0;
			while (!$(colid).childNodes[i].id)
			{
				i++;
			}
			$(colid).insertBefore(newitem, $(colid).childNodes[i]);
			data.otheriid = $(colid).childNodes[i+1].id.substring(4);
			$('item' + 'moveup' + data.otheriid).style.display = 'inline';
			
		},
		
		rv7 : function (data)
		{
			for (num in data.remove)
			{
				$(data.remove[num]).parentNode.removeChild($(data.remove[num]));
			}
		},
		
		rv8 : function (data)
		{
			if (data.code == 111500)	// move up
			{
				var current = $(data.type + data.ID);
				var switcher = $(data.type + data.ID).previousSibling;
				data.otheriid = $(data.type + data.ID).previousSibling.id.substring(data.type.length);
				data.otherpos = parseInt(data.newpos) + 3;
				
				$(data.type + 'toolbox' + data.ID).style.display = 'none';
				$(data.type + 'toolbox' + data.otheriid).style.display = 'none';
				
				if (parseInt(data.newpos) <= 2)
				{
					$(data.type + 'moveup' + data.ID).style.display = 'none';
				}
				else
				{
					$(data.type + 'moveup' + data.ID).style.display = 'inline';
				}
				$(data.type + 'movedown' + data.ID).style.display = 'inline';

				if (parseInt(data.otherpos) >= parseInt(data.maxpos))
				{
					$(data.type + 'movedown' + data.otheriid).style.display = 'none';
				}
				else
				{
					$(data.type + 'movedown' + data.otheriid).style.display = 'inline';
				}
				$(data.type + 'moveup' + data.otheriid).style.display = 'inline';

				data.otherpiid = items[data.otheriid].piid;

				$(data.type + data.ID).parentNode.insertBefore(current, switcher);
			}
			else		// move down
			{
				var current = $(data.type + data.ID);
				var switcher = $(data.type + data.ID).nextSibling;
				data.otheriid = $(data.type + data.ID).nextSibling.id.substring(data.type.length);
				data.otherpos = parseInt(data.newpos) - 3;
				
				$(data.type + 'toolbox' + data.ID).style.display = 'none';
				$(data.type + 'toolbox' + data.otheriid).style.display = 'none';
				
				if (parseInt(data.otherpos) <= 2)
				{
					$(data.type + 'moveup' + data.otheriid).style.display = 'none';
				}
				else
				{
					$(data.type + 'moveup' + data.otheriid).style.display = 'inline';
				}
				$(data.type + 'movedown' + data.otheriid).style.display = 'inline';

				if (parseInt(data.newpos) >= parseInt(data.maxpos))
				{
					$(data.type + 'movedown' + data.ID).style.display = 'none';
				}
				else
				{
					$(data.type + 'movedown' + data.ID).style.display = 'inline';
				}
				$(data.type + 'moveup' + data.ID).style.display = 'inline';

				data.otherpiid = items[data.otheriid].piid;

				$(data.type + data.ID).parentNode.insertBefore(switcher, current);
			}
			
		},
		
		rv9 : function (data)
		{
			newbodyitemdiv = document.createElement('div');
			
			backlink = document.createElement('a');
			backlink.id = 'returnToPageLink'; 
			backlink.href = '#';
			backlink.innerHTML = 'Return to Page';
			if (data.hide)
			{
				$(data.hide).style.visibility = 'hidden';
			}
			
			if (data.newbody)
			{
				newbodyitemdiv.innerHTML = data.newbody;
			}

			if (data.masterlist)
			{
				mlinfo = document.createElement('span');
				mlinfo.id = 'masterlist';
				mlinfo.innerHTML = data.masterlist.join(',');
				mlinfo.style.display = 'none';
				newbodyitemdiv.appendChild(mlinfo);
			}
			
			else if (data.permdata)
			{		
				var tables = makePermTable(data, 0, 'Site', 2);
				
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(document.createElement('br'));
				
				newbodyitemdiv.appendChild(document.createTextNode("SITE PERMISSIONS MUST HAVE ALL FOUR SET TO YES!"));
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(document.createElement('br'));				
				newbodyitemdiv.appendChild(document.createTextNode("Permissions for User Permissions Managing:  (S)"));
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(tables[0]);
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(tables[1]);
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(document.createElement('br'));
				
				var tables = makePermTable(data, 1, 'Site', 3);
				newbodyitemdiv.appendChild(document.createTextNode("Permissions for Navigation Changing:  (S)"));
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(tables[0]);
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(tables[1]);
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(document.createElement('br'));
				
				var tables = makePermTable(data, 2, 'Site', 5);
				newbodyitemdiv.appendChild(document.createTextNode("Permissions for Global Email Address:  (S)"));
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(tables[0]);
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(tables[1]);
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(document.createElement('br'));
				
				var tables = makePermTable(data, 3, 'Site', 6);
				newbodyitemdiv.appendChild(document.createTextNode("Permissions for User Managing:  (S)"));
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(tables[0]);
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(tables[1]);
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(document.createElement('br'));
				
				var tables = makePermTable(data, 4, 'Generic', 1);
				newbodyitemdiv.appendChild(document.createTextNode("Generic Permissions for Pages:"));
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(tables[0]);
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(tables[1]);
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(document.createElement('br'));
				
				var tables = makePermTable(data, 5, 'Generic', 2);
				newbodyitemdiv.appendChild(document.createTextNode("Generic Permissions for Items:"));
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(tables[0]);
				newbodyitemdiv.appendChild(document.createElement('br'));
				newbodyitemdiv.appendChild(tables[1]);
			}
			nodes = $(store.activeCol).childNodes;
			hider = document.createElement('div');
			hider.id = 'hider';
			hider.style.display = 'none';
			$('all').appendChild(hider);
						
			while($(store.activeCol).childNodes.length > 0)
			{
				hider.appendChild($(store.activeCol).childNodes[0]);
			}
			
			newbodyitemdiv.id = 'sitePermBody';
			newbodyitemdiv.className = 'item';
			$(store.activeCol).appendChild(backlink);
			
			
			if (data.loosedata)
			{
				window['hm']['addReturnToPageHandler'](data.hide, data.others);
				newbodyitemdiv.innerHTML = data.loosedata;
			}
			
			
			
			$(store.activeCol).appendChild(newbodyitemdiv);
		},
		
		rv10 : function (data)
		{
			window[data.call](data.arg);
		},
		
		rve2_10 : function (data)
		{
			added_new = 1;
			document.forms['refreshMemberList'].submit();
			$('memberpart4' + data.memid).innerHTML = data.dropdown;
			$('atup' + data.memid).style.background = "red";
			$('atup' + data.memid).style.color = "white";
			$('atup' + data.memid).style.fontWeight = "bold";
			$('atup' + data.memid).style.fontSize = "0.7em";
			setTimeout(function () { $('atup' + data.memid).parentNode.removeChild($('atup' + data.memid)); },1500);
		},
		
		rv : function (rvNum, data)
		{
			this['rv' + rvNum](data);
		},
		
		error6 : function (data)
		{
			log (data.errorResponse);
			if (data.errorResponse)
			{
				makeSimpleMsgBox('Error', data.errorResponse);
			}
			else if (data.errorCode)
			{
				makeSimpleMsgBox('Error', data.errorCode);
			}
			else
			{
				makeSimpleMsgBox('Error', 'Unknown Error. Type: ' + data.error);
			}
		}
		
		
};
