    function PDialog(wrapper,element){
        this.isShow = false;
        this.wrapper=$(wrapper);
        this.element=$(element);
        this.buttonClose = $(wrapper).find('.btn-close');
        this.window_height=parseFloat(window.innerHeight); //parseFloat($(window).height());
        this.window_width=parseFloat(window.innerWidth);//parseFloat($(window).width());
        this.isLock = false;
        /*********************/
        this.boxes = [];
        this.currentBox=null;
        /*********************/
        var dialog=this;
        this.element.find('.select-box-wrapper').find('input[type="text"]').each(function(index,item){
            dialog.boxes.push(item.name);
        });

        $(this.buttonClose).click(function(){
            console.log(dialog.isLock);
            if(dialog.isLock===true) return false;
            dialog.off();
        });
        $(wrapper).click(function(e){
            if(dialog.isLock===true) return false;
            var parents=$(e.target).closest(element);
            if(parents.length ===0){
                dialog.off();
            }
        });
        $(window).resize(function(){
            var w=parseFloat(window.innerWidth);
            var h= parseFloat(window.innerHeight);
            if(dialog.window_width!==w||dialog.window_height!==h)
            {
                dialog.window_height = h;
                dialog.window_width = w;
                if(!dialog.isShow){
                    dialog.init();
                    return false;
                }else {
                    dialog.show();
                }
            }
        });
       $(document).scroll(function(){
            /*if(dialog.isShow)
                dialog.show();*/
        });
        $(element).click(function(e){
            e.preventDefault();
            e.stopPropagation();
            dialog.clearSelectBox(e);
            return false;
        });
        this.init();
    }
    PDialog.prototype.clearSelectBox=function(event){
        var name = $(event.target).attr('name');
        var cur_class=$(event.target).attr('class');

        if(this.boxes.indexOf(name)!==-1)
            this.currentBox = name;

        if(typeof name ==='undefined'&&cur_class!='select-search-content'){
            $(".select-box-wrapper .select-search-content").hide();
            return true;
        }
        if((this.currentBox!=null&&name==this.currentBox)||cur_class=='select-search-content') {
            return true;
        }
        else {
            $(".select-search-content").hide();
            return true;
        }
    };
    PDialog.keys = {37: 1, 38: 1, 39: 1, 40: 1};
    PDialog.prototype.lock=function(callback){
        this.isLock=true;
        $(this.wrapper).find('input, textarea, select').attr('disabled','true');
        if($.isFunction(callback))
            callback();
    };
    PDialog.prototype.unLock=function(callback){
        this.isLock=false;
        $(this.wrapper).find('input, textarea, select').removeAttr('disabled');
        if($.isFunction(callback))
            callback();
    };
    PDialog.prototype.init=function(time,isWait){
        var height=0;
        var width=0;
        if(!this.isShow) {
            height = parseFloat($(this.element).find(">:first-child").height());
            width = parseFloat($(this.element).find(">:first-child").width());
        }else {
            height = parseFloat($(this.element).find(">:first-child").height());
            width = parseFloat($(this.element).find(">:first-child").width());
        }
        //console.log('{h:'+height+',w:'+width+'}');
        var scrollTop =parseFloat($(document).scrollTop());
        var scrollLeft =parseFloat($(document).scrollLeft());
        var top  = parseFloat(this.window_height/2-height/2)+height+scrollTop-50;
        var left  = parseFloat(this.window_width/2-width/2)-scrollLeft;
        var dialog=this;
        this.Clear();
        $(this.wrapper).find('.message').slideUp('slow',function(){
            $(this).remove();
        });
        if(isNaN(time)) time=1000;
        $(this.element).stop().transition({ y: -top,x:left},time,function(){
            if(!isNaN(isWait)&&isWait==true)
            $(dialog.wrapper).css({'visibility': 'hidden','opacity':0});
        });
        if(isNaN(isWait)||isWait==false) {
            $(this.wrapper).animate({
                opacity: 0
            }, 300, function() {
                $(dialog.wrapper).css('visibility', 'hidden');
            });
        }
    };
    PDialog.keys = {37: 1, 38: 1, 39: 1, 40: 1};
    PDialog.prototype.disableScroll= function() {
        if (window.addEventListener) // older FF
            window.addEventListener('DOMMouseScroll', this.preventDefault, false);
        window.onwheel = this.preventDefault; // modern standard
        window.onmousewheel = document.onmousewheel = this.preventDefault; // older browsers, IE
        window.ontouchmove  = this.preventDefault; // mobile
        document.onkeydown  = this.preventDefaultForScrollKeys;
    };
    PDialog.prototype.preventDefault=function(e){
        e = e || window.event;
        if (e.preventDefault)
            e.preventDefault();
        e.returnValue = false;
    };
    PDialog.prototype.preventDefaultForScrollKeys =function(e){
        /*if (typeof  PDialog.keys[e.keyCode] === 'undefined' || !isNaN(PDialog.keys[e.keyCode])) {
            //this.preventDefault(e);
            return false;
        }*/
    };
    PDialog.prototype.enableScroll=function() {
        if (window.removeEventListener)
            window.removeEventListener('DOMMouseScroll', this.preventDefault, false);
        window.onmousewheel = document.onmousewheel = null;
        window.onwheel = null;
        window.ontouchmove = null;
        document.onkeydown = null;
        //$(this.wrapper).onmousewheel=null;
    };
    PDialog.prototype.show=function(isAnimated){
        var height=0;
        var width=0;
        if(!this.isShow) {
             height = parseFloat($(this.element).find(">:first-child").height());
             width = parseFloat($(this.element).find(">:first-child").width());
        }else {
             height = parseFloat($(this.element).find(">:first-child").height());
             width = parseFloat($(this.element).find(">:first-child").width());
        }
        $(this.wrapper).css({'visibility': 'visible','display':'block','opacity':1});
        var scrollTop =0;//parseFloat($(document).scrollTop());
        var scrollLeft =0;//parseFloat($(document).scrollLeft());
        var top=parseFloat(this.window_height/2-height/2)+scrollTop-50;
        var left  = parseFloat(this.window_width/2-width/2)-scrollLeft;
        if(!this.isShow) {
            this.disableScroll();
            this.Clear();
        }
        this.isShow = true;
        var time=0;
        if(!this.isShow) {
            time=500;
            if(!isNaN(isAnimated)&&isAnimated==false) time=0;
            $(this.element).stop().transition({x:left},0);
            $(this.element).stop().transition({ y: top,x:left,opacity:1},time);
        }
        else {
            time=500;
            if(!isNaN(isAnimated)&&isAnimated==false) time=0;
            $(this.element).stop().transition({ y: top,x:left,opacity:1},time);
        }
    };
    PDialog.prototype.off=function(isEnableScroll,time,isWait){
        this.init(time,isWait);
        if(isNaN(isEnableScroll)||isEnableScroll==true)
            this.enableScroll();
        this.isShow = false;
    };
    PDialog.prototype.triggerClick=function(obj,callback){
        var dialog=this;
        $(obj).click(function(){
            if(dialog.isLock==true) return false;
            dialog.show();
            callback();
        });
    };
    PDialog.prototype.Clear=function(callback){
        $(this.wrapper).find('input, textarea, select')
            .not(':input[type=button], :input[type=submit], :input[type=reset]').val('');
        $(".checkbox-wrapper .checkbox").removeClass('active');
        if($.isFunction(callback))
            callback();
    };
    PDialog.prototype.RunTimer=function(time,url,callback){
        var tick = parseInt(time);
        console.log(tick);
        var dialog=this;
        this.isLock=true;
        var timerInfo=$(this.wrapper).find("i.time");
        var timer=setInterval(function(){
            tick--;
            $(timerInfo).text(tick);
            if(tick===0){
                clearInterval(timer);
                if($.isFunction(callback))
                {
                    callback();
                    dialog.isLock=false;
                    window.location=url;
                }
                else window.location=url;
            }
        }, 1000);
    };
    PDialog.prototype.MessageDisplay=function(type,message,isLoading,isAnimated,isConfirmed,acceptBtnTxt,cancelBtnTxt,acceptEvt,cancelEvt,messageObj){
        this.isLock=false;
        type=String(type).toLowerCase();
        var messageWrapper = $(this.wrapper).find('.message-wrapper');
        var currentMessage=$(messageWrapper).find('.message');
        if(!isNaN(isAnimated)&&isAnimated==false)$(currentMessage).remove();
        else {
            $(currentMessage).slideUp('slideUp', function () {
                $(this).remove();
            });
        }
        if(!isNaN(isConfirmed)&&isConfirmed==true)
            var messageRec=$("<div class='message'><span></span><i class='accept-msg-btn msg-btn left'>"+acceptBtnTxt+"</i><i class='cancel-msg-btn msg-btn right'>"+cancelBtnTxt+"</i></div>");
        else
            var messageRec=$("<div class='message'><span></span></div>");
        $(messageRec).addClass(type);
        if(!isNaN(isLoading)&&isLoading==true){
            $(messageRec).addClass('progress-style');
            this.isLock=true;
        }
        $(messageRec).find('span').html(message);
        $(messageWrapper).append(messageRec);
        var parent = this;
        //add events
        if(!isNaN(isConfirmed)&&isConfirmed==true){
            $(messageWrapper).find('.accept-msg-btn').click(function(){acceptEvt(parent,messageObj);});
            $(messageWrapper).find('.cancel-msg-btn').click(function(){cancelEvt(parent,messageObj);});
        }
        if(!isNaN(isAnimated)&&isAnimated==false)$(messageRec).show();
        else $(messageRec).slideDown('fast');
    };
    PDialog.prototype.FixMessageDisplay=function(type,message,isLoading,isAnimated,isConfirmed,acceptBtnTxt,cancelBtnTxt,acceptEvt,cancelEvt){
        this.isLock=false;
        type=String(type).toLowerCase();
        var currentMessage=$(this.wrapper).find('.message');
        var messageWrapper = $(this.wrapper).find('.fix-message-wrapper');
        if(!isNaN(isAnimated)&&isAnimated==false)$(currentMessage).remove();
        else {
            $(currentMessage).slideUp('slideUp', function () {
                $(this).remove();
            });
        }
        if(!isNaN(isConfirmed)&&isConfirmed==true)
            var messageRec=$("<div class='message'><span></span><i class='accept-msg-btn msg-btn left'>"+acceptBtnTxt+"</i><i class='cancel-msg-btn msg-btn right'>"+cancelBtnTxt+"</i></div>");
        else
            var messageRec=$("<div class='message'><span></span></div>");
        $(messageRec).addClass(type);
        if(!isNaN(isLoading)&&isLoading==true){
            $(messageRec).addClass('progress-style');
            this.isLock=true;
        }
        $(messageRec).find('span').html(message);
        $(messageWrapper).append(messageRec);
        var parent = this;
        //add events
        if(!isNaN(isConfirmed)&&isConfirmed==true){
            $(messageWrapper).find('.accept-msg-btn').click(function(){acceptEvt(parent);});
            $(messageWrapper).find('.cancel-msg-btn').click(function(){cancelEvt(parent);});
        }
        if(!isNaN(isAnimated)&&isAnimated==false)$(messageRec).show();
        else $(messageRec).slideDown('fast');
    };
    PDialog.prototype.hideMessage=function(isAnimated){
        this.isLock=false;
        var currentMessage=$(this.wrapper).find('.message');
        //var messageWrapper = $(this.wrapper).find('.message-wrapper');
        if(!isNaN(isAnimated)&isAnimated==false)$(currentMessage).remove();
        else {
            $(currentMessage).slideUp('slideUp', function () {
                $(this).remove();
            });
        }
    };
    PDialog.prototype.cancelClick=function(obj,callback,isClosed,isWait){
        var dialog=this;
        $(obj).click(function(){
            if(dialog.isLock==true) return false;
            if(!isNaN(isClosed)&&isClosed==true){
                dialog.off(NaN,NaN,isWait);
                dialog.isShow = false;
            }
            callback(obj);
        });
    };
