// Errors handling script

function ErrorMessage (param)
{
	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="/index/ads">contact us</a> to report this error.';
	}
	else message = param;
		
	if (!$('#error_dialog').length)
	{
		$('body').append('<div id="error_dialog" style="display:none;"></div>');		
	}
	else
	{
		$('#error_dialog').dialog('option', 'buttons', { "Close": function() { $(this).dialog("close"); } });
	}
	
	$('#error_dialog').html('<table class="centered"><tr><td>'+message+'</td></tr></table>');
	$('body').css('overflow', 'hidden');	
    $("#error_dialog").dialog({
        height: 240,
        width: 460,
        modal: true,
        resizable: false,	        
        closeOnEscape: true,
        title: 'An error occured',
        buttons : { 
    		"Close": function() { $(this).dialog("close"); }
    	},
        close: function() {	    		
            $(this).dialog('destroy');
            $(this).html('');
    		$('body').css('overflow', 'auto');	            
        }
    });
    $('#error_dialog').find('button:first').focus();
}
