var pageCurrent = 'toc';
var objPage = null;


function pageJump(pageName) {
	if (!pageName) {
		pageName = 'toc';
	}

	if (pageName == 'search') {
		showAllPages();
		window.scroll(0,0);
		return;
	}
	
	// Handle pages/anchors that have moved
	if (qsParm['anchor'] != null) {
		if (qsParm['anchor'] == 'input_output_errors') {
			pageName = 'debug';
		}
	}

	if (objPage) {
		objPage.style.display = 'none';
	}

	pageCurrent = pageName;
	objPage = document.getElementById(pageName);
	objPage.style.display = 'block';
	if (qsParm['anchor'] != null) {
		var destinationLink = document.getElementById(qsParm['anchor']);
		if (!destinationLink) {
			window.scroll(0,0);
		} else {
			var destx = destinationLink.offsetLeft; 
			var desty = destinationLink.offsetTop;
			window.scroll(destx,desty);
		}
	} else {
		window.scroll(0,0);
	}
}

var qsParm = new Array();
function qs() {
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			qsParm[key] = val;
		}
	}
}

function showAllPages() {
	if (!document.styleSheets) return;
	var theRules = new Array();
	if (document.styleSheets[0].cssRules)
		theRules = document.styleSheets[0].cssRules
	else if (document.styleSheets[0].rules)
		theRules = document.styleSheets[0].rules
	else return;
	
	for (var i=0; i<theRules.length; i++) {
		if (theRules[i].selectorText == ".page") {
			theRules[i].style.display = 'block';
			break;
		}
	}
	
}

function launchNetworkDiags() {
    ccc = window.HelpController;
    ccc.launchNetworkDiagnostics('');
}

function localizedStringForKey(key) {
    var ccc = window.HelpController;
	return ccc.localizedStringForKey(key);
}

function errorMessage() {
    var ccc = window.HelpController;
	return ccc.NSURLErrorMessage('');
}
