//////////////////////////////////////////////////////////////////////////////
//	Author: 		Andrew Dennison											//
//	Date: 			27/01/03												//
//	Description:	Popup window to display Comma Seperated Values (CSV)	//
//////////////////////////////////////////////////////////////////////////////

////////////////////////////////
//	Global Variables

// Browser Versions
var m_boNS4=document.layers?true:false;
var m_boIE=document.all?true:false;
var m_boNS6=!m_boIE&&document.getElementById?true:false;
var m_boOldBrowser=!m_boNS4&&!m_boNS6&&!m_boIE;

// Window Variables
var m_xWindow = 0;
var m_fWindowWidth = 0;
var m_fWindowHeight = 0;
var m_fWindowX;
var m_fWindowY;

var displaybelow = false;


//////////////////////////////////////////////////////////////////////////////
//	Method: 		Andrew Dennison											//
//	Date: 			27/01/03												//
//	Name:			Popup_Init												//
//	Description:	Initialises module										//
//	Parameters:		none													//
//	Returns:		none													//	
//////////////////////////////////////////////////////////////////////////////
function Popup_Init()
{
 	if( m_boNS4 )
	{
		m_xWindow = document.popupwindowID;
	}
 
 	if( m_boIE )
	{
		m_xWindow = document.all.popupwindowID.style;
	}
 
 	if( m_boNS6 )
	{
		m_xWindow = document.getElementById( "popupwindowID" ).style;
	}
} // Popup_Init




//////////////////////////////////////////////////////////////////////////////
//	Method: 		Andrew Dennison											//
//	Date: 			27/01/03												//
//	Name:			Popup_Pop												//
//	Description:	Renders the popup window								//
//	Parameters:		none													//
//	Returns:		none													//	
//////////////////////////////////////////////////////////////////////////////
function Popup_Pop(_bg1, _bg2, _displaybelow, _message, _bogift, _giftimage )
{  
  	var columns = 4;
	var tablewidth = 550;
	var boEven = true;
	var boHideColumn = false;
	var boNoData;
	
	displaybelow = _displaybelow;
	
  	var names =_message.split(",");
	
	if( columns > names.length )
	{
		columns = names.length;	
	}
	
	var columnwidth = tablewidth / columns;
	var rows = names.length / columns;
	rows = Math.ceil(rows);
	
	if( ( rows * ( columns-1 ) ) >= names.length )
	{
		boHideColumn = true;
	}
	
	if( names[0] == '' )
	{
		boNoData = true;
	}
	else
	{
		boNoData = false;
	}
	
	var content = "<table width=" + ( columns * columnwidth ) +" border=1 align=center cellpadding=10 cellspacing=0 bordercolor=dfe5f7>";
	
	if( boNoData )
	{
		content += "<tr><td bgcolor=777792 bordercolor=777792><p><strong>Currently no people are booked into this class</strong></p></td></tr>";
		content += "</table>";
	}
	else
	{
		if( names.length == 1)
		{
			content += "<tr><td bgcolor=777792 bordercolor=777792><p><strong>Currently 1 person is booked into this class</strong></p></td></tr>";
		}
		else
		{
			content += "<tr><td bgcolor=777792 bordercolor=777792><p><strong>Currently " + names.length + " people are booked into this class</strong></p></td></tr>";
		}
		content += "<tr><td bgcolor=B1B3C8 bordercolor=B1B3C8 ><table width=" + ( columns * columnwidth ) +" border=1 cellpadding=2 cellspacing=0 bordercolor=FFFFFF>";  
		
		for(var i=0; i < rows; i++)
		{
			boEven = true;
			content += "<tr>";
			
			for(var j=0; j < columns; j++)
			{
				if( (j == columns-1) && boHideColumn )
				{
					if( !boEven )
					{
						content += "<td height=\"20\" align=left bordercolor=" + _bg1 + " bgcolor=" + _bg1 + ">"; 
					}
					else
					{
						content += "<td height=\"20\" align=left bordercolor=" + _bg2 + " bgcolor=" + _bg2 + ">"; 
					}
				}
				else
				{
					if( boEven )
					{
						content += "<td height=\"20\" align=left bordercolor=" + _bg1 + " bgcolor=" + _bg1 + ">"; 
					}
					else
					{
						content += "<td height=\"20\" align=left bordercolor=" + _bg2 + " bgcolor=" + _bg2 + ">"; 
					}
				}	
				boEven ^= 1;
				
				content += "<p class = \"name\">";
				if( i + ( rows * j ) < names.length)
				{
					if(_bogift)
					{
						// Now use the _ delimination to get the award number
						var entry = names[ i + ( rows * j ) ].split("_");
						
						//if( entry.length >= 2 )
						if( entry[1] != "" )
						{	
							content += "<img src=\"" + _giftimage + "\" align=\"absmiddle\"> ";
							content += entry[0];
						}
						else
						{
							content += entry[0];
						}
					}
					else
					{
						content += names[ i + ( rows * j ) ];
					}
				}
				else
				{
					content += "&nbsp";
				}
				content += "</p>";
				content += "</td>";
			}
			content += "</tr>";
		}
		
		content += "</td></tr></table>";
		content += "</table>";
	}
		
	m_fWindowWidth = ( columns * columnwidth );
	m_fWindowHeight = rows * 22;
	
	m_xWindow.left =  m_fWindowX - ( m_fWindowWidth / 2  );
	
	if(displaybelow)
	{
  	m_xWindow.top  =  m_fWindowY + 22;
	}
	else
	{
		m_xWindow.top  =  m_fWindowY - ( m_fWindowHeight + 80 );
	}
	  
	if(m_boOldBrowser)
	{
		alert("You have an m_boOldBrowser web browser:\n"+_m);
		return;
	}
	else
	{
		if(m_boNS4)
		{
			  m_xWindow.document.open();
			  m_xWindow.document.write(content);
			  m_xWindow.document.close();
			  m_xWindow.visibility="visible";
		}
		if(m_boNS6)
		{
			  document.getElementById("popupwindowID").style.position="absolute";
			  document.getElementById("popupwindowID").style.left=m_fWindowX;
			  document.getElementById("popupwindowID").style.top=m_fWindowY;
			  document.getElementById("popupwindowID").innerHTML=content;
			  m_xWindow.visibility="visible";
		}
		if(m_boIE)
		{
			  document.all("popupwindowID").innerHTML=content;
			  m_xWindow.visibility="visible";
		}
  	}
}

function get_mouse(e)
{
  m_fWindowX=(m_boNS4||m_boNS6)?e.pageX:event.clientX+document.body.scrollLeft; 
  m_fWindowY=(m_boNS4||m_boNS6)?e.pageY:event.clientY+document.body.scrollLeft; 
  if(m_boIE&&navigator.appVersion.indexOf("MSIE 4")==-1)
	  m_fWindowY+=document.body.scrollTop;
  m_xWindow.left =  m_fWindowX - ( m_fWindowWidth / 2  );
  
	if(displaybelow)
	{
		m_xWindow.top  =  m_fWindowY + 20;
	}
	else
	{
		m_xWindow.top  =  m_fWindowY - ( m_fWindowHeight + 80 );
	}
}


function removeBox()
{
  if(!m_boOldBrowser)
  {
	m_xWindow.visibility="hidden";
  }
}


if(m_boNS4)
  document.captureEvents(Event.MOUSEMOVE); 
if(m_boNS6)
  document.addEventListener("mousemove", get_mouse, true);
if(m_boNS4||m_boIE)
  document.onmousemove=get_mouse;