var xmlhttp;
var MCalField;
var MCalField2;
var dateStored;

function changeCal() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("MCalHere").innerHTML=xmlHttp.responseText;
//updateDate()
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function openMCal(e,obj){
	MCalField=obj;
    var posx = 0;
    var posy = 0;
    if (!e) var e = window.event;
    if (e.clientX || e.clientY)
    {
        posx = e.clientX + document.body.scrollLeft;
        posy = e.clientY + document.body.scrollTop;
    }
    else if (e.pageX || e.pageY)
    {
        posx = e.pageX;
        posy = e.pageY;
    }
	// Changed to go to actual field instead of mouse pos!
	document.getElementById('MCalWrap').style.left = findPosX(document.getElementById(MCalField));//posx;
	document.getElementById('MCalWrap').style.top = findPosY(document.getElementById(MCalField));//posy;
	document.getElementById('MCalWrap').style.display = '';
var xf = "" + MCalField;
if(document.getElementById(xf).value==""){
	calCall();
	}
	else{
	// this is a specicific call
	//calCall('true');
	calCall();
	}
}

function closeMCal(){
document.getElementById('MCalWrap').style.display = 'none';
}

function calOver(obj) {
var selected 
selected = document.getElementById(obj);
selected.className = "MCalDateOn";
}

function calOut(obj) {
var selected 
selected = document.getElementById(obj);
selected.className = "MCalDate";
}

function calOver2(obj) {
var selected 
selected = document.getElementById(obj);
selected.className = "MCalDateOn2";
}

function calOut2(obj) {
var selected 
selected = document.getElementById(obj);
selected.className = "MCalDate2";
}

function calOverG(obj) {
var selected 
selected = document.getElementById(obj);
selected.className = "MCalDate4On";
}

function calOutG(obj) {
var selected 
selected = document.getElementById(obj);
selected.className = "MCalDate4";
}

function MCalSend(obj){
var mon=document.getElementById("selectMonth").value; 
var yr=document.getElementById("selectYear").value; 
if(obj<10){
obj="0"+obj;
}

var MCalReturn = obj + "/" + mon + "/" + yr
//var xf = "" + MCalField;
//document.getElementById(xf).value=MCalReturn;
//closeMCal();
document.location.href="/camcog-events.asp?d="+MCalReturn;
}

function setMonth(obj){
	document.getElementById("selectMonth").value=obj;
	changeDate();
}

function setYear(obj){
	document.getElementById("selectYear").value=obj;
	changeDate();
}

function changeDate(){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var mon=document.getElementById("selectMonth").value; 
var yr=document.getElementById("selectYear").value; 
var url="/resource/MCal/returnMCal.asp";
url=url+"?mon="+mon;
url=url+"&yr="+yr;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=changeCal;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function calCall(obj){
if(!obj) {
 xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/resource/MCal/returnMCal.asp";
url=url+"?sid="+Math.random();
xmlHttp.onreadystatechange=changeCal;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
else{
// this is a specific call
monthSpecific();
}
}

function monthPrev(){ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var mon=document.getElementById("selectMonth").value; 
var yr=document.getElementById("selectYear").value; 

mon=parseFloat(mon)-1
if(mon==0){
mon=12
yr=parseFloat(yr)-parseFloat(1);
}

var url="/resource/MCal/returnMCal.asp";
url=url+"?mon="+mon;
url=url+"&yr="+yr;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=changeCal;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function monthNext(){ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var mon=document.getElementById("selectMonth").value; 
var yr=document.getElementById("selectYear").value; 

mon=parseFloat(mon)+1
if(mon==13){
mon=1
yr=parseFloat(yr)+parseFloat(1);
}

var url="/resource/MCal/returnMCal.asp";
url=url+"?mon="+mon;
url=url+"&yr="+yr;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=changeCal;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

