var dialogInstance;

jQuery(document).ready(function($) {
	var dialogDiv;

	if ($('#dialog').length == 0){
		dialogDiv = jQuery("<div></div>").attr('id','dialog');
		$("body").append(dialogDiv);
	}

	dialogDiv = $('#dialog');

	dialogInstance = dialogDiv.dialog({
	       autoOpen: false,
	       position: ['auto', 100],
	       modal: true,
	       resizable: false,
	       height: 450,
	       width: 580,
		closeOnEscape: true,
	       close: function() {
			if(jQuery("#redirect_url").val() != '' && jQuery("#redirect_url").val() != null)
			{
	       	window.location.href = jQuery("#redirect_url").val();
	       	}
	       }
	   });
});


function showDialog(src, title, width, height, noClose)
{
	if(title != null){
		dialogInstance.dialog('option', 'title', title);
	}

	if (width) dialogInstance.dialog('option', 'width', width);
	if (height) dialogInstance.dialog('option', 'height', height);
    
    if(noClose) {
        dialogInstance.dialog('option', 'closeOnEscape', false);
        dialogInstance.dialog('option', 'open', function(event, ui) { $(".ui-dialog-titlebar-close").hide(); });
    }

	dialogInstance.html('<iframe id="modalIframeId" width="100%" height="100%" marginWidth="0" marginHeight="0" frameBorder="0" scrolling="auto" />').dialog("open");

    jQuery("#modalIframeId").attr("src", src);

    return false;
}

