// JavaScript Document

function removeWindow() {
    ColdFusion.Window.destroy('DetailWindow',true);
}
var cursorX;
var cursorY;
function CursorPosition(e) {
	cursorX = 0;
	cursorY = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		cursorX = e.pageX;
		cursorY = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		cursorX = e.clientX + document.getElementById("calendarPageContainer").scrollLeft	+ document.documentElement.scrollLeft;
		cursorY = e.clientY + document.getElementById("calendarPageContainer").scrollTop + document.documentElement.scrollTop;
	}
	// cursorX and cursorY contain the mouse position relative to the document
}
function makeWindow(Title,ClubID,Type,ID,Date) {
	//do we have a window already open?
    try {
        ColdFusion.Window.destroy('DetailWindow',true);
    } catch(e) { }
	
	var yOffset = 200;
	var xOffset = 50;
	var xResolution = document.getElementById("calendarPageContainer").clientWidth;
	var winWidth = 340;
	var winHeight = 175;
	var winLocationX = 0;
	var winLocationY = 0;
	
    //set the x location for window
	if (xResolution > cursorX + xOffset + winWidth) {
		winLocationX = cursorX + xOffset;
	}
	else if (cursorX > winWidth + xOffset) {
		winLocationX = cursorX - (winWidth + xOffset);
	}
	else {
		winLocationX = cursorX;
	}
	
	//set the y location for window
	if (cursorY > yOffset + 25) {
		winLocationY = cursorY - yOffset;
	}
	else {
		winLocationY = cursorY + 25;
	}
	
	if (Type == "ceid") {
		ColdFusion.Window.create('DetailWindow',Title,'',{x:winLocationX,y:winLocationY,width:winWidth,height:winHeight,resizable:true});
		ColdFusion.navigate('/calendar/window/calendar_event_window.cfm?&c=' + ClubID + '&ceid=' + ID + '&displayDate=' + Date,'DetailWindow',resizeWindow);
	}
	else if (Type == "smid") {
		ColdFusion.Window.create('DetailWindow',Title,'',{x:winLocationX,y:winLocationY,width:winWidth,height:winHeight,resizable:true},resizeWindow);
		ColdFusion.navigate('/calendar/window/meet_event_window.cfm?&c=' + ClubID + '&smid=' + ID,'DetailWindow',resizeWindow);
	}
	else if (Type =="cid") {
		ColdFusion.Window.create('DetailWindow',Title,'',{x:winLocationX,y:winLocationY,width:winWidth,height:winHeight,resizable:true},resizeWindow);
		ColdFusion.navigate('/calendar/window/event_event_window.cfm?&c=' + ClubID + '&cid=' + ID,'DetailWindow',resizeWindow);
	}
	
	document.getElementById(ColdFusion.Window.getWindowObject('DetailWindow').header.id).className = "windowHdr"; //assign windowHdr class to header
//	ColdFusion.Log.dump(win.header);

	ColdFusion.Window.onHide('DetailWindow',removeWindow);
}
//open new window and submit Form vars to print page
function printCalendar() {
	var form = document.getElementById('calendarForm');
	var pastAction = form.action;
	form.setAttribute("target", "_blank");
	form.action = '/calendar/print/';
	form.submit();
	//remove print attributes
	form.action = pastAction;
	form.removeAttribute("target");
}
//advance calendar month
function advanceMonth(month,year) {
	document.getElementById('monthField').value=month;
    document.getElementById('yearField').value=year;
    document.forms['calendarForm'].submit();
}

