
	var ngwwbook = '';
	var ngwwpage = '';
	var ngwwtocx = true;

	$(document).ready(function(){
	
		if (ngwwtocx) {
			if (document.getElementById('ng1wwtcnt')) {
				ngwwTreeB();
				document.getElementById('ng1wwtcnt').style.display="block";
				// ngwwtocx = false;
			}
		}
		
		//  $("span").click( function() { alert(this.value); var i = '#ng1ww' + this.id; return false;} );

		$("#woptabs").tabs();
		
		ngSearchView();
		
	});
	
	function ngwwTreeB() {
		$('#ng1wwtoc').treeview({
			persist: "cookie",
			cookieId: "ng1wwx",
			collapsed: true,
			unique: true,
			url: "index.php?module=ng1ww&xmit=ng1wwajx"
		});
	}
	function ngwwTreeC(id) {
		//$(gdd).remove;
		//alert($(gdd).parents("img").filter(":first").val);
		//$(idd).treeview({
		//});
		alert(id);
	}
	
	function ngwwExpCla() {
		// expand collapse switch
		if (ngwwtocx==true) {
			ngwwtocx=false;
			document.getElementById('ng1wwboxop').textContent = 'Expand';
			document.getElementById('ng1wwtcnt').style.display="none";
		} else {
			ngwwtocx=true;
			document.getElementById('ng1wwboxop').textContent = 'Collapse';
			// ngwwTreeV();
			document.getElementById('ng1wwtcnt').style.display="block";
		}
	}
	
	function ngwwDocSet(book, page) {
		// nmu
		ngwwbook=book;
		ngwwpage=page;
	}

	function ngwwDocGet() {
		// nmu
		document.getElementById('ng1wwedit').href =
			'ng1ww/op/open/htm/' + ngwwbook + ',' + ngwwpage;
	}

	//
	
	function ngSel2In(e) {
		var i = document.getElementById('phpws_form_' + e + 'sel').value;
		if (i > 0) {
			document.getElementById('phpws_form_' + e).value
				= document.getElementById('phpws_form_' + e + 'sel').options[i].text;
		} else {
			document.getElementById('phpws_form_' + e).value = '';
		}
		// document.getElementById('phpws_form_' + e + 'sel').selectedIndex=null;
		document.getElementById('phpws_form_' + e).focus();
	}
	
	//
	// part ngHelp
	function ngHelpClick(hlpid) {
		var elmnt = document.getElementById(hlpid);
		var x = elmnt.previousSibling.offsetLeft;
		var y = elmnt.previousSibling.offsetTop + 20;
		elmnt.style.left = x + 'px';
		elmnt.style.top = y + 'px';
		elmnt.style.display='block';
	}

	function ngHelpOvr(hlpid) {
		var elmnt = document.getElementById(hlpid);
		if (elmnt.previousSibling.previousSibling.tagName=='A') {
			elmnt.previousSibling.style.textDecoration = 'underline';
			elmnt.previousSibling.previousSibling.style.textDecoration = 'underline';
		}
	}

	function ngHelpOff(hlpid) {
		var elmnt = document.getElementById(hlpid);
		elmnt.style.display='none';
		if (elmnt.previousSibling.previousSibling.tagName=='A') {
			elmnt.previousSibling.style.textDecoration = 'none';
			elmnt.previousSibling.previousSibling.style.textDecoration = 'none';
		}
	}

	//
	// Part search
	function ngTermsView(div) {
		var elmnt = document.getElementById(div);
		if (elmnt.style.display=='none') {
			elmnt.style.display='block';
		} else {
			elmnt.style.display='none';
		}
	}
	
	function ngSearchView() {
		if(document.getElementById('searchSelect')) {
			var lookfor = document.getElementById('searchphrase');
			hiSearchTerms(lookfor.value, false);
		}
	}
	
	function ngSearchPosit() {
		if(document.getElementById('searchSelect')) {
			var lookfor = document.getElementById('searchphrase');
			// has to work out
		}
	}

	function hiSearchTerms(searchText, treatAsPhrase, hiliteStart, hiliteEnd) {
		// treatAsPhrase parameter = search entire phrase, else take words
		if (treatAsPhrase) {
			searchArray = [searchText];
		} else {
			searchArray = searchText.split(" ");
		}
		if (!document.body || typeof(document.body.innerHTML) == "undefined") {
			return false;
		}
		var bodyText = document.body.innerHTML;
		for (var i = 0; i < searchArray.length; i++) {
			bodyText = doSearchHilite(bodyText, searchArray[i], hiliteStart, hiliteEnd);
		}
		document.body.innerHTML = bodyText;
		return true;
	}

	function doSearchHilite(bodyText, searchTerm, hiliteStart, hiliteEnd) {
		if ((!hiliteStart) || (!hiliteEnd)) {
			hiliteStart = "<font style='background-color:#FFFF00;'>";
			hiliteEnd = "</font>";
		}
		var newText = "";
		var lcSearchTerm = searchTerm.toLowerCase();
		var lcBodyText = bodyText.toLowerCase();
		var i = bodyText.indexOf('<div id="main-content">',0);
		while (bodyText.length > 0) {
			i = lcBodyText.indexOf(lcSearchTerm, i+1);
			if (i < 0) {
				newText += bodyText;
				bodyText = "";
			} else {
				// skip anything inside an HTML tag
				if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
					// skip anything inside a <script> block
					if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
						newText += bodyText.substring(0, i) + hiliteStart + bodyText.substr(i, searchTerm.length) + hiliteEnd;
						bodyText = bodyText.substr(i + searchTerm.length);
						lcBodyText = bodyText.toLowerCase();
						i = -1;
					}
				}
			}
		}  
		return newText;
	}



	

