function clsEvent(eventID,eventDate,title,description,address,city,zipCode,state,firstName,lastName,displayReport,country,eventFrequency,spanDays,repeatEvery,repeatWhichTime,stopAfter,occursEvery,occursWhichDay,repeatWhichMonth,startTime,endTime,memberID,regStartDate,regEndDate,isregistered,regoccurrencedate,seatsRemaining,location)
{
        this.EventID=eventID;
        this.EventDate=eventDate;
        this.Title=title;
        this.Description=description;
        this.Location=location;
        this.Address=address;
        this.City=city;
        this.ZipCode=zipCode;
        this.State=state;
        this.FirstName=firstName;
        this.LastName=lastName;
        this.DisplayReport=displayReport;
        this.Country=country;
        this.EventFrequency=eventFrequency;
        this.SpanDays=spanDays;
        this.RepeatEvery=repeatEvery;
        this.RepeatWhichTime=repeatWhichTime;
        this.StopAfterDate=stopAfter;
        this.OccursEvery=occursEvery;
        this.OccursWhichDay=occursWhichDay;
        this.RepeatWhichMonth=repeatWhichMonth;
        this.StartTime=startTime;
        this.EndTime=endTime;
        this.MemberID=memberID;
        this.RegStartDate=regStartDate;
        this.RegEndDate=regEndDate;
        this.IsRegistered=isregistered;
        this.RegisteredOccurrenceDate=regoccurrencedate;
        this.SeatsRemaining = parseInt(seatsRemaining);
        this.costs = new Array();
}

clsEvent.prototype.addCost = function(objCost){
        this.costs[this.costs.length] = objCost;
}

function clsEvents(cID,mID,fName,lName,location,address,city,state,zip,email,isAdmin)
{
        this.events = new Array();
        this.TreasurerClubID=cID;
        this.TreasurerMemberID=mID;
        this.TreasurerFirstName=fName;
        this.TreasurerLastName=lName;
        this.TreasurerLocation=location;
        this.TreasurerAddress=address;
        this.TreasurerCity=city;
        this.TreasurerState=state;
        this.TreasurerZip=zip;
        this.TreasurerEmail=email;
        this.IsAdmin = isAdmin;
	 this.members = new Array();
}

clsEvents.prototype.addEvent = function(objEvent){
        this.events[this.events.length] = objEvent;
}

function clsCost(eventID,eventCost,eventCostName,eventCostID)
{
        this.EventID=eventID;
        this.EventCost=eventCost;
        this.EventCostName=eventCostName;
        this.EventCostID=eventCostID;
}

function clsMember(memberID,memberName)
{
	this.MemberID=memberID;
	this.MemberName=memberName;
}

function leapYear(year) {
        if (year % 4 == 0){ 
                // basic rule
                return true; 
                // is leap year 
        }else{ 
                //else not needed when statement is "return"
                return false; 
                //is not leap year
        }
}

function resizePosWindow(objDiv){
        //if browser supports window.innerWidth
        if (window.innerWidth){
                if(typeof(objDiv.style.minHeight!='undefined')){
                        objDiv.style.minHeight='175px';
                        var left = ((window.innerWidth/2)-(parseInt(objDiv.style.width)/2));
                        var top = ((window.innerHeight/2)-(parseInt(objDiv.style.minHeight)/2));
                }else{
                        objDiv.style.height='175px';
                        var left = ((window.innerWidth/2)-(parseInt(objDiv.style.width)/2));
                        var top = ((window.innerHeight/2)-(parseInt(175)/2));
                }
        }else{
                objDiv.style.height='175px';
                var left = ((document.body.clientWidth/2)-(parseInt(objDiv.style.width)/2));
                var top = ((document.body.clientHeight/2)-(parseInt(175)/2));
        }
	//get scroll pos
	var scrollTop = document.body.scrollTop;
	if(scrollTop == 0)
	{
		if (window.pageYOffset){
			scrollTop = window.pageYOffset;
		}else{
			scrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}
	}
	//add scroll pos to top
        objDiv.style.top=top+scrollTop;
        objDiv.style.left=left;
}

function showEvent(EventID,EventDate,mID,isAdmin){
var objDiv=document.getElementById('Event');
var objEvent = null;
var objEventCost = null;
var disablebutton='';
var tmpDate='';
var arrDate='';
var dtRegDate='';
var dtNow='';
resizePosWindow(objDiv);

for(var i=0; i<objEvents.events.length;i++){
        objEvent=objEvents.events[i];
        if(EventID==objEvent.EventID){
                var strCostHTML='';
                var bHasFees=false;
                //strHTML='<table border=0 cellpadding=0 cellspacing=0 width="100%">';
                //strHTML+='<tr><td class="MenuHeader" align="center" valign="middle" width="95%" height="17"><font class="menuheadertextsmallbold">' + objEvent.Title + '</font></td><td class="MenuHeader" align="left" valign="middle" width="5%"><a href="javascript:void(0);" id="closeevent" name="closeevent" onclick="hideEvent();" border="0"><img src="../php/Images/deleteicon.gif" border=0></a></td></tr>';
                //strHTML+='<tr><td colspan="2">';
                //strHTML+='<div style="height:230px;overflow:auto;width:520px;background-Color:#FFFFFF;">';
                //strHTML+='<table border=0 cellpadding=0 cellspacing=0 width=518>';
                //if(objEvent.Description!=''){
                        //strHTML+='<tr><td width=25>&nbsp;</td><td class=bodytextsmall width="493" NOWRAP><font color=#000000><br><b>Description:</b><br>' + objEvent.Description + '</font></td></tr>';
                //}
                //if(objEvent.StartTime!=''||objEvent.EndTime!=''){
                        //strHTML+='<tr><td width=25>&nbsp;</td><td class=bodytextsmall width="493" NOWRAP><br><font color=#000000><b>Time:</b></font></td></tr>';
                        //strHTML+='<tr><td width=25>&nbsp;</td><td class=bodytextsmall width="493" NOWRAP>';
                        //strHTML+='<font color=#000000>' + objEvent.StartTime;
                        //if(objEvent.EndTime!=''){
                               // strHTML+=' - ' + objEvent.EndTime;
                        //}
                       // strHTML+='</font><br>';
                        //strHTML+='</td></tr>';
                //}
                //if(objEvent.Location!=''||objEvent.Address!=''||objEvent.City!=''||objEvent.ZipCode!=''||objEvent.State!=''||objEvent.Country!=''){
                        //strHTML+='<tr><td width=25>&nbsp;</td><td class=bodytextsmall width="493" NOWRAP><br><font color=#000000><b>Location:</b></font></td></tr>';
                        //strHTML+='<tr><td width=25>&nbsp;</td><td class=bodytextsmall width="493" NOWRAP>';
                        //if(objEvent.Location!=''){
                               // strHTML+='<font color=#000000>' + objEvent.Location + '</font><br>';
                        //}
                        //if(objEvent.Address!=''){
                              //  strHTML+='<font color=#000000>' + objEvent.Address + '</font><br>';
                        //}
                        //if(objEvent.City!=''||objEvent.State!=''){
                              //  strHTML+='<font color=#000000>' + objEvent.City + ', ' + objEvent.State + ' </font><br>';
                       // }
                       //if(objEvent.ZipCode!=''){
                        //        strHTML+='<font color=#000000>' + objEvent.ZipCode +'</font><br>';
                        //}
                        //if(objEvent.Country!=''){
                        //        strHTML+='<font color=#000000>' + objEvent.Country +'</font>';
                        //}else{
                        //        strHTML+='<font color=#000000>' + 'UNITED STATES' +'</font>';
                        //}
                        //strHTML+='</td></tr>';
                //}
               // strHTML+='<tr><td width=25>&nbsp;</td><td class=bodytextsmall width="493" NOWRAP><br><font color=#000000><b>Event Fee(s):</b></font></td></tr>';
                for(var j=0; j<objEvent.costs.length;j++){
                        objEventCost = objEvent.costs[j];
                        if(EventID==objEventCost.EventID){
                                if(objEventCost.EventCost!=''){
                                        bHasFees=true;
					break;
                                        //if(strCostHTML==''){
                                                //strCostHTML='<tr><td width=25>&nbsp;</td><td class=bodytextsmall width="473" NOWRAP>';
                                        //}
                                        //strCostHTML+='<font color=#000000>' + //objEventCost.EventCostName + ' - $' + //objEventCost.EventCost + '</font><br>';
                                }
                        }
                }
                //if(strCostHTML==''){
                        //strCostHTML='<tr><td width=25>&nbsp;</td><td class=bodytextsmall width="493" NOWRAP><font color=#000000>None<br></font></td></tr>';
               // }else{
                      //  strCostHTML+='</td></tr>';
                //}
                //strHTML+=strCostHTML;
                //if(objEvent.FirstName!=''||objEvent.LastName!=''){
                        //strHTML+='<tr><td width=25>&nbsp;</td><td class=bodytextsmall width="493" NOWRAP><font color=#000000><br><b>Event added by:</b><br>' + //objEvent.FirstName + ' ' + objEvent.LastName + '</font></td></tr>';
                //}
                //strHTML+='</table>';
                //strHTML+='</div>';
                //strHTML+='</td></tr>';
                //strHTML+='<tr><td colspan="2" align="center" valign="middle" height="30">';

                //determine if registration button should be disabled or not
                //if(objEvent.RegStartDate != ''){
                        //check if registration start date is less/equal to now
                        //tmpDate = objEvent.RegStartDate;
                        //arrDate = tmpDate.split("-");
                        //if(arrDate.length > 2){
                       // dtRegDate = new Date(arrDate[0],(arrDate[1]-1),arrDate[2]);
                       // dtNow = new Date();
                       // if(dtNow < dtRegDate || mID == ""){
                        //        disablebutton='DISABLED';
                        //}
                       // }
                //}
                //if(objEvent.RegEndDate != ''&&disablebutton!='DISABLED'){
                        //check if registration end date is greater/equal to event date
                        //tmpDate = objEvent.RegEndDate;
                        //arrDate = tmpDate.split("-");
                        //if(arrDate.length > 2){
                       // dtRegDate = new Date(arrDate[0],(arrDate[1]-1),arrDate[2]);
                       // dtNow = new Date();
                       // if(dtNow > dtRegDate || mID == ""){
                      //          disablebutton='DISABLED';
                      //  }
                     //   }
                //}
                //if(objEvent.IsRegistered == "true")
                //{
                      //  if(objEvent.RegisteredOccurrenceDate!=""){
                             //   if(IsRegisteredForDate(objEvent.RegisteredOccurrenceDate,EventDate)){
                                        //strHTML+='<font class="bodytextsmall"><font color=red>You have already registered for this event.<br>&nbsp;</font></font>';
                                //}
                        //}else{
                         //       strHTML+='<font color=red><br><br>You have already registered for this event.<br><br></font>';
                       // }
               // }

                //if(mID != "" && objEvent.RegStartDate != ''){
                   //     strHTML+='<input type="button" id="register" name="register" class="buttons" value="Register Now" onclick="registerEvent(' + objEvent.EventID + ',' + bHasFees + ','+'\''+EventDate+'\''+',false);" ' + disablebutton + '>';
                //}

                //determine whether to disable attendee button
               // disablebutton='DISABLED';
               // if(objEvent.DisplayReport!='0' || isAdmin=='true' || mID==objEvent.MemberID){
                 //       disablebutton='';
               // }

               // if(mID != "" && objEvent.RegStartDate != ''){
                      //  strHTML+='&nbsp;<input type="button" id="viewattendees" name="viewattendees" class="buttons" value="Attendee Report" onclick="getAttendeeReport(' + objEvent.EventID + ','+'\''+EventDate+'\''+');" ' + disablebutton + '>';
                //}

                //if(objEvent.City!=''&&objEvent.State!=''){
                        //add map
                        //strHTML+='&nbsp;<input type="button" id="viewmap" name="viewmap" class="buttons" value="View Map" onclick="getMap(\'' + objEvent.Address + '\',\'' + objEvent.City + '\',\'' + objEvent.State + '\',\'' + objEvent.Country + '\');">';
               // }

                //if(objEvents.IsAdmin){
                        //add edit button
                       // strHTML+='&nbsp;<input type="button" id="editevent" name="editevent" class="buttons" value="Edit Event" onclick="editEvent(\'' + objEvent.EventID + '\');">';
                //}
                //if(objEvents.IsAdmin && objEvent.RegStartDate != ''){
                        //add event registrants
                       // strHTML+='&nbsp;<input type="button" id="addregs" name="addregs" class="buttons" value="Add Registrants" onclick="registerEvent(' + objEvent.EventID + ',' + bHasFees + ','+'\''+EventDate+'\''+',true);">';
                //}
                //strHTML+='<br>&nbsp;</td></tr>';
                //strHTML+='</table>';
                //objDiv.innerHTML=strHTML;
                break;
        }
}
//objDiv.style.display='block';
registerEvent(objEvent.EventID,EventDate,false);
}

function IsRegisteredForDate(regoccurrencedates,currenteventdate)
{
        var registereddates = regoccurrencedates.split("~");
        var arrDate = currenteventdate.split('-');
        var curDay = arrDate[2];
        var curMonth = arrDate[1];
        if(curDay < 10)
        {
                curDay = '0' + curDay;
        }
        if(curMonth < 10)
        {
                curMonth = '0' + curMonth;
        }
        currenteventdate = arrDate[0] + '-' + curMonth + '-' + curDay;
        if(registereddates.length > 0)
        {
                for(var i=0; i < registereddates.length; i++){
                        if(registereddates[i] == currenteventdate){
                                return true;
                        }
                }
        }
        return false;
}

function editEvent(eid){
      window.location.href='Manager.php?ID='+eid+'&dt=AE';
}

function addEventRegistrants(eid,red){
      window.location.href='Manager.php?dt=MER&ID='+eid+'&red='+red;
}

function getAttendeeReport(eid,red){
        window.location.href='Manager.php?dt=R&type=9&eid='+eid+'&red='+red;
}

function getMap(Address,City,State,Country){
        if(Country == "UNITED STATES")
        {
                mapCountry = "US";
        }else{
                mapCountry = Country;
        }
        mapurl='http://www.mapquest.com/maps/map.adp?city=' + City + '&state=' + State + '&address=' +  Address + '&country=' + mapCountry + '&zoom=7';
        var windowprops = "location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=yes,width=700,height=500";
        popup = window.open(mapurl,"MapPopup",windowprops);
}

function hideEvent(){
        var objDiv=document.getElementById('Event');
        objDiv.style.display='none';
}

function registerEvent(EventID,EventDate,bAddReg){
var objDiv=document.getElementById('Event');
var objEvent = null;
var objEventCost = null;
var bHasFees=false;
var disablebutton='';
var tmpDate='';
var arrDate='';
var dtRegDate='';
var dtNow='';
var bIsRegistered=false;
resizePosWindow(objDiv);

for(var i=0; i<objEvents.events.length;i++){
        objEvent = objEvents.events[i];
        if(EventID==objEvent.EventID){
                //determine if registration button should be disabled or not
                if(objEvent.RegStartDate != ''){
                        //check if registration start date is less/equal to now
                        tmpDate = objEvent.RegStartDate;
                        arrDate = tmpDate.split("-");
                        if(arrDate.length > 2){
                        dtRegDate = new Date(arrDate[0],(arrDate[1]-1),arrDate[2]);
                        dtNow = new Date();
                        if(dtNow < dtRegDate){
                                disablebutton='DISABLED';
                        }
                        }
                }
                if(objEvent.RegEndDate != ''&&disablebutton!='DISABLED'){
                        //check if registration end date is greater/equal to event date
                        tmpDate = objEvent.RegEndDate;
                        arrDate = tmpDate.split("-");
                        if(arrDate.length > 2){
                        dtRegDate = new Date(arrDate[0],(arrDate[1]-1),arrDate[2]);
                        dtNow = new Date();
                        if(dtNow > dtRegDate){
                                disablebutton='DISABLED';

                        }
                        }
                }
		//is already registered?
                if(objEvent.IsRegistered == "true"&&!bAddReg)
                {
                        if(objEvent.RegisteredOccurrenceDate!=""){
                                if(IsRegisteredForDate(objEvent.RegisteredOccurrenceDate,EventDate)){
					bIsRegistered = true;
                                }
                        }else{
				bIsRegistered = true;
                        }
                }

		//has costs/fees?
                for(var j=0; j<objEvent.costs.length;j++){
                        objEventCost = objEvent.costs[j];
                        if(EventID==objEventCost.EventID){
                                if(objEventCost.EventCost!=''){
                                        bHasFees=true;
					break;
                                }
                        }
                }
                var strCostHTML='';
                strHTML='<table border=0 cellpadding=0 cellspacing=0 width=100% height="100%">';
                strHTML+='<tr><td class="MenuHeader" align="center" valign="middle" width="95%" height="17"><font class="menuheadertextsmallbold">Order Form</font></td><td class="MenuHeader" align="left" valign="middle" width="5%"><a href="javascript:void(0);" id="closeevent" name="closeevent" onclick="hideEvent();" border="0"><img src="Images/deleteicon.gif" border=0></a></td></tr>';
                strHTML+='<tr><td colspan="2">';
                strHTML+='<div style="height:205px;overflow:auto;width:550px;">';
                strHTML+='<table border=0 cellpadding=0 cellspacing=0 width=498>';
                strHTML+='<tr><td width=25>&nbsp;</td><td class=bodytextsmall width="525" NOWRAP valign="top"><br><br><font color=#000000><b>Event</b></font></td></tr>';
                strHTML+='<tr><td width=25>&nbsp;</td><td class=bodytextsmall width="525" NOWRAP valign="top" height=5><font color=#000000>' + objEvent.Title + '</font></td></tr>';
                strHTML+='<tr><td width=25>&nbsp;</td><td class=bodytextsmall width="525" NOWRAP valign="top"><br><font color=#000000><b>Quantity:</b></font></td></tr>';
                if(bHasFees){
                        for(var j=0; j<objEvent.costs.length;j++){
                                objEventCost=objEvent.costs[j];
                                if(EventID==objEventCost.EventID){
                                        if(objEventCost.EventCost!=''){
	                                        if(objEventCost.EventCost!=0){
        	                                        strCostHTML+='<tr><td width=25>&nbsp;</td><td class=bodytextsmall width="525" NOWRAP valign="top"><input type="text" class="textbox" name="quantity" value="0" maxlength=8 size=3><input type="hidden" name="eventcosts" value="'+objEventCost.EventCost+'"><input type="hidden" name="eventcostids" value="'+objEventCost.EventCostID+'"><input type="hidden" name="eventcostnames" value="'+objEventCost.EventCostName+'">';
                	                                strCostHTML+='&nbsp;&nbsp;<font color=#000000>' + objEventCost.EventCostName + ' x $' + objEventCost.EventCost + '</font></td></tr>';
                        	                }else{
		                                        strCostHTML+='<tr><td width=25>&nbsp;</td><td class=bodytextsmall width="525" NOWRAP valign="top"><input type="text" class="textbox" name="quantity" value="0" maxlength=8 size=3><input type="hidden" name="eventcosts" value="'+objEventCost.EventCost+'"><input type="hidden" name="eventcostids" value="'+objEventCost.EventCostID+'"><input type="hidden" name="eventcostnames" value="'+objEventCost.EventCostName+'">';
                	                                strCostHTML+='&nbsp;&nbsp;<font color=#000000>' + objEventCost.EventCostName + '</font></td></tr>';
						}
                                        }
                                }
                        }

                }else{
                        strCostHTML='<tr><td width=25>&nbsp;</td><td class=bodytextsmall width="525" NOWRAP valign="top"><input type="text" class="textbox" name="quantity" value="1" maxlength=8 size=3><input type="hidden" name="eventcosts" value="Free"><input type="hidden" name="eventcostids" value=""><input type="hidden" name="eventcostnames" value=""></td></tr>'; 
                }
                strHTML+=strCostHTML;

		  if(bAddReg){
			if(objEvents.members.length > 0){
                	   strHTML+='<tr><td width=25>&nbsp;</td><td class=bodytextsmall width="525" NOWRAP valign="top"><br><font color=#000000><b>Member:</b></font></td></tr>';
			   strHTML+='<tr><td width=25>&nbsp;</td><td class=bodytextsmall width="525" NOWRAP valign="top"><select class="select" name="registeringmember">';
			   var objEventMember = null;
                        for(var j=0; j<objEvents.members.length; j++){
                                objEventMember=objEvents.members[j];
				     if(objEventMember != null){
                                	if(objEventMember.MemberID!=''){
        	                  		strHTML+='<option value="'+objEventMember.MemberID+'">'+objEventMember.MemberName+'</option>';
                        	     	}
				     }
                        }
			    strHTML+='</select></td></tr>';
			}
                }
                strHTML+='</table>';
                strHTML+='</div>';
                strHTML+='</td></tr>';
		if(bIsRegistered){
			strHTML+='<tr><td class=bodytextblack align=center><font color=red>You have already registered for this event.</font></td></tr>';
		}

		if(!bAddReg && bHasFees && objEvents.TreasurerEmail !=''){
			strHTML+='<tr><td class=bodytextblack align=center><input type="checkbox" name="payoffline" value="yes"><font color=#000000>&nbsp;I\'ll pay offline by paying the Club Treasurer directly.</font></td></tr>';
		}
		if(bAddReg || (bHasFees && objEvents.TreasurerEmail == '')){
			strHTML+='<tr><td class=bodytextsmall>&nbsp;</td></tr><tr><td><input type="hidden" name="payoffline" value="yes"></td></tr>';
		}
                strHTML+='<tr><td class=bodytextblack align=center>To "Unregister", use a negative number (i.e. -2). Refunds will be handled by your Treasurer.<br>&nbsp;</td></tr>';
                strHTML+='<tr><td align="center" valign="middle" height="30"><input type="submit" name="submit" class="buttons" value="';
                if(bHasFees){
                        strHTML+='Register';
                }else{
                        strHTML+='Complete';
                }
                strHTML+='" ';
		if((bAddReg && objEvents.members.length == 0)||disablebutton!=''){
		strHTML+='disabled';
		}
		strHTML+='><br>&nbsp;</td></tr>';
                strHTML+='</table><input type="hidden" name="EventID" value="'+EventID+'"><input type="hidden" name="EventName" value="' + objEvent.Title + '"><input type="hidden" name="MemberID" value="'+objEvents.TreasurerMemberID+'">';
                strHTML+='<input type="hidden" name="quantityandcostids" value=""><input type="hidden" name="totalprice" value=""><input type="hidden" name="ProcessType" value="EVENTS"><input type="hidden" name="ClubID" value="'+objEvents.TreasurerClubID+'">';
                if(bHasFees){
                        strHTML+='<input type="hidden" name="DisplayCCForm" id="DisplayCCForm" value="true">';
                }else{
                        strHTML+='<input type="hidden" name="DisplayCCForm" id="DisplayCCForm" value="false">';
                }       
                strHTML+='<input type="hidden" name="firstname" value="'+objEvents.TreasurerFirstName+'">';
                strHTML+='<input type="hidden" name="lastname" value="'+objEvents.TreasurerLastName+'">';
                strHTML+='<input type="hidden" name="location" value="'+objEvents.TreasurerLocation+'">';
                strHTML+='<input type="hidden" name="address1" value="'+objEvents.TreasurerAddress+'">';
                strHTML+='<input type="hidden" name="city" value="'+objEvents.TreasurerCity+'">';
                strHTML+='<input type="hidden" name="state" value="'+objEvents.TreasurerState+'">';
                strHTML+='<input type="hidden" name="zip" value="'+objEvents.TreasurerZip+'">';
                strHTML+='<input type="hidden" name="ReoccurringEventDate" value="'+EventDate+'">';
                strHTML+='<input type="hidden" name="totalquantity" value="1">';
                strHTML+='<input type="hidden" name="paypalbusiness" value="'+objEvents.TreasurerEmail+'">';
                strHTML+='<input type="hidden" name="seatsremaining" value="' + objEvent.SeatsRemaining + '">';
                objDiv.innerHTML=strHTML;
                break;
        }
}
objDiv.style.display='block';
}

function verifyForm(objForm){

var strElName='';
var strElValue='';
var bSubmit=true;
var strEventDetails='';
var strQuantityandCostIDS='';
var totalprice=0;
var totalquantity=0;
if(typeof(objForm.elements)!='undefined'){
        for(var i=0; i < objForm.elements.length; i++){
                if(typeof(objForm.elements[i].type)!='undefined'){
                        if(objForm.elements[i].type=='text'){
                                strElName=objForm.elements[i].name;
                                strElValue=objForm.elements[i].value;
                                if(strElName=='quantity'){
                                        if(strElValue==''){
                                                alert("Quantity must contain a value.");
                                                objForm.elements[i].focus();
                                                bSubmit=false;
                                                break;
                                        }else{
                                                if(isNaN(strElValue)){
                                                        alert("Quantity must be numeric.");
                                                        objForm.elements[i].focus();
                                                        bSubmit=false;
                                                        break;
                                                }
                                        }
                                }else{
                                        if(strElValue==''){
                                                alert("Field must contain a value.");
                                                objForm.elements[i].focus();
                                                bSubmit=false;
                                                break;
                                        }
                                }
                        }
                }
        }
}
        if(bSubmit){
                var seatsremaining=parseInt(objForm.seatsremaining.value);
                //store event order details such as the quantity/cost/name of cost
                if(typeof(objForm.quantity.length)!='undefined'){
                        var FoundCount=0;
                        for(var i=0; i < objForm.quantity.length; i++){
                                if(objForm.quantity[i].value!=''&&objForm.quantity[i].value!='0'){
                                        FoundCount+=1;
                                        if(strQuantityandCostIDS==''){
                                                strQuantityandCostIDS=objForm.quantity[i].value + '^' + objForm.eventcostids[i].value + '^' + objForm.eventcosts[i].value + '^' + objForm.eventcostnames[i].value;
                                        }else{
                                                strQuantityandCostIDS+='~' + objForm.quantity[i].value + '^' + objForm.eventcostids[i].value + '^' + objForm.eventcosts[i].value + '^' + objForm.eventcostnames[i].value;
                                        }
                                        if(objForm.eventcosts[i].value != "Free"){
                                                totalprice+=objForm.quantity[i].value * objForm.eventcosts[i].value;
                                        }
                                        totalquantity=totalquantity + parseInt(objForm.quantity[i].value);
                                }
                        }
                        if(totalquantity > seatsremaining){
                                alert('The quantity order exceeds the total seats(' + seatsremaining + ') remaining for the event.');
                                bSubmit=false;
                        }
                        if(FoundCount==0){
                                alert('Quantity must be specified.');
                                bSubmit=false;
                        }else{
                                objForm.totalprice.value=parseFloat(totalprice);
                        }
                }else{
                        if(objForm.quantity.value!=''&&objForm.quantity.value!='0'){
                                var quantity = parseInt(objForm.quantity.value);
                                strQuantityandCostIDS=quantity + '^' + objForm.eventcostids.value + '^' + objForm.eventcosts.value + '^' + objForm.eventcostnames.value;
                                if(objForm.eventcosts.value != "Free"){
                                        totalprice=quantity * objForm.eventcosts.value;
                                        objForm.totalprice.value=parseFloat(totalprice);
                                }else{
                                        objForm.totalprice.value=0;
                                }
                                if(quantity > seatsremaining){
                                        alert('The quantity order exceeds the total seats(' + seatsremaining + ') remaining for the event.');
                                        bSubmit=false;
                                }
                        }else{
                                alert('Quantity must be specified.');
                                objForm.quantity.focus();
                                bSubmit=false;
                        }
                }
        }
        if(bSubmit){
                var bPayOffLine = false;
                if(typeof(objForm.payoffline) != 'undefined')
                {
                        if(objForm.payoffline.checked)
                        {
                                bPayOffLine = true;
                        }
                }
		  //if add reg select found then payoffline as well
		  if(typeof(objForm.registeringmember) != 'undefined'){
			bPayOffLine = true;
		  }
                objForm.quantityandcostids.value=strQuantityandCostIDS;
                if(objForm.DisplayCCForm.value=='true'&&!(bPayOffLine)){
                        var win = window.open("PayPalProcess.php?ptype=E","processWindow");
                }else{
                        objForm.target="_self";
                }
                var objDiv=document.getElementById('Event');
                objDiv.style.display='none';
                return true;
        }else{
                return false;
        }
}
function getDays(month, year) {
        // create array to hold number of days in each month
        var ar = new Array(12);
        ar[0] = 31; // January
        ar[1] = (leapYear(year)) ? 29 : 28; // February
        ar[2] = 31; // March
        ar[3] = 30; // April
        ar[4] = 31; // May
        ar[5] = 30; // June
        ar[6] = 31; // July
        ar[7] = 31; // August
        ar[8] = 30; // September
        ar[9] = 31; // October
        ar[10] = 30; // November
        ar[11] = 31; // December

        // return number of days in the specified month (parameter)
        return ar[month];
}

function getMonthName(month) {
        // create array to hold name of each month
        var ar = new Array(12);
        ar[0] = "January";
        ar[1] = "February";
        ar[2] = "March";
        ar[3] = "April";
        ar[4] = "May";
        ar[5] = "June";
        ar[6] = "July";
        ar[7] = "August";
        ar[8] = "September";
        ar[9] = "October";
        ar[10] = "November";
        ar[11] = "December";

        // return name of specified month (parameter)
        return ar[month];
}
var now;
function nextMonth(){
        // get same date in the next month
        var dt_next_month = new Date(now);
        dt_next_month.setMonth(dt_next_month.getMonth() + 1);
        if (dt_next_month.getDate() != now.getDate()){
                dt_next_month.setDate(0);
        }
        window.location.href='Manager.php?dt=C&d='+dt_next_month;
}
function prevMonth(){
        // get same date in the previous month
        var dt_prev_month = new Date(now);
        dt_prev_month.setMonth(dt_prev_month.getMonth() - 1);
        if (dt_prev_month.getDate() != now.getDate()){
                dt_prev_month.setDate(0);
        }
        window.location.href='Manager.php?dt=C&d='+dt_prev_month;
}
function prevYear(){
        // get same date in the previous year
        var dt_prev_year = new Date(now);
        dt_prev_year.setYear(dt_prev_year.getYear() - 1);
        alert(window.location.href);
        window.location.href='Manager.php?dt=C&d='+dt_prev_year;
}
function getNewDate(){
        //get month
        var monthval = document.forms[0].ddmonth.options[document.forms[0].ddmonth.selectedIndex].value;
        var yearval = document.forms[0].ddyear.options[document.forms[0].ddyear.selectedIndex].value;
        var dateval = monthval + '/01/' + yearval;
        window.location.href='Manager.php?dt=C&d='+dateval;
}
function replaceIt(sString, sReplaceThis, sWithThis) { 
if (sReplaceThis != "" && sReplaceThis != sWithThis) { 
var counter = 0; 
var start = 0; 
var before = ""; 
var after = ""; 
while (counter<sString.length) { 
start = sString.indexOf(sReplaceThis, counter); 
if (start == -1) { 
break; 
} else { 
before = sString.substr(0, start); 
after = sString.substr(start + sReplaceThis.length, sString.length); 
sString = before + sWithThis + after; 
counter = before.length + sWithThis.length; 
} 
} 
} 
return sString; 
} 

function addEventLink(EventDate,objEvent,CalorListDisplay,ReoccurringBeginDate,mID,isAdmin,isPrintMode,isDetailPage){
        //event name & desc
        var eventName = objEvent.Title;
        var eventDesc = objEvent.Description;
	var clubID = '<?php echo getSessionVariable("ClubID"); ?>';
        //determine what type of link to add if in calendar mode or list mode
        switch(CalorListDisplay){
        case "L":
                if(!(isPrintMode)){
			if(!(isDetailPage)){ //if not viewing from details page
				//if mID specified they are logged in so do redirect to that page
				if(mID!=''&&clubID!=''){
					document.write('<tr><td nowrap>&nbsp;</td><td class="bodytext" align="left" valign="top" width="40" nowrap><a href="Manager.php?dt=VED&ID='+objEvent.EventID+'&d='+EventDate+'" border=0><img src="../php/Images/viewicon.gif" ALT="View '+eventName+'" border=0></a>&nbsp;</td><td class="bodytext" align="left" valign="top" nowrap>'+EventDate+'</td><td class="bodytext" align="left" valign="top" width="220">'+eventName+'</td><td class="bodytext" align="left" valign="top" width="300">'+eventDesc+'</td></tr>');
				}else{
					document.write('<tr><td nowrap>&nbsp;</td><td class="bodytext" align="left" valign="top" width="40" nowrap><a href="index.php?dt=VED&eid='+objEvent.EventID+'&d='+EventDate+'" border=0><img src="../php/Images/viewicon.gif" ALT="View '+eventName+'" border=0></a>&nbsp;</td><td class="bodytext" align="left" valign="top" nowrap>'+EventDate+'</td><td class="bodytext" align="left" valign="top" width="220">'+eventName+'</td><td class="bodytext" align="left" valign="top" width="300">'+eventDesc+'</td></tr>');
				}
			}else{
				//viewing from details page so display different layout
				//event details
				document.write('<tr><td height="1" colspan="5" class="HorzontalRuleCellBackground"><img src="Images/FormSpacer.gif"></td></tr><tr><td height="20"><span class="bodytext">'+EventDate+'</span></td><td align="center"><span class="bodytext" align="center">'+eventName+'</span></td><td align="center"><a href="Manager.php?dt=VED&ID='+objEvent.EventID+'&d='+EventDate+'" class="formlink">View</a></td><td width="5"></td><td align="center">&nbsp;</td></tr>');
			}
                }else{
			document.write('<tr><td class="bodytextbold" align="left" valign="top" nowrap>&nbsp;</td><td class="bodytextblack" align="left" valign="top" nowrap>'+EventDate+'</td><td class="bodytextblack" align="left" valign="top" width="220">'+eventName+'</td><td class="bodytextblack" align="left" valign="top" width="300">'+eventDesc+'</td></tr>');
                }
        break;
        case "C":
                //get event link container
                var objDayDiv = document.getElementById(EventDate);
                if(objDayDiv!=null){
                        //create link
                        
                        eventHover=eventName;
			   eventName = "\u2022" + eventName;
                        //if(eventName.length > 17){
                                //eventName = eventName.substr(0,14)+'...';
                        //}

                        if(!(isPrintMode)){
                                var objLink = document.createElement('a');
				//if mID specified they are logged in so do redirect to that page
				if(mID!=''&&clubID!=''){
                                	objLink.setAttribute('href','Manager.php?dt=VED&ID='+objEvent.EventID+'&d='+EventDate);
				}else{
                                	objLink.setAttribute('href','index.php?dt=VED&eid='+objEvent.EventID+'&d='+EventDate);
				}
                                objLink.setAttribute('title',eventHover);
                                objLink.className = 'calendarlink';
                                objLink.id = 'calendarlink'+EventDate;
                                objLink.appendChild(document.createTextNode(eventName));
                                //append to day div
                                objDayDiv.appendChild(objLink);
                        }else{
                                objDayDiv.className = 'bodytextblack';
                                objDayDiv.appendChild(document.createTextNode(eventName));
                        }
                        var objBR = document.createElement('br');
                        objDayDiv.appendChild(objBR);
                }
        break;
        default:
        break;
        }
}

function isEventDate(curDay,curMonth,curYear,objEvent){
        var curDate=curYear;
        if(curMonth < 10){
                curDate = curDate+'-0'+curMonth;
        }else{
                curDate = curDate+'-'+curMonth;
        }
        if(curDay < 10){
                curDate = curDate+'-0'+curDay;
        }else{
                curDate = curDate+'-'+curDay;
        } 
        //add calendar event link
        if(curDate==objEvent.EventDate){
                return true;
        }else{
                return false;
        }
}

function SetRepeatingEvents(curMonth,curYear,calendarEndDay,firstDay,CalorListDisplay,mID,isAdmin,isPrintMode,isDetailPage){
var objEvent=null;
var startDate=null;
var calendarEndDate=calendarEndDay+'/'+curMonth+'/'+curYear;
var diff;
var arrStartDate=null;
var startday=1;
var totalDays=0;
var curWeek=1;
var reoccurringbegindate='';
var prevMonth=12;//default to december
for(var i=0; i < objEvents.events.length; i++){
	objEvent=objEvents.events[i];
	startDate = objEvent.EventDate;
	arrStartDate = startDate.split('-');
	startday=1;
	totalDays=0;    
	ReoccurringBeginDate='';
	curWeek=1;
	switch(objEvent.EventFrequency){
		case '1':
			var haseventinprevmonth=false;
			//calculate the start day if event is set in previous month and span date specified
			if(curMonth != 1){
				prevMonth=curMonth-1;
			}
			if(prevMonth == arrStartDate[1]){
				startday=parseFloat(arrStartDate[2]);
				// number of days in current month
				var daysinprevmonth = getDays(parseFloat(arrStartDate[1])-1, parseFloat(arrStartDate[0]));
				var eventdaysinprevmonth = (daysinprevmonth - startday)+1;//add 1 to account day event falls on
				//adjust the span days
				objEvent.SpanDays = objEvent.SpanDays - eventdaysinprevmonth;
				startday=1;
				var eventMonth = curMonth.toString();
				if(eventMonth.length < 2){
					eventMonth = '0' + eventMonth;
				}
				objEvent.EventDate=curYear.toString() + '-' + eventMonth + '-' + "01"
			}
			for(var day=startday; day <= calendarEndDay; day++){
				if(isEventDate(day,curMonth,curYear,objEvent)){
					for (var spandays = 1; spandays <= objEvent.SpanDays; spandays++){
						//if day is less than end calendar day then ok otherwise break out;
						if(day <= calendarEndDay){
								if(spandays==1){
									//capture event date for attendee etc..
									ReoccurringBeginDate=curYear+'-'+curMonth+'-'+day;
								}
								repeatEventDate=curYear+'-'+parseInt(curMonth)+'-'+parseInt(day);
								//check stop after date
								//if(!(isPassedStopDate(repeatEventDate,objEvent.StopAfterDate)){
								//add calendar event link
								addEventLink(curYear+'-'+curMonth+'-'+day,objEvent,CalorListDisplay,ReoccurringBeginDate,mID,isAdmin,isPrintMode,isDetailPage);
								//add span to day increment
								day++;
						}else{
							break;
						}
					}
				}
			}
		break;
		case '2':
			//var doPrevMonthSpanDays=false;
			//var prevRepeatWhichTime=objEvent.RepeatWhichTime;
			//check repeater type day,week,month,year
			if((curMonth==arrStartDate[1]&&curYear==arrStartDate[0])||(objEvent.RepeatWhichTime=='MONTHS'||objEvent.RepeatWhichTime=='YEARS'))
			{
				startday=parseFloat(arrStartDate[2]);
			}
			//calculate the start day if event is set in previous month and span date specified
			//if((curMonth > arrStartDate[1]) || (curMonth == 1 && arrStartDate[1] == 12)){
				// number of days in current month
				//var daysinprevmonth = getDays(parseFloat(arrStartDate[1])-1, parseFloat(arrStartDate[0]));
				//var eventdaysinprevmonth = (daysinprevmonth - parseFloat(arrStartDate[2]))+1;//add 1 to account day event falls on
				//adjust the span days
				//objEvent.SpanDays = objEvent.SpanDays - eventdaysinprevmonth;
				////startday=1;
				////objEvent.RepeatWhichTime='DAYS';
				//doPrevMonthSpanDays=true;
			///}
			for(var day=startday; day <= calendarEndDay; day++){
				//check to make sure that stop date limit hasn't been reached
				if(!(isPassedStopDate(curYear,curMonth,day,objEvent.StopAfterDate))){
					//get difference from start date
					diff=DateDiff(parseFloat(arrStartDate[1]),parseFloat(arrStartDate[2]),parseFloat(arrStartDate[0]),curMonth,day,curYear,objEvent.RepeatWhichTime);
					//if less than zero it means event date falls within current month so by pass otherwise proceed
					if(diff >= 0){
					if((diff % parseInt(objEvent.RepeatEvery))==0){
						//set max totals
						if(objEvent.RepeatWhichTime=='WEEKS'){
							//totalDays = parseFloat(startday) + ((curWeek * 7) * objEvent.RepeatEvery);
							totalDays = day;
							totalDays += parseFloat(objEvent.SpanDays);
						}else{
							totalDays = calendarEndDay;
						}
						for (var spandays = 1; spandays <=  objEvent.SpanDays; spandays++){
							//if day is less than end calendar day then ok otherwise break out;
							if(day <= totalDays){
								//check stop after date if current date greater than stopafter then dont display
								if(!(isPassedStopDate(curYear,curMonth,day,objEvent.StopAfterDate))){
									if(spandays==1){
										//capture event date for attendee etc..
										ReoccurringBeginDate=curYear+'-'+parseFloat(curMonth)+'-'+parseFloat(day);
									}
									repeatEventDate=curYear+'-'+parseFloat(curMonth)+'-'+parseFloat(day);
									//add calendar event link
									addEventLink(repeatEventDate,objEvent,CalorListDisplay,ReoccurringBeginDate,mID,isAdmin,isPrintMode,isDetailPage);
									//add span to day increment
									if(spandays < objEvent.SpanDays){
										day++;
									}
								}else{
									break;
								}
							}else{
								break;
							}
						}
						if(objEvent.RepeatWhichTime=='MONTHS'||objEvent.RepeatWhichTime=='YEARS'){
							//if month or year repeater and found then exit after outputting
							day=totalDays;
							break;
						}
						if(objEvent.RepeatWhichTime=='WEEKS'){
							day=(totalDays-1);
							curWeek+=1;
						}					////if(doPrevMonthSpanDays){
							//startday=parseFloat(arrStartDate[2]);
							//objEvent.RepeatWhichTime=prevRepeatWhichTime;
						//}
					}
					}
				}else{
					break;
				}
			}
		break;
		case '3':
			var day=1;
			var dayPos = firstDay;
			var week = 1;
			//floating events type
			diff=DateDiff(arrStartDate[1],arrStartDate[2],arrStartDate[0],curMonth,calendarEndDay,curYear,'MONTHS');
			//if less than zero it means event date falls within current month so by pass otherwise proceed
			if(diff >= 0){
				//check for remainder by doing modulus if there is a remainder than 
				//this event is not repeatable on this current month otherwise it is
				if(diff % parseInt(objEvent.RepeatWhichMonth) == 0){
					var totalWeeks=(Math.ceil((calendarEndDay + firstDay - 1) / 7));
					var totalLastWeekDays=parseInt(7-(((totalWeeks * 7) - (firstDay-1))-calendarEndDay))
					//change the week to plus one wek if the first calendar day is greater than OccursWhichDay value
					if(parseInt(objEvent.OccursEvery)==5){
						if(parseInt(objEvent.OccursWhichDay) > totalLastWeekDays){
							//change the week to previous one because that week is where that last day resides
							objEvent.OccursEvery=(totalWeeks-1);
						}else{
							objEvent.OccursEvery=totalWeeks;
						}
					}else{
						if(parseInt(objEvent.OccursWhichDay) < firstDay){
							objEvent.OccursEvery=parseInt(objEvent.OccursEvery)+1;
						}
					}
					for (week; week<= totalWeeks; ++week){
						if(!(isPassedStopDate(curYear,curMonth,day,objEvent.StopAfterDate))){
						for(var weekday = dayPos; weekday <= 7; ++weekday){
							if(!(isPassedStopDate(curYear,curMonth,day,objEvent.StopAfterDate))){
							if(parseInt(objEvent.OccursWhichDay)==weekday){
								if((week==parseInt(objEvent.OccursEvery))){
									//add link
									for (var spandays = 1; spandays <= objEvent.SpanDays; spandays++){
										//if day is less than last date then ok otherwise break out;
										//if the day exceeeds the calendar end day then we need to start setting remainder days from
										//previous month if span days moves through into next month
										if(day > calendarEndDay && parseInt(curMonth) > parseInt(arrStartDate[1])){
											day=1;
											//recalculate span days
											var eventstartday=parseFloat(arrStartDate[2]);
											//calculate the start day if event is set in previous month and span date specified
											// number of days in current month
											var daysinprevmonth = getDays(parseInt(arrStartDate[1])-1, parseInt(arrStartDate[0]));
											var eventdaysinprevmonth = (daysinprevmonth - eventstartday)+1;//add 1 to account day event falls on
											//adjust the span days
											objEvent.SpanDays = objEvent.SpanDays - eventdaysinprevmonth;
											spandays = 1;
										}
										if(day <= calendarEndDay){
											if(!(isPassedStopDate(curYear,curMonth,day,objEvent.StopAfterDate))){
												if(spandays==1){
													//capture event date for attendee etc..
													ReoccurringBeginDate=curYear+'-'+parseInt(curMonth)+'-'+parseInt(day);
												}
												repeatEventDate=curYear+'-'+parseInt(curMonth)+'-'+parseInt(day);
												//add calendar event link
												addEventLink(repeatEventDate,objEvent,CalorListDisplay,ReoccurringBeginDate,mID,isAdmin,isPrintMode,isDetailPage);
												//add span to day increment
														if(spandays < objEvent.SpanDays){
														day++;
														}
											}else{
												break;
											}
										}else{
											break;
										}
									}
								}
							}
							day++;
							}else{
								break;
							}
						}
						dayPos=1;
						}else{
							break;
						}
					}
				}
			}
		break;
		default:
		break;
	}
}
}

function isPassedStopDate(curYear,curMonth,day,StopAfterDate){
        var dtStopDate;
        var dtCurDate;
        var arrDate;
        var retVal=false;
        if(StopAfterDate!=''){
                arrDate = StopAfterDate.split("-");
                dtCurDate = new Date(curYear,(curMonth-1),day);
                dtStopDate = new Date(arrDate[0],(arrDate[1]-1),arrDate[2]);
                if(dtCurDate > dtStopDate)
                {
                        retVal = true;
                }
        }
        return retVal;
}

function DateDiff(date1, date2)
{
        //for now returns difference in seconds only.
        var objDate1=new Date(date1);
        var objDate2=new Date(date2);
        return (objDate1.getTime()-objDate2.getTime())/1000;
}


function DateDiff(mo1, dy1, yr1, mo2, dy2, yr2,diffType){
var strDate1=yr1+'/'+mo1+'/'+dy1+' 12:00:00';
var strDate2=yr2+'/'+mo2+'/'+dy2+' 12:00:00';
var Date1 = new Date(strDate1);
var Date2 = new Date(strDate2);
  switch (diffType) {
    case "s":return parseInt((Date2 - Date1) / 1000);
    case "n":return parseInt((Date2 - Date1) / 60000);
    case "h":return parseInt((Date2 - Date1) / 3600000);
    case "DAYS":return Math.round(((Date2 - Date1) / 86400000)*10)/10;
    case "WEEKS":return Math.round((Date2 - Date1) / (86400000 * 7)*10)/10;
    case "MONTHS":return (Date2.getMonth()+1)+((Date2.getFullYear()-Date1.getFullYear())*12) - (Date1.getMonth()+1);
    case "YEARS":
        var months=(Date2.getMonth()+1)+((Date2.getFullYear()-Date1.getFullYear())*12) - (Date1.getMonth()+1);
        return Math.round((months/12)*10)/10;
  }
}
function setCal(mID,isAdmin,d,isPrintMode) {
        var curMonth='';
        var curYear='';
        var dDate=d;
        // standard time attributes
        if(dDate==''){
                now = new Date();
        }else{
                now = new Date(dDate);
        }
        if(curMonth == '' && curYear == ''){
                curYear = now.getFullYear();
                curMonth = now.getMonth();
        }else{
                curYear = parseInt(curYear);
                curMonth = parseInt(curMonth);
        }
        var monthName = getMonthName(curMonth);
        date = now.getDate();
        //now = null;

        // create instance of first day of month, and extract the day on which it occurs
        var firstDayInstance = new Date(curYear, curMonth, 1);
        var firstDay = firstDayInstance.getDay();
        firstDayInstance = null;

        // number of days in current month
        var days = getDays(curMonth, curYear);

        // call function to draw calendar
        buildCalendar(firstDay + 1, days, date, monthName, curMonth, curYear, mID, isAdmin, isPrintMode);
}
function buildCalendar(firstDay, lastDate, date, monthName, month, year, mID, isAdmin, isPrintMode) {
        // constant table settings
        var headerHeight = 45; // height of the table's header cell
        var border = 0; // 3D height of table's border
        var headerSize = "14"; // size of tables header font
        var colWidth = 85; // width of columns in table
        var dayCellHeight = 20; // height of cells containing days of the week
        var cellHeight = 70; // height of cells representing dates in the calendar
        var todayColor = "red"; // color specifying today's date in the calendar
        var strDate='';
	 var currentDate = new Date();
        // create basic table structure
        var text = ""; // initialize accumulative variable to empty string
         if(mID != "")
        {
                pName="Manager.php?";
        }else{
                pName="index.php?ecal=1&";
        }
        if(!(isPrintMode)){
        text += '<TABLE class="calendar_datelinks_border" cellpadding="5" cellspacing="0" width="100%">'; // table settings
        text += '<tr><TD COLSPAN=7 HEIGHT=' + headerHeight + ' align=center class=menuheadertextcolor>'; // create table header cell
        text += '<a href="' + pName + 'dt=C&d=01/01/' + year + '" border=0  class=calendarlink>  Jan&nbsp; &nbsp;  </a>';
        text += '<a href="' + pName + 'dt=C&d=02/01/' + year + '" border=0  class=calendarlink>  Feb&nbsp; &nbsp;    </a>';
        text += '<a href="' + pName + 'dt=C&d=03/01/' + year + '" border=0  class=calendarlink>  Mar&nbsp; &nbsp;    </a>';
        text += '<a href="' + pName + 'dt=C&d=04/01/' + year + '" border=0  class=calendarlink>  Apr&nbsp; &nbsp;    </a>';
        text += '<a href="' + pName + 'dt=C&d=05/01/' + year + '" border=0  class=calendarlink>  May&nbsp; &nbsp;    </a>';
        text += '<a href="' + pName + 'dt=C&d=06/01/' + year + '" border=0  class=calendarlink>  Jun &nbsp; &nbsp;   </a>';
        text += '<a href="' + pName + 'dt=C&d=07/01/' + year + '" border=0  class=calendarlink>  Jul&nbsp; &nbsp;  </a>';
        text += '<a href="' + pName + 'dt=C&d=08/01/' + year + '" border=0  class=calendarlink>  Aug&nbsp; &nbsp;    </a>';
        text += '<a href="' + pName + 'dt=C&d=09/01/' + year + '" border=0  class=calendarlink>  Sep&nbsp; &nbsp;    </a>';
        text += '<a href="' + pName + 'dt=C&d=10/01/' + year + '" border=0  class=calendarlink>  Oct&nbsp; &nbsp;    </a>';
        text += '<a href="' + pName + 'dt=C&d=11/01/' + year + '" border=0  class=calendarlink>  Nov&nbsp; &nbsp;    </a>';
        text += '<a href="' + pName + 'dt=C&d=12/01/' + year + '" border=0  class=calendarlink>  Dec</a>';
        text += '<br>';

                var curMonth=(month+1);
                var tempMonth = curMonth.toString();
                if(tempMonth.length < 2){  var curMonth='0'+tempMonth;  }

               	var prevMonth=month;
                var tempMonth = prevMonth.toString();
                if(tempMonth.length < 2){  var prevMonth='0'+tempMonth;  }

                var nextMonth=(month+2);
                var tempMonth = nextMonth.toString();
                if(tempMonth.length < 2){  var nextMonth='0'+tempMonth;  }

                var nextMonthYear=year;
                var prevMonthYear=year;
                if(nextMonth=='13'){
                        nextMonthYear=year+1;
                        nextMonth='01';
                 }
                if(prevMonth=='00'){
                        prevMonthYear=year-1;
                        prevMonth='12';
                 }

        text += '<a href="' + pName + 'dt=C&d=' + curMonth + '/01/' + (year-1) + '" border=0  class=calendarlink> &lt;&lt;Prev Year&nbsp;&nbsp;&nbsp;</a>';
        text += '<a href="' + pName + 'dt=C&d=' + prevMonth + '/01/' + (prevMonthYear) +  '" border=0 class=calendarlink>&lt;Prev Month&nbsp;&nbsp;&nbsp;</a>';
        text += '<a href="' + pName + 'dt=C" border=0  class=calendarlink> &lt;Today&gt;&nbsp;&nbsp;&nbsp;</a>';
        text += '<a href="' + pName + 'dt=C&d=' + nextMonth + '/01/' + (nextMonthYear) +  '" border=0 class=calendarlink>Next Month&gt;&nbsp;&nbsp;&nbsp;</a>';
        text += '<a href="' + pName + 'dt=C&d=' + curMonth + '/01/' + (year+1) + '" border=0 class=calendarlink>Next Year&gt;&gt; </a>';
        text += '</td></tr>';
        text += '</table>';
        }

        var curBoldFont='bodytextbold';
        if(isPrintMode){
                curBoldFont='bodytextboldblack';
        }

        text += '<TABLE BORDER="0" cellpadding="0" cellspacing="0" width="100%">'; // table settings
        text += '<tr><TD COLSPAN="7" HEIGHT="' + headerHeight + '" align=center>'; // create table header cell
        text += '<FONT class="'+curBoldFont+'" style="font-size:' + headerSize + ';"><br>'; // set font for table header
        text += monthName + ' ' + year; 
        text += '</FONT>'; // close table header's font settings
        text += '</TD></tr>'; // close header cell

        // variables to hold constant settings
        var openCol = '<TD width=' + colWidth + ' height=' + dayCellHeight + ' align="center" valign="center">';
        openCol += '<FONT class="'+curBoldFont+'">';
        var closeCol = '</FONT></TD>';

        // create array of abbreviated day names
        var weekDay = new Array(7);
        weekDay[0] = "Sun";
        weekDay[1] = "Mon";
        weekDay[2] = "Tue";
        weekDay[3] = "Wed";
        weekDay[4] = "Thur";
        weekDay[5] = "Fri";
        weekDay[6] = "Sat";

        // create first row of table to set column width and specify week day
        text += '<TR>';
        for (var dayNum = 0; dayNum < 7; ++dayNum) {
                text += openCol + weekDay[dayNum] + closeCol;
        }
        text += '</TR>';
        text += '</TABLE>';

        text += '<TABLE BORDER="0" cellpadding="0" cellspacing="0" width="100%" class="calendarborder">'; // table settings

        // declaration and initialization of two variables to help with tables
        var day = 1;
        var curCell = 1;

        for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row) {
                text += '<TR ALIGN="left" VALIGN="top">';
                for (var col = 1; col <= 7; ++col) {
                        if (curCell < firstDay || day > lastDate) {
                                text += '<TD class="calendarcellborder" bgcolor="#AAAAAA">&nbsp;</TD>';
                                curCell++;
                        } else {
                                if (day == currentDate.getDate() && month == currentDate.getMonth() && year == currentDate.getFullYear()) {//todays date
                                        text += '<TD HEIGHT=' + cellHeight + ' class="calendarcellborder" bgcolor="#DDDDDD" width=' + colWidth + ' >';
   //                                     text += '<TD HEIGHT=' + cellHeight + ' class="calendarcellborder" bgcolor="#FFFFFF" width=' + colWidth + ' >';
                                        text += '<FONT class="'+curBoldFont+'" style="color:#FF0000;"><b>';
                                        text += day;
                                        curdte=strDate = year+'-'+(month+1)+'-'+day;
                                        text += '</b></font><Div id="'+year+'-'+(month+1)+'-'+day+'"></Div></TD>';
                                } else {
                                        text += '<TD HEIGHT=' + cellHeight + ' class="calendarcellborder" bgcolor="#FFFFFF" width=' + colWidth + ' ><font class="'+curBoldFont+'" style="color:#000000;"><b>' + day;
                                        strDate = year+'-'+(month+1)+'-'+day;
						text += '</b></font><Div id="'+year+'-'+(month+1)+'-'+day+'"></Div></TD>';
                                       // text += '</b></font><Div id="'+year+'-'+(month+1)+'-'+day+'" style="white-space: nowrap;"></Div></TD>'; //this is for no wrap e name
                                }
                                day++;
                        }
                }
                text += '</TR>';        
        }

        // close all basic table tags
        text += '</TABLE>';
        // print accumulative HTML string
        document.write(text) ;

        //set floating events
        SetRepeatingEvents(month+1,year,lastDate,firstDay,"C",mID,isAdmin,isPrintMode,false);
}
function setEvents(mID,isAdmin,d,isPrintMode) {
        var curMonth='';
        var curYear='';
        var dDate=d;
        // standard time attributes
        if(dDate==''){
                now = new Date();
        }else{
                now = new Date(dDate);
        }
        if(curMonth == '' && curYear == ''){
                curYear = now.getFullYear();
                curMonth = now.getMonth();
        }else{
                curYear = parseInt(curYear);
                curMonth = parseInt(curMonth);
        }
        var monthName = getMonthName(curMonth);
        date = now.getDate();
        //now = null;
        // create instance of first day of month, and extract the day on which it occurs
        var firstDayInstance = new Date(curYear, curMonth, 1);
        var firstDay = firstDayInstance.getDay();
        firstDayInstance = null;

        // number of days in current month
        var days = getDays(curMonth, curYear);

        // call function to draw calendar
        buildEventList(firstDay + 1, days, date, monthName, curMonth, curYear, mID, isAdmin, isPrintMode);
}

function setDetailPageEvents(mID,isAdmin,d) {
        var curMonth='';
        var curYear='';
        var dDate=d;
        // standard time attributes
        if(dDate==''){
                now = new Date();
        }else{
                now = new Date(dDate);
        }
        if(curMonth == '' && curYear == ''){
                curYear = now.getFullYear();
                curMonth = now.getMonth();
        }else{
                curYear = parseInt(curYear);
                curMonth = parseInt(curMonth);
        }
        var monthName = getMonthName(curMonth);
        date = now.getDate();
        //now = null;
        // create instance of first day of month, and extract the day on which it occurs
        var firstDayInstance = new Date(curYear, curMonth, 1);
        var firstDay = firstDayInstance.getDay();
        firstDayInstance = null;

        // number of days in current month
        var days = getDays(curMonth, curYear);

        // call function to draw calendar
        buildDetailPageEventList(firstDay + 1, days, date, monthName, curMonth, curYear, mID, isAdmin);
}

function buildDetailPageEventList(firstDay, lastDate, date, monthName, month, year, mID, isAdmin) {
        // constant table settings
        var headerHeight = 45; // height of the table's header cell
        var border = 0; // 3D height of table's border
        var headerSize = "14"; // size of tables header font
        var strDate='';
        // create basic table structure
        var text = ""; // initialize accumulative variable to empty string
        pName="Manager.php?";
        var curBoldFont='bodytextbold';

        if(objEvents.events.length>0){
		text += '<TABLE BORDER="0" cellpadding="0" cellspacing="1" width="100%">';
		text += '<tr><td width="" valign="bottom"><span class="Title"><b>Date</b></span></td><td width="" align="center" valign="middle"><span class="Title"><b>Event</b></span></td><td width="50" align="center" valign="middle"></td><td width="5"></td><td width="50" align="center" valign="middle"></td></tr>';
		document.write(text);
                SetRepeatingEvents(month+1,year,lastDate,firstDay,"L",mID,isAdmin,false,true);
		document.write('</TABLE>');
        }else{
                document.write('<TABLE BORDER="0" cellpadding="0" cellspacing="0" width="100%"><tr><td class="'+curBoldFont+'" colspan="3" align="center">No upcoming event(s) found</td></tr></TABLE>');
        }
}

function buildEventList(firstDay, lastDate, date, monthName, month, year, mID, isAdmin, isPrintMode) {
        // constant table settings
        var headerHeight = 45; // height of the table's header cell
        var border = 0; // 3D height of table's border
        var headerSize = "14"; // size of tables header font
        var strDate='';
        // create basic table structure
        var text = ""; // initialize accumulative variable to empty string
        if(mID != "")
        {
                pName="Manager.php?";
        }else{
                pName="index.php?ecal=1&";
        }
        if(!(isPrintMode)){
        text += '<TABLE class="calendar_datelinks_border" cellpadding="5" cellspacing="0" width="100%">'; // table settings
        text += '<TD COLSPAN=7 HEIGHT=' + headerHeight + ' align=center class=menuheadertextcolor>'; // create table header cell
        text += '<a href="' + pName + 'dt=EL&d=01/01/' + year + '" border=0  class=calendarlink>  Jan&nbsp; &nbsp;  </a>';
        text += '<a href="' + pName + 'dt=EL&d=02/01/' + year + '" border=0  class=calendarlink>  Feb&nbsp; &nbsp;    </a>';
        text += '<a href="' + pName + 'dt=EL&d=03/01/' + year + '" border=0  class=calendarlink>  Mar&nbsp; &nbsp;    </a>';
        text += '<a href="' + pName + 'dt=EL&d=04/01/' + year + '" border=0  class=calendarlink>  Apr&nbsp; &nbsp;    </a>';
        text += '<a href="' + pName + 'dt=EL&d=05/01/' + year + '" border=0  class=calendarlink>  May&nbsp; &nbsp;    </a>';
        text += '<a href="' + pName + 'dt=EL&d=06/01/' + year + '" border=0  class=calendarlink>  Jun &nbsp; &nbsp;   </a>';
        text += '<a href="' + pName + 'dt=EL&d=07/01/' + year + '" border=0  class=calendarlink>  Jul&nbsp; &nbsp;  </a>';
        text += '<a href="' + pName + 'dt=EL&d=08/01/' + year + '" border=0  class=calendarlink>  Aug&nbsp; &nbsp;    </a>';
        text += '<a href="' + pName + 'dt=EL&d=09/01/' + year + '" border=0  class=calendarlink>  Sep&nbsp; &nbsp;    </a>';
        text += '<a href="' + pName + 'dt=EL&d=10/01/' + year + '" border=0  class=calendarlink>  Oct&nbsp; &nbsp;    </a>';
        text += '<a href="' + pName + 'dt=EL&d=11/01/' + year + '" border=0  class=calendarlink>  Nov&nbsp; &nbsp;    </a>';
        text += '<a href="' + pName + 'dt=EL&d=12/01/' + year + '" border=0  class=calendarlink>  Dec</a>';
        text += '<br>';
        var tempMonth = month.toString();
        if(tempMonth.length < 2){
                var curMonth='0'+(month+1);
                var prevMonth='0'+month;
                var nextMonth='0'+(month+2);
                var prevMonthYear=year;
                var nextMonthYear=year;
                if(prevMonth=='00'){
                        prevMonthYear=year-1;
                        prevMonth='12'
                }
        }else{
                var curMonth=(month+1);
                var prevMonth=month;
                var nextMonth=(month+2);
                var nextMonthYear=year;
                var prevMonthYear=year;
                if(nextMonth=='13'){
                        nextMonthYear=year+1;
                        nextMonth='01';
                }
        }
        text += '<a href="' + pName + 'dt=EL&d=' + curMonth + '/01/' + (year-1) + '" border=0  class=calendarlink> &lt;&lt;Prev Year&nbsp;&nbsp;&nbsp;</a>';
        text += '<a href="' + pName + 'dt=EL&d=' + prevMonth + '/01/' + (prevMonthYear) +  '" border=0 class=calendarlink>&lt;Prev Month&nbsp;&nbsp;&nbsp;</a>';
        text += '<a href="' + pName + 'dt=EL" border=0  class=calendarlink> &lt;Today&gt;&nbsp;&nbsp;&nbsp;</a>';
        text += '<a href="' + pName + 'dt=EL&d=' + nextMonth + '/01/' + (nextMonthYear) +  '" border=0 class=calendarlink>Next Month&gt;&nbsp;&nbsp;&nbsp;</a>';
        text += '<a href="' + pName + 'dt=EL&d=' + curMonth + '/01/' + (year+1) + '" border=0  class=calendarlink>Next Year&gt;&gt; </a>';
        text += '</td></tr>';
        text += '</table>';
        }
        
        var curBoldFont='bodytextbold';
        if(isPrintMode){
                curBoldFont='bodytextboldblack';
        }

        if(objEvents.events.length>0){
                if(!(isPrintMode)){
                        text += '<TABLE BORDER="0" cellpadding="5" cellspacing="0" width="100%">'; // table settings
                        text += '<tr><TD COLSPAN=5 HEIGHT=' + headerHeight + ' align=center>'; // create table header cell
                        text += '<FONT class="'+curBoldFont+'" style="font-size:' + headerSize + ';">'; // set font for table header
                        text += monthName + ' ' + year; 
                        text += '</FONT>'; // close table header's font settings
                        text += '</TD></tr>'; // close header cell
                        document.write(text);
                        document.write('<tr><td>&nbsp;</td><td class="'+curBoldFont+'" align="left">View</td><td class="'+curBoldFont+'" align="left">Date</td><td class="'+curBoldFont+'" align="left">Title</td><td class="'+curBoldFont+'" align="left">Description</td></tr>');
                }else{
                        text += '<TABLE BORDER="0" cellpadding="5" cellspacing="0" width="100%">'; // table settings
                        text += '<tr><TD COLSPAN=4 HEIGHT=' + headerHeight + ' align=center>'; // create table header cell
                        text += '<FONT class="'+curBoldFont+'" style="font-size:' + headerSize + ';">'; // set font for table header
                        text += 'Event List';
                        text += '</FONT>'; // close table header's font settings
                        text += '</TD></tr>'; // close header cell
                        document.write(text);
                        document.write('<tr><td class="'+curBoldFont+'" align="left">&nbsp;</td><td class="'+curBoldFont+'" align="left">Date</td><td class="'+curBoldFont+'" align="left">Title</td><td class="'+curBoldFont+'" align="left">Description</td></tr>');
                }
                SetRepeatingEvents(month+1,year,lastDate,firstDay,"L",mID,isAdmin,isPrintMode,false);
        }else{
                document.write('<TABLE BORDER="0" cellpadding="0" cellspacing="0" width="100%"><tr><td class="'+curBoldFont+'" colspan="3" align="center">No events found with this date</td></tr>');
        }
        // close all basic table tags
        document.write('</TABLE>');
}

