function openImg(url, width, height)
{
	/* TODO */
	alert('deprecated');
	var args = "width="+width+",height="+height+",resizable,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes";
	var href = typeof(url) == "string" ? url : url.href;
	var status = window.open(href, "OpenImg", args);
	status.focus();
	if(status)
		return false;
	else
		return true;
}


function openHelp(target_url)
{
	/* TODO */
	alert('deprecated');
	/*
  	popup = window.open(target_url, "", "scrollbars=1,menubar=1,resizable=1,width=450,height=350");
  	if(popup)
  	{
    	popup.focus();
    	return false;
  	}
  	else
    	return true;
  */
}


function toggleTableRow(id)
{
	if($(id).style.display == "none")
	{
		displayTableRow(id);
		return true;
	}
	else
	{
		hideTableRow(id);
		return false;
	}
}

function displayTableRow(id)
{
	try {
		$(id).style.display = "table-row";
	}
	catch(e) {
		$(id).style.display = "inline";
	}
}

function hideTableRow(id) { $(id).style.display = "none"; }

function setVisible(id) { $(id).style.visibility = "visible"; }
function setHidden(id) { $(id).style.visibility = "hidden"; }

function toggleDiv(id)
{
	if($(id).style.display == "none")
	{
		displayDiv(id);
		return true;
	}
	else
	{
		hideDiv(id);
		return false;
	}
}

function displayDiv(id) { $(id).style.display = ""; }
function hideDiv(id) { $(id).style.display = "none"; }

function toggleIcon(id_active, id_inactive, checked)
{
	var img_active = $(id_active);
	var img_inactive = $(id_inactive);
	if(checked)
	{
		img_active.style.display = "";
		img_inactive.style.display = "none";
	}
	else
	{
		img_active.style.display = "none";
		img_inactive.style.display = "";
	}
}

function setCheckbox(id, value, checked)
{
	if(value == checked)
		$(id).checked = true;
}

function unsetCheckbox(id, value, checked)
{
	if(value == checked)
		$(id).checked = false;
}


function confirmSubmit(text)
{
	var agree = confirm(text);
	return agree ? true : false;
}

function html_entity_decode(value)
{
	var ta = document.createElement('textarea');
	ta.innerHTML = value.replace(/</g, '&lt;').replace(/>/g, '&gt;');
	return ta.value;
}

function updateMenu(selected)
{
	var menu_box = $('menu_box');
	var menu_span = $('MenuSpan'+selected);
	menu_box.getElements('span[class=menu_selected]').each(function(el) { el.set('class','menu'); });
	menu_box.getElements('span[id^=MenuSpan]').each(function(el) { el.setStyle('display','none'); });
	if(menu_span)
		menu_span.setStyle('display','');
	$('MenuId'+selected).set('class','menu_selected').getParents('span[id^=MenuSpan]').each(function(el) {
		el.setStyle('display','');
		$('MenuId'+el.id.substr(8)).set('class','menu_selected');
	});
}

function updateMessages(messages)
{
	if(messages.length > 0)
		$('message_c').setStyle('display','').getElement('td').set('html',messages);
	else
		$('message_c').setStyle('display','none').getElement('td').set('html','&nbsp;');
}

function loadMenu(link) { sendRequest(link, function(response){ callbackMenu(response); }); }

function callbackMenu(response)
{
	document.title = html_entity_decode(response.head.title);
	$('history_box').set('html',response.header.history);
	$('lg_box').set('html',response.header.languages);
	updateMessages(response.header.messages);
	$('data').set('html',response.data);
	$('box').set('html',response.box);
	Slimbox.scanPage();
}

function sendRequest(link, callback)
{
	try {
		var jsonRequest = new Request.JSON({
			secure: true,
			method: 'get',
			data: {ajax: 1},
			url: link,
			onSuccess: callback,
			onRequest: function(){
				var loading = $('loading');
				if(loading)
					loading.set('class','loading-visible');
				},
    		onFailure: function(xhr) { alert(xhr.statusText); },
    		onComplete: function() {
    			var loading = $('loading');
    			if(loading)
    				loading.set('class','loading-invisible');
    			},
    		onError: function(text, error) { location.href = link; },
    		onException: function(headerName, value) { location.href = link; }
		}).send();
  }
  catch(e) {
	  alert('Error sending request!');
  }
}


var Cerebro = new Class({
	
	fx: null,
	
	init: function(id){
		this.fx = new Fx.Slide($(id)); 
		return this.fx;
	},
	
	slideIn: function(){
		this.fx.slideIn();
		return this.fx;
	},
	
	slideOut: function(){
		this.fx.slideOut();
		return this.fx;
	},
	
	toggle: function(){
		this.fx.toggle();
		return this.fx;
	},
	
	hide: function(){
		this.fx.hide();
		return this.fx;
	},
	
	show: function(){
		this.fx.show();
		return this.fx;
	}
});
var cjs = new Cerebro();

/*
function Cat( name ) {
  this.name = name;

  this.sayName = function() {
    console.log(this.name);
  }
}

var cat = new Cat("rover");
cat.sayName();
*/

