function SaveExportParams(sContext, sExportParam) {
	RCallExecute('sys/scripts/RemoteScripting/RSMisc.asp','SaveExportParams','DummySub',sContext,escape(sExportParam))
}

function GoTop(sUrl, bReplace){
	var s = new String

	s = BuildURL(sUrl)

	if (GoTop.arguments.length > 1){
		if (bReplace){
			window.top.location.replace(s)
		}else{
			window.top.location.href = s
		}
	}else{
		window.top.location.href = s
	}
}

function BuildURL(sUrl, sParams, sPageTitle){
	var s = new String(applicationBase+sUrl)
	if (s.indexOf('?') == -1){
		s = s + '?WinSesID=' + window.top.nWindowSessionID
	}else{
		s = s + '&WinSesID=' + window.top.nWindowSessionID
	}
	if ((BuildURL.arguments.length > 2) && (sPageTitle != null)) {
		s = s + '&PageTitle=' + sPageTitle
	}
	if ((BuildURL.arguments.length > 1) && (sParams != null)) {
		s = s + '&' + sParams
	}
	return s
}

function GoMain(sUrl, bReplace, sParams){
	var s

	if (MainPages.length==0) {
		MainPages[0] = window.top.frames["maintopic"].location.href
	}

	s = BuildURL(sUrl, sParams)

	if (GoMain.arguments.length > 1){
		if (bReplace){
			MainPages[MainPages.length-1] = s
			window.top.frames["maintopic"].location.replace(MakeUniqueQString(s))
		}else{
			MainPages[MainPages.length] = s
			window.top.frames["maintopic"].location.href = MakeUniqueQString(s)
		}
	}else{
		MainPages[MainPages.length] = s
		window.top.frames["maintopic"].location.href = MakeUniqueQString(s)
	}

	//DumpMainPages('GoMain')
}

function DumpMainPages(sOp) {
	var s = sOp + '(' + MainPages.length + ')\r\n'
	for (var i=0; i<MainPages.length; i++){
		s = s + i + ':' + MainPages[i] + '\r\n'
	}
	alert(s)
}

function MakeUniqueQString(s,sAppendChar) {
	var oDate = new Date()
	if ((sAppendChar == null) || !OneOf(sAppendChar,'?','&')) {
		sAppendChar = ((s.indexOf('?')==-1)? '?': '&')
	}
	return (s + sAppendChar + 'TS=' + oDate.getTime())
}

function GoWindow(sUrl, oWindow, sParams, bReplace){
	var s=BuildURL(sUrl, sParams)

	if (GoWindow.arguments.length > 3){
		if (bReplace){
			oWindow.location.replace(s)
		}else{
			oWindow.location.href = s
		}
	}else{
		oWindow.location.href = s
	}
}

function MainBack(){
	//DumpMainPages('GoBack')
	if (MainPages.length >= 2) {
		s = MainPages[MainPages.length-2]
		window.top.frames["maintopic"].location.href = MakeUniqueQString(s)
		--MainPages.length
	}


	//window.top.frames["maintopic"].history.go(-1)
	//window.top.frames["maintopic"].location.reload(true)
}

function RefreshHomePage(){
	var sMainURL = window.top.frames["maintopic"].location.href
	sMainURL = sMainURL.toLowerCase()
	if (sMainURL.indexOf('home.asp') != -1) {
		window.top.frames["maintopic"].location.reload(true)
	}
}

function RptDisconnect() {
	RCallExecuteNoWait('Reports/RSReportsPreview.asp', 'WhackSDConnection', 'DummySub')
}

function WhackQueryInstance(sHandle) {
	RCallExecuteNoWait('Query/RScriptQueryNode.asp', 'ShutDownQuery', 'DummySub', sHandle)
}

function WhackBatchInstance(sHeaderHandle,sDataEntryHandle) {
	RCallExecuteNoWait('Batch/RSBatch.asp', 'ShutDownBatch', 'DummySub', sHeaderHandle, sDataEntryHandle)
}

function ReleaseTabbedPageObject(sHandle) {
	RCallExecuteNoWait('sys/scripts/RemoteScripting/RSMisc.asp', 'ShutDownTabbedPage', 'DummySub', sHandle)
}

function ReleasePageObject(sHandle) {
	RCallExecuteNoWait('sys/scripts/RemoteScripting/RSMisc.asp', 'ShutDownPage', 'DummySub', sHandle)
}

function ReleaseReportObject(sHandle) {
	RCallExecuteNoWait('sys/scripts/RemoteScripting/RSMisc.asp', 'ShutDownReport', 'DummySub', sHandle)
}

function TabSwitchOut(sTabPageHandle) {
	RCallExecuteNoWait('sys/scripts/RemoteScripting/RSMisc.asp', 'TabSwitchOut', 'DummySub', sTabPageHandle)
}

function SetMainTopicWindow(owindow) {
	if (owindow.name == 'subtopic') {
		owindow.parent.document.location.replace(owindow.document.location.href)
	}
}

function SetMainCaptionLeft(sCaption, sImage, sSubCaption){
	window.top.frames["mainmenu"].SetCaptionLeft(sCaption, sImage, sSubCaption)
}

function SetMainMenu(iMenuID, sSubCaption){
	/*
	var sParms
	sParms = 'MenuId=' + iMenuID
	if (SetMainMenu.arguments.length > 1) {
		sParms = sParms + '&SubCaption=' + escape(sSubCaption)
	}
	GoWindow('MainMenu.asp', window.top.frames["mainmenu"], sParms)
	*/
	if (SetMainMenu.arguments.length == 1) { sSubCaption = '' }
	if (window.top.frames['mainmenu'].SetMainMenu) {
		window.top.frames['mainmenu'].SetMainMenu(iMenuID, sSubCaption)
	}
}

function SetMainMenuDisplay(Sector) {
	window.top.frames["mainmenu"].SetMainMenuDisplay(Sector)
}

function DummySub(oRCallObject) {return}

function LargeFontsInstalled(){
	if (typeof(ClientInfo)=='undefined') {
		return false
	} else {
		try {
			return ClientInfo.LargeFonts
		}

		catch(e) {
			return false;
		}
	}
}

function ClientInfoState() {
	//This will force a dialog box, in case security settings are set that way. Otherwise, user might get
	//dialog on the parent of a modal dialog
	DialogWidth(10)
}

function DialogWidth(nWidth) {
	if (typeof(ClientInfo)=='undefined') {
		return nWidth
	} else {
		try {
			return ClientInfo.Width(nWidth)
		}

		catch(e) {
			return(nWidth);
		}
	}
}

function DialogHeight(nHeight) {
	if (typeof(ClientInfo)=='undefined') {
		return nHeight
	} else {
		try {
			return ClientInfo.Height(nHeight)
		}

		catch(e) {
			return(nHeight);
		}
	}
}

function GetPleaseWaitingHTML(sText,bShowImage){
	var sImg = ''

	if (bShowImage) {
		sImg = '<img id="QueryGif" src="images\/EarthSpinN.gif" style="height:40px;width:40px;">'
	}

	var sHtml = '<div><div style="vertical-align:middle;display:inline;width:60px">' + sImg + '<\/div><div style="vertical-align:middle;display:inline;margin-left:15px;Font-family:tahoma,verdana;font-size:10pt;position:relative;top:0;left:0;">' + sText + '<\/div><\/div>'

	return sHtml
}

function MarkTopRecordDirty(){
	if (window.top.frames["maintopic"].wphMarkAsDirty) {
		window.top.frames["maintopic"].wphMarkAsDirty()
	}
}

function IsTopRecordDirty() {
	if (window.top.frames["maintopic"].wphPageIsDirty) {
		return window.top.frames["maintopic"].wphPageIsDirty()
	} else {
		return false
	}
}

function IgnoreTopRecordDirtyFlag() {
	if (window.top.frames["maintopic"].wphIgnorePageDirty) {
		window.top.frames["maintopic"].wphIgnorePageDirty()
	}
}

function GetTopRecordHeading() {
	if (window.top.frames["maintopic"].GetHeading) {
		return window.top.frames["maintopic"].GetHeading()
	} else {
		return ''
	}
}

function SaveQueryHeaderToPageAndWhack(sQHeader,sPageHandle,sQueryHandle) {
	RCallExecuteNoWait('Query/RScriptQueryNode.asp','SaveQueryHeaderToPageAndWhack','DummySub',sQHeader,sPageHandle,sQueryHandle)
}

function checkField(o,sCaption,bRequired,nFormat,nMax,nMin,nFlags,nMaxLength) {
	if (o==null || (o.tagName).toLowerCase()=='span') {return}
	if (o.value.length==0) {
		if (bRequired) {
			throw(gsRequiredFieldMissingColon+sCaption)	
		} else {
			return	
		}
	}
	switch (nFormat) {

		case fmtAMOUNT:
		case fmtAMOUNT_NEGATIVE:
		case fmtAMOUNT_NEGATIVE_NOCURRENCY:
		case fmtAMOUNT_NEGATIVE_THREE_DECIMAL:
		case fmtAMOUNT_NOCURRENCY:
		case fmtAMOUNT_THREE_DECIMAL:
		case fmtAMOUNT_ALLOW_ZERO:
			if (!oLibPage.ValidAmount(o.value)) { 
				throw(gsInvalidAmount+': ' + sCaption)
			}
			break
		case fmtNUMBER:
		case fmtNUMBER_DECIMAL:
		case fmtNUMBER_4DECIMAL:
		case fmtNUMBER_DEFAULT_ZERO:
		case fmtNUMBER_FORMATTED:
		case fmtNUMBER_NEGATIVE:
		case fmtRATE:
		case fmtGPA:
		case fmtPERCENT_NONNEGATIVE:
		case fmtANNUAL_RATE:
		case fmtNUMBER_THREE_DECIMAL_CUT_ZEROS:
			if (!oLibPage.ValidNumber(o.value,nFlags)) { 
				if (nFormat==fmtGPA) {
					throw('You have entered an invalid '+sCaption+'. Please reenter.')
				} else {
					throw(gsInvalidNumber+': ' + sCaption)
				}
			}
			if (nMin>0 && o.value<nMin) { 
				throw(gsInvalidMinValue+'\nMin Value='+nMin+' for '+sCaption)
			}
			if (nMax>0 && o.value>nMax) { 
				throw(gsInvalidMaxValue+'\nMax Value='+nMax+' for '+sCaption)
			}
			break
		case fmtDATEMDY:
		case fmtMMYYYY:
		case fmtMMDD:
			if (!oLibPage.ValidDate(o.value,nFormat)) { 
				throw(gsInvalidDate+': ' + sCaption)
			}
			break
		case fmtCLASS_OF:
			if (!oLibPage.ValidDate(o.value,nFormat)) { 
				throw(gsInvalidClassOf)
			}
			break
		case fmtDATE_FUZZY:
			if (!oLibPage.ValidDate(o.value,nFormat)) { 
				throw(gsInvalidFuzzyDate+': ' + sCaption)
			}
			break
		case fmtTIME:
			if (!oLibPage.ValidTime(o.value)) { 
				throw(gsInvalidTime+': ' + sCaption)
			}
			break
		case fmtTRANSIT_ROUTING:
		case fmtSORT_CODE:
		case fmtBSB:
		case fmtINSTITUTION_ID:
		case fmtBANK_NUMBER:
			if (!oLibPage.ValidSortCode(o.value,nFormat,nMaxLength)) { 
				throw('Invalid ' + sCaption)
			}
			break
	}
}	
