//Developed by Mrigesh Rajbhandari (mickey@byu.edu) 07/18/2006 BYU copyright 2008
    
window.onload = function () {
	var calendarMode = readCookie('byu_cal_cookie');
	
	if (calendarMode) {
		bas_cal = new Byucal('epoch_basic',calendarMode+'_view',document.getElementById('basic_container'));
		changeType(calendarMode);
		eraseCookie('byu_cal_cookie');
		createCookie('byu_cal_cookie',calendarMode,90)
	}
	else{
		bas_cal = new Byucal('epoch_basic','day_view',document.getElementById('basic_container'));
		changeType('day');		
		
	}
	
	
	
};
function Byucal(name,mode,targetelement,multiselect)
{
	this.state = 0;
	this.name = name;
	this.curDate = new Date();
	this.selDate;
	this.mode = mode;
	this.selectMultiple = (multiselect == true); //'false' is not true or not set at all
	
	//the various calendar variables
	this.selected;
	this.selectedDates = new Array();
	this.selectedDateslist = new Array();
	this.calendar;
	this.calHeading;
	this.calCells;
	this.rows;
	this.cols;
	this.cells = new Array();
	
	//The controls
	this.monthSelect;
	this.yearSelect;
	this.monthobj;
	this.eventobj;
	this.dwnevent;
	this.dwnevents;
	this.viewtypemonth;
	this.viewtypeday;
	this.downloadevents;
	
	
	//standard initializations
	this.mousein = false;
	this.calConfig();
	this.setDays();
	
	
	this.displayYear = this.displayYearInitial;
	this.displayMonth = this.displayMonthInitial;
	
	this.createCalendar(); //create the calendar DOM element and its children, and their related objects
							
	if(this.mode == 'day_view' && targetelement && targetelement.type == 'text') //if the target element has been set to be an input text box
	{
		this.tgt = targetelement;
		this.calendar.style.position = 'absolute';
		this.topOffset = this.tgt.offsetHeight; // the vertical distance (in pixels) to display the calendar from the Top of its input element
		this.leftOffset = 0; 					// the horizontal distance (in pixels) to display the calendar from the Left of its input element
		this.calendar.style.top = this.getTop(targetelement) + this.topOffset + 'px';
		this.calendar.style.left = this.getLeft(targetelement) + this.leftOffset + 'px';
		document.body.appendChild(this.calendar);
		this.tgt.calendar = this;
		this.tgt.onfocus = function () {this.calendar.show();}; //the calendar will day_view when the input element is focused
		this.tgt.onblur = function () {if(!this.calendar.mousein){this.calendar.hide();}}; //the calendar will day_view when the input element is focused
	}
	else
	{
		this.container = targetelement;
		this.container.appendChild(this.calendar);
	}
	
	this.state = 2; //0: initializing, 1: redrawing, 2: finished!
	this.visible ? this.show() : this.hide();
	this.onLoad();
}
//-----------------------------------------------------------------------------

Byucal.prototype.onLoad = function ()


{
	
		if(!this.visible){
			var temp_month=this.monthSelect.value;
			var year=this.yearSelect.value;
			temp_month=eval(Number(temp_month)+1);
		
		
			if(this.monthSelect.value==this.curDate.getMonth() && this.yearSelect.value==this.curDate.getFullYear()){
						generatelist(temp_month+'/'+this.curDate.getDate()+'/'+year);
						generateiconlist(temp_month+'/'+this.curDate.getDate()+'/'+year);
						
			}else{
						generatelist(temp_month+'/1/'+year);
						generateiconlist(temp_month+'/1/'+year);
						
			}
			
	}else{
	
		loadMulti((this.monthSelect.value),this.yearSelect.value);
		
	}
	
}


Byucal.prototype.more = function ()


{
	
	
}

Byucal.prototype.calConfig = function () //PRIVATE: initialize calendar variables
{
	//this.mode = 'flat'; //can be 'flat' or 'day_view'
	this.displayYearInitial = this.curDate.getFullYear(); //the initial year to display on load
	this.displayMonthInitial = this.curDate.getMonth(); //the initial month to display on load (0-11)
	this.rangeYearLower = 2006;
	this.rangeYearUpper = new Date().getFullYear() + 1;
	this.minDate = new Date(2006,0,1);
	this.maxDate = new Date(new Date().getFullYear() + 1, 0, 1);
	this.startDay = 0; // the day the week will 'start' on: 0(Sun) to 6(Sat)
	this.showWeeks = true; //whether the week numbers will be shown
	this.selCurMonthOnly = false; //allow user to only select dates in the currently displayed month
	this.clearSelectedOnChange = true; //whether to clear all selected dates when changing months
	
	//flat mode-only settings:
	this.selectMultiple = true; //whether the user can select multiple dates (flat mode only)

	switch(this.mode) //set the variables based on the calendar mode
	{
		case 'day_view': //day_view options
			this.visible = false;

			break;
		case 'month_view':
			this.visible = true;

			break;
	}
	this.setLang();
};
//-----------------------------------------------------------------------------
Byucal.prototype.setLang = function()  //all language settings for Byucal are made here.  Check Date.dateFormat() for the Date object's language settings
{
	//this.daylistview = new Array('sundaylist','mondaylist','tuesdaylist','wednesdaylist','thursdaylist','fridaylist','saturdaylist','sundaylist','mondaylist','tuesdaylist','wednesdaylist','thursdaylist','fridaylist','saturday');
	this.daylist = new Array('sunday','monday','tuesday','wednesday','thursday','friday','saturday','sunday','monday','tuesday','wednesday','thursday','friday','saturday'); /*
	
	<lang:en>*/
	this.shortdaylist = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
	this.months_sh = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	//this.event_sh= new Array('All in One','Academic','Alumni','Conferences','Devotionals','Events','Fine Arts','Sports','BYUSA','Intramurals');
		this.event_sh= new Array('All in One','Academic','Alumni','Conferences','Devotionals','Events','Fine Arts','Sports','Intramurals');
		this.key_images = new Array('','list-red.gif','list-magenta.gif','list-orange.gif','list-green.gif','list-black.gif','list-violet.gif','list-blue.gif','');
	this.months_but = new Array('JanBut','FebBut','MaBut','ApBut','MayBut','JunBut','JulBut','AugBut','SepBut','OctBut','NovBut','DecBut');
	
	this.monthup_title = 'Go to the next month';
	this.monthdn_title = 'Go to the previous month';
	this.clearbtn_title = 'Clears any dates selected on the calendar';
	this.maxrange_caption = 'This is the maximum range';
};
//-----------------------------------------------------------------------------
Byucal.prototype.getTop = function (element) //PRIVATE: returns the absolute Top value of element, in pixels
{
    var oNode = element;
    var iTop = 0;
    
    while(oNode.tagName != 'TYPE') {
        iTop += oNode.offsetTop;
        oNode = oNode.offsetParent;
    }
    
    return iTop;
};
//-----------------------------------------------------------------------------
Byucal.prototype.getLeft = function (element) //PRIVATE: returns the absolute Left value of element, in pixels
{
    var oNode = element;
    var iLeft = 0;
    
    while(oNode.tagName != 'TYPE') {
        iLeft += oNode.offsetLeft;
        oNode = oNode.offsetParent;        
    }
    
    return iLeft;
};
//-----------------------------------------------------------------------------
Byucal.prototype.show = function () //PUBLIC: displays the calendar
{
	this.calHeading.style.display = 'block';
	//this.calCells.style.display = 'block';
	this.visible = true;
};
//-----------------------------------------------------------------------------
Byucal.prototype.hide = function () //PUBLIC: Hides the calendar
{
	this.calHeading.style.display = 'none';

	
	//this.calCells.style.display = 'none';
	this.visible = false;
	
};
//-----------------------------------------------------------------------------
Byucal.prototype.toggle = function (type) //PUBLIC: Toggles (shows/hides) the calendar depending on its current state
{
	if(type=='day') {
	
		this.hide();
		this.toggleMonth();
			eraseCookie('byu_cal_cookie');
	
			createCookie('byu_cal_cookie','day',90)
		
	}
	else {
		this.show();
		this.toggleMonth();
			eraseCookie('byu_cal_cookie');
	
			createCookie('byu_cal_cookie','month',90)
	}
};
//-----------------------------------------------------------------------------
Byucal.prototype.setDays = function ()  //PRIVATE: initializes the standard Gregorian Calendar parameters
{
	this.daynames = new Array();
	var j=0;
	for(var i=this.startDay; i< this.startDay + 7;i++) {
		this.daynames[j++] = this.daylist[i];
	}
		
	this.monthDayCount = new Array(31,((this.curDate.getFullYear() - 2000) % 4 ? 28 : 29),31,30,31,30,31,31,30,31,30,31);
};
//-----------------------------------------------------------------------------
Byucal.prototype.setClass = function (element,className) //PRIVATE: sets the CSS class of the element, W3C & IE
{
	element.setAttribute('class',className);
	element.setAttribute('className',className); //<iehack>
};
//-----------------------------------------------------------------------------
Byucal.prototype.createCalendar = function ()  //PRIVATE: creates the full DOM implementation of the calendar
{
	var tbody, tr, td;
	this.calendar = document.createElement('div');
	this.calendar.setAttribute('id',this.name+'_calendar');
	this.setClass(this.calendar,'calendar');
	//to prevent IE from selecting text when clicking on the calendar
	this.calendar.onselectstart = function() {return false;};
	this.calendar.ondrag = function() {return false;};
	tbody = document.createElement('div');
	
	//create the Main Calendar Heading
	tr = document.createElement('div');
	
	tr.appendChild(this.createMainHeading());

	tbody.appendChild(tr);
	
	//create the calendar Day Heading
	tr = document.createElement('div');

	tr.appendChild(this.createDayHeading());

	tbody.appendChild(tr);

	//create the calendar Day Cells
	tr = document.createElement('div');

	tr.setAttribute('id',this.name+'_cell_td');
	this.calCellContainer = tr;	//used as a handle for manipulating the calendar cells as a whole
	tr.appendChild(this.createCalCells());

	tbody.appendChild(tr);
	
	//add the tbody element to the main calendar table
	this.calendar.appendChild(tbody);
	//and add the onmouseover events to the calendar table
	this.calendar.owner = this;
		//and add the onmouseover events to the calendar table
	this.calendar.owner = this;
	this.calendar.onmouseover = function() {this.owner.mousein = true;};
	this.calendar.onmouseout = function() {this.owner.mousein = false;};


};
//-----------------------------------------------------------------------------
Byucal.prototype.createMainHeading = function() //PRIVATE: Creates the primary calendar heading, with months & years
{
    //create the containing <div> element

    var container = document.createElement('div');
    container.setAttribute('id', this.name + '_mainheading');
    this.setClass(container, 'mainheading');
    this.monthobj = document.createElement('div');
    this.monthobj.setAttribute('id', 'month');
    var loader = document.createElement('div');
    loader.setAttribute('id', 'loader');
    this.monthSelect = document.createElement('select');
    monthgroup = document.createElement('div');
    monthgroup.setAttribute('id', 'monthGroup');
    yearSelect_attach = document.createElement('div');
    this.yearSelect = document.createElement('select');
    this.yearsel = document.createElement('div');
    var monthDndiv = document.createElement('div');
    var monthUpdiv = document.createElement('div');

    this.dwnevent = document.createElement('div');
    this.dwnevent.setAttribute('id', 'downloads');

    this.dwnevents = document.createElement('div');
    this.dwnevents.setAttribute('id', 'popupDownload');
    //var monthdiv = document.createElement('div');
    this.eventobj = document.createElement('div');
    this.eventobj.setAttribute('id', 'eventme');
    var evnt, m, event_all, keyImg;
    //alert(this.event_sh.length);
    for (m = 0; m < this.event_sh.length; m++) {
        //if(m==8 || m==9){
        if (m == 8) {
            event_all = document.createElement('a');

            event_all.appendChild(document.createTextNode(this.event_sh[m]));

            if (m == 0) {
                event_all.setAttribute('class', 'currentlyDisplayedSelected');
                event_all.setAttribute('className', 'currentlyDisplayedSelected');
            }
            event_all.setAttribute('id', 'icon_8');
            var icon_8 = new Image();
            icon_8.src = 'http://news.byu.edu/images/externallinkhover.gif';
            event_all.setAttribute('target', "_blank");

            if (m == 8) {
                //event_all.setAttribute('href','http://attu.byu.edu/eventcalendar/events/');	
                event_all.setAttribute('href', 'http://intramurals.byu.edu/activities.php');
            }
            //else if(m==9){
            //event_all.setAttribute('href','http://intramurals.byu.edu/activities.php');	
            //}
            event_all.owner = this;
            this.eventobj.appendChild(event_all);
        } else {


            event_all = document.createElement('a');

            if (this.key_images[m] != '') {
                keyImg = document.createElement('img');
                keyImg.setAttribute('src', './images/' + this.key_images[m]);
                keyImg.style.border = '0';
                keyImg.style.paddingBottom = '.2em';
                keyImg.style.paddingRight = '.5em';
                event_all.appendChild(keyImg);
            }

            event_all.appendChild(document.createTextNode(this.event_sh[m]));

            if (m == 0) {
                event_all.setAttribute('class', 'currentlyDisplayedSelected');
                event_all.setAttribute('className', 'currentlyDisplayedSelected');
            }
            event_all.setAttribute('id', 'color_' + m);
            event_all.setAttribute('href', 'javascript:void(0)');
            event_all.owner = this;
            event_all.onmouseup = function() {
                var temp_id = this.id;
                temp_id = temp_id.substring(6);


                this.owner.LoadEvent(this.owner.displayYear, temp_id);
                this.owner.CssEvent(this);

            };

            this.eventobj.appendChild(event_all);
        }
    }

    dwnEvt = document.createElement('img');
    dwnEvt.setAttribute('src', '../images/download-cal.gif');
    dwnEvt.owner = this;
    dwnEvt.onmouseup = function() {
        this.owner.CssShowCheck(this);
    };
    //HIDES DOWNLOAD EVENT--NOT CURRENTLY WORKING
    /*this.dwnevent.appendChild(dwnEvt);
	
	
	
		dwnEvtmonth = document.createElement('div');
    dwnEvtmonth.setAttribute('class','check_month');
    dwnEvtmonth.setAttribute('className','check_month');
    dwnEvtmonth.setAttribute('id','check_month');
    dwnEvtmonth_name = document.createElement('div');
    dwnEvtmonth_name.setAttribute('className','title');
    dwnEvtmonth_name.setAttribute('class','title');
		
		dwnEvtmonth_name.appendChild(document.createTextNode("Choose category:"));
    dwnEvtmonth.appendChild(dwnEvtmonth_name);

	for(m=0;m < this.event_sh.length;m++)
    {
		
		if(m==7 || m==8){
			
    }else
		
		
    { 

		event_checkbox_div = document.createElement('div');
    event_checkbox = document.createElement('input');
    event_checkbox.setAttribute('type','checkbox');
    event_checkbox.setAttribute('class','test');
    event_checkbox.setAttribute('className','test');
    if(m==0){event_checkbox.checked=true;	}

			event_checkbox.setAttribute('name','event'+m);
    // event_checkbox.appendChild(document.createTextNode(this.event_sh[m]));
	
			event_checkbox.owner = this;
			
    event_checkbox_div.appendChild(event_checkbox);
    event_checkbox_div.appendChild(document.createTextNode(this.event_sh[m]));
    dwnEvtmonth.appendChild(event_checkbox_div);
		
			
    }
		
	}
	
	this.dwnevents.appendChild(dwnEvtmonth);
	
			dwnEvtgroup = document.createElement('div');
    dwnEvtgroup.setAttribute('class','check_group');
    dwnEvtgroup.setAttribute('className','check_group');
    dwnEvtgroup.setAttribute('id','check_group');
		
		dwnEvtgroup_name = document.createElement('div');
    dwnEvtgroup_name.appendChild(document.createTextNode("Choose time frame:"));
		
		
    dwnEvtgroup_name.setAttribute('className','title');
    dwnEvtgroup_name.setAttribute('class','title');
    dwnEvtgroup.appendChild(dwnEvtgroup_name);
		
				dwnEvtcurrent = document.createElement('div');
    dwnEvtcurrent.setAttribute('class','check');
    dwnEvtcurrent.setAttribute('className','check');
    dwnEvtcurrentinput = document.createElement('input');
    dwnEvtcurrentinput.setAttribute('name','sem');
    dwnEvtcurrentinput.setAttribute('type','checkbox');
				
    dwnEvtcurrentinput.owner = this;			
    dwnEvtcurrent.appendChild(dwnEvtcurrentinput);
    dwnEvtcurrent.appendChild(document.createTextNode("Current month"));
    dwnEvtgroup.appendChild(dwnEvtcurrent);
		
		
    dwnEvtfall = document.createElement('div');
    dwnEvtfall.setAttribute('class','check');
    dwnEvtfall.setAttribute('className','check');
    dwnEvtfallinput = document.createElement('input');
    dwnEvtfallinput.setAttribute('name','sem');
    dwnEvtfallinput.setAttribute('type','checkbox');
			
    dwnEvtfallinput.owner = this;
    dwnEvtfall.appendChild(dwnEvtfallinput);
    dwnEvtfall.appendChild(document.createTextNode("Fall semester"));
    dwnEvtgroup.appendChild(dwnEvtfall);
		
		dwnEvtwinter = document.createElement('div');
    dwnEvtwinter.setAttribute('class','check');
    dwnEvtwinter.setAttribute('className','check');
    dwnEvtwinterinput = document.createElement('input');
    dwnEvtwinterinput.setAttribute('name','sem');
    dwnEvtwinterinput.setAttribute('type','checkbox');
    dwnEvtwinterinput.owner = this;
    dwnEvtwinter.appendChild(dwnEvtwinterinput);
    dwnEvtwinter.appendChild(document.createTextNode("Winter semester"));
    dwnEvtgroup.appendChild(dwnEvtwinter);
		
		dwnEvtsumsp = document.createElement('div');
    dwnEvtsumsp.setAttribute('class','check');
    dwnEvtsumsp.setAttribute('className','check');
    dwnEvtsumspinput = document.createElement('input');
    dwnEvtsumspinput.setAttribute('name','sem');
    dwnEvtsumspinput.setAttribute('type','checkbox');
    dwnEvtsumspinput.owner = this;
    dwnEvtsumsp.appendChild(dwnEvtsumspinput);
    dwnEvtsumsp.appendChild(document.createTextNode("Sum/Spr semester"));
    dwnEvtgroup.appendChild(dwnEvtsumsp);
		


		dwnEvtsubmit = document.createElement('div');
    dwnEvtsubmit.setAttribute('class','button');
    dwnEvtsubmit.setAttribute('className','button');
    dwnEvtsubmitinput = document.createElement('img');
    dwnEvtsubmitinput.setAttribute('src','images/download-ical-events.gif');

			dwnEvtsubmitinput.owner = this;
    dwnEvtsubmitinput.onclick = function() {
    this.owner.CssCheckbox(this);
    };
    dwnEvtsubmit.appendChild(dwnEvtsubmitinput);	
	   
	   
	   
    dwnEvtgroup.appendChild(dwnEvtsubmit);
	   
	   
	   
    dwnEvtinfo = document.createElement('div');
    dwnEvtinfo.setAttribute('class','check');
    dwnEvtinfo.setAttribute('className','check');
    dwnEvtinfo.appendChild(document.createTextNode(""));
    dwnEvtgroup.appendChild(dwnEvtinfo);
	   
	   
		
		 this.dwnevents.appendChild(dwnEvtgroup);*/



    var opt, i = 0, month;
    for (i = 0; i < 12; i++) {


        opt = document.createElement('option');
        opt.setAttribute('value', i);
        if (this.state == 0 && this.displayMonth == i) {
            opt.setAttribute('selected', 'selected');

        }
        opt.appendChild(document.createTextNode(this.months_sh[i]));
        this.monthSelect.appendChild(opt);

        month = document.createElement('a');
        month.setAttribute('id', i);
        month.setAttribute('href', 'javascript:void(0)');



        if (this.state == 0 && this.displayMonth == i) {
            month.setAttribute('className', 'currentlyDisplayedSelected');
            month.setAttribute('class', 'currentlyDisplayedSelected');

        }
        month.appendChild(document.createTextNode(this.months_sh[i]));
        month.owner = this;
        month.onmouseup = function() {
            this.owner.goToMonth(this.owner.displayYear, this.id);
            this.owner.CssMonth(this);
        };

        this.monthobj.appendChild(month);




    }
    //alert(this.months_sh[this.displayMonth]+' '+this.displayYear );
    //monthdiv.appendChild(document.createTextNode(this.displayMonth));
    //and fill the year select box
    for (i = this.rangeYearLower; i <= this.rangeYearUpper; i++) {
        opt = document.createElement('option');

        opt.setAttribute('value', i);
        if (this.state == 0 && this.displayYear == i) {
            opt.setAttribute('selected', 'selected');
        }
        opt.appendChild(document.createTextNode(i));
        this.yearSelect.appendChild(opt);




    }
    //add the appropriate children for the month buttons


    //alert(test);
    monthUpdiv.setAttribute('id', 'buttonUp');
    monthUp = document.createElement('img');
    monthUp.setAttribute('src', 'images/next.gif');
    monthUp.setAttribute('value', '>');
    monthUp.setAttribute('title', this.monthup_title);
    monthUpdiv.appendChild(monthUp);

    monthDndiv.setAttribute('id', 'buttonDn');


    monthDn = document.createElement('img');
    monthDn.setAttribute('src', 'images/previous.gif');
    monthDn.setAttribute('value', '<');
    monthDn.setAttribute('title', this.monthdn_title);
    monthDndiv.appendChild(monthDn);







    this.monthSelect.owner = this.yearSelect.owner = monthUp.owner = monthDn.owner = this;
    //assign the event handlers for the controls
    monthUp.onmouseup = function() { this.owner.nextMonth(); };
    monthDn.onmouseup = function() { this.owner.prevMonth(); };






    this.monthSelect.onchange = function() {
        this.owner.displayMonth = this.value;
        this.owner.displayYear = this.owner.yearSelect.value;
        this.owner.goToMonth(this.owner.displayYear, this.owner.displayMonth);
    };

    this.yearSelect.onchange = function() {
        this.owner.displayMonth = this.owner.monthSelect.value;
        this.owner.displayYear = this.value;
        this.owner.goToMonth(this.owner.displayYear, this.owner.displayMonth);
    };

    //and finally add the elements to the containing div

    downloadevents = document.createElement("img");
    downloadevents.setAttribute("src", "images/downloadevents.gif");
    downloadevents.setAttribute("id", "downloadbutton");
    downloadevents.onclick = function() { window.open("http://news.byu.edu/calendar/download-events.aspx", 'mywindow', 'status=1,location=0,width=550,height=310,scrollbars=1'); };
    container.appendChild(downloadevents);
    //container.appendChild(this.e);	
    container.appendChild(this.eventobj);
    monthgroup.appendChild(monthDndiv);
    monthgroup.appendChild(this.monthobj);
    monthgroup.appendChild(monthUpdiv);
    monthgroup.appendChild(monthUpdiv);
    yearSelect_attach.appendChild(this.yearSelect);
    monthgroup.appendChild(yearSelect_attach);
    monthgroup.appendChild(this.dwnevent);
    monthgroup.appendChild(loader);
    monthgroup.appendChild(this.dwnevents);
    container.appendChild(monthgroup);

    var thisDate = new Date();

    var thisDiv = document.createElement("div");
    var thisDiv2 = document.createElement("div");
    //console.log("Mode: " + this.mode
    thisDiv2.id = "monthSelector";
    thisDiv.id = "dateSelector";
    thisDiv.setAttribute("class", "none");


    dwnDiv = document.createElement('div');
    dwnDiv.setAttribute('id', 'viewtoggle');
    dwnText = document.createElement('em');
    dwnText.appendChild(document.createTextNode('Select view type:'));
    this.viewtypeday = document.createElement('img');
    this.viewtypeday.setAttribute('src', '../images/day.on.gif');
    this.viewtypeday.owner = this;
    this.viewtypeday.onmouseup = function() {
        changeType('day');
        this.owner.toggle('day');
    };

    this.viewtypemonth = document.createElement('img');
    this.viewtypemonth.setAttribute('src', '../images/month.off.gif');
    this.viewtypemonth.owner = this;
    this.viewtypemonth.onmouseup = function() {

        changeType('month');
        this.owner.toggle('month');
    };

    dwnDiv.appendChild(this.viewtypeday);
    dwnDiv.appendChild(this.viewtypemonth);
    dwnDiv.appendChild(dwnText);
    thisDiv.appendChild(dwnDiv);
    
    var selectElem = document.createElement("select");
    selectElem.id = "monthSelector";
    selectElem.owner = this;
    selectElem.onchange = function() { this.owner.goToMonth(document.getElementById('yearSelector').options[document.getElementById('yearSelector').selectedIndex].text, this.selectedIndex); };
    for (i = 0; i < 12; i++) {
        var jan = document.createElement("option");
        jan.innerHTML = this.months_sh[i];
        if (thisDate.getMonth() == i)
            jan.setAttribute("selected", true);
        selectElem.appendChild(jan);
    }
    container.appendChild(thisDiv2);
    thisDiv2.appendChild(thisDiv);
    thisDiv.appendChild(selectElem);
    var selectElem2 = document.createElement("select");
    selectElem2.id = "yearSelector";
    selectElem2.owner = this;
    selectElem2.onchange = function() { this.owner.goToMonth(selectElem2.options[this.selectedIndex].text, selectElem.selectedIndex); };

    for (i = new Date().getFullYear() + 1; i > 2007; i--) {
        var jan = document.createElement("option");
        jan.innerHTML = i;
        if (i == new Date().getFullYear())
            jan.setAttribute("selected", true);
        selectElem2.appendChild(jan);
    }
    thisDiv.appendChild(selectElem2);
    var todayBut = document.createElement("a");
    todayBut.owner = this;
    todayBut.setAttribute("href", "javascript:void(0);");
    todayBut.onmouseup = function() { this.owner.goToMonth(thisDate.getFullYear(), thisDate.getMonth()); selectElem2.selectedIndex = 1; selectElem.selectedIndex = thisDate.getMonth() };
    todayBut.innerHTML = "Today";
    thisDiv.appendChild(todayBut);
    //container.appendChild(monthDndiv);
    //container.appendChild(this.monthobj);
    //container.appendChild(monthUpdiv);
    //yearSelect_attach.appendChild(this.yearSelect);
    //container.appendChild(yearSelect_attach);	
    //container.appendChild(loader);
    return container;
};

//-----------------------------------------------------------------------------



//-----------------------------------------------------------------------------
Byucal.prototype.createDayHeading = function ()  //PRIVATE: creates the heading containing the day names
{
	//create the table element
	this.calHeading = document.createElement('div');


		this.calHeading.setAttribute('id','weekheading');
	
	var tbody,tr,td;
	tbody = document.createElement('div');
	
	this.cols = new Array(false,false,false,false,false,false,false);
	
	//if we're showing the week headings, create an empty <td> for filler

	//populate the day titles
	for(var dow=0;dow<7;dow++)
	{
		td = document.createElement('div');
	
		td.setAttribute('id',this.daynames[dow]);
	
		if(this.selectMultiple) { //if selectMultiple is true, assign the cell a CalHeading Object to handle all events
			td.headObj = new CalHeading(this,td,(dow + this.startDay < 7 ? dow + this.startDay : dow + this.startDay - 7));
		}
		tbody.appendChild(td);
	}
	//tbody.appendChild(tr);
	this.calHeading.appendChild(tbody);
	return this.calHeading;	
};
//-----------------------------------------------------------------------------
Byucal.prototype.createCalCells = function ()  //PRIVATE: creates the table containing the calendar day cells
{
	this.rows = new Array(false,false,false,false,false,false);
	this.cells = new Array();
	var row = -1, totalCells = (this.showWeeks ? 48 : 42);
	var beginDate = new Date(this.displayYear,this.displayMonth,1);
	var endDate = new Date(this.displayYear,this.displayMonth,this.monthDayCount[this.displayMonth]);
	var sdt = new Date(beginDate);
	sdt.setDate(sdt.getDate() + (this.startDay - beginDate.getDay()) - (this.startDay - beginDate.getDay() > 0 ? 7 : 0) );
	//create the table element
	this.calCells = document.createElement('div');
	this.calCells.setAttribute('id','monthcontainer');
	this.calCells.setAttribute('id',this.name+'_calcells');
	this.setClass(this.calCells,'calcells');
	var tbody,tr,td,span;
	tbody = document.createElement('div');
	tbodylistevents = document.createElement('div');
	
		if(this.visible){
		tbody.setAttribute('id','wmonth');
		}else{
		tbody.setAttribute('id','listmonth');
		tbodylistevents.setAttribute('id','listevents');
		tbodylistevents.style.zIndex = 500000;
		
		
		
		}

	if(!this.visible){
		for(var i=0;i<7;i++)
		{
			
				if(i % 8 == 0)
				{
					
					tr = document.createElement('div');
					tr.setAttribute('id','listweek');
					tr.setAttribute('class','listweekheader');
					tr.style.height = '14px';
		  
			
			
					}
					
			td = document.createElement('div');
		  td.setAttribute('id','wey');
	td.appendChild(document.createTextNode(this.shortdaylist[i]));// +' ' +sdt.getUeDay()));
		  
			 tr.appendChild(td);
			tbody.appendChild(tr);
		
		}      

	} 
	for(var i=0;i<totalCells;i++)
	{
		if(this.showWeeks) //if we are showing the week headings
		{
			if(i % 8 == 0)
			{
					row++;
					tr = document.createElement('div');
					tr.setAttribute('id','week');
					if(this.visible){
					tr.setAttribute('id','week');
				}else{
				tr.setAttribute('id','listweek');
				}
			 
			//	td = document.createElement('td');
				
				if(this.selectMultiple) { //if selectMultiple is enabled, create the associated weekObj objects
					//td.weekObj = new WeekHeading(this,td,sdt.getWeek(),row)
				}
				else //otherwise just set the class of the td for consistent look
				{
					//td.setAttribute('class','wkhead');
					//td.setAttribute('className','wkhead'); //<iehack>
								}
				
				//td.appendChild(document.createTextNode(sdt.getWeek()));			
				//tr.appendChild(td);
				i++;
			}
		}
		else if(i % 7 == 0) //otherwise, new row every 7 cells
		{
			row++;
			tr = document.createElement('div');
			 tr.setAttribute('id','week');
			
		}
		//create the day cells
		
		td = document.createElement('div');
		
		if(this.visible){
		td.setAttribute('id','day');
		}else{
			
			if(this.displayMonth != sdt.getMonth() ){
				
			}else{
				
		td.setAttribute('id','t'+sdt.getDate());	
			}
		//span = document.createElement('div');
		//span.setAttribute('id','t'+sdt.getDate());
		//td.appendChild(span);
		}
		
     if(this.visible){
		 tdd = document.createElement('div');
		 if(this.visible){
		 tdd.setAttribute('id','daycounter');
		 }else{
		 tdd.setAttribute('style','width:10px;');
		 }
			tdd.appendChild(document.createTextNode(sdt.getDate()));// +' ' +sdt.getUeDay()));
	 }else{

//td.appendChild(document.createTextNode(sdt.getDate()));// +' ' +sdt.getUeDay()));
td.innerHTML += "<span style='display:block;clear:both;'>" + sdt.getDate() + "</span>";
	 }


	 
		if(!this.visible){
			
		}else{
			
			if(this.displayMonth != sdt.getMonth() )
			{
				td.appendChild(tdd);
			}else{
			td.appendChild(tdd);
			span = document.createElement('div');
			span.setAttribute('id','t'+sdt.getDate());
			span.setAttribute('class','minimize_page');
			span.setAttribute('className','minimize_page');
			td.appendChild(span);
			more = document.createElement('div');
			more.setAttribute('id','more'+sdt.getDate());
			more.setAttribute('className','more');
			more.setAttribute('class','more');
			

			td.appendChild(more);
			}
		}
       

		

	  	

		var cell = new CalCell(this,td,sdt,row,this.visible);
		this.cells.push(cell);
		td.cellObj = cell;
			
		sdt.setDate(sdt.getDate() + 1); //increment the date

		 
		 tr.appendChild(td);
		
		tbody.appendChild(tr);
	}
	this.calCells.appendChild(tbody);
	
	if(!this.visible){
		listtitle = document.createElement('div');
		listtitle.setAttribute('id','listTitle');
		
		if(this.monthSelect.value==this.curDate.getMonth() && this.yearSelect.value==this.curDate.getFullYear()){
			listtitle.appendChild(document.createTextNode(this.curDate.getDate()));
		}else{
			listtitle.appendChild(document.createTextNode('1'));
		}
		tbodylistevents.appendChild(listtitle);
		tbodylistevents.appendChild(listtitle);
	}
	
	listdiv = document.createElement('div');
    listdiv.setAttribute('id','listviewWindow');
	
	tbodylistevents.appendChild(listdiv);
	
	
	
	
	
	
	this.calCells.appendChild(tbodylistevents);
	tbodylistevents
	this.reDraw();
	

	return this.calCells;
};
//-----------------------------------------------------------------------------
Byucal.prototype.reDraw = function () //PRIVATE: reapplies all the CSS classes for the calendar cells, usually called after chaning their state
{
	this.state = 1;
	var i,j;
	for(i=0;i<this.cells.length;i++) {
		this.cells[i].selected = false;
	}

	//alert(this.selectedDates);
	this.state = 2;
};
//-----------------------------------------------------------------------------
Byucal.prototype.deleteCells = function () //PRIVATE: removes the calendar cells from the DOM (does not delete the cell objects associated with them
{
	this.calCellContainer.removeChild(this.calCellContainer.firstChild); //get a handle on the cell table (optional - for less indirection)
	this.cells = new Array(); //reset the cells array
};
//-----------------------------------------------------------------------------
Byucal.prototype.goToMonth = function (year,month) //PUBLIC: sets the calendar to display the requested month/year
{
	this.monthSelect.value = this.displayMonth = month;
	this.yearSelect.value = this.displayYear = year;
	this.monthobj.value = this.displayMonth = month
	this.deleteCells();
	this.calCellContainer.appendChild(this.createCalCells());
	this.visible ? this.show() : this.hide();

	if(!this.visible){
		var temp_month=month;
		temp_month=eval(Number(temp_month)+1);

if(this.monthSelect.value==this.curDate.getMonth() && this.yearSelect.value==this.curDate.getFullYear()){
	     	generatelist(temp_month+'/'+this.curDate.getDate()+'/'+year);
			generateiconlist(temp_month+'/'+this.curDate.getDate()+'/'+year);
			
}else{
		    generatelist(temp_month+'/1/'+year);
			generateiconlist(temp_month+'/1/'+year);
			
}
	}else{
	
	loadMulti(month,year);
	}
};

Byucal.prototype.toggleMonth = function ()
{
	if(this.visible){
		this.monthSelect.value = this.displayMonth;
		this.yearSelect.value = this.displayYear ;
		this.monthobj.value = this.displayMonth ;
		this.deleteCells();
		this.calCellContainer.appendChild(this.createCalCells());
		loadMulti(this.displayMonth,this.displayYear);
		
	
	}else{
		
		this.monthSelect.value = this.displayMonth;
		this.yearSelect.value = this.displayYear ;
		this.monthobj.value = this.displayMonth ;
		this.deleteCells();
		this.calCellContainer.appendChild(this.createCalCells());
		
		
		var temp_month=this.displayMonth;
			temp_month=eval(Number(temp_month)+1);
	
			if(this.monthSelect.value==this.curDate.getMonth() && this.yearSelect.value==this.curDate.getFullYear()){
						generatelist(temp_month+'/'+this.curDate.getDate()+'/'+this.displayYear);
						generateiconlist(temp_month+'/'+this.curDate.getDate()+'/'+this.displayYear);
						
			}else{
						generatelist(temp_month+'/1/'+year);
						generateiconlist(temp_month+'/1/'+year);
						
			}
	
	

	}

}
Byucal.prototype.CssMonth = function (month) //PUBLIC: sets the calendar to display the requested month/year
{
	for(i=0;i<12;i++)
	{
	  	  test =this.monthobj.getElementsByTagName("a")[i];
	  test.setAttribute('class','');
	  test.setAttribute('className','');
	}
	month.setAttribute('class','currentlyDisplayedSelected');;
	month.setAttribute('className','currentlyDisplayedSelected');;
	
	//alert(month);
};


Byucal.prototype.CssEvent = function (month) //PUBLIC: sets the calendar to display the requested month/year
{
	for(i=0;i<this.event_sh.length;i++)
	{
	  test =this.eventobj.getElementsByTagName("a")[i];
	  test.setAttribute('class','');
	  test.setAttribute('className','');;
	  
	}
	
	month.setAttribute('class','currentlyDisplayedSelected');;
	month.setAttribute('className','currentlyDisplayedSelected');;
	
	//alert(month);
};
Byucal.prototype.CssCheckbox = function(checkbox)
{
	
check_currentmonth =this.dwnevents.getElementsByTagName("input")[8];
check_fall =this.dwnevents.getElementsByTagName("input")[9];
check_winter =this.dwnevents.getElementsByTagName("input")[10];
check_sumspr =this.dwnevents.getElementsByTagName("input")[11];




	var load_month=document.getElementById("xmlload").innerHTML;
	check_allinone =this.dwnevents.getElementsByTagName("input")[0];

	check_academic =this.dwnevents.getElementsByTagName("input")[1];
	check_alumni =this.dwnevents.getElementsByTagName("input")[2];
	check_conf =this.dwnevents.getElementsByTagName("input")[3];
	check_devotionals =this.dwnevents.getElementsByTagName("input")[4];
	check_events =this.dwnevents.getElementsByTagName("input")[5];
	check_arts =this.dwnevents.getElementsByTagName("input")[6];
	check_sports =this.dwnevents.getElementsByTagName("input")[7];

	

if(check_currentmonth.checked==true || check_fall.checked==true || check_winter.checked==true|| check_sumspr.checked==true){
		
		if(check_allinone.checked==true){	
			icalmulti="icalmulti.aspx?month="+load_month+"&alumni=false";
			window.open (icalmulti,"mywindow"); 
		}else if(check_academic.checked==true){
		
			icalmulti="icalmulti.aspx?month="+load_month+"&alumni=false&type=academic";
			window.open (icalmulti,"mywindow"); 

		}else if(check_conf.checked==true){
		   
			icalmulti="icalmulti.aspx?month="+load_month+"&alumni=false&type=conf";
			window.open (icalmulti,"mywindow"); 

		}else if(check_devotionals.checked==true){
		   
			icalmulti="icalmulti.aspx?month="+load_month+"&alumni=false&type=devotionals";
			window.open (icalmulti,"mywindow"); 

		}else if(check_events.checked==true){
		
			icalmulti="icalmulti.aspx?month="+load_month+"&alumni=false&type=events";
			window.open (icalmulti,"mywindow"); 

		}else if(check_arts.checked==true){
		    
			icalmulti="icalmulti.aspx?month="+load_month+"&alumni=false&type=arts";
			window.open (icalmulti,"mywindow"); 

		}else if(check_sports.checked==true){
		   
			icalmulti="icalmulti.aspx?month="+load_month+"&alumni=false&type=sports";
			window.open (icalmulti,"mywindow"); 

		}else if(check_alumni.checked==true){
		   
			icalmulti="icalmulti.aspx?month="+load_month+"&alumni=true";
			window.open (icalmulti,"mywindow"); 

		}
}
	
	
};

Byucal.prototype.CssShowCheck = function (month) //PUBLIC: sets the calendar to display the requested month/year
{
	var temp_event_sh=this.event_sh.length -2;
	 check_test =this.dwnevents.getElementsByTagName("input")[0];
	 if(check_test.getAttribute("class")=="test"){
		 var obj = document.getElementById("popupDownload");
			 obj.setAttribute('className','popupDownloadvisible');
			 obj.setAttribute('class','popupDownloadvisible');
				check_test.setAttribute('class','test1');
				check_test.setAttribute('className','test1');
	 }else{
		 	var obj = document.getElementById("popupDownload");
				obj.setAttribute('className','popupDownloadhidden');
				obj.setAttribute('class','popupDownloadhidden');
				
	
				check_test.setAttribute('class','test');
				check_test.setAttribute('className','test');
			
	 }
	 
	  

	

};




Byucal.prototype.LoadEvent = function (year,event_type) //PUBLIC: sets the calendar to display the requested month/year
{
	
	var event_t=event_type;
	event_type_array= new Array('academic','offCampus','conferences','devotionals','events','arts','sports','forums');
	number= event_t-1;
	document.getElementById('xmltype').innerHTML = event_type_array[number];
	this.monthSelect.value = this.displayMonth;
	this.yearSelect.value = this.displayYear = year;
	this.deleteCells();
	this.calCellContainer.appendChild(this.createCalCells());
	if(event_type == 0){
		
		
			if(!this.visible){
		var temp_month=this.displayMonth;
		temp_month=eval(Number(temp_month)+1);

if(this.monthSelect.value==this.curDate.getMonth() && this.yearSelect.value==this.curDate.getFullYear()){
	     	generatelist(temp_month+'/'+this.curDate.getDate()+'/'+year);
			generateiconlist(temp_month+'/'+this.curDate.getDate()+'/'+year);
			
}else{
		    generatelist(temp_month+'/1/'+year);
			generateiconlist(temp_month+'/1/'+year);
			
}
	}else{
	
	loadMulti((this.displayMonth),this.displayYear);
	}
	
	}else{
					if(!this.visible){
		var temp_month=this.displayMonth;
		temp_month=eval(Number(temp_month)+1);

if(this.monthSelect.value==this.curDate.getMonth() && this.yearSelect.value==this.curDate.getFullYear()){
	     	generatelist(temp_month+'/'+this.curDate.getDate()+'/'+year);
			generateiconlist(temp_month+'/'+this.curDate.getDate()+'/'+year);
			
}else{
		    generatelist(temp_month+'/1/'+year);
			generateiconlist(temp_month+'/1/'+year);
			
}
	}else{
	
	loadMulti((this.displayMonth),this.displayYear,event_type);
	}
		
		
		
		
	}

	
	
	
};

Byucal.prototype.Changemonth = function (year,month) //PUBLIC: sets the calendar to display the requested month/year
{
	this.monthSelect.value = this.displayMonth = month;
	this.monthobj.value = this.displayMonth = month;
	this.yearSelect.value = this.displayYear = year;
	this.deleteCells();
	this.calCellContainer.appendChild(this.createCalCells());

	loadMulti(month,year);
	
	
						if(!this.visible){
		var temp_month=month;
		temp_month=eval(Number(temp_month)+1);

	if(this.monthSelect.value==this.curDate.getMonth() && this.yearSelect.value==this.curDate.getFullYear()){
	     	generatelist(temp_month+'/'+this.curDate.getDate()+'/'+year);
			generateiconlist(temp_month+'/'+this.curDate.getDate()+'/'+year);
			
}else{
		    generatelist(temp_month+'/1/'+year);
			generateiconlist(temp_month+'/1/'+year);
			
}
	}else{
	
	loadMulti(month,year);
	}
	
};




//-----------------------------------------------------------------------------
Byucal.prototype.nextMonth = function () //PUBLIC: go to the next month.  if the month is december, go to january of the next year
{
	
	//increment the month/year values, provided they're within the min/max ranges
	if(this.monthSelect.value < 11) {
		this.monthSelect.value++;
	}
	else
	{
		if(this.yearSelect.value < this.rangeYearUpper)
		{
			this.monthSelect.value = 0;
			this.yearSelect.value++;
		}
		else {
			//alert(this.maxrange_caption);
		}
	}

	this.displayMonth = this.monthSelect.value;	
	this.displayYear = this.yearSelect.value;
	
	for(i=0;i<12;i++)
	{
	  	  test =this.monthobj.getElementsByTagName("a")[i];
	  test.setAttribute('class','');
	  test.setAttribute('className','');
	}
	month_sel =this.monthobj.getElementsByTagName("a")[this.displayMonth];
	month_sel.setAttribute('class','currentlyDisplayedSelected');;
	month_sel.setAttribute('className','currentlyDisplayedSelected');;


	
	//and refresh the calendar for the new month/year
	this.deleteCells();
	this.calCellContainer.appendChild(this.createCalCells());
	
	
	if(!this.visible){
		var temp_month=this.monthSelect.value;
		temp_month=eval(Number(temp_month)+1);

if(this.monthSelect.value==this.curDate.getMonth() && this.yearSelect.value==this.curDate.getFullYear()){
	     	generatelist(temp_month+'/'+this.curDate.getDate()+'/'+year);
			generateiconlist(temp_month+'/'+this.curDate.getDate()+'/'+year);
			
}else{
		    generatelist(temp_month+'/1/'+year);
			generateiconlist(temp_month+'/1/'+year);
			
}
	}else{
	
	loadMulti((this.monthSelect.value),this.yearSelect.value);
	}
	
	
	
	//alert(this.months_sh[this.displayMonth]+' '+this.displayYear );
};
//-----------------------------------------------------------------------------
Byucal.prototype.prevMonth = function () //PUBLIC: go to the previous month.  if the month is january, go to december of the previous year
{
	//increment the month/year values, provided they're within the min/max ranges
	if(this.monthSelect.value > 0)
		this.monthSelect.value--;
	else
	{
		if(this.yearSelect.value > this.rangeYearLower)
		{
			this.monthSelect.value = 11;
			this.yearSelect.value--;
		}
		else {
			alert(this.maxrange_caption);
		}
	}
	
	//assign the currently displaying month/year values
	this.displayMonth = this.monthSelect.value;
	this.displayYear = this.yearSelect.value;
	
		for(i=0;i<12;i++)
	{
	  	  test =this.monthobj.getElementsByTagName("a")[i];
	  test.setAttribute('class','');
	  test.setAttribute('className','');
	}
	month_sel =this.monthobj.getElementsByTagName("a")[this.displayMonth];
	month_sel.setAttribute('class','currentlyDisplayedSelected');;
	month_sel.setAttribute('className','currentlyDisplayedSelected');;
	
	//and refresh the calendar for the new month/year
	this.deleteCells();
	this.calCellContainer.appendChild(this.createCalCells());
			if(!this.visible){
		var temp_month=this.monthSelect.value;
		temp_month=eval(Number(temp_month)+1);

if(this.monthSelect.value==this.curDate.getMonth() && this.yearSelect.value==this.curDate.getFullYear()){
	     	generatelist(temp_month+'/'+this.curDate.getDate()+'/'+year);
			generateiconlist(temp_month+'/'+this.curDate.getDate()+'/'+year);
			
}else{
		    generatelist(temp_month+'/1/'+year);
			generateiconlist(temp_month+'/1/'+year);
			
}
	}else{
	
	loadMulti((this.monthSelect.value),this.yearSelect.value);
	}
	//alert(this.months_sh[this.displayMonth]+' '+this.displayYear );
};
//-----------------------------------------------------------------------------
Byucal.prototype.addZero = function (vNumber) //PRIVATE: pads a 2 digit number with a leading zero
{
	return ((vNumber < 10) ? '0' : '') + vNumber;
};
//-----------------------------------------------------------------------------
Byucal.prototype.addDates = function (dates,redraw)  //PUBLIC: adds the array "dates" to the calendars selectedDates array (no duplicate dates) and redraws the calendar
{
	var j,in_sd;
	for(var i=0;i<dates.length;i++)
	{	
		in_sd = false;
		for(j=0;j<this.selectedDates.length;j++)
		{
			if(dates[i].getUeDay() == this.selectedDates[j].getUeDay())
			{
				in_sd = true;
				break;
			}
		}
		if(!in_sd) { //if the date isn't already in the array, add it!
			this.selectedDates.push(dates[i]);
		}
	}
	if(redraw != false) {//redraw  the calendar if "redraw" is false or undefined
		this.reDraw();
	}
};
//-----------------------------------------------------------------------------
Byucal.prototype.removeDates = function (dates,redraw)  //PUBLIC: adds the dates to the calendars selectedDates array and redraws the calendar
{
	var j;
	for(var i=0;i<dates.length;i++)
	{
		for(j=0;j<this.selectedDates.length;j++)
		{
			if(dates[i].getUeDay() == this.selectedDates[j].getUeDay()) { //search for the dates in the selectedDates array, removing them if the dates match
				this.selectedDates.splice(j,1);
			}
		}
	}
	if(redraw != false) { //redraw  the calendar if "redraw" is false or undefined
		this.reDraw();
	}
};
//-----------------------------------------------------------------------------
Byucal.prototype.outputDate = function (vDate, vFormat) //PUBLIC: outputs a date in the appropriate format (DEPRECATED)
{
	var vDay			= this.addZero(vDate.getDate()); 
	var vMonth			= this.addZero(vDate.getMonth() + 1); 
	var vYearLong		= this.addZero(vDate.getFullYear()); 
	var vYearShort		= this.addZero(vDate.getFullYear().toString().substring(3,4)); 
	var vYear			= (vFormat.indexOf('yyyy') > -1 ? vYearLong : vYearShort);
	var vHour			= this.addZero(vDate.getHours()); 
	var vMinute			= this.addZero(vDate.getMinutes()); 
	var vSecond			= this.addZero(vDate.getSeconds()); 
	return vFormat.replace(/dd/g, vDay).replace(/mm/g, vMonth).replace(/y{1,4}/g, vYear).replace(/hh/g, vHour).replace(/nn/g, vMinute).replace(/ss/g, vSecond);
};
//-----------------------------------------------------------------------------
Byucal.prototype.updatePos = function (target) //PUBLIC: moves the calendar's position to target's location (day_view mode only)
{
	this.calendar.style.top = this.getTop(target) + this.topOffset + 'px'
	this.calendar.style.left = this.getLeft(target) + this.leftOffset + 'px'
}
//-----------------------------------------------------------------------------

/*****************************************************************************/
function CalHeading(owner,tableCell,dow)
{
	this.owner = owner;
	this.tableCell = tableCell;
	this.dayOfWeek = dow;
	
	//the event handlers

}
//-----------------------------------------------------------------------------
CalHeading.prototype.onclick = function ()
{
	//reduce indirection:
	
};
/*****************************************************************************/
function WeekHeading(owner,tableCell,week,row)
{
	this.metaco=this.headObj.owner;
	this.owner = owner;
	this.tableCell = tableCell;
	this.week = week;
	this.tableRow = row;

}
//-----------------------------------------------------------------------------
WeekHeading.prototype.onclick = function ()
{
	//reduce indirection:

};
/*****************************************************************************/
//-----------------------------------------------------------------------------
function CalCell(owner,tableCell,dateObj,row,visible)
{
	
	this.owner = owner;		//used primarily for event handling
	this.tableCell = tableCell; 			//the link to this cell object's table cell in the DOM
	this.cellClass;	
	this.cellinitial=0;	
	//the CSS class of the cell
	this.selected = false;	//whether the cell is selected (and is therefore stored in the owner's selectedDates array)
	this.date = new Date(dateObj);
	this.dayOfWeek = this.date.getDay();
	this.week = this.date.getWeek();
	this.tableRow = row;
	this.visibility=visible;

	if(this.owner.displayMonth == this.date.getMonth() )
	{
	//assign the event handlers for the table cell element
		
		 this.tableCell.onclick = this.onclick;
		this.tableCell.onmouseover = this.onmouseover;
		this.tableCell.onmouseout = this.onmouseout;
		
	}
	//and set the CSS class of the table cell
	this.setClass();
}
//-----------------------------------------------------------------------------
CalCell.prototype.onmouseover = function () //replicate CSS :hover effect for non-supporting browsers <iehack>
{

var cell = this.cellObj;
if(!cell.selected)
	{
	this.setAttribute('class', 'man');
	this.setAttribute('className','man');
	}
	

	
};
//-----------------------------------------------------------------------------
CalCell.prototype.onmouseout = function () //replicate CSS :hover effect for non-supporting browsers <iehack>
{
	this.cellObj.setClass();
};
//-----------------------------------------------------------------------------
CalCell.prototype.onclick = function () 
{


	var cell = this.cellObj;
	var visible=cell.visibility;
	var owner=cell.owner;


	var d = cell.date;
	var curr_date = d.getDate();
	var curr_month = d.getMonth();
	var curr_year = d.getFullYear();
	if(visible){
	expandWindow(curr_date);
	}else{
			
	
			for(i=0;i<owner.cells.length;i++)
			{
				for(j=0;j<owner.selectedDateslist.length;j++) { //if the cell's date is in the selectedDates array, set its selected property to true
					if(owner.cells[i].date.getUeDay() == owner.selectedDateslist[j].getUeDay() ) {
						owner.cells[i].selected = false;
					}
				}
			
			owner.cells[i].setClass();
			}
			cell.selected=true;   
		
		                   
		owner.selectedDateslist.push(cell.date);        
		this.setAttribute('class', 'clickdate');
		this.setAttribute('className', 'clickdate');
		
		
	curr_month=curr_month+1;
	generatelist(curr_month+'/'+curr_date+'/'+curr_year);
	document.getElementById("listTitle").innerHTML=curr_date;
	}


};
//-----------------------------------------------------------------------------
CalCell.prototype.setClass = function ()  //private: sets the CSS class of the cell based on the specified criteria
{
	
	
	
	
 if(this.date.getDate() == 1 && this.owner.displayMonth == this.date.getMonth() && this.cellinitial==0 && !this.owner.visible){
		 if(this.date.getFullYear() == this.owner.curDate.getFullYear()){
			 if(this.date.getMonth() != this.owner.curDate.getMonth() ){
				this.selected=true;
				this.owner.selDate=this.date.getDate() ;
			 }
		  }else{
			    this.selected=true;
				this.owner.selDate=this.date.getDate() ;
		  }
	  }
	  else{
		this.owner.selDate=this.date.getDate() ;  
	  }
	
	

   
	if(this.selected) {
		
	  //  alert(this.owner.selDate);
		this.cellinitial=1;
		this.cellClass = 'clickdate';	
		

        
	}
	else if(this.owner.displayMonth != this.date.getMonth() ) {
		this.cellClass = 'notmnth';	
	}
	else if(this.date.getDay() > 0 && this.date.getDay() < 6) {
		this.cellClass = 'wkday';
	}
	else {
		this.cellClass = 'wkend';
	}
	
	if(this.date.getFullYear() == this.owner.curDate.getFullYear() && this.date.getMonth() == this.owner.curDate.getMonth() && this.date.getDate() == this.owner.curDate.getDate()) {
		this.cellClass = 'curdate';
	}
		
	
	
	
	this.tableCell.setAttribute('class',this.cellClass);
	this.tableCell.setAttribute('className',this.cellClass); //<iehack>
	
	
};
/*****************************************************************************/
Date.prototype.getDayOfYear = function () //returns the day of the year for this date
{
	return parseInt((this.getTime() - new Date(this.getFullYear(),0,1).getTime())/86400000 + 1);
};
//-----------------------------------------------------------------------------
Date.prototype.getWeek = function () //returns the day of the year for this date
{
	return parseInt((this.getTime() - new Date(this.getFullYear(),0,1).getTime())/604800000 + 1);
};

//-----------------------------------------------------------------------------
Date.prototype.getUeDay = function () //returns the number of DAYS since the UNIX Byucal - good for comparing the date portion
{
	return parseInt(Math.floor((this.getTime() - this.getTimezoneOffset() * 60000)/86400000)); //must take into account the local timezone
};
//-----------------------------------------------------------------------------
Date.prototype.dateFormat = function(format)
{
	if(!format) { // the default date format to use - can be customized to the current locale
		format = 'm/d/Y';
	}
	LZ = function(x) {return(x < 0 || x > 9 ? '' : '0') + x};
	var MONTH_NAMES = new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
	var DAY_NAMES = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
	format = format + "";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=this.getFullYear().toString();
	var M=this.getMonth()+1;
	var d=this.getDate();
	var E=this.getDay();
	var H=this.getHours();
	var m=this.getMinutes();
	var s=this.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	// Convert real this parts into formatted versions
	var value = new Object();
	//if (y.length < 4) {y=''+(y-0+1900);}
	value['Y'] = y.toString();
	value['y'] = y.substring(2);
	value['n'] = M;
	value['m'] = LZ(M);
	value['F'] = MONTH_NAMES[M-1];
	value['M'] = MONTH_NAMES[M+11];
	value['j'] = d;
	value['d'] = LZ(d);
	value['D'] = DAY_NAMES[E+7];
	value['l'] = DAY_NAMES[E];
	value['G'] = H;
	value['H'] = LZ(H);
	if (H==0) {value['g']=12;}
	else if (H>12){value['g']=H-12;}
	else {value['g']=H;}
	value['h']=LZ(value['g']);
	if (H > 11) {value['a']='pm'; value['A'] = 'PM';}
	else { value['a']='am'; value['A'] = 'AM';}
	value['i']=LZ(m);
	value['s']=LZ(s);
	//construct the result string
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
		}
	return result;
	
};
/*****************************************************************************/

/*********************************************start rollover********************************/




if (typeof document.attachEvent!='undefined') {
   window.attachEvent('onload',init);
   document.attachEvent('onmousemove',moveMouse);
   
   }
else {
   window.addEventListener('load',init,false);
   document.addEventListener('mousemove',moveMouse,false);
  // document.addEventListener('click',checkMove,true);
}

var oDv=document.createElement("div");
var dvHdr=document.createElement("div");
var dvBdy=document.createElement("div");
var dvTime=document.createElement("div");
var windowlock,boxMove,fixposx,fixposy,lockX,lockY,fixx,fixy,ox,oy,boxLeft,boxRight,boxTop,boxBottom,evt,mouseX,mouseY,boxOpen,totalScrollTop,totalScrollLeft;
boxOpen=false;

ox=10;
oy=10;
lockX=0;
lockY=0;

function init() {
	oDv.appendChild(dvHdr);
	oDv.appendChild(dvBdy);
	oDv.appendChild(dvTime);
	oDv.style.position="absolute";
	oDv.style.visibility='hidden';
	oDv.style.zIndex='6';
	document.body.appendChild(oDv);	
}

function defHdrStyle() {
	//dvHdr.innerHTML='<img  style="vertical-align:middle"  src="../info.gif">  '+dvHdr.innerHTML;
	dvHdr.style.fontWeight='bold';
	dvHdr.style.width='150px';

	dvHdr.style.fontFamily='arial';
	dvHdr.style.border='1px solid #A5CFE9';
	dvHdr.style.padding='3';
	dvHdr.style.fontSize='11';
	dvHdr.style.color='#4B7A98';
	dvHdr.style.background='#D5EBF9';
	dvHdr.style.filter='alpha(opacity=85)'; // IE
	dvHdr.style.opacity='0.85'; // FF
}

function defBdyStyle() {
	dvBdy.style.borderBottom='1px solid #A5CFE9';
	dvBdy.style.borderLeft='1px solid #A5CFE9';
	dvBdy.style.borderRight='1px solid #A5CFE9';
	dvBdy.style.width='150px';
	dvBdy.style.fontFamily='arial';
	dvBdy.style.fontSize='11';
	dvBdy.style.padding='3';
	dvBdy.style.color='#1B4966';
	dvBdy.style.background='#FFFFFF';
	dvBdy.style.filter='alpha(opacity=85)'; // IE
	dvBdy.style.opacity='0.85'; // FF
}

function defTimStyle() {
	dvTime.style.borderBottom='1px solid #A5CFE9';
	dvTime.style.borderLeft='1px solid #A5CFE9';
	dvTime.style.borderRight='1px solid #A5CFE9';
	dvTime.style.width='150px';
	dvTime.style.fontFamily='arial';
	dvTime.style.fontSize='11';
	dvTime.style.padding='3';
	dvTime.style.color='#1B4966';
	dvTime.style.background='#FFFFFF';
	dvTime.style.filter='alpha(opacity=85)'; // IE
	dvTime.style.opacity='0.85'; // FF
}

function checkElemBO(txt) {
if (!txt || typeof(txt) != 'string') return false;
if ((txt.indexOf('header')>-1)&&(txt.indexOf('type')>-1)&&(txt.indexOf('[')>-1)&&(txt.indexOf('[')>-1)) 
   return true;
else
   return false;
}

function scanBO(curNode) {
	  if (checkElemBO(curNode.title)) {
         curNode.boHDR=getParam('header',curNode.title);
         curNode.boBDY=getParam('type',curNode.title);
		 curNode.boTIME=getParam('time',curNode.title);
			curNode.boCSSBDY=getParam('cssbody',curNode.title);			
			curNode.boCSSHDR=getParam('cssheader',curNode.title);
			curNode.boCSSTME=getParam('csstime',curNode.title);
			curNode.IEbugfix=(getParam('hideselects',curNode.title)=='on')?true:false;
			curNode.fixX=parseInt(getParam('fixedrelx',curNode.title));
			curNode.fixY=parseInt(getParam('fixedrely',curNode.title));
			curNode.absX=parseInt(getParam('fixedabsx',curNode.title));
			curNode.absY=parseInt(getParam('fixedabsy',curNode.title));
			curNode.offY=(getParam('offsety',curNode.title)!='')?parseInt(getParam('offsety',curNode.title)):10;
			curNode.offX=(getParam('offsetx',curNode.title)!='')?parseInt(getParam('offsetx',curNode.title)):10;
			curNode.fade=(getParam('fade',curNode.title)=='on')?true:false;
			curNode.fadespeed=(getParam('fadespeed',curNode.title)!='')?getParam('fadespeed',curNode.title):0.04;
			curNode.delay=(getParam('delay',curNode.title)!='')?parseInt(getParam('delay',curNode.title)):0;
			if (getParam('requireclick',curNode.title)=='on') {
				curNode.requireclick=true;
				
				//document.all?curNode.attachEvent('onmouseover',hideBox):curNode.addEventListener('mouseover',hideBox,false);
			}
			else {// Note : if requireclick is on the stop clicks are ignored   			
   		
   		}
			curNode.windowLock=getParam('windowlock',curNode.title).toLowerCase()=='off'?false:true;
			curNode.title='';
			curNode.hasbox=1;
	   }
	   else
	      curNode.hasbox=2;   
}


function getParam(param,list) {
	var reg = new RegExp('([^a-zA-Z]' + param + '|^' + param + ')\\s*=\\s*\\[\\s*(((\\[\\[)|(\\]\\])|([^\\]\\[]))*)\\s*\\]');
	var res = reg.exec(list);
	var returnvar;
	if(res)
		return res[2].replace('[[','[').replace(']]',']');
	else
		return '';
}

function Left(elem){	
	var x=0;
	if (elem.calcLeft)
		return elem.calcLeft;
	var oElem=elem;
	while(elem){
		 if ((elem.currentStyle)&& (!isNaN(parseInt(elem.currentStyle.borderLeftWidth)))&&(x!=0))
		 	x+=parseInt(elem.currentStyle.borderLeftWidth);
		 x+=elem.offsetLeft;
		 elem=elem.offsetParent;
	  } 
	oElem.calcLeft=x;
	return x;
	}

function Top(elem){
	 var x=0;
	 if (elem.calcTop)
	 	return elem.calcTop;
	 var oElem=elem;
	 while(elem){		
	 	 if ((elem.currentStyle)&& (!isNaN(parseInt(elem.currentStyle.borderTopWidth)))&&(x!=0))
		 	x+=parseInt(elem.currentStyle.borderTopWidth); 
		 x+=elem.offsetTop;
	         elem=elem.offsetParent;
 	 } 
 	 oElem.calcTop=x;
 	 return x;
 	 
}

var ah,ab,at;
function applyStyles() {
	if(ab)
		oDv.removeChild(dvBdy);
	if (ah)
		oDv.removeChild(dvHdr);
	if (at)
		oDv.removeChild(dvTime);
	dvHdr=document.createElement("div");
	dvTime=document.createElement("div");
	dvBdy=document.createElement("div");
	
	CBE.boCSSBDY?dvBdy.className=CBE.boCSSBDY:defBdyStyle();
	CBE.boCSSHDR?dvHdr.className=CBE.boCSSHDR:defHdrStyle();
	CBE.boCSSTIME?dvTime.className=CBE.boCSSTIME:defTimStyle();
	dvHdr.innerHTML=CBE.boHDR;
	dvTime.innerHTML=CBE.boTIME;
	dvBdy.innerHTML=CBE.boBDY;
	
	ah=false;
	ab=false;
	at=false;
	if (CBE.boHDR!='') {		
		oDv.appendChild(dvHdr);
		ah=true;
	}	
		if (CBE.boTIME!=''){
		oDv.appendChild(dvTime);
		at=true;
	}
	if (CBE.boBDY!=''){
		oDv.appendChild(dvBdy);
		ab=true;
	}
	
}

var CSE,iterElem,LSE,CBE,LBE, totalScrollLeft, totalScrollTop, width, height ;
var ini=false;

// Customised function for inner window dimension
function SHW() {
   if (document.body && (document.body.clientWidth !=0)) {
      width=document.body.clientWidth;
      height=document.body.clientHeight;
   }
   if (document.documentElement && (document.documentElement.clientWidth!=0) && (document.body.clientWidth + 20 >= document.documentElement.clientWidth)) {
      width=document.documentElement.clientWidth;   
      height=document.documentElement.clientHeight;   
   }   
   return [width,height];
}


var ID=null;
function moveMouse(e) {
   //boxMove=true;
	e?evt=e:evt=event;
	
	CSE=evt.target?evt.target:evt.srcElement;
	
	if (!CSE.hasbox) {
	   // Note we need to scan up DOM here, some elements like TR don't get triggered as srcElement
	   iElem=CSE;
	   while ((iElem.parentNode) && (!iElem.hasbox)) {
	      scanBO(iElem);
	      iElem=iElem.parentNode;
	   }	   
	}
	
	if ((CSE!=LSE)&&(!isChild(CSE,dvHdr))&&(!isChild(CSE,dvTime))&&(!isChild(CSE,dvBdy))){		
	   if (!CSE.boxItem) {
			iterElem=CSE;
			while ((iterElem.hasbox==2)&&(iterElem.parentNode))
					iterElem=iterElem.parentNode; 
			CSE.boxItem=iterElem;
			}
		iterElem=CSE.boxItem;
		if (CSE.boxItem&&(CSE.boxItem.hasbox==1))  {
			LBE=CBE;
			CBE=iterElem;
			if (CBE!=LBE) {
				applyStyles();
				if (!CBE.requireclick)
					if (CBE.fade) {
						if (ID!=null)
							clearTimeout(ID);
						ID=setTimeout("fadeIn("+CBE.fadespeed+")",CBE.delay);
					}
					else {
						if (ID!=null)
							clearTimeout(ID);
						COL=1;
						ID=setTimeout("oDv.style.visibility='visible';ID=null;",CBE.delay);						
					}
				if (CBE.IEbugfix) {hideSelects();} 
				fixposx=!isNaN(CBE.fixX)?Left(CBE)+CBE.fixX:CBE.absX;
				fixposy=!isNaN(CBE.fixY)?Top(CBE)+CBE.fixY:CBE.absY;			
				lockX=0;
				lockY=0;
				boxMove=true;
				ox=CBE.offX?CBE.offX:10;
				oy=CBE.offY?CBE.offY:10;
			}
		}
		else if (!isChild(CSE,dvHdr) && !isChild(CSE,dvBdy)&& !isChild(CSE,dvTime) && (boxMove))	{
			// The conditional here fixes flickering between tables cells.
			if ((!isChild(CBE,CSE)) || (CSE.tagName!='TABLE')) {   			
   			CBE=null;
   			if (ID!=null)
  					clearTimeout(ID);
   			fadeOut();
   			showSelects();
			}
		}
		LSE=CSE;
	}
	else if (((isChild(CSE,dvHdr) || isChild(CSE,dvBdy)|| isChild(CSE,dvTime))&&(boxMove))) {
		totalScrollLeft=0;
		totalScrollTop=0;
		
		iterElem=CSE;
		while(iterElem) {
			if(!isNaN(parseInt(iterElem.scrollTop)))
				totalScrollTop+=parseInt(iterElem.scrollTop);
			if(!isNaN(parseInt(iterElem.scrollLeft)))
				totalScrollLeft+=parseInt(iterElem.scrollLeft);
			iterElem=iterElem.parentNode;			
		}
		if (CBE!=null) {
			boxLeft=Left(CBE)-totalScrollLeft;
			boxRight=parseInt(Left(CBE)+CBE.offsetWidth)-totalScrollLeft;
			boxTop=Top(CBE)-totalScrollTop;
			boxBottom=parseInt(Top(CBE)+CBE.offsetHeight)-totalScrollTop;
			doCheck();
		}
	}
	
	if (boxMove&&CBE) {
		// This added to alleviate bug in IE6 w.r.t DOCTYPE
		bodyScrollTop=document.documentElement&&document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop;
		bodyScrollLet=document.documentElement&&document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft;
		mouseX=evt.pageX?evt.pageX-bodyScrollLet:evt.clientX-document.body.clientLeft;
		mouseY=evt.pageY?evt.pageY-bodyScrollTop:evt.clientY-document.body.clientTop;
		if ((CBE)&&(CBE.windowLock)) {
			mouseY < -oy?lockY=-mouseY-oy:lockY=0;
			mouseX < -ox?lockX=-mouseX-ox:lockX=0;
			mouseY > (SHW()[1]-oDv.offsetHeight-oy)?lockY=-mouseY+SHW()[1]-oDv.offsetHeight-oy:lockY=lockY;
						mouseX > (SHW()[0]-dvBdy.offsetWidth-ox)?lockX=-mouseX-ox+SHW()[0]-dvBdy.offsetWidth:lockX=lockX;
			mouseX > (SHW()[0]-dvTime.offsetWidth-ox)?lockX=-mouseX-ox+SHW()[0]-dvTime.offsetWidth:lockX=lockX;

			
		}
		oDv.style.left=((fixposx)||(fixposx==0))?fixposx:bodyScrollLet+mouseX+ox+lockX+"px";
		oDv.style.top=((fixposy)||(fixposy==0))?fixposy:bodyScrollTop+mouseY+oy+lockY+"px";		
		
	}
}

function doCheck() {	
	if (   (mouseX < boxLeft)    ||     (mouseX >boxRight)     || (mouseY < boxTop) || (mouseY > boxBottom)) {
		if (!CBE.requireclick)
			fadeOut();
		if (CBE.IEbugfix) {showSelects();}
		CBE=null;
	}
}

function pauseBox(e) {
   e?evt=e:evt=event;
	boxMove=false;
	evt.cancelBubble=true;
}

function showHideBox(e) {
	oDv.style.visibility=(oDv.style.visibility!='visible')?'visible':'hidden';
}

function hideBox(e) {
	oDv.style.visibility='hidden';
}

var COL=0;
var stopfade=false;
function fadeIn(fs) {
		ID=null;
		COL=0;
		oDv.style.visibility='visible';
		fadeIn2(fs);
}

function fadeIn2(fs) {
		COL=COL+fs;
		COL=(COL>1)?1:COL;
		oDv.style.filter='alpha(opacity='+parseInt(100*COL)+')';
		oDv.style.opacity=COL;
		if (COL<1)
		 setTimeout("fadeIn2("+fs+")",20);		
}


function fadeOut() {
	oDv.style.visibility='hidden';
	
}

function isChild(s,d) {
	while(s) {
		if (s==d) 
			return true;
		s=s.parentNode;
	}
	return false;
}

var cSrc;
function checkMove(e) {
	e?evt=e:evt=event;
	cSrc=evt.target?evt.target:evt.srcElement;
	if ((!boxMove)&&(!isChild(cSrc,oDv))) {
		fadeOut();
		if (CBE&&CBE.IEbugfix) {showSelects();}
		boxMove=true;
		CBE=null;
		

	}
	
		


}

function showSelects(){
   var elements = document.getElementsByTagName("select");
   for (i=0;i< elements.length;i++){
      elements[i].style.visibility='visible';
   }
   
}

function hideSelects(){
   var elements = document.getElementsByTagName("select");
   for (i=0;i< elements.length;i++){
   elements[i].style.visibility='hidden';
   }
}



