cc=0
var openbooks = new Array()
openbooks["firstbookicon"]="open";

function showsubtoc(elmnt){
	document.getElementById(elmnt).style.display="block"
}

function hidemenu(elmnt){
	document.getElementById(elmnt).style.display="none"
}

function changetocimage(icon){
	var bi = document.getElementById(icon).id
	var f = openbooks[bi];
	var ext = ".jpg"
	// 0 means closed icon and 1 means open icon
	switch (f)
	{
		case 0:
			document.getElementById(icon).src="images/expanded_open_book_icon" + ext
			openbooks[bi] = 1
			break
		case 1:
			document.getElementById(icon).src="images/collasped_closed_book_icon" + ext
			openbooks[bi] = 0
			break
		default:
			document.getElementById(icon).src="images/expanded_open_book_icon" + ext
			openbooks[bi] = 1
			break
	}
}

function dynamicmenu(element,icon){
	var bi = document.getElementById(icon).id
	var f = openbooks[bi];
	var ext = ".jpg"
	// 0 means closed icon and 1 means open icon
	switch (f)
	{
		case 0:
			document.getElementById(icon).src="images/expanded_open_book_icon" + ext
			document.getElementById(element).style.display="block"
			openbooks[bi] = 1
			break
		case 1:
			document.getElementById(icon).src="images/collasped_closed_book_icon" + ext
			document.getElementById(element).style.display="none"
			openbooks[bi] = 0
			break
		default:
			document.getElementById(icon).src="images/expanded_open_book_icon" + ext
			document.getElementById(element).style.display="block"
			openbooks[bi] = 1
			break
	}
}

function showtoclocation(element,icon,link,ancestor){
}


function cleartoclocation(link,element){
}

function highlightString() { 	
	var filePath 		= decodeURIComponent(window.location.href); //else non English characters will be encoded.
	var searchType	    = filePath.substring(filePath.indexOf("searchType=") + 11, filePath.indexOf("&"));
	var isCaseSensitive = filePath.substring(filePath.indexOf("isCaseSensitive=") + 16, filePath.indexOf("&", filePath.indexOf("isCaseSensitive=")));
	var language		= filePath.substring(filePath.indexOf("language=") + 9, filePath.lastIndexOf("&"));
	var textToHighlight = filePath.substring(filePath.indexOf("textToHighlight=") + 16);			
	
	//to activate case sensitive highlighting
	isCaseSensitive = isCaseSensitive == "true" ? true : false;	
	
	//to activate whole word highlighting
	var isWholeWord	= true;
	if(typeof language != "undefined" && (language=="zh" || language=="zh_cn" || language=="zh_tw" ||  language=="zh-cn" || language=="zh-tw" || language=="ja" ||language=="ko" )){ 
		isWholeWord = false;
	}
	
	var wordsList 		= new Array();
	if(searchType == 'phrase'){
		wordsList.push(textToHighlight.replace(/##/g, " "));
	}else{
		wordsList = textToHighlight.split(",");
	}
	
	// When TOC is loaded turn on highlighting on search strings from last search
	if (window.find) {  // Chrome and Fire fox browsers
		
		if (window.getSelection) { // Using nested if because ampersands choke indexer			
			try {
				document.designMode = "on";
				var sel = window.getSelection();
				numberOfSearchStrings = wordsList.length -1;
				for (var i = numberOfSearchStrings; i >= 0; i--) {
					sel.collapse(document.body, 0);					
					//window.find(aString, aCaseSensitive, aBackwards, aWrapAround, aWholeWord, aSearchInFrames, aShowDialog);
					while (window.find(wordsList[i], isCaseSensitive, false, false, isWholeWord, false, false)) {
						document.execCommand("HiliteColor", false, "yellow");
						sel.collapseToEnd();
					}
					sel.collapse(document.body, 0);
				}
				//javascript:scroll(0,0);
				document.designMode = "off";
			}
			catch(err) {
			}
		}		

	}else if (document.body.createTextRange) { // IE browsers		
		//2 for whole word only
		//4 for case sensitive only
		//6 for case sensitive and whole word //
		var findOption = 0;		
		if(isWholeWord){
			findOption += 2
		}
		if(isCaseSensitive){
			findOption += 4
		}	
		
		// Select the body element content as the text range
		var docBody = document.body.createTextRange();
		// For each search string hit set background color to yellow
		for (var i = 0; i<wordsList.length; i++) {			
			var t = docBody.duplicate();      		
			while (t.findText(wordsList[i], 1000000000, findOption)) {
				t.execCommand("BackColor", false, "yellow");
				t.collapse(false);
			}
		}
	}
}

function loaddynamicTOC(topic,icon,link,ancestor) {	
	highlightString();
	try {
		window.parent.frames['contentspane'].frames['nav-main'].showtoclocation(topic,icon,link,ancestor);
	}
	catch(err) {
	}
}

function clearbgcolortoc(link,element){
	try {
		window.parent.frames['contentspane'].frames['nav-main'].cleartoclocation(link,element);
	}
	catch(err) {
	}
}

function closeHelp() {
	myWindow = window.top;
	// window.parent.frames['contentspane'].close();
	// myWindow.close();
	window.parent.closehelpframe();
}

// Remove previously saved search hit strings 
function flushSearch() {
    // Remove any search strings from previous search by flushing storage (Chrome,Firefox) or
    // setting cookies to null value (IE)
    var browser = navigator.userAgent;
    if (browser.indexOf('MSIE') == -1) {
		$.jStorage.flush(); // Chrome and Firefox search strings use jstorage and json
    }
    // IE search strings are in cookies
    if (document.cookie && document.cookie != '') { // check cookies for search strings
		var split = document.cookie.split('; ');
		var cookies = {};
		for (var i = 0; i < split.length; i++) {
			var name_value = split[i].split("=");
			cookies[decodeURIComponent(name_value[0])] = decodeURIComponent(name_value[1]);
		}
		// For each previously-existing search string cookie set value to null
		for(var name in cookies) {
			if (name.indexOf("search-word") != -1) {  // Search string cookies begin with "search-word"
				$.cookie(name, null);
			}
		}
    }
}
