//1、命名空间注册工具类   
var Namespace = new Object();
Namespace.register = function(path){
    var arr = path.split(".");
    var ns = "";
    for(var i=0;i<arr.length;i++){
        if(i>0) ns += ".";
        ns += arr[i];
        eval("if(typeof(" + ns + ") == 'undefined') " + ns + " = new Object();");
    }
}
//2、注册命名空间com.zzwtec.community     
Namespace.register("com.zzwtec.community");
//3、使用命名空间      
com.zzwtec.community.PropertyList = function(){
     this.popPropertyList = pop_property_list;
     this.data = {};    
}
com.zzwtec.community.CommunityList = function(){
    this.popCommunityList = pop_community_list;
    this.data = {};    
}

com.zzwtec.community.BuildList = function(){
    this.popBuildList = pop_build_list;
    this.data = {};
}
com.zzwtec.community.BuildList2 = function(){
    this.popBuildList = pop_build_list2;
    this.data = {};
}

com.zzwtec.community.BuildList3 = function(data){   
    this.data = data || {};
}
com.zzwtec.community.DeviceList = function(){
    this.popDeviceList = pop_device_list;
    this.data = {};
}
/**
 * 弹出回填列表
 */
com.zzwtec.community.BuildList3.prototype.popBuildList = function(){
	//buildList2.data = data;
	var data = this.data;
	var areaWidth = $('div.viewFramework-work-area').width();
	doDataPost(data, false, ctx+"/common/build/backfill3", function(htmlText){
		indexLayer = layer.open({
	        type: 1,
	        title: '请选择楼栋',
	        offset: ['56px',($(window).width()-areaWidth)+'px'],
	        area: [areaWidth+'px', 'auto'],
	        content: htmlText //注意，如果str是object，那么需要字符拼接。
		});
		$('.layui-layer-content').css('height','auto');
		//需要判别之前记住的东东
		//checkedboxInpage();
	});
	
}

com.zzwtec.community.CellList = function(){
    this.popCellList = pop_cell_list;
    this.data = {};
    this.callback = function(){
    	console.log('callback等待赋值');
    };
}

com.zzwtec.community.CellList2 = function(){
    this.popCellList2 = pop_cell_list2;
    this.data = {};
    this.callback = function(){
    	console.log('callback等待赋值');
    };
}

com.zzwtec.community.UserList = function(){
    this.popUserList = pop_user_list;
    this.data = {};
    this.callback = function(){
        console.log('callback等待赋值');
    };
}

com.zzwtec.community.AreaList = function(){
    this.popAreaList = pop_area_list;
    this.data = {};
}
com.zzwtec.community.ResourceList = function(){
    this.popResourceList = pop_resource_list;
	// this.data = resourceList.data;
}

com.zzwtec.community.permissionNames = function(){
	this.setNameList = setNameList;
	this.getNameList = getNameList;
    this.data = {};
}
com.zzwtec.community.PrimeTimeList = function(){
    this.popPrimeTimeList = pop_primetime_list;
    this.data = {};
}



 /**
 * 调用该函数实现弹出小区列表，实现回填当前域的功能
 * 点击选中小区文本框  $('input.form-select[name$=communityName]') * 
 */
var pop_community_list = function(data){
	var areaWidth = $('div.viewFramework-work-area').width();
	doDataPost(data, false, ctx+"/common/community/backfill", function(htmlText){
		indexLayer = layer.open({
	        type: 1,
	        title: '请选择小区',
	        offset: ['56px',($(window).width()-areaWidth)+'px'],
	        area: [areaWidth+'px', 'auto'],
	        content: htmlText //注意，如果str是object，那么需要字符拼接。
		});
		$('.layui-layer-content').css('height','auto');
	});
}

/**
 * 调用该函数实现弹出楼栋列表，实现回填当前域的功能
 */
var pop_build_list = function(data){
	buildList.data = data;
	var areaWidth = $('div.viewFramework-work-area').width();
	doDataPost(data, false, ctx+"/admcommon/build/backfill_radio", function(htmlText){
		indexLayer = layer.open({
	        type: 1,
	        title: '请选择楼栋',
	        offset: ['56px',($(window).width()-areaWidth)+'px'],
	        area: [areaWidth+'px', 'auto'],
	        content: htmlText //注意，如果str是object，那么需要字符拼接。
		});
		$('.layui-layer-content').css('height','auto');
	});
}

var pop_build_list2=function(data){
	buildList2.data = data;
	var areaWidth = $('div.viewFramework-work-area').width();
	doDataPost(data, false, ctx+"/common/build/backfill2", function(htmlText){
		indexLayer = layer.open({
	        type: 1,
	        title: '请选择楼栋',
	        offset: ['56px',($(window).width()-areaWidth)+'px'],
	        area: [areaWidth+'px', 'auto'],
	        content: htmlText //注意，如果str是object，那么需要字符拼接。
		});
		$('.layui-layer-content').css('height','auto');
		//需要判别之前记住的东东
		checkedboxInpage();
	});
}

/**
 * 调用该函数实现弹出小区列表，实现回填当前域的功能
 * 点击选中小区文本框  $('input.form-select[name$=communityName]') * 
 */
var pop_property_list = function(data){
	var areaWidth = $('div.viewFramework-work-area').width();
	doDataPost(data, false, ctx+"/common/property/backfill", function(htmlText){
		indexLayer = layer.open({
	        type: 1,
	        title: '请选择小区',
	        offset: ['56px',($(window).width()-areaWidth)+'px'],
	        area: [areaWidth+'px', 'auto'],
	        content: htmlText //注意，如果str是object，那么需要字符拼接。
		});
		$('.layui-layer-content').css('height','auto');
	});
}


/**
 * 调用该函数实现弹出房间列表，实现回填当前域的功能
 */
var pop_cell_list = function(data){
	//var data = {};	
	//data.buildId = data.buildId;
	var areaWidth = $('div.viewFramework-work-area').width();
	doDataPost(data, false, ctx+"/common/cell/backfill", function(htmlText){
		indexLayer = layer.open({
	        type: 1,
	        title: '请选择房间',
	        offset: ['56px',($(window).width()-areaWidth)+'px'],
	        area: [areaWidth+'px', 'auto'],
	        content: htmlText //注意，如果str是object，那么需要字符拼接。
		});
		$('.layui-layer-content').css('height','auto');
	});
}

/**
 * 调研该函数实现弹出用户房间列表，实现回填当前与的功能
 * 点击选中小区文本框  $('input.form-select[name$=cellName]')
 */
var pop_cell_list2 = function(data){	
	var areaWidth = $('div.viewFramework-work-area').width();
	doDataPost(data, false, ctx+"/common/cell/backfill2", function(htmlText){
		indexLayer = layer.open({
	        type: 1,
	        title: '请选择住户房间',
	        offset: ['56px',($(window).width()-areaWidth)+'px'],
	        area: [areaWidth+'px', 'auto'],
	        content: htmlText //注意，如果str是object，那么需要字符拼接。
		});
		$('.layui-layer-content').css('height','auto');
		checkedboxInpage();
		cellList2.data = data;
	    cellList2.callback(data);
	    
	});
}

/**
 * 调用该函数实现弹出小区列表，实现回填当前域的功能
 */
var pop_area_list = function(){
//	var data = {};
	var data =areaList.data;
	var areaWidth = $('div.viewFramework-work-area').width();
	doDataPost(data, false, ctx+"/common/area/backfill", function(htmlText){
        var isJsonObject = (
        	typeof(htmlText) == "object"
			&& Object.prototype.toString.call(htmlText).toLowerCase() == "[object object]"
			&& !htmlText.length
		);
        if (isJsonObject) {
        	if (htmlText.code != 0) {
        		alert(htmlText.msg);
        		return;
			}
		}

		indexLayer = layer.open({
	        type: 1,
	        title: '请选择区域',
	        offset: ['56px',($(window).width()-areaWidth)+'px'],
	        area: [areaWidth+'px', 'auto'],
	        content: htmlText //注意，如果str是object，那么需要字符拼接。
		});
		$('.layui-layer-content').css('height','auto');
	});
}


/**
 * 调用该函数实现弹出资源列表，实现回填当前域的功能
 */
var pop_resource_list = function(){
    var data =resourceList.data;
    var areaWidth = $('div.viewFramework-work-area').width();
    doDataPost(data, false, ctx+"/common/resources/single_selection/backfill", function(htmlText){
        indexLayer = layer.open({
            type: 1,
            title: '请选择资源',
            offset: ['56px',($(window).width()-areaWidth)+'px'],
            area: [areaWidth+'px', 'auto'],
            content: htmlText //注意，如果str是object，那么需要字符拼接。
        });
        $('.layui-layer-content').css('height','auto');

    });
}

var pop_primetime_list = function(){
    var data =primeTimeList.data;
    var areaWidth = $('div.viewFramework-work-area').width();
    doDataPost(data, false, ctx+"/common/prime_time/backfill", function(htmlText){
        indexLayer = layer.open({
            type: 1,
            title: '请选择黄金时段',
            offset: ['56px',($(window).width()-areaWidth)+'px'],
            area: [areaWidth+'px', 'auto'],
            content: htmlText //注意，如果str是object，那么需要字符拼接。
        });
        $('.layui-layer-content').css('height','auto');
        checkedboxInpage();
    });
}

/**
 * 调用该函数实现弹出房间列表，实现回填当前域的功能
 */
var pop_user_list = function(data){
    //var data = {};
    //data.buildId = data.buildId;
    var areaWidth = $('div.viewFramework-work-area').width();
    doDataPost(data, false, ctx+"/common/user/backfill", function(htmlText){
        indexLayer = layer.open({
            type: 1,
            title: '请选择住户',
            offset: ['56px',($(window).width()-areaWidth)+'px'],
            area: [areaWidth+'px', 'auto'],
            content: htmlText //注意，如果str是object，那么需要字符拼接。
        });
        $('.layui-layer-content').css('height','auto');
    });
}

/**
 * 调用该函数实现弹出设备列表，实现回填当前域的功能
 * 点击选中小区文本框
 */
var pop_device_list = function(data){
    var areaWidth = $('div.viewFramework-work-area').width();
    doDataPost(data, false, ctx+"/common/device/single_selection/backfill", function(htmlText){
        indexLayer = layer.open({
            type: 1,
            title: '请选择设备',
            offset: ['56px',($(window).width()-areaWidth)+'px'],
            area: [areaWidth+'px', 'auto'],
            content: htmlText //注意，如果str是object，那么需要字符拼接。
        });
        $('.layui-layer-content').css('height','auto');
    });
}

var setNameList = function(names){
	this.nameList = names; 
}

var getNameList = function(){
	return this.nameList; 
}



var propertyList = new com.zzwtec.community.PropertyList();
var communityList = new com.zzwtec.community.CommunityList();
//代表单选楼栋
var buildList = new com.zzwtec.community.BuildList();
//代表可以多选
var buildList2 = new com.zzwtec.community.BuildList2();
//代表可以多选（逐步支持面向对象模式）
var buildList3 = new com.zzwtec.community.BuildList3();
//支持单选回填
var cellList = new com.zzwtec.community.CellList();
//支持多选回填
var cellList2 = new com.zzwtec.community.CellList2();
var areaList = new com.zzwtec.community.AreaList();
var permissionList = new com.zzwtec.community.permissionNames();
//支持单选回填
var resourceList = new com.zzwtec.community.ResourceList();
//广告黄金时段支持多选回填
var primeTimeList = new com.zzwtec.community.PrimeTimeList();
//支持单选回填
var userList = new com.zzwtec.community.UserList();
//单选回填设备
var deviceList = new com.zzwtec.community.DeviceList();
