var isAv8 = true;

//These are variables that are fixed for a user session
var sGuid=""; 
var sCustID="0";
var sCategory="0";
var sEmail = "";
var srcBanner="";
var sWdUid = "";
var sWdPwd = "";
var bGotWdAccount = "0";
var bIsIE5 = true;
var nInitialFolderID = 2147483647;
var nInitialItemID = 2147483647;
var base;
var tdw = '18px';
var bAllowedVideoUpload = "0";

//General variables
var bLoggedOut = false;
var sCurrentSearch = "";
var nLastSelected = 2147483647;
var bFirstTime = false;
var aString = "";
var numXcart = "0";
var consoleWindowHandle = null;

//Av61 is a state machine.   
var t = new Array();
t[0] = new Array('20');
t[1] = new Array('01');
t[2] = new Array('00');
t[3] = new Array('00');
var ct;
var ta;
var ba;
var pa;
var prvw;
var gds = new Array("","");

function qs2(){
	//we return the first two params of the querystring
	return("g="+sGuid+"&c="+sCategory + "&ie=" + (bIsIE5?'1':'0'));
}

function qs3(e){
	//we return the first two params of the querystring
	return("g="+sGuid+"&c="+sCategory + "&e" + "=" + e + "&ie=" + (bIsIE5?'1':'0'));
}

function updateShow(num){frames[1].frames[0].document.getElementById('txtItems').value = zPadCartItems(num);}

function qs4(f, e) {
	//return first four params of the query string for a particular frame
	return(qs2() + "&s" + f + "=" + t[f][0] + "&e" + "=" + e);
}

function loadedCSC(guid, category, email, bannerFile, wdUid, wdPwd, custID, numInCart, initialFolder, initialItem, allowedVideoUpload){	
	//check the customer IDs
	if (parseInt(custID,10) != thisCustID) {
		alert("The username and password you have entered does not match this website");
		return;
	}
	// We fill up some of the variables that remain the same throughout this session	
	sGuid = guid; sCategory = category; sEmail = email; sWdUid = wdUid; sWdPwd = wdPwd; sCustID = custID;
	nInitialFolderID = initialFolder;
	nInitialItemID = initialItem;
	base = window.location.href.substr(0, window.location.href.indexOf('csc/'));
	srcBanner = base + "csc/" + bannerFile;
	bAllowedVideoUpload = allowedVideoUpload;
	
	//Now the browser details
	if (document.getElementById) {
		if (document.all){
			bIsIE5 = true;
			tdw = tdIE;	
		}
		else {
			bIsIE5 = false;
			tdw = tdMoz;
			if (parseInt(category, 10) > 2) alert("You have logged on as a private user, but you are not using Internet Explorer version 5+.\n\nYou will be able to use the basic Avitage features (build a Show etc) but you will not be able to do the Personal Library functions that involve dragging and dropping.");
		}
	}
	else alert("You are using an old or reduced browser; to view this site, you need an up-to-date browser, such as IE5+, Netscape 7+ or Firefox");
	
	numXcart = numInCart;

	//Does this user have a wd account
	if ((sWdPwd.length > 0) && (sWdUid.length > 0)) bGotWdAccount = "1";
	//Now we load up the banner file
	frames[0].location = srcBanner;   
	bFirstTime = true;
}

function runMain() {
	// the Main frameset
	frames[1].location = base + 'mainFs.htm';	
}

function runMLeft(){
	    frames[1].frames[0].location = "left/leftTop.htm?cat=" +  sCategory + "&vid=" + bAllowedVideoUpload;
}

function runLeft(){
	var a = arguments;
	var qr = "";
	var anc = "";
	
	switch (a[0]){
		case '97': //folder icon clicked
			init();
			var pType = parseInt(leftDoc.getElementById(a[1]).getAttribute('y'),16);
			if ((pType > 130) && (pType < 151)) {
				if ((pType == 132)||(pType==142)||(pType==136)) pwdAsk(a[1]);
				else wdoc(a[1], '16');
			}
			else tog(a[1]); 
			return;
		
		case '98':
			init();
			var pType = parseInt(leftDoc.getElementById(a[1]).getAttribute('y'),16);
			if ((pType > 130) && (pType < 151)) {
				if ((pType == 132)||(pType==142)||(pType==136)) pwdAsk(a[1]);
				else wdoc(a[1], '16');
			}
			else ftc(a[1]); 
			return;
	
		case '01': 
			if (nInitialFolderID == 2147483647) t[0][0]='20'; 
			else {t[0][0]='10'; qr="&ft="+nInitialFolderID.toString();}
			qr += "&tdw="+tdw;
			updateShow(numXcart);
			break;
			
		case '02': case '03': 
			focusLeft(0);
			t[0] = new Array(a[0], a[1], a[2], a[3]);
			if (focusLeft(2)) {runRight('3a', t[0][1]); return;}
			else {qr="&it="+a[1]; break;}
			
		case '04':
		    t[0][0]='20'; 
		    qr += "&tdw="+tdw;
		    break;
		    
//6.2			
		case '05': wdoc(a[1], '16'); return;
			//focusLeft(0);
			//t[0] = new Array(a[0], a[1], a[2], a[3]);
			//if (focusLeft(2)) {runRight('14','16', t[0][1]); return;}
		//	else {qr="&it="+a[1]; break;}
			
//6.2:						
		case '06': tog(a[1]); 
			return; //used to be case '07' as well
			//qr="&fl="+a[1]; anc = "#" + a[1]; break;
			
		case "07":
			draw(true);
			return;
			

		///case '09': //lib dropdown clicked
	//		t[0][0] = a[1];
	//		qr="&xx=" + Math.random();
		//	if (t[0].length > 1) 	anc = "#" + t[0][1];
		//	break;
				
		case '0a': //lib mode dialog been clicked OK
			switch (a[1]){
				case '52': //add folder
					addFldr(a[2].substr(0,(a[2].length-1)), a[3]);
					return;	
				
				case '54': // renaming folder
					renFldr(a[2].substr(0,(a[2].length-1)), a[3]); return;
				
				case '57': case '60': // lock webDoc, unlock webDoc, 
					frames[1].frames[3].location = base + "left/hid.aspx?" + qs3(a[1]) + "&ri=" + a[3].substr(0, a[3].length-1) + "&nm=" + a[2];
					return;
					
				case '53': 
					remFldr(a[2]);
					return;
		
				case '5a': //export folder
					t[0][0] = a[1];
					runRight(a[0], a[1], a[2]);return; // no need to run left
					
			//	 case '66': break; //edit comments
					
				case '68':
					t[0] = new Array('68',a[2],a[3],a[4]);
					//aFoldersChecked[0], escape(sEmail), sExpiry
					break;
					
				case '69': //module clicked second time
					addModule(a[2]); return;
					//qr="&ic="+t[0][1]+"&dx="+t[0][3]+"&em="+t[0][2]; break;
					
				case '6f':
					//sExpiry, escape(sEmail), escape(url), escape(title), checkBox rowId; 
					qr="&dx="+a[2]+"&em="+a[3]+"&ul="+a[4]+"&nm="+a[5];
					addLinkOrFlash(a[6].substr(0,a[6].length-1), qr, '90');
					return;
					
				case '70':
					//lnk, sKey, aFoldersChecked[0]);
					impFldr(a[2], a[3], a[4].substr(0, a[4].length-1)); return;
					
				case '58': //uploading Flash
					qr="&id="+a[2];
					addLinkOrFlash(a[3], qr, '109');
					return;
					
				case '71':  
					$_deleteRow(a[2]);
					return;
					
				case '72':  //'0a', '72', sExpiry, escape(sEmail), dumpID, escape(title), aFoldersChecked[0], notes
					qr="&dx="+a[2]+"&em="+a[3]+"&di="+a[4]+"&nm="+a[5]+"&cm="+a[7];
					addLinkOrFlash(a[6].substr(0,a[6].length-1), qr, '10a');
					return;				    
					
			} 
			t[0][0] = a[1];			
			break;

		case '0b':
			t[0][0]='21'; break;
			
		case '1f':
			if (focusLeft(2)){t[0][0] = '05'; runRight('14','16', t[0][1]); return;}
			else {
				if (t[0].length > 1) {t[0][0] = '05'; qr="&it="+t[0][1]; break;}
				else{
					t[3][0] = 'ff';
					frames[1].frames[2].frames[1].location = base + "btm/btmEm.htm?28";
					return;
				}
			}
			
		case "21":
			var ret = window.showModalDialog(base + "btm/btmToPl.htm","" , "dialogHeight: 110px; dialogWidth: 450px; edge: raised; center:yes; help: No; resizable: Yes; status: No; scroll: No;");
			if (ret == "") return;
			t[0][0] = '08';
			var esc = getSavedCartsFolderEState(); 
			var epl = leftDoc.getElementById('i').getAttribute('e');
			frames[1].frames[3].location = base + "left/hid.aspx?" + qs3('96') + "&esc=" + esc + "&epl=" + epl + "&nm="+escape(ret);
			return;		
			
		case '27':
			t[0][0] = '06';
			if (!focusLeft(1)) break;
			else return;
			
		case "2a": case "5b":
			t[0] = new Array('05', a[1], a[2], a[3]);
			runRight('14','16', t[0][1]); return;
			
		
			
		case "2c": //
			t[0][0] = '09';
			aString = a[1]; // status message
			addPPT(a[2], a[3]); //rowId, temp Folder Id
			return;
			
		case "2d":
			t[0] = new Array('05', a[1], a[2], a[3]);
			runRight('14','2e', t[0][1]); return;
			
		case "2f":
			t[0] = new Array('05', a[1], a[2], a[3]);
			aString = "Link (URL) added successfully.";
			runRight('14','2e', t[0][1]); return;	
			
		case "3b":
			draggedFolder(a[1], a[2], a[3]);
			return;
			
		case "3e":
			qr="&bl="+a[1]+"&tt="+a[2]+"&ri="+selRowId + "&dc="+escape(a[3]);
			addItems(a[2], qr);
			return;
			
		case "3f":
			aString = "Drag and drop successful.";
			var aSel = frames[1].frames[3].x[0];
			var riLoad = frames[1].frames[3].x[1];
			if (riLoad == 'x') draw(false);
			else {
				// add loading row
				init();
				var indent = (riLoad == '' ? 1 : $_getIndentById(riLoad))
				var loadingRow = $_createLoadingRow(indent);
				if (riLoad == '') leftDoc.getElementById('kt').appendChild(loadingRow);
				else leftDoc.getElementById('kt').insertBefore(loadingRow, leftDoc.getElementById(riLoad));	
				draw(true);		
			}
			wdoc(aSel, '2e');  return;
			
		case "47":
			focusLeft(1);
			return;
			
		case "48": case "a0":
			qr="&ft="+a[1]+"&tdw="+tdw;
			break;
			
		case "49":
			t[0] = new Array('05');
			if (!sel(a[2])) return; // select the current row	
			runRight('14', '4a', a[1], a[2]);
			return;
			
//6.2			
		case "63":   //used to be case "62": as well
			// proper folder title clicked
			ftc(a[1]); return;
			//focusLeft(0);
			//t[0] = new Array('11', a[1], a[2], a[3]);
			//qr="&fl="+a[1]; anc = "#" + a[1]; 
		//	break;
		
		case "7e":
			draw(false); runRight('0a','71'); return;
			
		case "7f":
			draw(false); return;
			
		case "8d":
		    focus(1);
		    frames[1].frames[2].location = base + "right/rightInit.htm"; return;	
		    
			
		case "90": case "91": case "109": case "10a":
			draw(true); wdoc(frames[1].frames[3].x[0], '16');  return;
			
		case "92": 
			draw(true); return;
			
		case "93":			
			draw(true); wdoc(frames[1].frames[3].x[0], '2e');  return;
			
		case "95":
			if (a[1].length == 0) runRight('01');
			else dlti(a[1]);
			return;
			
		case "96":
			saveCart();
			return;
			
		case "99":
			droppedFolder(); return;
			
		case "9c":
			reOwner(a[1]);
			return;

		case "9e": draw(false); alert("Folder locked successfully");return;
		
		case "9f": draw(false); alert("Folder unlocked successfully");return;
			
		case "100":
			unLinkFirst(a[1]);
			return;
			
		case "101":
			draw(false); runTop('7a');
			return;
			
		default: alert("left event missing from runLeft(): " + a[0]);
	}
	
	//get checked folders, update state and hit left.aspx
	//var checked = arrayOfFoldersChecked();	
	frames[1].frames[1].location = base + "left/left.aspx?" + qs4(0, a[0]) + qr;
}

function focusLeft(p) { //0 = no focus or select, 1 = focus, 2 = select
	if (!bIsIE5) return(false);
	if (t[0].length < 4) return(false);
	if(t[0][0] == "69") return(false);
	var c = eval("frames[1].frames[1].document.getElementsByName." + t[0][2]);
	if (c == null) return(false);
	var canDrag = (t[0][3] == '1');
	switch (p) {
		case 0:
			if (canDrag) c.className = 'bhv';
			else c.className = '';
			break;
			
		case 1:
			if (canDrag) c.className = 'bhv focus';
			else c.className = 'focus';
			break;
	
		case 2:
			if (canDrag) c.className = 'bhv selected';
			else c.className = 'selected';
			break;
	}
	window.focus();
	return(true);
}

function runRight(){
	var a = arguments;
	var qr = "";
	
	switch(a[0]){
		case '01': case '0b':
			t[1][0] = a[0];
			break;
			
		case '09':
			focus(1);
			t[1][0] = a[1];
			break;
		
		case '0a': //lib mode dialog been clicked OK
			t[1][0]=a[1];
			switch (a[1]){			
				case '52': case '54': case '57': case '60': //add folder, rename folder, lock webDoc, unlock webDoc; been done in left
					break;
					
				case '53': //remove folder
					break;
				
				case '5a': //export folder
					qr="&ri="+a[2].substr(0, a[2].length-1);break;
					
				case '66':  //edit comment
					qr="&ri="+a[2].substr(0, a[2].length - 1); break;
					
				case '67':
					var f = frames[1].frames[2].document.frmComment;
					f.action = base + 'right/rightLib.aspx?' + qs4(1,a[0]) + '&ri=' + a[2].substr(0, a[2].length - 1);
					f.submit();
					return;
					
				case '68': //module first clicked: checked folder to be module, escape(sEmail), Expiry number of days;
					ct = new Array(a[2].substr(0, a[2].length - 1), a[3], a[4]);
					//qr="&ri="+a[2].substr(0, a[2].length - 1) + "&em=" + a[3] + "&dx=" + a[4];
					break;
					
				case '6a':
					var f = frames[1].frames[2].document.frmUpload;
					f.action = base + "right/rightLibPptEf.aspx?" + qs4(1,'0a') + "&cx=" + a[2].substr(0, a[2].length - 1) + "&wv=" + a[3];
					f.submit();
					return;
					
				case '6c': 
					var f = frames[1].frames[2].document.frmUpload;
					f.action = base + "right/rightLibPptEf.aspx?" + qs4(1,'0a') + "&cx=&wv=" + a[2];
					f.submit();
					return;					
					
				case '6e':
					var f = frames[1].frames[2].document.frmUpFlash;
					f.action = base + "right/rightLibFlash.aspx?" + qs4(1,'0a') + "&cx=" + a[2].substr(0, a[2].length - 1);
					f.submit(); return;
					
				case'70': // checking remove folder		
					qr="&ri=" + a[2].substr(0,(a[2].length-1));
					break;
					
				case '71':
					break;
					
				case '106':
					var f = frames[1].frames[2].document.frmUpload;
					f.action = base + "right/rightBatchReplace.aspx?" + qs4(1,'0a') + "&dx=" + sExpiryDays + "&wv=" + a[2];
					f.submit();
					return;
			}
			break;
			
		case '0c':
			//alert("Rights state is " + t[1][0] + ", tops state is " + t[2][0]);
			if (t[1][0] == 'ff') {
				var ts = parseInt(t[2][0], 16);
				if ((ts > 1) && (ts < 101)) {t[0] = new Array('07');return;}
				else {t[0] = new Array('21'); t[1] = new Array('02');}
			}
			else return;
			break;
									
		case '10':
			t[1][0] = a[0];
			focus(1);
			var p = frames[1].frames[2].frames[1].document.getElementById('proc');
			if (p != null) p.style.color="#ff0000";
			if (isAv8)
				qr="&jt=Y29tcGlsZVBwdA2&ri="+selRowId+"&px="+a[1]+"&nt=0"; 
			else
				qr="&ri="+selRowId+"&nt=0"; 
			break;	
			
		case '11':
			t[1][0] = '0d';
			focus(1);
			qr="&ri="+selRowId+"&nt=0"; 
			break;
			
		case '12':
			t[1][0] = '0e';
			focus(1);
			qr="&ri="+selRowId+"&nt=0"; 
			break;
			
		case '13': 
			t[1][0] = '0f';
			focus(1);
			qr="&ri="+selRowId;
			break;			
			
		case '14':
			t[1] = new Array('ff');
			ta = new Array(a.length - 1);
			for (var i = 1; i < a.length; i++) ta[i-1] = a[i];
			if (frames[1].frames[2].frames[0] == undefined) frames[1].frames[2].location = base + "right/rightFs.htm";	
			else runTop();
			return;	
			
		case '15':
			t[1] = new Array('ff');
			ba = new Array(a.length - 1);
			for (var i = 1; i < a.length; i++) ba[i-1] = a[i];
			if (frames[1].frames[2].frames[0] == undefined) frames[1].frames[2].location = base + "right/rightFs.htm?x";	
			else runBottom();
			return;	
			
		case '1b':
			t[1][0] = '19';
			focus(1);
			var p = frames[1].frames[2].frames[1].document.getElementById('proc');
			if (p != null) p.style.color="#ff0000";
			if (isAv8)
				qr="&jt=Y29tcGlsZVBwdA2&px="+a[1]+"&nt=0"; 
			else
				qr="&nt=0"; 
			break;				
		
		case '1c': 
			t[1][0] = '17';
			break;
			
		case '1d': 		
			t[1][0] = '18';
			break;
			
		case'1e':		
			t[1][0] = '0f';
			break;	
			
		case '30':
			t[1][0] = '13';
			qr="&fn="+escape(a[1]+"/"+a[2])+"&ri="+ selRowId;
			break;
			
		case '31':
			t[1][0] = '19';
			ct = new Array(a[1], a[2]);  //days to expiry, unescaped cartName
			qr="&nm="+escape(a[2])+"&pi="+a[3]+"&nt=0";
			break;			
			
		case '32':
			t[1][0] = '1c';		
			qr="&fn="+escape(a[1]+"/"+a[2]);
			break;
			
		case '33': case '34':
			if (a[0] == '33') t[1][0] = '1a'; else t[1][0] = '1b';
			//runRight(p, days.toString(), cartName, audio, rel, email, folder index, flash player);
			ct = new Array(a[1], a[5]);  //days to expiry, unescaped email
			qr="&nm="+escape(a[2])+"&au="+a[3]+"&rl="+escape(a[4])+"&em="+escape(a[5])+"&fp="+a[7]+"&nt=0";
			break;
			
		case '35': // wmp output secure directory + file; id of webDoc in tree
			t[1][0] = '14';		
			qr="&fn="+a[1]+"&ri="+selRowId+"&dx="+ct[0]+"&em="+escape(ct[1])+"&nm="+escape(ct[2]);
			break;	
		
		case '36': // wmp output secure directory + file
			t[1][0] = '1d';
			qr="&dx="+ct[0]+"&fn="+a[1]+"&em="+escape(ct[1]);
			break;
			
		case "37":
			t[1][0] = '15';		
			qr="&fn="+a[1]+"&ri="+selRowId+"&dx="+ct[0]+"&em="+escape(ct[1])+"&nm="+escape(ct[2]);
			break;			
		
		case "38":
			t[1][0] = '1e';
			qr="&dx="+ct[0]+"&fn="+a[1]+"&em="+escape(ct[1]);
			break;	
			
		case "3a":
			t[1][0] = '1f';
			qr="&ri="+ a[1]+"&nt=0";	
			break;	
			
		case "4d":
			focusLeft(1);
			frames[1].frames[2].location = base + "admin/acHome.htm"; return;	
			
		case "4e":
			frames[1].frames[2].location = base + "admin/acPwd.aspx?" + qs2() + "&op="+escape(a[1])+"&np="+escape(a[2]); return;	
			
		case "4f":
			frames[1].frames[2].location = base + "admin/acLinks.aspx?" + qs2() + "&e=4f&so="+a[1]; return;	
			
		case "51":
			focusLeft(1);
			frames[1].frames[2].location = base + "admin/adHome.htm"; return;	
			
		case "5d":
			frames[1].frames[2].location = base + "admin/adMngLinks.aspx?" + qs2() + "&e=5d&so="+a[1]+"&ru="+a[2]; return;	
			
		case '60': case '61':
			if (a[0] == '60') t[1][0] = '11'; else t[1][0] = '12';
			//runRight(p, days.toString(), cartName, audio, rel, email, folder index, flash player);
			ct = new Array(a[1], a[5], a[2]);  //days to expiry, unescaped email, unescaped show name
			qr="&nm="+escape(a[2])+"&au="+a[3]+"&rl="+escape(a[4])+"&em="+escape(a[5])+"&ri="+selRowId+"&fp="+a[7]+"&nt=0";
			break;		
			
		case '84':
			t[1][0] = '24';
			focus(1);
			qr="&ri="+selRowId + "&np=" + a[1]; 
			break;			
			
		case '85':
			t[1][0] = '25';
			qr="&np=" + a[1]; 
			break;		
			
		case '86':
			t[1][0] = '26';
			focus(1);
			qr="&ri="+selRowId+"&nt=0"; 
			break;			
			
		case '87':
			t[1][0] = '27';
			qr = "&nt=0"; 
			break;				
			
		case '88':
			t[1][0] = '28';
			qr="&fn="+escape(a[1]+"/"+a[2])+"&ri="+ selRowId;
			break;		
			
		case '89':
			t[1][0] = '29';		
			qr="&fn="+escape(a[1]+"/"+a[2]);
			break;	
			
		case '8a':
			t[1][0] = '2a';
			focus(1);
			if (isAv8) {
				var p = frames[1].frames[2].frames[1].document.getElementById('proc');
				if (p != null) p.style.color="#ff0000";
				qr="&jt=Y29tcGlsZUF1ZGlv0&ri="+selRowId+"&nt=0"; 
			}
			else 
				qr="&ri="+selRowId+"&nt=0"; 

			break;			
			
		case '8b':		
			t[1][0] = '2b';
			if (isAv8) {
				focus(1);
				var p = frames[1].frames[2].frames[1].document.getElementById('proc');
				if (p != null) p.style.color="#ff0000";
				qr="&jt=Y29tcGlsZUF1ZGlv0&nt=0"; 
			}
			break;
			
		case '8c':
			t[1][0] = '2c';		
			//before Adam's change for 6.8.3, podcast : qr="&fn="+a[1]+"&ri="+a[2]+"&ct="+a[3]+"&nm="+escape(a[4]);
			qr="&fn="+a[1]+"&ri="+a[2]+"&ct="+a[3]+"&nm="+escape(a[4])+"&fl="+escape(a[5])+"&fc="+a[6];
			break;		
			
		case '103':
			frames[1].frames[2].location = base + "admin/showDetails.aspx?" + qs2() + "&e=103&li="+a[1]; return;	
			
		case '107':
			frames[1].frames[2].location = base + "right/rightBatRep3.aspx?" + qs2() + "&er="+a[1]+"&dix="+a[2]; return;	
			
		case 'b0':
		    frames[1].frames[2].location = base + "right/consoleAsk.aspx?" + qs3('b0') + "&ri="+selRowId; return;	
		
		case 'b1':
		    frames[1].frames[2].location = base + "right/consoleAsk.aspx?" + qs3('b1'); return;	
	
		default: alert("right state and mode missing: " + a[0] + " " + a[1]);
	
	}
	switch (t[1][0]) {
		case '01':
			frames[1].frames[2].location = base + "right/rightInit.htm"; break;
			
		case '02':
			frames[1].frames[2].location = base + "right/rightBlank.htm"; break;
			
		case '0f':
			frames[1].frames[2].location = base + "wd/wdHost.aspx?" + qs4(1,a[0]) + qr;break;
			
		case '10': case '11': case '12': case '19': case '1a': case '1b': case '26': case '27':
			if (isAv8)
				frames[1].frames[2].location = base + "right/netProc.aspx?" + qs4(1,a[0]) + qr;
			else
				frames[1].frames[2].location = base + "right/rightProc.aspx?" + qs4(1,a[0]) + qr;
			break;
		
//      before Adam's change for 6.8.3 podcast		
//		case '13': case '1c': case '15': case '1e': case'2c':
//			frames[1].frames[2].location = base + "right/pptShow.aspx?" + qs4(1,a[0]) + qr;break;

		case '13': case '1c': case '15': case '1e':
			frames[1].frames[2].location = base + "right/pptShow.aspx?" + qs4(1,a[0]) + qr;break;
		case '2c':
		    switch (a[3]){
		        case '4':
                    frames[1].frames[2].location = base + "right/audShow.aspx?" + qs4(1,a[0]) + qr;break;
                default:
                    frames[1].frames[2].location = base + "right/pptShow.aspx?" + qs4(1,a[0]) + qr;break;
		        }
		    break;

			
		case '14': case '1d':
			frames[1].frames[2].location = base + "right/wmpStShow.aspx?" + qs4(1,a[0]) + qr;break;
			
	//	case '16':
		//	frames[1].frames[2].location = base + "right/pptCompile.aspx?" + qs4(1,a[0]) + qr;break;
			
		case '17': case '18': case '0e':
			frames[1].frames[2].location = base + "right/wmpCompile.aspx?" + qs4(1,a[0]) + qr;break;

		case '0d': 
			if (isAv8)
				frames[1].frames[2].location = base + "right/videoShow.aspx?" + qs4(1,a[0]) + qr;
			else
				frames[1].frames[2].location = base + "right/wmpCompile.aspx?" + qs4(1,a[0]) + qr;
			break;	
			
		case '1f':
			frames[1].frames[2].location = base + "right/wdLocked.aspx?" + qs4(1,a[0]) + qr;break;
			
		case '5b':
		    frames[1].frames[2].location = base + "right/rightLibKnowledge.aspx?" + qs4(1, a[0]) + qr; break;

		case '5d': case '61':
		    frames[1].frames[2].location = base + "right/rightLibVideo.aspx?" + qs4(1, a[0]) + "&new=1"; break;
			
		case '5f': case '5c':
			frames[1].frames[2].location = base + "right/rightLibPptEf.aspx?" + qs4(1,a[0]) + qr;break;
			
		case '58':
			frames[1].frames[2].location = base + "right/rightLibFlash.aspx?" + qs4(1,a[0]) + qr;break;
			
		case '70':
			frames[1].frames[2].location = base + "right/checkRemove.aspx?" + qs4(1,a[0]) + qr;break;
			
		case '24': case '25':
			frames[1].frames[2].location = base + "right/genName.aspx?" + qs4(1,a[0]) + qr;break;		
			
		case '28': case '29':
			frames[1].frames[2].location = base + "right/webExName.aspx?" + qs4(1,a[0]) + qr;break;			
			
		case '2a': case '2b':
			if (isAv8)
				frames[1].frames[2].location = base + "right/netProc.aspx?" + qs4(1,a[0]) + qr;
			else
				frames[1].frames[2].location = base + "right/audioCompile.aspx?" + qs4(1,a[0]) + qr;
			break;	
					
		case '105': case '109':
			frames[1].frames[2].location = base + "right/rightBatchReplace.aspx?" + qs4(1,a[0]) + qr;break;

		default:
			frames[1].frames[2].location = base + "right/rightLib.aspx?" + qs4(1, a[0]) + qr;
	}
}

function runTop() {
	var a = arguments;
	var qr = "";
	if (a.length > 0) {
		ta = new Array(a.length);
		for (var i = 0; i < a.length;i++) ta[i] = a[i];
	}
	switch (ta[0]){
	
		case "16": 
			t[2] = new Array('01');	
			qr="&ri="+selRowId;
			break;		
			
		case "a7":	
			t[2] = new Array('06');	
			qr="&ri="+selRowId + "&ss=" + nInitialItemID.toString();
			break;		
				
		case "20": case "25":
			frames[1].frames[0].document.getElementById('txtItems').value = zPadCartItems("0");
			t[2][0] = '04'; break;
			
		case "26":
			t[2] = new Array('02', ta[1], ta[2]);
			qr="&ni="+t[2][1]+"&th="+t[2][2];
			frames[1].frames[0].document.getElementById('txtItems').value = zPadCartItems(ta[1]);
			break;
			
		case "28":
			t[2][0] = '03'; break;
			
		case "29": return;
		
		case "2e":
			t[2] = new Array('01',ta[1]);
			qr="&ri="+selRowId+"&ms="+aString;
			aString = "";
			break;			
			
		case "40":
			if (!bIsIE5) { //~moz
				switch(ta[1]) {
					case '97': alert("You cannot use the Replace Slide Graphic function unless your browser is Internet Explorer version 5+"); return;
					case '95': alert("You cannot move items (except for your Custom Show) unless your browser is Internet Explorer version 5+"); return;
				}
			}
			t[2] = new Array(ta[1], t[3][1]);
			//qr="&it="+t[3][1];
			break;
			
		case "41":	
			switch (ta[1]) {
				case "a6": 
					t[2] = new Array(ta[1], t[0][1]);
					qr="&og="+ta[2]+"&ng="+ta[3]+"&bl="+ta[4]; break;
				default: 
					t[2] = new Array(ta[1], ta[2]);
					qr="&bk="+ta[2]+"&dc="+ta[3]+"&sg="+ta[4] + "&ri="+selRowId; break;
			}
			break;
			
		case "45":
			t[2] = new Array('05', ta[1]);
			focus(1);
			qr="&ni="+ta[1];
			break;
			
		case "4a":
			t[2] = new Array('01',ta[1], ta[2]);
			qr="&ri="+t[2][2]+"&ss="+t[2][1];
			break;
			
		case "4c":
			t[2] = new Array('01',ta[1]);
			qr="&ms="+aString+"&ri="+selRowId;;
			aString = "";
			break;			

//6.2			
		case "64": 
			t[2] = new Array('c0', ta[1]);	
			qr="&ri="+selRowId; 
			break;
		
		case "65": 
			t[2] = new Array('c0', ta[1]);
			qr="&ri="+ta[1]; 
			break;
			
		case "66":
			t[2] = new Array('01',ta[1]);
			qr="&ri="+ta[1]; 
			break;			
			
		case "7a":
			qr="&ri="+selRowId; 
			break;		
			
		case "10b":
			t[2] = new Array('a7', ta[1]);
			qr="&ri="+selRowId+"&id="+ta[1]; 
			break;
	}
	switch (ta[0]){

		case "40": case "41": case "10b":
				if (frames[1].frames[2].document.body.rows != topItemsMngHeight + ",*") frames[1].frames[2].document.body.rows = topItemsMngHeight + ",*";
				frames[1].frames[2].frames[0].location = base + "top/topItemsMng.aspx?" + qs4(2,ta[0]) + qr;
				break;
		default:
				if (frames[1].frames[2].document.body.rows != topCommentHeight + ",*") frames[1].frames[2].document.body.rows = topCommentHeight + ",*";
				frames[1].frames[2].frames[0].location = base + "top/topComment.aspx?" + qs4(2,ta[0]) + qr;
				break;
	
	}
}

function runBottom() {
	var a = arguments;
	var qr = "";
	var arr;
	if (a.length > 0) {
		ba = new Array(a.length);
		for (var i = 0; i < a.length;i++) ba[i] = a[i];
	}
	switch (ba[0]){
				
		case "0d":
			t[3][0] = '02';
			focus(1);
			var f = frames[1].frames[2].frames[1].document.frm;
			f.action = base + "btm/btmCt.aspx?" + qs4(3,ba[0]) + "&ri="+selRowId + "&vw=1"; 
			f.submit();
			return;
			
		case "0f":
			t[3][0] = '02';
			focus(1);
			qr = "&vw=1"
			break;
			
		case "17": case "a2":
			t[3] = new Array('01');
			if (a.length < 2) qr="&vw=1"+"&ri="+selRowId;
			else qr="&ri="+ba[1] +"&vw=1";   //rowId, view (1 = don't know, 2 = listview, 3 = thumbnail)
			break;
			
		case "18": case "a3":
			qr="&vw=2&ri="+selRowId;
			break;
						
		case "19": case "a4":
			qr="&vw=3&ri="+selRowId;
			break;		
			
		case "22":
			t[3][0] = '02';
			var f = frames[1].frames[2].frames[1].document.frm;
			f.action = base + "btm/btmCt.aspx?" + qs4(3,ba[0]) + "&vw=1"; 
			f.submit();
			return;
			
		case "23":
			qr="&vw=2";
			break;
			
		case "24":
			qr="&vw=3";
			break;
		
		case "29":
			frames[1].frames[2].frames[1].location = base + "btm/btmEm.htm?" + ba[1]; return;
			
		case "2b":
			var f = frames[1].frames[2].frames[1].document.frm;
			f.action = base + "btm/btmCt.aspx?" + qs4(3,ba[0]) + "&vw=2"; 
			f.submit();
			return;
			
		case "3c":
			qr="&tc="+a[1]+"&dc="+a[2]+"&re="+a[3];
			break;
			
		case "3d":
			qr="&vw=1&ri="+selRowId+"&tc="+a[1]+"&re="+a[3]+"&dc="+escape(a[2]);
			break;
			
		case "41":
			t[3] = new Array(ba[1]);
			switch (ba[1]){
				case "a0": //remove items
					qr="&bl="+ba[2]+"&vw=1&dc="+escape(ba[3]) + "&ri="+selRowId;
					aString = "Remove operation completed";
					break;
					
				case "a1": //rename item
					qr="&dc="+ba[2]+"&vw=1&nm="+escape(ba[3])+"&ri="+selRowId + "&bk=" + ba[4];
					aString = "";
					break;
					
				case "a2": //re-epxiry
					qr="&dx="+ba[2]+"&vw=1&dc="+escape(ba[3])+"&ri="+selRowId;
					aString = "";
					break;
					
				case "a3": //re-author
					qr="&nm="+escape(ba[2])+"&vw=1&dc="+escape(ba[3])+"&ri="+selRowId;
					aString = "";
					break;
					
				case "a4": //re-owner
					qr="&ru="+ba[2]+"&vw=1&dc="+escape(ba[3])+"&ri="+selRowId;
					aString = "";
					break;
			}
			break;
			
		case "42":
			t[3][0] = '03';
			qr = "&vw=1&so="+ba[1]+"&nm="+ba[2];
			break;		
			
		case "43":
			qr="&vw=2&si="+ba[1];
			break;
						
		case "44":
			qr="&vw=3&si="+ba[1];
			break;	
			
		case "46":
			t[3][0] = '02';
			var f = frames[1].frames[2].frames[1].document.frm;
			f.action = base + "btm/btmCt.aspx?" + qs4(3,ba[0]) + "&it=" + ba[1] + "&vw=1"; 
			f.submit();
			return;		
			
		case "4b":
			t[3] = new Array('01',ba[1]);
			qr="&vw=1&ri="+ba[1]+"&ss="+ba[2];
			break;		
						
		case "64":
			frames[1].frames[2].frames[1].location = base + "btm/btmFolderEmpty.htm";
			return;
			
		case "65":
			t[3] = new Array('c0', ba[1], ba[2]);
			qr = "&ri="+ba[1];
			break;
			
		case "66":
			t[3] = new Array('01', ba[1], ba[2]);
			qr = "&ri="+ba[1];		
			break;
			
		case "67": case "68": case "6a": case "6d": case "6f":
			qr = "&ri="+t[3][1];
			break;
				
		case "69": case "6b": case "6c": case "6e":
			var f = frames[1].frames[2].frames[1].document.frm;
			if (t[3][2]=="2") 
				f.action = base + "btm/discReadO.aspx?" + qs4(3,ba[0]) + "&ri="+t[3][1];
			else
				f.action = base + "btm/discReadNo.aspx?" + qs4(3,ba[0]) + "&ri="+t[3][1];
			f.submit();
			return;		
			
		case "7a":
			qr="&ri="+selRowId; 
			break;	
			
		case "a5": case "a6":
			t[3][0] = '01';
			focus(1);
			var f = frames[1].frames[2].frames[1].document.frm;
			f.action = base + "btm/btmArWd.aspx?" + qs4(3,ba[0]) + "&ri="+selRowId + "&vw=1"; 
			f.submit();
			return;
			
		default: alert("cscjs runBottom() - event " + ba[0] + " NOT written yet");		
	}
	
	switch (ba[0]){
		case "0f": case"23": case "24": case "3c":
			frames[1].frames[2].frames[1].location = base + "btm/btmCt.aspx?" + qs4(3,ba[0]) + qr; 
			break;
		case "42": case "43": case "44":
			frames[1].frames[2].frames[1].location = base + "btm/btmSch.aspx?" + qs4(3,ba[0]) + qr; 
			break;
		case "65": case "66": case "68": 
			 if (t[3][2]=="2")
				frames[1].frames[2].frames[1].location = base + "btm/discReadO.aspx?" + qs4(3,ba[0]) + qr; 
			else
				frames[1].frames[2].frames[1].location = base + "btm/discReadNo.aspx?" + qs4(3,ba[0]) + qr; 
			break;
		case "67":
			frames[1].frames[2].frames[1].location = base + "btm/discAddPost.aspx?" + qs4(3,ba[0]) + qr; 
			break;
		case "6a":
			frames[1].frames[2].frames[1].location = base + "btm/discEditO.aspx?" + qs4(3,ba[0]) + qr; 
			break;
		case "6d":
			frames[1].frames[2].frames[1].location = base + "btm/discOwner.aspx?" + qs4(3,ba[0]) + qr; 
			break;
		case "6f":
			frames[1].frames[2].frames[1].location = base + "btm/discDownload.aspx?" + qs4(3,ba[0]) + qr; 
			break;		
		case "7a":
			frames[1].frames[2].frames[1].location = base + "btm/propIntLnks.aspx?" + qs4(3,ba[0]) + qr; 
			break;		
		case "a2": case "a3": case "a4":
			frames[1].frames[2].frames[1].location = base + "btm/btmArWd.aspx?" + qs4(3,ba[0]) + qr; 
			break;					
		default:
			frames[1].frames[2].frames[1].location = base + "btm/btmWd.aspx?" + qs4(3,ba[0]) + qr; 
			break;
	}

}

function hitPreview(){
	var a = arguments; 
	var qr = qs2()+"&ps="+a[0] + "," + a[1];
	var params = "width=" + previewWidth + ",height=" + previewHeight + ",scrollbars=1,resizable=1,dependent=1,location=1";//,menubar=1";
	var w = window.open(base + "prvw/prvwFs.aspx?" + qr + "&ftt=1", "_blank",params);
	w.focus();
}

function relOpen(itemID){
	var params ="screenX=200,toolbar=0,status=0,menubar=0,scrollbars=1,resizable=1,width=720,height=500,titlebar=yes,dependent=1";
	window.open('../prvw/relList.aspx?' + qs2() + "&ps=" + itemID + "_0",'related', params);
}

function setGuids(){
	if (gds[0] != "") frames[1].frames[2].frames[0].document.getElementById('txtItemOld').value = gds[0];
	if (gds[1] != "") frames[1].frames[2].frames[0].document.getElementById('txtItemNew').value = gds[1];
}

function clearGuids(){
	for (var i = 0; i < 2; i++) gds[i] = "";
}

function hitReplace(itemGuidOld, itemGuidNew) {
	var ret = window.showModalDialog(base + "top/replace.aspx?" + qs2() + "&og=" + itemGuidOld + "&ng=" + itemGuidNew, new Array(1,1) , "dialogHeight: 520px; dialogWidth: 700px; edge: raised; center:yes; help: No; resizable: Yes; status: No;");	
	if (ret == -1) return;
	runTop("41", "a6", itemGuidOld, itemGuidNew, ret.toString());
}

function logout(param){	
	if (param == 1) {
		location = base + "csc/logout.aspx?g=" + sGuid;
		bLoggedOut = true;
	}
	else {
		if (!bLoggedOut) window.open(base + "csc/logout.aspx?g=" + sGuid, "_blank", "width=600,height=400");		
	}
}

function trim(sIn) {
	var s = sIn;
	while (''+s.charAt(0)==' ') s = s.substring(1,s.length);
	while (''+s.charAt(s.length-1)==' ') s = s.substring(0,s.length-1);
	return(s); 
} 

function zPadCartItems(s){
	switch(s.length){
		case 1: return("   "+s);
		case 2: return("  "+s);
		case 3: return(" "+s);
		default: return(s);
	}
}

function arrayOfFoldersChecked() {
	//	We return an array of the number of Library checkboxes checked

	var cChecked = new Array(0);
	var sFields;

	var cChks = frames[1].frames[1].document.getElementsByName('ch');
	if (cChks == null) return cChecked;
	if (cChks.length == null) {
	//	We only have one checkbox
		if (cChks.checked == true) {
			sFields = cChks.id.split('x');
			cChecked[cChecked.length] = sFields[3].replace("m","-");

		}
	}
	else {
	//	More than one checkbox	
		for (var i = 0; i < cChks.length; i++) {
			if (cChks[i].checked == true) {
				sFields = cChks[i].id.split('x');
				cChecked[cChecked.length] = sFields[3].replace("m","-");
			}
		}
	}
	return cChecked;
}

//###############  6.2 stuff:   #############################################################


var leftDoc;
var selRowId = '';
var focused = false;
var selRowTr = null;
var cche = new Array('');

function init() {leftDoc = frames[1].frames['mainLeft'].document;}

function focus(p){
	// param p: 0 = deselect (no focus and no select); 1 = focus; 2 = select;
	if (p == 0) {$_deSelectAll(); return;}
	if (selRowId == '') return;
	var selectedCell = leftDoc.getElementById(selRowId + 'r');
	if (selectedCell == null) return;
	if (p == 2) {
		if (!focused) return; //we want to turn focus off, but it is already off
		selectedCell.className='bhv selected';
		focused = false;
	}
	else {
		if (focused) return; //we want to turn focus on, but it is already on
		selectedCell.className='bhv focus';
		focused = true;
	}
}

function saveCart() {
	var riLoad = frames[1].frames[3].x[0];
	if (riLoad == 'x') draw(false);
	else {
		// add loading row
		init();
		var indent = (riLoad == '' ? 1 : $_getIndentById(riLoad))
		var loadingRow = $_createLoadingRow(indent);
		if (riLoad == '') leftDoc.getElementById('kt').appendChild(loadingRow);
		else leftDoc.getElementById('kt').insertBefore(loadingRow, leftDoc.getElementById(riLoad));	
		draw(true);		
	}
	alert("Show has been saved to your 'Saved Shows' folder in your Personal Library.");
}


function tog(rowID){
	init();
	var folder = leftDoc.getElementById(rowID);
	if (folder == null) return;
	if (folder.getAttribute('e') == '1') $_collapseFolder(rowID);
	else {
		// we need to expand the folder; do we have its children in the browser?
		if (folder.getAttribute('c').length < 2) {
			// we need to load children from the database
			var loadingRow = $_createLoadingRow($_getIndentById(rowID));
			var targetId = $_getRowBelow(rowID);
			if (targetId == '') leftDoc.getElementById('kt').appendChild(loadingRow);
			else leftDoc.getElementById('kt').insertBefore(loadingRow, leftDoc.getElementById(targetId));
			frames[1].frames[3].location = base + "left/hid.aspx?" + qs3('06') + "&ri=" + rowID;
		}
		else $_expandFolder(rowID);
	}
}


function draw(deleteLoading) {
	// params: 0 = title; 1 = id, 2 = e, 3 = s, 4 = c, 5 = y, 6 = o, 7 = h, 8  = l (link)
	init();
	var newRows = frames[1].frames[3].a;
	var existingRows = frames[1].frames[3].p;
	var removingRows = frames[1].frames[3].r;
	// first get the maximum indent of the new rows
	var maxIndentNewRows = 0; var thisIndent = 0;
	for (var k = 0; k<newRows.length; k++) {
		thisIndent = $_getIndentById(newRows[k][1]);
		if (thisIndent > maxIndentNewRows) maxIndentNewRows = thisIndent;
	}
	//what is the current max indent of the tree before we add these new rows?
	var maxIndentBefore = parseInt(leftDoc.getElementById('fr').getAttribute('c'), 10) - 3;
	var incrementalIndent = maxIndentNewRows - maxIndentBefore;
	if (incrementalIndent > 0) $_increaseMaxIndent(incrementalIndent);
	var maxIndentAfter = (incrementalIndent < 1 ? maxIndentBefore : maxIndentBefore + incrementalIndent);
	//add the newRows backwards; first the bottom row
	var daddy = leftDoc.getElementById('kt'); var bottomRow;
	var rowBelow = leftDoc.getElementById('ld'); var firstChild;
	for(var i = (newRows.length - 1); i >= 0; i--) {
		bottomRow = $_newRow(newRows[i], maxIndentAfter);
		daddy.insertBefore(bottomRow, rowBelow);
		rowBelow = bottomRow;
	}
	// now adjust the existingRows
	for(var j = 0; j<existingRows.length; j++) $_existingRow(existingRows[j]);
	//delete any rows to be removed
	for(var l = 0; l<removingRows.length; l++) $_deleteRow(removingRows[l]);
	//finally get rid of loading folder
	if (deleteLoading) $_deleteRow('ld');
}

function $_existingRow(existingRow){
	var folder = leftDoc.getElementById(existingRow[1]);
	folder.setAttribute('e', existingRow[2]);
	folder.setAttribute('s', existingRow[3]);
	folder.setAttribute('c', existingRow[4]);
	folder.setAttribute('y', existingRow[5]);
	folder.setAttribute('o', existingRow[6]);
	var owned = parseInt(existingRow[6], 10);
	folder.setAttribute('h', existingRow[7]);
	var ch = leftDoc.getElementById(existingRow[1]+'n');
	if (ch != null) ch.disabled = (owned==0);
	folder.setAttribute('l', existingRow[8]);
	// adjust the folder icon
	var img = leftDoc.getElementById(existingRow[1] + "q");
	if (img != null) img.src="../cg/" + $_folderIcon(existingRow);
	// the cell title
	var title = leftDoc.getElementById(existingRow[1]+'s');
	var cellTitle = leftDoc.getElementById(existingRow[1] + 'r');
	if (title != null) title.innerHTML = existingRow[0];	
	else {
		var pType = parseInt(existingRow[5],16);
		var iInner = "<a href='#' onclick=\"top.frames[0].runLeft('98','";
		iInner += existingRow[1] + "');return(false);\" id='" + existingRow[1] + "s'>" + existingRow[0] + "</a>";
		cellTitle.innerHTML = iInner;
	}
	if (selRowId == existingRow[1]) {
		if (focused) cellTitle.className='bhv focus'; else cellTitle.className='bhv selected';
	}
	else cellTitle.className = 'bhv';

}

function ftc(rowID){
	// proper folder title has been clicked
	init();
	if (!sel(rowID)) return; // select the current row
	tog(rowID);   //toggle it
	runRight('14', '64');
}

function rtc() {
	// Main Library folder title has been clicked
	init();
	if (!sel('j')) return; // select the current row
	runRight('14', '64');
}

function wdoc(rowID, topParam) {
	//webDoc has been clicked
	init();
	if (!sel(rowID)) return; // select the current row	
	runRight('14',topParam, rowID);
}

function dlti(rowID) {
	init();
	if (!sel(rowID)) return; // select the current row	
	runRight('14','a7', rowID);
}


function pwdAsk(rowID) {
	//webDoc has been clicked
	init();
	if (!sel(rowID)) return; // select the current row	
	runRight('3a', rowID);
}

function remFldr(rowId) {
	//we are to remove this folder
	//instead of the loading row, we replace this folder's name by 'removing...'
	init();
	var titleCell = leftDoc.getElementById(rowId + 'r');
	if (titleCell == null) return;
	titleCell.innerHTML = "removing....";
	titleCell.className = 'loading';
	// now call hid
	frames[1].frames[3].location = base + "left/hid.aspx?" + qs3('7e') + "&ri=" + rowId;
}

function addFldr(rowID, name){
	// adding a folder with rowID checked, ie adding folder as last sibling
	init();
	var row = leftDoc.getElementById(rowID);
	if (row == null) return;
	//do they own the folder?
	var owned = $_folderOwned(rowID);
	if ((owned == '0')||(owned=='2')) {alert('You do not own the folder you have checked, so you cannot add a new folder into it');return;}
	// is this folder expanded ?
	var pTypeN = parseInt(row.getAttribute('y'), 16);
    if (((pTypeN < 131) || (pTypeN > 150)) && (row.getAttribute('e')=='0')) {
		//this is a proper folder that needs to be expanded first	
		if (row.getAttribute('c').length > 1) $_expandFolder(rowID);  // its children are already here in the DOM
	}
	//put in the loading row
	var loadingRow = $_createLoadingRow($_getIndentById(rowID));
	var targetId = $_getRowBelowLastDescendent(rowID);
	if (targetId == '') leftDoc.getElementById('kt').appendChild(loadingRow);
	else leftDoc.getElementById('kt').insertBefore(loadingRow, leftDoc.getElementById(targetId));
	frames[1].frames[3].location = base + "left/hid.aspx?" + qs3('52') + "&ri=" + rowID + "&nm=" + name;		
}

function renFldr(rowId, name){
	init();
	var titleCell = leftDoc.getElementById(rowId + 'r');
	if (titleCell == null) return;
	titleCell.innerHTML = "renaming....";
	titleCell.className = 'loading';
	// now call hid
	frames[1].frames[3].location = base + "left/hid.aspx?" + qs3('7f') + "&ri=" + rowId + "&nm=" + name;			
}

function addLinkOrFlash(rowId, qr, _event){
	//_event = '90' is link, _event = '109' is Flash, '10a' is Knowledge item
	init();
	var row = leftDoc.getElementById(rowId);
	if (row == null) return;
	var pTypeN = parseInt(row.getAttribute('y'), 16);
    if (((pTypeN < 131) || (pTypeN > 150)) && (row.getAttribute('e')=='0')) {
		//this is a proper folder that needs to be expanded first	
		if (row.getAttribute('c').length > 1) $_expandFolder(rowId);  // its children are already here in the DOM
	}		
	//put in the loading row
	var loadingRow = $_createLoadingRow($_getIndentById(rowId));
	var targetId = $_getRowBelowLastDescendent(rowId);
	if (targetId == '') leftDoc.getElementById('kt').appendChild(loadingRow);
	else leftDoc.getElementById('kt').insertBefore(loadingRow, leftDoc.getElementById(targetId));	
	// now call hid
	frames[1].frames[3].location = base + "left/hid.aspx?" + qs3(_event) + "&ri=" + rowId + qr;			
}

function addItems(rowId, qr){
	// user has dropped some items from the selected webDoc onto rowId
	init();
	var row = leftDoc.getElementById(rowId);
	if (row == null) return;
	var pTypeN = parseInt(row.getAttribute('y'), 16);
	if (((pTypeN < 131) || (pTypeN > 150)) && (row.getAttribute('e')=='0')) {
		//this is a proper folder that needs to be expanded first	
		if (row.getAttribute('c').length > 1) $_expandFolder(rowId);  // its children are already here in the DOM
	}			
	frames[1].frames[3].location = base + "left/hid.aspx?" + qs3('3e') + qr;
}

function draggedFolder(re, tt, dt){
	init();
	var row = leftDoc.getElementById(tt);
	if (row == null) return;
	var pTypeN = parseInt(row.getAttribute('y'), 16);
	if (((pTypeN < 131) || (pTypeN > 150)) && (row.getAttribute('e')=='0')) {
		//this target folder is a proper folder that needs to be expanded first	
		if (row.getAttribute('c').length > 1) $_expandFolder(tt);  // its children are already here in the DOM
	}			
	frames[1].frames[3].location = base + "left/hid.aspx?" + qs3('3b') + "&re="+re+"&tt="+tt+"&dt="+dt;
}

function droppedFolder(){
	var riLoad = frames[1].frames[3].x[0];
	var loadingRow = $_createLoadingRow(parseInt(frames[1].frames[3].x[1], 10));
	if (riLoad == '') leftDoc.getElementById('kt').appendChild(loadingRow);
	else leftDoc.getElementById('kt').insertBefore(loadingRow, leftDoc.getElementById(riLoad));
	draw(true);
}


function addPPT(rowId, tempFolderId){
	init();
	if (rowId != "x") {
		// user has checked a folder to add PPT slides into
		var row = leftDoc.getElementById(rowId);
		if (row == null) return;
		var pTypeN = parseInt(row.getAttribute('y'), 16);
		if (((pTypeN < 131) || (pTypeN > 150)) && (row.getAttribute('e')=='0')) {
			//this is a proper folder that needs to be expanded first	
			if (row.getAttribute('c').length > 1) $_expandFolder(rowId);  // its children are already here in the DOM
		}	
		//put in the loading row
		var loadingRow = $_createLoadingRow($_getIndentById(rowId));
		var targetId = $_getRowBelowLastDescendent(rowId);
		if (targetId == '') leftDoc.getElementById('kt').appendChild(loadingRow);
		else leftDoc.getElementById('kt').insertBefore(loadingRow, leftDoc.getElementById(targetId));			
		frames[1].frames[3].location = base + "left/hid.aspx?" + qs3('94') + "&ri=" + rowId + "&fi="+tempFolderId;
	}	
	else {
		// we create folder for the ppt slides = a webDoc at indent 1 at the bottom of the Personal Library
		//put in the loading row
		var loadingRow = $_createLoadingRow(1);
		leftDoc.getElementById('kt').insertBefore(loadingRow, leftDoc.getElementById('j'));	
		// now call hid
		frames[1].frames[3].location = base + "left/hid.aspx?" + qs3('93') + "&fi="+tempFolderId;		
	}
}

function unLinkFirst(rowId) {
	init();
	var row = leftDoc.getElementById(rowId);
	if (row == null) return;
	var pTypeN = parseInt(row.getAttribute('y'), 16);
    if (((pTypeN < 131) || (pTypeN > 150)) && (row.getAttribute('e')=='1'))
		//this is a proper folder that needs to be collapsed first	
		$_collapseFolder(rowId); 
	frames[1].frames[3].location = base + "left/hid.aspx?" + qs3('100') + "&ri=" + rowId;
}

function unLinkDone(rowId) {
	init();
	var row = leftDoc.getElementById(rowId);
	if (row == null) return;	
	var ch;
	row.setAttribute('o', '3');
	row.setAttribute('l', '0');
	var pType = parseInt(row.getAttribute('y', 16));
	if ((pType > 130) && (pType < 151)) row.setAttribute('y', '83');
	else row.setAttribute('y', '64');
	ch = leftDoc.getElementById(rowId + 'n');
	if (ch != null) {ch.checked = false; ch.disabled = false;}
	var img = leftDoc.getElementById(rowId + "q");
	if (img != null) {
		if ((pType > 130) && (pType < 151))
			img.src="../cg/doc.gif";
		else {
			 if (row.getAttribute('e')=='1') img.src="../cg/fo.gif"; else img.src="../cg/fc.gif";
		}
	}

	// now the descendents
	var daddy = leftDoc.getElementById('kt');
	var rows = daddy.childNodes;
	var pattern = rowId + 'l';
	var lenPattern = pattern.length; var thisRowId = ''; 
	for (var i = 0; i < rows.length; i++) {
		if (rows[i].attributes != null) {
			thisRowId = rows[i].getAttribute('id');
			if ((thisRowId != null) && (thisRowId.length > lenPattern)) {
				if (thisRowId.substr(0, lenPattern) == pattern) {
					rows[i].setAttribute('o', '3');
					rows[i].setAttribute('l', '0');
					// and set the checkbox to ungreyed
					ch = leftDoc.getElementById(thisRowId + 'n');
					if (ch != null) {ch.checked = false; ch.disabled = false;}
				}
			}
		}
	}	
	runTop('7a');


}

function impFldr(lnk, key, rowId){
	init();
	var row = leftDoc.getElementById(rowId);
	if (row == null) return;
	var pTypeN = parseInt(row.getAttribute('y'), 16);
    if (((pTypeN < 131) || (pTypeN > 150)) && (row.getAttribute('e')=='0')) {
		//this is a proper folder that needs to be expanded first	
		if (row.getAttribute('c').length > 1) $_expandFolder(rowId);  // its children are already here in the DOM
	}		
	//put in the loading row
	var loadingRow = $_createLoadingRow($_getIndentById(rowId));
	var targetId = $_getRowBelowLastDescendent(rowId);
	if (targetId == '') leftDoc.getElementById('kt').appendChild(loadingRow);
	else leftDoc.getElementById('kt').insertBefore(loadingRow, leftDoc.getElementById(targetId));	
	// now call hid
	frames[1].frames[3].location = base + "left/hid.aspx?" + qs3('70') + "&ri=" + rowId + "&bl="+lnk+"&nm="+key;			
}

function addModule(checkedFolders) {
	if (ct.length != 3) {alert("Error locator # csc 234d9"); return;}
	var containerFolder='';
	switch (checkedFolders.length) {
		case 1:
			//this is OK provided it is not the module folder ct[0]
			if (checkedFolders[0].substr(0, checkedFolders[0].length-1) == ct[0]) {
				alert("You need to check the folder into which you want your new module to be placed; this cannot be the folder that is the module itself.");
				return;
			}
			containerFolder = checkedFolders[0].substr(0, checkedFolders[0].length-1);	
			break;
			
		case 2:
			// this is OK provided one of them is the module, then the other must be the container
			if (checkedFolders[0].substr(0, checkedFolders[0].length-1) == ct[0]) containerFolder = checkedFolders[1].substr(0, checkedFolders[1].length-1);	
			else {if (checkedFolders[1].substr(0, checkedFolders[1].length-1) == ct[0]) containerFolder = checkedFolders[0].substr(0, checkedFolders[0].length-1);}
			if (containerFolder == '') {
				alert("You need to check the the one folder into which you want to place your new module; you currently have two checked");
				return;
			}
			break;
			
		default:
			alert("You need to check the the one folder into which you want to place your new module; you currently have more than one checked");
			return;			
	}
	init();
	var row = leftDoc.getElementById(containerFolder);
	if (row == null) return;
	var pTypeN = parseInt(row.getAttribute('y'), 16);
	if (pTypeN == 135) {alert("The folder that you have checked to put your new module into is itself a module; you need to choose another folder"); return;}
    if (((pTypeN < 131) || (pTypeN > 150)) && (row.getAttribute('e')=='0')) {
		//this is a proper folder that needs to be expanded first	
		if (row.getAttribute('c').length > 1) $_expandFolder(containerFolder);  // its children are already here in the DOM
	}		
	//put in the loading row
	var loadingRow = $_createLoadingRow($_getIndentById(containerFolder));
	var targetId = $_getRowBelowLastDescendent(containerFolder);
	if (targetId == '') leftDoc.getElementById('kt').appendChild(loadingRow);
	else leftDoc.getElementById('kt').insertBefore(loadingRow, leftDoc.getElementById(targetId));	
	// now call hid
	frames[1].frames[3].location = base + "left/hid.aspx?" + qs3('91') + "&cm=" + ct[0] + "&ri="+containerFolder+"&em="+ct[1]+"&dx="+ct[2];			
}

function selOwned(){
	if (selRowTr == null) return(-1);
	else return($_folderOwned(selRowId));
}

function $_folderOwned(rowId) {
	var row = leftDoc.getElementById(rowId);
	var owned = 0;
	if (row != null) owned = parseInt(row.getAttribute('o'), 10);
	//but what is the linkage?
	switch (parseInt(row.getAttribute('l'), 10)){
		case 3: return(0);
		case 2: if ((owned == 3)||(owned==2)) return(2); else return(0);
		default: return(owned);
	}
}

function chOwned(chId) {
	//What is the ownership of the folder represented by this checkbox
	init();
	var rowId = chId.substr(0, chId.length-1);
	return($_folderOwned(rowId));
}

function isWebDoc(rowId){
	init();
	var folder = leftDoc.getElementById(rowId);
	if (folder == null) {
		alert("Error locator # csc 43292");
		return(false);
	}
	var pType = parseInt(folder.getAttribute('y'), 16);
	return((pType > 130) && (pType < 151));
}

function isUnlockedWd(rowId){
	init();
	var folder = leftDoc.getElementById(rowId);
	if (folder == null) {
		alert("Error locator # csc 43292");
		return(false);
	}
	var pType = parseInt(folder.getAttribute('y'), 16);
	return(((pType > 130) && (pType < 151)) && (!((pType == 132) || (pType == 142) || (pType == 136))));
}

function isLockedWd(rowId){
	init();
	var folder = leftDoc.getElementById(rowId);
	if (folder == null) {
		alert("Error locator # csc 43292");
		return(false);
	}
	var pType = parseInt(folder.getAttribute('y'), 16);
	return((pType == 132) || (pType == 142) || (pType == 136));
}

function $_deSelectAll() {
	if (selRowId == '') return;
	var selectedCell = leftDoc.getElementById(selRowId + 'r');
	if (selectedCell != null) {selectedCell.className='bhv'; selRowId = ''; selRowTr = null;}
}

function sel(rowID){
	init();
	if (rowID == '') return(false);
	$_deSelectAll();	
	var selectedCell = leftDoc.getElementById(rowID + 'r');
	if (selectedCell != null) {
		selectedCell.className='bhv selected'; 
		selRowId = rowID; 
		focused=false; 
		selRowTr = leftDoc.getElementById(rowID);
		return(true);
	}
	else return(false);
}

function $_collapseFolder(rowID) {
	init();
	var folder = leftDoc.getElementById(rowID);
	if (folder == null) return;
	var childID = folder.getAttribute('c');
	var child; var chb;
	while(1==1) {
		if (childID == '') break;
		child = leftDoc.getElementById(childID);
		if (child == null) break;
		child.style.display = 'none';
		chb = leftDoc.getElementById(childID + 'n');
		if (chb != null) chb.checked = false;
		$_collapseFolder(childID);		
		childID = child.getAttribute('s');	
	}
	folder.setAttribute('e', '0');	
	var pType = parseInt(folder.getAttribute('y'),16);
	var img = leftDoc.getElementById(rowID + "q");
	if ((pType > 99) && (pType < 131)) {if (img != null) img.src=((pType==113)?'../cg/a_c.gif':'../cg/fc.gif');}	
	else {if (pType == 254) {if (img != null) img.src = '../cg/a_top_c.gif';}}
}

function $_expandFolder(rowID) {
	var folder = leftDoc.getElementById(rowID);
	var childID = folder.getAttribute('c');
	if (childID == 'l') return;
	var child;
	while(1==1) {
		if (childID == '') break;
		child = leftDoc.getElementById(childID);
		if (child == null) break;
		child.style.display = '';
		childID = child.getAttribute('s');
	}
	folder.setAttribute('e', '1');	
	var pType = parseInt(folder.getAttribute('y'),16);
	var img = leftDoc.getElementById(rowID + "q");
	if ((pType > 99) && (pType < 131)) {if (img != null) img.src=((pType==113)?'../cg/a_o.gif':'../cg/fo.gif');	}
	else {if (pType == 254) {if (img != null) img.src = '../cg/a_top_o.gif';}}
}

function $_treeOwner(){
	// if no arguments, use selected; else use sent rowID
	var firstLetter;
	if (arguments.length == 0) firstLetter = selRowId.substr(0,1); else firstLetter = arguments[0].substr(0,1);
	return(leftDoc.getElementById(firstLetter).getAttribute('to'));
}

function $_increaseMaxIndent(incIndent){
	//we need to increase the whole tree's max indent
	//first the formatting row
	var frRow = leftDoc.getElementById('fr');
	var colsBefore = frRow.getAttribute('c');
	var frTitleRow = leftDoc.getElementById('fr'+colsBefore);
	var brCell;
	for (var i = 0; i < incIndent; i++) {
		brCell = leftDoc.createElement('TD');
		brCell.innerHTML = "<img='..\cg\s.gif' width='" + tdw + "' height='1px'>";
		brCell.setAttribute('width', tdw);
		brCell.setAttribute('height', '1px');
		frRow.insertBefore(brCell, frTitleRow);	
	}
	var colsAfter = parseInt(colsBefore, 10) + incIndent + '';
	frTitleRow.setAttribute('id', 'fr' + colsAfter);
	frRow.setAttribute('c', colsAfter);
	// now the contents row
	var titleCell;
	titleCell = leftDoc.getElementById('ctd');
	titleCell.colSpan = titleCell.colSpan + incIndent;
	//now the rest of the tree
	var daddy = leftDoc.getElementById('kt');
	var rows = daddy.childNodes; 
	var rowID;
	for (var i = 0; i < rows.length; i++) {
		if ((rows[i].attributes != null) && (rows[i].getAttribute('id')!=null)) {
			rowID = rows[i].getAttribute('id');
			if ((rowID != 'fr') && (rowID != 'ct')) {
				titleCell = leftDoc.getElementById(rows[i].getAttribute('id') + 'r');
				if (titleCell != null) titleCell.colSpan = titleCell.colSpan + incIndent;
			}
		}
	}	
}

function $_folderIcon(a){
	//a[] is our usual array: 0 = title; 1 = id, 2 = e, 3 = s, 4 = c, 5 = y, 6 = o, 7 = h, 8 = l (link)

	var pType = parseInt(a[5],16);	
	if ((pType > 130) && (pType < 161)) {
		//webDoc
		switch (pType) {
			case 135: return("mdf.gif");
			case 136: return("docL_d.gif");
			case 132: case 142: return("docL.gif");
			default:
				switch (a[8]) {
					case '1': return("doc_s.gif"); break;
					case '2': return("doc_d.gif"); break;
					default: return("doc.gif"); break;
				}		
				break;	
		}		
	} 
	else {
		// folders
		switch (pType) {
			case 254: return((a[2]=='1')?"a_top_o.gif":"a_top_c.gif");
			case 113: return((a[2]=='1')?"a_o.gif":"a_c.gif");
			case 249: case 253: return("lib.gif");
			default:
				switch (a[8]) {
					case '1': return("fo_s.gif");
					case '2': return("fo_d.gif");
					default: if (a[2]=='1') return("fo.gif"); else return("fc.gif");
				}
		}
	}	
}

function $_newRow(params, maxIndent){

	// params: 0 = title; 1 = id, 2 = e, 3 = s, 4 = c, 5 = y, 6 = o, 7 = h, 8 = l (link)
	var a = new Array('','','0','','','0','0', '0', '0');  //the defaults for these values
	for (var i = 0; i < params.length; i++) a[i] = params[i];
	
	//new row as <tr..> with its attributes
	var newTR = leftDoc.createElement("TR");
	newTR.setAttribute('id', a[1]);
	newTR.setAttribute('e', a[2]);
	newTR.setAttribute('s', a[3]);
	newTR.setAttribute('c', a[4]);
	newTR.setAttribute('y', a[5]);
	newTR.setAttribute('o', a[6]);
	var owned = parseInt(a[6], 10);
	newTR.setAttribute('h', a[7]);
	newTR.setAttribute('l', a[8]);
	
	//now indent
	var brCell;
	var indent = $_getIndentById(a[1]);
	for (var i = 0; i < indent; i++){
		brCell = leftDoc.createElement('TD');
		brCell.innerHTML = '<br>';
		brCell.setAttribute('width', tdw);
		newTR.appendChild(brCell);
	}
	
	// checkbox
	var pType = parseInt(a[5], 16);
	var chCell = leftDoc.createElement('TD');
	if ((parseInt(sCategory, 10) > 2)&&(!((pType==113)||(pType==137)||(pType==254)))) {
		chCell.setAttribute('width', tdw);
		chCell.setAttribute('align', 'right');
		chCell.setAttribute('id', a[1] + 'm');
		var chInner = "<input type=checkbox id='" + a[1] + "n'";
		if (owned == 0) chInner += " disabled>"; else chInner += " name='ch'>";
		chCell.innerHTML = chInner;
	} else {
		chCell.setAttribute('width', '1px');
		chCell.setAttribute('align', 'right');
		chCell.innerHTML = "<img border='0' src='../cg/spacer.gif' width='1' height='20'>";
	}
	newTR.appendChild(chCell);
	
	// icon column
	
	var iCell = leftDoc.createElement('TD');
	iCell.setAttribute('width', tdw);
	iCell.setAttribute('id', a[1] + 'o');
	var iInner = "<a href='#' onclick=\"top.frames[0].runLeft('";
	if ((pType > 130) && (pType < 161)) {
	// web doc
		iInner += "97','" + a[1] + "');return(false);\" id='" + a[1] + "p'><img src='../cg/";
		switch (pType) {
			case 135: iInner += "mdf.gif' "; break;
			case 136: iInner += "docL_d.gif' "; break;
			case 132: case 142: iInner += "docL.gif' "; break;
			default:
				switch (a[8]) {
					case '1': iInner += "doc_s.gif' "; break;
					case '2': iInner += "doc_d.gif' "; break;
					default: iInner += "doc.gif' "; break;
				}		
				break;	
		}
		iInner += "alt='Web page of items - click to view' border='0' width='15' height='13' align='bottom' id='" + a[1] + "q'></a>";
	} 
	else {
		// folders
		iInner += "97','" + a[1] + "');return(false);\" id='" + a[1] + "p'>";
		if ((pType == 254) || (pType == 113)) {
			iInner += "<img src='../cg/";
			if (a[2]=='1') {iInner += ((pType==254)?"a_top_o":"a_o"); iInner += ".gif' alt='Close archive folder' border='0' width='15' height='13' align='bottom' id='" + a[1] + "q'></a>";}
			else {iInner += ((pType==254)?"a_top_c":"a_c"); iInner += ".gif' alt='Open archive folder' border='0' width='15' height='13' align='bottom' id='" + a[1] + "q'></a>";}
		}
		else {
			if (pType > 239) iInner += "<img src='../cg/lib.gif' alt='Toggle Library' border='0' width='16' height='16' align='bottom' id='" + a[1] + "q'></a>";
			else { switch (a[8]) {
				case '1': iInner += "<img src='../cg/fo_s.gif' "; break;
				case '2': iInner += "<img src='../cg/fo_d.gif' "; break;
				default: if (a[2]=='1') iInner += "<img src='../cg/fo.gif' "; else iInner += "<img src='../cg/fc.gif' "; break;
				}
				iInner += "alt='Toggle Folder' border='0' width='15' height='13' align='bottom' id='" + a[1] + "q'></a>";
			}
		}
	}
	iCell.innerHTML = iInner;
	iCell.className = "bhv";
	newTR.appendChild(iCell);
	
	//now title cell
	var titleCell = leftDoc.createElement('TD');
	titleCell.colSpan = maxIndent - indent + 1;
	titleCell.setAttribute('id', a[1]+'r');
	iInner = "<a href='#' onclick=\"top.frames[0].runLeft('98','";
	iInner += a[1] + "');return(false);\" id='" + a[1] + "s'>" + a[0] + "</a>";
	titleCell.className = "bhv";
	titleCell.innerHTML = iInner;
	newTR.appendChild(titleCell);	

	return(newTR);

}

function $_getIndentById(rowID) {
	//we return the number of l's in rowID
	var pos=0; 
	var num=0;
	while(1==1) {
		pos = rowID.indexOf('l', ++pos);
		if (pos == -1) return(num);
		num++;
	}
}

function $_getRowBelow(rowID) {
	//what is the rowID of the row immediately below this one, or zls if we are the last row in the tree
	var row = leftDoc.getElementById(rowID);
	if (row == null) return('');
	//Does it have any children ?  If so, the row below will be the first child
	var firstChildId = row.getAttribute('c');
	if ((firstChildId != 'n')&&(firstChildId !='l')) return(firstChildId);
	// no children, so the row below will be the next sibling
	var nextSiblingId = row.getAttribute('s');
	if (nextSiblingId != '') return(nextSiblingId);
	//If we are here,there is no next sibling, so let's run through the whole tree
	var daddy = leftDoc.getElementById('kt');
	var rows = daddy.childNodes; var sentRowIndex = -1;
	for (var i = 0; i < rows.length; i++) {
		if ((rows[i].attributes != null) && (rows[i].getAttribute('id')==rowID)) {
			sentRowIndex = i; 
			break;
		}
	}	
	if (sentRowIndex == -1) return(''); //sent row is the last in the tree
	for (i = (sentRowIndex + 1); i < rows.length; i++) {
		if ((rows[i].attributes != null) && (rows[i].getAttribute('id') != null)) return(rows[i].getAttribute('id'));
	}
	return('');
}

function reOwner(rowId) {
	// user is no longer owner of this folder, nor any of its children
	init();
	var row = leftDoc.getElementById(rowId);
	if (row == null) return;	
	var owner = parseInt(row.getAttribute('o'), 10);
	var ch;
	if (owner == 3) row.setAttribute('o', '2');
	else {
		row.setAttribute('o', '0');
		ch = leftDoc.getElementById(rowId + 'n');
		if (ch != null) {ch.checked = false; ch.disabled = true;}
	}
	// now the descendents
	var daddy = leftDoc.getElementById('kt');
	var rows = daddy.childNodes;
	var pattern = rowId + 'l';
	var lenPattern = pattern.length; var thisRowId = ''; 
	for (var i = 0; i < rows.length; i++) {
		if (rows[i].attributes != null) {
			thisRowId = rows[i].getAttribute('id');
			if ((thisRowId != null) && (thisRowId.length > lenPattern)) {
				if (thisRowId.substr(0, lenPattern) == pattern) {
					rows[i].setAttribute('o', '0');
					// and set the checkbox to greyed
					ch = leftDoc.getElementById(thisRowId + 'n');
					if (ch != null) {ch.checked = false; ch.disabled = true;}
				}
			}
		}
	}	
	runTop('7a');

}

function getSavedCartsFolderEState(){
	init();
	var daddy = leftDoc.getElementById('kt');
	var rows = daddy.childNodes;
	for (var i = 0; i < rows.length; i++) {
		if ((rows[i].attributes != null) && (rows[i].getAttribute('y')=='6f')) return(rows[i].getAttribute('e'));
	}	
	return('-1');
}

function $_createLoadingRow(indent){
	//if there is a current loading row, delete it
	$_deleteRow('ld');
	var loadingRow = leftDoc.createElement("TR");
	loadingRow.setAttribute('id', 'ld');
	//now indent
	var brCell;
	for (var i = -1; i <= indent; i++){
		brCell = leftDoc.createElement('TD');
		brCell.innerHTML = '<br>';
		brCell.setAttribute('width', '16px');
		loadingRow.appendChild(brCell);
	}
	//now title cell
	var titleCell = leftDoc.createElement('TD');
	titleCell.colSpan = parseInt(leftDoc.getElementById('fr').getAttribute('c'), 10) - indent - 2;
	titleCell.className = 'loading';
	titleCell.innerHTML = "Loading...";
	loadingRow.appendChild(titleCell);	

	return(loadingRow);
}

function $_deleteRow(rowId){
	var row = leftDoc.getElementById(rowId);
	if (row != null) leftDoc.getElementById('kt').removeChild(row);
}

function $_getParentIdFromChild(childID) {
	var posLastL = childID.lastIndexOf('l');
	if (posLastL == -1) return(null);
	return(childID.substr(0, posLastL));
}

function $_getPreviousSiblingID(){
	//params: EITHER siblingID of the row whose previous sibling we want; OR siblingID, parentID of siblingID
	//returns rowID of previous sibling, or empty string if siblingID is the first sibling
	var siblingID = arguments[0];
	var parentID;
	if (arguments.length > 1) parentID = arguments[1];
	else parentID = getParentIdFromChild(siblingID);
	
	var childID = leftDoc.getElementById(parentID).getAttribute('c');
	if (childID == siblingID) return(''); //sent siblingID is the first child, so there is no previous sibling
	var child;
	while(1==1) {
		child = leftDoc.getElementById(childID);
		childID = child.getAttribute('s');
		if (childID == '') return('');
		if (childID == siblingID) return(child.getAttribute('id'));
	}	
}

function $_getRowBelowLastDescendent(rowId){
	//we want the rowID that is below the last descendent of rowId
	var parentID; var nextSiblingID; var childID;
	init();
	parentID = rowId;
	while (1==1){
		if (parentID == 'i') return('j');
		if (parentID == 'j') return('');			
		//does this parent have a next sibling ?
		nextSiblingID = leftDoc.getElementById(parentID).getAttribute('s');
		if (nextSiblingID != '') return(nextSiblingID);
		childID = parentID; 	
		parentID = $_getParentIdFromChild(childID);
	}
}



