
/******************************************************************************
Below code is only needed to view calendar - Code for editing at end of file
TODO: needs much more analysis; many functions at end of file used for display
******************************************************************************/
/*-----------------------------------------------------------------------------
toggle debug; called by invisible link in heading
-----------------------------------------------------------------------------*/
function setDebug(win)
{
	if (typeof win == 'undefined') win = window;

	var debugState = !RZ.debug
	if (win.confirm('Set debug ' + debugState + '?'))
	{
		RZ.debug = debugState
		win.onunload = null;
		win.location.reload()
	}

	return void(0)
}
/*-----------------------------------------------------------------------------
If reloading frame - only can be used from inside this file
-----------------------------------------------------------------------------*/
function RZisReload()
{
	if(typeof RZ == 'undefined'
	|| typeof RZ.calendar == 'undefined'
	|| typeof RZ.calendar.date == 'undefined'
	|| typeof RZ.calendar.isDataLoaded == 'undefined')
		return true
	else
		return false
}
/*-----------------------------------------------------------------------------
Soft reload of specified url in specified frame
-----------------------------------------------------------------------------*/
function RZsoftReload(frame)
{
	if (navigator.appVersion.indexOf('MSIE') != -1)	//IE
		frame.history.go(0);

	else											//NS
		frame.location.reload(true);
}
/*-----------------------------------------------------------------------------
Load frame with specified url
Note: iframe frames should not be reloaded until parent page comletes loading
-----------------------------------------------------------------------------*/
function RZloadFrame(frame,url)
{
	url = RZ.calendar.pathname + url;
	frame.location.replace(url);
}
/*-----------------------------------------------------------------------------
Clear last scheduled timeout
-----------------------------------------------------------------------------*/
function RZclearTimeout()
{
	if (typeof RZ.calendar.timeout != 'undefined'
	&& RZ.calendar.timeout != null)
		clearTimeout(RZ.calendar.timeout);
	RZ.calendar.timeout = null
}
/*-----------------------------------------------------------------------------
Calling parameters:
	url#{calendarName}{,date}{,view}

	where:
		calendarName		Name of any valid calendar
		date				any valid date
		view				-month, -week, -day, -brief, -mini

Returns:
	RZ.calendar.name
	RZ.calendar.date
	RZ.calendar.view
	updates cooresponding cookies (backward compatibility)

Note:
	Calendar cookies cleared if any parameters are specified.
-----------------------------------------------------------------------------*/
function RZcalendarParameters()
{
    var calname = ''
    var caldate = new Date();
    var calview = 'month'	//default if not iframe
    if (parent.location.href != document.location.href)
    	calview = 'brief'	//default if called from iframe

	var hash = location.hash
	if (hash.length > 0)
	{
		hash = hash.substring(1)
		if (hash.indexOf('%') != -1) hash = unescape(hash);
	}
	if (hash.substr(0,1) == ',')
		hash = hash.substr(1);

	//----- Check for view
	var pos = hash.lastIndexOf('-')
	if (pos != -1)
	{
		var opt = hash.substring(pos+1).toLowerCase()
		switch (opt)
		{
			case 'month':
			case 'week':
			case 'day':
			case 'brief':
			case 'mini':
				calview = opt;
				hash = hash.substring(0,pos)
				break;
			default:
		}
	}

	//----- String trailing blanks and/or commas
	while (hash.length > 0
	&& (hash.substring(hash.length-1)==' '
	||  hash.substring(hash.length-1)==','))
		hash = hash.substring(0,hash.length-1)

	//----- Check for date
	//dave, feb 2, 1999
	//10-22-1998
	//feb 28, 1999

    pos = hash.indexOf(',');
    if (pos == -1) pos = hash.lastIndexOf(' ');
    if (pos != -1)
    {
		// if 2nd comma or date is valid after 1st comma
		if ( hash.indexOf(',',pos+1) != -1
		|| !isNaN(Date.parse(replace(hash,'-','/').substring(pos))) )
		{
			calname = hash.substring(0,pos);
			caldate = hash.substring(pos+1);
		}
		//	is hash is valid date using first comma
		else if ( !isNaN(Date.parse(replace(hash,'-','/'))) )
		{
			calname = ''		//no name
			caldate = hash;		//have date
		}
		else
		{
			calname = hash
			caldate = new Date()
		}
	}
	else if ( !isNaN(Date.parse(replace(hash,'-','/'))) )
	{
		caldate = hash;		//have date
	}
	else
	{
		calname = hash;		//have name
	}

	caldate = new Date(replace(caldate,'-','/'));
	if ( isNaN(caldate) )
		caldate = new Date();

	//----- See if only specified calendar is allowed
	if (calname.indexOf('*') == 0)
	{
		calname = calname.substring(1);
		RZ.calendar.exclusive = calname;
	}

	//----- Save specified calender name, date and view
	RZ.calendar.name = RZrestoreName(calname);
	RZ.calendar.date = caldate;
	RZ.calendar.view = calview;
}

/*-----------------------------------------------------------------------------
Checks if the given month in given year active in javaScript Database
Month ranges from 1 to 12; year is 4 digit year
-----------------------------------------------------------------------------*/
function RZis_activemonth(month, year)
{
	toRet = false;
	if ( ( typeof RZ != 'undefined' )
	&& ( typeof RZ.calendar != 'undefined' )
	&& ( typeof RZ.calendar.months != 'undefined' )
	&& ( typeof RZ.calendar.months[month] != 'undefined' )
	&& ( typeof RZ.calendar.months[month].years != 'undefined' ) )
	{
		var numElems = RZ.calendar.months[month].years.length;
		for ( var i = 0; i < numElems; i++ )
		{
			if ( ( typeof RZ.calendar.months[month].years[i] != 'undefined' )
				&& ( year == RZ.calendar.months[month].years[i].year ) )
			{
				toRet = true;
				break;
			}
		}
	}
	return toRet;
}

/*-----------------------------------------------------------------------------
Adds a new object to the calendar, month , year tree from javaScript DB
Month ranges from 1 to 12; year is 4 digit year
-----------------------------------------------------------------------------*/
function RZactivemonth_add(month,year)
{
	//----- Create months and months[month] object
	if (typeof RZ.calendar.months == 'undefined') RZ.calendar.months = new Object();
	if (typeof RZ.calendar.months[month] == 'undefined') RZ.calendar.months[month] = new Object();

	//----- Determine next year index
	//		(if necessary, create RZ.calendar.months[month].years)
	var yrIdx = 0;
	if (typeof RZ.calendar.months[month].years == 'undefined')
		RZ.calendar.months[month].years = new Array();
	else
		yrIdx = RZ.calendar.months[month].years.length;

	//----- Create new event object and set year
	RZ.calendar.months[month].years[yrIdx] = new Object();
	RZ.calendar.months[month].years[yrIdx].year = year;

	return;
}
/*-----------------------------------------------------------------------------
Used for getting the active month file name,
that is to be included depending on the calendar name
-----------------------------------------------------------------------------*/
function RZgetActiveMonthListFileName( calendarName )
{
	if ( null == calendarName || "" == calendarName )
		return null;

	var calid = RZ.calendar.ids[calendarName.toLowerCase()]
	return ("calendar_" + calid + "_activemonths.html")
}

/*-----------------------------------------------------------------------------
Used for getting the active month file name also based on the calendar name.
month ranges from 1 to 12; year is 4 digit year
-----------------------------------------------------------------------------*/
function RZgetActiveMonthDataFileName( calendarName, year, month )
{
	if (null == calendarName || "" == calendarName)
		return null;

	else if (null == year)
		return null;

	else if (null == month || month < 1 || month > 12)
		return null;

	var monthStr = (month).toString()
	if (monthStr.length == 1)
		monthStr = '0' + monthStr;

	var calid = RZ.calendar.ids[calendarName.toLowerCase()]
	var filename = "calendar_" + calid
				 + "_activemonthsdata_"
				 + year + '-' + monthStr + ".html";

	return filename;
}
/*-----------------------------------------------------------------------------
Return number of events for specified day
days (optional): either RZ.calendar.days (default) or RZ.calendar.daysNext
-----------------------------------------------------------------------------*/
function RZevent_count(day,days)
{
	if (RZ.calendar)
	{
		if (!days) days = RZ.calendar.days
		if (days && days[day] && days[day].events)
			return days[day].events.length;
	}
	return 0;
}
/*-----------------------------------------------------------------------------
Return specified event for specified day for active months
used in javaScript Database
days (optional): either RZ.calendar.days (default) or RZ.calendar.daysNext
-----------------------------------------------------------------------------*/
function RZevent_get(day,eventIdx,days)
{
	if (RZ.calendar)
	{
		if (!days) days = RZ.calendar.days
		if (days && days[day] && days[day].events)
			return days[day].events[eventIdx];
	}
	return null;
}
/*-----------------------------------------------------------------------------
Return mixed case calendar name
-----------------------------------------------------------------------------*/
function RZcalendarName(calname)
{
	if (RZisReload()) return '';

	if (typeof calname == 'undefined')
		calname = RZ.calendar.name;

	if (calname != '')
	{
		var calid = RZ.calendar.ids[calname.toLowerCase()];
		calname = RZ.calendar.names[calid];
	}

	return calname;
}
/*-----------------------------------------------------------------------------
Restore calendar name after reading from cookie or url
-----------------------------------------------------------------------------*/
function RZrestoreName(filename)
{
	filename = replace(filename,'%20',' ')
	filename = replace(filename,'&sqout',"'")
	return filename;
}
/*-----------------------------------------------------------------------------
Restore calendar name after reading from cookie or url
-----------------------------------------------------------------------------*/
function replace( inStr, fromString, toString )
{
	var pos = 0
	if (inStr == null
	|| typeof inStr.length == 'undefined' //true or false
	|| inStr.length == 0) return '';

	var fromLen = fromString.length
	if (fromLen == 0) return inStr

	while (true)
	{
		pos = inStr.indexOf(fromString,pos)
		if (pos == -1) break
		inStr = RZsubstring( inStr, 0, pos )
		      + toString
		      + RZsubstring( inStr, pos + fromLen )
		pos += toString.length
	}
	return inStr
}
/*-----------------------------------------------------------------------------
Returns day of week
-----------------------------------------------------------------------------*/
function RZdayName(date)
{
	var days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	return days[ date.getDay() ];
}
/*-----------------------------------------------------------------------------
Returns month of year
-----------------------------------------------------------------------------*/
function RZmonthName(date)
{
	var months = new Array('January','February','March','April','May','June',
	                       'July','August','September','October','November','December');
	return months[ date.getMonth() ];
}
/*-----------------------------------------------------------------------------
Returns day with suffix: e.g. 1st, 2nd, 3rd, 4th, etc.
-----------------------------------------------------------------------------*/
function RZdaySuffix(date)
{
    var suffix = ''
    var day = date.getDate();
    if (day == 1 || day == 21 || day == 31)
    	suffix = 'st';
    else if (day == 2 || day == 22)
    	suffix = 'nd';
    else if (day == 3 || day == 23)
    	suffix = 'rd';
    else
    	suffix = 'th';
    return day + suffix;
}
/*-----------------------------------------------------------------------------
method to convert the military time to am and pm, put space at end if not blank
-----------------------------------------------------------------------------*/
function RZgetTimeInAmPmSpace(time)
{
	var returnValue = RZgetTimeInAmPm(time);
	if (returnValue != '')
		returnValue += ' '
	return returnValue
}
/*-----------------------------------------------------------------------------
method to convert the military time to am and pm
-----------------------------------------------------------------------------*/

function RZgetTimeInAmPm(time)
{

	if (time == '' || time == ':')
		return '';

	var inParts = time.split(":");
	var am_pm;
	if(inParts[0] =='0')
	{
		am_pm = " am";
		inParts[0] = '12'
		return (inParts[0] + ":" + inParts[1] + am_pm);
	}
	if(inParts[0] =='1' || inParts[0] =='2' || inParts[0] =='3' || inParts[0] =='4' || inParts[0] =='5'
	|| inParts[0] =='6' || inParts[0] =='7' || inParts[0] =='8' || inParts[0] =='9' || inParts[0] =='10'
	|| inParts[0] =='11'||inParts[0] =='12' )
	{
		am_pm = " am";
		if(inParts[0] =='12')
			am_pm = " pm";
		return (inParts[0] + ":" + inParts[1] + am_pm);
	}
	else
	{
		am_pm = " pm";
	}
	if(inParts[0] =='13')
		inParts[0] = '1'
	if(inParts[0] =='14')
		inParts[0] = '2'
	if(inParts[0] =='15')
		inParts[0] = '3'
	if(inParts[0] =='16')
		inParts[0] = '4'
	if(inParts[0] =='17')
		inParts[0] = '5'
	if(inParts[0] =='18')
		inParts[0] = '6'
	if(inParts[0] =='19')
		inParts[0] = '7'
	if(inParts[0] =='20')
		inParts[0] = '8'
	if(inParts[0] =='21')
		inParts[0] = '9'
	if(inParts[0] =='22')
		inParts[0] = '10'
	if(inParts[0] =='23')
		inParts[0] = '11'

	return (inParts[0] + ":" + inParts[1] + am_pm);
}
/******************************************************************************
Above code is only needed to view mini? calendar - remainder needed for editing
******************************************************************************/
/**	calendar_app.js
 *  JavaScript Library used for Calendar Application
 *
 *  $Author:   mindfire  $
 */

/*-----------------------------------------------------------------------------
Define RZ object and variables usually defined in jsp headers
-----------------------------------------------------------------------------*/
if (typeof RZ == 'undefined') var RZ = new Object();
if (typeof RZ.calendar == 'undefined') RZ.calendar = new Object();
if (typeof RZ.calendar.name == 'undefined') RZ.calendar.name = "";
if (typeof RZ.calendar.group == 'undefined') RZ.calendar.group = "";
if (typeof RZ.calendar.view == 'undefined') RZ.calendar.view = "";
if (typeof RZ.calendar.viewdate == 'undefined') RZ.calendar.viewdate = null;
if (typeof RZ.calendar.debug == 'undefined') RZ.calendar.debug = false;

/*-----------------------------------------------------------------------------
Define RZ authentication variables set/used in various files across application
-----------------------------------------------------------------------------*/
// credentials for all defined calendars
if (typeof RZ.calendar.credentials == 'undefined') RZ.calendar.credentials = new Array();

// credentials for current calendar being displayed
if (typeof RZ.calendar.user == 'undefined') RZ.calendar.user = "";
if (typeof RZ.calendar.roles == 'undefined') RZ.calendar.roles = "";
if (typeof RZ.calendar.administrators == 'undefined') RZ.calendar.administrators = "";
if (typeof RZ.calendar.editors == 'undefined') RZ.calendar.editors = "";
if (typeof RZ.calendar.rolluplist == 'undefined') RZ.calendar.rolluplist = "";

/*-----------------------------------------------------------------------------
Define variables commonly used in Calendar Application
-----------------------------------------------------------------------------*/

//the day number in order of display in weekview
var RZweekDayArray = ["1","4","2","5","3","6","7"];

//set for time not defined
var RZblankTime = 100;

//set for the time delay in the calendar heading

var RZtimeOut = 1000;

//set for the time delay for the notable event display
var RZtimeOut_notable = 1500;

//set for the time delay the display of the main bodies
var RZtimeOut_main = 1000;

var RZcount = 0;

//set to default start hour
var RZdefaultStartTimeHour = 8;

//month array used in HTML for all the views
var RZmonthNameArr = ["January", "February", "March", "April", "May", "June",
						"July", "August", "September", "October", "November", "December"];

var RZmonthArray = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];

//time array to get the time in the day view
var RZtimeArr = ["12","1","2","3","4","5","6","7","8","9","10","11","12","1",
				"2","3","4","5","6","7","8","9","10","11"];

// day array to get the day name
var RZdayArr = ["", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];

// variable which sets the summary length
var RZsummaryLength = 30;

//variable which represents a blank when entered in the url
var RZcharSpace = "%20";

//variable that specifies the minimum duration
var RZminDuration = 15;

/*-----------------------------------------------------------------------------
Function Block - Active Months
-----------------------------------------------------------------------------*/
function addRZcharSpace(file_name)
{
	var new_file="";
	for(var u=0;u<file_name.length;u++)	{
		if(file_name.charAt(u) == ' ') {
			new_file += RZcharSpace;
		} else {
			new_file += file_name.charAt(u);
		}
	}
	return new_file;
}

/*-----------------------------------------------------------------------------
Function to deselect a list on the basis of
"-Select-", "-Roles-" and "-Users-" option
-----------------------------------------------------------------------------*/
function deselectValue(formList)
{
	for (var i = 0; i < formList.length; i++)
	{
		if (formList.options[i].text == "-Select-"
		|| formList.options[i].text == "-Users-"
		|| formList.options[i].text == "-Roles-")
		{
			formList.options[i].selected = false;
		}
	}
}

/*-----------------------------------------------------------------------------
Function which checks whether the date is same
-----------------------------------------------------------------------------*/
function checkForSameDate (date1, date2 )
{
	if (date1.getDate() == date2.getDate()
	&& date1.getMonth() == date2.getMonth()
	&& date1.getFullYear() == date2.getFullYear())
		return true;
	else
		return false;
}
/*-----------------------------------------------------------------------------
Function to popup the event details
-----------------------------------------------------------------------------*/
function RZpopupEventDetail(eventid, show_event)
{

	var eventurl = "../calendar_view_common/calendar_event_detail.html#"
				+ eventid + "#" + show_event;
	RZ.calendar.eventwindow = RZpopupUrl('Events',eventurl,'600','500','');
	window.focus()
}

/*-----------------------------------------------------------------------------
Function to popup the signup form

Input Arguments:
coordinator_email-		email address of event coordinator
supervisor_approval-	'yes' if supervisor approval is required
-----------------------------------------------------------------------------*/
function RZpopupSignupDetail(coordinator_email, supervisor_approval, eventid, date)
{
	//----- Calculate absolute url reference (allows call from any frame)
	var url = location.href;
	var pos = url.indexOf('#')
	if (pos != -1)
		url = url.substring(0,pos)
	url = url.substring(0,url.lastIndexOf("/"))

	url += "/calendar_view_common/calendar_main_signup.html";

	RZ.calendar.coordinator_email = coordinator_email;
	RZ.calendar.supervisor_approval = supervisor_approval;
	RZ.calendar.eventId = eventid;
	RZ.calendar.date = date;
	RZ.calendar.signupwin = RZpopupUrl('RZsignup', url, '520', '500', 'no');
	return void(0);		//for href value
}
/*-----------------------------------------------------------------------------
Function to parse the path to get the webspace path
-----------------------------------------------------------------------------*/
function parse_path(pathname)
{
	var c = 0;
	var signpath = "";
	for ( i=0; i<pathname.length ;i++)
	{
		signpath += pathname.charAt(i);
		if ( pathname.charAt(i) == '/' )
			c++;

		if (c == 2 )
		{
			i++;
			while ( i != pathname.length && pathname.charAt(i) != '/' )
			{
				signpath += pathname.charAt(i);
				i++;
			}
			break;
		}
	}
	return signpath;
}

/*-----------------------------------------------------------------------------
Create & return new event object for specified day of month
used in javaScript Database
-----------------------------------------------------------------------------*/
function RZevent_addMonth(inDate)
{
	var dateObj = null;
	dateObj = new Date(inDate);

	return RZevent_add(dateObj.getDate());
}

/*-----------------------------------------------------------------------------
Create & return new event object for specified day of month
used in javaScript Database
-----------------------------------------------------------------------------*/
function RZevent_add(day)
{
	var dayObj = !RZ.calendar.isNextMonthDataLoaded ? 'days' : 'daysNext';

	//----- Create days and days[day] object
	if (typeof RZ.calendar[dayObj] == 'undefined')
		RZ.calendar[dayObj] = new Object();

	if (typeof RZ.calendar.days[day] == 'undefined')
		RZ.calendar[dayObj][day] = new Object();

	//----- Determine next event index (if necessary, create RZ.calendar.days[day].events)
	var eventIdx = 0;
	if ( typeof RZ.calendar[dayObj][day].events == 'undefined')
		RZ.calendar[dayObj][day].events = new Array();
	else
		eventIdx = RZ.calendar[dayObj][day].events.length;

	//----- Create new event object
	RZ.calendar[dayObj][day].events[eventIdx] = new Object();
	return RZ.calendar[dayObj][day].events[eventIdx];
}


/*-----------------------------------------------------------------------------
Returns array of years for the calendar.
used in Calendra Header, fetched from javascript database
-----------------------------------------------------------------------------*/
function RZgetAllYears()
{
	var arr = new Array();
	var flag = false;
	var numElems, i, j, year;

	if ( typeof RZ != 'undefined'
	&& typeof RZ.calendar != 'undefined'
	&& typeof RZ.calendar.months != 'undefined')
	{
		for (var month = 0; month < 12; month++) {
			if ( ( typeof RZ.calendar.months[month] != 'undefined' )
				&& ( typeof RZ.calendar.months[month].years != 'undefined' ) )
			{
				numElems = RZ.calendar.months[month].years.length;
				for ( i = 0; i < numElems; i++ ) {
					if ( typeof RZ.calendar.months[month].years[i] != 'undefined' )	{
						year = RZ.calendar.months[month].years[i].year;
						for ( j = 0; j < arr.length; j++ ) {
							if ( arr[j] == year ) {
								flag = true;
								break;
							}
						}
						if ( false == flag ) {
						//this implies year doesn't already exist.
						//so insert in the array arr
							arr[arr.length] = year;
						} else {
							flag = false;
						}
					}
				}
			}
		}
	}
	return arr;
}

/*-----------------------------------------------------------------------------
Function Block - Active Weeks
-----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
Function to find the weekdate and the file name
-----------------------------------------------------------------------------*/
function RZgetWeekDate(day)
{
	//RETRIEVING THE DATE
	var wdate = RZgetDateForView( RZ.calendar.date );

	//CALLING THE FUNCTION TO FIND THE DATE AND MONTH
	var RZweekDate = RZgetCurrentDate(wdate, day);
	weekDate = new Date( RZweekDate.getFullYear(), RZweekDate.getMonth(),
						RZweekDate.getDate());

	//RETRIEVING THE WEEK NUMBER
	var RZyearWeek = weekNumber_local(RZweekDate);
	return weekDate;
}

/*-----------------------------------------------------------------------------
Return specified event for specified day[1 - 7 for Mon - Sun]  for active weeks
used in javaScript Database
-----------------------------------------------------------------------------*/
function RZeventfromweek_get(day,eventIdx)
{
	if ( typeof RZ.calendar != 'undefined'
	&& typeof RZ.calendar.weekdays != 'undefined'
	&& typeof RZ.calendar.weekdays[day] != 'undefined'
	&& typeof RZ.calendar.weekdays[day].events != 'undefined'
	&& typeof RZ.calendar.weekdays[day].events[eventIdx] != 'undefined')
		return RZ.calendar.weekdays[day].events[eventIdx];
	 else
		return null;
}

/*-----------------------------------------------------------------------------
Create & return new event object for specified day[1 - 7 for Mon - Sun] of week
used in javaScript Database
-----------------------------------------------------------------------------*/
function RZevent_addWeek(inDate)
{
	var dateObj = null;
	var dayNo;

	dateObj = new Date(inDate);
	dayNo = dateObj.getDay();
	if ( 0 == dayNo ) dayNo = 7;

	return RZeventtoweek_add(dayNo);
}

/*-----------------------------------------------------------------------------
Create & return new event object for specified day[1 - 7 for Mon - Sun] of week
used in javaScript Database
-----------------------------------------------------------------------------*/
function RZeventtoweek_add(day)
{
	//----- Create weekdays and weekdays[day] object
	if (typeof RZ.calendar.weekdays == 'undefined')
		RZ.calendar.weekdays = new Object();

	if (typeof RZ.calendar.weekdays[day] == 'undefined')
		RZ.calendar.weekdays[day] = new Object();

	//----- Determine next event index (if necessary, create RZ.calendar.weekdays[day].events)
	var eventIdx = 0;
	if ( typeof RZ.calendar.weekdays[day].events == 'undefined')
		RZ.calendar.weekdays[day].events = new Array();
	else
		eventIdx = RZ.calendar.weekdays[day].events.length;

	//----- Create new event object
	RZ.calendar.weekdays[day].events[eventIdx] = new Object();
	return RZ.calendar.weekdays[day].events[eventIdx];
}

/*-----------------------------------------------------------------------------
Used for getting the active week file name,
that is to be included depending on the calendar name
-----------------------------------------------------------------------------*/
function RZgetActiveWeekListFileName( calendarName )
{
	if ( null == calendarName || "" == calendarName )
		return null;

	var calid = RZ.calendar.ids[calendarName.toLowerCase()]
	return ("calendar_" + calid + "_activeweeks.html")
}

/*-----------------------------------------------------------------------------
Used for getting the active week's data file name,
that is to be included depending on the calendar name
-----------------------------------------------------------------------------*/
function RZgetActiveWeekDataFileName( calendarName, year, yearweek )
{
	if (null == calendarName || "" == calendarName)
		return null;

	else if (null == year)
		return null;

	else if (null == yearweek || 1 > yearweek || 53 < yearweek)
		return null;

	//----- Published filenames can not contain single quote
	calendarName = replace(calendarName,"'","_");

	var yearweekStr = yearweek.toString()
	if (yearweekStr.length == 1)
		yearweekStr = '0' + yearweekStr;

	var calid = RZ.calendar.ids[calendarName.toLowerCase()]
	var filename = "calendar_" + calid
				 + "_activeweeksdata_"
				 + year + '-' + yearweek + ".html";

	return filename;
}

/*-----------------------------------------------------------------------------
Checks if the given week in given year active in javaScript Database
-----------------------------------------------------------------------------*/
function RZis_activeweek(yearweek, year)
{
	toRet = false;
	if ( ( typeof RZ.calendar != 'undefined' )
	&& ( typeof RZ.calendar.yearweeks != 'undefined' )
	&& ( typeof RZ.calendar.yearweeks[yearweek] != 'undefined' )
	&& ( typeof RZ.calendar.yearweeks[yearweek].years != 'undefined' ) )
	{
		var numElems = RZ.calendar.yearweeks[yearweek].years.length;
		for ( var i = 0; i < numElems; i++ )
		{
			if ( ( typeof RZ.calendar.yearweeks[yearweek].years[i] != 'undefined' )
			&& ( year == RZ.calendar.yearweeks[yearweek].years[i].year ) )
			{
				toRet = true;
				break;
			}
		}
	}
	return toRet;
}

/*-----------------------------------------------------------------------------
Adds a new object to the calendar, yearweek , year tree from javaScript DB
-----------------------------------------------------------------------------*/
function RZactiveweek_add(yearweek,year)
{
	//----- Create yearweeks and yearweeks[yearweek] object
	if (typeof RZ.calendar.yearweeks == 'undefined')
		RZ.calendar.yearweeks = new Object();

	if (typeof RZ.calendar.yearweeks[yearweek] == 'undefined')
		RZ.calendar.yearweeks[yearweek] = new Object();

	//----- Determine next year index
	// (if necessary, create RZ.calendar.yearweeks[yearweek].years)
	var yrIdx = 0;
	if (typeof RZ.calendar.yearweeks[yearweek].years == 'undefined')
		RZ.calendar.yearweeks[yearweek].years = new Array();
	else
		yrIdx = RZ.calendar.yearweeks[yearweek].years.length;

	//----- Create new event object
	RZ.calendar.yearweeks[yearweek].years[yrIdx] = new Object();
	RZ.calendar.yearweeks[yearweek].years[yrIdx].year = year;

	return;
}


/*-----------------------------------------------------------------------------
General Function Block
-----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
Returns current date if cookie is not set
-----------------------------------------------------------------------------*/
function RZgetDateForView( date )
{
	if ( "" == date )
		date = new Date();
	else
		date = new Date(date);
		if ( isNaN(date) ) date = new Date();

	return date;
}

/*-----------------------------------------------------------------------------
Function to sort Array
-----------------------------------------------------------------------------*/
function RZsortArray(inArr)
{
	if ( null == inArr ) return null;

	var temp, i, j, k;

	for ( i = 0; i <= (inArr.length - 2); i++ )
	{
		for ( j = i+1; j <= (inArr.length - 1); j++ )
		{
			if ( inArr[i] > inArr[j] )
			{
				temp = inArr[i];
				inArr[i] = inArr[j];
				inArr[j] = temp;
			}
		}
	}
	return inArr;
}

/*-----------------------------------------------------------------------------
Function to check if input string is numeric or not
-----------------------------------------------------------------------------*/
function RZisNumeric(strVal)
{
	var ch;
	for (var n = strVal.length - 1; n >= 0; n--)
	{
		ch = strVal.charAt (n);
		if ( !( ch>='0' && ch<='9' ) )
			return false;
	}
	return true;
}

/*-----------------------------------------------------------------------------
Function to check if input string is alphanumeric or not
-----------------------------------------------------------------------------*/
function RZisAlphaNumeric(strVal)
{
	var ch;
	for (var n = strVal.length - 1; n >= 0; n--)
	{
		ch = strVal.charAt (n);
		if (!( ( ch>='a' && ch<='z' )
		|| ( ch>='A' && ch<='Z' )
		|| ( ch>='0' && ch<='9' )))
		{
			return false;
		}
	}
	return true;
}

/*-----------------------------------------------------------------------------
Function to check if input character is digit or not
-----------------------------------------------------------------------------*/
function RZisDigit (ch)
{
	if ( ch>='0' && ch<='9' )
		return true;
	else
		return false;
}

/*-----------------------------------------------------------------------------
used in the weekview to view the dates and day name
gets the currentdate and month
------------------------------------------------------------------------------*/
function RZgetCurrentDate(RZdate, RZday)
{
	var RZcurrentDay = RZdate.getDay();

	// CHANGING THE CURRENT DAY TO 7 FOR SUNDAY
	if (RZcurrentDay == 0)
		RZcurrentDay = 7;

	// GETTING THE CURRENT DATE, MONTH, YEAR
	var RZcurrentDate  = RZdate.getDate();
	var RZcurrentMonth = RZdate.getMonth();
	var RZcurrentYear  = RZdate.getFullYear();

	// FIND THE TOTAL DAYS IN A MONTH
	var RZtotalDays = getDaysInMonth_local(RZcurrentMonth, RZcurrentYear);

	if (RZday < RZcurrentDay)
	{
		RZcurrentDate = RZcurrentDate - (RZcurrentDay - RZday) ;
		if (RZcurrentDate <= 0)
		{
			RZcurrentMonth = RZcurrentMonth - 1;
			// CHECKING IF MONTH IS IN PREVIOUS YEAR
			if (RZcurrentMonth < 0)
			{
				RZcurrentMonth = 11;
				RZcurrentYear = RZcurrentYear - 1;
			}
			RZtotalDays = getDaysInMonth_local(RZcurrentMonth, RZcurrentYear);
			RZcurrentDate = RZcurrentDate + RZtotalDays;
		}
	}
	else if (RZday > RZcurrentDay)
	{
		RZcurrentDate = RZcurrentDate + ( RZday - RZcurrentDay);
		if (RZcurrentDate > RZtotalDays)
		{
			RZcurrentMonth = RZcurrentMonth + 1;
			//CHECKING IF MONTH IS IN NEXT YEAR
			if (RZcurrentMonth > 11)
			{
				RZcurrentMonth = 0;
				RZcurrentYear = RZcurrentYear + 1;
			}
			RZcurrentDate = RZcurrentDate - RZtotalDays;
		}
	}
	var RZDate = new Date(RZcurrentYear, RZcurrentMonth, RZcurrentDate);
	return RZDate;
}

/*-----------------------------------------------------------------------------
Function to get the hours
-----------------------------------------------------------------------------*/
function RZgetHrs(name)
{
	var hrsList = "<select name = '"+name+"' onChange='setStartHour()'>"

	for ( i = 0; i < 24; i++ )
	{
		if ( i == RZdefaultStartTimeHour )
			hrsList += "<option selected>";
		else
			hrsList += "<option>";

		hrsList += i + "</option>";
	}
	hrsList += "</select>";
	return hrsList;
}

/*-----------------------------------------------------------------------------
Function which validates the phone number
check if phone number is in the format (XXX) XXX-XXXX
-----------------------------------------------------------------------------*/
function checkPhoneNumber(phonenumber)
{

/* +--+ Phone no. format is changed

	var i;
	var phone = phonenumber.value;
	var lenPhone = phone.length;

	//if phone not available than no check
	if ( 0 == lenPhone ) return true;


	//if phone number only has blank spaces than error
	phone = RZtrim(phone);
	lenPhone = phone.length;
	if ( 0 == lenPhone ) return false;

	//if phone is lesser then the expected length than error
	if ( 11 > lenPhone ) return false;
	//if 1st char is not "(" than error
	if ( "(" != phone.charAt(0) ) return false;

	//next 3 chars must be digits if not error
	for ( i = 1; i < 4; i++ ) {
		if ( ! RZisDigit(phone.charAt(i) ) ) return false;
	}

	//next 2 chars must be ") " if not error
	if ( ( ")" != phone.charAt(4) ) || ( " " != phone.charAt(5) ) ) return false;

	//next 3 chars must be digits if not error
	for ( i = 6; i < 9; i++ ) {
		if ( ! RZisDigit(phone.charAt(i) ) ) return false;
	}

	//next char must be "-" if not error
	if ( "-" != phone.charAt(9) ) return false;

	//rest of the chars must be digits if not error
	for ( i = 10; i < lenPhone; i++ ) {
		if ( ! RZisDigit(phone.charAt(i) ) ) return false;
	}
	for ( i = 0; i < lenPhone; i++ ) {
		if ( ! RZisDigit(phone.charAt(i) ) ) return false;
	}
*/

	return true; //every thing is fine.

}

/*-----------------------------------------------------------------------------
Function which validates the phone number
check if phone number is in the format (XXX) XXX-XXXX
-----------------------------------------------------------------------------*/
function checkPhone(phoneNo)
{

return true;
/* no validation for phone no.
	if (phoneNo.value == '') return true;

	var phoneRE = /^\(*\d{3}\)*\s*\d{3}-*\d{4}$/;
	if (phoneNo.value.match(phoneRE)) {
		return true;
	} else {
		return false;
	}
*/
}

/*-----------------------------------------------------------------------------
Function which checks the validation of email
-----------------------------------------------------------------------------*/
function checkEmail(email_value)
{
	var i =0;
	var k;
	var email = email_value;

	if (email != '') {
		// FIRST AND LAST CHARACTER SHOULD NOT BE "@"
		if(email.charAt(0) == '@' || email.charAt(email.length-1)=='@')	{
			return false;
		}
		k = email.indexOf("@",i);
		if ( k < 0)	{
			return false;
		}
		i = k+1;
		k = email.indexOf("@",i);
		if (k > 0) {
			return false;
		}

		//SHOULD CONTAIN ONLY CHARS BETWEEN a-z, A-Z , 0-9, '-', '_', '.'
		for (var n = email.length - 1; n >= 0; n--)	{
			ch = email.charAt (n);
			if (!( ( ch>='a' && ch<='z' ) || ( ch>='A' && ch<='Z' )
				|| ( ch>='0' && ch<='9' ) || ( ch == '.' )
				|| ( ch == '-' ) || (ch == '_') || ( ch == '@' ) ))
		    	{
					return false;
		      	}
		 }
	}
	return true;

}

/*-----------------------------------------------------------------------------
Function to check the uniqueness of the calendar name
-----------------------------------------------------------------------------*/
function checkUniqueValue(cArr, cvalue)
{
	if ( typeof cArr != 'undefined')
	{
		for (u2 = 0; u2 < cArr.length; u2++)
		{
			if (cvalue == cArr[u2]) return false;
		}
	}
	return true;
}

/*-----------------------------------------------------------------------------
Function to retrieve the start time in minutes (input is X:XX)
-----------------------------------------------------------------------------*/
function RZgetTimeInMinutes(mvalue)
{
	var first=0;
	var second=0;
	var totalTime = 0;
	var timeIndex;

	if (mvalue != '')
	{
		timeIndex = mvalue.indexOf(":");
		first = mvalue.substring(0,timeIndex);
		second = mvalue.substring(timeIndex+1, mvalue.length);
		totalTime = (first * 60) + (second * 1);
	}
	else
		totalTime = 0;

	return totalTime;
}

/*-----------------------------------------------------------------------------
Function to display the error messages
-----------------------------------------------------------------------------*/
function RZfieldError (theField, errorMsg, win)
{
	if (typeof win == 'undefined') win = window;

	theField.focus()
	theField.select()
	win.alert(errorMsg)
	return false
}


/*-----------------------------------------------------------------------------
Function to replace the %20 string with blank
-----------------------------------------------------------------------------*/
function replaceSpace(filename)
{
	return replace(filename,'20%',' ');
}

/*-----------------------------------------------------------------------------
Function to remove starting "--"
-----------------------------------------------------------------------------*/
function removeStartHyphen( inStr )
{
	if ( 0 == inStr.indexOf("--") )
		inStr = inStr.substring(2);

	return(inStr);
}

/*-----------------------------------------------------------------------------
Function to get values of "show_all" and "restricted_calendar_list"
of current calendar from calendar_heading page.
It is used by body files of 3 views

Returns inArr with the following values:
	1st element contains "showall"
	2nd element contains "restrictedlist"
-----------------------------------------------------------------------------*/
function RZgetParamsOfCurrentCalendar(inArr, inCalId)
{
	var i,selObj,optObj
	inArr[0] = '';
	inArr[1] = '';

	while (true)
	{
		if (RZisReload()) break;	//if top frame reloading
		if (typeof topframe.mainFrame == 'undefined') break;
		if (typeof topframe.mainFrame.headerFrame == 'undefined') break;
		var headerFrame = topframe.mainFrame.headerFrame;

		if (typeof headerFrame.document.calendar_heading == 'undefined') break;
		if (typeof headerFrame.document.calendar_heading.calendarName == 'undefined') break;
		selObj = headerFrame.document.calendar_heading.calendarName;
		if (typeof selObj.length == 'undefined') break;

		for ( i = 0; i < selObj.length; i++ )
		{
			optObj = selObj.options[i];
			if (inCalId == optObj.value)
			{
				inArr[0] = topframe.RZ.calendar.credentials[inCalId].showall;
				inArr[1] = topframe.RZ.calendar.credentials[inCalId].restrictedlist;
				break;
			}
		}
		inArr[1] = "|" + inArr[1] + "|";
		break;
	}

	return inArr;
}

/*-----------------------------------------------------------------------------
Function which finds the calendar name the event belongs to based on the
calendar id
-----------------------------------------------------------------------------*/
function RZgetCalendarNameForEvent(id)
{
	return RZ.calendar.names[id];

/*	Old method
	var optionId;
	var RZcalendar_name = "";

	if(RZwinaccess(parent)
	&& RZwinaccess (parent.parent)
	&& RZwinaccess(parent.parent.mainFrame))
	{
		if(parent.parent.mainFrame.document.calendar_heading != null
		&& parent.parent.mainFrame.document.calendar_heading.calendarName != null
		&& typeof parent.parent.mainFrame.document.calendar_heading.calendarName == 'object')
		{
			var selObj = "";
			selObj = parent.parent.mainFrame.document.calendar_heading.calendarName;

			for ( var i = 0; i < selObj.length; i++ )
			{
				optionId = selObj.options[i].value;

				if ( optionId == id )
				{
					RZcalendar_name = removeStartHyphen(selObj.options[i].text);
					return RZcalendar_name;
				}

			}
		}

	}

	return RZcalendar_name;
*/
}

/*-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------*/
function getHtmlOfDayEvents(arr)
{
	var toReturn = "";
	for(var i = 0; i < arr.length; i ++)
		toReturn += arr[i][1];

	return toReturn ;
}

/*-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------*/
function sortOnTime(arr, loB, hiB)
{
	if(loB == hiB || loB > hiB)
		return;

	var min = new Array();
	min[0] = arr[loB][0];
	min[1] = arr[loB][1];
	var minIdx = loB;

	var min_temp = min[0];
	for(var i = loB; i < hiB; i++)
	{
		if(min_temp > arr[i][0])
		{
			minIdx = i;
			min_temp = arr[i][0];
		}
	}
	if(minIdx != loB)
	{
		arr[loB][0] = arr[minIdx][0];
		arr[loB][1] = arr[minIdx][1];
		arr[minIdx][0] = min[0];
		arr[minIdx][1] = min[1];
	}
	loB++;
	sortOnTime(arr, loB, hiB);
}