window.defaultStatus="Vancouver Guild of Puppetry";
// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false;
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEDOWN);
// Set-up to use getMouseXY function onMouseMove
document.onmousedown = getMouseXY;
// Temporary variables to hold mouse x-y pos.s
var tempX = 0;
var tempY = 0;
var admin_path = 'http://vgop.org/vgop_admin';

var winWidth = 0;
var winHeight = 0;
var winMidX = 0;

// Figures out the width, height window deminsions and middle vertical position
function getWindowDeminsions() {  
	  if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		winWidth = window.innerWidth;
		winHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		winWidth = document.documentElement.clientWidth;
		winHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		winWidth = document.body.clientWidth;
		winHeight = document.body.clientHeight;
	  }
	  winMidX = winWidth/2;
}

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	} 
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}  
// catch possible negative values in NS4
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0} 	
	return true;
}

var lastDay = "";
function getDayInfo (day,events,url)
{
	var width = 200;
	getWindowDeminsions();
	
	document.getElementById('DayInfo').innerHTML = '<img src="/template/default/images/loading.gif" width="120" height="30" alt="Loading..." />';
	document.getElementById('DayInfo').style.top = tempY+"px";
	if(tempX > winMidX)
		document.getElementById('DayInfo').style.left = (tempX-(width+16))+'px'; 
	else
		document.getElementById('DayInfo').style.left = (tempX+16)+'px'; 
	document.getElementById('DayInfo').style.width = width+'px';
	if(document.getElementById('DayInfo').style.visibility == "hidden")
		document.getElementById('DayInfo').style.visibility="visible";
	else
		if(lastDay == day)
		document.getElementById('DayInfo').style.visibility="hidden";
	
	lastDay = day;
	var pars = 'a=view_day&d='+day+'&events='+events+'&i=Yes';
    var target = 'DayInfo';
	var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});

}
function getEventInfo (event,day,url,elm)
{
	getWindowDeminsions();
	var target = (elm)? elm : "EventInfo";
	document.getElementById(target).innerHTML = '<img src="/template/default/images/loading.gif" width="120" height="30" alt="Loading..." />';
	if(document.getElementById('DayInfo').style.visibility == "visible")
		document.getElementById('DayInfo').style.visibility="hidden";

	if(document.getElementById(target).style.visibility == "hidden")
		document.getElementById(target).style.visibility="visible";
	document.getElementById(target).style.left = (winMidX-380)+'px'; 		
	var pars = 'a=view_event&i=Yes&e='+event+'&d='+day;
   	var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});

}

function popupCalendar (url,calendarid,month,year,day)
{
	document.getElementById('popupCalendar').innerHTML = '<img src="/template/default/images/loading.gif" width="120" height="30" alt="Loading..." />';
	if (!month && !year && !day)
	{
		var month = document.getElementById('select_month').value;
		var year = document.getElementById('select_year').value;
		var day = document.getElementById('select_day').value;
	}
	
	if(document.getElementById('popupCalendar').style.visibility == "hidden")
		document.getElementById('popupCalendar').style.visibility="visible";
	document.getElementById('popupCalendar').style.left = (winMidX+255)+'px'; 
	var pars = 'a=popupCalendar&i=Yes&d='+year+'-'+month+'-'+day+'&cal_id='+calendarid;
    var target = 'popupCalendar';
	var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});

}

function changeDate(date,fieldid)
{
	document.getElementById(fieldid).value = date;
	document.getElementById('popupCalendar').style.visibility="hidden";

}

function closeHelp(id)
{
	document.getElementById(id).style.visibility="hidden";
	return true;
}

function changeVisibility(id, width)
{
	document.getElementById(id).style.top = tempY+"px";
	document.getElementById(id).style.left = (tempX+16)+'px'; 
	document.getElementById(id).style.width = width+'px';
	if(document.getElementById(id).style.visibility == "hidden")
		document.getElementById(id).style.visibility="visible";
	else
		document.getElementById(id).style.visibility="hidden";	
	return true;
}