// JavaScript Document

var loadState = "firstLoad"
var fullDateDisplay = "";
var dayOfTheWeekDisplay = "";
var duration = 1;
var startTimestamp = "";
var endTimestamp = "";
var calendar = ""
var bookMode = "book"
var newDateDisplay = ""
var target = "";
var target = "";
var timeArrayDivIds = new Array('12 AM', '1 AM', '2 AM', '3 AM', '4 AM', '5 AM', '6 AM', '7 AM', '8 AM', '9 AM', '10 AM', '11 AM', '12 PM', '1 PM', '2 PM', '3 PM', '4 PM', '5 PM', '6 PM', '7 PM', '8 PM', '9 PM', '10 PM', '11 PM')
//document.bgcolor = bgcolor;
//window.onload = getStudioAvailability;


function checkIfDaysMatch(timestamp1, timestamp2){
	if(timestamp1.getFullYear() != timestamp2.getFullYear()) {
		return false;
	} else {
		if(timestamp1.getMonth() != timestamp2.getMonth()) {
			return false;
		} else {
			if(timestamp1.getDate() != timestamp2.getDate()) {
				return false;
			} else {
				return true;
			}
		}
	}
}

function setSchedule() {
	
	
	resetScheduleGrid()
	//alert("Here")
	//var now = new Date
	for(i=0; i < regularScheduleArray.length; i++) {
		if(regularScheduleArray[i].day_of_the_week_num == bookingDate.getDay()) {
			//alert(regularScheduleArray[i].start_time)
			//alert(scheduleArray[i].id)
		
	
			for(j=0; j<scheduleArray.length; j++) {
				var div = document.getElementById(scheduleArray[j].id);
				var startHour = j
				var endHour = j+1
				if(startHour < regularScheduleArray[i].start_hour) {
					div.innerHTML = scheduleArray[j].id+ " BLOCKED"
					scheduleArray[j].status = "blocked";
					div.style.backgroundColor = '#CCFF99'
					div.style.fontWeight = 'bold'
				}
				/*
				if(endHour > regularScheduleArray[i].end_hour) {
					div.innerHTML = scheduleArray[j].id+ " BLOCKED"
					scheduleArray[j].status = "blocked";
					div.style.backgroundColor = '#CCFF99'
					div.style.fontWeight = 'bold'
				}
				*/
			}
		}
	}
	bookingDateEnd = new Date()
	bookingDateEnd.setTime(bookingDate.getTime());
	bookingDateEnd.setDate(bookingDate.getDate() + 1);
	for(i=0; i < blockScheduleArray.length; i++) {
		//alert("here")
		if(blockScheduleArray[i].endTimestamp < bookingDate || blockScheduleArray[i].startTimestamp > bookingDateEnd) {
			// ignore all blocks that end before the booking date or start after the booking date
			//alert("here")
			continue;
		} else {
			if(blockScheduleArray[i].startTimestamp.getDate() == bookingDate.getDate() && blockScheduleArray[i].endTimestamp.getDate() == bookingDate.getDate()) { // There is a block that starts during the booking day and ends during the booking day
				//alert("block starts this day and ends this day")
				for(j=0; j<scheduleArray.length; j++) {
					var div = document.getElementById(scheduleArray[j].id);
					var startHour = j
					var endHour = j+1
					var blockStartHour = blockScheduleArray[i].startTimestamp.getHours();
					var blockEndHour = blockScheduleArray[i].endTimestamp.getHours();
					if(startHour >= blockStartHour/* && endHour <= sessionEndHour*/ ) {
						if(startHour == blockStartHour) {
							div.innerHTML = scheduleArray[j].id+ " BLOCKED"
							scheduleArray[j].status = "blocked";
							div.style.backgroundColor = '#CCFF99'
							div.style.fontWeight = 'bold'
						}
						if(startHour > blockStartHour && endHour <= blockEndHour ) {
							div.innerHTML = scheduleArray[j].id+ " BLOCKED"
							scheduleArray[j].status = "blocked";
							div.style.backgroundColor = '#CCFF99'
							div.style.borderTop = 'medium solid #CCFF99'
							div.style.fontWeight = 'bold'
						}
					}
				}
				continue;
			}
			if(blockScheduleArray[i].startTimestamp.getYear() == bookingDate.getYear() && blockScheduleArray[i].startTimestamp.getMonth() == bookingDate.getMonth() && blockScheduleArray[i].startTimestamp.getDate() == bookingDate.getDate() && blockScheduleArray[i].endTimestamp > bookingDate) { // There is a block that starts during the booking day and ends after the booking day
				//alert("block starts this day and ends after this day")
				for(j=0; j<scheduleArray.length; j++) {
					var div = document.getElementById(scheduleArray[j].id);
					var startHour = j
					var endHour = j+1
					var blockStartHour = blockScheduleArray[i].startTimestamp.getHours();
					//var blockEndHour = blockScheduleArray[i].endTimestamp.getHours();
					if(startHour >= blockStartHour/* && endHour <= sessionEndHour*/ ) {
						if(startHour == blockStartHour) {
							div.innerHTML = scheduleArray[j].id+ " BLOCKED"
							scheduleArray[j].status = "blocked";
							div.style.backgroundColor = '#CCFF99'
							div.style.fontWeight = 'bold'
						}
						/*
						if(startHour > blockStartHour && endHour <= blockEndHour ) {
							div.innerHTML = scheduleArray[j].id+ " BLOCKED"
							scheduleArray[j].status = "blocked";
							div.style.backgroundColor = '#CCFF99'
							div.style.borderTop = 'medium solid #CCFF99'
							div.style.fontWeight = 'bold'
						}
						*/
					}
				}
				continue;
			}
			if(blockScheduleArray[i].startTimestamp < bookingDate && blockScheduleArray[i].endTimestamp.getYear() == bookingDate.getYear() && blockScheduleArray[i].endTimestamp.getMonth() == bookingDate.getMonth() && blockScheduleArray[i].endTimestamp.getDate() == bookingDate.getDate()) { // There is a block that starts before the booking day and ends on the booking day
				//alert("block starts before this day and ends this day")
				for(j=0; j<scheduleArray.length; j++) {
					var div = document.getElementById(scheduleArray[j].id);
					var startHour = j
					var endHour = j+1
					//var blockStartHour = blockScheduleArray[i].startTimestamp.getHours();
					var blockEndHour = blockScheduleArray[i].endTimestamp.getHours();
					if(startHour < blockEndHour/* && endHour <= sessionEndHour*/ ) {
						//if(startHour == blockStartHour) {
						//	div.innerHTML = scheduleArray[j].id+ " BLOCKED"
						//	scheduleArray[j].status = "blocked";
						//	div.style.backgroundColor = '#CCFF99'
						//	div.style.fontWeight = 'bold'
						//}
						
						if(endHour <= blockEndHour ) {
							div.innerHTML = scheduleArray[j].id+ " BLOCKED"
							scheduleArray[j].status = "blocked";
							div.style.backgroundColor = '#CCFF99'
							div.style.borderTop = 'medium solid #CCFF99'
							div.style.fontWeight = 'bold'
							//alert('hi')
						}
					}
				}
				continue;
			}
			if(blockScheduleArray[i].startTimestamp < bookingDate && blockScheduleArray[i].endTimestamp > bookingDateEnd) { // There is a block that starts before the booking day and ends after the booking day
				//alert("block starts before this day and ends after this day")
				for(j=0; j<scheduleArray.length; j++) {
					var div = document.getElementById(scheduleArray[j].id);
					div.innerHTML = scheduleArray[j].id+ " BLOCKED"
					scheduleArray[j].status = "blocked";
					div.style.backgroundColor = '#CCFF99'
					div.style.fontWeight = 'bold'
				}
				//alert("bookingDate="+bookingDate+" - "+bookingDateEnd+"\nblockStart="+blockScheduleArray[i].startTimestamp+"\nblockEnd="+blockScheduleArray[i].endTimestamp)
				continue;
			}
			//alert("no condition")
		}
	}
	
	
	
	
	for(i=0; i < sessionsArray.length; i++) {
		if(sessionsArray[i].confirmation_status != "confirmed") {
			continue;
		} else {
			if(sessionsArray[i].startTimestamp.getFullYear() != bookingDate.getFullYear()) {
				continue;
			} else {
				if(sessionsArray[i].startTimestamp.getMonth() != bookingDate.getMonth()) {
					continue;
				} else {
					if(sessionsArray[i].startTimestamp.getDate() != bookingDate.getDate()) {
						continue;
					}
					//alert(bookMode)
					if(bookMode == "reschedule" && sessionsArray[i].session_id == session.session_id) {
						//alert("working")
						continue;
					}
				}
			}
		}
		//alert("Made it")
		
		//client_list += clientsArray[i].first_name+' ' +clientsArray[i].last_name+'<br />';
		var sessionStartTimestamp = new Date
		var sessionendTimestamp = new Date
		sessionStartTimestamp.setTime(sessionsArray[i].startTimestamp);
		sessionendTimestamp.setTime(sessionsArray[i].endTimestamp);
		
		
		
		var sessionStartHour = sessionStartTimestamp.getHours();
		var sessionEndHour = sessionendTimestamp.getHours();
		if(sessionStartTimestamp.getDate() != sessionendTimestamp.getDate() ) {
			sessionEndHour += 24
		}
		
	
		for(j=0; j<scheduleArray.length; j++) {
			var div = document.getElementById(scheduleArray[j].id);
			var startHour = j
			var endHour = j+1
			if(startHour >= sessionStartHour/* && endHour <= sessionEndHour*/ ) {
				if(startHour == sessionStartHour) {
					//for(c=0; c < clientsArray.length; c++) {
						//alert(i);
						//if(clientsArray[c].client_id == sessionsArray[i].client_id) {
							//alert('hi')
							//alert(sessionsArray.length);
							//otherSessionClient = clientsArray[c].full_name
							//blockSchedule(clientsArray[c].full_name, sessionsArray[i].start_timestamp, sessionsArray[i].end_timestamp);
							div.innerHTML = scheduleArray[j].id+ " BLOCKED" //+clientsArray[c].full_name
							scheduleArray[j].status = "blocked";
							//div.innerHTML += scheduleArray[j].status
							div.style.backgroundColor = '#CCFF99'
							//div.style.color = 'white'
							div.style.fontWeight = 'bold'
					//alert('hi');
						//}
				//	}
				}
				if(startHour > sessionStartHour && endHour <= sessionEndHour ) {
					//alert('hi');
					//for(c=0; c < clientsArray.length; c++) {
						//alert(i);
						//if(clientsArray[c].client_id == sessionsArray[i].client_id) {
							//alert(sessionsArray.length);
							//otherSessionClient = clientsArray[c].full_name
							//blockSchedule(clientsArray[c].full_name, sessionsArray[i].start_timestamp, sessionsArray[i].end_timestamp);
							div.innerHTML = scheduleArray[j].id+ " BLOCKED" //+ " "+clientsArray[c].full_name
							scheduleArray[j].status = "blocked";
							//div.innerHTML += scheduleArray[j].status
							div.style.backgroundColor = '#CCFF99'
							div.style.borderTop = 'medium solid #CCFF99'
							//div.style.color = 'white'
							div.style.fontWeight = 'bold'
						//}
					//}
				}
			}
		}
		//alert('Setting Schedule')
		//document.getElementById('other_sessions').innerHTML += otherSessionClient+"<br />";
		//document.getElementById('client_list').options[i+1].value = clientsArray[i].id;
		//document.getElementById('client_list').onchange = gotClient;
	}
	
	for(j=0; j<scheduleArray.length; j++) {
		var div = document.getElementById(scheduleArray[j].id);
		if(scheduleArray[j].status == "not_set" ) {
			scheduleArray[j].status = "open";
			//div.innerHTML += scheduleArray[j].status
		} else {
			//document.getElementById(timeArrayDivIds[j]).style.backgroundColor = 'blue'
		}	
		//alert('hi')
	}
	//alert(hour);
	setHighlight()
}

/*
function getVal(theData,theTag) {
	alert(theTag)
	return theData.getElementsByTagName(theTag)[0].firstChild.nodeValue;
}
*/

function getSessionsForMonth(month, year) {
	//alert('hi')
	monthSessionsArray = new Array();
	monthSessionsCount = 0
	for(var i=0; i < sessionsArray.length; i++) {
		if(sessionsArray[i].startTimestamp.getFullYear() == year && (sessionsArray[i].startTimestamp.getMonth()+1) == month) {
			//alert(hey)
			monthSessionsArray[monthSessionsCount] = sessionsArray[i];
			monthSessionsCount++
		}
	}
	//alert(monthSessionsArray[0].startTimestamp)
	
	renderCal();
}

function setHighlight() {
	//alert('hi')
	for (i=0; i < scheduleArray.length; i++) {
		//alert((i+j))
		var div = document.getElementById(scheduleArray[i].id)
		if(i < (scheduleArray.length-duration)) {
			//alert(scheduleArray[i].status)
			//div.innerHTML += " "+scheduleArray[i].status
			var blocked = "none";
			for (d=0; d < duration; d++) {
				if(scheduleArray[i+d].status != "open") {
					blocked = "yes"
				}
			}
			if(scheduleArray[i].status == "open" && blocked == "none") {
				div.style.cursor = 'pointer'
				//if(scheduleArray[i].end_timestamp > (currentTime.getTime()/1000)) {
				//	div.backgroundColorSaved = "white";
				//} else {
				//	alert(div.end_timestamp+" "+currentTime.getTime()/1000)
					div.backgroundColorSaved = "#FFFFCC";
				//}
				div.style.backgroundColor = div.backgroundColorSaved 
				highlight(i, div);
				removeHighlight(i, div);
				//alert(fullDateDisplay)
				div.startTimestamp = new Date(fullDateDisplay)
				for (t=0; t < scheduleArray.length; t++) {
					if(scheduleArray[i].id == div.id) {
						div.startTimestamp.setHours(i)
					}
				}
				div.endTimestamp = new Date()
				div.endTimestamp.setTime(div.startTimestamp.getTime()+(duration*60*60*1000))
				//startTimestampSeconds = startTimestamp.getTime();
				//alert('startTimestamp='+startTimestamp+'\nendTimestamp='+endTimestamp)
				//alert('startTimestamp='+startTimestampSeconds+'\nendTimestamp='+endTimestamp)
				div.onclick = function() {
						window.open (
				'http://www.mystudiosessions.com/newmember.php');
						return;
					
					if(target == "") {
					//confirmSession();
						window.open (
				'http://www.mystudiosessions.com/new_session.php?&book_the_session=book_it&studio_id='+studioID+'&studio_key=&session_start_timestamp='+(startTimestamp.getTime()/1000)+'&session_end_timestamp='+(endTimestamp.getTime()/1000)+'&duration='+duration)
					} else {
						window.location = 
				'http://www.mystudiosessions.com/new_session.php?&book_the_session=book_it&studio_id='+studioID+'&studio_key=&session_start_timestamp='+(startTimestamp.getTime()/1000)+'&session_end_timestamp='+(endTimestamp.getTime()/1000)+'&duration='+duration
					}
				}
			}
			if(scheduleArray[i].status == "open" && blocked == "yes") {
				div.backgroundColorSaved = "#CCCCCC";
				div.style.backgroundColor = div.backgroundColorSaved
				
			}

			if(scheduleArray[i].status == "blocked") {
				
			}
			//var div = timeArrayDivIds[i+j]
		}
		if(i >= (scheduleArray.length-duration) && scheduleArray[i].status == "open") {
				//div.innerHTML += ' '+scheduleArray[i].status
				div.backgroundColorSaved = "#CCCCCC";
				div.style.backgroundColor = div.backgroundColorSaved
		}
	}
}
function highlight(i, div){
	//alert('hi')
	div.onmouseover = function() {
		//alert('hi')
		for (j=0; j < duration; j++) {
			var div = document.getElementById(scheduleArray[(i+j)].id)
			if(i+j < scheduleArray.length && scheduleArray[(i+j)].status == "open") {
				div.style.backgroundColor = 'yellow'
				div.innerHTML = '&nbsp;'
				div.style.textAlign = 'center'
				startTimestamp = new Date(fullDateDisplay)
				startTimestamp.setHours(i)
				endTimestamp = new Date()
				endTimestamp.setTime(startTimestamp.getTime()+(duration*60*60*1000))
				document.getElementById('startTimestamp').style.color = 'gray'
				document.getElementById('endTimestamp').style.color = 'gray'
				document.getElementById('startTimestamp').innerHTML = displayTime(startTimestamp)
				document.getElementById('endTimestamp').innerHTML = displayTime(endTimestamp)
				if(j != 0) {
					div.style.borderTop = 'medium solid yellow'
					//document.getElementById(div).style.borderRight = 'medium solid gray'
					//document.getElementById(div).style.borderLeft = 'medium solid gray'
				}
				if(j == 0) {
					div.innerHTML = div.id+" - "+document.getElementById(scheduleArray[(1*duration)+i].id).id
					//alert('i='+i+'\nduration='+duration+'\nduration plus i='+(duration+i))
				}
			} else {
				//div.style.backgroundColor = 'gray'
			}
		}
	}
}

function displayTime(timestamp){
	hour = timestamp.getHours();
	var tag = "AM";
	if (hour > 12) {
		hour = hour - 12;
		tag = "PM";
	}
	
	if (hour == 12) {
		//hour = hour - 12;
		tag = "PM";
	}
	if (hour == 0) {
		hour = 12;
		//tag = "PM";
	}
			
	var minutes =  "0" + timestamp.getMinutes()
	return hour+":"+minutes.substr(-2,2)+" "+tag
}
function removeHighlight(i, div){
	//alert('hi')
	div.onmouseout = function() {
		document.getElementById('startTimestamp').innerHTML = ""
		document.getElementById('endTimestamp').innerHTML = ""
		document.getElementById('startTimestamp').style.color = 'black'
		document.getElementById('endTimestamp').style.color = 'black'
		for (j=0; j < duration; j++) {
			var div = document.getElementById(scheduleArray[(i+j)].id)
			div.style.backgroundColor = div.backgroundColorSaved
			div.style.borderBottom = div.borderBottomSaved
			div.style.borderTop = div.borderTopSaved
			div.innerHTML = div.id
			div.style.textAlign = 'left'
			if(i+j < (scheduleArray.length-duration) && scheduleArray[(i+j)].status == "open") {
				//div.style.borderTop = 'medium solid gray'
				//div.style.backgroundColor = 'white'
				//div.style.borderRight = 'medium solid gray'
				//div.style.borderLeft = 'medium solid gray'
			} else {
				//div.style.backgroundColor ='gray'
				//disableHighlight(i, div, duration);	
			}
		}
	}
}
function getLastSessionEndHour() {
	var sessionStartTimestamp = new Date
	var sessionendTimestamp = new Date
	//alert(sessionsArray.length);
	sessionStartTimestamp.setTime(sessionsArray[(sessionsArray.length-1)].start_timestamp*1000);
	sessionendTimestamp.setTime(sessionsArray[(sessionsArray.length-1)].end_timestamp*1000);
	//alert('hi');
	var sessionStartHour = sessionStartTimestamp.getHours();
	var sessionEndHour = sessionendTimestamp.getHours();
	if(sessionStartTimestamp.getDate() != sessionendTimestamp.getDate() ) {
		sessionEndHour += 24
	}
	return sessionEndHour
}
function resetScheduleGrid() {
	
	document.getElementById('day_grid').innerHTML =
		"<table width='500px'>"+
			"<tr>"+
				"<td id='theader' colspan='4'>"+
					"<div style='background-color:yellow'>"+
						"<div id='date1' align='center'>"+newDateDisplay+"</div>"+
					"</div>"+
				"</td>"+
			"</tr>"+
			"<tr>"+
				"<td id='sessionGroup1' valign='top' width='125px'>"+
					"<div id='12 AM'>12 AM</div>"+
					"<div id='1 AM'>1 AM</div>"+
					"<div id='2 AM'>2 AM</div>"+
					"<div id='3 AM'>3 AM</div>"+
					"<div id='4 AM'>4 AM</div>"+
					"<div id='5 AM'>5 AM</div>"+
					"<div id='6 AM'>6 AM</div>"+
					"<div id='7 AM'>7 AM</div>"+
				"</td>"+
				"<td id='sessionGroup2' valign='top' width='125px'>"+
					"<div id='8 AM'>8 AM</div>"+
					"<div id='9 AM'>9 AM</div>"+
					"<div id='10 AM'>10 AM</div>"+
					"<div id='11 AM'>11 AM</div>"+
					"<div id='12 PM'>12 PM</div>"+
					"<div id='1 PM'>1 PM</div>"+
					"<div id='2 PM'>2 PM</div>"+
					"<div id='3 PM'>3 PM</div>"+
				"</td>"+
				"<td id='sessionGroup3' valign='top' width='125px'>"+
					"<div id='4 PM'>4 PM</div>"+
					"<div id='5 PM'>5 PM</div>"+
					"<div id='6 PM'>6 PM</div>"+
					"<div id='7 PM'>7 PM</div>"+
					"<div id='8 PM'>8 PM</div>"+
					"<div id='9 PM'>9 PM</div>"+
					"<div id='10 PM'>10 PM</div>"+
					"<div id='11 PM'>11 PM</div>"+
				"</td>"+
				"<td id='sessionGroup4' valign='top' width='125px'>"+
					""+
				"</td>"+
			"</tr>"+
		"</table>"
	scheduleArray = new Array()
	
	for(var i=0; i < timeArrayDivIds.length; i++) {
		var tempObj = new Object
		tempObj.id = timeArrayDivIds[i]
		tempObj.status = "not_set"
		scheduleArray[i] = tempObj;
		//document.getElementById('day_grid').innerHTML += "<div id='"+scheduleArray[i].id+"'></div>";
	}
	
	
	//alert(scheduleArray.length)
	for(var d=0; d < duration; d++) {
		var tempObj = new Object
		tempObj.id = scheduleArray[d].id+' '
		//alert('hi')
		tempObj.status = "not_set"
		scheduleArray[(24+d)] = tempObj;
		//alert(scheduleArray[(25+d)].id)
		document.getElementById('sessionGroup4').innerHTML += "<div id='"+scheduleArray[(24+d)].id+"'></div>";
	}
	//alert(scheduleArray.length)
	if(sessionsArray.length > 0) {
		lastSessionEndHour = getLastSessionEndHour()
		//alert(lastSessionEndHour)
		if(lastSessionEndHour>=scheduleArray.length) {
			var current_length = scheduleArray.length
			var diff = lastSessionEndHour - scheduleArray.length
			//div.style.borderBottom = 'medium solid #CCFF99'
			//resetTimslot(j)
			for(var m=0; m <= diff; m++) {
				var tempObj = new Object
				tempObj.id = scheduleArray[(current_length-24+m)].id+' '
				tempObj.status = "not_set"
				scheduleArray[(current_length+m)] = tempObj;
				//alert(scheduleArray[(25+d)].id)
				//alert(scheduleArray[(current_length+m)].id)
				document.getElementById('sessionGroup4').innerHTML += "<div id='"+scheduleArray[(current_length+m)].id+"'></div>";
		
			}
		}
	}
	
	for(i=0; i<scheduleArray.length; i++) {
		//alert(scheduleArray[i].id)
		resetTimslot(i)
	}
}
function resetTimslot(i) {
	var div = document.getElementById(scheduleArray[i].id);
	div.innerHTML = div.id
	div.backgroundColorSaved ='gray'
	div.style.backgroundColor =div.style.backgroundColor;
	div.onmouseover =''
	div.onmouseout =''
	div.onclick = ''
	div.style.cursor = ''
	div.style.textAlign = 'left'
	div.style.borderRight = 'medium solid gray'
	div.borderTopSaved = 'medium solid gray'
	div.style.borderTop = div.borderTopSaved
	div.style.borderLeft = 'medium solid gray'
	div.borderBottomSaved = ''
	div.style.borderBottom = div.borderBottomSaved
	if(i == (scheduleArray.length-1)) {
		div.borderBottomSaved = 'medium solid gray'
		div.style.borderBottom = div.borderBottomSaved
	}
}
function renderCal() {
	//alert('hi')
	for(i=0; i<sessionsArray.length; i++) {
		//var startTimestamp = monthSessionsArray[i].start_timestamp
		if(sessionsArray[i].confirmation_status == "confirmed") {
			var sessionStartTimestamp = new Date()
			sessionStartTimestamp.setTime(sessionsArray[i].startTimestamp.getTime());
			var sessionDateDisplay = (sessionStartTimestamp.getMonth()+1) + '/' + sessionStartTimestamp.getDate() + '/' + sessionStartTimestamp.getFullYear()
			calendar.addRenderer(sessionDateDisplay, calendar.renderCellStyleHighlight1);
			//alert('hi')
		}
	}
		//alert(sessionDateDisplay)
	//calendar.addRenderer("6/28/2009", calendar.renderCellStyleHighlight2);
	now = new Date
	if(bookMode == "reschedule") {
		now.setTime(session.startTimestamp)
	}
	todaysDateFormatted = (now.getMonth()+1) + "/" + now.getDate() + "/" + now.getFullYear()
	calendar.select(todaysDateFormatted);
	calendar.cfg.setProperty("pagedate", (now.getMonth()+1) + "/" + now.getFullYear());
	//alert(todaysDateFormatted)
	calendar.cfg.setProperty("mindate", todaysDateFormatted);
	//calendar.doCellMouseOver = function(e, call) {
	//	document.getElementById('fullDateDisplay').innerHTML = 'here';
	//}
	calendar.render(); 
}

function getStudioAvailability() {
	var loadingPanel = 
		new YAHOO.widget.Panel("wait",  
			{ width:"240px", 
			  fixedcenter:true, 
			  close:false, 
			  draggable:false, 
			  zindex:4,
			  modal:true,
			  visible:false
			} 
		);

	loadingPanel.setHeader("Loading Studio Schedule, please wait...");
	loadingPanel.setBody('<img src="http://l.yimg.com/a/i/us/per/gr/gp/rel_interstitial_loading.gif" />');
	loadingPanel.render(document.body);
	loadingPanel.show();

	//oldPage = currentPage
	//currentPage = "book"
	// Get Studio Info
	//clientsArray = new Array();
	//client = new Object
	
	TEMPsessionsArray = new Array();
	TEMPtotalPendingInvoicesArray = new Array
	TEMPtodaysSessionsArray = new Array
	TEMPupdateActualSessionsArray = new Array
	TEMPupcomingSessionsArray = new Array
	var sUrl = "studio_availability.php?studio_id="+studioID;
	var div = document.getElementById('main_content');
	function getVal(theData,theTag) {
		if(theData.getElementsByTagName(theTag)[0] && theData.getElementsByTagName(theTag)[0].firstChild && theData.getElementsByTagName(theTag)[0].firstChild.nodeValue) {
				//alert(theData.getElementsByTagName(theTag)[0].length)
			return theData.getElementsByTagName(theTag)[0].firstChild.nodeValue;
		} else {
			return "";
		}
	}
	var handleSuccess = function(o){
	
		if(o.responseText !== undefined){
		//alert('');
			if(o.responseXML == null) {
				
			}
			var root = o.responseXML.documentElement;
			studio_id = root.getElementsByTagName("studio_id")[0].firstChild.nodeValue;
			studioName = root.getElementsByTagName("studio_name")[0].firstChild.nodeValue;
			studioLogo = root.getElementsByTagName("studio_logo")[0].firstChild.nodeValue;
			room_id = root.getElementsByTagName("room_id")[0].firstChild.nodeValue;
			//alert(studioName)
			
			
			sessionStats = new Object;
			sessionStats.confirmed = new Array();
			sessionStats.rescheduled = new Array();
			sessionStats.declined = new Array();
			sessionStats.pending = new Array();
			sessionStats.pendingMissed = new Array();
			sessionStats.canceled = new Array();
			var sessionCount = 0
			var sessionConfirmedCount = 0
			var sessionRescheduledCount = 0
			var sessionDeclinedCount = 0
			var sessionPendingCount = 0
			var sessionPendingMissedCount = 0
			var sessionCanceledCount = 0
			var phoneNumberCount = 0
			var allSessions = root.getElementsByTagName("session");
			var allRegularSchedule = root.getElementsByTagName("day");
			var allBlockSchedule = root.getElementsByTagName("block");
			
			
			// Sessions
			var upcomingSessionsCount = 0
			var todaysSessionsCount = 0
			var updateActualSessionsCount = 0
			var sessionRequestsCount = 0
			var loopTest = 0
			sessionRequestsArray = new Array();
			regularScheduleArray = new Array();
			blockScheduleArray = new Array();
			now = new Date
			
			for(var i=0; i < allBlockSchedule.length; i++) {
				var tempObj = new Object
				var startTimestamp = new Date
				startTimestamp.setTime(getVal(allBlockSchedule[i],"start_timestamp")*1000);
				tempObj.startTimestamp = startTimestamp
				var endTimestamp = new Date
				endTimestamp.setTime(getVal(allBlockSchedule[i],"end_timestamp")*1000);
				tempObj.endTimestamp = endTimestamp
				//tempObj.end_timestamp = getVal(allRegularSchedule[i],"end_timestamp")
				blockScheduleArray[i] = tempObj
			}
			
			for(var i=0; i < allRegularSchedule.length; i++) {
				var tempObj = new Object
				tempObj.day_of_the_week_num = getVal(allRegularSchedule[i],"day_of_the_week_num")
				tempObj.day_of_the_week = getVal(allRegularSchedule[i],"day_of_the_week")
				tempObj.start_time = getVal(allRegularSchedule[i],"start_time")
				tempObj.end_time = getVal(allRegularSchedule[i],"end_time")
				tempObj.start_hour = getVal(allRegularSchedule[i],"start_hour")
				tempObj.end_hour = getVal(allRegularSchedule[i],"end_hour")
				regularScheduleArray[i] = tempObj
			}
			for(var i=0; i < allSessions.length; i++) {
				var tempObj = new Object
				//tempObj.session_id = getVal(allSessions[i],"session_id")
				//tempObj.user_id = getVal(allSessions[i],"user_id")
				//tempObj.client_id = getVal(allSessions[i],"client_id")
				tempObj.confirmation_status = getVal(allSessions[i],"confirmation_status")
				//tempObj.start_timestamp = getVal(allSessions[i],"start_timestamp")
				//tempObj.end_timestamp = getVal(allSessions[i],"end_timestamp")
				
				var startTimestamp = new Date
				startTimestamp.setTime(getVal(allSessions[i],"start_timestamp")*1000);
				tempObj.startTimestamp = startTimestamp
				
				var endTimestamp = new Date
				endTimestamp.setTime(getVal(allSessions[i],"end_timestamp")*1000);
				tempObj.endTimestamp = endTimestamp
				
				//var actualStartTimestamp = new Date
				//actualStartTimestamp.setTime(getVal(allSessions[i],"actual_start_timestamp")*1000);
				//tempObj.actualStartTimestamp = actualStartTimestamp
				
				//var actualEndTimestamp = new Date
				//actualEndTimestamp.setTime(getVal(allSessions[i],"actual_end_timestamp")*1000);
				//tempObj.actualEndTimestamp = actualEndTimestamp
				
				
				TEMPsessionsArray[i] = tempObj;
				
				
				//if(loopTest<1) {
				//	alert(now)
				//	loopTest++
				//}
				
				if(TEMPsessionsArray[i].confirmation_status == "rescheduled") {
					//alert(TEMPsessionsArray[i].confirmation_status)
				}
				//alert('here')
				switch(TEMPsessionsArray[i].confirmation_status) {
					case "confirmed":
						sessionStats.confirmed[sessionConfirmedCount] = TEMPsessionsArray[i]
						sessionConfirmedCount++
						if(checkIfDaysMatch(now, TEMPsessionsArray[i].startTimestamp)) {
							TEMPtodaysSessionsArray[todaysSessionsCount] = TEMPsessionsArray[i]
							//alert('hi')
							todaysSessionsCount++
							
						} else {
							if(TEMPsessionsArray[i].startTimestamp>now) {
								TEMPupcomingSessionsArray[upcomingSessionsCount] = TEMPsessionsArray[i]
								//alert('hi')
								upcomingSessionsCount++
							}
						}
						/*
						WHAT IS THIS?
						if(TEMPsessionsArray[i].endTimestamp < now && (TEMPsessionsArray[i].actualStartTimestamp.getTime() == 0 || TEMPsessionsArray[i].actualEndTimestamp.getTime() == 0)) {
							TEMPupdateActualSessionsArray[updateActualSessionsCount] = TEMPsessionsArray[i]
							//alert('hi')
							updateActualSessionsCount++
						}
						*/
							
						break;
					case "rescheduled":
						sessionStats.rescheduled[sessionRescheduledCount] = TEMPsessionsArray[i]
						//alert(TEMPsessionsArray[i].confirmation_status+'hi')
						//alert(sessionRescheduledCount)
						sessionRescheduledCount++
						break;
					case "declined":
						sessionStats.declined[sessionDeclinedCount] = TEMPsessionsArray[i]
						if(sessionDeclinedCount == 0) {
							//alert('hey')
						}
						sessionDeclinedCount++
						break;
					case "pending":
						if(TEMPsessionsArray[i].endTimestamp<now) { // In the past
							sessionStats.pendingMissed[sessionPendingMissedCount] = TEMPsessionsArray[i]
							sessionPendingMissedCount++
						} else { // pending
							sessionStats.pending[sessionPendingCount] = TEMPsessionsArray[i]
							sessionPendingCount++
							sessionRequestsArray[sessionRequestsCount] = TEMPsessionsArray[i]
							//alert('hi')
							sessionRequestsCount++
						}
						break;
					case "canceled":
						sessionStats.canceled[sessionCanceledCount] = TEMPsessionsArray[i]
						sessionCanceledCount++
						break;
				}
				//alert('there')
			}
		}
		
		//clientsArray = TEMPclientsArray
		sessionsArray = TEMPsessionsArray
		//sessionDetailsArray = TEMPsessionDetailsArray
		//sessionRemindersArray = TEMPsessionRemindersArray
		//invoicesArray = TEMPinvoicesArray
		//paymentsArray = TEMPpaymentsArray
		//discountsArray = TEMPdiscountsArray
		//phoneNumbersArray = TEMPphoneNumbersArray
		//songsArray = TEMPsongsArray
		todaysSessionsArray = TEMPtodaysSessionsArray
		updateActualSessionsArray = TEMPupdateActualSessionsArray
		//totalPendingInvoicesArray = TEMPtotalPendingInvoicesArray
		upcomingSessionsArray = TEMPupcomingSessionsArray
		//document.getElementById('main_content').innerHTML = "Ready"
		lastUpdate = new Date
		loadingPanel.hide();
		
		//var page = YAHOO.util.History.getCurrentState("page");
		//var id = YAHOO.util.History.getCurrentState("id");
		//var tab = YAHOO.util.History.getCurrentState("tab");
		//alert(id)
		if(loadState == "firstLoad") {
			loadState = "loaded"
			loadBookingForm()
			/*
			if(page == "client") {
				//alert("hello"+id)
				//if(lastGotClient != id) {
				getClientInfo(id)
				tabView.set('activeIndex', tab);
				//}
			} else {
				if(page == "session") {
					//alert("hello"+id)
					//if(lastGotClient != id) {
					getSessionInfo(id)
					sessionTabs.set('activeIndex', tab);
					//}
				} else {
					loadMainPage()
				}
			}
			*/
		} else {
			/*
			if(currentPage == "main") {
				loadMainPage()
			}
			*/
		}
		//alert(lastUpdate)
		//content.style.visibility = "visible";

	}
	
	var handleFailure = function(o){
		alert('prob67');
		if(o.responseText !== undefined){
			div.innerHTML = "<li>Transaction id: " + o.tId + "</li>";
			div.innerHTML += "<li>HTTP status: " + o.status + "</li>";
			div.innerHTML += "<li>Status code message: " + o.statusText + "</li>";
		}
	}
	
	var callback =
	{
	  success: handleSuccess,
	  failure: handleFailure,
	  argument: { foo:"foo", bar:"bar" }
	};
	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
}
function loadBookingForm() {
	//document.getElementById('main_header').innerHTML = null
	/*
		"<table width='100%'>"+
			"<tr>"+
				"<td><img width='50' src='"+studioLogo+"'></td>"+
				"<td><h1 align='left'>"+studioName+"</h1></td>"+
			"</tr>"+
		"</table>"
	*/
	checked1 = ""
	if(duration == 1) {
		checked1 = "checked"
	}
	checked2 = ""
	if(duration == 2) {
		checked2 = "checked"
	}
	checked3 = ""
	if(duration == 3) {
		checked3 = "checked"
	}
	checked4 = ""
	if(duration == 4) {
		checked4 = "checked"
	}
	checked5 = ""
	if(duration == 5) {
		checked5 = "checked"
	}
	checked6 = ""
	if(duration == 6) {
		checked6 = "checked"
	}
	checked7 = ""
	if(duration == 7) {
		checked7 = "checked"
	}
	checked8 = ""
	if(duration == 8) {
		checked8 = "checked"
	}
	checked9 = ""
	if(duration == 9) {
		checked9 = "checked"
	}
	checked10 = ""
	if(duration == 10) {
		checked10 = "checked"
	}
	document.getElementById('main_content').innerHTML = 
	"<div id='session_select' style='padding-top:10px'>"+
		"<div class='yui-g'>"+
			"<div class='yui-u first'>"+
				"<span style='background-color:#00FFCC'><b>1. How many hours?</b></span>"+
				"<div id='buttongroup1' class='yui-buttongroup'>"+
					"<input id='radio1' type='radio' name='radiofield1' value='1' "+checked1+">"+
					"<input id='radio2' type='radio' name='radiofield1' value='2' "+checked2+">"+
					"<input id='radio3' type='radio' name='radiofield1' value='3' "+checked3+">"+
					"<input id='radio4' type='radio' name='radiofield1' value='4' "+checked4+">"+
					"<input id='radio5' type='radio' name='radiofield1' value='5' "+checked5+"><br />"+
					"<input id='radio6' type='radio' name='radiofield1' value='6' "+checked6+">"+
					"<input id='radio7' type='radio' name='radiofield1' value='7' "+checked7+">"+
					"<input id='radio8' type='radio' name='radiofield1' value='8' "+checked8+">"+
					"<input id='radio9' type='radio' name='radiofield1' value='9' "+checked9+">"+
					"<input id='radio10' type='radio' name='radiofield1' value='10' "+checked10+"><br />&nbsp;"+
				"</div>"+
				"<div class='yui-skin-sam' id='cal'><span style='background-color:#00FFCC'>"+
					"<b>2. What day are you booking for?</b></span>"+
					"<div id='calendarContainer'></div>"+
				"</div>"+
				"<div style='clear:both;'></div>"+
			"</div>"+
			"<div class='yui-skin-sam' style='padding-left: 40px;'>"+
				"<div class='yui-skin-sam'>"+
					"<table id='preview'>"+
					"<tr>"+
					"<td>"+
						"<p style='font-size:20; text-align:center'; font-weight:bold>Book Your Session Online!</p><br/>"+
						"<b>Instructions:</b><br/>"+studioName+" makes it easy for you to request your session.<br/><ol><li>Choose how many hours are booking.</li><li>Choose the date for your session.</li><li>Then choose an available session for that day.</li></ol>"+
						"<table align='center' cellpadding='10' BORDER=1 RULES=NONE FRAME=BOX width='250' style='background-color:#FFFFFF;'>"+
						"<col width=75>"+
							"<tr>"+
								"<td align='center' colspan='2' bgcolor='#0099FF'><b>SESSION INFO</b></br /></td>"+
							"</tr>"+
							"<tr>"+
								"<td align='right'><b>Studio:&nbsp;</b></td>"+
								"<td id='studioName'>"+studioName+"</td>"+
							"</tr>"+
							"<tr>"+
								"<td align='right'><b>Hours:&nbsp;</b></td>"+
								"<td id='duration'>"+duration+"</td>"+
							"</tr>"+
							"<tr>"+
								"<td align='right'><b>Day:&nbsp;</b></td>"+
								"<td id='dayOfTheWeekDisplay'>"+dayOfTheWeekDisplay+"</td>"+
							"</tr>"+
							"<tr>"+
								"<td align='right'><b>Date:&nbsp;</b></td>"+
								"<td id='fullDateDisplay'>"+fullDateDisplay+"</td>"+
							"</tr>"+
							"<tr>"+
								"<td align='right'><b>Start Time:&nbsp;</b></td>"+
								"<td id='startTimestamp'>"+startTimestamp+"</td>"+
							"</tr>"+
							"<tr>"+
								"<td align='right'><b>End Time:&nbsp;</b></td>"+
								"<td id='endTimestamp'>"+endTimestamp+"</td>"+
							"</tr>"+
						"</table>"+
					
					"</td>"+
					"</tr>"+
					"</table>"+
				"</div>"+
			"</div>"+
		"</div>"+
		"<div id='schedule-main' class='yui-u'><span style='background-color:#00FFCC'><br /><b>3. Choose an available session.</b></span>"+
			"<div id='schedule'>"+
				"<div id='day_grid'>"+
					"<table>"+
						"<tr>"+
							"<td id='theader'>"+
								"<div style='background-color:yellow'>"+
									"<div id='date1' align='center'>&nbsp;</div>"+
								"</div>"+
							"</td>"+
						"</tr>"+
						"<tr>"+
							"<td id='latenight'>"+
								"<div id='12 AM'>12 AM</div>"+
								"<div id='1 AM'>1 AM</div>"+
								"<div id='2 AM'>2 AM</div>"+
								"<div id='3 AM'>3 AM</div>"+
								"<div id='4 AM'>4 AM</div>"+
								"<div id='5 AM'>5 AM</div>"+
								"<div id='6 AM'>6 AM</div>"+
								"<div id='7 AM'>7 AM</div>"+
								"<div id='8 AM'>8 AM</div>"+
							"</td>"+
							"<td id='morning'>"+
								"<div id='9 AM'>9 AM</div>"+
								"<div id='10 AM'>10 AM</div>"+
								"<div id='11 AM'>11 AM</div>"+
								"<div id='12 PM'>12 PM</div>"+
								"<div id='1 PM'>1 PM</div>"+
								"<div id='2 PM'>2 PM</div>"+
								"<div id='3 PM'>3 PM</div>"+
								"<div id='4 PM'>4 PM</div>"+
							"</td>"+
							"<td id='morning'>"+
								"<div id='5 PM'>5 PM</div>"+
								"<div id='6 PM'>6 PM</div>"+
								"<div id='7 PM'>7 PM</div>"+
								"<div id='8 PM'>8 PM</div>"+
								"<div id='9 PM'>9 PM</div>"+
								"<div id='10 PM'>10 PM</div>"+
								"<div id='11 PM'>11 PM</div>"+
							"</td>"+
						"</tr>"+
					"</table>"+
				"</div>"+
			"</div>"+
		"</div>"+
	"</div>";
	
	YAHOO.util.Event.addListener("12am", "click", highlight)
	var oButtonGroup1 = new YAHOO.widget.ButtonGroup("buttongroup1") 
	//oButtonGroup1.getMenu().subscribe("click", onMenuClick);
	//alert(oButtonGroup1.selectedMenuItem)
	 //checkedButtonChange  : onButtonClick
	oButtonGroup1.addListener("checkedButtonChange", onButtonClick)
	//oButtonGroup1.getMenu().subscribe("click", onMenuClick); 
	//oButtonGroup1.valueChange = onButtonClick;
	function onButtonClick(){
		duration = oButtonGroup1.get("checkedButton").get("value")*1
		document.getElementById('duration').innerHTML = duration;
		//setHighlight()
		setSchedule()
		//alert(oButtonGroup1.get("checkedButton").get("value"))
	};
	calendar = new YAHOO.widget.Calendar("calendarContainer",{navigator:true});
	//function getTodayLabel() {
		//return dateToLocaleString(currentTime, this);
	//	alert("hi")
	//}
	//calendar.render();
	
	
	//alert("hi")
	
	
	
	function handleSelect(type,args,obj) {
		
		
		var dates = args[0];
		var date = dates[0];
		var year = date[0], month = date[1], day = date[2];

		var selected = args[0];
		var selDate = this.toDate(selected[0]);
		bookingDate = selDate
		//getSchedule(selDate.getTime()/1000)
		

		//alert(selDate.getDay())
		
		
		
		
		
		
		
		var txtDate1 = document.getElementById("date1");
					//alert(this);
		//txtDate1.innerHTML = "Schedule for <b>"+dateToLocaleString(selDate, this)+"</b>";
		fullDateDisplay = dateToLocaleString(selDate, this);
		dayOfTheWeekDisplay = dateTodDayOfTheWeek(selDate, this);
		newDateDisplay = 'Schedule for <b>'+fullDateDisplay+'</b>';
		//txtDate1.innerHTML = "Schedule for "+month + "/" + day + "/" + year;
		//txtDate1.innerHTML = "Schedule for <b>"+dateToLocaleString(selDate, call)+"</b>";
		//alert(selDate)
		//alert(currentTime.getDate());
		//alert("hi")
		//txtDate1.innerHTML = "Schedule for <b>"+dateToLocaleString(selDate, this)+"</b>";
		var attributes3 = { 
			opacity: { from: 1, to: 0 }
		}; 
		var anim3 = new YAHOO.util.ColorAnim('schedule', attributes3, .1);
		//alert(document.getElementById('main').filters[0].opacity);
		anim3.animate();
		
		
		
		var attributes4 = { 
			opacity: { from: 0, to: 1 }
		}; 
		var anim4 = new YAHOO.util.ColorAnim('schedule', attributes4, .5);
		//anim2.animate();
		
		
		anim3.onComplete.subscribe(function() {
			//alert(newDateDisplay);
			txtDate1.innerHTML = newDateDisplay;
			document.getElementById('fullDateDisplay').innerHTML = fullDateDisplay;
			document.getElementById('dayOfTheWeekDisplay').innerHTML = dayOfTheWeekDisplay;
			
			//alert(selDate)
			//var selDate = call.toDate(selected[0]);
			//alert(selDate)
			resetScheduleGrid();
			//alert('hi')
			setSchedule()
			anim4.animate();
		});
	
		anim4.onComplete.subscribe(function() {
			//document.getElementById('main').innerHTML += "<br /><span style='opacity:.2'>Who are you booking this Session For?</span>";
			//alert(document.getElementById('main').filters[0].opacity);
			//document.getElementById('main').filters[0].opacity = "";
			//document.getElementById('main').removeProperty("style");
			//document.getElementById('date1').removeAttribute("style");
			//document.getElementById('client_list').onchange = gotClient;
		});
				
	}
	function dateToLocaleString(dt, cal) {
		//alert('hi');
		var wStr = cal.cfg.getProperty("WEEKDAYS_LONG")[dt.getDay()];
		var dStr = dt.getDate();
		var mStr = cal.cfg.getProperty("MONTHS_LONG")[dt.getMonth()];
		var yStr = dt.getFullYear();
		return (mStr + " " + dStr + ", " + yStr);
	}
	function dateTodDayOfTheWeek(dt, cal) {
		//alert('hi');
		var wStr = cal.cfg.getProperty("WEEKDAYS_LONG")[dt.getDay()];
		var dStr = dt.getDate();
		var mStr = cal.cfg.getProperty("MONTHS_LONG")[dt.getMonth()];
		var yStr = dt.getFullYear();
		return (wStr);
	}


	calendar.selectEvent.subscribe(handleSelect, calendar, true);
	//alert('hi')
	renderCal();
}

function confirmSession() {
	
	var attributes = { 
		opacity: { from: 1, to: 0 }
	}; 
	var anim = new YAHOO.util.ColorAnim('session_select', attributes, .1);
	//alert(document.getElementById('main').filters[0].opacity);
	anim.animate();
	
	
	
	var attributes2 = { 
		opacity: { from: 0, to: 1 }
	}; 
	var anim2 = new YAHOO.util.ColorAnim('confirm', attributes2, .5);
	//anim2.animate();
	
	
	anim.onComplete.subscribe(function() {
									   //alert(startTimestamp)
		//window.location = 
		//	'http://www.mystudiosessions.com/new_session.php?&book_the_session=book_it&studio_id='+studioID+'&studio_key=&session_start_timestamp='+(startTimestamp.getTime()/1000)+'&session_end_timestamp='+(endTimestamp.getTime()/1000)+'&duration='+duration
			
			
		window.open (
			'http://www.mystudiosessions.com/new_session.php?&book_the_session=book_it&studio_id='+studioID+'&studio_key=&session_start_timestamp='+(startTimestamp.getTime()/1000)+'&session_end_timestamp='+(endTimestamp.getTime()/1000)+'&duration='+duration, '_blank')
									   
									   
									   
									   
									   
									   
									   
									   
									   
									   
									   
	//alert('hi')
		document.getElementById('main_content').innerHTML = 
		"<div id='preview'>"+
			"<b>Client:</b> <a href='#' onclick='getClientInfo("+client.client_id+"); return false;'>"+client.full_name+"</a><br />"+
			"<b>Hours:</b> <span id='duration'>"+duration+"</span><br />"+
			"<b>Day:</b> <span id='dayOfTheWeekDisplay'>"+dayOfTheWeekDisplay+"</span><br />"+
			"<b>Date:</b> <span id='fullDateDisplay'>"+fullDateDisplay+"</span><br />"+
			"<b>Start Time:</b> <span id='startTimestamp'>"+displayTime(startTimestamp)+"</span><br />"+
			"<b>End Time:</b> <span id='endTimestamp'>"+displayTime(endTimestamp)+"</span><br /><br />"+
		"</div>"+
		"<div id='session_options'>"+
			"<b>Email:</b><br />"+
			"<label style='cursor:pointer'><input id='client_email_checkbox' type='checkbox' name='email'/> Email "+client.full_name+" the info for this session</label><br />"+
		"</div><br /><br />"+
		"<div id='session_options'>"+
			"<b>Invitations:</b><br />"+
			"<label id='client_invite' style='cursor:pointer'><input id='client_invite_checkbox' type='checkbox' name='client_invite'/> Invite "+client.full_name+" to this session</label><br />"+
			"<div id='client_reminder_div' style='visibility:hidden'><label id='client_reminder' style='cursor:pointer'><input id='client_reminder_checkbox' type='checkbox' name='client_reminder'/> Set an email reminder for "+client.full_name+"</label> <select id='client_reminder_times'></select> before the session</div>"+
			"<br /><br />Staff:"+
			"<div id='staff'></div>"+
			"<br /><br />"+
			"<label style='cursor:pointer'><input id='confirm_checkbox' type='checkbox' name='confirm'/> Confirm this session</label><br />"+
		"</div>"+
		"<div id='POSTData'></div>"+
		/*
		"<div class='yui-skin-sam'>"+
			"<style>"+
				"#expandcontractdiv {border:1px dotted #dedede; background-color:#EBE4F2; margin:0 0 .5em 0; padding:0.4em;}"+
				"#treeDiv1 { background: #fff; padding:1em; margin-top:1em; }"+
			"</style>"+
			
			//<!-- markup for expand/contract links -->
			//"<div id='expandcontractdiv'>"+
			//	"<a id='collapse' href='#'>Collapse all</a>"+
			//"</div>"+
			
			//"<div id='treeDiv1'></div>"+
			//"<div>"+
			//	"<button id='show1'>Show panel1</button> "+
			//	"<button id='hide1'>Hide panel1</button>"+
			//"</div>"+
	
			//"<div id='module1'>"+
			//	"<div class='hd'>Panel #1 from Markup</div>"+
			//	"<div class='bd'>This is a Panel that was marked up in the document.</div>"+
			//	"<div class='ft'>End of Panel #1</div>"+
			//"</div>"+
		"</div>"+
		*/
		"<div class='yui-skin-sam' id='confirm'><br /><a id='linkbutton1'>Book This Session</a></div>";
		
		document.getElementById('client_email_checkbox').checked = true
		document.getElementById('client_invite_checkbox').checked = true
		document.getElementById('client_reminder_checkbox').checked = true
		
		var oLinkButton1 = new YAHOO.widget.Button("linkbutton1", { onclick: { fn: book_session } }); 
		
		/*
		myModule = new YAHOO.widget.Module("module1", { visible: false }); 
		//alert('hi')
		myModule.render(); 
		YAHOO.util.Event.addListener("staff_invite_checkbox", "click", myModule.show, myModule, true);
		YAHOO.util.Event.addListener("hide1", "click", myModule.hide, myModule, true);
		*/
		var showHideReminderOnClick = function(e) {
			showHideReminder()
		}
		function showHideReminder() {
			//alert(document.getElementById('client_reminder_times').length)
			if(document.getElementById('client_invite_checkbox').checked == true && document.getElementById('client_reminder_times').length > 0) {
				document.getElementById('client_reminder_checkbox').checked = true
				document.getElementById('client_reminder_div').style.visibility = "visible"
			}
			if(document.getElementById('client_invite_checkbox').checked == false) {
				document.getElementById('client_reminder_div').style.visibility = "hidden"
			}
		}
		YAHOO.util.Event.addListener("client_invite", "click", showHideReminderOnClick);
		
		
		
		for (var i = 0; i < staffArray.length; i++) {
			document.getElementById('staff').innerHTML +=
			"<label style='cursor:pointer'>"+
				"<input id='staff_invite_checkbox_"+i+"' type='checkbox' name='staff_invite"+i+"'/> Invite "+staffArray[i].full_name+
				" to this session</label><br />";
			//alert(staffArray[i].title)
			document.getElementById('staff_invite_checkbox_'+i).checked = false
		}
		for (var i = 0; i < staffArray.length; i++) {
			if(staffArray[i].title == "Engineer") {
				document.getElementById('staff_invite_checkbox_'+i).checked = true
				//alert('hi')
			}
		}
		
		var sr7D = new Object
		sr7D.description = "7 Days"
		sr7D.time = (startTimestamp.getTime()/1000)-(60*60*24)*7
	
		var sr6D = new Object
		sr6D.description = "6 Days"
		sr6D.time = (startTimestamp.getTime()/1000)-(60*60*24)*6
		
		var sr5D = new Object
		sr5D.description = "5 Days"
		sr5D.time = (startTimestamp.getTime()/1000)-(60*60*24)*5
	
		var sr4D = new Object
		sr4D.description = "4 Days"
		sr4D.time = (startTimestamp.getTime()/1000)-(60*60*24)*4
		
		var sr3D = new Object
		sr3D.description = "3 Days"
		sr3D.time = (startTimestamp.getTime()/1000)-(60*60*24)*3
	
		var sr2D = new Object
		sr2D.description = "2 Days"
		sr2D.time = (startTimestamp.getTime()/1000)-(60*60*24)*2
		
		var sr1D = new Object
		sr1D.description = "1 Day"
		sr1D.time = (startTimestamp.getTime()/1000)-(60*60*24)*1
	
		var sr12H = new Object
		sr12H.description = "12 Hours"
		sr12H.time = (startTimestamp.getTime()/1000)-(60*60)*12
		
		var sr6H = new Object
		sr6H.description = "6 Hours"
		sr6H.time = (startTimestamp.getTime()/1000)-(60*60)*6
	
		var sr3H = new Object
		sr3H.description = "3 Hours"
		sr3H.time = (startTimestamp.getTime()/1000)-(60*60)*3
	
		var sr1H = new Object
		sr1H.description = "1 Hour"
		sr1H.time = (startTimestamp.getTime()/1000)-(60*60)*1
		
		time_before_array = new Array(sr7D, sr6D, sr5D, sr4D, sr3D, sr2D, sr1D, sr12H, sr6H, sr3H, sr1H) 
	
		//alert('hi')
		o=0
		for(i=0; i<time_before_array.length; i++) {
			var currentTime = new Date()
			var currentTimeStamp = currentTime.getTime()/1000
			//alert(currentTimeStamp+" "+ time_before_array[i].time)
			if(time_before_array[i].time>currentTimeStamp){
				document.getElementById('client_reminder_times').options[o] = new Option(time_before_array[i].description);
				document.getElementById('client_reminder_times').options[o].value = time_before_array[i].time;
				o++;
			}
		}
		for(i=0; i<document.getElementById('client_reminder_times').length; i++) {
			if(document.getElementById('client_reminder_times').options[i].value == sr1D.time){
				//alert(document.getElementById('client_reminder_times').length)
				document.getElementById('client_reminder_times').selectedIndex = i;
				//alert(document.getElementById('client_reminder_times').selectedIndex)
			}
		}
		showHideReminder();
		
		// AJAX
		var postData = "username=anonymous&userid=0";
		var handleSuccess = function(o){
			if(o.responseText !== undefined){
				div.innerHTML = "Transaction id: " + o.tId;
				div.innerHTML += "HTTP status: " + o.status;
				div.innerHTML += "Status code message: " + o.statusText;
				div.innerHTML += "<li>HTTP headers: <ul>" + o.getAllResponseHeaders + "</ul></li>";
				div.innerHTML += "PHP response: " + o.responseText;
				div.innerHTML += "Argument object: " + o.argument;
			}
		}
		
		var callback =
		{
		  success:handleSuccess,
		  failure: handleFailure,
		  argument: ['foo','bar']
		};

		var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData); 
			//document.getElementById('main').innerHTML += client_list;
		anim2.animate();
		
	});

	anim2.onComplete.subscribe(function() {
	
		//document.getElementById('main').innerHTML += "<br /><span style='opacity:.2'>Who are you booking this Session For?</span>";
		//alert('confirm');
		//document.getElementById('main').filters[0].opacity = "";
		//document.getElementById('main').removeProperty("style");
		//document.getElementById('main_header').removeAttribute("style");
		document.getElementById('main_content').removeAttribute("style");
	});
}