var firstTime=true
// DEVELOPMENT: var ajaxHost="http://localhost/forgetmenotfarms/brkg/ajaxResponses/";
var ajaxHost = "http://www.forgetmenotfarms.com/brkg/ajaxResponses/"; // PRODUCTION
var ContentDiv = document.getElementById("content");
	
function pageInit(){
	moonrise()
	writeAccess()
}

function moonrise(){
	if(firstTime){
		moonObj = document.getElementById("moon").style
		moonObj.top="540px"
		moonObj.height="0px"
	}
	firstTime=false
	
	currTop = parseInt(moonObj.top)-2
	currHeight = parseInt(moonObj.height)
	if(currHeight<=292){
		currHeight+=2
		moonObj.height=currHeight+"px"
	}
	moonObj.top=currTop+"px"
	
	if(currTop>8){
		setTimeout("moonrise()",20)
	}		
}

function writeAccess(str){
	xmlWA = GetXmlHttpObject();
	
	var ContentDiv = document.getElementById("content");

  	if (xmlWA==null){
  		ContentDiv.innerHTML = "Your browser does not support AJAX!";
  		return;
  	}

	var strURL = ajaxHost+"access.php";
	if('tok' == str){
		strURL += "?tok";
	}
	if('logout' == str){
		strURL += "?logout";
	}
	if('login' == str){
		var un = document.getElementById("inpUserName").value;
		var pw = document.getElementById("inpPassword").value;
		strURL += "?" + un + "&" + pw;
	}
	try{
		xmlWA.open("GET",strURL,true);
	}
	catch(err){
		alert(err);
	}
	xmlWA.send(null);
	xmlWA.onreadystatechange=function(){
		if (xmlWA.readyState==4 && xmlWA.status==200) {
      		ContentDiv.innerHTML=xmlWA.responseText;
      	}
	}
	
}

function scheduleDetailsPage(itemid){
	var xmlHttp=GetXmlHttpObject();
	var strURL = ajaxHost+"fillScheduleItem.php?" + itemid;
	var ContentDiv = document.getElementById("content");
	
	if (xmlHttp==null){
  		ContentDiv.innerHTML = "Your browser does not support AJAX!";
  		return;
  	}
  	xmlHttp.open("GET", strURL, true);
  	xmlHttp.send(null);
  	xmlHttp.onreadystatechange=function() {
   	if (xmlHttp.readyState==4 && xmlHttp.status==200) {
      	ContentDiv.innerHTML=xmlHttp.responseText;
		}
     	}
}

function thisWeekPage(){
	var xmlHttp=GetXmlHttpObject();
	var strURL = ajaxHost+"fillThisWeekCalendar.php";
	var ContentDiv = document.getElementById("content");
	if (xmlHttp==null){
  		ContentDiv.innerHTML = "Your browser does not support AJAX!";
  		return;
  	} 
  	xmlHttp.open("GET", strURL, true);
	xmlHttp.send(null);		
  	xmlHttp.onreadystatechange=function() {
   	if (xmlHttp.readyState==4 && xmlHttp.status==200) {
      	ContentDiv.innerHTML=xmlHttp.responseText;
		}
     	}
}

function nextWeekPage(){
	var xmlHttp=GetXmlHttpObject();
	var strURL = ajaxHost+"fillNextWeekCalendar.php";
	var ContentDiv = document.getElementById("content");
	if (xmlHttp==null){
  		ContentDiv.innerHTML = "Your browser does not support AJAX!";
  		return;
  	}  
  	xmlHttp.open("GET", strURL, true);
	xmlHttp.send(null);		
  	xmlHttp.onreadystatechange=function() {
   	if (xmlHttp.readyState==4 && xmlHttp.status==200) {
      	ContentDiv.innerHTML=xmlHttp.responseText;
		}
     	}
}

function GetXmlHttpObject(){
	var jxm=null;
	try{
  		// Firefox, Opera 8.0+, Safari
  		jxm=new XMLHttpRequest();
  	}
	catch (e){
  		// Internet Explorer
  		try{
    		jxm=new ActiveXObject("Msxml2.XMLHTTP");
    	}
  		catch (e){
    		jxm=new ActiveXObject("Microsoft.XMLHTTP");
    	}
  	}
	return jxm;
}
