function createTable( root )
{
	var x = xmlDoc.getElementsByTagName('emperor');
	var newEl = document.createElement('TABLE');
	newEl.setAttribute('cellPadding',5);
	var tmp = document.createElement('TBODY');
	newEl.appendChild(tmp);
	var row = document.createElement('TR');
	for (j=0;j<x[0].childNodes.length;j++)
	{
		if (x[0].childNodes[j].nodeType != 1) continue;
		var container = document.createElement('TH');
		var theData = document.createTextNode(x[0].childNodes[j].nodeName);
		container.appendChild(theData);
		row.appendChild(container);
	}
	tmp.appendChild(row);
	for (i=0;i<x.length;i++)
	{
		var row = document.createElement('TR');
		for (j=0;j<x[i].childNodes.length;j++)
		{
			if (x[i].childNodes[j].nodeType != 1) continue;
			var container = document.createElement('TD');
			var theData = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);
			container.appendChild(theData);
			row.appendChild(container);
		}
		tmp.appendChild(row);
	}
	
	document.getElementById('writeroot').appendChild(newEl);
}

function myCreateTable( numRows, numCols )
{
	//var x = xmlDoc.getElementsByTagName('emperor');
	
	// create table-element
	var newEl = document.createElement('TABLE');
	
	// set table attributes
	newEl.setAttribute('cellPadding',5);
	newEl.setAttribute('id','mytest..');
	
	var tmp = document.createElement('TBODY');
	newEl.appendChild(tmp);
	
	
	//var row = document.createElement('TR');
	
	/*
	
	for (j=0;j<x[0].childNodes.length;j++)
	{
		if (x[0].childNodes[j].nodeType != 1) continue;
		var container = document.createElement('TH');
		var theData = document.createTextNode(x[0].childNodes[j].nodeName);
		container.appendChild(theData);
		row.appendChild(container);
	}
	tmp.appendChild(row);*/
	
	for (i=0;i<numRows;i++)
	{
		var row = document.createElement('TR');
		
		for (j=0;j<numCols;j++)
		{
			//if (x[i].childNodes[j].nodeType != 1) continue;
			
			var container = document.createElement('TD');
			var theData = document.createTextNode('htmnl-data whateva..');
			container.appendChild(theData);
			row.appendChild(container);
		}
		
		tmp.appendChild(row);
	}
	
	//document.getElementById('writeroot').appendChild(newEl);
	
	return newEl;
}

function createProdlist( parent )
{
			var UL = document.createElement('UL');
			UL.setAttribute('class','admin');
			UL.setAttribute('id', 'prd_c_40539');
			UL.setAttribute('style', 'margin:0px; padding:0px;');
		var link = '?cmd=products&amp;cat=40539'; 
		var showhide = '<a href="#" onclick="document.getElementById(\'action\').value=\'hide\'; document.getElementById(\'productId\').value=\'137078\'; document.getElementById(\'postcat\').value = 40539; document.forms[0].submit();"> [Skjul] </a>';  	
			
				
			 
					var LI = document.createElement('LI');
					LI.setAttribute('class','admin');
					LI.setAttribute('style','margin:0px; padding:0px;');
					LI.setAttribute('id','prd_139675_40539');
					
					var TABLE = document.createElement('TABLE');
					
					// set table attributes
					TABLE.setAttribute('cellPadding',0);
					TABLE.setAttribute('cellSpacing',0);
					TABLE.setAttribute('border',0);
					TABLE.setAttribute('width','100%');
					
					
					var TBODY = document.createElement('TBODY');
					
					var TR = document.createElement('TR');
					TR.setAttribute('bgcolor', '#b3c6d7'); 
					
					var TD = document.createElement('TD');
					TD.setAttribute('width', '15'); 
					
					
					
					var INPUT = document.createElement('INPUT');
					
					INPUT.setAttribute('type', 'checkbox'); 
					INPUT.setAttribute('name', 'prod[139675]'); 
					INPUT.setAttribute('value', '137078');
					
					
					TD.appendChild(INPUT);
				
					TR.appendChild(TD);
					
				
					var TD = document.createElement('TD');
						
					TD.innerHTML = '<a href="?cmd=products&amp;action=update2&amp;productId=137078">99 Vectra 1.8 CD (100 gram)</a>';
					
					TR.appendChild(TD);
				
				
					var TD = document.createElement('TD');
					TD.setAttribute('width', '120'); 
					
					TD.innerHTML = '<a href="?cmd=products&amp;action=update2&amp;productId=137078">34DS223</a>';
					
					TR.appendChild(TD);
					
					
					var TD = document.createElement('TD');
					TD.setAttribute('width', '40'); 
					
					TD.innerHTML = '<a href="#" onclick="document.getElementById(\'action\').value=\'delete\'; document.getElementById(\'productId\').value=\'137078\'; document.getElementById(\'postcat\').value = \'40539\';  document.forms[0].submit();  ">		                 [Slett] 		               </a> ';

					TR.appendChild(TD);	
					
				
					var TD = document.createElement('TD');
					TD.setAttribute('width', '40'); 

					TD.innerHTML = showhide;
					
					TR.appendChild(TD);
					
				
					var TD = document.createElement('TD');
					TD.setAttribute('width', '20'); 
					TD.setAttribute('style', 'text-align: center;'); 
					
					
					var SPAN = document.createElement('SPAN');
					SPAN.setAttribute('class', 'prodhandle'); 
					
					
							var IMG = document.createElement('IMG');
							IMG.src = "img/up_down.gif";
							IMG.setAttribute('alt', 'Dra her for å flytte produktet.');
							IMG.setAttribute('style', 'cursor:move;');
							
							SPAN.appendChild(IMG);						
						
					
					TD.appendChild(SPAN);
					
					TR.appendChild(TD);	
					
					TBODY.appendChild(TR);	
					
					TABLE.appendChild(TBODY);	
					
					LI.appendChild(TABLE); 
					
					UL.appendChild(LI); 

			
				
			 
					var LI = document.createElement('LI');
					LI.setAttribute('class','admin');
					LI.setAttribute('style','margin:0px; padding:0px;');
					LI.setAttribute('id','prd_139676_40539');
					
					var TABLE = document.createElement('TABLE');
					
					// set table attributes
					TABLE.setAttribute('cellPadding',0);
					TABLE.setAttribute('cellSpacing',0);
					TABLE.setAttribute('border',0);
					TABLE.setAttribute('width','100%');
					
					
					var TBODY = document.createElement('TBODY');
					
					var TR = document.createElement('TR');
					TR.setAttribute('bgcolor', '#c3d1df'); 
					
					var TD = document.createElement('TD');
					TD.setAttribute('width', '15'); 
					
					
					
					var INPUT = document.createElement('INPUT');
					
					INPUT.setAttribute('type', 'checkbox'); 
					INPUT.setAttribute('name', 'prod[139676]'); 
					INPUT.setAttribute('value', '137079');
					
					
					TD.appendChild(INPUT);
				
					TR.appendChild(TD);
					
				
					var TD = document.createElement('TD');
						
					TD.innerHTML = '<a href="?cmd=products&amp;action=update2&amp;productId=137079">Vectra 89 modell (50000000 gram)</a>';
					
					TR.appendChild(TD);
				
				
					var TD = document.createElement('TD');
					TD.setAttribute('width', '120'); 
					
					TD.innerHTML = '<a href="?cmd=products&amp;action=update2&amp;productId=137079">11   821fds</a>';
					
					TR.appendChild(TD);
					
					
					var TD = document.createElement('TD');
					TD.setAttribute('width', '40'); 
					
					TD.innerHTML = '<a href="#" onclick="document.getElementById(\'action\').value=\'delete\'; document.getElementById(\'productId\').value=\'137078\'; document.getElementById(\'postcat\').value = \'40539\';  document.forms[0].submit();  ">		                 [Slett] 		               </a> ';

					TR.appendChild(TD);	
					
				
					var TD = document.createElement('TD');
					TD.setAttribute('width', '40'); 

					TD.innerHTML = showhide;
					
					TR.appendChild(TD);
					
				
					var TD = document.createElement('TD');
					TD.setAttribute('width', '20'); 
					TD.setAttribute('style', 'text-align: center;'); 
					
					
					var SPAN = document.createElement('SPAN');
					SPAN.setAttribute('class', 'prodhandle'); 
					
					
							var IMG = document.createElement('IMG');
							IMG.src = "img/up_down.gif";
							IMG.setAttribute('alt', 'Dra her for å flytte produktet.');
							IMG.setAttribute('style', 'cursor:move;');
							
							SPAN.appendChild(IMG);						
						
					
					TD.appendChild(SPAN);
					
					TR.appendChild(TD);	
					
					TBODY.appendChild(TR);	
					
					TABLE.appendChild(TBODY);	
					
					LI.appendChild(TABLE); 
					
					UL.appendChild(LI); 
				/*
				var link = '?cmd=products&amp;cat=40539'; var showhide = '<a href="#" onclick="document.getElementById('action').value='hide'; document.getElementById('productId').value='137081'; document.getElementById('postcat').value = 40539; document.forms[0].submit();"> [Skjul] </a>';  	*/
			
					var LI = document.createElement('LI');
					LI.setAttribute('class','admin');
					LI.setAttribute('style','margin:0px; padding:0px;');
					LI.setAttribute('id','prd_139677_40539');
					
					var TABLE = document.createElement('TABLE');
					
					// set table attributes
					TABLE.setAttribute('cellPadding',0);
					TABLE.setAttribute('cellSpacing',0);
					TABLE.setAttribute('border',0);
					TABLE.setAttribute('width','100%');
					
					
					var TBODY = document.createElement('TBODY');
					
					var TR = document.createElement('TR');
					TR.setAttribute('bgcolor', '#b3c6d7');  
					
					var TD = document.createElement('TD');
					TD.setAttribute('width', '15'); 
					
					
					
					var INPUT = document.createElement('INPUT');
					
					INPUT.setAttribute('type', 'checkbox'); 
					INPUT.setAttribute('name', 'prod[139677]'); 
					INPUT.setAttribute('value', '137081');
					
					
					TD.appendChild(INPUT);
				
					TR.appendChild(TD);
					
				
					var TD = document.createElement('TD');
						
					TD.innerHTML = '<a href="?cmd=products&amp;action=update2&amp;productId=137081">CCR MegaTurbo (200 gram)</a>';
					
					TR.appendChild(TD);
				
				
					var TD = document.createElement('TD');
					TD.setAttribute('width', '120'); 
					
					TD.innerHTML = '<a href="?cmd=products&amp;action=update2&amp;productId=137081">fsa</a>';
					
					TR.appendChild(TD);
					
					
					var TD = document.createElement('TD');
					TD.setAttribute('width', '40'); 
					
					TD.innerHTML = '<a href="#" onclick="document.getElementById(\'action\').value=\'delete\'; document.getElementById(\'productId\').value=\'137078\'; document.getElementById(\'postcat\').value = \'40539\';  document.forms[0].submit();  ">		                 [Slett] 		               </a> ';

					TR.appendChild(TD);	
					
				
					var TD = document.createElement('TD');
					TD.setAttribute('width', '40'); 

					TD.innerHTML = showhide;
					
					TR.appendChild(TD);
					
				
					var TD = document.createElement('TD');
					TD.setAttribute('width', '20'); 
					TD.setAttribute('style', 'text-align: center;'); 
					
					
					var SPAN = document.createElement('SPAN');
					SPAN.setAttribute('class', 'prodhandle'); 
					
					
							var IMG = document.createElement('IMG');
							IMG.src = "img/up_down.gif";
							IMG.setAttribute('alt', 'Dra her for å flytte produktet.');
							IMG.setAttribute('style', 'cursor:move;');
							
							SPAN.appendChild(IMG);						
						
					
					TD.appendChild(SPAN);
					
					TR.appendChild(TD);	
					
					TBODY.appendChild(TR);	
					
					TABLE.appendChild(TBODY);	
					
					LI.appendChild(TABLE); 
					
					UL.appendChild(LI); 
				
				
				parent.appendChild(UL);
				
			
				var INPUT = document.createElement('INPUT');
				
				INPUT.setAttribute('type', 'hidden'); 
				INPUT.setAttribute('id', 'postcat'); 
				INPUT.setAttribute('name', 'cat');
				INPUT.setAttribute('value', '');
				INPUT.setAttribute('style', 'display: none;');
					
				parent.appendChild(INPUT);
				
				
				Sortable.create(
					'prd_c_40539',
					{tag:'li',handle:'prodhandle', onUpdate: 
						function()
						{
							var order = escape(Sortable.serialize('prd_c_40539'));
							
							xmlhttprequest('reorderproduct','' + order + '');					
						}
					}
				);
	
}

function xmlhttprequest(mode, id, extra)
{
	var myConn = new XHConn();
	
	if (!myConn) 
		alert("XMLHTTP not available. Try a newer/better browser.");
	
	var fnWhenDone = function (oXML) { 
		update('Oppdatert!');  
		self.setTimeout('vent(\'hidden\');', 1000);
		
	}; 
	
	/*alert(oXML.responseText);*/
	
	//var fnWhenDone2 = function (oXML) { alert(oXML.responseText); window.location.reload(true);};
	
	//myFCKeditor.GetValue()
	//escape(b64.encode(document.getElementById('textfield').value)
	
	switch (mode)
	{


		case 'loadproducts' :
			vent('visible');	
			
			// document.getElementById('prodlist' + id).style.display = '';
			
			document.getElementById('product_details_' + id).innerHTML = '<em>laster produkter..</em>';
			 
			var query =  'loadproducts=' + id;
			
			var fnWhenDone = function (oXML) { 
				
				vent('hidden');
				
				//var productlist = decodeBase64(oXML.responseText);
				
				var productlist = oXML.responseText;
				var parent = document.getElementById('product_details_' + id);
				
				parent.innerHTML = '';
				
				/*alert(productlist);*/
				
				if(productlist == '') {
					parent.innerHTML  = '<em>ingen produkter</em>';
				} else {
					eval (productlist);	
				}
			};
			
			myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
			
		break;				
		
		case 'updateprices' :
			vent('visible');
			
			var query =  'updateprices=' + extra;
			var fnWhenDone = function (oXML) { 
				update(oXML.responseText);  
				self.setTimeout('vent(\'hidden\')', 500);
			}; 			
			myConn.connect("xmlrpc/rpc_process.php?" + id, "POST", query, fnWhenDone);
			
		break;
		
		case 'reorderproduct' :
			vent('visible');
			
			var query =  'reorderproduct=' + id;
			var fnWhenDone = function (oXML) { 
				update('Oppdatert!');  
				self.setTimeout('vent(\'hidden\')', 500);
			}; 			
			myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
			
		break;
		

		case 'reordercategory' :
			vent('visible');
			
			var query =  'reordercategory=true&' + id;
			var fnWhenDone = function (oXML) { 
				update('Oppdatert!');  
				self.setTimeout('vent(\'hidden\')', 500);
			}; 			
			myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
			
		break;		
		
		case 'reorderproductoptions' :
			vent('visible');			
						
			var query =  'reorderproductoptions=' + id;
			var fnWhenDone = function (oXML) {
				//alert(decodeBase64(oXML.responseText));
				update('Oppdatert!');  
				self.setTimeout('vent(\'hidden\')', 500);
			}; 
			
			myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
			
		break;	
		
		case 'changegroup' :
			vent('visible');	
			var query =  'changegroup=' + document.getElementById('custgroups_'+id).value + '&custId='+id;		
			myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
		break;
		
		case 'set_external_id' :
			vent('visible'); 
			var query =  'set_external_id=' + escape(document.getElementById('external_id_'+id).value) + '&custId='+id;		
			myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
		break;
		
		case 'set_customer_note' :
			vent('visible'); 
			var query =  'set_customer_note=' + escape(document.getElementById('customer_note_'+id).value) + '&custId='+id;		
			myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
		break;
		
		case 'user_set_email' :
			vent('visible'); 
			var query =  'user_set_email=' + escape(document.getElementById('email_'+id).value) + '&custId='+id;		
			myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
		break;	
		
		case 'kp_update_customer' :

			vent('visible');
			
			var username 			= escape(document.getElementById('username_'+id).value);
			var old_username		= escape(document.getElementById('old_username_'+id).value);
			var email	 			= escape(document.getElementById('email_'+id).value);
			var old_email 			= escape(document.getElementById('old_email_'+id).value);
			var flexi_accesslevel 	= escape(document.getElementById('flexi_accesslevel_'+id).value);
			var external_id		 	= escape(document.getElementById('external_id_'+id).value);
			var old_external_id		= escape(document.getElementById('old_external_id_'+id).value);
			var phone			 	= escape(document.getElementById('phone_'+id).value);
			var mobile			 	= escape(document.getElementById('mobile_'+id).value);
			var fax				 	= escape(document.getElementById('fax_'+id).value);
			var address1		 	= escape(document.getElementById('address1_'+id).value);
			var zip				 	= escape(document.getElementById('zip_'+id).value);
			var city			 	= escape(document.getElementById('city_'+id).value);
			if(document.getElementById('notes_'+id)) {
				var notes 	= escape(document.getElementById('notes_'+id).value);
			} else {
				var notes = "";
			}
			
			var mustChangePasswordAtNextLogon 	= (document.getElementById('mustChangePasswordAtNextLogon_'+id).checked);
			var new_password	 	= escape(document.getElementById('new_password_'+id).value);

			var query =  'kp_update_customer='+id+'&username='+username+'&email='+email+'&flexi_accesslevel='+flexi_accesslevel+'&external_id='+external_id+'&phone='+phone+'&mobile='+mobile+'&fax='+fax+'&address1='+address1+'&zip='+zip+'&city='+city+'&notes='+notes+'&new_password='+new_password+'&mustChangePasswordAtNextLogon='+mustChangePasswordAtNextLogon;
			
			//alert(query);
			fnWhenDone = function (oXML) {
				
				var returned = escape(decodeBase64(oXML.responseText));
				
				//alert('returned value: '+returned);
				var error1 = false;
				var error2 = false;
				var error3 = false;

				if (returned.indexOf('username') > -1) {
					//alert('username pos: '+returned.indexOf('username'));
					document.getElementById('username_'+id).value = old_username;
					error1 = 'Brukernavn ikke unikt';
				} else {
					document.getElementById('old_username_'+id).value = username;
				}
				
				if (returned.indexOf('email') > -1) {
					//alert('email pos: '+returned.indexOf('email'));
					document.getElementById('email_'+id).value = old_email;
					error1 = 'E-post ikke unik';
				} else {
					document.getElementById('old_email_'+id).value = email;
				}
				
				if (returned.indexOf('external_id') > -1) {
					//alert('ext id pos: '+returned.indexOf('external_id'));
					document.getElementById('external_id_'+id).value = old_external_id;
					error2 = 'Ekstern ID ikke unik';
				} else {
					document.getElementById('old_external_id_'+id).value = external_id;
				}
				
				if (error1 || error2 || error3) {
					
					update('<strong>Oppdatering feilet: </strong>'+(error1?'<br>'+error1:'')+(error2?'<br>'+error2:'')+(error3?'<br>'+error3:''));
					self.setTimeout('vent(\'hidden\')', 4000);
									
				} else {
										
					update('Oppdatert!');
					self.setTimeout('vent(\'hidden\')', 500);
				}	
			};
			
					
			myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
		break;			
		
		case 'generate_password' :
			vent('visible');
			
			fnWhenDone = function (oXML) {
				
				var returned = escape(decodeBase64(oXML.responseText));
				
				document.getElementById(id).value = returned;
										
				update('Ferdig!');
				self.setTimeout('vent(\'hidden\')', 500);
					
			};
			
			myConn.connect("xmlrpc/rpc_process.php", "POST", 'generate_password=1', fnWhenDone);
		break;
		

		case 'showhelp' :
			
			fnWhenDone = function (oXML) {
				
				// alert("done");
									
			};
			
			myConn.connect("xmlrpc/rpc_process.php", "POST", 'showhelp=' + id , fnWhenDone);
		break;			
		
		
		case 'verify' :
			vent('visible');
						
			fnWhenDone = function (oXML) {
				
				var returned = escape(decodeBase64(oXML.responseText));
				
				if (returned == 'ERROR') {
					
					document.getElementById(id).value = '';
					document.getElementById(id).focus();
					
					update('Du må fylle inn en unik verdi!');
					self.setTimeout('vent(\'hidden\')', 4000);
					
				} else {
					vent('hidden');
				}
					
			};
			
			var query = 'verify='+id+'&verifyvalue='+document.getElementById(id).value;
			
			myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
		break;
		
		case 'changeartgroup' :
			vent('visible');			
			var query =  'changeartgroup=' + document.getElementById('artgroups_'+id).value + '&catId='+id;
			myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
		break;
		
		case 'categories' :
			var query =  'changegroup=' + document.getElementById('custgroups_'+id).value + '&custId='+id;	
			myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
		break;
		
		case 'changetext' :	
			var query =  'changegroup=' + escape(b64.encode(document.getElementById('textfield').value))
				  + '&relId=' + activelayerId2
				  + '&nodeId=' + document.getElementById('nodeid').value ;			  
			myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
		break;
		
		case 'get_pn_place' :		
			var query = '_pn=' + id;		
					
			fnWhenDone = function (oXML) { 
				
				var city = document.getElementById('city');
				var placeComment = document.getElementById('placeComment');		
				var place = decodeBase64(oXML.responseText);
								
				// city.readOnly = 1;	
				
				//window.alert(place);
				if (place == 'UKJENT') {				
					// city.readOnly = 0;
					placeComment.innerHTML = 'Vennligst spesifisér stedsnavn';
					city.focus();
				}
				
				city.value = place;
				
			};
			
			myConn.connect("/kp/xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
		break;
		
		
		case 'changeFpCat' :		
			
			vent('visible');
			var query = 'changeFpCat=' + id;
			myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
		break;
		
		
		case 'saveProductOption' :
		
			vent('visible');
			var insertName = document.getElementById('tempOpt_' + id).value;
			
			/*errorRestore = function () {
				restore.innerHTML = oldName;
			};*/
			
			fnWhenDone = function (oXML) { 				
					
				var oldName = document.getElementById('valueOf_' + id).value;
				var restore = document.getElementById('editOpt_' + id);	
				var returnName = decodeBase64(oXML.responseText);
				
				var dropDown = document.getElementById('ownerOf_' + id).value;
				var dropdownOptionId = document.getElementById('defaultDropdown_' + dropDown);
				/// loop through this dropdown and match old name to get the right one for replacing
				

				if (returnName == 'ERROR') {
					
					restore.innerHTML = oldName; //'<span style="color: red;">Feilet!</span>';
					update('Oppdatering feilet!');
					self.setTimeout('vent(\'hidden\')', 4000);
					//self.setTimeout('errorRestore(restore, oldName)', 3000);	
									
				} else {
					
					dropdownOptionId.text = returnName;
					restore.innerHTML = returnName;
					for (var c=0; c < dropdownOptionId.options.length; c++)
					{
						if (dropdownOptionId.options[c].text == oldName)
							dropdownOptionId.options[c].text = returnName;
					}
					
					update('Oppdatert!');
					self.setTimeout('vent(\'hidden\')', 1000);
				}	
				
				
				
			};
			var query = 'saveProductOption=' + id + '&newVal=' + b64.encode(insertName);
			myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
		break;
		
		
		case 'CleanUpHtml' :	
			fnWhenDone = function (oXML) { 
			/*	update('Htmldriten er fixet!');  
				self.setTimeout('vent(\'hidden\')', 1000);*/
				
				//window.open(oXML.responseText);
				//alert(oXML.responseText); 
				
				document.getElementById('contents___Frame').contentWindow.document.getElementById('eEditorArea').contentWindow.document.body.innerHTML = oXML.responseText;
				
			}; 
		
			//var html = b64.encode(document.getElementById('contents___Frame').contentWindow.document.getElementById('eEditorArea').contentWindow.document.body.innerHTML);
			//var html = escape(b64.encode(document.getElementById('contents___Frame').contentWindow.document.getElementById('eEditorArea').contentWindow.document.body.innerHTML));
			
			var html = document.getElementById('contents___Frame').contentWindow.document.getElementById('eSource').innerHTML;
					
			alert('BEFORE: ' + html);			
			
			html = b64.encode(html);
			
			var query =  'CleanUpHtml=true'  
				  +  '&html='
				  + html;
			
			myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
		break;
		
		default :
			window.alert('xmlhttprequest-modus: ' + mode + ' er ikke definert i xmlhttp.js .');
		break;
	}
	
	
	/*
	if(mode == 'changegroup')	 
	{
		vent('visible');
		
		var query =  'changegroup=' + document.getElementById('custgroups_'+id).value + '&custId='+id;			  
			  
 		//alert(query);
 		
		myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
	}	
	
	else if(mode == 'changeartgroup')	 
	{
		vent('visible');
		
		var query =  'changeartgroup=' + document.getElementById('artgroups_'+id).value + '&catId='+id;			  
			  
 		//alert(query);
 		
		myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
	}
	
	else if (mode == 'categories')
	{
		//vent('visible');
		
		var query =  'changegroup=' + document.getElementById('custgroups_'+id).value + '&custId='+id;			  
			  
 		//alert(query);
 		
		myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
	}
	
	else if(mode == 'changetext')
	{
		var query =  'changegroup=' + escape(b64.encode(document.getElementById('textfield').value))
			  + '&relId=' + activelayerId2
			  + '&nodeId=' + document.getElementById('nodeid').value ;
			  
		myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
	}

	else if(mode == 'CleanUpHtml')
	{
		//vent('visible');
		
		fnWhenDone = function (oXML) { 
/*			update('Htmldriten er fixet!');  
			self.setTimeout('vent(\'hidden\')', 1000);*/
			
			//window.open(oXML.responseText);
			//alert(oXML.responseText); 
		/*	
			document.getElementById('contents___Frame').contentWindow.document.getElementById('eEditorArea').contentWindow.document.body.innerHTML = oXML.responseText;
			
			
			
			
			
		}; 
	
		//var html = b64.encode(document.getElementById('contents___Frame').contentWindow.document.getElementById('eEditorArea').contentWindow.document.body.innerHTML);
		//var html = escape(b64.encode(document.getElementById('contents___Frame').contentWindow.document.getElementById('eEditorArea').contentWindow.document.body.innerHTML));
		
		var html = document.getElementById('contents___Frame').contentWindow.document.getElementById('eSource').innerHTML;
		

		
		alert('BEFORE: ' + html);
		
		
		html = b64.encode(html);
		
		var query =  'CleanUpHtml=true'  
			  +  '&html='
			  + html;
			//
			
			
			 
		
		myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);

		//query = "url=http://www.nsn.no";
		 
		
		
		//myConn.connect("http://www.serviceavdelingen.no/cgi-bin/scrub.cgi", "POST", query, fnWhenDone);
		
	} else if(mode == 'load_products')	 {
		
		vent('visible');
		
		var query =  'load_products=' + id;			  
			  
 		alert(query);
 		
		myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
	
	} else if (mode == 'get_pn_place') {
		
		var query = '_pn=' + id;		
				
		fnWhenDone = function (oXML) { 
			
			document.getElementById('city').readOnly = 1;			
			
			var  place = decodeBase64(oXML.responseText);
			
			//window.alert(place);
			if (place == 'UKJENT') {				
				document.getElementById('city').readOnly = 0;
				document.getElementById('city').focus();
			}	
			document.getElementById('city').value = place;
			
		};
		
		myConn.connect("../kp/xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
		
	} else if (mode == 'changeFpCat') {
		
		vent('visible');
		
		var query = 'changeFpCat=' + id;
		//window.alert(mode + '=' + id);
		
		myConn.connect("xmlrpc/rpc_process.php", "POST", query, fnWhenDone);
	}
	*/
	//make this huge elseif into a switch maybe?
}