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]="Sep 6, 2010 19:00:00";
 
//meetings outside of regular schedule

            //ensure array elements are numbered sequentially, starting from zero
            mtg_spec[0]="Sep 7, 2010 19:00:00";
            mtg_spec[1]="Oct 18, 2010 19:00:00";    
            mtg_spec[2]="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;
}


//determine daylight saving time zone depending on time of year
function dst_adj(date_val) {

	var zone;

 	month= new Date(date_val).getMonth();
	dayofm= new Date(date_val).getDate();
	dayofw= new Date(date_val).getDay();


	if (month>3 && month <9)
		zone=mdt;
	else if (month<3 || month>9)
		zone=mst;
	else if (month==3)
		if (dayofm>=7)
		   zone=mdt;
		else
		   if ((dayofm-dayofw)>0)
			zone=mdt;
		   else
			zone=mst;
	else if (month==9)
		if (31-dayofm>=7)
		   zone=mdt;
		else
		   if (31-dayofm+dayofw<7)
			zone=mst;
		   else
			zone=mdt;

	return zone;

}


//determines if timezone shift has occured due to daylight saving time between two dates
function dst_shift(date1, date2) {

	tzdates= new Array()
	tzdiff= new Array()

	tzdates[0]=date1
	tzdates[1]=date2


	for (i=0;i<2;i++) {
	 	month= new Date(tzdates[i]).getMonth();
		dayofm= new Date(tzdates[i]).getDate();
		dayofw= new Date(tzdates[i]).getDay();

		if (month>3 && month <9)
			zone=mdt;
		else if (month<3 || month>9)
			zone=mst;
		else if (month==3)
			if (dayofm>=7)
			   zone=mdt;
			else
			   if ((dayofm-dayofw)>0)
				zone=mdt;
			   else
				zone=mst;
		else if (month==9)
			if (31-dayofm>=7)
			   zone=mdt;
			else
			   if (31-dayofm+dayofw<7)
				zone=mst;
			   else
				zone=mdt;

		tzdiff[i]=zone;
	}
		    
	if (tzdiff[0]==tzdiff[1])
		shift=0;
	else if (tzdiff[0]==mdt && tzdiff[1]== mst)
		shift=1*const_hour;
	else if (tzdiff[0]==mst && tzdiff[1]== mdt)
		shift=-1*const_hour;

	return shift;
}


//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;
}
