<% Option Explicit %>
<!--#include virtual="/adovbs.inc"-->
<!--#include file="../Connections/conn.asp"-->
<%
Function IsBlankOrNull(val)
	If IsNull(val) or val = "" Then
		IsBlankOrNull = True
	Else
		IsBlankOrNull = False
	End If
End Function

Function NullIfBlank(val)
	If val="" Then
		NullIfBlank = Null
	Else
		NullIfBlank = val
	End If
End Function
%>
<%
Dim conn
Set conn = Server.CreateObject("ADODB.Connection")
With conn
	.ConnectionString = strConn
	.CursorLocation = adUseClient
End With
conn.Open()

Dim comm, rs
Set comm=Server.CreateObject("ADODB.Command")
With comm
	.ActiveConnection = conn
	.CommandText = "calendarEventSelectScrolling"
	.CommandType = adCmdStoredProc
	.Parameters.Append( .CreateParameter ("categoryId", adInteger, adParamInput, 4, NullIfBlank(Request.QueryString("categoryId")) ) )
End With
Set rs = comm.Execute()

'Response.Write("Record Count: " & rs.RecordCount & "<br>")
'Response.End

comm.ActiveConnection = Nothing
Set comm = Nothing

%>
<%
Dim theLink
Dim scrollerContent, bNeedLineBreak
scrollerContent = ""
bNeedLineBreak = False
If rs.EOF Then
	scrollerContent = "<span class='no-events'>(No events available)</span>"
Else
	Do While Not rs.EOF
		If Not IsBlankOrNull(rs("startDate").Value) Then
			scrollerContent = scrollerContent & "<span class='event-date'>" & MonthName(Month(rs("startDate").Value)) & " " & Day(rs("startDate").Value) & ", " & Year(rs("startDate").Value) & "</span><br>"
		End If
		
		If Not IsBlankOrNull(rs("name").Value) Then
			scrollerContent = scrollerContent & "<span class='event-name'>"
		End If
		
		If Not IsBlankOrNull(rs("link").Value) Then			
			theLink = rs("link")
			If Left(theLink,7) <> "http://" Then theLink = "http://" & theLink
			scrollerContent = scrollerContent & "<a href=""" & theLink & """>"
		Else
			'
		End If	
		
		If Not IsBlankOrNull(rs("name").Value) Then
			scrollerContent = scrollerContent & rs("name").Value & "<br>"
			bNeedLineBreak = False
		Else
			bNeedLineBreak = True
		End If
		
		If Not IsBlankOrNull(rs("link").Value) Then
			scrollerContent = scrollerContent & "</a>"
		End If	
		
		If Not IsBlankOrNull(rs("name").Value) Then
			scrollerContent = scrollerContent & "</span>"
		End If
		
		If bNeedLineBreak Then 
			scrollerContent = scrollerContent & "<br>"
			bNeedLineBreak = False
		End If
		
		If Not IsBlankOrNull(rs("startDate").Value) Then
			If DatePart("H", rs("startDate").Value) = 0 Then
				'scrollerContent = scrollerContent & " <span class='event-time'>" & FormatDateTime(rs("startDate").Value,2) & "</span><br>"
			Else
				scrollerContent = scrollerContent & " <span class='event-time'>" & Replace(FormatDateTime(rs("startDate").Value,3),":00 ","") & "</span><br>"
			End If
			bNeedLineBreak = False
		Else
			bNeedLineBreak = True
		End If
		
		If Not IsBlankOrNull(rs("location").Value)  Then
			scrollerContent = scrollerContent & " <span class='event-location'>" & rs("location").Value & "</span><br>"
			bNeedLineBreak = False
		Else
			bNeedLineBreak = True
		End If
		
		If Not IsBlankOrNull(rs("description").Value)  Then
			scrollerContent = scrollerContent & " <span class='event-description'>" & Replace(rs("description"), vbcrlf, "<br>") & "</span><br>"
			bNeedLineBreak = False
		Else
			bNeedLineBreak = True
		End If
		
		scrollerContent = scrollerContent & "<a class='footer_txtCopy' href=""/calendar/calendarEventViewDay.asp?editDate=" & _
			FormatDateTime(rs("startDate"),2) & _
			"&calendarCategory=1&id=" & rs("id") & """>Details</a><br>"		
		
		If bNeedLineBreak Then 
			scrollerContent = scrollerContent & "<br>"
			bNeedLineBreak = False
		End If
		
		If Not IsBlankOrNull(rs("calendarCategoryName").Value) Then
			If CInt(Request.QueryString("categoryId")) <> CInt(rs("requestingCalendarCategoryId").Value) Then
				scrollerContent = scrollerContent & " <span class='event-origin'>(" & Replace(rs("requestingCalendarName"), vbcrlf, "<br>") & ")</span><br>"
			End If
		End If
		
		scrollerContent = scrollerContent & "<br>"
		
		rs.movenext
	Loop
	
End If

rs.Close
Set rs = Nothing
conn.Close()
Set conn = Nothing
%>
var scrollerContent=new Array()
scrollerContent.push("<%=Replace(Replace(Replace(scrollerContent, vbCrLf, "\n" ),"/","\/"),"""","\""")%>");
scrollerContent.push(scrollerContent[0]);


/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function Scroller(content, divId, divClass, delay, imgId, startImageName, stopImageName){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=1 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
this.isScrolling=false;
this.startStopButtonId = imgId;
this.startImageName = startImageName;
this.stopImageName = stopImageName;
this.startStop = function() {
	if (this.isScrolling) {
		scrollerinstance.mouseoverBol=0;
	}
	else {
		scrollerinstance.mouseoverBol=1;
	}
	this.isScrolling = !this.isScrolling;
	this.updateButtonImage();
}
this.updateButtonImage = function() {
	try {
	if (this.isScrolling) {
		document.getElementById(this.startStopButtonId).src = this.stopImageName;
	}
	else {
		document.getElementById(this.startStopButtonId).src = this.startImageName;
	} }
	catch(e) {
	}
		
}

if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize();scrollerinstance.isScrolling = true;scrollerinstance.updateButtonImage();}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize();scrollerinstance.isScrolling = true;scrollerinstance.updateButtonImage();})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize();scrollerinstance.isScrolling = true;scrollerinstance.updateButtonImage();}, 500)

}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

Scroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(Scroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){}
document.getElementById(this.tickerid).onmouseout=function(){}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}

Scroller.prototype.reinitialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(Scroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
}

// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

Scroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+1)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-(1*this.mouseoverBol)+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-(1*this.mouseoverBol)+"px"
setTimeout(function(){scrollerinstance.animateup()}, 25)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

Scroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

Scroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

Scroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==0) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 1000)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

Scroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}