function onEnter(event, func, obj)
{
	var code = event.keyCode;
    if(code == 13)
	{
		if(obj == undefined)func();
		else
		{
			func.apply(obj);
		}//else
	}//if enter
}//onEnter

function displayBox(id)
{
	$('#' + id).show(700);
}//displayBox

function hideBox(id)
{
	$('#' + id).hide(700);
}//hideBox

function switchBox(id, black_bg)
{
	var $box = $('#' + id);
	var css;

	if($box.css('display') == 'none')
	{
		$box.show(700);
		if(black_bg == true)
		{
			switchBlackLayer(true);
		}//if black_bg
	}//if !box
	else
	{
		$box.hide(700);
		switchBlackLayer(false);
	}//else
}//switchBox

function switchBlackLayer(on, hide_select)
{
	if(on != false)
	{
		$('#blackLayer').css({display:'block', height:$('html')[0].scrollHeight});
		if(hide_select != false)$('select').hide();
	}//if on
	else
	{
		$('#blackLayer').css({display:'none'});
		if(hide_select != false)$('select').show();
	}//else
}//switchBlackLayer

function swapBoxes(id1, id2, black_bg)
{
	switchBox(id1, black_bg);
	switchBox(id2, black_bg);
}//switchBox

function centerBox(id, offset_w, offset_h)
{
	var pos_l = $(document).scrollLeft() + (($(window).width() - $('#' + id).width()) / 2);
	var pos_t = $(document).scrollTop() + (($(window).height() - $('#' + id).height()) / 2);

	if(offset_w != undefined)pos_l += offset_w;
	if(offset_h != undefined)pos_t += offset_h;

	$('#' + id).css('left', pos_l);
	$('#' + id).css('top', pos_t);
}//centerBox

function setLoading(on)
{
	if(on)
	{
		centerBox('loadingBox');
		$('#loadingBox').show();
	}//if on
	else
	{
		$('#loadingBox').hide();
	}//else off
}//setLoading

function errorBox(msg, html_msg)
{
	var box_id = (html_msg != true)?('errorBox'):('errorBoxHtml');

	if(msg != undefined && msg != '' && msg != null)
	{
		if(html_msg != true)$('#' + box_id + 'Text').val(msg);
			else $('#' + box_id + 'Text').html(msg);

		centerBox(box_id);

		$('#' + box_id).show();
	}//if msg
	else
	{
		$('#' + box_id).hide();
	}//else
}//errorBox

var messageBoxTO = 666;
var messageBoxCallback = null;

function messageBox(msg, callback, time)
{
	if(messageBoxTO != 666)clearTimeout(messageBoxTO);
	if(callback != undefined)messageBoxCallback = callback;

	if(msg != undefined && msg != 0)
	{
		centerBox('messageBox');
		$('#messageBox').html('<div>' + msg + '</div>');
		$('#messageBox').show();
		messageBoxTO = setTimeout(function(){messageBox()}, (time == undefined)?(1000):(time));
	}//if msg
	else
	{
		$('#messageBox').hide();
		if(typeof(messageBoxCallback) == 'function')messageBoxCallback();
		messageBoxCallback = null;
	}//else hide
}//messageBox

function freeBox(content)
{
	if(content != undefined && content != '' && content != null)
	{
		$('#freeBox').html(content);
		centerBox('freeBox');
		$('#freeBox').show();
	}//if msg
	else $('#freeBox').hide();
}//freeBox

function fillContainer(html, id)
{
	$('#' + id).html(html);
}//fillContainer

function addAfter(html, sel)
{
	$(sel).after(html)
}//addAfter

function addBefore(html, sel)
{
	$(sel).before(html)
}//addBefore

function removeElement(sel)
{
	$(sel).remove();
}//removeElement

function setFields(obj)
{
	for(var field in obj)
	{
		$('#' + field).val(obj[field])
	}//for field in obj
}//setFields

function confirmSubmit(msg)
{
   var agree = confirm(msg);
   if(agree)return true ;
	else return false ;
}//confirmSubmit

function confirmAction(msg, action)
{
	$('#confirmBox').data('action', action);
	$('#confirmBox').children('.message').html(msg);

	centerBox('confirmBox');
	displayBox('confirmBox');
}//confirmSubmit

function gotoAnchor(name)
{
	window.location = '#' + name;
}//gotoAnchor

// ALIENS!

/**
* Function : dump()
* Arguments: The data - array,hash(associative array), object
*    		 The level - OPTIONAL
* Returns  : The textual representation of the array.
*
* This function was inspired by the print_r function of PHP.
* This will accept some data as the argument and return a
* text that will be a more readable version of the
* array/hash/object that is given.
*
* http://www.openjs.com/scripts/others/dump_function_php_print_r.php
*/
function dump(arr, level)
{
	var dumped_text = "";
	if(!level) level = 0;

	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";

	if(typeof(arr) == 'object') { //Array/Hashes/Objects
		for(var item in arr) {
			var value = arr[item];

			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}//dump

//http://www.netlobo.com/url_query_string_javascript.html
function getParam(name)
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(window.location.href);
	if(results == null)return "";
		else return results[1];
}//getParam