// JavaScript Document

<!--- script to window --->

removeWindow = function() {
    ColdFusion.Window.destroy('DetailWindow',true);
}
removeImage = function() {
    ColdFusion.Window.destroy('ImageWindow',true);
}

var cursorX;
var cursorY;

CursorPosition = function(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.body.scrollLeft	+ document.documentElement.scrollLeft;
		cursorY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	// cursorX and cursorY contain the mouse position relative to the document
}

makeWindow = function(Title,Source,ClubID,Type,ID) {
	//do we have a window already open?
    try {
        ColdFusion.Window.destroy('DetailWindow',true);
    } catch(e) { }
	
    var winLocationX = cursorX + 150;
	var winLocationY = cursorY - 100;
	
	ColdFusion.Window.create('DetailWindow',Title,'',
		{x:winLocationX,y:winLocationY,width:500,height:100,resizable:true,initshow:true});
	ColdFusion.navigate(Source + '?&c=' + ClubID + '&' + Type + '=' + ID,'DetailWindow',resizeWindow);
	
	myWindow = ColdFusion.Window.getWindowObject('DetailWindow');
	//Add a listener to the "beforehide" event       
    //myWindow.on('beforeshow',resizeWindow);
	
	//assign windowHdr class to header
	document.getElementById(myWindow.header.id).className = "windowHdr"; 

	//ColdFusion.Window.onShow('DetailWindow',resizeWindowWidth);
	ColdFusion.Window.onHide('DetailWindow',removeWindow);
}

imageWindow = function(Title,Source,ClubID,Type,ID,Location) {
	//do we have a window already open?
    try {
        ColdFusion.Window.destroy('ImageWindow',true);
    } catch(e) { }
	
	ColdFusion.Window.create('ImageWindow',Title,'',
		{center:true,width:550,height:475,resizable:true,modal:true});
	ColdFusion.navigate(Source + '?&c=' + ClubID + '&' + Type + '=' + ID + '&' + Location,'ImageWindow');
	
	myWindow = ColdFusion.Window.getWindowObject('ImageWindow');
	//Add a listener to the "beforehide" event       
    //myWindow.on('beforeshow',resizeWindow);
	
	//assign windowHdr class to header
	document.getElementById(myWindow.header.id).className = "windowHdr"; 

	//ColdFusion.Window.onShow('DetailWindow',resizeWindowWidth);
	ColdFusion.Window.onHide('ImageWindow',removeImage);
}

resizeWindow = function (){
	var winWidth = 500;
	//Get window object    
	myWindow = ColdFusion.Window.getWindowObject('DetailWindow');
	//Get the Windows Element object    
   	winEl = myWindow.getEl();
	//Get window height of inner HTML
	var winHeight = document.getElementById('winTable').clientHeight;
	//Overwrite the base width
	/*if (document.getElementById('winTable').clientWidth > 500) {
		winWidth = document.getElementById('winTable').clientWidth;
	}
	else {
		winWidth = 500;
	}*/
	//Set the window height
	myWindow.setContentSize(winWidth,winHeight);
}


