
var Popup = Class.create();

Popup.prototype = {
	
	initialize: function(containerId, linkId, closeCallback)
	{
		this.opened = false;
		this.container = $(containerId);
		this.closeCallback = closeCallback;
		
		if (!this.container)
			return false;
		
		if (linkId)
			this.link = $(linkId);
		
		if (this.link)
			Event.observe(this.link, 'click', this.open.bindAsEventListener(this));
	}, 
	
	open: function(e)
	{
		this.container.style.display = 'block';
		Event.observe(document, 'click', this.globalPopupWatcher.bindAsEventListener(this));
		this.opened = true;
		
		if (e)
			Event.stop(e);
	},
	
	globalPopupWatcher: function(e)
	{
		var target = Event.element(e);
		if (!this.opened)
			return;
		
		if (target == this.container)
			return;
		
		if (target.nodeName != 'BODY' && target.nodeName != 'HTML') {
			var parent = target.parentNode;
			while (parent.nodeName != 'BODY') {
				if (parent == this.container)
					return;
				else
					parent = parent.parentNode;
			}
		}
		this.close();
		
	},
	
	close: function()
	{	
		this.container.style.display = 'none';
		this.opened = false;
		
		if (this.closeCallback) {
			this.closeCallback();
			
		}
	}
	
};

function expandFaq(obj)
{
	var node = obj.parentNode.parentNode;
	var div = node.getElementsByTagName('div')[0];

	if (div.style.display == 'block')
		div.style.display = 'none';
	else
		div.style.display = 'block';
		
	return false;
}

function checkRegEx(value,RegEx){
var regex = new RegExp(RegEx);
var match = regex.exec(value);
if (match == null)
	return false;
else
	return value;
	
}






