var LinkWatcher = Class.create();


LinkWatcher.prototype = {

	initialize: function(id, func) {
		this.link = $(id);
		$(id).setAttribute('href', '#');
		this.func = func;
		this.enabled = 1;
		this.link.onclick = this.fireAction.bindAsEventListener(this);
	},

	setEnabled: function(enabled) {
		this.enabled = enabled;
	},
	   
	fireAction: function(evt){
		if(this.enabled){
			try{
				eval(this.func);
			}catch(e){
				debug('LinkWatcher.fireAction', 'exception: '+e);
			}
		}else{}
		return false;
	}
};

/**
 * modal window functions
 */
function openModalDialog(e, r, is_html_content) {
	var posX, posY;

	try {
		pos=Position.cumulativeOffset($(r));
		posX = pos[0];
		posY = pos[1];
	}catch(exc){
		posX = 100;
		posY = 100;
	}

	modal_window = new Window('modal_window', {className: "alphacube",top:posY, left:posX, height: 1, width: 1, minHeight:0, minWidth:0, zIndex:150, opacity:1, resizable:false, draggable:false,closable: false, minimizable: false, maximizable: false })
	if(is_html_content) {
		modal_window.setHTMLContent(e);	
	}else{
		modal_window.setContent(e);
	}
	
	modal_window.setDestroyOnClose();
	modal_window.show(true);
}

function closeModalDialog(e){
	Element.hide(e);
	modal_window.close();
}
