// Help Popup
function HlpShowPopUp()
{
	SysShowModal("HlpTipPopUp.aspx", "", "550px", "200px",null,1)
}

// Help Glossary
function HlpGlossary(txt)
{
	SysShowModal("HlpGlossaryPopUp.aspx?term=" + txt, "", "300px", "250px",null,1)
}

function SysSearch(txt)
{
	document.location = "SysSearch.aspx?text=" +txt
}

// Help Documents
function HlpDocument(helpID)
{
	var w = window.open("HlpDocument.aspx?Mode=5&helpid=" + helpID, "EOLHELP", "width=800,height=500,resizable=yes,scrollbars=yes,status=yes,toolbar=yes,menubar=no,location=no");
	if (hlpBalloonOn)
	{
		HlpBalloonOff();
		return;
	}
	if (w!=null)
		w.focus();
}

// Balloon help
var hlpBalloonCx;
var hlpBalloonOn = false;
function HlpBalloonOff()
{
	document.body.runtimeStyle.cursor = "default";
	hlpBalloonOn = false;
}
function HlpBalloon(helpID, type)
{
	SysMenuHide();
	if (hlpBalloonOn)
	{
		HlpBalloonOff();
		return;
	}
	window.document.body.runtimeStyle.cursor = "help";
	hlpBalloonOn = true;
	var a = SysCallback("hlpdocument.aspx?mode=1&helpid=" + helpID);
	var cx = window.createPopup();
	hlpBalloonCx = cx;
	cx.document.write(a);
	cx.document.close();

	var t = cx.document.getElementById('helpBalloon');
	if (t == null)
		return null;
	if (type==null)
		HlpBalloonAttachEvent(window.document);
	else
		HlpWizardAttachEvent(window.document);
}
function HlpBalloonAttachEvent(el)
{
	SysAttachEvent(el, "onmouseover", function() {HlpBalloonMouseOver()});
	SysAttachEvent(el, "onmouseout", function() {HlpBalloonMouseOut()});

	SysAttachEvent(el, "onactivate", function() {HlpBalloonMouseOver()});
	SysAttachEvent(el, "onblur", function() {HlpBalloonMouseOut()});
}
function HlpGetBalloonText(el)
{
	var td;
	if (el.id!=null && el.id!='')
		td = hlpBalloonCx.document.getElementById(el.id);
	while (td==null && el!=null)
	{
		el = el.parentElement;
		if (el!=null && el.id!=null && el.id!='')
		{
			td = hlpBalloonCx.document.getElementById(el.id);
		}
	}
	return td;
}
var hlpBalloonCxShow;
var hlpBalloonCurrent;
function HlpBalloonMouseOver()
{
	if (!hlpBalloonOn)
		return;
	var el = event.srcElement;
	if (el==null)
		return;
	var td = HlpGetBalloonText(el);
	if (td==null)
		return null;
	if (hlpBalloonCurrent == td.id)
		return;
	var txt = SysGetInnerText(td);
	if (txt == null)
		return;
	el = SysGetElement(td.id);
	hlpBalloonCxShow = window.createPopup();
	
	var s1 = '<html><head><link rel="stylesheet" type="text/css" href="SilverAndRed.css"></head>' +
	'<body scroll="auto" style="overflow:hidden;border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none">' +
	'<script language="javascript" src="SysControls.js" ><' + '/script>' + 
	'<div id="help" class="HelpBalloon">';
	var s2 = '</div></body></html>';
	var x = SysLeft(el);
	var y = SysBottom(el);
	hlpBalloonCxShow.show(x, y, 400, 1);
	hlpBalloonCxShow.document.write(s1 + txt + s2);
	hlpBalloonCxShow.document.close();

	var d = hlpBalloonCxShow.document.getElementById('help');
	if (d != null)
	{
		hlpBalloonCxShow.show(x, y, d.offsetWidth, d.offsetHeight);
	}
	hlpBalloonCurrent = td.id;
}
function HlpBalloonMouseOut()
{
	if (hlpBalloonCxShow==null)
		return;
	hlpBalloonCurrent = null;
	hlpBalloonCxShow.hide();
}

// Help Wizard
var hlpWizardctl;
function HlpWizardStart(helpID, ctlID)
{
	hlpWizardctl = SysGetElement(ctlID);
	if (hlpWizardctl)
	{
		HlpBalloon(helpID, "a")
	}
}
function HlpWizardAttachEvent(el)
{
	if (el.id != null && el.id !='')
	{
		SysAttachEvent(el, "onmouseover", function() {HlpWizardMouseOver()});
		SysAttachEvent(el, "onmouseout", function() {HlpWizardMouseOut()});

		SysAttachEvent(el, "onfocus", function() {HlpWizardMouseOver()});
		SysAttachEvent(el, "onblur", function() {HlpWizardMouseOut()});
	}
}
var hlpWizardCurrent;
var counter = 0;
function HlpWizardMouseOver()
{
	var el = event.srcElement;
	if (el==null)
		return;

	var td = HlpGetBalloonText(el);
	if (td==null)
		return null;
	if (hlpWizardCurrent == td.id)
		return	
	var txt = SysGetInnerText(td);
	if (txt != null)
	{
		SysSetInnerText(hlpWizardctl, txt);
		hlpWizardCurrent = td.id;
	}
}
function HlpWizardMouseOut()
{
}

// How To
var hlpHtRunning=false;
function HlpHtClose()
{
	parent.hlpHtRunning=false;
	parent.prtStopHelp()
}
function HlpHtStart()
{
	parent.hlpHtRunning=true;
	var hdoc=HlpHtDoc();
	if (hdoc==null)
		return;
	var doc=HlpHtMainDoc();		
	var pg=HlpHtFile(doc);
	HlpHtSetFirstText(hdoc,pg)
}
function HlpHtFile(doc)
{
	var pn = doc.location.pathname;
	var li = pn.lastIndexOf('/')
	var dot = pn.lastIndexOf('.')
	if (li<0 || dot<0)
		return null;
	return pn.substring(li+1,dot)
}
function HlpHtControl()
{
	if (!hlpHtRunning)
		return;
	var doc=HlpHtMainDoc();
	var hdoc=HlpHtDoc();
	if (hdoc==null)
		return;
	var pg=HlpHtFile(doc);
	HlpHtTabClose(hdoc);
	HlpHtTabOpen(hdoc,pg)
	HlpHtAddEvents(doc)
	HlpHtSetFirstText(hdoc,pg)
}
function HlpHtSetFirstText(hdoc,pg)
{
	var tb = hdoc.getElementById("t" + pg)
	if (tb==null || tb.rows.length==0)
		return;
	HlpHtCloseText(hdoc,tb);
	for (var iel=0; iel<tb.rows.length;iel++)
	{
		var tr = tb.rows[iel];
		if (tr.className=='' && tr.runtimeStyle.textDecoration!='line-through')
		{
			HlpHtShowText(tr);
			return;
		}
	}
}
function HlpHtDoc()
{
	var hlp = parent.document.getElementById('Help');
	if (hlp==null)
		return;
	return hlp.contentWindow.document;
}
function HlpHtMainDoc()
{
	var main = parent.document.getElementById('MainWindow');
	if (main==null)
	return;
	try
	{
		return main.contentWindow.document;
	}
	catch(e)
	{
		return null;
	}
}
function HlpHtTabClose(doc)
{
	var tb = doc.getElementById("HelpRows");
	if (tb==null)
		return;
	for (var i=0; i<tb.rows.length;i++)
	{
		var tr = tb.rows[i];
		var ctl = tr.getAttribute('ctl');
		if (ctl!=null)
			tr.runtimeStyle.display = 'none';
	}
}
function HlpHtTabOpen(doc,pg)
{
	var tr = doc.getElementById("p" + pg)
	if (tr==null)
		return;
	tr.runtimeStyle.display = 'block';
}
function HlpHtAddEvents(doc)
{
	for (var ifr=0; ifr<doc.forms.length;ifr++)
	{
		var form = doc.forms[ifr];
		for (var iel=0; iel<form.elements.length;iel++)
		{
			var el=form.elements[iel];
			if (el.tagName=='BUTTON' || (el.tagName=='INPUT' && el.Type=="BUTTON") )
			{
				SysAttachEvent(el, "onclick", new Function('HlpHtHandleOnClick("' + el.id + '")'))
			}
			else
			{
				SysAttachEvent(el, "onchange", new Function('HlpHtHandleOnChange("' + el.id + '")'))
			}
		}
	}
}
function HlpHtHandleBrowser(el)
{
	if (!parent.hlpHtRunning)
		return;
	HlpHtChange(el)
}
function HlpHtHandleOnChange(el)
{
	HlpHtChange(el)
}
function HlpHtHandleOnClick(el)
{
	HlpHtChange(el)
}
function HlpHtChange(el)
{
	var tr = HlpHtScratch(el);
	if (tr!=null)
		tr = tr.nextSibling;
	HlpHtShowText(tr);
}
function HlpHtShowText(tr)
{
	if (tr!=null)
		tr = tr.nextSibling;
	if (tr!=null)
		tr.runtimeStyle.display = 'block';
}
function HlpHtSetText(tr)
{
	if (tr==null)
		return;
	var hdoc=HlpHtDoc();
	if (hdoc==null)
		return;
	var div = hdoc.getElementById("helpText");
	if (div==null)
		return;
	var txt = tr.getAttribute("txt");
	if (txt!=null)
		div.innerText = tr.getAttribute("txt");
	else
		div.innerText = '';
}
function HlpHtScratch(el)
{
	var hdoc=HlpHtDoc();
	var doc=HlpHtMainDoc();
	if (hdoc==null || doc==null)
		return;
	var pg = HlpHtFile(doc);
	var tb = hdoc.getElementById("t" + pg)
	if (tb==null || tb.rows.length==0)
		return;
	var tr = hdoc.getElementById('p' + pg)
	if (tr==null)
		return;
	var ctl = tr.getAttribute('ctl');
	if (ctl==null) 
		return;
	var tr = hdoc.getElementById('p' + ctl + el)
	if (tr==null)
	{
		tr = HlpHtFindControlRow(el,tb);
		if (tr==null)
			return;
	}
	HlpHtCloseText(hdoc,tb)
	HlpHtScratchUntil(tr,tb);
	tr = tr.nextSibling;
	tr.runtimeStyle.display = 'none';
	return tr;
}
function HlpHtFindControlRow(el,tb)
{
	for (var iel=0; iel<tb.rows.length;iel++)
	{
		var tr = tb.rows[iel];
		var ctlid = tr.getAttribute('ctlid');
		if (ctlid!=null)
		{
			var ids = ctlid.split(' ');
			for (var si=0; si<ids.length;si++)
			{
				if (ids[si]==el)
					return tr;
			}
		}
	}
}
function HlpHtScratchUntil(trUntil,tb)
{
	for (var iel=0; iel<tb.rows.length;iel++)
	{
		var tr = tb.rows[iel];
		if (tr.className!='HelpGuideText')
			tr.runtimeStyle.textDecoration='line-through';	
		if (tr==trUntil)
			return;
	}
}
function HlpHtCloseText(hdoc,tb)
{
	for (var iel=0; iel<tb.rows.length;iel++)
	{
		var tr = tb.rows[iel];
		if (tr.className=='HelpGuideText')
		{
			tr.runtimeStyle.display = 'none';
		}
	}
}
function HlpHtMouseOver()
{
	HlpHtSwitchColors(true)
}
function HlpHtMouseOut()
{
	HlpHtSwitchColors(false)
}
function HlpHtSwitchColors(add)
{
	var el = event.srcElement;
	el = el.parentElement;
	var ctlid=el.getAttribute("ctlid");
	if (ctlid==null)
		return;
	var ids = ctlid.split(' ');
	for (var si=0; si<ids.length;si++)
	{
		HlpHtSwitchColor(ids[si],add);
	}
}
function HlpHtSwitchColor(id,add)
{
	var doc = HlpHtMainDoc();
	if (doc != null)
	{
		var el = doc.getElementById(id);
		if (el!=null)
		{
			if (el.parentElement.tagName == 'TD')
				el=el.parentElement;
			if (add)
				SysAddClass(el,'HelpGuideSelect')
			else
				SysRemoveClass(el,'HelpGuideSelect')
		}
	}
}

