// JavaScript Document
function getHTTPObject(){

	if (window.ActiveXObject) 
	      return new ActiveXObject("Microsoft.XMLHTTP");
 	
	else if (window.XMLHttpRequest) 
     	  return new XMLHttpRequest();
 
 	else {
		alert("Your browser does not support AJAX.");
		return null;
	}
 
}

function next_page(live_site,month,year) {

	httpObject 	= getHTTPObject();
	var cell 	= document.getElementById('mod_js_calendar_content');
	
	if(cell){
		//set 50% fade to cell div
		cell.style.opacity = '0.5';
		cell.style.filter = 'alpha(opacity=50)';
		
		//add preload image
		var divTag=document.createElement("div");
		divTag.id = "preload";
        divTag.setAttribute("align","center");
        divTag.style.margin = "0px auto";
        divTag.style.position = "absolute";		
        divTag.style.left = "0";
        divTag.style.top = "0";		
        divTag.style.width = "100%";
        divTag.style.height = "100%";
        divTag.style.zIndex = "100";
		cell.appendChild(divTag);

		var divImg=document.createElement("div");
		divImg.id = "imgcontent";
        divImg.style.position = "absolute";		
        divImg.style.left = "40%";
        divImg.style.top = "40%";
		//divImg.style.backgroundColor="#FFFFFF";
		//divImg.style.opacity = '0.8';
		//divImg.style.filter = 'alpha(opacity=80)';
		
		var oImg=document.createElement("img");
		oImg.setAttribute('src', 'modules/mod_jscalendar/images/ajax-loader.gif');
		oImg.setAttribute('alt', 'Please wait');
		oImg.setAttribute('title', 'Please wait');
		divImg.appendChild(oImg);
		
		divTag.appendChild(divImg);
		
		if (httpObject != null){
			httpObject.open("POST", live_site+"modules/mod_jscalendar/helpers/calendar.php?mod_month="+month+"&mod_year="+year, true);

			httpObject.send(null);
			httpObject.onreadystatechange = function() {
				if(httpObject.readyState == 4) {
					var records = httpObject.responseText;
					
					//remove the loading effect added above
					//set 100% fade to cell div
					cell.style.opacity = '1';
					cell.style.filter = 'alpha(opacity=100)';

					//display the results, first explode it 
					var fields_array = records.split('explode'); 
					//first explode result goes to the calendar layout
					cell.innerHTML  = fields_array[0];
					
					if(fields_array[1]){
						//second explode result goes to EvenBox
						var newbox = fields_array[1].split('|');
						for(var i in newbox){
							if(typeof(newbox[i])=='string'){
								var newbox_content = newbox[i];
								var newbox_pieces = newbox_content.split('+');
								new modEventsBox({event_box:'mod_eventbox_'+newbox_pieces[1], ajax:live_site+'modules/mod_jscalendar/helpers/modEventsBox.php?'+newbox_pieces[0]});
							}
						}
					}
				}
			}
		}		
		
	}
}
