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

var req;

function navigate(month,year,page_id,parent_level) {
	hide_popup();
	var url = "calendar.php?PAGE_ID="+page_id+"&PARENT_LEVEL="+parent_level+"&month="+month+"&year="+year+"&rnd="+(new Date()).getTime();
	if(window.XMLHttpRequest) {
			req = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	req.open("GET", url, true);
	req.onreadystatechange = callback;
	req.send(null);
}

function callback() {
	if(req.readyState == 4) {
		if(req.status == 200) {
				response = req.responseText;
				document.getElementById("sc_calendar").innerHTML = response;
		} else {
				alert("There was a problem retrieving the data:\n" + req.statusText);
		}
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function show_popup(day, text) {
	var coors = findPos(day);
	var popup = document.getElementById("sc_calendar_popup");
	popup.style.display = "block";
	popup.style.top = coors[1] + 'px';
	popup.style.left = coors[0] + 'px';
	while (text.indexOf("@@@") > -1)
		text = text.replace("@@@", "'");
	popup.innerHTML = text;
	set_timer();
}

function hide_popup() {
	var popup = document.getElementById("sc_calendar_popup");
	popup.style.display = "none";
}


var timerID = null;

function set_timer() {
    if (timerID != null)
		clearTimeout(timerID);
    timerID = self.setTimeout("hide_popup()", 2000)
}

function stop_timer() {
    if (timerID != null)
		clearTimeout(timerID);
}
