// Errors handling script

function ErrorMessage (param,extra)
{
	if (typeof(param) == 'object')
	{
		if (param.status == 200) message = param.responseText;
		else message = 'Sorry, an unexpected application error occured. Please, try again later or <a href="/contact/">contact us</a> to report this error.';
	}
	else message = param;
		
	if (!$('#dialog').length)
	{
		$('body').append('<div id="dialog" style="display:none;"></div>');		
	}
	
	$('#dialog').html(message);
	$('body').css('overflow', 'hidden');
	if(!extra){extra = {};}
	width = (extra.width ? extra.width : 310);
	height = (extra.height ? extra.height : 250);
	title = extra.title ? extra.title : 'An error occured';
    $("#dialog").dialog({
        height: height,
        width: width,
        modal: true,
        resizable: false,	        
        closeOnEscape: true,
        title: title,
        buttons : {
    		'Close' : function () {
    			$(this).dialog('close');
    		}    		
    	},        
        close: function() {	    		
            $(this).dialog('destroy');
            $(this).html('');
    		$('body').css('overflow', 'auto');	            
        }
    });	
}
