/*----------------------------------------------------------------------------------------
|
|        Press Room Script by Josh Miller
|        written for City of Elmira Website
|        @ http://www.ci.elmira.ny.us
|
-------------------------------------------------------------------------------------------*/ 
<!-- Begin


byDate=1;byTitle=2;byType=3;
var preText="";

function startPresses(param, flag){
	preText=param+"&nbsp;"
	store=new Array(); counter=0;
	for (i=0; i<prdate.length; i++){
		if(prtype[i].toLowerCase()==param.toLowerCase() || param=="All"){
			store[counter]=i
			counter++
		}	
	}
	var url=document.location.toString();				//parse the url to determine the state requested
	urlLength=url.length;							
	y=url.lastIndexOf("html");				
	y=y+4;	
	var params=url.substring(y,urlLength);
	if( params==""){									//if no state, then display the next month of events
		printReleases(store, byDate, flag)
	}
	else{
		state=params.substring(1,3);				
		if (state=="sd"){								//if the state is id, then print the event with the id
			printReleases(store, byDate, flag)
		}
		else if (state=="st"){							//if the state is preview, then preview the number of days requested
			printReleases(store, byTitle, flag)
		}
		else if (state=="ty"){							//if the state is preview, then preview the number of days requested
			printReleases(store, byType, flag)
		}
		else{
			printReleases(store, byDate, flag)
		}
	}
}

function printReleases(releases, sort, flag){
	if (sort==byDate){
		releases.sort(sortPressDates)	
	}
	else if (sort==byTitle){
		releases.sort(sortTitles)
	}
	else if (sort==byType){
		releases.sort(sortTypes)
	}
	else{
		releases.sort(sortPressDates)	
	}
	document.write("<table width='95%' cellpadding='0' cellspacing='2' border='0'>")
	if (flag==1){
		document.write("<tr><td class='featureheader'><a href='index.html?sd' title='Click here to sort Press Releases by Date' class='featureheader'>Date</a></td><td class='featureheader'><a href='index.html?st' title='Click here to sort Press Releases by Title' class='featureheader'>Title</a></td><td class='featureheader'><a href='index.html?ty' title='Click here to sort Press Releases by Topic' class='featureheader'>Topic</a></td></tr>")
	}
	else{
		document.write("<tr><td colspan='3' class='subtitle'>"+preText+"Press Releases from the Press Room</td></tr>")
	}
	document.write("<tr><td colspan='3' bgcolor='#000000'><img src='../index/pics/dot.gif' height='2'></td></tr>")
	if (store.length==0){
		document.write("<tr><td>There are no press releases at this time<td></tr>")
	}

	for (i=0; i<releases.length; i++){
		document.write("<tr><td valign='top' width='80' class='smalltext'>"+formatDate(prdate[releases[i]])+"</td>")
		document.write("<td valign='top' class='smalltext'><a href='../pressroom/"+prlink[releases[i]]+"' class='release'>"+ptitle[releases[i]]+"</a></td>")
		if (flag==1){
			document.write("<td valign='top' width='100' class='smalltext'>"+prtype[releases[i]]+"</td>")	
		}
		document.write("</tr><tr><td colspan='3' bgcolor='#000000'><img src='../index/pics/dot.gif' height='1'></td></tr>")
	}
	if (releases.length!=prdate.length){
		document.write("</tr><tr><td colspan='3' class='smalltext'><a href='../pressroom/index.html'>Show All Press Releases</a></td></tr>")
	}
	document.write("</table><br>")
	websiteUpdates();
}

/***********************************************
* Portions of below functions from:
* Memory Ticker script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
function printScroller(){
	pressreleases=""
	releases=new Array(); counter=0;
	for (i=0; i<prdate.length; i++){
		releases[counter]=i
		counter++	
	}
	releases.sort(sortPressDates)	
	pressreleases=pressreleases+"<table width='100%' cellpadding='0' cellspacing='2' border='0'>"
	if (releases.length==0){
		pressreleases=pressreleases+"<tr><td>There are no press releases at this time<td></tr>"
	}
	tickercontents=new Array()
	for (i=0; i<NumberOfPressReleases; i++){
		tickercontents[i]="<img src='../index/pics/dot.gif' height='1'><br><a href='../pressroom/"+prlink[releases[i]]+"' class='presstext'><b>"+prdate[releases[i]].toLocaleDateString()+"</b><br><img src='../index/pics/dot.gif' height='2' border='0'><br>"+ptitle[releases[i]]+"</a></td></tr>"
	}
	pressreleases=pressreleases+"</table>"

	persistlastviewedmsg=1 //should messages' order persist after users navigate away (1=yes, 0=no)?
	persistmsgbehavior="onload" //set to "onload" or "onclick".

	tickdelay=4000

	divonclick=(persistlastviewedmsg && persistmsgbehavior=="onclick")? 'onClick="savelastmsg()" ' : ''
	currentmessage=0
	if (persistlastviewedmsg && persistmsgbehavior=="onload")
		window.onunload=savelastmsg
	if (document.all||document.getElementById)
		document.write('<div id="memoryticker" '+divonclick+'></div>')
	if (window.addEventListener)
		window.addEventListener("load", beginticker, false)
	else if (window.attachEvent)
		window.attachEvent("onload", beginticker)
	else if (document.all || document.getElementById)
		window.onload=beginticker
}

function printIndexPressReleases(){
	document.write("	<table border='0' cellpadding='2' cellspacing='0' width='100%'><tr>");
	document.write("	<td valign='top' align='left' width='70'><a href='../pressroom/' title='Click here for more press releases'><img src='../thumbs/pressreleases.jpg' border='0'></a></td>	");
	document.write("	<td valign='top' align='left'><a href='../pressroom/' class='featureheader' title='Click here for more press releases'>Press Releases</a><span class='featuretext'>");
	printScroller()
	document.write("	<span class ='smalltext'>&nbsp;&nbsp;&nbsp;<a href='../pressroom' title='Click here for more'>&raquo;Click here for more press releases</a></span></td></tr>");
	document.write("	<tr><td colspan='2' align='center' valign='middle'><span class='featuredivider'>- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - </span></td></tr></table>");

}

function changetickercontent(){
	if (crosstick.filters && crosstick.filters.length>0)
		crosstick.filters[0].Apply()
	crosstick.innerHTML=tickercontents[currentmessage]
	if (crosstick.filters && crosstick.filters.length>0)
		crosstick.filters[0].Play()
	currentmessage=(currentmessage==tickercontents.length-1)? currentmessage=0 : currentmessage+1
	var filterduration=(crosstick.filters&&crosstick.filters.length>0)? crosstick.filters[0].duration*1000 : 0
	setTimeout("changetickercontent()",tickdelay+filterduration)
}

function beginticker(){
	if (persistlastviewedmsg && get_cookie("lastmsgnum")!="")
		revivelastmsg()
	crosstick=document.getElementById? document.getElementById("memoryticker") : document.all.memoryticker
	changetickercontent()
}

function get_cookie(Name) {
	var search = Name + "="
	var returnvalue = ""
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		if (offset != -1) {
			offset += search.length
			end = document.cookie.indexOf(";", offset)
			if (end == -1)
				end = document.cookie.length;
				returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
}

function savelastmsg(){
	document.cookie="lastmsgnum="+currentmessage
}

function revivelastmsg(){
	currentmessage=parseInt(get_cookie("lastmsgnum"))
	currentmessage=(currentmessage==0)? tickercontents.length-1 : currentmessage-1
}

//************************************************

function formatDate(date){
	dAte=date.getDate()
	Mont=date.getMonth()
	Year=date.getYear()
	return addZero((Mont+1))+"-"+addZero(dAte)+"-"+Year
}

function addZero(x){
	if(x<10){return "0"+x}
	else{return x}
}//end addZero function

function sortPressDates(a,b){
	//pre: a and b are the indexes of dates in the date array
	it=prdate[a];that=prdate[b];	
	thisDate=it.getDate();thisMonth=it.getMonth();thisYear=it.getYear();
	thatDate=that.getDate();thatMonth=that.getMonth();thatYear=that.getYear();
	if((thisYear-thatYear)>0){return -1;}
	else if ((thisYear-thatYear)<0){return 1;}
	else{
		if ((thisMonth-thatMonth)>0){return -1;}
		else if ((thisMonth-thatMonth)<0){return 1;}
		else{if ((thisDate-thatDate)>0){return -1;}else if ((thisDate-thatDate)<0){return 1}else{return 0}}
	}
}//end sortPressDates function

function sortTitles(A,B){
	//post:	returns 1 if A is bigger than B
	//		returns -1 if A is smaller than B
	//		returns 0 if A is the same as B
	a=ptitle[A]
	b=ptitle[B]
	a=a.toLowerCase();									//set a and b to lowercase for comparison
	b=b.toLowerCase();
	result=new Array()									//store the result of the letter by letter comparison
	for (i=0; i<a.length; i++){							//for each character in the string
		if(a.charCodeAt(i)>b.charCodeAt(i)){			//if the unicode value of a is greater than b
			result[i]=1									//then store 1 in the result array
		}	//end if								
		else if (a.charCodeAt(i)<b.charCodeAt(i)){		//if the unicode value of a is less than b
			result[i]=-1								//then store -1 in the result array
		}	//end else if
		else if (a.charCodeAt(i)==b.charCodeAt(i)){		//if the unicode value of a is the same as b
			result[i]=0									//then store 0 in the result array
		}	//end else if
	}//end for loop
	g=0													//set g to 0 for a counter variable
	flag=0												//set the flag to 0 - assume they are the same word until proven otherwise
	while (flag==0 && g<result.length-1){				//while the flag proves they are still the same, and the result array has values
		test=result[g]									//assign test the value to be tested from the result array
		if(test==-1){									//if the result array is storing -1 then		
			flag=1										//change the flag
			Result=-1									//and store -1 to return to the function
		}	//end if				
		else if (test==1){								//if the result array is storing +1 then
			flag=1										//change the flag
			Result=1									//and store 1 to return to the function
		}	//end if else
		else if (test==0){								//if the result array is storing 0
			flag=0										//do not change the flag- the words may still be the same- check the rest of the result array
		}	//end if else								
		g++
	}	//end while
	if(flag==0){															//if the flag is still 0, the words are similar or the same: eg: Josh and Joshua
		if (a.length-b.length < 0){											//if the length of b is longer, then 
			Result=-1														//store -1 to return to the function
		}	//end if
		else if (b.length-a.length < 0){									//if the length of a is longer
			Result=1														//store 1 to return to the function
		}	//end else if													
		else if (a.length-b.length == 0){									//if the lengths are the same, it is the same word: eg: Josh and Josh
			Result=0														//store 0 to return to the function
		}	//end else if
	}
	return Result;															//return the stored Result to the function
}


function sortTypes(A,B){
	//post:	returns 1 if A is bigger than B
	//		returns -1 if A is smaller than B
	//		returns 0 if A is the same as B
	a=prtype[A]
	b=prtype[B]
	a=a.toLowerCase();									//set a and b to lowercase for comparison
	b=b.toLowerCase();
	result=new Array()									//store the result of the letter by letter comparison
	for (i=0; i<a.length; i++){							//for each character in the string
		if(a.charCodeAt(i)>b.charCodeAt(i)){			//if the unicode value of a is greater than b
			result[i]=1									//then store 1 in the result array
		}	//end if								
		else if (a.charCodeAt(i)<b.charCodeAt(i)){		//if the unicode value of a is less than b
			result[i]=-1								//then store -1 in the result array
		}	//end else if
		else if (a.charCodeAt(i)==b.charCodeAt(i)){		//if the unicode value of a is the same as b
			result[i]=0									//then store 0 in the result array
		}	//end else if
	}//end for loop
	g=0													//set g to 0 for a counter variable
	flag=0												//set the flag to 0 - assume they are the same word until proven otherwise
	while (flag==0 && g<result.length-1){				//while the flag proves they are still the same, and the result array has values
		test=result[g]									//assign test the value to be tested from the result array
		if(test==-1){									//if the result array is storing -1 then		
			flag=1										//change the flag
			Result=-1									//and store -1 to return to the function
		}	//end if				
		else if (test==1){								//if the result array is storing +1 then
			flag=1										//change the flag
			Result=1									//and store 1 to return to the function
		}	//end if else
		else if (test==0){								//if the result array is storing 0
			flag=0										//do not change the flag- the words may still be the same- check the rest of the result array
		}	//end if else								
		g++
	}	//end while
	if(flag==0){															//if the flag is still 0, the words are similar or the same: eg: Josh and Joshua
		if (a.length-b.length < 0){											//if the length of b is longer, then 
			Result=-1														//store -1 to return to the function
		}	//end if
		else if (b.length-a.length < 0){									//if the length of a is longer
			Result=1														//store 1 to return to the function
		}	//end else if													
		else if (a.length-b.length == 0){									//if the lengths are the same, it is the same word: eg: Josh and Josh
			Result=0														//store 0 to return to the function
		}	//end else if
	}
	return Result;															//return the stored Result to the function
}










// End -->

