var winId	= $.getUrlParam("winId");
var jobid = $.getUrlParam("jobid");
var flag = true;
var flagLog = true;
var flagPic= true;
var flagVideo = true;
var flagRecord = true;
var faultdeviceid	= $.getUrlParam("faultdeviceid");
var channelnum	= $.getUrlParam("channelnum");
var jobStatus	= $.getUrlParam("jobStatus");
var faultdevicename	= $.getUrlParam("faultdevicename");
var faultdevicetype	= $.getUrlParam("faultdevicetype");
$(function() {
	console.log("---------------------------" + jobStatus);
	initDetailTab();
	initOrder();
});
function initOrder(){
	$.ajax({
		url : "ywrepairjobinfoAction!get_Ywrepairjobinfo.do",
		type : "POST",
		dataType : "JSON",
		async:false,
		data : {jobid:jobid},
		success : function(res){
			if(res){
				faultdevicetypename=res.faultdevicetypename;
				if(faultdevicetypename=='服务器'){
					console.log($("#detailtab .tabs li:eq(1)"))
					$("#detailtab .tabs li:eq(1)").hide();
					$("#detailtab .tabs li:eq(2)").hide();
					$("#detailtab .tabs li:eq(3)").hide();
				}
			}
			else{
				$.showMsg("未关联到工单！")
			}
		},
		error : function(res){ }
	});
}
//
function unloadWindow(){
	var winVideo		=	$("#repairVideo")[0].contentWindow;
	var winRecord		=	$("#repairRecord")[0].contentWindow;
	winVideo&&winVideo.unloadWindow&&winVideo.unloadWindow();
	winRecord&&winRecord.unloadWindow&&winRecord.unloadWindow();
}
function initDetailTab(){
	detailtab = $("#detailtab").tabs({
		onSelect:function(title,index){
			var winVideo		=	$("#repairVideo")[0].contentWindow;
			var winRecord		=	$("#repairRecord")[0].contentWindow;
			winVideo&&winVideo.unloadWindow&&winVideo.unloadWindow();
			winRecord&&winRecord.unloadWindow&&winRecord.unloadWindow();
			if(index==2){
				if(!flagVideo){
					$("#repairRecord").prop("src",'');
					$("#repairVideo").prop("src",'../ywrepairjobVideo/ywrepairjobVideo.jsp?jobid='+jobid+"&videonum="+faultdeviceid+"&channelnum="+channelnum+"&channelname="+encodeURI(faultdevicename));
				}
			}else if(index==3){
				if(!flagRecord){
					$("#repairVideo").prop("src",'');
					$("#repairRecord").prop("src",'../ywrepairjobRecord/ywrepairjobRecord.jsp?jobid='+jobid+"&videonum="+faultdeviceid+"&channelnum="+channelnum+"&channelname="+encodeURI(faultdevicename));
				}
			}else {
			}
			loadUserChannel(index);
		}
	});
}
//
function loadUserChannel(index){
	var ppp = $("#repairOrder").prop("src");
	if(flag){
		if(index == 0 ){
			flag = false;
			$("#repairOrder").prop("src",'../dodelayjob/delay.jsp?jobid='+jobid+"&winId="+winId);
			return;
		}	
	}
	if(flagVideo){
		if(index == 2){
			flagVideo = false;
			$("#repairVideo").prop("src",'../ywrepairjobVideo/ywrepairjobVideo.jsp?jobid='+jobid+"&videonum="+faultdeviceid+"&channelnum="+channelnum+"&channelname="+encodeURI(faultdevicename));
			return;
		}
	}
	if(flagRecord){
		if(index == 3){
			flagRecord = false;
			$("#repairRecord").prop("src",'../ywrepairjobRecord/ywrepairjobRecord.jsp?jobid='+jobid+"&videonum="+faultdeviceid+"&channelnum="+channelnum+"&channelname="+encodeURI(faultdevicename));
			return;
		}
	}
	if(flagLog){
		if(index == 4){
			flagLog = false;
			$("#opreateLog").prop("src",'../ywrepairjoboplog/ywrepairjoboplog.jsp?jobid='+jobid);
			return;
		}
	}
	
	if(flagPic){
		if(index == 1){
			flagPic = false;
			$("#repairPic").prop("src",'../ywrepairjobPic/ywrepairjobPic.jsp?jobid='+jobid+'&jobStatus='+encodeURI(jobStatus));
			return;
//			$("#errorPic").prop("src",'../ywrepairjoboplog/ywrepairjoboePicture.jsp?jobid='+jobid);
			// 获取图片
//			$.ajax({
//				url : "ywrepairjobinfoAction!get_Ywrepairjobinfo.do",
//				type : "POST",
//				dataType : "JSON",
//				data : {jobid:jobid},
//				success : function(res){
//					if(res){
//						var proName = window.location.pathname.split("/")[1];
//						var sysUrl = "http://"+window.location.host+"/"+proName;
//						var picProxyGetUrl = sysUrl+"/sourceProxy?fileType=picUrlProxy&picUrl="+res.faultpictureurl;
//						$("#picture img").attr("src",picProxyGetUrl);
//					}else{
//						$.showMsg("未关联到工单！")
//					}
//				},
//				error : function(res){ }
//			});
		}
	}
}


