function setClock(obj,timevalue){
//set 'current time' for clock1 (hidden clock used for determining next meeting time date and if current time within valid link window), 
	clock_obj1=obj;
	clock_obj1.value=timevalue;
	window.setInterval("clock_obj1.value=new Date(Date.parse(clock_obj1.value)+1000)",1000);
}

//set time value constants
	const_hour= 1000 * 60 * 60;
	const_week= 1000 * 60 * 60 * 24 * 7;

//declare arrays
	mtg_miss= new Array();
	mtg_spec= new Array();

//define time zones
	mdt=" GMT-0600"
	mst=" GMT-0700"

//*********************************************************
//*******Ensure values set in this section are valid ******
//set meeting duration (in hours) and schedule frequency (in weeks)
	mtg_dur= const_hour * 4;
	mtg_freq = const_week * 2;

//**All dates to be entered in MMM DD, YYYY HH:MM:SS format. Do not include time zone value.**

//initial and max date values
            mtg_init="Jan 11, 2010 19:00:00";
            mtg_max="Dec 20, 2010 19:00:00";

//regular meeting dates missed within regular schedule (no meeting occuring) 

            //ensure array elements are numbered sequentially, starting from zero
            mtg_miss[0]="May 17, 2010 19:00:00";
            mtg_miss[1]="Sep 6, 2010 19:00:00";
 
//meetings outside of regular schedule

            //ensure array elements are numbered sequentially, starting from zero
            mtg_spec[0]="May 17, 2010 13:30:00";
            mtg_spec[1]="Sep 7, 2010 19:00:00";
            mtg_spec[2]="Oct 18, 2010 19:00:00";    
            mtg_spec[3]="Nov 1, 2010 19:00:00";			

//set links
            url_live_h="http://stream.netro.ca/cogp";
            url_live_l="http://stream.netro.ca/cogpl";
            url_err="javascript:alert('There is no LIVE webcast in progress.  Please wait until the next scheduled meeting begins.')";

//******************end of section*************************
//*********************************************************

//format all given dates to and sort by numerical GMT value
	var miss_num;
	var spec_num;

	//initial and max dates 
	mtg_init=Date.parse(new Date(mtg_init));
	mtg_max=Date.parse(new Date(mtg_max));

	//missed meetings
	miss_num=mtg_miss.length;
	i=0;
	for (i=0;i<miss_num;i++) {
		mtg_miss[i]=Date.parse(new Date(mtg_miss[i]))
	}
	mtg_miss.sort(num_sort);

	//special out-of-schedule meetings
	spec_num=mtg_spec.length;
	i=0;
	for (i=0;i<spec_num;i++) {
		mtg_spec[i]=Date.parse(new Date(mtg_spec[i]))
	}
	mtg_spec.sort(num_sort);	

//function to sort array in numerical order
function num_sort(num1, num2) {

	return num1-num2;
}


//determines if timezone shift has occured due to daylight saving time between two dates
function dst_shift(date1, date2) {

	tzDate1= getTimeZone(date1);
	tzDate2= getTimeZone(date2);
	
	if (tzDate1==tzDate2)
		shift=0;
	else if (tzDate1==mdt && tzDate2== mst)
		shift=1*const_hour;
	else if (tzDate1==mst && tzDate2== mdt)
		shift=-1*const_hour;
	else
		shift=0;
		
	return shift;
}

function getTimeZone(timezoneDate) {

	currentmonth= new Date(timezoneDate).getMonth();
	dayofmonth= new Date(timezoneDate).getDate();
	dayofweek= new Date(timezoneDate).getDay();

	MARCH_MONTH_VALUE= 2;
	NOVEMBER_MONTH_VALUE =10;

	if (currentmonth>MARCH_MONTH_VALUE && currentmonth <NOVEMBER_MONTH_VALUE)
		zone=mdt;
	else if (currentmonth<MARCH_MONTH_VALUE || currentmonth>NOVEMBER_MONTH_VALUE)
		zone=mst;
	else if (currentmonth==MARCH_MONTH_VALUE)
		//Cahnge on 2nd Sunday
		if ((dayofmonth-dayofweek-7)>0)
			zone=mdt;
		   else
			zone=mst;
	else if (currentmonth==NOVEMBER_MONTH_VALUE)
		//Change on 1st Sunday
		   if ((dayofmonth-dayofweek)>0)
			zone=mst;
		   else
			zone=mdt;

	return zone;
}


//gets next valid meeting date
function getmtgdate() {

	// declare vars
	var mtgdate;
	var setmtg;
	var i;
	var j;
	var dt_now;
	
	//set value for current date and time
	dt_now= new Date();
	dt_now= Date.parse(clock_obj1.value);

	mtgdate=mtg_init; 

	//check each scheduled interval from initial date to see if less than current date
	while ((mtgdate<dt_now) && ((mtgdate+mtg_dur>dt_now) != true)){
		i=0;
		setmtg=false;

		//check for exceptions within current interval
		while (i<spec_num && setmtg==false) {
    
			if (mtg_spec[i]>mtgdate && (mtg_spec[i]+mtg_dur>dt_now) && mtg_spec[i]<mtgdate+mtg_freq) {
				mtgdate=mtg_spec[i];
				setmtg=true		
			}
			i++
		}

		//check if next intervals should be skipped
		i=0;
		while (i<miss_num) {

			if (mtg_miss[i]==mtgdate+mtg_freq) {
				mtgdate=mtgdate+mtg_freq;
				//check for exceptions within interval of regular meeting that was skipped 
				j=0;
				while (j<spec_num && setmtg==false) {
					if (mtg_spec[j]>mtgdate && (mtg_spec[j]+mtg_dur>dt_now) && mtg_spec[j]<mtgdate+mtg_freq) {
						mtgdate=mtg_spec[j];
						setmtg=true
					}		
					j++ 
				}
			}
			i++ 
		} 

		//if exception not found within interval, skip to next interval
		if (setmtg==false) 
			mtgdate=mtgdate+mtg_freq+dst_shift(mtgdate,mtgdate+mtg_freq); 
	}
			
	//return next date found, unless beyond max date, then send blank date

	if (mtgdate<=mtg_max)
		return mtgdate;  
	else
		return 0;


}
//determines which link to follow depending on dates
function golink(bandwidth,timevalue) {

	var mtgdate_start, mtgdate_end;
	var bsuffix;
	var dt_now;

	//set value for current date and time
	dt_now= new Date();
	dt_now= Date.parse(clock_obj1.value);

	//set bandwidth options
	if (bandwidth==0) 
		bsuffix="h";
	else
		bsuffix="l";
	
	//get next meeting times
	mtgdate_start=getmtgdate();
	mtgdate_end=mtgdate_start+mtg_dur;

	//compare against current time
	if (dt_now >= mtgdate_start && dt_now < mtgdate_end)
		window.location.href= eval("url_live_" + bsuffix);
	else
		window.location.href= url_err;
}
