﻿/*alert personalizado*/
function alertDialog(vc_mensagem, vc_title, vc_funcoes, it_width) {
    $(document).ready(function() {        
        var obj = getDivDialog('dialog');
        vc_mensagem = vc_mensagem.replace(/\n/gi, '<br />');
        obj.innerHTML = vc_mensagem;

        //valores padrao caso nao receba esses valores
        if (typeof (vc_title) == "undefined" || vc_title == null) {
            vc_title = "ATENÇÃO!";
        }

        if (typeof (it_width) == "undefined" || it_width == null) {
            it_width = 450;
        }

        if (typeof (vc_funcoes) == "undefined" || vc_funcoes == null) {
            vc_funcoes = "void(0);";
        }

        //$('#dialog').dialog("destroy");

        // Dialog Propriedades
        $('#dialog').dialog({
            autoOpen: false,
            modal: true,
            draggable: false,
            overlay: { backgroundColor: '#000', opacity: 0.95 },
            title: '<span class=\'ui-icon ui-icon-alert\'>&nbsp;</span>&nbsp;' + vc_title,
            width: it_width,
            position: "center",
            hide: "hide",
            buttons: { "Ok": function() { $(this).dialog("close"); } },
            close: function() { eval(vc_funcoes); }

        });

        //hover states on the static widgets
        $('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); },
		function() { $(this).removeClass('ui-state-hover'); }
	);

        $("#dialog").dialog("open");
    });
}

/*confirm personalizado*/
function confirmDialog(vc_mensagem, vc_title, vc_funcao_ok, vc_funcao_cancelar, it_width) {
	var obj = getDivDialog('dialog');
	vc_mensagem = vc_mensagem.replace(/\n/gi, '<br />');
	obj.innerHTML = vc_mensagem;

	if (typeof (vc_title) == "undefined" || vc_title == null) {
		vc_title = "ATENÇÃO!";
	}

	if (typeof (it_width) == "undefined" || it_width == null) {
		it_width = 450;
	}

	if (typeof (vc_funcao_ok) == "undefined" || vc_funcao_ok == null) {
		vc_funcao_ok = "$(this).dialog(\"close\");";
	}

	if (typeof (vc_funcao_cancelar) == "undefined" || vc_funcao_cancelar == null) {
		vc_funcao_cancelar = "$(this).dialog(\"close\");";
	}

	$('#dialog').dialog("destroy");

	// Dialog Propriedades
	$('#dialog').dialog({
		autoOpen: false,
		modal: true,
		overlay: { backgroundColor: '#000', opacity: 0.95 },
		title: '<span class=\'ui-icon ui-icon-alert\'>&nbsp;</span>&nbsp;' + vc_title,
		width: it_width,		
		hide: "slide",
		buttons: {
			"Não": function() { eval(vc_funcao_cancelar) }
			, "Sim": function() { eval(vc_funcao_ok) }
		}
		//close: function(){eval(vc_funcoes);}

	});

	//hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); },
		function() { $(this).removeClass('ui-state-hover'); }
	);

	$("#dialog").dialog("open");
}

function getDivDialog(idDialog) {
    //var tmpDiv = (document.getElementById(idDialog)) ? document.getElementById(idDialog) : document.createElement('div');
    if (document.getElementById(idDialog)) {
        return document.getElementById(idDialog)
    }
    else 
    {
        var tmpDiv = document.createElement('div');

        with (tmpDiv) {
            className = 'dialog';
            setAttribute('id', idDialog);
            setAttribute('title', 'Atenção!');
            style.display = 'none';
        }

        $('body').append(tmpDiv);
        return tmpDiv;
    }
}
