
function j_Help()
{
	var url = document.location.href;
	var page = j_getUrlParam(url, "Page");

	if(page.toLowerCase() != "ctmdocumentpage")
	{
		if(page.toLowerCase() != "")
		{
		if (url)
			window.showModalDialog("../Help/" + page + ".aspx", null, 'help:no;status:yes;dialogWidth:800px;dialogHeight:600px;');
		}
	}
}

function j_clickSysMenu(oAnchor)
{
	top.status = oAnchor.innerText;

	if (lastTab != null)
		lastTab.className	= "TABNOTSELECTED";
	if (lastTableSubTabBlad != null)
		lastTableSubTabBlad.style.display = "none";
	if (lastSubTab != null)
		lastSubTab.className	= "SUBTABNOTSELECTED";

	jn_callWebServicesAsync(oAnchor.href, oAnchor.innerText, 0);
}

function j_initWS(oControl)
{
	var baseUrl;
	var oBases;
	var qi;
	var url2;
	
	if (oControl.readyState=="complete")
	{
		oBases	= document.getElementsByTagName("BASE");
		baseUrl	= (oBases.length > 0) ? oBases[0].href : document.URL;
		qi		= baseUrl.lastIndexOf("?");
		url2	= qi > 0 ? baseUrl.substr(0, qi) : baseUrl;

        try { oControl.useService(url2.substr(0, baseUrl.lastIndexOf("/")) + "/../webservices/AMIWebService.asmx?WSDL","wsService"); } catch (e) {}
	}
}

function j_IPOnload()
{
	j_checkExplorerVersion();

	if (typeof(service)=='undefined')
	{
		ws = document.createElement("<div onreadystatechange=\"j_InitWS()\" id=\"service\" style=\"behavior:url(../scripts/webservice.htc)\"></div>");
		document.body.appendChild(ws);
	}
	
	if (service.readyState=="ready")
		service.useService("../webservices/AMIWebService.asmx?WSDL","wsService");
}

function j_IPOnunload()
{
	document.all.service.wsService.callService(jn_logDone, "Logout");
}

function j_basePath()
{
	var oBaseColl = document.all.tags('BASE');
	url = (oBaseColl && oBaseColl.length) ? oBaseColl[0].href : window.location.href;
	url	= url.substring(0, url.lastIndexOf("/") + 1);
	
	return url;
}

var lastTab				= null;
var lastTableSubTabBlad	= null;
function jn_clickTab(oAnchor)
{
	var	tab		= oAnchor.parentElement.parentElement.parentElement.parentElement;
	var	oSubAnchors;
	var rc		= true;

	if (lastTab != null)
		lastTab.className	= "TABNOTSELECTED";

	tab.className	= "TABSELECTED";
	lastTab	= tab
	
	if (lastTableSubTabBlad != null)
		lastTableSubTabBlad.style.display = "none";
	if (lastSubTab != null)
		lastSubTab.className	= "SUBTABNOTSELECTED";
		
	lastTableSubTabBlad	= document.all.item("tablesubtabblad" + oAnchor.menuitemid);
	if (lastTableSubTabBlad != null)
	{
		lastTableSubTabBlad.style.display = "inline";
		if (oAnchor.href == null || oAnchor.href.length == 0 || oAnchor.href == j_basePath())
		{
			rc			= false;
			oSubAnchors = lastTableSubTabBlad.getElementsByTagName("A");
			
			if (oSubAnchors.length > 0)
			{
				if ( oSubAnchors[0].href.indexOf("CurrentSwyxPeer") >= 0 )
				{
					if ( oSubAnchors[0].href.charAt(oSubAnchors[0].href.length-1) != '=' )
						oSubAnchors[0].href += '=';
					
					try { oSubAnchors[0].href += j_getCurrentSwyxPeer(); }
					catch (e) {}
				}
				
				oSubAnchors[0].click();
			}
		}
	}
	
	jn_callWebServicesAsync(oAnchor.href, tab.id.split("tab")[1]);

	return rc;
}

var lastSubTab	= null;
function jn_clickSubTab(oAnchor)
{
	var	tab		= oAnchor.parentElement.parentElement.parentElement.parentElement;

	if (lastSubTab != null)
		lastSubTab.className	= "SUBTABNOTSELECTED";

	tab.className	= "SUBTABSELECTED";
	lastSubTab		= tab

	jn_callWebServicesAsync(oAnchor.href, "");

	return true;
}

function jn_callWebServicesAsync(url, tabNumber)
{
	/* call webservices after timeout to improve performance */		
	window.setTimeout("jn_callWebServices('" + url + "', '" + tabNumber + "')", 50);
}

function jn_callWebServices(url, tabNumber)
{
	if (document.all.service != null && document.all.service.wsService != null)
	{
		if (tabNumber != null && tabNumber.length > 0)
			document.all.service.wsService.callService(jn_logDone, "setSessionSetting", "TABNUMBER", tabNumber);
		if (url != null && url.length > 0)
		{
			url	= url.replace(/\&/g, "&amp;")
			document.all.service.wsService.callService(jn_logDone, "setSessionSetting", "TABURL", url);
		}
	}
}

function jn_logDone(result)
{
	if (result.error)
		alert ("Er is een fout opgetreden\n\n" + result.errorDetail.string);
}

function jn_ClearHistory()
{
	if (document.all.hidHistory != null) 
		document.all.hidHistory.value = '';
	if (document.all.hidNavInfo != null) 
		document.all.hidNavInfo.value = '';
	if (document.all.hidNavLabel != null) 
		document.all.hidNavLabel.value = '';
	if (document.all.htcHistory != null) 
		document.all.htcHistory.innerHTML = '&nbsp;';

}

function jn_LoadHistory()
{
	var NavLabel	= document.all.hidNavLabel;
	var NavInfo		= document.all.hidNavInfo;
	var NavHistory	= document.all.hidHistory;
	
	var NavCell		= document.all.htcHistory;
	var anchorText;

	if (NavLabel!=null && NavInfo!=null && NavCell!=null && NavHistory!=null)
	{
		var LabelCells	= NavLabel.value.split(" -> ");
		var InfoCells	= NavInfo.value.split(" -> ");
		var Hrefs		= NavHistory.value.split("#");
		var	title		= "";
		
		NavCell.innerHTML = Hrefs.length > 0 ? "" : "&nbsp;";
		
		if (Hrefs.length > 0)
		{
			try
			{
				title = document.all.contentIframe.contentWindow.document.title;
			} catch (e) {}
		
			anchorText		= LabelCells[0];
			if (typeof(anchorText)=='undefined') anchorText = '';
			if (anchorText.length > 40)
				anchorText	= anchorText.substring(0, 38) + "...";
			NavCell.innerHTML += "<a target=\"contentIframe\" onclick=\"j_RollBackHistory(" + 0 + ")\" href=\"" + Hrefs[0] + "\" title=\"" + LabelCells[0] + "\">" + anchorText + "</a>"
		
			for (var i=1;i<Hrefs.length;i++)
			{
				anchorText		= InfoCells[i - 1];
				if (typeof(anchorText)=='undefined') anchorText = '';
				if (anchorText.length > 40)
					anchorText	= anchorText.substring(0, 38) + "...";
				
				NavCell.innerHTML += " &raquo; <a target=\"contentIframe\" onclick=\"j_RollBackHistory(" + i + ")\" href=\"" + Hrefs[i] + "\" title=\"" + LabelCells[i] + " van " + InfoCells[i - 1] + "\">" + anchorText + "</a>"
			}

			anchorText		= InfoCells[Hrefs.length - 1];
			if (typeof(anchorText)=='undefined') anchorText = '';
			if (anchorText.length > 40)
				anchorText	= anchorText.substring(0, 38) + "...";
			NavCell.innerHTML += " &raquo; <B title=\"" + title + " van " + InfoCells[Hrefs.length - 1] + "\">" + anchorText + "</B>";
		}
	}
}

