var winId	= $.getUrlParam("winId");
var records = top.$("#"+winId).panel("options").data;
var type	= $.getUrlParam("type");
$(function(){
	//加载下拉选项
	//setTimeout(loadValue,500);
	$("#type").val(type);
	loadValue();

	$("#rwms").combobox({
		onChange:function(newValue,oldValue){
			changeDisplayByModel(newValue);
		}
	});
	if(records.flag){
		$("#rwms").combobox("setValue",records.rwms)
	}else{
		$("#rwms").combobox("setValue",Constants.everydayonce)
	}

});
function loadValue(){
	//加载下拉框
	$.ajax({
		url:" xtclAction!query_Xtcl_task.do",
		type:"post",
		dataType:"JSON",
		async:false,
		data : {"csdl":"ywVideoTaskModel,ywTaskSwitch,ywTaskEnable"},
		success:function(res){
			if(res && res.length>0){
				var taskTypeArr = [];
				var taskModelArr = [];
				var taskLevelArr = [];
				var taskSwitchArr = [];
				var taskEnableArr = [];
				for(i in res){
					if(res[i].csdl=="ywVideoTaskModel"){
					//	console.log("任务模式：",res);  暂时注释掉   自定义时间
						if(res[i].csdm !='3'){
							if(res[i].csdm=="1"){							
								taskModelArr.push({"id":res[i].csdm,"text":res[i].csmc,"selected":true})
							}else{
								taskModelArr.push({"id":res[i].csdm,"text":res[i].csmc})
							}
						}						
					}else if(res[i].csdl=="ywTaskEnable"){
						if(res[i].csdm=="0"){
							taskEnableArr.push({"id":res[i].csdm,"text":res[i].csmc,"selected":true})
						}else{
							taskEnableArr.push({"id":res[i].csdm,"text":res[i].csmc})
						}
					}else{
						if(res[i].csdm=="0"){
							taskSwitchArr.push({"id":res[i].csdm,"text":res[i].csmc,"selected":true})
						}else{
							taskSwitchArr.push({"id":res[i].csdm,"text":res[i].csmc})
						}
					}
				}
				$("#rwms").combobox("loadData", taskModelArr);
				$("#rw_state").combobox("loadData",taskEnableArr);
			}
		}
	});
	if(records.flag){
		changeDisplayByModel(records.rwms);
		$("#id").val(records.id);
		$("#rw_name ").textbox("setValue",records.rw_name);
		$("#rw_type").combobox("setValue",records.rw_type+"");
		$("#rwms").combobox("setValue",records.rwms+"");
		$("#rw_state").combobox("setValue",records.rw_state+"");
		$("#zxsj").timespinner("setValue",records.zxsj );
		$("#jgsj").numberbox("setValue",records.jgsj);
		
		if(records.mondayswitch==1){
			$('#mondayswitch').attr("checked",true);
		}else{
			$('#mondayswitch').attr("checked",false);

		}
		$("#mondayruntime").timespinner("setValue",records.mondayruntime);
		$("#mondayrunbyhour").textbox("setValue",records.mondayrunbyhour);

		if(records.tuesdayswitch==1){
			$('#tuesdayswitch').attr("checked",true);
		}else{
			$('#tuesdayswitch').attr("checked",false);

		}
		$("#tuesdayruntime").timespinner("setValue",records.tuesdayruntime);
		$("#tuesdayrunbyhour").textbox("setValue",records.tuesdayrunbyhour);

		if(records.wednesdayswitch==1){
			$('#wednesdayswitch').attr("checked",true);
		}else{
			$('#wednesdayswitch').attr("checked",false);

		}
		$("#wednesdayuntime").timespinner("setValue",records.wednesdayuntime);
		$("#wednesdayunbyhour").textbox("setValue",records.wednesdayunbyhour);

		if(records.thursdayswitch==1){
			$('#thursdayswitch').attr("checked",true);
		}else{
			$('#thursdayswitch').attr("checked",false);

		}
		$("#thursdayruntime").timespinner("setValue",records.thursdayruntime);
		$("#thursdayrunbyhour").textbox("setValue",records.thursdayrunbyhour);

		if(records.fridayswitch==1){
			$('#fridayswitch').attr("checked",true);
		}else{
			$('#fridayswitch').attr("checked",false);

		}
		$("#fridayruntime").timespinner("setValue",records.fridayruntime);
		$("#fridayrunbyhour").textbox("setValue",records.fridayrunbyhour);

		if(records.saturdatswitch==1){
			$('#saturdatswitch').attr("checked",true);
		}else{
			$('#saturdatswitch').attr("checked",false);

		}
		$("#saturdatruntime").timespinner("setValue",records.saturdatruntime);
		$("#saturdatrunbyhour").textbox("setValue",records.saturdatrunbyhour);

		if(records.sundayswitch==1){
			$('#sundayswitch').attr("checked",true);
		}else{
			$('#sundayswitch').attr("checked",false);

		}
		$("#sundayruntime").timespinner("setValue",records.sundayruntime);
		$("#sundayrunbyhour").textbox("setValue",records.sundayrunbyhour);
	}else{
		
		$("#daystarttime").timespinner("setValue",'08:00' );
		$("#daystarttimebyhour").numberbox("setValue",4);
		$("#channeltotals").numberbox("setValue",records.channeltotals);
		$("#mondayruntime").timespinner("setValue",'08:00');
		$("#mondayrunbyhour").textbox("setValue",4);
		$("#tuesdayruntime").timespinner("setValue",'08:00');
		$("#tuesdayrunbyhour").textbox("setValue",4);
		$("#wednesdayuntime").timespinner("setValue",'08:00');
		$("#wednesdayunbyhour").textbox("setValue",4);
		$("#thursdayruntime").timespinner("setValue",'08:00');
		$("#thursdayrunbyhour").textbox("setValue",4);
		$("#fridayruntime").timespinner("setValue",'08:00');
		$("#fridayrunbyhour").textbox("setValue",4);
		$("#saturdatruntime").timespinner("setValue",'08:00');
		$("#saturdatrunbyhour").textbox("setValue",4);
		$("#sundayruntime").timespinner("setValue",'08:00');
		$("#sundayrunbyhour").textbox("setValue",4);
	}
}
function changeDisplayByModel(newValue){
	if(newValue==Constants.everydayonce){
		$("#startTime").css("display","block");
		$("#intervalTime").css("display","none");
		$("#monday").css("display","none");
		$("#tuesday").css("display","none");
		$("#wednesday").css("display","none");
		$("#thursday").css("display","none");
		$("#friday").css("display","none");
		$("#saturday").css("display","none");
		$("#sunday").css("display","none");
	}else if(newValue==Constants.everydaymanytimes){
		$("#startTime").css("display","block");
		$("#intervalTime").css("display","block");
		$("#monday").css("display","none");
		$("#tuesday").css("display","none");
		$("#wednesday").css("display","none");
		$("#thursday").css("display","none");
		$("#friday").css("display","none");
		$("#saturday").css("display","none");
		$("#sunday").css("display","none");
		
	}else if(newValue==Constants.customizingtime){
		$("#startTime").css("display","none");
		$("#intervalTime").css("display","none");
		$("#monday").css("display","block");
		$("#tuesday").css("display","block");
		$("#wednesday").css("display","block");
		$("#thursday").css("display","block");
		$("#friday").css("display","block");
		$("#saturday").css("display","block");
		$("#sunday").css("display","block");
		
	}
}

/*
var xx1 = $("#xx1").textbox("getValue");//文本
var xx2 = $("#xx2").combobox("getValue");//下拉
var xx3 = $("#xx3").datetimebox("getValue");//日期
var xx4 = $("#xx4").numberbox("getValue");//数字
$('#xx5').combobox({  
	url:'xtclAction!select_Xtcl.do?csdl=xx5&page=1&rows=1000', 
	textField:"csmc",  
	valueField:"csdm",
	panelWidth:148,
	loadFilter:function(data){
		//data.unshift({"csmc":"选择","csdm":""});
		return data;
	}
});
$("#xx6").textbox("setValue",records.xx6);
$("#xx7").combobox("setValue",records.xx7);
$("#xx8").combobox("setValue",records.xx8);
$("#xx9").datetimebox("setValue",$.getNowTime());
$("#xx10").datetimebox("setValue",$.getTodayStart('00:00:00',-3));//往前推3天  +'00:00:00'
$("#xx11").datetimebox("setValue",$.getTodayEnd());//当天 +'23:59:59'	
$("#xx12").datetimebox("setValue",$.getDateNumToStr(records.xx12));
$("#xx13").numberbox("setValue",records.xx13);
*/