/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


function wxmodal(){

    var obj = this;

    this.callback = null;
    this.param = null;

    /************************************************
     * CONSTRUTOR
     ************************************************/
    $(function(){

        $('body').append('<div id="wxmodal" class="wxmodal"></div>');
        $('#wxmodal').jqm({modal:true});


    });

    /*************************************************
     * TELA DE CONFIRMAÇÃO
     *************************************************/
    this.confirm = function(msg, callback, param){

        obj.callback = callback;
        obj.param = param;

        var html = "<div id='wxmodal-close' onClick='$(\"#wxmodal\").jqmHide();' ></div>";
        html += "<div id='wxmodal-msg'>" + msg + "</div>";

        html += "<div id='wxmodal-button'>";
        html += "<input type='button' value='Sim' onClick='wxmodal.fnCallback()'/>";
        html += "<input type='button' value='Não' onClick='$(\"#wxmodal\").jqmHide();' />";
        html += "</div>";

        $('#wxmodal').html(html);
        $('#wxmodal').jqmShow();

    }

    /*************************************************
     * TELA DE ALERT
     *************************************************/
    this.alert = function(msg, callback, param){

        obj.callback = callback;
        obj.param = param;

        var html = "<div id='wxmodal-close' onClick='wxmodal.fnCallback()'></div>";
        html += "<div id='wxmodal-msg'>" + msg + "</div>";


        html += "<div id='wxmodal-button'>";
//        html += "<input type='button' value='Ok' onClick='wxmodal.fnCallback()'/>";
        html += "</div>";

        $('#wxmodal').html(html);
        $('#wxmodal').jqmShow();

    }

    /*************************************************
     * LOADING
     *************************************************/
    this.startLoading = function(msg){

        var html = "<div id='wxmodal-msg'>" + msg + "</div>";

        $('#wxmodal').html(html);
        $('#wxmodal').jqmShow();

    }

    this.stopLoading = function(){

        $('#wxmodal').jqmHide();

    }

     /*************************************************
     * CALLBACK
     *************************************************/
    this.fnCallback = function(){

        var param = (obj.param) ? obj.param : null;

        $('#wxmodal').jqmHide();

        if (obj.callback)
            obj.callback(param);

    }

}

/**
 * INICIALIZA O JQMODAL POR PADRÂO
 */
var wxmodal = new wxmodal();
