function handleDivTag_calendarm(divtag){
   var divtag;
   return divtag;
}

function createRequestObject_calendarm() {
	var req;
	if(window.XMLHttpRequest){
		req = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("There was a problem creating the XMLHttpRequest object");
	}
	return req;
}
	
var http_calendarm = createRequestObject_calendarm();
var divhandler_calendarm = new handleDivTag_calendarm(null);

function sendRequest_calendar1m(more,divtag) {
	if (window.timeoutID) window.clearTimeout(window.timeoutID);
	//if (document.getElementById(divtag)) document.getElementById(divtag).innerHTML = "<img src='/filebin/images/loading_apple.gif'>";
	window.timeoutID = window.setTimeout("sendRequest_calendarm('"+more+"', '"+divtag+"')",200);
}
function sendRequest_calendar1m_mc(more,divtag) {
	if (window.timeoutID) window.clearTimeout(window.timeoutID);
	//if (document.getElementById(divtag)) document.getElementById(divtag).innerHTML = "<img src='/filebin/images/loading_apple.gif'>";
	window.timeoutID = window.setTimeout("sendRequest_calendarm('"+more+"', '"+divtag+"')",200);
}
function sendRequest_calendarm(more,divtag) {
	//alert(more);
	if (document.getElementById(divtag)) document.getElementById(divtag).innerHTML = "<img src='/filebin/images/loading.gif'>";
	
	if (divtag == "calendar_ajax")	http_calendarm.open("get", "/filebin/ajax/php/public_calendar_np.php?"+more);
	if (divtag == "mini_calendar")	{
		http_calendarm.open("get", "/filebin/ajax/php/public_calendar_np_big.php?"+more+"&currMonth="+js_month+"&currYear="+js_year);	
	}
	if (divtag == "event_detail")	{
            http_calendarm.open("get", "/filebin/ajax/php/public_calendar_event_detail.php?"+more+"&currMonth="+js_month+"&currYear="+js_year);
            //sendRequest_calendar1m(more, "mini_calendar");
        }
	http_calendarm.onreadystatechange = handleResponse_calendarm;
	divhandler_calendarm.divtag = divtag;
	//if (document.getElementById(divhandler_calendarm.divtag).innerHTML == "logout") window.location.reload();
	http_calendarm.send(null);
}

function handleResponse_calendarm() {    
	if(http_calendarm.readyState == 4 && http_calendarm.status == 200){
		var response = http_calendarm.responseText;
		if(response) {
			document.getElementById(divhandler_calendarm.divtag).innerHTML = response;
			
			
			
			if (document.all) {
			  if (document.documentElement) {
				vHeight = document.documentElement.clientHeight;
			  } else {
				vHeight = document.body.clientHeight
			  }
			} else {
			  vHeight = window.innerHeight;
			}
			var brs=navigator.userAgent.toLowerCase();
			if (brs.indexOf("mozilla") == -1) {

					if (document.body.offsetHeight < vHeight) {				
						//setFooter();				
						window.setTimeout('document.getElementById("wrapper").style.height=(vHeight-100)+"px"; ',20)
						
					}else{
						window.setTimeout('document.getElementById("wrapper").style.height=parseInt(document.getElementById("event_detail").style.height); ',20)			
					}
			}else{
				document.getElementById("wrapper").style.minHeight=(vHeight-150)+"px";
				//window.setTimeout('document.getElementById("wrapper").style.height=parseInt(document.body.offsetHeight)+"px";',100)
				
			}
			
		}
		//else document.getElementById(divhandler_calendarm.divtag).innerHTML = "Loading...";
	}
}
function reg_event(id) {
	var name =  "reg_form_"+id;
	document.getElementById(name).submit();	
}

//big calendar pop up even details
function event_d(event_id, page_id) {
	var more = "type="+event_id+"&day_id="+page_id;
	sendRequest_calendar1m(more,'event_detail');
}
function event_mc(event_id, page_id) {
	var more = "type="+event_id+"&day_id="+page_id;
	sendRequest_calendar1m(more,'mini_calendar');
}
function moveObject(e, id, page_id) {
  var tempX = 0;
  var tempY = 0;
  var offset = 5;
/*
  if (document.all) {
    tempX = event.clientX + document.documentElement.scrollLeft;//document.body.scrollLeft;
    tempY = event.clientY + document.documentElement.scrollTop;//document.body.scrollTop;
	//alert(event.clientY+" ScrollTop:"+document.documentElement.scrollTop);
  } else {
    tempX = e.pageX;
    tempY = e.pageY;
  }
alert("test");
*/
  // step 4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}
  if (tempX>255) tempX = tempX - 255;
	document.getElementById("mini_calendar").style.left = tempX+"px";
	document.getElementById("mini_calendar").style.top = tempY+"px";
	//alert(tempX+" "+tempY);
	document.getElementById("mini_calendar").style.display = "block";
	document.getElementById("event_detail").style.left = tempX+"px";
	document.getElementById("event_detail").style.top = tempY+"px";
	//alert(tempX+" "+tempY);
	document.getElementById("event_detail").style.display = "block";
	event_d(id, page_id);
  }
 /*function close_div(div) {
	 document.getElementById(div+"_iframe").style.display = "none";
	 if (div=="event") document.getElementById("event_detail").style.display = "none";
 }
*/