
function getXY(el) {
	var xy = new Array(0, 0);
	while (el) {
		xy[0] += el.offsetLeft;
		xy[1] += el.offsetTop;
		el = el.offsetParent;
	}
	return xy;
}

function qkZoom(imgURL, imgTitle, imgWidth, imgHeight) {
	imgURL = encodeURIComponent(imgURL);
	if (!imgWidth)
		imgWidth = 650;
	if (!imgHeight)
		imgHeight = 650;
	var hWnd = window.open("/qk2/showImage.aspx?imgURL=" + imgURL, "qkZoom", "scrollbars=yes,menubar=no,personalbar=no,resizable=yes,toolbar=no,width=" + imgWidth + ",height=" + imgHeight);
}
	
function qkFlash(flashName, imgWidth, imgHeight) {
	flashName = encodeURIComponent(flashName);
	if (!imgWidth)
		imgWidth = 550;
	if (!imgHeight)
		imgHeight = 520;
	var hWnd = window.open("/qk2/img/flash/educational/showFlash.aspx?flashId=" + flashName, "qkVideo", "scrollbars=yes,menubar=no,personalbar=no,resizable=yes,toolbar=no,width=" + imgWidth + ",height=" + imgHeight);
}
	
function showCalendar(target) {
	calendarTarget = target;
	curDateStr = target.innerHTML;
	
	var curMonth;
	var curDay;
	var curYear;
	
	if (curDateStr == "") {
		var now = new Date();
		curMonth = now.getMonth()+1;
		curDay = now.getDate();
		curYear = now.getUTCFullYear();
	}
	else {
		var parts = curDateStr.split("/");
		curMonth = parts[0];
		curDay = parts[1];
		curYear = parts[2];
	}
	
			if (calendarTarget.id == 'startdate'){
			curMonth = 10;
			}
			else if (calendarTarget.id == 'enddate'){
			curMonth = 10;
			}	
	refreshCalendar(curMonth, curYear);

//	document.getElementById('shade').style.display = "block";
//	document.getElementById('shade').style.width = document.body.clientWidth;
	document.getElementById('calendarDiv').style.display = "block";
	var xy = getXY(target);
	document.getElementById('calendarDiv').style.left = (xy[0]) + "px";
	document.getElementById('calendarDiv').style.top = (xy[1]) + "px";
}

function refreshCalendar(curMonth, curYear) {
	document.getElementById('calendarMonth').innerHTML = getMonthStr(curMonth);
	document.getElementById('calendarYear').innerHTML = curYear;
	
	var g = document.getElementById('calendarGrid');
	g.innerHTML = "";
	var tb = document.createElement("TABLE");
	tb.style.width = "100%";
	var tbody = document.createElement("TBODY");
	tb.appendChild(tbody);
	var tr;
	var i;
	var w = 1;
	var firstDay = new Date(curYear+"/"+curMonth+"/"+1);  // this object represents the first day of this month
	for (i=1-firstDay.getDay(); i<=daysInMonth(curMonth, curYear); i++) {
		if (w % 7 == 1) {
			tr = document.createElement("TR");
		}
		el = document.createElement("TD");
		if (i >= 1) {
			el.className = "cDate";
			el.innerHTML = i;
			el.onclick = pickDate;
		}
		else {
			el.className = "cDateEmpty";
		}
		g.appendChild(el);
		tr.appendChild(el);
		
		if (w % 7 == 0) {
			tbody.appendChild(tr);
		}
		w++;
	}
	if ((w - 1) % 7 > 0) {
		for (i= 7 - ((w - 1) % 7); i > 0; i--) {
			el = document.createElement("TD");
			el.className = "cDateEmpty";
			tr.appendChild(el);
		}
		tbody.appendChild(tr);
	}
	
	g.appendChild(tb);
}

function hideCalendar() {
//	document.getElementById('shade').style.display = "none";
	document.getElementById('calendarDiv').style.display = "none";
}

function nextMonth() {
	var curMonth = getMonthInt(document.getElementById('calendarMonth').innerHTML);
	var curYear = document.getElementById('calendarYear').innerHTML;
	
	var nextMonth = curMonth + 1;
	var nextYear = curYear;
	if (nextMonth > 12) {
		nextMonth = 1;
		nextYear++;
	}
	
	refreshCalendar(nextMonth, nextYear);
}

function prevMonth() {
	var curMonth = getMonthInt(document.getElementById('calendarMonth').innerHTML);
	var curYear = document.getElementById('calendarYear').innerHTML;
	
	var prevMonth = curMonth - 1;
	var prevYear = curYear;
	if (prevMonth < 1) {
		prevMonth = 12;
		prevYear--;
	}
	
	refreshCalendar(prevMonth, prevYear);
}

function pickDate() {
	if (calendarTarget != null) {
		with (this) {
			// innerHTML is the date number
			calendarTarget.innerHTML = "";
			var year = document.getElementById('calendarYear').innerHTML;
			var month = (String) (getMonthInt(document.getElementById('calendarMonth').innerHTML));
			while (month.length < 2)
				month = "0" + month;
			var day = innerHTML;
			while (day.length < 2)
				day = "0" + day;
			var dateString = month + "/" + day + "/" + year;
			calendarTarget.innerHTML = dateString;
			document.getElementById('podate').value = dateString;
			if (calendarTarget.id == 'startdate'){
			document.getElementById('checkIn').value = dateString;
			}
			else if (calendarTarget.id == 'enddate'){
			document.getElementById('checkOut').value = dateString;
			}
			
			
		}
	}
	hideCalendar();
}

function getMonthInt(month) {
	switch (month.toLowerCase()) {
		case "january":		return 1;
		case "february":	return 2;
		case "march":		return 3;
		case "april":		return 4;
		case "may":			return 5;
		case "june":		return 6;
		case "july":		return 7;
		case "august":		return 8;
		case "september":	return 9;
		case "october":		return 10;
		case "november":	return 11;
		case "december": 	return 12;
		default:			var now = new Date();
							return now.getMonth() + 1;
	}
}

function getMonthStr(num) {
	var monthNames = new Array( "January","February","March","April","May","June","July","August","September","October","November","December");
	if (num <= 0 || num > 12) {
		var now = new Date();
		return monthNames[now.getMonth()];
	}
	return monthNames[num-1];
}

function daysInMonth(month, year) {
	var m = [31,28,31,30,31,30,31,31,30,31,30,31];
	if (month != 2) return m[month - 1];
	if (year%4 != 0) return m[1];
	if (year%100 == 0 && year%400 != 0) return m[1];
	return m[1] + 1;
}

window.onload = ActivateFlash

function ActivateFlash()
{
	var objects = document.getElementsByTagName("object");
	for (var i = 0; i < objects.length; i++)
		objects[i].outerHTML = objects[i].outerHTML;
}
