var xmlhttp;
var MCalField;
var MCalField2;
var dateStored;

function changeCal() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("MCalHere").innerHTML=xmlHttp.responseText;
}
}

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;
    }
	document.getElementById('MCalWrap').style.left = posx;
	document.getElementById('MCalWrap').style.top = 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 calOverD(obj) {
var selected;
selected = document.getElementById(obj);
selected.className = "MCalDate3On";
}

function calOutD(obj) {
var selected 
selected = document.getElementById(obj);
selected.className = "MCalDate3";
}

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 MCalSend(obj){
var mon=document.getElementById("selectMonth").value; 
var yr=document.getElementById("selectYear").value; 
if(obj<10){
obj="0"+obj;
}
if(mon<10){
mon="0"+mon;
}
var MCalReturn = obj + "/" + mon + "/" + yr
//var xf = "" + MCalField;
//document.getElementById(xf).value=MCalReturn;
//closeMCal();
document.location.href="excursion-day-view.asp?d=" + MCalReturn;
}

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="/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="/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="/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="/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);
}

////// NEW STUFF JANUARY 2010
function getElementLeft(Elem) {
		var elem;
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		xPos = elem.offsetLeft;
		tempEl = elem.offsetParent;
  		while (tempEl != null) {
  			xPos += tempEl.offsetLeft;
	  		tempEl = tempEl.offsetParent;
  		}
		return xPos;
}


function getElementTop(Elem) {
		if(document.getElementById) {	
			var elem = document.getElementById(Elem);
		} else if (document.all) {
			var elem = document.all[Elem];
		}
		yPos = elem.offsetTop;
		tempEl = elem.offsetParent;
		while (tempEl != null) {
  			yPos += tempEl.offsetTop;
	  		tempEl = tempEl.offsetParent;
  		}
		return yPos;
}


function loseBig(obj){
document.getElementById('calOverMe').style.display = "none";
}
