function toggleObject(name, slide)
{
	if ( typeof(slide) != 'undefined' ) {
		$('#'+name).slideFadeToggle();
	}
	else {
		$('#'+name).toggle();
	}
}

jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
	return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
};

function switchObjects(name1, name2)
{
    if ( $('#'+name1).css("display") == "none" )
    {
        $('#'+name2).hide();
        $('#'+name1).show();
    }
    else
    {
        $('#'+name1).hide();
        $('#'+name2).show();
    }
}

function confirmLink(question, url)
{
    var is_confirmed = confirm(question);

    if (is_confirmed && url != '')
        window.location = url;

    return is_confirmed;
}

function removeObject(question, url, container, process)
{
	if ( confirm(question) == true ) {
		$('#'+process).addClass('icon-progress');
		$.post(url, {},
			function(response) {
				$('#'+process).removeClass('icon-progress');
				$('#'+container).remove();
			}
		);
		return true;
	}
}

function htmlentities(str)
{
	return str.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
}

function decode_htmlentities(str)
{
	return str.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>');
}

function nicetrim(str, len, safe, ext)
{
	if ( typeof(ext) == 'undefined' ) {
		ext = '&hellip;';
	}

	if ( str.length > len ) {
		var addext = 1;
		str = str.substr(0, len);
	}

	if ( typeof(safe) != 'undefined' ) {
		str = htmlentities(str);
		str = str.replace(/'/g,'&#039;').replace(/"/g,'&quot;');
	}

	if ( typeof(addext) != 'undefined' ) {
		str = str+ext;
	}

	return str;
}
