/**
 * Created by kogting on 14-7-3.
 */
function areasPopup(options){
    var title = options.title;
    var width = options.width;
    var height = options.height;
    var Html = '';
    Html += '<div class="search"><span class="fc-gray">请搜索城市：</span><div class="search-input" style=""><input id="search-info" type="text" value=""><span id="deleInput" class="close-tag mt1"></span></div><input id="searchBtn" type="button" class="btn-pop search-btn" value="搜索"></div>';
    Html +='<div class="search-result"><div class="add-all"><a id="addResults" href="javascript:;">全部添加<span class="add-area add-icon"></span></a></div></div>';
    Html += '<div class="area-set"><div class="list-con"><div class="name">请选择地区<a href="javascript:;" style="color:#36aeea;text-decoration:none;" id="select_all">全选</a></div><div class="con"><div id="j-areaList"></div></div></div><div class="selected-con"><div class="name">已选择的地区<a href="javascript:;" style="color:#36aeea;text-decoration:none;" id="unselect_all">清空</a></div><div class="con"></div></div><div class="area-bottom row-fluid"><a href="javascript:;" id="areasconfirm" style="margin-left:618px;margin-top:18px;display: block; text-align: center; font-size:14px;line-height:30px;background-color: #68ba31;width:115px; height:30px;color:white;border-radius:5px 5px 5px 5px;cursor: pointer;text-decoration:none;" class="btn-pop btn-success span2">确定</a></div></div>';
    var template = '<div id="areas_mask" class="mask"></div>'+
        '<div id="areas_popup" class="popup" style="z-index:110; ">'+
        '<div class="title">'+
        '<strong>'+title+'</strong>'+
        '<span id="close" class="close-tag"></span>'+
        '<span class="restore-tag"></span>'+
        '<span class="max-tag"></span>'+
        '</div>'+
        '<div class="popup-content">'+
        Html+
        '</div>'+
        '</div>';
    $("#areas_layout").append(template);

    var popup = $("#areas_popup");
    popup.css({
        'width':width,
        'left':($(window).width() - parseInt(width))/2 + 'px'
    });
    popup.css({
        height:height,
        top:($(window).height() - parseInt(height))/900 + 'px'
    });

    this.opt = $.extend({
        masker: true,
        width:'60%',
        height:'60%',
        title:'',
        zIndex:110,
        forceRemove:false
    },options);

    this.mask = $("#areas_mask");
    this.max = popup.find('.max-tag');
    this.restore = popup.find('.restore-tag');
    this.content = popup.find('.popup-content');
    this.close = popup.find('#close');
    this.close.click(function(){
        this.hide();
        this.mask.hide();
    }.bind(this));
    this.hide = function(){
        if (this.opt.forceRemove) {
            popup.empty().remove();
            this.mask.empty().remove();
        }else{
            popup.hide();
            this.mask.hide();
        }
        $(document.body).css({overflow:'auto'});
    };
    this.show = function(){
        popup.show();
        this.mask.show();
    }
    this.remove = function(){
        popup.remove();
        this.mask.remove();
    }
}