// Ergonet JavaScript Document
// no overlap with conducta/lib.
// var targetDivA5 = $targetDivA5 set in dataSourceA5Editor
var dataSourcePathA5="/lib/aria5/app/dataSource.php"; // declared in connect
var conducta = false;
var lookupDomain=document.domain;
var xmlhttp=false;
var pathForTheRecord='';
var xhr=true;
var autoXhrMode=true;
var locationTimeoutId=null;
var lastHash='';
var permDivs = Array('menuPermanent','menuTop','notesDiv','debugDiv','errorNote','indexContainer','bubbleBar','ergonetMenu','bubbleManager','loggedInMessage','logoutLinkContainer','onPageMediaPlayer');
var excludeFromDepth = Array('menuPermanent','menuTop','notesDiv','debugDiv','errorNote','indexContainer','bubbleBar','loggedInMessage','logoutLinkContainer','onPageMediaPlayer');
var browser;
var browserVersion;
var operatingSystem;
var xmlhttp;
var oldBrowserMode=false;
var IE6=false;
var operatingSystem='', browser='', browserVersion='', IE=false, ns=false, win=false, mac=false;
function set_def_q() {
if (document.getElementById("def_td") != null) {
document.getElementById("def_td").bgColor = "#FF0000";
}
}
function previewpagepath() {
var root_path = '<?php echo $rooturl; ?>';
var obj = document.forms.page_form.pageurl;
var pagepath = obj.value;
var pathpreview_content = "<a href='"+root_path+pagepath+"' target='_blank'>"+root_path+pagepath+"</a>";
document.getElementById("pathpreview").innerHTML = pathpreview_content;
}
function addHtmToContent01(Htm) {
	var obj = document.forms.page_form.content01;
	var currentText = obj.value;
	obj.value = currentText+Htm;
	obj.focus();
}
function replaceLineReturns(m) {
	var obj = document.forms.page_form.content01;
	var currentText = obj.value;
	var lines_array = currentText.split('\n');
	if (lines_array.length > 1) {
		var n=0;
		var processedText = '';
		for(var i=0; i<lines_array.length; i++) {
			n= lines_array[i].length;
		//	alert(lines_array[i].substr((n-1),1));
			if (lines_array[i].substr((n-1),1) == ">") {
				processedText += lines_array[i]+"\n";
			} else {
				// if the next member of the array is void then only add </p>
				// if the next member of the array is not null then add <p>
				switch (m) {
				case 'p':
				if (!lines_array[i+1]) {
					processedText += lines_array[i]+"";
				} else {
					processedText += lines_array[i]+"</p>\n\n<p>";
				}
				break;
				case 'li':
				if (!lines_array[i+1]) {
					processedText += lines_array[i]+"</li>\n";
				} else {
					processedText += lines_array[i]+"\n<li>";
				}
				break;
				case 'br':
				if (!lines_array[i+1]) {
					processedText += lines_array[i]+"</br>\n";
				} else {
					processedText += lines_array[i]+"\n<br>";
				}
				break;
				}
			}
		}
	} else {
		processedText = currentText;
	}
//	processedText = currentText.replace(/([\r\n])+/g, "<br>\n");
//	alert(processedText);
	obj.value = processedText;
	obj.focus();
}
function replaceab() {
var a=document.getElementById('replacea').value;
var b=document.getElementById('replaceb').value;
var replacemessage="Replace '"+a+"' with '"+b+"' ?";
if (!b) {
	replacemessage= "Delete instances of: "+a;
}
	temp=window.confirm(replacemessage);
	if(temp == true) {
		var obj = document.forms.page_form.content01;
		var currentText = obj.value;
		//var searchobj = eval('/"'+a+'"/g');
		//a="'"+a+"'";
		var searchobj = new RegExp(a, "g");
		//alert(searchobj);
		processedText = currentText.replace(searchobj, b);
		obj.value = processedText;
	}
}
function ensmSave(varName) {
	//trace('varName: '+varName);
	var str = "";
	var obj=document.getElementById(varName);
	if (obj != null) {
		//trace('obj val: '+obj.value);
		if (obj.type=="checkbox") {
			var val = 'false';
			if (obj.checked) val='true';
			str = "&newVariable="+varName + "&newValue=" +val;
		} else {
			str = "&newVariable="+varName + "&newValue=" + obj.value;
			
		}
		//trace('str: '+str);
		str = dataSourcePathA5 + "?func=saveEns" + str;
//		trace(str);
		sendToServerAria5(str);
	}	
}

function setDefSetMode(sw) {
	// systemDefaultsList
	switch(sw) {
	case "domain":
		str = dataSourcePathA5 + "?func=systemDefaultsList&defSetMode=domain";
		sendToServerAria5(str);
	break;
	case "all":
		str = dataSourcePathA5 + "?func=systemDefaultsList&defSetMode=all";
		sendToServerAria5(str);
	break;
	default:
		var str = "<div id=\"systemDefaultsListWide\"><div class=\"defSetModeLinkDiv\"><a href=\"javascript:setDefSetMode('domain')\">Edit Settings for "+lookupDomain+"</a></div>";
		str += "<div class=\"defSetModeLinkDiv\"><a href=\"javascript:setDefSetMode('all')\">Edit Settings for all domains</a></div></div>";
		var systemDefaultsList = document.getElementById('systemDefaultsList');
		systemDefaultsList.innerHTML = str;
	break;
	}
}

function setValueOfInput(cntrl,val) {
	if (cntrl) {
		var obj = document.getElementById(cntrl);
		if (obj != null) {
			if (obj.type == 'checkbox') {
				if (val=='true') {
					obj.checked=true;
				} else {
					obj.checked=false;
				}
			} else {
				obj.value=val;
			}
		}
	}
	var obj = document.getElementById('ens_'+cntrl);
	if (obj != null) {
		obj.style.color='#FF0000';
	}
}

function aria5menu() {
	var str = "func=aria5menu"
	str = dataSourcePathA5 + "?" + str;
	sendToServerAria5(str);
}


var hiders = new Array('bubManContent','bubManMid','bubManTop','bubManCloseLink','bubManScrollDown');
function bubbleManager(bool) {
	var bubMan = document.getElementById('bubbleManager');
	
	var bubManBot = document.getElementById('bubManBot');
	var bubManCont = document.getElementById('bubManContent');
	var obj = null;
	if (bubMan != null) {
		
		if (bool) {
			
			var str = "func=bubbleManager"
			str = dataSourcePathA5 + "?" + str;
			sendToServerAria5(str);
			
			if (bubMan.style.height != bubManMaxHeight+"%") {
				
				bubManSlide(true);
				bubManBot.style.backgroundImage="url(/lib/aria5/graphics/skin/default/bubManBot.png)";
				bubManBot.style.height="10%";
				
				for (var i=0; i<hiders.length; i++) {
					obj = document.getElementById(hiders[i]);
					if (obj != null) { obj.style.display='block'; }
				}
			
			}
		} else {
		//	bubMan.style.height='40px';
			bubManSlide(false);
			
		}
		
	}
}
function bubManScrollDown() {
	var bubManCont = document.getElementById('bubManContent');
	bubManCont.scrollTop += 100;
}
function bubManScrollUp() {
	var bubManCont = document.getElementById('bubManContent');
	bubManCont.scrollTop -= 100;
}

var bubManSlidePeriod=null;
var bubManSlideCount=1;
var bubManSlideMax=11;
var bubManHeight=0;
var bubManMaxHeight=90;
var bubManMinHeight=5;
var bubManObj = null;

function bubManSlide(bool) {
	bubManObj = document.getElementById('bubbleManager');
	bubManSlideCount=1;
	if (bubManObj != null) {
		if (bool) {
			bubManHeight = bubManMinHeight;
		} else {
			bubManHeight = bubManMaxHeight;
		}
		bubManSlidePeriod = window.setInterval(bubManSlideStep,30,bool);
	}
}

function bubManSlideStep(bool) {
	if (bubManSlideCount < bubManSlideMax) {
		var inc = (bubManMaxHeight - bubManMinHeight) / bubManSlideMax;
		if (bool) {
			// opening
			bubManObj.style.height = (inc*bubManSlideCount)+"%";
			bubManObj.style.opacity = (((100 / bubManSlideMax)*bubManSlideCount)/100);
		} else {
			// closing
			bubManObj.style.height = (bubManMaxHeight - (inc*bubManSlideCount))+"%";
			bubManObj.style.opacity = (1- ((100 / bubManSlideMax)*bubManSlideCount)/100);
		}
		bubManSlideCount++;
	} else {
		bubManSlideCount=1;
		window.clearInterval(bubManSlidePeriod);
		if (bool) {
			bubManObj.style.height = bubManMaxHeight+"%";
			bubManObj.style.opacity = 1;
		} else {
			bubManObj.style.height = bubManMinHeight+"%";
			bubManObj.style.opacity = 1;
			var bubManBot = document.getElementById('bubManBot');
			bubManBot.style.backgroundImage="none";
			var bubManCont = document.getElementById('bubManContent');
			
			bubManBot.style.height="40px";
			bubManCont.innerHTML='';
			
			for (var i=0; i<hiders.length; i++) {
				obj = document.getElementById(hiders[i]);
				if (obj != null) { obj.style.display='none'; }
			}
			
		}
	}
}

var shakes=7;
var shakeCounter=1;
var loginDivObj = null;
var shakeInterval = null;

function animateLoginFail() {
	loginDivObj = document.getElementById('loginDiv');
	if (loginDivObj != null) {
		//shakeLoginDiv();
		shakeInterval = window.setInterval(shakeLoginDiv,60);
	}
}

function shakeLoginDiv() {
	if (shakeCounter / 2 != Math.floor(shakeCounter / 2)) {
		loginDivObj.style.left = (loginDivObj.offsetLeft + 5) + 'px';
	} else {
		loginDivObj.style.left = (loginDivObj.offsetLeft - 5) + 'px';	
	}
	
	shakeCounter ++;
	if (shakeCounter > shakes) {
		shakeCounter = 1;
		window.clearInterval(shakeInterval);
	} 
}

function ergonetMenu() {
	var obj=document.getElementById('ergonetMenu');
	var obj1=document.getElementById('ergMenuMid');
	var obj2=document.getElementById('ergMenuBot');
	if (obj != null) {
		obj.style.zIndex=1000;
		if (obj.offsetHeight != 20) {
			obj.style.height = '20px';
			if (obj1 != null) {
				obj1.style.display='none';
			}
			if (obj2 != null) {
				obj2.style.display='none';
			}
		} else {
			obj.style.height = '450px';
			if (obj1 != null) {
				obj1.style.display='block';
			}
			if (obj2 != null) {
				obj2.style.display='block';
			}
		}
	}
}
function logoutLink() {
	var obj = document.getElementById('logoutLinkContainer');
	if (obj != null) {
		obj.innerHTML = "<a href='?logout'>Log Out</a>";	
	}
}
function userNameFocus() {
	var obj = document.getElementById('username');
	if (obj !=null) {
		obj.focus();
	} else {
//		trace('missing username field');	
	}
}
function passwordFocus() {
	var obj = document.getElementById('password');
	if (obj !=null) {
		obj.focus();
	} else {
//		trace('missing password field');	
	}
}

function contactSolo(adrid,p) {
	if (!p) p=0;
	var str = "func=contactSolo&adrid="+ adrid+"&p="+p;
	str = dataSourcePathA5 + "?" + str;
	sendToServerAria5(str);
}

function initSideMenu() {
	var str = "func=initSideMenu"
	str = dataSourcePathA5 + "?" + str;
	sendToServerAria5(str);
}
function setMyCommunity() {
	var str = "func=initCommunity"
	str = dataSourcePathA5 + "?" + str;
	sendToServerAria5(str);
}

//function userManage() { sendFunc('userManage'); }
function userSolo(uid) { sendToServerAria5(dataSourcePathA5 + "?func=userSolo&uid="+ uid);}
function bookingSolo(bkid) { sendToServerAria5(dataSourcePathA5 + "?func=bookingSolo&bkid="+ bkid);}

function bookingEdit() { sendFunc('bookingEdit'); }
function bookingFinancial() { sendFunc('bookingFinancial'); }
function bookingEngagement() { sendFunc('bookingEngagement'); }
function bookingContract() { sendFunc('bookingContract'); }
function bookingContact() { sendFunc('bookingContact'); }
function bookingSales() { sendFunc('bookingSales'); }
function bookingPurchasing() { sendFunc('bookingPurchasing'); }
function bookingFunctions() { sendFunc('bookingFunctions'); }

function diaryDay() { sendFunc('diaryDay'); }
function diaryDayEdit() { sendFunc('diaryDayEdit'); }
function diaryDayEditNext() { sendFunc('diaryDayEditNext'); }
function diaryDayEditPrev() { sendFunc('diaryDayEditPrev'); }
function diaryDayNext() { sendFunc('diaryDayNext'); }
function diaryDayPrevious() { sendFunc('diaryDayPrevious'); }
function diaryDaySave() { sendFunc('diaryDaySave'); }
function diaryMonth() { sendFunc('diaryMonth'); }
function diaryMonthNext() { sendFunc('diaryMonthNext'); }
function diaryMonthPrevious() { sendFunc('diaryMonthPrevious'); }
function diaryYear() { sendFunc('diaryYear'); }
function diaryYearNext() { sendFunc('diaryYearNext'); }
function diaryYearPrev() { sendFunc('diaryYearPrev'); }
function diaryMonthDayEdit() { sendFunc('diaryMonthDayEdit'); }
function diaryMonthDayEditNext() { sendFunc('diaryMonthDayEditNext'); }
function diaryMonthDayEditPrev() { sendFunc('diaryMonthDayEditPrev'); }
function diaryMonthDayEditSave() { sendFunc('diaryMonthDayEditSave'); }
function diaryYearSymbolEdit() { sendFunc('diaryYearSymbolEdit'); }
function diaryYearSymbolEditSave() { sendFunc('diaryYearSymbolEditSave'); }

function artistPreview() { sendFunc('artistPreview'); }
function artistEdit() { sendFunc('artistEdit'); }
function artistDetails() { sendFunc('artistDetails'); }
function artistSkills() { sendFunc('artistSkills'); }
function artistStatus() { sendFunc('artistStatus'); }
function artistMeasurements() { sendFunc('artistMeasurements'); }
function artistAssociations() { sendFunc('artistAssociations'); }
function artistFunctions() { sendFunc('artistFunctions'); }
function artistUploads() { sendFunc('artistUploads'); }

function artistSolo(aid) { sendToServerAria5(dataSourcePathA5 + "?func=artistSolo&aid="+ aid);}

function wbSetPage(str) { 
	//trace(dataSourcePathA5 + "?func=wbSetPage&"+ str);
	sendToServerAria5(dataSourcePathA5 + "?func=wbSetPage&"+ str);
}
function wbPageSolo(str) { 
	sendToServerAria5(dataSourcePathA5 + "?func=wbPageSolo&"+ str);
}

/* tony */
function userCommandGroupSet(appid,cgid,uid) { sendFunc("userCommandGroupSet&appid="+ appid + "&cgid="+ cgid + "&uid="+uid); }
function userCommandDenialSet(comid,uid) { sendFunc("userCommandDenialSet&comid="+ comid + "&uid="+uid); }  
function userPreview() { sendFunc("userPreview"); }
function userNew() { sendFunc("userNew"); }
function userDelete() { sendFunc("userDelete"); }

function userEdit() { sendFunc("userEdit"); }
function userCommandGroups() { sendFunc("userCommandGroups"); }
function userProjectGroups() { sendFunc("userProjectGroups"); }
function userFileSystem() { sendFunc("userFileSystem"); }
function userContact() { sendFunc("userContact"); }
function userDenials() { sendFunc("userDenials"); }
function userFunctions() { sendFunc("userFunctions"); }

function userList() { sendFunc("userList"); } // not needed normally ? init effectively
function userListFirst() { sendFunc("userListFirst"); }
function userListPrevious() { sendFunc("userListPrevious"); }
function userListNext() { sendFunc("userListNext"); }
function userListLast() { sendFunc("userListLast"); }
//function userListSearch() { sendFunc("userListSearch,userListFirst"); } // called using post
function userListFilter() { sendFunc("userListFilter,userListFirst"); }
function userListClearSearch() { sendFunc("userListClearSearch,userListFirst"); }

function projectList() { sendFunc('projectListView'); }
function projectSolo(prjid) { sendFunc("projectSolo&prjid="+ prjid); }
function projectListFirst() { sendFunc('projectListFirst'); }
function projectListPrevious() { sendFunc('projectListPrevious'); }
function projectListNext() { sendFunc('projectListNext'); }
function projectListLast() { sendFunc('projectListLast'); }
function projectListSearch() { sendFunc('projectListSearch'); }
function projectListClearSearch() { sendFunc('projectListClearSearch'); }
function projectListFilter() { sendFunc('projectListFilter'); }

function projectEdit() { sendFunc('projectEdit'); }
function projectGroups() { sendFunc('projectGroups'); }
function projectMembers() { sendFunc('projectMembers'); }
function projectDiary() { sendFunc('projectDiary'); }

function projectNew() { sendFunc('projectNew'); }
function projectDelete() { sendFunc('projectDelete'); }
function projectPictureLookup() { sendFunc('projectPictureLookup'); }
function projectGroupNew() { sendFunc('projectGroupNew'); }
function projectGroupSave() { sendFunc('projectGroupSave'); }
function projectGroupDelete() { sendFunc('projectGroupDelete'); }
function projGrpMemAdd() { sendFunc('projGrpMemAdd'); }
function projGrpMemDelete() { sendFunc('projGrpMemDelete'); }
function projDiaryMonthViewPrevious() { sendFunc('projDiaryMonthViewPrevious'); }
function projDiaryMonthViewNext() { sendFunc('projDiaryMonthViewNext'); }
function projDiaryMonthViewDayEdit() { sendFunc('projDiaryMonthViewDayEdit'); }
function projDiaryMonthViewDayPrevious() { sendFunc('projDiaryMonthViewDayPrevious'); }
function projDiaryMonthViewDayNext() { sendFunc('projDiaryMonthViewDayNext'); }

function todo() { sendFunc('todo'); }
function todoList() { sendFunc('todoList'); }
// and while we're at it lets do a load of list init calls
function courseList() { sendFunc('courseList'); }
function eventList() { sendFunc('eventList'); }
function eventSolo() { sendFunc('eventSolo'); }
function eventList() { sendFunc('bookingList'); }
function forumList() { sendFunc('forumList'); }
function threadList() { sendFunc('threadList'); }
function messageList() { sendFunc('messageList'); }
function shoutList() { sendFunc('shoutList'); }
function contactList() { sendFunc('contactList'); }
function contactHistoryList() { sendFunc('contactHistoryList'); }
function catalogueList() { sendFunc('catalogueList'); }
function productList() { sendFunc('productList'); }
function assetsList() { sendFunc('assetsList'); }
function lookup() { sendFunc('lookup'); }
function paymentGatewayList() { sendFunc('paymentGatewayList'); }
function shopFeedList() { sendFunc('shopFeedList'); }
function jobsList() { sendFunc('jobsList'); }
function orderList() { sendFunc('orderList'); }
function despatchList() { sendFunc('despatchList'); }
function websiteConstantList() { sendFunc('websiteConstantList'); }
function websiteFeedList() { sendFunc('websiteFeedList'); }
function websiteMenuList() { sendFunc('websiteMenuList'); }
function websiteMenuRowList() { sendFunc('websiteMenuRowList'); }
function websitePageList() { sendFunc('websitePageList'); }
function mediaPlayerList() { sendFunc('mediaPlayerList'); }
function playlistList() { sendFunc('playlistList'); }
function trackList() { sendFunc('trackList'); }
function videoList() { sendFunc('videoList'); }
function galleryList() { sendFunc('galleryList'); }
function mediaFeedList() { sendFunc('mediaFeedList'); }
function artistList() { sendFunc('artistList'); }
function actList() { sendFunc('actList'); }
function scheduleList() { sendFunc('scheduleList'); }
function fileList() { sendFunc('fileList'); }
function userList() { sendFunc('userList'); }
function screenLabelList() { sendFunc('screenLabelList'); }
function recordsetList() { sendFunc('recordsetList'); }
function archiveList() { sendFunc('archiveList'); }
function systemDefaultList() { sendFunc('systemDefaultList'); }

// and for each list view it's method handles
function todoListFirst() { sendFunc('todoListFirst'); }
function todoListPrevious() { sendFunc('todoListPrevious'); }
function todoListNext() { sendFunc('todoListNext'); }
function todoListLast() { sendFunc('todoListLast'); }
function todoListSearch() { sendFunc('todoListSearch'); }
function todoListFilter() { sendFunc('todoListFilter'); }
function courseListFirst() { sendFunc('courseListFirst'); }
function courseListPrevious() { sendFunc('courseListPrevious'); }
function courseListNext() { sendFunc('courseListNext'); }
function courceListLast() { sendFunc('courceListLast'); }
function courseListSearch() { sendFunc('courseListSearch'); }
function courseListFilter() { sendFunc('courseListFilter'); }
function eventListFirst() { sendFunc('eventListFirst'); }
function eventListPrevious() { sendFunc('eventListPrevious'); }
function eventListNext() { sendFunc('eventListNext'); }
function eventListLast() { sendFunc('eventListLast'); }
function eventListSearch() { sendFunc('eventListSearch'); }
function eventListFilter() { sendFunc('eventListFilter'); }
function bookingListFirst() { sendFunc('bookingListFirst'); }
function bookingListPrevious() { sendFunc('bookingListPrevious'); }
function bookingListNext() { sendFunc('bookingListNext'); }
function bookingListLast() { sendFunc('bookingListLast'); }
function bookingListSearch() { sendFunc('bookingListSearch'); }
function bookingListFilter() { sendFunc('bookingListFilter'); }
function forumListFirst() { sendFunc('forumListFirst'); }
function forumListPrevious() { sendFunc('forumListPrevious'); }
function forumListNext() { sendFunc('forumListNext'); }
function forumListLast() { sendFunc('forumListLast'); }
function forumListSearch() { sendFunc('forumListSearch'); }
function forumListFilter() { sendFunc('forumListFilter'); }
function threadListFirst() { sendFunc('threadListFirst'); }
function threadListPrevious() { sendFunc('threadListPrevious'); }
function threadListNext() { sendFunc('threadListNext'); }
function threadListLast() { sendFunc('threadListLast'); }
function threadListSearch() { sendFunc('threadListSearch'); }
function threadListFilter() { sendFunc('threadListFilter'); }
function messageListFirst() { sendFunc('messageListFirst'); }
function messageListPrevious() { sendFunc('messageListPrevious'); }
function messageListNext() { sendFunc('messageListNext'); }
function messageListLast() { sendFunc('messageListLast'); }
function messageListSearch() { sendFunc('messageListSearch'); }
function messageListFilter() { sendFunc('messageListFilter'); }
function shoutListFirst() { sendFunc('shoutListFirst'); }
function shoutListPrevious() { sendFunc('shoutListPrevious'); }
function shoutListNext() { sendFunc('shoutListNext'); }
function shoutListLast() { sendFunc('shoutListLast'); }
function shoutListSearch() { sendFunc('shoutListSearch'); }
function shoutListFilter() { sendFunc('shoutListFilter'); }
function contactListFirst() { sendFunc('contactListFirst'); }
function contactListPrevious() { sendFunc('contactListPrevious'); }
function contactListNext() { sendFunc('contactListNext'); }
function contactListLast() { sendFunc('contactListLast'); }
function contactListSearch() { sendFunc('contactListSearch'); }
function contactListFilter() { sendFunc('contactListFilter'); }
function contactHistoryListFirst() { sendFunc('contactHistoryListFirst'); }
function contactHistoryListPrevious() { sendFunc('contactHistoryListPrevious'); }
function contactHistoryListNext() { sendFunc('contactHistoryListNext'); }
function contactHistoryListLast() { sendFunc('contactHistoryListLast'); }
function contactHistoryListSearch() { sendFunc('contactHistoryListSearch'); }
function contactHistoryListFilter() { sendFunc('contactHistoryListFilter'); }
function catalogueListFirst() { sendFunc('catalogueListFirst'); }
function catalogueListPrevious() { sendFunc('catalogueListPrevious'); }
function catalogueListNext() { sendFunc('catalogueListNext'); }
function catalogueListLast() { sendFunc('catalogueListLast'); }
function catalogueListSearch() { sendFunc('catalogueListSearch'); }
function catalogueListFilter() { sendFunc('catalogueListFilter'); }
function productListFirst() { sendFunc('productListFirst'); }
function productListPrevious() { sendFunc('productListPrevious'); }
function productListNext() { sendFunc('productListNext'); }
function productListLast() { sendFunc('productListLast'); }
function productListSearch() { sendFunc('productListSearch'); }
function productListFilter() { sendFunc('productListFilter'); }
function assetsListFirst() { sendFunc('assetsListFirst'); }
function assetsListPrevious() { sendFunc('assetsListPrevious'); }
function assetsListNext() { sendFunc('assetsListNext'); }
function assetsListLast() { sendFunc('assetsListLast'); }
function assetsListSearch() { sendFunc('assetsListSearch'); }
function assetsListFilter() { sendFunc('assetsListFilter'); }
function lookupFirst() { sendFunc('lookupFirst'); }
function lookupPrevious() { sendFunc('lookupPrevious'); }
function lookupNext() { sendFunc('lookupNext'); }
function lookupLast() { sendFunc('lookupLast'); }
function lookupSearch() { sendFunc('lookupSearch'); }
function lookupFilter() { sendFunc('lookupFilter'); }
function paymentGatewayListFirst() { sendFunc('paymentGatewayListFirst'); }
function paymentGatewayListPrevious() { sendFunc('paymentGatewayListPrevious'); }
function paymentGatewayListNext() { sendFunc('paymentGatewayListNext'); }
function paymentGatewayListLast() { sendFunc('paymentGatewayListLast'); }
function paymentGatewayListSearch() { sendFunc('paymentGatewayListSearch'); }
function paymentGatewayListFilter() { sendFunc('paymentGatewayListFilter'); }
function shopFeedListFirst() { sendFunc('shopFeedListFirst'); }
function shopFeedListPrevious() { sendFunc('shopFeedListPrevious'); }
function shopFeedListNext() { sendFunc('shopFeedListNext'); }
function shopFeedListLast() { sendFunc('shopFeedListLast'); }
function shopFeedListSearch() { sendFunc('shopFeedListSearch'); }
function shopFeedListFilter() { sendFunc('shopFeedListFilter'); }
function jobsListFirst() { sendFunc('jobsListFirst'); }
function jobsListPrevious() { sendFunc('jobsListPrevious'); }
function jobsListNext() { sendFunc('jobsListNext'); }
function jobsListLast() { sendFunc('jobsListLast'); }
function jobsListSearch() { sendFunc('jobsListSearch'); }
function jobsListFilter() { sendFunc('jobsListFilter'); }
function orderListFirst() { sendFunc('orderListFirst'); }
function orderListPrevious() { sendFunc('orderListPrevious'); }
function orderListNext() { sendFunc('orderListNext'); }
function orderListLast() { sendFunc('orderListLast'); }
function orderListSearch() { sendFunc('orderListSearch'); }
function orderListFilter() { sendFunc('orderListFilter'); }
function despatchListFirst() { sendFunc('despatchListFirst'); }
function despatchListPrevious() { sendFunc('despatchListPrevious'); }
function despatchListNext() { sendFunc('despatchListNext'); }
function despatchListLast() { sendFunc('despatchListLast'); }
function despatchListSearch() { sendFunc('despatchListSearch'); }
function despatchListFilter() { sendFunc('despatchListFilter'); }
function websiteConstantListFirst() { sendFunc('websiteConstantListFirst'); }
function websiteConstantListPrevious() { sendFunc('websiteConstantListPrevious'); }
function websiteConstantListNext() { sendFunc('websiteConstantListNext'); }
function websiteConstantListLast() { sendFunc('websiteConstantListLast'); }
function websiteConstantListSearch() { sendFunc('websiteConstantListSearch'); }
function websiteConstantListFilter() { sendFunc('websiteConstantListFilter'); }
function websiteFeedListFirst() { sendFunc('websiteFeedListFirst'); }
function websiteFeedListPrevious() { sendFunc('websiteFeedListPrevious'); }
function websiteFeedListNext() { sendFunc('websiteFeedListNext'); }
function websiteFeedListLast() { sendFunc('websiteFeedListLast'); }
function websiteFeedListSearch() { sendFunc('websiteFeedListSearch'); }
function websiteFeedListFilter() { sendFunc('websiteFeedListFilter'); }
function websiteMenuListFirst() { sendFunc('websiteMenuListFirst'); }
function websiteMenuListPrevious() { sendFunc('websiteMenuListPrevious'); }
function websiteMenuListNext() { sendFunc('websiteMenuListNext'); }
function websiteMenuListLast() { sendFunc('websiteMenuListLast'); }
function websiteMenuListSearch() { sendFunc('websiteMenuListSearch'); }
function websiteMenuListFilter() { sendFunc('websiteMenuListFilter'); }
function websiteMenuRowListFirst() { sendFunc('websiteMenuRowListFirst'); }
function websiteMenuRowListPrevious() { sendFunc('websiteMenuRowListPrevious'); }
function websiteMenuRowListNext() { sendFunc('websiteMenuRowListNext'); }
function websiteMenuRowListLast() { sendFunc('websiteMenuRowListLast'); }
function websiteMenuRowListSearch() { sendFunc('websiteMenuRowListSearch'); }
function websiteMenuRowListFilter() { sendFunc('websiteMenuRowListFilter'); }
function websitePageListFirst() { sendFunc('websitePageListFirst'); }
function websitePageListPrevious() { sendFunc('websitePageListPrevious'); }
function websitePageListNext() { sendFunc('websitePageListNext'); }
function websitePageListLast() { sendFunc('websitePageListLast'); }
function websitePageListSearch() { sendFunc('websitePageListSearch'); }
function websitePageListFilter() { sendFunc('websitePageListFilter'); }
function mediaPlayerListFirst() { sendFunc('mediaPlayerListFirst'); }
function mediaPlayerListPrevious() { sendFunc('mediaPlayerListPrevious'); }
function mediaPlayerListNext() { sendFunc('mediaPlayerListNext'); }
function mediaPlayerListLast() { sendFunc('mediaPlayerListLast'); }
function mediaPlayerListSearch() { sendFunc('mediaPlayerListSearch'); }
function mediaPlayerListFilter() { sendFunc('mediaPlayerListFilter'); }
function playlistListFirst() { sendFunc('playlistListFirst'); }
function playlistListPrevious() { sendFunc('playlistListPrevious'); }
function playlistListNext() { sendFunc('playlistListNext'); }
function playlistListLast() { sendFunc('playlistListLast'); }
function playlistListSearch() { sendFunc('playlistListSearch'); }
function playlistListFilter() { sendFunc('playlistListFilter'); }
function trackListFirst() { sendFunc('trackListFirst'); }
function trackListPrevious() { sendFunc('trackListPrevious'); }
function trackListNext() { sendFunc('trackListNext'); }
function trackListLast() { sendFunc('trackListLast'); }
function trackListSearch() { sendFunc('trackListSearch'); }
function trackListFilter() { sendFunc('trackListFilter'); }
function videoListFirst() { sendFunc('videoListFirst'); }
function videoListPrevious() { sendFunc('videoListPrevious'); }
function videoListNext() { sendFunc('videoListNext'); }
function videoListLast() { sendFunc('videoListLast'); }
function videoListSearch() { sendFunc('videoListSearch'); }
function videoListFilter() { sendFunc('videoListFilter'); }
function galleryListFirst() { sendFunc('galleryListFirst'); }
function galleryListPrevious() { sendFunc('galleryListPrevious'); }
function galleryListNext() { sendFunc('galleryListNext'); }
function galleryListLast() { sendFunc('galleryListLast'); }
function galleryListSearch() { sendFunc('galleryListSearch'); }
function galleryListFilter() { sendFunc('galleryListFilter'); }
function mediaFeedListFirst() { sendFunc('mediaFeedListFirst'); }
function mediaFeedListPrevious() { sendFunc('mediaFeedListPrevious'); }
function mediaFeedListNext() { sendFunc('mediaFeedListNext'); }
function mediaFeedListLast() { sendFunc('mediaFeedListLast'); }
function mediaFeedListSearch() { sendFunc('mediaFeedListSearch'); }
function mediaFeedListFilter() { sendFunc('mediaFeedListFilter'); }
function artistListFirst() { sendFunc('artistListFirst'); }
function artistListPrevious() { sendFunc('artistListPrevious'); }
function artistListNext() { sendFunc('artistListNext'); }
function artistListLast() { sendFunc('artistListLast'); }
function artistListSearch() { sendFunc('artistListSearch'); }
function artistListFilter() { sendFunc('artistListFilter'); }
function actListFirst() { sendFunc('actListFirst'); }
function actListPrevious() { sendFunc('actListPrevious'); }
function actListNext() { sendFunc('actListNext'); }
function actListLast() { sendFunc('actListLast'); }
function actListSearch() { sendFunc('actListSearch'); }
function actListFilter() { sendFunc('actListFilter'); }
function scheduleListFirst() { sendFunc('scheduleListFirst'); }
function scheduleListPrevious() { sendFunc('scheduleListPrevious'); }
function scheduleListNext() { sendFunc('scheduleListNext'); }
function scheduleListLast() { sendFunc('scheduleListLast'); }
function scheduleListSearch() { sendFunc('scheduleListSearch'); }
function scheduleListFilter() { sendFunc('scheduleListFilter'); }
function fileListFirst() { sendFunc('fileListFirst'); }
function fileListPrevious() { sendFunc('fileListPrevious'); }
function fileListNext() { sendFunc('fileListNext'); }
function fileListLast() { sendFunc('fileListLast'); }
function fileListSearch() { sendFunc('fileListSearch'); }
function fileListFilter() { sendFunc('fileListFilter'); }
function userListFirst() { sendFunc('userListFirst'); }
function userListPrevious() { sendFunc('userListPrevious'); }
function userListNext() { sendFunc('userListNext'); }
function userListLast() { sendFunc('userListLast'); }
function userListSearch() { sendFunc('userListSearch'); }
function userListFilter() { sendFunc('userListFilter'); }
function screenLabelListFirst() { sendFunc('screenLabelListFirst'); }
function screenLabelListPrevious() { sendFunc('screenLabelListPrevious'); }
function screenLabelListNext() { sendFunc('screenLabelListNext'); }
function screenLabelListLast() { sendFunc('screenLabelListLast'); }
function screenLabelListSearch() { sendFunc('screenLabelListSearch'); }
function screenLabelListFilter() { sendFunc('screenLabelListFilter'); }
function recordsetListFirst() { sendFunc('recordsetListFirst'); }
function recordsetListPrevious() { sendFunc('recordsetListPrevious'); }
function recordsetListNext() { sendFunc('recordsetListNext'); }
function recordsetListLast() { sendFunc('recordsetListLast'); }
function recordsetListSearch() { sendFunc('recordsetListSearch'); }
function recordsetListFilter() { sendFunc('recordsetListFilter'); }
function archiveListFirst() { sendFunc('archiveListFirst'); }
function archiveListPrevious() { sendFunc('archiveListPrevious'); }
function archiveListNext() { sendFunc('archiveListNext'); }
function archiveListLast() { sendFunc('archiveListLast'); }
function archiveListSearch() { sendFunc('archiveListSearch'); }
function archiveListFilter() { sendFunc('archiveListFilter'); }
function systemDefaultListFirst() { sendFunc('systemDefaultListFirst'); }
function systemDefaultListPrevious() { sendFunc('systemDefaultListPrevious'); }
function systemDefaultListNext() { sendFunc('systemDefaultListNext'); }
function systemDefaultListLast() { sendFunc('systemDefaultListLast'); }
function systemDefaultListSearch() { sendFunc('systemDefaultListSearch'); }
function systemDefaultListFilter() { sendFunc('systemDefaultListFilter'); }
// well those were the list view method handlers
// ... phew .. but we forgot all the clear search commands
function bookingListClearSearch() { sendFunc('bookingListClearSearch'); }
function todoListClearSearch() { sendFunc('todoListClearSearch'); }
function courseListClearSearch() { sendFunc('courseListClearSearch'); }
function eventListClearSearch() { sendFunc('eventListClearSearch'); }
function forumListClearSearch() { sendFunc('forumListClearSearch'); }
function threadListClearSearch() { sendFunc('threadListClearSearch'); }
function messageListClearSearch() { sendFunc('messageListClearSearch'); }
function shoutListClearSearch() { sendFunc('shoutListClearSearch'); }
function contactListClearSearch() { sendFunc('contactListClearSearch'); }
function contactHistoryListClearSearch() { sendFunc('contactHistoryListClearSearch'); }
function catalogueListClearSearch() { sendFunc('catalogueListClearSearch'); }
function productListClearSearch() { sendFunc('productListClearSearch'); }
function assetsListClearSearch() { sendFunc('assetsListClearSearch'); }
function lookupclearSearch() { sendFunc('lookupclearSearch'); }
function paymentGatewayListClearSearch() { sendFunc('paymentGatewayListClearSearch'); }
function shopFeedListClearSearch() { sendFunc('shopFeedListClearSearch'); }
function jobsListClearSearch() { sendFunc('jobsListClearSearch'); }
function orderListClearSearch() { sendFunc('orderListClearSearch'); }
function despatchListClearSearch() { sendFunc('despatchListClearSearch'); }
function websiteConstantListClearSearch() { sendFunc('websiteConstantListClearSearch'); }
function websiteFeedListClearSearch() { sendFunc('websiteFeedListClearSearch'); }
function websiteMenuListClearSearch() { sendFunc('websiteMenuListClearSearch'); }
function websiteMenuRowListClearSearch() { sendFunc('websiteMenuRowListClearSearch'); }
function websitePageListClearSearch() { sendFunc('websitePageListClearSearch'); }
function mediaPlayerListClearSearch() { sendFunc('mediaPlayerListClearSearch'); }
function playlistListClearSearch() { sendFunc('playlistListClearSearch'); }
function trackListClearSearch() { sendFunc('trackListClearSearch'); }
function videoListClearSearch() { sendFunc('videoListClearSearch'); }
function galleryListClearSearch() { sendFunc('galleryListClearSearch'); }
function mediaFeedListClearSearch() { sendFunc('mediaFeedListClearSearch'); }
function artistListClearSearch() { sendFunc('artistListClearSearch'); }
function actListClearSearch() { sendFunc('actListClearSearch'); }
function scheduleListClearSearch() { sendFunc('scheduleListClearSearch'); }
function fileListClearSearch() { sendFunc('fileListClearSearch'); }
function userListClearSearch() { sendFunc('userListClearSearch'); }
function screenLabelListClearSearch() { sendFunc('screenLabelListClearSearch'); }
function recordsetListClearSearch() { sendFunc('recordsetListClearSearch'); }
function archiveListClearSearch() { sendFunc('archiveListClearSearch'); }
// that'll do for now on the 'clearSearch front !!

//tony epasses functions
function ticketList() { sendFunc('ticketList'); }
function ticketSolo(ticid) { sendFunc("ticketSolo&ticid="+ ticid); }
function ticketListFirst() { sendFunc('ticketListFirst'); }
function ticketListPrevious() { sendFunc('ticketListPrevious'); }
function ticketListNext() { sendFunc('ticketListNext'); }
function ticketListLast() { sendFunc('ticketListLast'); }
function ticketListSearch() { sendFunc('ticketListSearch'); }
function ticketListClearSearch() { sendFunc('ticketListClearSearch'); }
function ticketListFilter() { sendFunc('ticketListFilter'); }

function ticketPreview() { sendFunc('ticketPreview'); }
function ticketNew() { sendFunc('ticketNew'); }
function ticketEdit() { sendFunc('ticketEdit'); }
function ticketAdjust() { sendFunc('ticketAdjust'); }
function ticketAssign() { sendFunc('ticketAssign'); }
function ticketDelete() { sendFunc('ticketDelete'); }



function sendFunc(f) { sendToServerAria5(dataSourcePathA5 + "?func="+f); }

function setLibrary(libId) {
	sendFunc("setLibrary&libId="+ libId);
}
function setSubject(libId,libsId) {
	sendFunc("setSubject&libId="+libId+"&libsId="+ libsId);
}

function in_array(needle, haystack, strict) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true
 
    var found = false, key, strict = !!strict;
 
    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            found = true;
            break;
        }
    }
 
    return found;
}

function getAllBubbles() {
	// these are all gonna get removed - change of bubble Wrap.
	var container = document.getElementById(targetDivA5);
	var bubblesArray = Array();
	if (container != null) {
		var elements = container.getElementsByTagName('div');
		for (var i=0; i<elements.length; i++) {
		//	
			if (elements[i].id != null && elements[i].id != '' && document.getElementById(elements[i].id) != null ) {
				
				if (elements[i].parentNode==container) {
					
					if ( !in_array(elements[i].id, permDivs, true)) {
						// must be of class 'bubble'
						//trace(elements[i].className);
						if (elements[i].className == 'bubble') {
							bubblesArray.push(elements[i]);
						}
					}
				}
			}
		}
	}
	return bubblesArray;
}
function getAllDepthBubbles() {
	var container = document.getElementById(targetDivA5);
	var bubblesArray = Array();
	if (container != null) {
		var elements = container.getElementsByTagName('div');
		for (var i=0; i<elements.length; i++) {
			if (elements[i].className == "bubble" ||
					elements[i].id == "bubbleManager" ||
						elements[i].id == "ergonetMenu") {
//			if (elements[i].id != null && elements[i].id != '' && document.getElementById(elements[i].id) != null ) {
				
				if (elements[i].parentNode==container) {
					
					if ( !in_array(elements[i].id, excludeFromDepth, true)) {
						bubblesArray.push(elements[i]);
					}
				}
			}
		}
	}
	return bubblesArray;
}
var isFading=false;
var fadeValue=1;
var fadeOutTimeout=null;
function fadeOutBubbles() {
	if (faderMode=='fade') {
		var fadeArray = getAllBubbles();
		if (fadeValue==1) { isFading=true; }
		fadeValue = fadeValue - 0.2;
		if (fadeValue>0.1 && isFading) {
			for (var i=0; i<fadeArray.length; i++) {
	//			fadeArray[i].style.opacity = fadeValue;
			}
			//trace('fade Out: '+fadeValue);
			fadeOutTimeout = window.setTimeout("fadeOutBubbles()",20);
		} else {
			for (var i=0; i<fadeArray.length; i++) {
				fadeArray[i].style.opacity = 0;
			}
			fadeValue=1;
			clearTimeout(fadeOutTimeout);
		}
	} else {
		
	}
}
// faderMode is the conducta control
var faderMode = "fade"; // or fade .. or whatever

var fadeInValue=0;
var fadeInTimeout=null;
function fadeInBubbles() {
	if (faderMode=='fade') {
		var fadeArray = getAllBubbles();
		isFading=false;
		fadeInValue = fadeInValue + 0.2;
		if (fadeInValue<1) {
			for (var i=0; i<fadeArray.length; i++) {
				fadeArray[i].style.opacity = fadeInValue;
			}
			
			fadeInTimeout = window.setTimeout("fadeInBubbles()",20);
		} else {
			for (var i=0; i<fadeArray.length; i++) {
				fadeArray[i].style.opacity = 1;
			}
			fadeInValue=0;
			clearTimeout(fadeInTimeout);
		}
	} else {
		
	}
	//trace('fade In: '+fadeInValue);
}
function flushBubbles() {
	/*
		flush removes all divs within container except:
		menuPermanent,notesDiv,debugDiv,errorNote
*/
	
	var container = document.getElementById(targetDivA5);
	var removeArray = getAllBubbles();
	/*
	if (container != null) {
		var elements = container.getElementsByTagName('div');
		for (var i=0; i<elements.length; i++) {
		//	
			if (elements[i].id != null && document.getElementById(elements[i].id) != null ) {
				
				if (elements[i].parentNode==container) {
					
					if ( !in_array(elements[i].id,permDivs,true)) {
						removeArray.push(elements[i]);
					}
				}
			}
		}
	}
	*/
	for (var i=0; i<removeArray.length; i++) {
		dropNode(removeArray[i].id);
		if (in_array(removeArray[i].id,bubDivIdArray,true)) {
			removeFromAppDivs(removeArray[i].id);
		}
	}
}
function removeFromAppDivs(id) {
	for (var i=0; i<bubDivIdArray.length; i++) {
		if (bubDivIdArray[i]==id) {
			bubDivIdArray.splice(i,1);
			break;
		}
	}
}
function reload(lcn) {
	window.location.href = lcn;
}

function createDivs() {
	var args = arguments;
	var node=null;
	for (var i=0; i<args.length; i++) {
	//	alert(args[i]);
		makeNode(args[i],targetDivA5);
		if ( !in_array(args[i], permDivs, true)) {
		//	trace(args[i]);
			bubDivIdArray.push(args[i]);
		}
	}
}
function isInDiv(parent,child) {
	if ( (parent == "container" || parent == "") && targetDivA5 ) {
		parent = targetDivA5;	
	}
	if (!targetDivA5) {
		trace("no targetDivA5 - see lib settings");	
	}
	var obj=document.getElementById(parent);

	
	if (obj!=null && child) {
		for (var i=0; i<obj.childNodes.length; i++) {
			var div = obj.childNodes[i].id;
			if (div) {
//				trace('found: '+div);
				if ( div==child	) {
	//				trace('found: '+child);
					return true;	
				}
			}
		}
	} else {
		trace('isInDiv error: parent: '+parent+', child: '+child);	
	}
	return false;
}
function addToDiv(div,content) {
	//trace('div: '+div+', content: '+content.replace(/</g,""));
	if (div) {
		var obj = document.getElementById(div);
		if (obj != null) {
			content = content.replace(/<div/g, "\n<div");
			obj.innerHTML = obj.innerHTML + "\n" + content;
		}
	}
}
function dropNode(id) {
	if (id) {
		var obj = document.getElementById(id);
		if (obj != null) {
			var par = obj.parentNode;
			if (par!=null) {
				par.removeChild(obj);
			}
		}
	}
}
function getNode(id) {
	if (id) {
		var obj = document.getElementById(id);
		if (obj!=null) { return obj; } else { return false; }
	}
}
function makeNode(id,parent) {
	if (parent == "container") {
		parent = targetDivA5;	
	}
	var pObj=null;
	if (pObj=getNode(parent)) {
		var nodeObj=null;
		if (nodeObj = getNode(id))  {
			// trace('node already exists: '+id);
		} else {
			var newElement=document.createElement('div');
			if (newElement != null) {
			//	newElement.className=id+'Div';
				newElement.id=id;
				pObj.appendChild(newElement);
				var n= pObj.childNodes.length;
				if (!in_array(id, permDivs, true)) {
					newElement.style.zIndex=n;
				}
			//	trace('z: '+n);
		//		getContent(pObj,id);
				return newElement;
			}
		}
	} else {
		trace('parent node not found: '+parent);
		return false;
	}
}
function makeNodeOfClass(id,parentID,clss) {
	if (parentID != null) {
		var pObj='';
		if (pObj=getNode(parentID)) {
			var nodeObj=null;
			if (nodeObj = getNode(id))  {
				// trace('node already exists: '+id);
			} else {
				var newElement=document.createElement('div');
				if (newElement != null) {
					newElement.className=clss;
					newElement.id=id;
					pObj.appendChild(newElement);
			//		getContent(pObj,id);
					return newElement;
				}
			}
		} else {
			trace('parent node not found: '+parentID);
			return false;
		}
	}
}

function init() {
	
	if (document.layers)
	  document.captureEvents(Event.MOUSEMOVE);
	if (document.layers || document.all)
	  document.onmousemove = getMouseXYA5;
	if (document.addEventListener)
	  document.addEventListener('mousemove', getMouseXYA5, true);	
		
	if (window.addEventListener) {
		window.addEventListener('DOMMouseScroll', wheel, false);
		window.onmousewheel = document.onmousewheel = wheel;
	}
	
	if (!conducta) {
		if( !window.XMLHttpRequest && window.ActiveXObject ) {
			window.XMLHttpRequest = function() {
			var a = [ 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.5.0' ],
			i = a.length; 
			while(i--) 
			{
				try {
				return new ActiveXObject( a[i] );
				alert(a[i]);
				} catch (e) { alert(e); }
				}
				return null;
			};
		}
		if( window.XMLHttpRequest ) {
		 xmlhttp = new XMLHttpRequest();  
		}
		if (createXMLHttpObject() && autoXhrMode) {
			xhr=true;
			locationTimeoutId=window.setInterval('locationHandler()',100);
			
			var str = "func=init,aria5menu"	;
			if (preFunc !='') { str = "func="+preFunc + ',aria5menu'; }
			str = dataSourcePathA5 + "?" + str;
			sendToServerAria5(str);
		}
		
		
		if (!window.addEventListener) {    
			window.addEventListener = function (type, listener, useCapture) {        
				attachEvent('on' + type, function() { listener(event) });    
			}
		} else {
			document.addEventListener('mousemove', getMouseXYA5, true);
		}
		
		ergonetMenu();
	}
}

/*

// From Product Builder

function locationMonitor() {
	//trace(currentCommand);
	var location = String(document.location);
	var newCommand = location.substr(location.indexOf("#")+1);
//	if (location.indexOf("#")==-1) {newCommand = 'catalogueBuild'; }
	if (newCommand != currentCommand) {
		var params = 'com='+newCommand;
		//getData('/lib/aria/estall/dataSource.php','page',params);
		getData('/lib/aria5/app/aria4/estall/dataSource.php','page',params);
		currentCommand = newCommand;
	}
	locationMonitorTimeoutId = window.setTimeout('locationMonitor()',100);
}

*/




useTinyMce = false;
useFCKeditor = false;
useCKeditor = true;
var editor;

function createCKeditor ( inDiv , textareaID ) {
	var inDivObj = document.getElementById(inDiv);
	if (inDivObj != null) {
		var content = inDivObj.innerHTML;
		var config = {};	
		inDivObj.innerHTML = '';
		editor = CKEDITOR.appendTo( inDivObj, config, content );
	}
}
				
				//require_once($atlasLibPrfx."ckeditor/ckeditor.php");
				//   <script type=\"text/javascript\" src=\"/lib/ckeditor/ckeditor.js\">
			
				//   ** i propose this for save operation.
				/*
				
				
				var editor_data = CKEDITOR.instances.element.getData();
						
						fldValuesArray[i]=editor_data;
						fieldArray[i]=element.id;
						
						CKEDITOR.instances.element.destroy();
						CKEDITOR.instances.element=null;
				
				
				*/
	/*
function createEditor()
{
	if ( editor )
		return;

	var html = document.getElementById( 'editorcontents' ).innerHTML;

	// Create a new editor inside the <div id="editor">, setting its value to html
	var config = {};
	editor = CKEDITOR.appendTo( 'editor', config, html );
}

function removeEditor()
{
	if ( !editor )
		return;

	// Retrieve the editor contents. In an Ajax application, this data would be
	// sent to the server or used in any other way.
	document.getElementById( 'editorcontents' ).innerHTML = editor.getData();
	document.getElementById( 'contents' ).style.display = '';

	// Destroy the editor.
	editor.destroy();
	editor = null;
}
*/

// DUPLICATE IN CONDUCTA ?
function postBubbleData(formName) {
	var paramArray = new Array();
	var fldValuesArray = new Array();
	var checksArray = new Array();
	var fieldArray = new Array();
	
	// used for select-multiple
	var options = new Array();
	
	if (document.forms[formName] != null) {
		var n=document.forms[formName].elements.length;
		var paramsArray = new Array();
		var str='';
		
		
		if (useTinyMce) {
			/*
			
			tiny mce retrieval here
			plus 'normal' retrieval
			
			
			*/
			var cntr=0;
			for (var i=0; i<n; i++) {
				
				var element = document.forms[formName].elements[i];
				
				var read=true;
				if (element.type ==undefined || element.type =="submit") {
					read=false;
				} else {
					//trace('<br />'+element.name+" :: "+element.id+" :: "+element.type);
				}
				if (element !=null && read) {
					if (element.type!="textarea") {
						if (element.type!="checkbox") {
							fldValuesArray[i]=element.value;
							fieldArray[i]=element.id;
						} else {
							fieldArray[i]=element.id;
							if (element.checked) {
								fldValuesArray[i]=element.value;
							} else {
								fldValuesArray[i]=0;
							}
						}
					} else {
						var ed = tinyMCE.get(element.id);
					//	ed.getContent();
						ed.setProgressState(0);
						fldValuesArray[i]=ed.getContent();
						fieldArray[i]=element.id;
					}
				}
			}	
		} else if (useFCKeditor) {
			/*
			
			fck retrieval here
			
			
			*/
		} else if (useCKeditor) {
			/*
			
			CKeditor retrieval here
			
			*/
			var cntr=0;
			for (var i=0; i<n; i++) {
				
				var element = document.forms[formName].elements[i];
//				trace('<br />'+element.name+" :: "+element.id+" :: "+element.type);
				var read=true;
				if (element.type ==undefined || element.type =="submit") {
					read=false;
				} else {
					//trace('<br />'+element.name+" :: "+element.id+" :: "+element.type);
				}
				if (element !=null && read) {
					//if (element.type!="textarea") {
						if (element.type!="checkbox") {
							fldValuesArray[i]=element.value;
							fieldArray[i]=element.id;
						} else {
							fieldArray[i]=element.id;
							if (element.checked) {
								fldValuesArray[i]=element.value;
							} else {
								fldValuesArray[i]=0;
							}
						}
			//		} else {

						// where it says 'element' in the string below it's the id of the field - e.g. content01A5
						/*
						
						var editor_data = editor.getData();
						fieldArray[i]=element.id;
						trace('editor fld: '+fieldArray[i]+', save: '+editor_data.substr(0,100)+"..");
						fldValuesArray[i]=editor_data;
						
						CKEDITOR.remove( editor );
						
						*/
//						CKEDITOR.instances.element.destroy();
//						CKEDITOR.instances.element=null;
//					}



				}

			}	
			if (editor) {
				var editor_data = editor.getData();
				i++;
				fieldArray[i]="content01A5";
		//		trace('editor fld: '+fieldArray[i]+', save: '+editor_data.substr(0,100)+"..");
				fldValuesArray[i]=editor_data;
				
				CKEDITOR.remove( editor );
			}
		} else {
			/*
			
			'normal' fields retrieval here
			
			
			*/
			var cntr=0;
			for (var i=0; i<n; i++) {
				
				var element = document.forms[formName].elements[i];
				
				var read=true;
				if (element.type ==undefined || element.type =="submit") {
					read=false;
				} else {
					//trace('<br />'+element.name+" :: "+element.id+" :: "+element.type);
				}
				
				if (element !=null && read) {
					
					if (element.type!="checkbox" && element.type!="radio" && element.type!="select-multiple") {
						fldValuesArray[cntr]=element.value;
						fieldArray[cntr]=element.id;
						
					} else {
						if (element.type=="checkbox") {
							fieldArray[cntr]=element.id;
							if (element.checked) {
								fldValuesArray[cntr]=element.value;
							} else {
								fldValuesArray[cntr]=0;
							}
						}
						if (element.type=="radio") {
							
							if (element.checked) {
								fieldArray[cntr]=element.id;
								fldValuesArray[cntr]=element.value;
							} 
						}
						if (element.type == "select-multiple"){
							var h=0;
							for (var j=0; j < element.options.length; j++) {	
								if(element.options[j].selected){
									//trace("mselect"+element.options[j].value);
									options[h]=element.options[j].value;
									h++;
								}
							}
							fldValuesArray[cntr]=options;
							fieldArray[cntr]=element.id;
						}
						
					}
					cntr++;
				}
			}	
		}
		
		var formSaveReport='';
		if (fieldArray.length>0 && fldValuesArray.length>0) {
			for (var i=0; i<fieldArray.length; i++) {
				if (fieldArray[i]) {
				paramArray.push(fieldArray[i] + "=" + fldValuesArray[i]);
				}
			}
		}
		if (checksArray.length>0 && chkValuesArray.length>0) {
			for (var i=0; i<checksArray.length; i++) {
				paramArray.push(checksArray[i] + "=" + chkValuesArray[i]);
			}
		}
		params = paramArray.join("&");
		//trace('post bubble: '+params);
		if (params) {
		//	xhrPost(params);
			postToServerA5(params);
		}
	} else {
		alert('cannot find: '+formName);
	}
}

var sendToServerAria5Counter=0;
function sendToServerAria5(uri) {
//	trace('^^^^^^^^^^^  sendTo Server : '+sendToServerAria5Counter+' ^^^^^^^^^^^^<hr>');
	sendToServerAria5Counter++;
	// Create an XMLHttpRequest and open it.
	// send the request with it's parameter string 
	// the response will be in the form of a string of javascript function calls
	// the response is then evaluated using eval(string)
	//trace(uri.indexOf('recordBubPos'));
	if (uri.indexOf('recordBubPos')==-1) {
//	note("<a href='"+uri+"'>"+uri+"</a>");
	}
	if (uri) {
		if (uri.substr(0,1) != "/") { uri="/"+uri; };
		xmlhttp = null;
		createXMLHttpObject();
		pathForTheRecord=uri;
		xmlhttp.open("GET", uri, true);
		xmlhttp.onreadystatechange = evaluateServerResponse; // NOTE: No Brackets on the end or it will NOT work.
		xmlhttp.initialise;
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
	//	trace(uri);
		xmlhttp.send(null);
	}
}

function postToServerA5(params) {
	var uri = dataSourcePathA5;
	if (uri.substr(0,1) != "/") { uri="/"+uri; };
 //trace('post: '+params);
//	note(uri);
	pathForTheRecord=uri+" ? POST ? "+params;
//trace('path: '+pathForTheRecord);
	xmlhttp = null;
	createXMLHttpObject();
	xmlhttp.open("POST", uri, true);
	xmlhttp.onreadystatechange = evaluateServerResponse; // note the absence of brackets!
	xmlhttp.initialise;
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
	xmlhttp.send(params);
}

function evaluateServerResponse() {
	//trace(xmlhttp.responseText);	
	if (xmlhttp != null) {
		if ( xmlhttp.readyState == 4) {
				
			if (xmlhttp.status == 200) {
					
					var xhrString = xmlhttp.responseText;
		
					xhrString = xhrString.replace("\n",'');
			//		trace(xhrString);
					
					if (xhrString.indexOf('<b>Warning</b>:')!=-1 || xhrString.indexOf('<!DOCTYPE HTML PUBLIC')!=-1) {
						note('Server-side error! - header received');
						
						trace(xhrString);
						xhrString="";
			//			alert('server-side error! \n'+xhrString);
					}
					if (xhrString.indexOf('<b>Parse error</b>:')!=-1) {
						note('Server-side error! - parse error');
						
						trace(xhrString);
						xhrString="";
					}
					if (xhrString.indexOf('<b>Fatal error</b>:')!=-1) {
						note('Server-side error! - Fatal error');
						
						trace(xhrString);
						xhrString="";
					}
					if (xhrString.indexOf('<b>Notice</b>:')!=-1) {
						note('Server-side Notice');
						
						trace(xhrString);
						xhrString="";
					}
					if (xhrString) {
						try {
							eval(xhrString);
							xhrString='';
							xmlhttp = null;
						}
						catch(err) {
							
					/*		var xhrArray = xhrString.split(";");
							for (var i=0; i<xhrArray.length; i++) {
								try {
									eval(xhrArray[i]);
								} catch(err) {
									note(err);
									trace(xhrArray[i]);
								}
							}
					*/
							note(err);
			//				trace(xhrString);
							xhrString='';
							xmlhttp = null;
							
						}
					}
				
			} else {
				if (xmlhttp.status==0) {
					
				} else {
					trace("Error! code: "+xmlhttp.status+"\npath: "+pathForTheRecord+"\nresponse: "+xmlhttp.responseText+"\n");
					xmlhttp = null;
					window.clearTimeout(noteTimeout);
				}
			} // end state 200
		} else {
			if (xmlhttp.readyState == 3) {
	//			alert("code: "+xmlhttp.readyState+"\nRequested path: "+pathForTheRecord);
			}	
			
	//		alert("code: "+xmlhttp.readyState+"\nRequested path: "+pathForTheRecord);
		} // end ready state 4
	}
}

var noteTimeout=null;
//  if conducta ..
function note(t) {
	var obj=document.getElementById('errorNote');
	if (obj != null) {
		obj.innerHTML = t;
		window.clearTimeout(noteTimeout);
		noteTimeout = window.setTimeout('clearNote()',4000);
	}
}
function clearNote() {
	var obj=document.getElementById('errorNote');
	window.clearTimeout(noteTimeout);
	if (obj != null) {
		obj.innerHTML = '';
	}
}



function getBubble( com, bwid ) {
	// does targetDiv exist ? if no then send a param to request it.
	var str = "func="+com+"&getBub="+ bwid;
	str = dataSourcePathA5 + "?" + str;
	sendToServerAria5(str);
}

var listPopArray = new Array();
var popListTargetObj = null;
var listPopTimeout = null;
function populateListAnimate(d,t) {
	var element = document.getElementById(d);
//	trace("text: "+t);
	clearTimeout(listPopTimeout);
	if (element != null) {
		element.innerHTML='';
		listPopArray = t.split("<div class=\"popList ");
		popListTargetObj = element;
		listPopTimeout = window.setTimeout("popList()",1);
	}	
	
}
function popList() {
	// animate drawing the list out down the page
	clearTimeout(listPopTimeout);
	if (listPopArray.length) {
		
		popListTargetObj.innerHTML += "<div class=\"popList " + listPopArray.shift();
		listPopTimeout = window.setTimeout("popList()",1);
	} else {
		
	}
}
var fadeList=null;
var listContent='';
var listDivId='';
var fadeListScrollSwitch=false;
function populateListFade(d,t,scr) {
	var element = document.getElementById(d);
	if (element != null) {
		fadeList=element;
		listContent=t;
		listDivId=d;
		if (scr) {
			fadeListScrollSwitch = true;
		} else {
			fadeListScrollSwitch = false;
		}
		fadeOutList();
	}
}
var isFadingList=false;
var fadeValueList=1;
var fadeOutTimeoutList=null;
function fadeOutList() {
	clearTimeout(fadeOutTimeoutList);
	if (fadeValueList==1) { isFadingList=true; }
	fadeValueList = fadeValueList - 0.2;
	if (fadeValueList>0.3 && isFadingList) {
		fadeList.style.opacity = fadeValueList;
		fadeOutTimeoutList = window.setTimeout("fadeOutList()",5);
	} else {
		fadeList.style.opacity = 0;
		fadeValueList=1;
		if (!fadeListScrollSwitch) {
			fadeList.innerHTML=listContent;	
		} else {
			populateListAnimate(listDivId,listContent)
		}
		fadeInTimeoutList = window.setTimeout("fadeInList()",10);
	}
}
var fadeInValueList=0;
var fadeInTimeoutList=null;
function fadeInList() {
	clearTimeout(fadeInTimeoutList);
	isFadingList=false;
	fadeInValueList = fadeInValueList + 0.2;
	if (fadeInValueList<1) {
		fadeList.style.opacity = fadeInValueList;
		fadeInTimeoutList = window.setTimeout("fadeInList()",50);
	} else {
		fadeList.style.opacity = 1;
		fadeInValueList=0;
	}
}
/*

function fadeInBubbles() {
	var fadeArray = getAllBubbles();
	isFading=false;
	fadeInValue = fadeInValue + 0.2;
	if (fadeInValue<1) {
		for (var i=0; i<fadeArray.length; i++) {
			fadeArray[i].style.opacity = fadeInValue;
		}
	//	trace('fade In: '+fadeInValue);
		fadeInTimeout = window.setTimeout("fadeInBubbles()",20);
	} else {
		for (var i=0; i<fadeArray.length; i++) {
			fadeArray[i].style.opacity = 1;
		}
		fadeInValue=0;
		clearTimeout(fadeInTimeout);
	}
}
*/

// lib functions from Jay Pritchard -- see also in dataSource.php

var popFormJsObj = new Object();
var my_store_elements 		= null;
var my_form_element_objs 	= new Object();
var my_form_element_tagnames 	= new Object();
var my_form_mixed_objs 		= new Object();


function initialiseFormElements() {
	
	popFormJsObj=new Object();
	if (document.getElementById('form_element_store')) {
		my_store_elements = document.getElementById('form_element_store').getElementsByTagName('*');
	}
	for (y=0;y<=my_store_elements.length-1;y++){
		elementname		=	my_store_elements[y].getAttribute('name');
		if( (elementname=='') || (elementname==null) || (elementname=='null') ){
			// do nothing
		}else{
			my_form_element_tagnames[elementname]	=	my_store_elements[y].nodeName;
			testnode	=	my_store_elements[y].parentNode;
			for(var j=0;j<20;j++){
				testnodename	=	testnode.nodeName;
				if(testnodename == 'SPAN'){
					my_form_mixed_objs[elementname]	=	testnode.childNodes;
					break;
				}else{
					testnode	= testnode.parentNode;
				}
			}
			my_form_element_objs[elementname]	=	my_store_elements[y];
		}
	}
}
/*
function buildform(formlabels1,formcontent1,datatypehash,tabletogo){
	
	info='';
	if (formcontent1 != null) {
	for (y in formcontent1){
		// Clone the element template
		datatype_id	=	(datatypehash[y]>0)?datatypehash[y]:1;
		info+=datatypehash[y]+' ';
		this_elementname				=	uitypes[datatypes[datatype_id].uitid].element_name;
		// target, named form element target
		form_element_source				=	my_form_element_objs[this_elementname];
		// peers and children within the templated uiType see formElements.php
		form_fragment_source			=	my_form_mixed_objs[this_elementname];
		var thisfieldname				=	y;
		// Add the clone into the main document via the target div
		//var theBR 						= 	document.createElement('br');
		//document.getElementById('demoform').appendChild(theBR);
		labeltext						=	(formlabels1[y]!='')?formlabels1[y]:'{No label value in DB for setting ['+y+'] }';
		formfielddata					=	(formcontent1[y]!='')?formcontent1[y]:'';
		var theLabel = document.createTextNode(labeltext+' ');
		//document.getElementById('demoform').appendChild(theLabel);
		elementref=addRowToTable(theLabel,form_fragment_source,tabletogo)
		// Find reference to form element in latest cloned fragment 
		elementref.setAttribute('id',y);
		elementref.setAttribute('name',y);
		element_needs_value_setting		=	(1)?true:false;
		if (element_needs_value_setting) {
			switch(form_element_source.nodeName) {
			case 'TEXTAREA':
				elementref.innerHTML=htmlentities(formfielddata);
			break;
			case 'INPUT':
				if(elementref.getAttribute('type')=='checkbox'){
					if(this_elementname=='checkbox_2'){
							//1 or 0
							elementref.checked=(formfielddata=='1')?true:false;
						}else{
							// true or false
							elementref.checked=(formfielddata=='true')?true:false;
						}
				}else{
					elementref.setAttribute('value',formfielddata);
				}
			break;
			default:
				elementref.setAttribute('value',formfielddata);
			}					
		}
		if(uitypes[datatypes[datatype_id].uitid].uiname=='textRow2'){
			// CUSTOM behaviour: Do box with link
			switch(valtypes[datatypes[formcontent1[y].datatype].vtid].description)
			{
			case 'Top level directory':
				thisurl=niceprefixwithslash(formcontent1[y]);
			break;
			case 'url':
				thisurl=niceprefixwithprotocol(formcontent1[y],'http://');
			break;
			case 'Email Address':
				thisurl=niceprefixwithprotocol(formcontent1[y],'mailto://');
			break;
			case 'uri':
				thisurl=niceprefixwithslash(formcontent1[y]);
			break;		
			default:
				thisurl=niceprefixwithslash(formcontent1[y]);
			}
			elementref.nextSibling.nextSibling.setAttribute('href',thisurl);
		}
	}
	}
	//alert('info'+info);
	info='';
	
}
*/
//Assign form element to settings item based on datatype
var popFormJsObj = new Object();

function populateForm(divId,formcontent){	
	if (formcontent) {
		for (y in formcontent) {
			this_elementname				=	uitypes[datatypes[formcontent[y].datatype].uitid].element_name;
			form_element_source				=	my_form_element_objs[this_elementname];
			// target, named form element target
			form_fragment_source			=	my_form_mixed_objs[this_elementname];
			// peers and children within the templated uiType see formElements.php
			formfielddata					=	(formcontent[y].value!='')?formcontent[y].value:'';
			var thisfieldname				=	formcontent[y].name;
			labeltext		=	(formcontent[y].label!='')?formcontent[y].label:'{No label }';
			//labeltext		=  '['+formcontent[y].datatype+'] '+labeltext;
			
			labeltext		=  '<span style="color:#FFFFFF">'+formcontent[y].name.substr(0,(formcontent[y].name.length -2))+'</span> '+labeltext;
			var theLabelDiv = document.createElement('DIV');
			theLabelDiv.innerHTML = labeltext;
			
			
			
			
			theLabelDiv.className="aria5LabelDiv";
			document.getElementById(divId).appendChild(theLabelDiv);
			var elementref=copyFragment(divId,form_fragment_source,this_elementname);
			var eventString = "";
			var eventArray = new Array();
			if (elementref == null) {
				
		//		trace( "null element: "+labeltext);
				
			} else {
				
				elementref.setAttribute('id',thisfieldname);
				elementref.setAttribute('name',thisfieldname);
				eventString = formcontent[y].events;
				eventArray = eventString.split("|");
				for(var i=0; i<eventArray.length-1; i+=2) {
					eventName = eventArray[i];
					eventCall = eventArray[i+1];
					if (eventName && eventCall) {
						elementref.setAttribute(eventName,eventCall);
					}
				}
				elementref.setAttribute('class',formcontent[y].cssClass);
				if (formcontent[y].isDisabled) {
					elementref.setAttribute('disabled','disabled');
				}
				if ( (datatypes[formcontent[y].datatype].uitid == 3) || (datatypes[formcontent[y].datatype].uitid == 4) ) {
					//trace(formcontent[y].optionArray);
					if ( (formcontent[y].optionArray != null) && (formcontent[y].optionArray.length==0) ) {
						elementref.options[0].text='not selectable';
					}
					if (formcontent[y].optionArray != null) {
						var n=0;
						for ( var i=0; i< formcontent[y].optionArray.length-1; i+=2 ) {
							var opt = new Option(formcontent[y].optionArray[i+1],formcontent[y].optionArray[i]);
							elementref.options[n]=opt;
							
							if (formcontent[y].value && (formcontent[y].optionArray[i]==formcontent[y].value) ) {
								elementref.selectedIndex = n;
							}
							n++;
						}
					} else {
						trace('popForm option array is null');	
					}
				}
				element_needs_value_setting		=	(1)?true:false;
				if (element_needs_value_setting) {
					switch(form_element_source.nodeName) {
					case 'TEXTAREA':
						elementref.innerHTML=htmlentities(formfielddata);
					break;
					case 'INPUT':
						if(elementref.getAttribute('type')=='checkbox'){
							if(this_elementname=='checkbox_2'){
									//1 or 0
									elementref.checked=(formfielddata=='1')?true:false;
								}else{
									// true or false
									elementref.checked=(formfielddata=='true')?true:false;
								}
						}else{
							elementref.setAttribute('value',formfielddata);
						}
					break;
					default:
						elementref.setAttribute('value',formfielddata);
					}					
				}
				if(uitypes[datatypes[formcontent[y].datatype].uitid].uiname=='textRow2'){
					// CUSTOM behaviour: Do box with link
					
					switch(valtypes[datatypes[formcontent[y].datatype].vtid].description)
					{
					case 'Top level directory':
						thisurl=niceprefixwithslash(formcontent[y].value);
					break;
					case 'url':
						thisurl=niceprefixwithprotocol(formcontent[y].value,'http://');
					break;
					case 'Email Address':
						thisurl=niceprefixwithprotocol(formcontent[y].value,'mailto://');
					break;
					case 'uri':
						thisurl=niceprefixwithslash(formcontent[y].value);
					break;		
					default:
						thisurl=niceprefixwithslash(formcontent[y].value);
					}
					elementref.nextSibling.nextSibling.setAttribute('href',thisurl);
					
				}
	
	
	
			}
		}
	}
}
function copyFragment(divId,mysourcefragment,elmntName) {
	var elementref=null;
	var obj = document.getElementById(divId);
	if (obj != null) {
		
		for (i=0; i<mysourcefragment.length; i++){
			var the_clone = mysourcefragment[i].cloneNode(true);
			obj.appendChild(the_clone);
			if(mysourcefragment[i].nodeName==my_form_element_tagnames[elmntName]){
				
			}
			if (mysourcefragment[i].name && (mysourcefragment[i].name == mysourcefragment[i].name)) {
			//	trace(' found name: '+mysourcefragment[i].name );
				elementref=obj.lastChild;
			}
			
		}
		if (!elementref) {
			trace('copyFragment not matched: '+my_form_element_tagnames[elmntName]+' in: '+elmntName);	
			for (i=0; i<mysourcefragment.length; i++){
				trace("name: "+elmntName);
			}
		}
	} else {
		trace('copyFragment "add to" obj not found: '+divId);	
	}
	return elementref;
}
/*
function populateForm(divId,formcontent) {
	
	if (divId && formcontent) {
		
		for (y in formcontent) {
		//	trace(y);
			// Clone the element template
			this_elementname				=	uitypes[datatypes[formcontent[y].datatype].uitid].element_name;
			if (!this_elementname) { trace('populateForm; missing element name'); return}
			
			form_element_source				=	my_form_element_objs[this_elementname];
			if (!my_form_mixed_objs) { trace('populateForm; missing mixed objects'); return}
			
			form_fragment_source			=	my_form_mixed_objs[this_elementname];
			if (!form_fragment_source) { trace('populateForm; form fragement source'); return}
			
			
			var the_clone					=	form_fragment_source.cloneNode(true);
			var thisfieldname				=	formcontent[y].name;
		
		
		//	var theBR 	=	document.createElement('br');
		//	document.getElementById(divId).appendChild(theBR);
		
			labeltext		=	(formcontent[y].label!='')?formcontent[y].label:'{  ['+formcontent[y].name+'] }';
	//		labeltext		=	'[sid'+formcontent[y].sid+':libsId'+formcontent[y].libsId+'] '+labeltext;
			labeltext		=  ''+formcontent[y].name+'</span> '+labeltext;
			labeltext		=  '<span style="color:#CCCCCC">'+formcontent[y].datatype+' '+labeltext;
			formfielddata	=	(formcontent[y].value!='')?formcontent[y].value:'{not set}';
			
	//		var theLabel = document.createTextNode(labeltext+' ');
			
			var theLabelDiv = document.createElement('DIV');
			theLabelDiv.innerHTML = labeltext+' ';
			theLabelDiv.className="aria5LabelDiv";
			document.getElementById(divId).appendChild(theLabelDiv);
			
			// Add the clone into the main document via the target div
			
			document.getElementById(divId).appendChild(the_clone);
			
			var elementref=new Array();
			// Find reference to form element in latest cloned fragment 
			elementref=document.getElementById(divId).lastChild.getElementsByTagName(form_element_source.nodeName);
			
			if (elementref.length>0) {
				// Caution there could be 2 items as some elements have an opening and closing tag, so just use the first 1
				elementref[0].setAttribute('id',y);
				elementref[0].setAttribute('name',y);
				
				var eventString = formcontent[y].events;
				var eventArray = eventString.split("|");
				for(var i=0; i<eventArray.length-1; i+=2) {
					eventName = eventArray[i];
					eventCall = eventArray[i+1];
					if (eventName && eventCall) {
						//trace(eventName+" , "+eventCall);
						elementref[0].setAttribute(eventName,eventCall);
					}
				}
				
				elementref[0].setAttribute('class',formcontent[y].cssClass);
				
				element_needs_value_setting=(uitypes[datatypes[formcontent[y].datatype].uitid].hasvalueproperty=='1')?true:false;
				if(element_needs_value_setting){
					if(form_element_source.nodeName!='TEXTAREA'){
						elementref[0].setAttribute('value',formfielddata);
					}else{
						elementref[0].innerHTML=htmlentities(formfielddata);
					}
				}
				
				
				if(uitypes[datatypes[formcontent[y].datatype].uitid].uiname=='textRow2'){
					// CUSTOM behaviour: Do box with link
					switch(valtypes[datatypes[formcontent[y].datatype].vtid].description)
					{
					case 'Top level directory':
						thisurl=niceprefixwithslash(formcontent[y].value);
					break;
					case 'url':
						thisurl=niceprefixwithprotocol(formcontent[y].value,'http://');
					break;
					case 'Email Address':
						thisurl=niceprefixwithprotocol(formcontent[y].value,'mailto:');
					break;
					case 'uri':
						thisurl=niceprefixwithslash(formcontent[y].value);
					break;		
					default:
						thisurl=niceprefixwithslash(formcontent[y].value);
					}
					if (elementref[0].nextSibling.nextSibling) {
						elementref[0].nextSibling.nextSibling.setAttribute('href',thisurl);
					} else {
						trace('populateForm error');
					}
				}
				
						//	create a select control
				if ( (datatypes[formcontent[y].datatype].uitid == 3) || (datatypes[formcontent[y].datatype].uitid == 4) ) {
					if (formcontent[y].optionArray.length==0) {
						elementref[0].options[0].text='not selectable';
					}
					var n=0;
					for ( var i=0; i< formcontent[y].optionArray.length-1; i+=2 ) {
						//trace(formcontent[y].optionArray[i]+" : "+formcontent[y].optionArray[i+1]+" : "+formcontent[y].value);
						var opt = new Option(formcontent[y].optionArray[i+1],formcontent[y].optionArray[i]);
						elementref[0].options[n]=opt;
						
						if (formcontent[y].value && (formcontent[y].optionArray[i]==formcontent[y].value) ) {
							//trace("selected");
							elementref[0].selectedIndex = n;
						}
						n++;
					}
				}
				
			}
		}
	}
}
*/

function niceprefixwithslash(this_string){
	if (this_string) {
	return (this_string.charAt(0)=='/')?this_string:'/'+this_string;
	} else {
	return "";	
	}
}

function niceprefixwithprotocol(this_string,protocol){
	return this_string=(this_string.substring(0,7)==protocol)?this_string:protocol+this_string;
}

function node_editor(form_item){
	preceding_form_item_id=form_item.previousSibling.id

	nodeAsString	=	(document.getElementById(preceding_form_item_id).value!='')?document.getElementById(preceding_form_item_id).value:'{not set}';
	govalidate(nodeAsString);
}

function govalidate(fragment)
{
  openwindow("http://validator.w3.org/check?prefill=1&doctype=XHTML 1.0 Strict&fragment="+escape(fragment),'validationresults');
} 

function openwindow(url,name)
{
  mywindow = window.open (url, name,"location=1,status=1,scrollbars=1,resizable=1, width=800,height=800");
 mywindow.focus();	
} 





function htmlentities (string, quote_style) {
    // Convert all applicable characters to HTML entities  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/htmlentities    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: nobbler
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Ratheous
    // -    depends on: get_html_translation_table
    // *     example 1: htmlentities('Kevin & van Zonneveld');    // *     returns 1: 'Kevin &amp; van Zonneveld'
    // *     example 2: htmlentities("foo'bar","ENT_QUOTES");
    // *     returns 2: 'foo&#039;bar'
    var hash_map = {}, symbol = '', tmp_str = '', entity = '';
    tmp_str = string.toString();    
    if (false === (hash_map = this.get_html_translation_table('HTML_ENTITIES', quote_style))) {
        return false;
    }
    hash_map["'"] = '&#039;';    for (symbol in hash_map) {
        entity = hash_map[symbol];
        tmp_str = tmp_str.split(symbol).join(entity);
    }
        return tmp_str;
}

function get_html_translation_table (table, quote_style) {
    // Returns the internal translation table used by htmlspecialchars and htmlentities  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/get_html_translation_table    // +   original by: Philip Peterson
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: noname
    // +   bugfixed by: Alex
    // +   bugfixed by: Marco    // +   bugfixed by: madipta
    // +   improved by: KELAN
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Frank Forte    // +   bugfixed by: T.Wild
    // +      input by: Ratheous
    // %          note: It has been decided that we're not going to add global
    // %          note: dependencies to php.js, meaning the constants are not
    // %          note: real constants, but strings instead. Integers are also supported if someone    
    // %          note: chooses to create the constants themselves.
    // *     example 1: get_html_translation_table('HTML_SPECIALCHARS');
    // *     returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}
    
    var entities = {}, hash_map = {}, decimal = 0, symbol = '';    var constMappingTable = {}, constMappingQuoteStyle = {};
    var useTable = {}, useQuoteStyle = {};
    
    // Translate arguments
    constMappingTable[0]      = 'HTML_SPECIALCHARS';    
    constMappingTable[1]      = 'HTML_ENTITIES';
    constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
    constMappingQuoteStyle[2] = 'ENT_COMPAT';
    constMappingQuoteStyle[3] = 'ENT_QUOTES';
     useTable       = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
    useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';
 
    if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
        throw new Error("Table: "+useTable+' not supported');        // return false;
    }
 
    entities['38'] = '&amp;';
    if (useTable === 'HTML_ENTITIES') {        entities['160'] = '&nbsp;';
        entities['161'] = '&iexcl;';
        entities['162'] = '&cent;';
        entities['163'] = '&pound;';
        entities['164'] = '&curren;';        entities['165'] = '&yen;';
        entities['166'] = '&brvbar;';
        entities['167'] = '&sect;';
        entities['168'] = '&uml;';
        entities['169'] = '&copy;';        entities['170'] = '&ordf;';
        entities['171'] = '&laquo;';
        entities['172'] = '&not;';
        entities['173'] = '&shy;';
        entities['174'] = '&reg;';        entities['175'] = '&macr;';
        entities['176'] = '&deg;';
        entities['177'] = '&plusmn;';
        entities['178'] = '&sup2;';
        entities['179'] = '&sup3;';        entities['180'] = '&acute;';
        entities['181'] = '&micro;';
        entities['182'] = '&para;';
        entities['183'] = '&middot;';
        entities['184'] = '&cedil;';        entities['185'] = '&sup1;';
        entities['186'] = '&ordm;';
        entities['187'] = '&raquo;';
        entities['188'] = '&frac14;';
        entities['189'] = '&frac12;';        entities['190'] = '&frac34;';
        entities['191'] = '&iquest;';
        entities['192'] = '&Agrave;';
        entities['193'] = '&Aacute;';
        entities['194'] = '&Acirc;';        entities['195'] = '&Atilde;';
        entities['196'] = '&Auml;';
        entities['197'] = '&Aring;';
        entities['198'] = '&AElig;';
        entities['199'] = '&Ccedil;';        entities['200'] = '&Egrave;';
        entities['201'] = '&Eacute;';
        entities['202'] = '&Ecirc;';
        entities['203'] = '&Euml;';
        entities['204'] = '&Igrave;';        entities['205'] = '&Iacute;';
        entities['206'] = '&Icirc;';
        entities['207'] = '&Iuml;';
        entities['208'] = '&ETH;';
        entities['209'] = '&Ntilde;';        entities['210'] = '&Ograve;';
        entities['211'] = '&Oacute;';
        entities['212'] = '&Ocirc;';
        entities['213'] = '&Otilde;';
        entities['214'] = '&Ouml;';        entities['215'] = '&times;';
        entities['216'] = '&Oslash;';
        entities['217'] = '&Ugrave;';
        entities['218'] = '&Uacute;';
        entities['219'] = '&Ucirc;';        entities['220'] = '&Uuml;';
        entities['221'] = '&Yacute;';
        entities['222'] = '&THORN;';
        entities['223'] = '&szlig;';
        entities['224'] = '&agrave;';        entities['225'] = '&aacute;';
        entities['226'] = '&acirc;';
        entities['227'] = '&atilde;';
        entities['228'] = '&auml;';
        entities['229'] = '&aring;';        entities['230'] = '&aelig;';
        entities['231'] = '&ccedil;';
        entities['232'] = '&egrave;';
        entities['233'] = '&eacute;';
        entities['234'] = '&ecirc;';        entities['235'] = '&euml;';
        entities['236'] = '&igrave;';
        entities['237'] = '&iacute;';
        entities['238'] = '&icirc;';
        entities['239'] = '&iuml;';        entities['240'] = '&eth;';
        entities['241'] = '&ntilde;';
        entities['242'] = '&ograve;';
        entities['243'] = '&oacute;';
        entities['244'] = '&ocirc;';        entities['245'] = '&otilde;';
        entities['246'] = '&ouml;';
        entities['247'] = '&divide;';
        entities['248'] = '&oslash;';
        entities['249'] = '&ugrave;';        entities['250'] = '&uacute;';
        entities['251'] = '&ucirc;';
        entities['252'] = '&uuml;';
        entities['253'] = '&yacute;';
        entities['254'] = '&thorn;';        entities['255'] = '&yuml;';
    }
 
    if (useQuoteStyle !== 'ENT_NOQUOTES') {
        entities['34'] = '&quot;';    }
    if (useQuoteStyle === 'ENT_QUOTES') {
        entities['39'] = '&#39;';
    }
    entities['60'] = '&lt;';    entities['62'] = '&gt;';
 
 
    // ascii decimals to real symbols
    for (decimal in entities) {        symbol = String.fromCharCode(decimal);
        hash_map[symbol] = entities[decimal];
    }
    
    return hash_map;}
	// End Lib functions from Jay Pritchard
	
	


	
	
	
	
	
	
	
	