// JavaScript Document
var docRoot = '/scheduler';

function Ajax ()
{
	if (window.XMLHttpRequest) {
		var ajax = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		var ajax = new ActiveXObject('Microsoft.XMLHTTP');
	}
	ajax.onreadystatechange = function() { setPage(ajax) };
	return ajax;
}

function PopJax ()
{
	var ajax = new Ajax;
	ajax.onreadystatechange = function() { setPopup(ajax) };
	return ajax;
}

function setPage (ajax)
{
	if (ajax.readyState == 4) {
		if (ajax.status == 200) {
			if (ajax.responseText != '') {
				document.getElementById('scroller').innerHTML = ajax.responseText;
			}
		}
	} else if (ajax.readyState == 2) {
		document.getElementById('scroller').innerHTML = 
			'<p style="text-align:center; color: #444;">'+
			'<img src="'+docRoot+'/images/loading.gif" height="24" width="24" alt="Loading." /> '+
			'Loading...</p>';
	}
}

function setPopup (ajax)
{
	if (ajax.readyState == 4) {
		if (ajax.status == 200) {
			if (ajax.responseText != '') {
				document.getElementById('popup').innerHTML = ajax.responseText;
			}
		}
	} else if (ajax.readyState == 2) {
		document.getElementById('popup').innerHTML = 
			'<p style="text-align:center; color: #444;">'+
			'<img src="'+docRoot+'/images/loading.gif" height="24" width="24" alt="Loading." /> '+
			'Loading...</p>';
	}
}

function updateAnnouncements ()
{
	var ajax = new Ajax;
	ajax.onreadystatechange = function() { announce(ajax); }
	ajax.open("GET",docRoot+"/announcements.php?echo=t",true);
	ajax.send("");
	setTimeout('updateAnnouncements()', 30000);
}

function announce (ajax)
{
	if (ajax.readyState == 4) {
		if (ajax.status == 200) {
			if (ajax.responseText != '') {
				document.getElementById('announcements').innerHTML = ajax.responseText;
			}
		}
	} else if (ajax.readyState == 2) {
		document.getElementById('announcements').innerHTML = 
			'<p style="text-align:center; color: #444;">'+
			'<img src="'+docRoot+'/images/loading.gif" height="24" width="24" alt="Loading." /> '+
			'Loading...</p>';
	}
}

function grayOut ()
{
	document.getElementById('main-gray').style.display = 'block';
}

function grayIn ()
{
	document.getElementById('main-gray').style.display = 'none';
}

function popIn ()
{
	document.getElementById('popup').style.display = 'block';
}

function popOut ()
{
	document.getElementById('popup').style.display = 'none';
	document.getElementById('popup').innerHTML = '';
}

function pGrayOut ()
{
	parent.document.getElementById('main-gray').style.display = 'block';
}

function pGrayIn ()
{
	parent.document.getElementById('main-gray').style.display = 'none';
}

function pPopIn ()
{
	parent.document.getElementById('popup').style.display = 'block';
}

function pPopOut ()
{
	parent.document.getElementById('popup').style.display = 'none';
	parent.document.getElementById('popup').innerHTML = '';
}



function adjust ()
{
	var div = document.getElementById('main');
	var gray = document.getElementById('main-gray');
	var nav = document.getElementById('sideNav');
	var scr = document.getElementById('scroller');
	if (window.ActiveXObject) {
		div.style.width = (document.body.clientWidth - 220)+'px';
		gray.style.width = (document.body.clientWidth - 220)+'px';
		div.style.height = (document.documentElement.clientHeight - 140)+'px';
		gray.style.height = (document.documentElement.clientHeight - 140)+'px';
		nav.style.height = (document.documentElement.clientHeight - 140)+'px';
		scr.style.height = (document.documentElement.clientHeight - 164)+'px';
	} else {
		div.style.width = (window.innerWidth - 244)+'px';
		gray.style.width = (window.innerWidth - 244)+'px';
		div.style.height = (window.innerHeight - 140)+'px';
		gray.style.height = (window.innerHeight - 140)+'px';
		nav.style.height = (window.innerHeight - 140)+'px';
		scr.style.height = (window.innerHeight - 164)+'px';
	}
}

function showNav ()
{
	if (document.getElementById('sNav')) {
		document.getElementById('sNavPrev').style.display = 'block';
		document.getElementById('sNavCurr').style.display = 'block';
		document.getElementById('sNavNext').style.display = 'block';
	}
}

function hideNav ()
{
	if (document.getElementById('sNav')) {
		document.getElementById('sNavPrev').style.display = 'none';
		document.getElementById('sNavCurr').style.display = 'none';
		document.getElementById('sNavNext').style.display = 'none';
	}
}

function getPos (obj)
{
	var posX = 0;
	var posY = 0;
	posX = obj.offsetLeft;
	posY = obj.offsetTop;
	while (obj = obj.offsetParent) {
		posX += obj.offsetLeft;
		posY += obj.offsetTop;
	}
	return [posX,posY];
}

function popmsg (msgid)
{
	window.open(docRoot + "/popup.php?id=" + msgid, "msgpopup", "width=300,height=200,scrollbars=no,status=no,toolbar=no,location=no,menubar=no,directories=no");
}

function writeBox (ajax)
{
	var dropBox = document.getElementById('dropbox');
		if (ajax.readyState == 4) {
		if (ajax.status == 200) {
			if (ajax.responseText != '') {
				dropBox.innerHTML = ajax.responseText;
			}
		}
	} else if (ajax.readyState == 2) {
		dropBox.innerHTML = 
			'<p style="text-align:center; color: #444;">'+
			'<img src="../images/loading.gif" height="24" width="24" alt="Loading." /> '+
			'Loading...</p>';
	}
}

function clearQuick ()
{
	var dropBox = document.getElementById('dropbox');
	dropBox.innerHTML = '';
	dropBox.style.left = 0+'px';
	dropBox.style.top  = 0+'px';
	dropBox.style.display = 'none';
}

function beginAppt (sid,uid)
{
	slot = sid;
	grayIn();
	popOut();
	hideNav();
	var ajax = new Ajax;
	ajax.open("GET", docRoot+"/my/a.php?begin="+sid, true);
	ajax.send('');
	setInterval('trigTimer('+uid+')',300000);
	setTimeout('endAppt('+sid+')', 3900000);
}

var rating = 0;
var starOff = docRoot + "/images/star-off.gif";
var starOn = docRoot + "/images/star-on.gif";

function starsOn (num)
{
	for (i = num; i > 0; i--) {
		document.getElementById('star'+i).src=starOn;
	}
	for (i = num+1; i < 6; i++) {
		document.getElementById('star'+i).src=starOff;
	}
}
function starsOff ()
{
	for (i = 5; i > rating; i--) {
		document.getElementById('star'+i).src=starOff;
	}
	for (i = 1; i < rating+1; i++) {
		document.getElementById('star'+i).src=starOn;
	}
}

function rate (n, s)
{
	rating = n;
	var ajax = new Ajax;
	ajax.onreadystatechange = function() {
		if (ajax.readyState == 4) {
			if (ajax.status == 200) {
					if (document.getElementById('ratemsg'))
						document.getElementById('ratemsg').innerHTML = "Thank You";
			}
		}
	};
	ajax.open("GET", docRoot+"/my/a.php?rate="+n+"&slot="+s, true);
	ajax.send('');
}

function trigTimer (uid)
{
	var ajax = new Ajax;
	ajax.onreadystatechange = function() { };
	ajax.open("GET", docRoot+"/my/a.php?tt="+uid, true);
	ajax.send('');
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=440');");
}