/*
*	popupwin.js
*	opens a popup window with no file menu with scroll bars
*	registers popUp Windows for a click event on a array of elements
*/

function PopUpWin(win, title, prop)
{
	this.properties = prop;
	this.win;
	
	if ( typeof(win) == 'string' )
	{
		this.win = document.getElementById(win);
		if ( this.win == null )
			throw new Error("Anchor id: " + win + " for popup window not found");
	}
	else
		this.win = win;
	
	this.title = title;
	
	this.regPopUp();
}

PopUpWin.prototype.regPopUp = function()
{
	var theObj = this;
	addEvent(this.win, 'click', function(e) { theObj.openPopUp.call(theObj, e); } );
}

PopUpWin.prototype.openPopUp = function(e)
{
	var tag = e.target ? e.target : e.srcElement;
	
	e.cancelable ? e.preventDefault() : e.returnValue = false;
		
    window.open(this.win.href, this.title, this.properties);
}

PopUpWin.prototype.toString = function()
{
	return this.title;
}

// the id of the tag is used for the title of the window in this method
// name is the class name of elements that are to be registered.
PopUpWin.regLinksByClassName = function(name, popUps, properties)
{
	theLinks = document.getElementsByTagName('a');
	
	for ( var i = 0; i != theLinks.length; i++ )
	{
		if ( theLinks[i].className == name )
			popUps[i] = new PopUpWin(theLinks[i], theLinks[i].id, properties); 
	}
}

/* as above but uses tag Id and stores the popup objects in the PopUpWin name space */
PopUpWin.popUps = new Array();
PopUpWin.regLinkById = function(tagId, properties)
{
	try
	{
		var theLink;
	
		if ( typeof(tagId) == 'string' )
		{
			theLink = document.getElementById(tagId);
			if ( theLink == null )
				throw new Error("tag id: " + tagId + " for popup window not found");
		}
		else
			theLink = tagId;
	
		PopUpWin.popUps.push(new PopUpWin(theLink, theLink.id, properties)); 
	}
	catch (ex)
	{
		alert(ex.message);
	}

}


// this verion now uses the PopUpWin names space to store the objects and you give it a window
// Title instead of using the id of the tag.
PopUpWin.regLinksByClass = function(name, title, properties)
{
	theLinks = document.getElementsByTagName('a');
	
	for ( var i = 0; i != theLinks.length; i++ )
	{
		if ( theLinks[i].className == name )
			PopUpWin.popUps.push(new PopUpWin(theLinks[i], title, properties)); 
	}
}
