
				const rpt_webrooturl = 'http://www4.cbs.state.or.us/ex/imd/reports';
				var load_time	= Math.round((new Date()).getTime/1000);
var t        	= 0;
var tickDiv 	= null;
var Jumped   	= "";
var imagelink	= null;
var textlink	= null;
var rpt_window  = 'rpt_window';

function getCookie(c_name)
{
	var i,x,y,ARRcookies=document.cookie.split(";");
	var cookie_name=c_name.toLowerCase();
	for (i=0;i<ARRcookies.length;i++)
	{
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"").toLowerCase();
		if (x==cookie_name)
		{
			return unescape(y);
		}
	}
}

function setCookie(c_name,value,exdays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

function rpt_debug_mode()
{
	return (getCookie("admin_debug")==true);
}

function resizeReportFrame()
{
	var bodyarea=document.getElementById('bodyarea');
	if(bodyarea!=undefined)
	{
		bodyarea.style.height=(document.body.clientHeight-30)+'px';
		setTimeout('resizeReportFrame()',250);
	}
}

function canAccessTop() {
    var html = null;
    try { 
      // deal with older browsers
      var doc = top.contentDocument || top.contentWindow.document;
      html = doc.body.innerHTML;
    } catch(err){
      // do nothing
    }

    return(html !== null);
}

function JumpToReport()
{
	if(imagelink!=undefined)
	{
		var jumpto=imagelink.dataset.jumpto;
		if(textlink!=null) textlink.style.display="none";
		if (canAccessTop() && top.location != location && top.location.protocol == 'https:' && jumpto.substr(0,5)== 'http:')
		{
			var domain=(jumpto.substr(7).replace(/\/.*$/,"")).trim();
			if(domain=="") domain="the report";
			if(confirm("You are leaving our secured page to view this report.\n\nContinue on to "+domain+"?"))
			{
				window.top.location = jumpto;
			}
			else
			{
				window.top.location="../";
			}
		}
		else
		{
			if(imagelink.dataset.beforejump!=undefined && imagelink.dataset.beforejump!='')
			{
				// actuate reports require a logout before loading the actual report
				// there may be other uses for this. It is set in the dsp_loading.cfm file
				var img = new Image(1,1);
				img.src=imagelink.dataset.beforejump;
			}
			setTimeout(function() { self.location = imagelink.dataset.jumpto; }, 500);
		}
		return(false);
	}
}

function ticker()
{
	t=t+1;
	m=parseInt(t/60);
	s="00"+(t-m*60);
	tickDiv.innerHTML=m+":"+s.substr(s.length-2);
}

function RptWin(URL)
{
	// browsers are having issues when we force a new window to open without
	// an tool bar or at a specific size so we must let the browser decide
	// how to open the window now. Schworak 2021-09-08
	if(URL=="")
	{
		return true; // no URL was provided so return TRUE so the link will act normal
	}
	w = window.open('about:blank',rpt_window);
	try
	{
		var doc=w.document;
	}
	catch(e)
	{
		// the user has changed the location of the previously opened
		// window or something else has caused us to lose access to it
		// so we must create a window with a new name and try again
		rpt_window = 'rpt_window_'+Math.floor(new Date());
		w = window.open('about:blank',rpt_window);
		try
		{
			var doc=w.document;
		}
		catch(e)
		{
			// we still can't get a grip on the window that we want
			// so open in the current window instead
			self.location=URL;
			return false; // return FALSE so the link will not try to do its own thing
		}
	}
	// we have access to the window so load our content
	w.focus();
	w.location=URL;
	return false; // return FALSE so the link will not try to do its own thing
}

function RunReportByNumber()
{
	report=window.prompt("Please enter the report number you wish to run then\npress ENTER or click OK to run the report.","");
	if (report != "" & report != null)
	{
		RptWin(rpt_webrooturl+"/rpt/index.cfm?ProgID=" + report.toUpperCase(), 700, 600);
	}
}

function ShowHideHeaderRow()
{
	try
	{
		var header_row=document.getElementById("header_row");
		var format_drop=document.getElementById("format_drop");
		if(header_row!=undefined && format_drop!=undefined)
		{
			if(format_drop.value == "csv" || format_drop.value == "txt")
			{
				header_row.style.display="";
			}
			else
			{
				header_row.style.display="none";
			}
		}
	}
	catch(er)
	{
		// who cares?
	}
}

function SelectAll(lst)
{
	var x=0;
	if(lst.selectedIndex == 0)
	{
		SelectNone(lst);
	}
	if(lst.selectedIndex == (lst.options.length-1))
	{
		SelectNone(lst);
		for(x=1; x<lst.options.length-1; x++)
		{
			lst.options[x].selected = true;
		}
	}
}

function SelectNone(lst)
{
	var x=0;
	for(x=0; x<lst.options.length; x++)
	{
		lst.options[x].selected = false;
	}
}


function pageReady() 
{
	var navbar=document.getElementById('navbar');
	var bodyarea=document.getElementById('bodyarea');
	var redirectImages=document.querySelectorAll('img[data-redirect]');
	var runreport=document.getElementById('rpt_run_report');
	var format_drop=document.getElementById("format_drop");
	var side_menu_attached=document.getElementById("side_menu_attached");
	var side_menu_login=document.getElementById("side_menu_login");
	divTick=document.getElementById("tick");
	imagelink=document.getElementById("imagelink");
	textlink=document.getElementById("textlink");

	ShowHideHeaderRow();
	
	for(var i=0; i<redirectImages.length; ++i)
	{
		redirectImages[i].onload = function() { self.location=redirectImages[i].dataset.redirect; } 
	}
	
	if(bodyarea!=undefined && imagelink==undefined)
	{
		// we are in the frame set so we need to load the frame areas
		var nav=getCookie("report_navbar");
		var bod=getCookie("report_bodyarea");
		
		document.body.style.padding="0";
		document.body.style.margin="0";
		resizeReportFrame();

		if(nav=="" || bod=="")
		{
			bodyarea.remove();
			var message=document.createElement("h3");
			message.innerHTML="Some reporting values are missing. We cannot continue.";
			document.body.append(message);
			history.go(-1);
		}
		else
		{
			if(navbar!=undefined) navbar.src=nav;
			bodyarea.src=bod;
		}
	}
	
	if(tickDiv!=undefined) self.setInterval(ticker,1000);
	if(textlink!=undefined)  
	{
		textlink.onclick = function() { return(JumpToReport()); }
		document.body.onunload = function() { textlink.style.display='none'; }
		setTimeout(JumpToReport,500);
	}
	if(format_drop!=undefined)
	{
		format_drop.onchange = function () { ShowHideHeaderRow(); }
		format_drop.onblur = function() { ShowHideHeaderRow(); }
	}
	if(side_menu_attached!=undefined)
	{
		side_menu_attached.onclick = function () { alert('There are two types of access.\n\n\nCatalog Access: How you are attached to the report catalog web page\n\nActuate Access: How you are attached to the individual reports'); return false; }
	}
	if(side_menu_login!=undefined)
	{
		side_menu_login.onclick = function() { NewWin(this,'width=550','height=375'); return false; }
	}
	if(imagelink!=undefined)
	{
		imagelink.onclick = function() { return(JumpToReport()); };

		if(rpt_debug_mode())
		{
			setTimeout("if(confirm('Debugging: Auto Load Report?')) JumpToReport();",5000);
		}
		else
		{
			setTimeout(function() {JumpToReport},500);
		}
	}
	else if (top.location != location && !top.location.match(/\/rpt\//)) 
	{ 
		top.location.href = document.location.href 
	}
	if(runreport!=undefined) runreport.onclick=RunReportByNumber;

    if (window.jQuery) {  
        // jQuery is loaded  
		$('[data-toggle="popover"]').popover({
	        placement : 'right',
	        trigger : 'hover'
	    });
		
		if($("#rpt_message_new_home").length>0)
		{
			$("#dcbs_messages_container_framework").parent().addClass("rpt_wrapper");
			$("#dcbs_messages_container_framework").parent().find(".clearfix").remove();
			$("#dcbs_messages_container_framework").prependTo("#rpt_message_new_home");
		}
		
		$("#format_drop").off("change").on("change",ShowHideHeaderRow);
		$("#format_drop").off("blur").on("blur",ShowHideHeaderRow);
		$('[data-change="SelectAll"]').off("change").on("change",function() { SelectAll(this); });
    
    	$("#side-menu").after($("#ion_msg_static"));
    	$("#ion_msg_static").css("margin-top","1em");
    	$("#ion_msg_static").css("margin-left","10em");
    	$("#ion_msg_static").css("padding-left","1em");
    	$("#ion_msg_static").find("br").remove();
    
	    $("a[data-alert]").off("click").on("click",function() {
	    	alert(this.dataset.alert);
	    	return false;
	    });
	        
	    $("a[data-target]").off("click").on("click",function() {
	    	return RptWin(this.href);
	    });
    }
}

// initialize the page with or without jQuery being loaded
if (window.jQuery) 
{  
	$(document).ready(pageReady);
}
else
{
	window.onload = function() { setTimeout(pageReady,100); }
}


// prevent ping-ponging which can happen when Actuate kicks us back to the
// current page. No other pages should be impacted.
if(getCookie("rpt_load_time")==load_time)
{
	history.go(-1); // go back one more page
	// in case there is no page to go back to, jump to the home page
	setTimeout('JumpTo=""; parent.location="#request.webrooturl#"',100);
}
else
{
	setCookie("rpt_load_time",load_time,null);
}
