//************************************************Const*******************************************************

/*snapshot const*/
var snapshotpath="\\SnapshotFolder\\";
var snapshotpathH="SnapshotFolder/";

/*playback const*/
var PbActionPlay="play";
var PbActionPause="pause";
var PbActionPlayPause="playpause";
var PbActionStop="stop";
var PbActionForward="forward";
var PbActionReverse="reverse";
var PbActionNextImg="nextImg";

var cFunctionDisabled = -1;
var cFunctionOff = 0;
var cFunctionOn = 1;
var cFunctionHide = 2;

/*Time*/
var ServerNoResponseTime = 63000; //用來決定CGI多久沒回傳就是No Response;

/*CSS (Color)*/
var emptygroup="#cccccc";
var emptycam="#BEBEBE";
var haverec="#666666";
var CamHadSelect="#0080C0";
var CamNoSelect="#333333";

/*Menu*/
var livesubmenu=1;
var seqsubmenu=2;
var pbsubmenu=3;

/*playback channel selection table const*/
var selctedchan="#ff0000";
var chan_no="#dddddd";
var chan_dis="#333333";
var chan_nopbpri="#dddddd";


var EvePbTime="";

function LanguageSetting() {
	for(i=1; i <= TotalVideoCom; i++)
	{
		document.getElementById("img_shapshot" +i).title = live_clicksnapshot;	
		document.getElementById("img_noshapshot" +i).title = live_nosnapshot;
		document.getElementById("img_speekdisplay" +i).title = live_stopaudio;	
		document.getElementById("img_speek" +i).title = live_playaudio;	
		document.getElementById("img_NoSpeek" +i).title = live_noaudio;
		document.getElementById("img_recording" +i).title = live_stopmanrec;
		document.getElementById("img_record" +i).title = live_startmanrecord;	
		document.getElementById("img_norecord" +i).title = live_norecord;
		document.getElementById("img_AudioPostOn" +i).title = live_AudioPostOff;	
		document.getElementById("img_AudioPostOff" +i).title = live_AudioPostOn;	
		document.getElementById("img_NoAudioPost" +i).title = live_AudioPostDisabled;
	}

	for (i=1; i<=4; i++)
	{
		document.getElementById("img_ExportAVIing" + i).title = live_exporttoaviing;	
		document.getElementById("img_ExportAVIOff" + i).title = live_exporttoavi;	
		document.getElementById("img_noExportAVI" + i).title = live_canntexporttoavi;			
	}

	document.getElementById("img_fullscreen").title = live_clickfullscreen;
	document.getElementById("imgKeepRatio1").title = live_dontkeepration;
	document.getElementById("imgKeepRatio2").title = live_keepration;
	document.getElementById("imgDontKeepRatio").title = live_keepration2;
	document.getElementById("cc_autopan").title = ptz_autopanleft;
	document.getElementById("stopautopan").title = ptz_autopanstop;
	document.getElementById("c_autopan").title = ptz_autopanright;
	document.getElementById("autopan").title = ptz_autopan;
	document.getElementById("PBReverse").title = pb_reversefor;
	document.getElementById("PBStop").title = pb_stop;
	document.getElementById("PBPlayPause").title = pb_playpause;
	document.getElementById("PBForward").title = pb_forward;
	document.getElementById("PBNextImg").title = pb_singalstep;

	document.getElementById("img_original_on").title = live_OriginalView;
	document.getElementById("img_original_off").title = live_OriginalView;
	document.getElementById("img_quad_on").title = live_QuadView;
	document.getElementById("img_quad_off").title = live_QuadView;
	document.getElementById("img_quad_source_on").title = live_QuadandSourceView;
	document.getElementById("img_quad_source_off").title = live_QuadandSourceView;
	document.getElementById("img_panorama_on").title = live_BroadView;
	document.getElementById("img_panorama_off").title = live_BroadView;
	document.getElementById("img_double_on").title = live_DoubleView;
	document.getElementById("img_double_off").title = live_DoubleView;
	document.getElementById("img_triple_on").title = live_TripleView;
	document.getElementById("img_triple_off").title = live_TripleView;

	MainForm.gotopresetpos.value=ptz_goto;
	MainForm.gotopresetpos.title = ptz_goto;
	MainForm.presetseqstart.value=button_start;
	MainForm.presetseqstart.title = button_start;
	MainForm.presetseqstop.value=button_stop;
	MainForm.presetseqstop.title = button_stop;
	MainForm.startseq.value=button_startseq;	
	MainForm.startseq.title = button_startseq;
	MainForm.startseqallG.value=button_seqGroup;	
	MainForm.startseqallG.title = button_seqGroup;
	MainForm.startseqallCam.value=button_seqChan;	
	MainForm.startseqallCam.title = button_seqChan;
	MainForm.seq_int_sel.title = button_seqint;
	MainForm.sel_search.title = pb_selmode;
	MainForm.pbsearchyear.title = pb_year;
	MainForm.pbsearchmonth.title = pb_month;
	MainForm.buttonSelDay[0].title = pb_calendar;
	MainForm.buttonSelDay[1].title = pb_calendar;
	MainForm.buttonIncrease[0].title = pb_increase;
	MainForm.buttonIncrease[1].title = pb_increase;
	MainForm.buttonDecrease[0].title = pb_decrease;
	MainForm.buttonDecrease[1].title = pb_decrease;
	MainForm.numsearchresult.title = pb_maxnum1To30;
	MainForm.buttonPBGo.value=button_go;
	MainForm.buttonPBGo.title = button_go;
	MainForm.buttonContiSearch.value=button_next;
	MainForm.buttonContiSearch.title = button_next;
	MainForm.buttonResearch.value=button_search;
	MainForm.buttonResearch.title = button_search;
	MainForm.buttonLastStep.value=button_backtotop;
	MainForm.buttonLastStep.title = button_backtotop;
	MainForm.buttonLastStep2.value=button_backtotop;
	MainForm.buttonLastStep2.title = button_backtotop;
	MainForm.buttonLastStep3.value=button_backtotop;
	MainForm.buttonLastStep3.title = button_backtotop;
	MainForm.btnUpdateLastEve.value=button_update;
	MainForm.btnUpdateLastEve.title = button_update;
	MainForm.btnBackTop.value=button_backtotop;
	MainForm.btnBackTop.title = button_backtotop;
	MainForm.jumpday.title = pb_mdy;
	MainForm.playsearchdate.title = pb_mdy;
	MainForm.stopbuzzerbutton.title = main_stopbuzzer;
	MainForm.stopbuzzerbutton.value = main_stopbuzzer;
	
	PTZSpeed.title = ptz_speed2;
	ptzUp.title = ptz_up;
	ptzUpRight.title = ptz_upright;
	ptzRight.title = ptz_right;
	ptzDownRight.title = ptz_downright;
	ptzDown.title = ptz_down;
	ptzLeftDown.title = ptz_leftdown;
	ptzLeft.title = ptz_left;
	ptzLeftUp.title = ptz_upleft;
	ptzHome.title = ptz_home;
	ptzZoomIn.title = ptz_zoomin;
	ptzZoomOut.title = ptz_zoomout;
	ptzUp.alt = ptz_up;
	ptzUpRight.alt = ptz_upright;
	ptzRight.alt = ptz_right;
	ptzDownRight.alt = ptz_downright;
	ptzDown.alt = ptz_down;
	ptzLeftDown.alt = ptz_leftdown;
	ptzLeft.alt = ptz_left;
	ptzLeftUp.alt = ptz_upleft;
	ptzHome.alt = ptz_home;
	ptzZoomIn.alt = ptz_zoomin;
	ptzZoomOut.alt = ptz_zoomout;
	
	ptzFocusOut.title = ptz_focusout;
	ptzFocusIn.title = ptz_focusin;
	ptzFocusAuto.title = ptz_focusauto;

	if (typeof(ptzIrisClose) != "undefined")
	{
		ptzIrisClose.title = ptz_irisclose;
		ptzIrisOpen.title = ptz_irisopen;
		ptzIrisAuto.title = ptz_irisauto;
		ptzIrisClose.alt = ptz_irisclose;
		ptzIrisOpen.alt = ptz_irisopen;
		ptzIrisAuto.alt = ptz_irisauto;
	}

	ptzFocusOut.alt = ptz_focusout;
	ptzFocusIn.alt = ptz_focusin;
	ptzFocusAuto.alt = ptz_focusauto;

	replaceTextChild(document.getElementById("startpreseq"), ptz_startpresetseq);
	
	Diveventtime.title = pb_hhmmss;
	DIVstarttime.title = pb_hhmmss;
}

function resize()	//設定video的大小與間隙寬度
{	
	var NowTime = new Date();
	if ((NowTime.getTime() - ResizeTime) < 100) return;
	ResizeTime = NowTime.getTime();  
	var width=get_broswerWidth();
	var height=get_broswerHeight();
	var dif=height-videoHight[1];
	if(0<dif && dif<140) return;
	if (SVRCamCount < 16) 
	{
		if ((height - 410 - SVRCamCount*23) >= 1) tdBottomSpace.height = (height - 410 - SVRCamCount*23);
		else tdBottomSpace.height = 1;
	}
		
	if (width==0 || height==0 || width<=300) return;
	TitleSpace.setAttribute("width", width-487);
	width=width-310;
	height=height-110;
	
	var tempW=width;
	var tempH=height-22;
	if (tempW*3 > tempH*4)
	{
		videoWidth[0]=true;
		videoHight[0]=false;
		tempW=Math.floor((tempH*4)/3);
	}//比較長或比較寬
	else
	{
		videoWidth[0]=false;
		videoHight[0]=true;
		tempH=Math.floor((tempW*3)/4);
	}
	videoHight[1]=tempH;
	videoWidth[1]=width;	
	
	tempW=width;
	tempH=height-44;
	if (tempW*3 > tempH*4) tempW=Math.floor((tempH*4)/3);//比較長或比較寬
	else tempH=Math.floor((tempW*3)/4);
	videoHight[2]=Math.floor(tempH/2);
	videoWidth[2]=width/2;	
	
	tempW=width;
	tempH=height-88;
	if (tempW*3 > tempH*4) tempW=Math.floor((tempH*4)/3);//比較長或比較寬
	else tempH=Math.floor((tempW*3)/4);
	videoHight[3]=Math.floor(tempH/4);
	videoWidth[3]=width/4;	

	tempW=width;
	tempH=height-66;
	if (tempW*3 > tempH*4) tempW=Math.floor((tempH*4)/3);//比較長或比較寬
	else tempH=Math.floor((tempW*3)/4);
	videoHight[4]=Math.floor(tempH/3);
	videoWidth[4]=width/3;	
}

function PbViewResize(VideoNo){
	if (live_seq_pb != pbsubmenu) return;
	if (SearchTypeSel.style.display != "none") return;
	if (GetSelSearchChan().toString().indexOf(",") == -1) return;
	if (Partition1[0].style.display == "none" || Partition4[0].style.display == "none" || Partition4[2].style.display == "none" || Partition4[3].style.display == "none")
	{
		OnePartitionShowVideoId = 1;
		pb_partition = 4;
		SetVideoArea(4, 1);	
	}
	else
	{
		OnePartitionShowVideoId = VideoNo;
		pb_partition = 1;
		SetVideoArea(1 ,VideoNo);
	}
}

function VideoTitleFPS()
{
	for(VT=1;VT <= TotalVideoCom;VT++)
	{
		var ch=parseInt(ComPlayingChan[VT],10);
		var spanFps = document.getElementById("spanCamfps_" +VT);
		if(ch>0 && ch<=SVRCamCount)
		{
			var partitionnow=0;
			if(live_seq_pb==livesubmenu) partitionnow=live_partition;
			else if(live_seq_pb==seqsubmenu) partitionnow=seq_partition;
			else if(live_seq_pb==pbsubmenu) partitionnow=pb_partition;
			else return;
			
			//title
			if (live_seq_pb==pbsubmenu && PBActionNow!=PbActionPlay) replaceTextChild(spanFps, " ");			
			else
			{
				var vfps=parseInt(document.getElementById("Video" +VT).FPS,10);
				if(vfps>30) vfps=30;
				replaceTextChild(spanFps, vfps+ " FPS");
			}
		}
		else replaceTextChild(spanFps, " ");
	}
	FPSTimer=setTimeout("VideoTitleFPS()", 1000);
}

function check_number(num)
{
	var pattern = /^\d+$/;
	if (pattern.test(num)==false) return false;
	else return true;
}

function getTimeByUI(dateYext, yyText, mmText, ssText, needUTC)
{
	var date=dateYext.value;	//June 06, 2001
	var sdate=new Date();
	var result;
	var value;

	sdate.setFullYear(date.substring(date.indexOf(",")+2), getMonthString(date.substring(0,date.indexOf(" ")))-1, date.substring(date.indexOf(" ")+1, date.indexOf(",")) );
	sdate.setHours(parseInt(yyText.value,10), parseInt(mmText.value,10), parseInt(ssText.value,10));

	if(needUTC)
	{	
		result=sdate.getUTCFullYear()+ ":";
		value=(sdate.getUTCMonth()+1);
		value= (value<10?'0':'') +value;
		result+=value+ ":";
		value=sdate.getUTCDate();
		value= (value<10?'0':'') +value;
		result+=value+ ":";
		value=sdate.getUTCHours();
		value= (value<10?'0':'') +value;
		result+=value+ ":";
		value=sdate.getUTCMinutes();
		value= (value<10?'0':'') +value;
		result+=value+ ":";
		value=sdate.getUTCSeconds();
		value= (value<10?'0':'') +value;
		result+=value;
		return result;
	}
	else
	{
		result=sdate.getFullYear()+ ":";
		value=(sdate.getMonth()+1);
		value= (value<10?'0':'') +value;
		result+=value+ ":";
		value=sdate.getDate();
		value= (value<10?'0':'') +value;
		result+=value+ ":";
		value=sdate.getHours();
		value= (value<10?'0':'') +value;
		result+=value+ ":";
		value=sdate.getMinutes();
		value= (value<10?'0':'') +value;
		result+=value+ ":";
		value=sdate.getSeconds();
		value= (value<10?'0':'') +value;
		result+=value;
		return result;		
	}
}

function transMediaId(mediaNo)
{
	var splitCount;
	if (live_seq_pb==livesubmenu) splitCount = live_partition;
	else if (live_seq_pb==seqsubmenu) splitCount = seq_partition;
	else if (live_seq_pb==pbsubmenu) splitCount = pb_partition;
	if (splitCount == 16)
	{
		if (mediaNo == 3) return 5;
		if (mediaNo == 4) return 6;
		if (mediaNo == 5) return 3;
		if (mediaNo == 6) return 4;
		if (mediaNo == 11) return 13;
		if (mediaNo == 12) return 14;
		if (mediaNo == 13) return 11;
		if (mediaNo == 14) return 12;
		return mediaNo;
	}
	else if (splitCount == 8)
	{
		return (mediaNo + 16);
	}
	else return mediaNo;
}

function SetVideoArea(partitionnow, VideoId)	//處理video area的display與size
{	
	partitionnow = parseInt(partitionnow, 10);
	if (partitionnow !=8)		
	{
		document.getElementById("TableView").style.display ="";
		document.getElementById("tbMode8").style.display ="none";
	}
	if(partitionnow==0)
	{
		if(live_seq_pb==livesubmenu) partitionnow=live_partition;
		else if(live_seq_pb==seqsubmenu) partitionnow=seq_partition;
		else if(live_seq_pb==pbsubmenu) partitionnow=pb_partition;
	}

	if (live_seq_pb==livesubmenu)
	{
		document.getElementById("Imgtd1").className = "ImgTdStyle";
		document.getElementById("Imgtd1").style.width = "85px";
	}
	else
	{
		document.getElementById("Imgtd1").className = "ImgSmallTdStyle";
		document.getElementById("Imgtd1").style.width = "65px";
	}

	if(partitionnow==1)
	{	
		if (VideoId == 1)
		{
			Partition1[0].style.display="";
			Partition1[1].style.display="";			
			var par=Partition4;	
			for(sV=0;sV<par.length;sV++) 
			{
				par[sV].style.display="none";
			}		
			document.getElementById("Video1").style.height = videoHight[1] + "px";
			if (( videoWidth[1]-175) > 0) document.getElementById("divCamName1").style.width = Math.floor(videoWidth[1]-175);
			else document.getElementById("divCamName1").style.width = 1;	
		}
		else
		{
			if (VideoId == 2)
			{
				var ShowVideo0 = 0;
				var ShowVideo1 = 1;
			}
			else if (VideoId == 3)
			{
				var ShowVideo0 = 2;
				var ShowVideo1 = 4;				
			}
			else if (VideoId == 4)
			{
				var ShowVideo0 = 3;
				var ShowVideo1 = 5;				
			}
			
			Partition1[0].style.display="none";
			Partition1[1].style.display="none";			
			var par=Partition4;	
			for(sV=0;sV<par.length;sV++) 
			{
				if (sV != ShowVideo0 && sV != ShowVideo1) par[sV].style.display="none";
				else
				{
					par[sV].style.display="";
				}
			}
		}
		document.getElementById("Video" + VideoId).style.height = videoHight[1] + "px";
		if (live_seq_pb==livesubmenu && var_ViewModeList[TdListCamId[MediaS]].length !=0)
		{
			document.getElementById("Imgtd1").style.width = (80 + var_ViewModeList[TdListCamId[MediaS]].split(";").length*20).toString() + "px";
			var intItemLength = 175 + var_ViewModeList[TdListCamId[MediaS]].split(";").length*25;
			if (( videoWidth[1]-intItemLength) > 0) document.getElementById("divCamName1").style.width = Math.floor(videoWidth[1]-intItemLength).toString() + "px";
			else document.getElementById("divCamName1").style.width = 1;	
		}
		else if (( videoWidth[1]-175) > 0) document.getElementById("divCamName" + VideoId).style.width = Math.floor(videoWidth[1]-175);
		else document.getElementById("divCamName" + VideoId).style.width = 1;	
//		Partition1[0].style.display="";	Partition1[1].style.display="";
//		var par=Partition4;	for(sV=0;sV<par.length;sV++) par[sV].style.display="none";
		par=Partition9;
		for(sV=0;sV<par.length;sV++) par[sV].style.display="none";
		par=Partition16;
		for(sV=0;sV<par.length;sV++) par[sV].style.display="none";
//		document.getElementById("Video1").style.height = videoHight[1] + "px";
//		if (( videoWidth[1]-165) > 0) document.getElementById("divCamName1").style.width = Math.floor(videoWidth[1]-165);
//		else document.getElementById("divCamName1").style.width = 1;
	}
	else if(partitionnow==4)
	{
		Partition1[0].style.display="";
		Partition1[1].style.display="";
		var par=Partition4;
		for(sV=0;sV<par.length;sV++) par[sV].style.display="";
		par=Partition9;
		for(sV=0;sV<par.length;sV++) par[sV].style.display="none";
		par=Partition16;
		for(sV=0;sV<par.length;sV++) par[sV].style.display="none";
		
		for(sV=1;sV<=4;sV++) document.getElementById("Video" + sV).style.height = videoHight[2] + "px";	
		if ((videoWidth[2]-175) > 0) for (videoId=1; videoId<=4; videoId++)document.getElementById("divCamName" +videoId).style.width = Math.floor(videoWidth[2]-175);
		else for (videoId=1; videoId<=4; videoId++)document.getElementById("divCamName" +videoId).style.width = 1;
	}
	else if(partitionnow==16)
	{
		Partition1[0].style.display="";
		Partition1[1].style.display="";
		var par=Partition4;
		for(sV=0;sV<par.length;sV++) par[sV].style.display="";
		par=Partition9;
		for(sV=0;sV<par.length;sV++) par[sV].style.display="";
		par=Partition16;
		for(sV=0;sV<par.length;sV++) par[sV].style.display="";
		
		for(sV=1;sV <= 16;sV++)
		{	
			document.getElementById("Video"+sV).style.height = videoHight[3] + "px";
			if ((videoWidth[3]-175) > 0) document.getElementById("divCamName"+sV).style.width = Math.floor(videoWidth[3]-175);
			else document.getElementById("divCamName"+sV).style.width = 1;
		}
	}
	else if(partitionnow==8)
	{	
		for (sV=1; sV<=4; sV++) StopMediaPlay(i);
		for (sV=1; sV<=4; sV++) PlayActiveXWithPri(i, 1, 0, 0);	
		
		document.getElementById("TableView").style.display ="none";
		document.getElementById("tbMode8").style.display ="";
		document.getElementById("Video17").style.height = (videoHight[3]*3 +48).toString() + "px";
		
		if ((videoWidth[3]*3 -365) > 0) document.getElementById("divCamName17").style.width = videoWidth[3]*3 -365;//20:CamId, 90:Img, 200:comboBox, fps:60 
		else document.getElementById("divCamName17").style.width = 1;
		for(sV=18;sV <= TotalVideoCom;sV++)
		{	
			document.getElementById("Video"+sV).style.height = videoHight[3] + "px";
			if ( (videoWidth[3]-175) > 0) document.getElementById("divCamName"+sV).style.width = videoWidth[3]-175;	
			else document.getElementById("divCamName"+sV).style.width = 1;	
		}
	}
	else if(partitionnow==9)
	{
		Partition1[0].style.display="";
		Partition1[1].style.display="";
		var par=Partition4;
		for(sV=0;sV<par.length;sV++) par[sV].style.display="";
		par=Partition9;
		for(sV=0;sV<par.length;sV++) par[sV].style.display="";
		par=Partition16;
		for(sV=0;sV<par.length;sV++) par[sV].style.display="none";
		
		for(sV=1;sV <= SVRCamCount;sV++)
		{	
			document.getElementById("Video"+sV).style.height = videoHight[4] + "px";
			if ((videoWidth[4]-175) > 0) document.getElementById("divCamName"+sV).style.width = Math.floor(videoWidth[4]-175);
			else document.getElementById("divCamName"+sV).style.width = 1;
		}
	}
}

function displayOneViedo(Dchan, mAction)
{	
	PlayActiveXWithPri(1,TdListCamId[Dchan],1, mAction);
	if (SVRCamCount >= 16) for(dO=2;dO <= 16;dO++) StopMediaPlay(dO);
	else
	{
		for(dO=2;dO <= 4;dO++) StopMediaPlay(dO);
		if (SVRCamCount == 8) for(dO=17;dO <= TotalVideoCom;dO++) StopMediaPlay(dO);
	}

	if (SVRCamCount >= 16) for(dO=2;dO <= 16;dO++) PlayActiveXWithPri(dO,dO,0,0);
	else
	{
		for(dO=2;dO <= 4;dO++) PlayActiveXWithPri(dO,2,0,0);
		if (SVRCamCount == 8) for(dO=17;dO <= TotalVideoCom;dO++) PlayActiveXWithPri(dO,dO,0,0);
	}
}

function displayFourViedo(group, mAction)
{	
	if (SVRCamCount >= 16) for(dO=5;dO <= 16;dO++) StopMediaPlay(dO);
	else if (SVRCamCount == 8) for(dO=17;dO <= TotalVideoCom;dO++) StopMediaPlay(dO);
	
	for(dF=1;dF<=4;dF++)
	{	
		var Fchan=(group-1)*4+dF;	
		PlayActiveXWithPri(dF,TdListCamId[Fchan],1,mAction);
	}

	if (SVRCamCount >= 16) for(dF=5;dF <= 16;dF++) PlayActiveXWithPri(dF,1,0,0);
	else if (SVRCamCount == 8) for(dF=17;dF <= TotalVideoCom;dF++) PlayActiveXWithPri(dF,1,0,0);
}

function StopMediaPlay(VideoNo) {
	//document.getElementById("Video" + VideoNo).DoDisconnect();
}

function setPbInfo()
{
	if (HTTPReq.readyState == 4) 
	{	
		if (HTTPReq.status != 200)
		{
			window.status = err_noresponse;
			return;
		}
		blnServerResponse = true;
		var result = HTTPReq.responseText.toString();
		if(result.substring(0,2)!="OK") 
		{	
			if (result.indexOf("(-5151)") != -1)
			{
				GetUidHTTPReq=getHTTPReq();
				if(typeof(GetUidHTTPReq)=="undefined") return;
				GetUidHTTPReq.onreadystatechange=ReGetUidOK;
				GetUidHTTPReq.open("POST", "http://" +webipport+ "/system/getuid.cgi", true);
				GetUidHTTPReq.send(null);				
			}
			PlaybackCommanding = false;
		}
		else
		{	
			var speed=result.split("\n");
			var pbSpeed=document.getElementById("playstatussped");
			if (speed[1]==0 && document.getElementById("PBPlayPause").src=="Images/PB_Play_Pause_Pause.gif") replaceTextChild(pbSpeed, speed[1]+'['+pb_pause+']');
			else if (speed[1]==0 && document.getElementById("PBPlayPause").src=="Images/PB_Play_Pause.gif") replaceTextChild(pbSpeed, speed[1]+'['+pb_stop+']');
			else if (speed[1]==1) replaceTextChild(pbSpeed, speed[1]+'['+pb_speednormal+']');
			else if (speed[1]>1)replaceTextChild(pbSpeed, speed[1]+'[FF]');
			else if (speed[1]<0)replaceTextChild(pbSpeed, speed[1]+'[FR]');
			if (parseInt(speed[1].replace("-"), 10) == 0) playbackSpeed = 1; //For Pi-Vu Pro
			else playbackSpeed = parseInt(speed[1].replace("-", ""), 10);
			if (speed[1]==1)
			{
				for (i = 1; i<=4; i++)
				{
					var camId = ComPlayingChan[i];
					if (camId == 0) continue;
					MediaOSD(document.getElementById("Video" + i), var_CameraEnOSD[camId], var_CameraEnOSDTimer[camId], var_CameraEnOSDFPS[camId], var_CameraEnOSDText[camId], unescape(var_CameraOSDText[camId]), var_CameraOSDPosition[camId], var_CameraOSDPosX[camId], var_CameraOSDPosY[camId], var_CameraOSDFontSize[camId], aOSDFontName[var_CameraOSDFont[camId]], var_CameraOSDTextColR[camId], var_CameraOSDTextColG[camId], var_CameraOSDTextColB[camId], var_CameraOSDTextBGTrans[camId], var_CameraOSDTextBGColR[camId], var_CameraOSDTextBGColG[camId], var_CameraOSDTextBGColB[camId]);
				}
			}
			else if (speed[1]!=0)
			{
				for (i = 1; i<=4; i++)
				{
					var camId = ComPlayingChan[i];
					if (camId == 0) continue;
					MediaOSD(document.getElementById("Video" + i), var_CameraEnOSD[camId], var_CameraEnOSDTimer[camId], 0, var_CameraEnOSDText[camId], unescape(var_CameraOSDText[camId]), var_CameraOSDPosition[camId], var_CameraOSDPosX[camId], var_CameraOSDPosY[camId], var_CameraOSDFontSize[camId], aOSDFontName[var_CameraOSDFont[camId]], var_CameraOSDTextColR[camId], var_CameraOSDTextColG[camId], var_CameraOSDTextColB[camId], var_CameraOSDTextBGTrans[camId], var_CameraOSDTextBGColR[camId], var_CameraOSDTextBGColG[camId], var_CameraOSDTextBGColB[camId]);
				}
			}
			if(pbplayed!=false && PBActionNow!=PbActionPause) setTimeout("getPBPlayingTime()",1);
			if (speed[1] != 0) PlaybackCommanding = false;
		}
		if (PlaybackCommanding == false) document.getElementsByTagName('body')[0].style.cursor="default";
		if (typeof(CGIResponseTimer)== "number") clearTimeout(CGIResponseTimer);	
	}
}

function click_cam_list(eve)
{
	var element=getEventTarget(eve);
	var id=element.getAttribute("id");
	if(id.indexOf("ViewList")==-1 && id.indexOf("ViewListImg")==-1) return;
	
	if(id.indexOf("ViewListImg")!=-1) id=id.substring(id.indexOf("ViewListImg")+11);		//ViewListImgG, ViewListImgC
	else if(id.indexOf("ViewList")!=-1) id=id.substring(id.indexOf("ViewList")+8);		//ViewListAll, ViewListG, ViewListC
	document.getElementById("img_original_on").style.display = "none";
	document.getElementById("img_original_off").style.display = "none";
	document.getElementById("img_quad_on").style.display = "none";
	document.getElementById("img_quad_off").style.display = "none";
	document.getElementById("img_quad_source_on").style.display = "none";
	document.getElementById("img_quad_source_off").style.display = "none";
	document.getElementById("img_panorama_on").style.display = "none";
	document.getElementById("img_panorama_off").style.display = "none";
	document.getElementById("img_double_on").style.display = "none";
	document.getElementById("img_double_off").style.display = "none";
	document.getElementById("img_triple_on").style.display = "none";
	document.getElementById("img_triple_off").style.display = "none";

	if(id=="All")
	{	
		if (SVRCamCount == 4 && live_seq_pb==livesubmenu)
		{
			setLiveCameraListUnderline(livesubmenu,SVRCamCount,0);	
			live_partition=4;	
			MediaG=1;			
		}
		else if (SVRCamCount != 4 && live_seq_pb==livesubmenu)
		{		
			setLiveCameraListUnderline(livesubmenu,SVRCamCount,0);	
			live_partition=SVRCamCount;
		}
		else if (live_seq_pb==seqsubmenu) return;
	}
	else
	{
		var index=id.substring(1);
		if(id.substring(0,1)=="A")
		{
			if(live_seq_pb==seqsubmenu)
			{
				if(typeof(SeqTimer)=='number') return;
				if(document.getElementById("seqsel_a" +id.substring(1)).checked==true) document.getElementById("seqsel_a" +id.substring(1)).checked="";
				else if(document.getElementById("seqsel_a" +id.substring(1)).disabled==false) document.getElementById("seqsel_a" +id.substring(1)).checked="checked";
				else return;
				groupClick("seqsel_a" +id.substring(1));
				return;
			}
			if (document.getElementById("ViewListA" +id.substring(1)).style.color==emptycam) return;
			setLiveCameraListUnderline(livesubmenu,16,id.substring(1));
			live_partition=16;
			MediaA=id.substring(1);
			OpenList(parseInt(id.substring(1), 10));
		} 
		else if(id.substring(0,1)=="G")
		{
			if(live_seq_pb==seqsubmenu)
			{
				if(typeof(SeqTimer)=='number') return;
				if(document.getElementById("seqsel_g" +id.substring(1)).checked==true) document.getElementById("seqsel_g" +id.substring(1)).checked="";
				else if(document.getElementById("seqsel_g" +id.substring(1)).disabled==false) document.getElementById("seqsel_g" +id.substring(1)).checked="checked";
				else return;
				groupClick("seqsel_g" +id.substring(1));
				return;
			}
			if (document.getElementById("ViewListG" +id.substring(1)).style.color==emptycam) return;
 			setLiveCameraListUnderline(livesubmenu,4,id.substring(1));
			live_partition=4;
			MediaG=id.substring(1);
		}
		else if(id.substring(0,1)=="C")
		{
			if(var_CameraIP[TdListCamId[index]].length==0) return;
			if(live_seq_pb==seqsubmenu)
			{
				if(typeof(SeqTimer)=='number') return;
				if(MainForm.seqsel_c[index-1].disabled==false)
				{
					if(MainForm.seqsel_c[index-1].checked==true) MainForm.seqsel_c[index-1].checked="";
					else MainForm.seqsel_c[index-1].checked="checked";
				}
				return;
			}
			var beforP=id.substring(1);
			if(!LiveViewChanPri[TdListCamId[beforP]]) return;
			setLiveCameraListUnderline(livesubmenu,1,id.substring(1));
			live_partition=1;
			MediaS=beforP;
			if (var_ViewMode[TdListCamId[beforP]].length != 0)
			{
				showFishEyeViewMode(TdListCamId[beforP], var_ViewMode[TdListCamId[beforP]]);
			}
		}
		else return;
	}
	PTZEnable();
	SetVideoArea(0, 1);
	MediaVideoPlay(ResetCom);
	setTimeout("GetCamStatus(true)",1000);
}

function showFishEyeViewMode(intCh, strViewMode)
{
	var arrViewList = var_ViewModeList[intCh].split(";");
	
	document.getElementById("img_original_on").style.display = "none";
	document.getElementById("img_original_off").style.display = "none";
	document.getElementById("img_quad_on").style.display = "none";
	document.getElementById("img_quad_off").style.display = "none";
	document.getElementById("img_quad_source_on").style.display = "none";
	document.getElementById("img_quad_source_off").style.display = "none";
	document.getElementById("img_panorama_on").style.display = "none";
	document.getElementById("img_panorama_off").style.display = "none";
	document.getElementById("img_double_on").style.display = "none";
	document.getElementById("img_double_off").style.display = "none";
	document.getElementById("img_triple_on").style.display = "none";
	document.getElementById("img_triple_off").style.display = "none";
	
	for (var modei=0; modei < arrViewList.length; modei++)
	{
		var ViewModeName = arrViewList[modei].split(":")[0];
		if (ViewModeName == strViewMode)
		{
			document.getElementById("img_"+ ViewModeName +"_on").style.display = "";
			document.getElementById("img_"+ ViewModeName +"_off").style.display = "none";
		}
		else
		{
			document.getElementById("img_"+ ViewModeName +"_on").style.display = "none";
			document.getElementById("img_"+ ViewModeName +"_off").style.display = "";				
		}
	}
}

function ChangeView(strViewMode)
{
	HTTPReq=getHTTPReq();
	if(typeof(HTTPReq)=="undefined") return;
	HTTPReq.open("POST", "http://" +webipport+ "/ptz/ptz.cgi?camera="+ TdListCamId[MediaS].toString() +"&mode=" + strViewMode, true);
	HTTPReq.send(null);
	
	var_ViewMode[TdListCamId[MediaS]] = strViewMode;
	showFishEyeViewMode(TdListCamId[MediaS], strViewMode);
	ChangeViewMode(TdListCamId[MediaS], strViewMode);
	PTZEnable();
}

//****************************************Search PlayBack Function***************************************************
function getPBLastestEventResult()	//get result from cgi and produce the image and link
{	
	if (HTTPReq.readyState == 4) 
	{
		document.getElementsByTagName('body')[0].style.cursor="default";
		var result = HTTPReq.responseText.toString();
		if(result.substring(0,2)!="OK") window.status=result;
		else document.getElementById("SearchLastEveResultList").innerHTML=getResult(result, CONST_playback_eventsearch_result_text);
	}
}
function searchLastestEvent()
{
	HTTPReq=getHTTPReq();
	if(typeof(HTTPReq)=="undefined") return;
	document.getElementById("SearchLastEveResultList").innerHTML = "";
	HTTPReq.onreadystatechange=getPBLastestEventResult;
	document.getElementsByTagName('body')[0].style.cursor="wait";
	HTTPReq.open("POST", "http://" +webipport+ "/system/searcheventpb.cgi?camera=" +GetSelSearchChan().toString() + "&numberofresults=15&searchway=1", true);
	HTTPReq.send(null);
}

function ChangePic(eve, filename)
{
	var element=getEventTarget(eve);
	var src=element.getAttribute("id");
	if(src.length==0) return;
	element.setAttribute("src", filename);
}

function switpresetseqaction(type)
{	
	var tstart="none"; tstop="none";
	if(type==0) tstop="";
	else if(type==1) tstart="";
	document.getElementById('presetseqstart').style.display=tstart;
	document.getElementById('presetseqstop').style.display=tstop;
}

function CamChkBoxClick(CamId){
	if (live_seq_pb==seqsubmenu) seqIndex=0;
}

function searchpbByTime(searchIndexLength, section, needwait)
{
	if(needwait) document.getElementsByTagName('body')[0].style.cursor="wait";
	var query="camera=" +GetSelSearchChan().toString();
	
	var tdate=new Date();
	var startTime = new Date();
	var endTime = new Date();
	startTime.setUTCFullYear(parseInt(pbSearchYear,10), parseInt(pbSearchMonth,10)-1, parseInt(pbSearchDate,10));	
	startTime.setUTCHours(parseInt(pbSearchHour,10), parseInt(pbSearchMin,10), parseInt(pbSearchSec,10));
	startTime.setUTCMilliseconds(0);
	if(section==30)			
	{	
		endTime.setFullYear(startTime.getFullYear(), startTime.getMonth() + 1, startTime.getDate());	
		endTime.setHours(startTime.getHours(), startTime.getMinutes(), startTime.getSeconds());
		endTime.setMilliseconds(0);
		section = Math.round((endTime.getTime() - startTime.getTime()) / 1000 / 60 / 60 / 24);
	}
	else if(section==24)	
	{	
		endTime.setFullYear(startTime.getFullYear(), startTime.getMonth(), startTime.getDate() + 1);	
		endTime.setHours(startTime.getHours(), startTime.getMinutes(), startTime.getSeconds());
		endTime.setMilliseconds(0);	
		//秒	 分	  時	 
		section = (endTime.getTime() - startTime.getTime()) / 1000 / 60 / 60;
	}
	else if(section==60 && searchIndexLength==4) 
	{	
		endTime.setTime(startTime.getTime()+60*60*1000);
		endTime.setMilliseconds(0);	
															  //秒	 分	  	 
		section = (endTime.getTime() - startTime.getTime()) / 1000 / 60 / 2;
	}
	else if(section==60 && searchIndexLength==5) 
	{	
		endTime.setTime(startTime.getTime()+120*1000);
		endTime.setMilliseconds(0);	
															  //秒
		section = (endTime.getTime() - startTime.getTime()) / 1000 / 5;
	}
	query+="&starttime=" +startTime.getUTCFullYear()+ ":" +((startTime.getUTCMonth()+1)<10?'0':'') +(startTime.getUTCMonth()+1).toString() + ":";
	query+=(startTime.getUTCDate()<10?'0':'') + startTime.getUTCDate()+ ":" + (startTime.getUTCHours()<10?'0':'') +startTime.getUTCHours().toString()+ ":";
	query+=(startTime.getUTCMinutes()<10?'0':'') + startTime.getUTCMinutes().toString() + ":" + (startTime.getUTCSeconds()<10?'0':'') +startTime.getUTCSeconds().toString();
	query+="&endtime=" +endTime.getUTCFullYear()+ ":" +((endTime.getUTCMonth()+1)<10?'0':'') +(endTime.getUTCMonth()+1).toString() + ":";
	query+=(endTime.getUTCDate()<10?'0':'') + endTime.getUTCDate()+ ":" + (endTime.getUTCHours()<10?'0':'') +endTime.getUTCHours().toString()+ ":";
	query+=(endTime.getUTCMinutes()<10?'0':'') + endTime.getUTCMinutes().toString() + ":" + (endTime.getUTCSeconds()<10?'0':'') +endTime.getUTCSeconds().toString();
	
	query+="&numbofseg=" +section;
	pbSearchType=searchIndexLength;
	document.getElementById("pbguidetable").innerHTML = "";
	HTTPSearchPBReq=getHTTPReq();
	if(typeof(HTTPSearchPBReq)=="undefined") return;
	HTTPSearchPBReq.onreadystatechange=getSearchpbByTimeResult;
	HTTPSearchPBReq.open("POST", "http://" +webipport+ "/system/searchpb.cgi?" +query, true);
	HTTPSearchPBReq.send(null);
}

function getSearchpbByTimeResult()
{
	if (HTTPSearchPBReq.readyState == 4) 
	{	
		if (HTTPSearchPBReq.status != 200)
		{
			window.status = err_noresponse;
			return;
		}
		blnServerResponse = true;
		if(HTTPSearchPBReq.responseText.toString().substring(0,2)!="OK") window.status=HTTPSearchPBReq.responseText;
		else 
		{	
			searchbytimeplayingtime="";
			var gSPBTR;
			var temp=HTTPSearchPBReq.responseText.split("\n");
			var result=new Array();
			for(gSPBTR=0;gSPBTR<temp.length;gSPBTR++) if(temp[gSPBTR].length>2) result[result.length]=temp[gSPBTR];
			var cameraID=new Array(); 
			var index=0;
			var tableTitle='';
			var startTime = new Date();
			var addTime = 0;  //以毫秒為單位
			var table = '';
			var lastStepTime = new Date();
			var lastUTCTime = new Date();
			for(gSPBTR = 0; gSPBTR < result.length; gSPBTR++)
			{
				result[gSPBTR]=result[gSPBTR].split(":");	//<camera ID>:<starttime>:<endtime>:<segment string>,	starttime/endtime- yyyy:mm:dd:hh:mm:ss
				cameraID[gSPBTR]=result[gSPBTR][0];	/*starttime=result[gSPBTR][1].split(":");	endtime=result[gSPBTR][2].split(":");*/
				startTime.setUTCFullYear(parseInt(result[gSPBTR][1] ,10), parseInt(result[gSPBTR][2] ,10) - 1, parseInt(result[gSPBTR][3] ,10));	
				startTime.setUTCHours(parseInt(result[gSPBTR][4] ,10), parseInt(result[gSPBTR][5] ,10), parseInt(result[gSPBTR][6] ,10));
				startTime.setUTCMilliseconds(0);	
				result[gSPBTR]=result[gSPBTR][13];
			}
			searchbytimeplayingtime = startTime.getUTCFullYear().toString() + '_' + ((startTime.getUTCMonth() + 1) <10?'0':'') + (startTime.getUTCMonth() + 1).toString() + '_' + (startTime.getUTCDate()<10?'0':'') + startTime.getUTCDate().toString();
			searchbytimeplayingtime += '_' + (startTime.getUTCHours()<10?'0':'') + startTime.getUTCHours().toString();
			searchbytimeplayingtime += '_' + (startTime.getUTCMinutes()<10?'0':'') + startTime.getUTCMinutes().toString();
			searchbytimeplayingtime += '_' + (startTime.getUTCSeconds()<10?'0':'') + startTime.getUTCSeconds().toString();

			if(pbSearchType==5)       //分
			{	
				lastStepTime.setFullYear(startTime.getFullYear(), startTime.getMonth(), startTime.getDate());
				lastStepTime.setHours(startTime.getHours(), 0, 0);
				tableTitle="4:" + lastStepTime.getUTCFullYear()+ ":" +(lastStepTime.getUTCMonth()+1) + ":" + lastStepTime.getUTCDate() + ":" + lastStepTime.getUTCHours() + ":" + lastStepTime.getUTCMinutes() + ":" + lastStepTime.getUTCSeconds();	
				addTime = 5000;	
			}
			else if(pbSearchType==4)  //時
			{	
				lastStepTime.setFullYear(startTime.getFullYear(), startTime.getMonth(), startTime.getDate());
				lastStepTime.setHours(0, 0, 0);
				tableTitle="3:" + lastStepTime.getUTCFullYear()+ ":" +(lastStepTime.getUTCMonth()+1) + ":" + lastStepTime.getUTCDate() + ":" + lastStepTime.getUTCHours() + ":" + lastStepTime.getUTCMinutes() + ":" + lastStepTime.getUTCSeconds();	
				addTime = 60 * 2 * 1000;	
			}
			else if(pbSearchType==3)  //日
			{	
				lastStepTime.setFullYear(startTime.getFullYear(), startTime.getMonth(), 1);
				lastStepTime.setHours(0, 0, 0);
				tableTitle="2:" + lastStepTime.getUTCFullYear()+ ":" +(lastStepTime.getUTCMonth()+1) + ":" + lastStepTime.getUTCDate() + ":" + lastStepTime.getUTCHours() + ":" + lastStepTime.getUTCMinutes() + ":" + lastStepTime.getUTCSeconds();	
				addTime = 60 *60 * 1000;	
			}
			else if(pbSearchType==2)  //月 
			{
				tableTitle="1:" + startTime.getFullYear();	
				addTime = 24 * 60 * 60 *1000;	
			}
			//testbox for save search info
			table+='<input type="text" id="SearchInfo" name="SearchInfo" style="display:none;" value="' +tableTitle+ '">';
			
			if(pbSearchType!=5) table+='<table border="0" bordercolor="#333333" cellspacing="1 align="center" cellpadding="0" cellspacing="0" onmousedown="searchIn(event); return false;" oncontextmenu="event.returnValue=false;" style="font-weight:bolder; font-size: 8px;">';
			else table+='<table border="0" cellspacing="1 bordercolor="#333333" align="center" cellpadding="0" cellspacing="0" onmousedown="PlayThisSec(event); return false;" oncontextmenu="event.returnValue=false;" style="font-weight:bolder; font-size: 8px;">';
			
			table+='<tr class="conceptText">';				
			if(pbSearchType != 2) table+='<td height="15" align="right" class="style8">' +startTime.getFullYear()+ '/' +((startTime.getMonth() + 1) <10?'0':'') + (startTime.getMonth() + 1).toString()+ '/' +(startTime.getDate()<10?'0':'') + startTime.getDate().toString()+ '</td>';
			else table+='<td height="15" align="right" class="style8">' +startTime.getFullYear()+ '&nbsp;</td>';

			for(gSPBTR=0;gSPBTR<cameraID.length;gSPBTR++) {	table+='<td width="50" align="center" valign="middle" class="style8"> ' +cameraID[gSPBTR]+ ' </td>';	}
			for(j=cameraID.length;j<4;j++) table+='<td width="50" align="center" valign="middle" class="style8"> --- </td>';
			table+='</tr>';
			for (timeList=0; timeList<result[0].length; timeList++)
			{
				var tdTitle = '';
				var timeIndex = pbSearchType + ':';
				table+='<tr>';

				var tmpMonth = ((startTime.getMonth() + 1) <10?'0':'') + (startTime.getMonth() + 1).toString();
				var tmpDate = (startTime.getDate()<10?'0':'') + startTime.getDate().toString();
				var tmpHours = (startTime.getHours()<10?'0':'') + startTime.getHours().toString();
				var tmpMinutes = (startTime.getMinutes()<10?'0':'') + startTime.getMinutes().toString();
				var tmpSeconds = (startTime.getSeconds()<10?'0':'') + startTime.getSeconds().toString();

				tdTitle = startTime.getFullYear() + "/" + tmpMonth + "/" + tmpDate + " " + tmpHours + ":" + tmpMinutes + ":" + tmpSeconds;
				if(pbSearchType!=2) table += '<td height="14" align="right" valign="middle" class="style8" nowrap="nowrap">' + tmpHours + ':' + tmpMinutes + ':' + tmpSeconds + '&nbsp;</td>';
				else table += '<td height="14" align="right" valign="middle" class="style8" nowrap="nowrap">' + tmpMonth + '/'+tmpDate+ '</td>';
				timeIndex += startTime.getUTCFullYear().toString() + '_' + ((startTime.getUTCMonth() + 1) <10?'0':'') + (startTime.getUTCMonth() + 1).toString() + '_' + (startTime.getUTCDate()<10?'0':'') + startTime.getUTCDate().toString();
				timeIndex += '_' + (startTime.getUTCHours()<10?'0':'') + startTime.getUTCHours().toString();
				timeIndex += '_' + (startTime.getUTCMinutes()<10?'0':'') + startTime.getUTCMinutes().toString();
				timeIndex += '_' + (startTime.getUTCSeconds()<10?'0':'') + startTime.getUTCSeconds().toString();
				
				for (i=0; i < cameraID.length; i++)
				{
					var tdBgColor = "#CCCCCC";
					if (result[i].charAt(timeList)=="1") tdBgColor = haverec;
					table+='<td id="' +timeIndex + '" title="' + tdTitle + '" bgcolor="' + tdBgColor + '">&nbsp;</td>';
				}
				for (i=cameraID.length; i < 4; i++)
				{
					table+='<td id="' + timeIndex + '" title="' + tdTitle + '" bgcolor="#CCCCCC">&nbsp;</td>';
				}
				table+='</tr>';
				if (pbSearchType == 2) startTime.setDate(startTime.getDate()+1);
				else startTime.setTime(startTime.getTime() + addTime);
			}
			table+='</table>';					

			document.getElementById("pbguidetable").innerHTML=table+ '<table width="300"><tr align="right"><td align="right" colspan="5"><input type="button" value="' +button_backprenext+ '" id="PlaybackPrenext" name="PlaybackPrenext" onclick="PbPreNext();" class="conceptText" style="height:23px; padding:1px 2px 1px 2px;" />&nbsp;&nbsp;&nbsp;<input type="button" value="' +button_backtotop+ '" id="buttonLastStep3" name="buttonLastStep3" onclick="SelectPlayback(0); playbystarttime(PbActionStop);" class="conceptText" style="height:23px; padding:1px 2px 1px 2px;" /></td></tr></table></table>';
			MainForm.buttonLastStep3.title = button_backtotop;
			document.getElementById("PlayControlButton").style.display="";			
			document.getElementsByTagName('body')[0].style.cursor="default";
		}
		if (typeof(CGIResponseTimer)== "number") clearTimeout(CGIResponseTimer);	
	}
}

function getPBPlayingTime()
{
	var earliest=-1;
	if(document.getElementById("Video1").TimeStamp>0) earliest=document.getElementById("Video1").TimeStamp;
	var chans=GetSelSearchChan().toString().split(",");
	var temptime;
	if(PBActionNow==PbActionReverse)
	{
		if(chans.length>1)
		{	
			temptime=document.getElementById("Video2").TimeStamp;
			if(temptime>0) if((earliest<0 )|| (earliest>temptime)) earliest=temptime;
			if(chans.length>2)
			{
				temptime=document.getElementById("Video3").TimeStamp;
				if(temptime>0) if((earliest<0 )|| (earliest>temptime)) earliest=temptime;
			}
			if(chans.length>3)
			{
				temptime=document.getElementById("Video4").TimeStamp;
				if(temptime>0) if((earliest<0 )|| (earliest>temptime)) earliest=temptime;
			}
		}
	}
	else
	{
		if(chans.length>1)
		{
			temptime=document.getElementById("Video2").TimeStamp;
			if(temptime>0) if((earliest<0 )|| (earliest<temptime)) earliest=temptime;
			if(chans.length>2)
			{
				temptime=document.getElementById("Video3").TimeStamp;
				if(temptime>0) if((earliest<0 )|| (earliest<temptime)) earliest=temptime;
			}
			if(chans.length>3)
			{
				temptime=document.getElementById("Video4").TimeStamp;
				if(temptime>0) if((earliest<0 )|| (earliest<temptime)) earliest=temptime;
			}
		}	
	}
	if(earliest<0) earliest=0;
	var esrlistTime=new Date();
	esrlistTime.setTime(earliest*1000);
	esrlistTime.setSeconds(esrlistTime.getSeconds()); //從格林威治時間調到時區時間
	
	var time=esrlistTime.getFullYear();
	var value=(esrlistTime.getMonth()+1);
	value=(value<10?'0':'') +value;	time+="/" +value;
	value=esrlistTime.getDate();
	value=(value<10?'0':'') +value;	time+="/" +value;
	value=esrlistTime.getHours();
	value=(value<10?'0':'') +value;	time+=" " +value;
	value=esrlistTime.getMinutes();
	value=(value<10?'0':'') +value;	time+=":" +value;
	value=esrlistTime.getSeconds();
	value=(value<10?'0':'') +value;	time+=":" +value;
	
	var objPBStatus = document.getElementById("playstatusplayingtime");
	if(pbplayed!=false && PBActionNow!=PbActionPause)
	{
		if(earliest==0) replaceTextChild(objPBStatus, "-------------------");
		else 
		{
			replaceTextChild(objPBStatus, time);
		}
		setTimeout("getPBPlayingTime()",900);
	}
	else if(pbplayed==false) replaceTextChild(objPBStatus, "-------------------");
}


//*************************Snapshot/ Speek/ FullScreen/ Record/ Cam Status/ AVI/ PTZ Speed/ Keep Ratio/ Manual Record**********************************
function SnapshotMethod(Schan)	//save snapshot	and open it.
{
	var filetime=document.getElementById("Video" +Schan).TimeStamp;
	if(filetime==0) return;
	var filename="CH"+ComPlayingChan[Schan]+"_"+filetime+ ".jpg";
	if(document.getElementById("Video" +Schan).SnapshotMethod(snapshotpath, filename)==0)
	{	//開啟新文件，寫入文件內容(指定image的src)
		var win=window.open("","","toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1");
		win.document.open("text/html","replace");
		win.document.write('<html><head><title>'+snapshotpathH+filename+'</title></head><body><img id="snapshot" name="snapshot" src="file:///'+snapshotpathH+filename+'"></body></html>');
		win.document.close();
	}
}

function Speek(startstop, index)
{
	if(startstop)
	{
		document.getElementById("Video" +index).AudioControlMethod(1);
		UICtrlAudioImg(index, cFunctionOn);
	}
	else
	{
		document.getElementById("Video" +index).AudioControlMethod(0);
		UICtrlAudioImg(index, cFunctionOff);
	}
	
	index=ComPlayingChan[index];
	if(live_seq_pb != pbsubmenu && var_CameraIP[index].length!=0) 
	{	
		CamAudioOpen[index]= (startstop? 1:0);
		window.parent.startFrame.form1.CamAudioOnOff[index-1].value =(startstop? 1:0);
	}
	else if(live_seq_pb == pbsubmenu) RecAudioOpen[index]= (startstop? 1:0);
}

function AudioPost(startstop, mediaindex, errCode)
{	
	if(startstop)
	{	
		var camIndex=ComPlayingChan[mediaindex];
		var audioPostInfo = new Array();
		var audioPostFormat = "";
		var sampleRate = -1;
		var channelCount = -1;
		var buffLength = -1;
		
		if (audioFormat[camIndex].indexOf(";") != -1)
		{
			audioPostInfo = audioFormat[camIndex].split(";");
			audioPostFormat = audioPostInfo[1];
			sampleRate = audioPostInfo[2].substring(3);
			channelCount = audioPostInfo[3].substring(3);
			buffLength = audioPostInfo[4].substring(4);
			if (sampleRate.length == 0) sampleRate = 0;
			else sampleRate = parseInt(sampleRate, 10);
			if (channelCount.length == 0) channelCount = 0;
			else channelCount = parseInt(channelCount, 10);
			if (buffLength.length == 0) buffLength = 0;
			else buffLength = parseInt(buffLength, 10);
			document.getElementById("Video" +mediaindex).AudioPostMediaType = audioPostFormat;
			document.getElementById("Video" +mediaindex).AudioPostSampleRate = sampleRate;
			document.getElementById("Video" +mediaindex).AudioPostChannels = channelCount;
			document.getElementById("Video" +mediaindex).AudioPostBufferLength = buffLength;
		}
		
		var intRET = parseInt(document.getElementById("Video" +mediaindex).AudioPostControlMethod(1), 10);
		if (intRET < 0)
		{
			if (intRET == -2) alert(live_CheckAudioDevice);
			else alert(live_AudioPostFail);
			return;
		}
		UICtrlAudioPostImg(mediaindex, cFunctionOn);
	} 
	else
	{	
		if (parseInt(errCode, 10) != 0) //0: audio post off
		{
			if (parseInt(errCode, 10) == 3) alert(live_CheckAudioDevice);
			else alert(live_AudioPostFail);
		}
		document.getElementById("Video" +mediaindex).AudioPostControlMethod(0);
		UICtrlAudioPostImg(mediaindex, cFunctionOff);
	}
}

function FullScreenMethod()
{
	OpenFullScreen=true;
	var playingnow=0;
	if(live_seq_pb==livesubmenu) playingnow=live_partition;
	else if(live_seq_pb==pbsubmenu) playingnow=pb_partition;
	else if(live_seq_pb==seqsubmenu) playingnow=seq_partition;
	else
	{
		OpenFullScreen=false;
		return;
	}
	
	if(playingnow==1)
	{	
		if (document.getElementById("Video1").FullScreenCtrlMethod(2,0,0) == -1)
		{
			OpenFullScreen = false;
			return;
		}
		if (Partition4[0].style.display != "none") document.getElementById("Video2").FullScreenCtrlMethod(1,1,1);
		else if (Partition4[2].style.display != "none") document.getElementById("Video3").FullScreenCtrlMethod(1,1,1);
		else if (Partition4[3].style.display != "none") document.getElementById("Video4").FullScreenCtrlMethod(1,1,1);
		else document.getElementById("Video1").FullScreenCtrlMethod(1,1,1);
	}
	else if(playingnow==4)
	{
		if (document.getElementById("Video1").FullScreenCtrlMethod(2,0,0) == -1)
		{
			OpenFullScreen = false;
			return;
		}
		document.getElementById("Video1").FullScreenCtrlMethod(1,1,4);
		document.getElementById("Video2").FullScreenCtrlMethod(1,2,4);
		document.getElementById("Video3").FullScreenCtrlMethod(1,3,4);
		document.getElementById("Video4").FullScreenCtrlMethod(1,4,4);	
	}
	else if(playingnow==16)
	{	
		if (document.getElementById("Video1").FullScreenCtrlMethod(2,0,0) == -1)
		{
			OpenFullScreen = false;
			return;
		}
		document.getElementById("Video1").FullScreenCtrlMethod(1,1,16);
		document.getElementById("Video2").FullScreenCtrlMethod(1,2,16);
		document.getElementById("Video3").FullScreenCtrlMethod(1,5,16);
		document.getElementById("Video4").FullScreenCtrlMethod(1,6,16);
		document.getElementById("Video5").FullScreenCtrlMethod(1,3,16);
		document.getElementById("Video6").FullScreenCtrlMethod(1,4,16);
		document.getElementById("Video7").FullScreenCtrlMethod(1,7,16);
		document.getElementById("Video8").FullScreenCtrlMethod(1,8,16);
		document.getElementById("Video9").FullScreenCtrlMethod(1,9,16);
		document.getElementById("Video10").FullScreenCtrlMethod(1,10,16);
		document.getElementById("Video11").FullScreenCtrlMethod(1,13,16);
		document.getElementById("Video12").FullScreenCtrlMethod(1,14,16);
		document.getElementById("Video13").FullScreenCtrlMethod(1,11,16);
		document.getElementById("Video14").FullScreenCtrlMethod(1,12,16);
		document.getElementById("Video15").FullScreenCtrlMethod(1,15,16);
		document.getElementById("Video16").FullScreenCtrlMethod(1,16,16);
	}
	else if(playingnow==8)
	{			
		if (document.getElementById("Video17").FullScreenCtrlMethod(2,0,0) == -1)
		{
			OpenFullScreen = false;
			return;
		}
		for(fS=1;fS <= SVRCamCount;fS++) document.getElementById("Video"+(fS+16).toString()).FullScreenCtrlMethod(1,fS,8);
	}
	else if(playingnow==9)
	{			
		if (document.getElementById("Video1").FullScreenCtrlMethod(2,0,0) == -1)
		{
			OpenFullScreen = false;
			return;
		}
		document.getElementById("Video1").FullScreenCtrlMethod(1,1,9);
		document.getElementById("Video2").FullScreenCtrlMethod(1,2,9);
		document.getElementById("Video3").FullScreenCtrlMethod(1,4,9);
		document.getElementById("Video4").FullScreenCtrlMethod(1,5,9);
		document.getElementById("Video5").FullScreenCtrlMethod(1,3,9);
		document.getElementById("Video7").FullScreenCtrlMethod(1,6,9);
		document.getElementById("Video9").FullScreenCtrlMethod(1,7,9);
		document.getElementById("Video10").FullScreenCtrlMethod(1,8,9);
		document.getElementById("Video13").FullScreenCtrlMethod(1,9,9);
	}
}

function sendRecordCGI()	//固定送出錄影訊息
{
	HTTPCamRecReq=getHTTPReq();
	if (typeof(HTTPCamRecReq)=="undefined")	return;
	var query="";
	for(sRC=1;sRC <= SVRCamCount;sRC++)
	{
		if(RecordCameras[sRC]==true)
		{
			if(query.length!=0) query+=",";
			query+=sRC;
		}
	}

	if(query.length!=0)
	{
		query="system/manualrecord.cgi?camera=" +query+ "&action=1&uid=" +uid;
		
		HTTPCamRecReq=getHTTPReq();
		if(typeof(HTTPCamRecReq)=="undefined") return;
		HTTPCamRecReq.onreadystatechange=SetRecOK;
		HTTPCamRecReq.open("POST", "http://" +webipport+ "/" +query, true);
		HTTPCamRecReq.send(null);
	}
	ManualRecTimer = setTimeout("sendRecordCGI()", 20000);
}

function SetRecOK()
{
	if (HTTPCamRecReq.readyState == 4) 
	{	
		if (HTTPCamRecReq.status != 200)
		{
			window.status = err_noresponse;
			return;
		}
		blnServerResponse = true;
		if(HTTPCamRecReq.responseText.toString().substring(0,2)!="OK") window.status=err_record;
		else GetCamStatus(true);
		if (typeof(CGIResponseTimer)== "number") clearTimeout(CGIResponseTimer);
	}
}

function GetCamStatus(plause)
{	
	if (typeof(CamSatTimer)== "number") clearTimeout(CamSatTimer);	
	var CGITime = new Date();
	if(GetServerCamStatusRes==false) window.status=err_noresponse;
	else GetServerCamStatusRes=false;
	blnServerResponse = false;
	HTTPCamStatReq=getHTTPReq();
	if(typeof(HTTPCamStatReq)=="undefined") return;

	CGIResponseTimer = setTimeout("CheckResponse()", ServerNoResponseTime);
	CGISentTime=Date.UTC(CGITime.getFullYear(), CGITime.getMonth(), CGITime.getDate(), CGITime.getHours(), CGITime.getMinutes(), CGITime.getSeconds(), CGITime.getMilliseconds())
	HTTPCamStatReq.onreadystatechange=GetStatusOK;
	HTTPCamStatReq.open("POST", "http://" +webipport+ "/camstatus.cgi", true);
	HTTPCamStatReq.send(null);	
}

function GetStatusOK()
{
	if (HTTPCamStatReq.readyState == 4)
	{	
		if (HTTPCamStatReq.status != 200)
		{
			if (typeof(CGIResponseTimer)== "number") clearTimeout(CGIResponseTimer);
			CheckResponse();
			window.status = err_noresponse;
			return;
		}
		blnServerResponse = true;
		if (ConnectToServer==true) 
		{
			ConnectToServer = false;
			setTimeout("reloaddata.location='Refresh.html'", 3000);
			CamSatTimer=setTimeout("GetCamStatus(false)", 6000);
		}
		else if(HTTPCamStatReq.responseText.toString().substring(0,2)=="OK")
		{	
			window.status = "";
			var CGITime = new Date();
			CGIReturnTime=Date.UTC(CGITime.getFullYear(), CGITime.getMonth(), CGITime.getDate(), CGITime.getHours(), CGITime.getMinutes(), CGITime.getSeconds(), CGITime.getMilliseconds())
			initAllData(false);	//initial data of user priviledge, camera list(name), timezone
			GetServerCamStatusRes=true;
			var camdata=HTTPCamStatReq.responseText.split("\n");
			for(gS=1;gS<=6;gS++) camdata[gS]=camdata[gS].split(",");
			for(gS=1;gS <= SVRCamCount;gS++)
			{
				CameraStatus[gS]=camdata[1][gS-1];
				CameraEventStatus[gS]=camdata[6][gS-1];
				CameraManuRec[gS]=camdata[2][gS-1];
				CameraSchRec[gS]=camdata[3][gS-1];
				CameraEveRec[gS]=camdata[4][gS-1];
				CameraConRec[gS]=camdata[5][gS-1];
			}
			CameraInfoStatus();

			if(camdata[7]=="0") MainForm.stopbuzzerbutton.style.display="none";
			else if(camdata[7]=="1") MainForm.stopbuzzerbutton.style.display="";

			var objDiskFail = document.getElementById("spanDiskFail")
			if(camdata[14]!="undefined" && camdata[14].indexOf("2") != -1)
			{
				replaceTextChild(objDiskFail, main_raid1fail);
				objDiskFail.style.display="";	
			}
			else
			{
				if(camdata[13]=="undefined" || camdata[13].indexOf("2") == -1) objDiskFail.style.display="none";
				else 
				{
					replaceTextChild(objDiskFail, main_diskfail);
					objDiskFail.style.display="";	
				}
			}
			document.getElementById("CpuUsedRate").innerHTML = live_sysloading + ": " + camdata[8];
			if ((CGIReturnTime-CGISentTime) > CGIResponseTime) CamSatTimer=setTimeout("GetCamStatus(false)", RefreshTime(CGISentTime, CGIReturnTime)); 
			else CamSatTimer=setTimeout("GetCamStatus(false)", StatusReFleshTime);
		}
		if (typeof(CGIResponseTimer)== "number") clearTimeout(CGIResponseTimer);	
	}
}

function CheckResponse(){
	if (blnServerResponse == false)
	{
		ConnectToServer = true;
		var nameInput=startFDoc.getElementsByName("camname");
		var ipInput=startFDoc.getElementsByName("camip");
		for(cL=1;cL <= SVRCamCount;cL++)
		{	
			nameInput[cL-1].value="";	
			ipInput[cL-1].value="";	
		}	

		if(typeof(SeqTimer)== "number") SeqStartStop();
		document.getElementById("CpuUsedRate").innerHTML = live_sysloading + ": --";
		startFDoc.getElementById("pageused").value = "Idle";		
		initAllData(false);
		GetCamStatus(false);
	}
}

function CameraInfoStatus()
{
	var imgsrc="";
	var status="";
	for(cIS=1;cIS <= SVRCamCount;cIS++)
	{
		status="";
		if(var_CameraIP[TdListCamId[cIS]].length!=0 && LiveViewChanPri[TdListCamId[cIS]])
		{	
			if(CameraStatus[TdListCamId[cIS]]==0) 
			{
				imgsrc="Images/camera-dis.gif";	
				status=live_dis;
			}
			else
			{	
				//image of live channel list
				if(CameraEventStatus[TdListCamId[cIS]]==1)
				{
					imgsrc="Images/camera-event_manual_rec.gif";
					status=live_event;
				}
				else if(CameraStatus[TdListCamId[cIS]]==2 || CameraStatus[TdListCamId[cIS]]==3) 
				{	
					imgsrc="Images/camera-rec.gif";	
					if(CameraConRec[TdListCamId[cIS]]==1) status=live_conrec; 
					else if(CameraSchRec[TdListCamId[cIS]]==1) status=live_schrec;	
				}
				else if(CameraStatus[TdListCamId[cIS]]==4 || CameraStatus[TdListCamId[cIS]]==5)
				{
					imgsrc="Images/camera-rec.gif";
					if(CameraEveRec[TdListCamId[cIS]]==1) status=live_eventrec;
					else if(CameraManuRec[TdListCamId[cIS]]==1) status=live_manurec;
				}
				else if(CameraStatus[TdListCamId[cIS]]==1)
				{
					imgsrc="Images/camera-con.gif";
					status=live_con;
				}
			}
		}
		else imgsrc="Images/camera-no.gif";
		imgsrc = "http://"+location.host + "/" + imgsrc;		
		if (document.getElementById("ViewListImgC" +cIS).src != imgsrc) document.getElementById("ViewListImgC" +cIS).src = imgsrc;
		if(status.length!=0)
		{
			status=user_ch+ " " +TdListCamId[cIS]+ ": " +status;
			document.getElementById("ViewListImgC" +cIS).title = status;
			document.getElementById("ViewListC" +cIS).title = status;
		}
	}
}

function ExportAVI(MediaNo){
	var Param = new Array();
	var AVIStartTime = new Date();
	var AVIEndTime = new Date(); 
	var NowPlayTime;
	var AVIChan = getText(document.getElementById("VideoSec"+MediaNo));
	getPBPlayingTime(); //先取得目前錄影播放的時間
	if (AVIChan >= 1 && AVIChan <= SVRCamCount)
	{
		if (getText(document.getElementById("playstatusplayingtime")).substring(0,3)== "---")
		{
			AVIStartTime.getFullYear();
			AVIStartTime.getMonth();
			AVIStartTime.getDate();
			AVIStartTime.getHours();
			AVIStartTime.getMinutes();
			AVIStartTime.getSeconds();
			AVIEndTime = AVIStartTime;
		}
		else
		{
			NowPlayTime=getText(document.getElementById("playstatusplayingtime")).split(" ");
			NowPlayTime[0]=NowPlayTime[0].split("/");
			AVIStartTime.setFullYear(NowPlayTime[0][0], NowPlayTime[0][1]-1, NowPlayTime[0][2]);
			NowPlayTime[1]=NowPlayTime[1].split(":");
			AVIStartTime.setHours(NowPlayTime[1][0], NowPlayTime[1][1], NowPlayTime[1][2]);
			AVIEndTime.setTime(AVIStartTime.getTime()+30000);
		}
		//先停止播放
		if (PBActionNow != PbActionStop && PBActionNow != PbActionPause && PBActionNow != PbActionNextImg) playbystarttime(PbActionPause);
		Param[0] = var_lang;
		Param[1] = "";
		Param[2] = AVIChan;
		Param[3] = document.getElementById("Video"+MediaNo);
		Param[4] = document.getElementById("img_ExportAVIing"+MediaNo); 
		Param[5] = document.getElementById("img_ExportAVIOff"+MediaNo);
		Param[6] = document.getElementById("img_noExportAVI"+MediaNo); 
		Param[7] = AVIStartTime; 
		Param[8] = AVIEndTime;
		Param[9] = EarlistRecordYear;
		Param[10] = SystemNowYear;
		Param[11] = startFDoc.getElementById("uid2").value;
		Param[12] = webipport;
		Param[13] = var_timezone;
		Param[14] = var_comip;
		Param[15] = var_comport;
		clearTimeout(CGIResponseTimer);
		clearTimeout(CamSatTimer);		
		if (navigator.appName=="Microsoft Internet Explorer") window.showModalDialog("ExportAVI.html", Param,'dialogWidth:600px;dialogHeight:370px;resizable:no;status:no;scrollbars:no');
		else window.open("ExportAVI.html",'newWin','modal=yes,width=600,height=370,resizable=no,scrollbars=no');
		GetCamStatus(false);
	}
}

function changeptzspeed(eve)
{
	if(MainForm.ptzcamera.disabled==true) return;
	var cam=MainForm.ptzcamera.value;
	if(cam.length<=0)
	{
		alert(err_noselcamera);
		return;
	}
	if(cam.indexOf("_") != -1) cam = parseInt(cam.split("_")[0], 10);
	var element=getEventTarget(eve);
	var id=element.getAttribute("id");
	if(id.length==0) return;
	if(id.indexOf("ptzspeed")==-1) return;
	if (var_CameraPTZSpeedRange[cam].indexOf(",") == -1)
	{	 
		alert(seqview_notsupport);	
		return;	
	}
		
	var speedRange = var_CameraPTZSpeedRange[cam].split(",");
	if (parseInt(speedRange[1], 10) == 0 || speedRange[0] == speedRange[1]) 
	{	 
		alert(seqview_notsupport);	
		return;	
	}

	for(cPS=1;cPS<=10;cPS++) document.getElementById("ptzspeed" +cPS).className="NotSelPTZSpeed";
	element.className="SelPTZSpeed";
	
	var index=parseInt(id.substring(8), 10);
	HTTPReq=getHTTPReq();
	if(typeof(HTTPReq)=="undefined") return;
	PTZSpeedCam=cam;
	HTTPReq.onreadystatechange=SetPTZSpeedOK;
	HTTPReq.open("POST", "http://" +webipport+ "/param.cgi?action=set&camera_c" +cam+ ".ptz.speed=" + Math.round(index * parseInt(speedRange[1] ,10) / 10), true);
	HTTPReq.send(null);
	cam = null;
}

function SetPTZSpeedOK(){
	if (HTTPReq.readyState == 4) 
	{	
		if(HTTPReq.responseText.toString().substring(0,2)!="OK") 
		{
			PTZSpeedCam="";
		}
		else 
		{
			HTTPReq=getHTTPReq();
			HTTPReq.onreadystatechange=GetPTZSpeedOK;
			HTTPReq.open("POST", "http://" +webipport+ "/param.cgi?action=get&group=camera_c" +PTZSpeedCam+ ".ptz.speed", true);
			HTTPReq.send(null);
		}
	}
}

function GetPTZSpeedOK(){
	if (HTTPReq.readyState == 4) 
	{			
		if (HTTPReq.status != 200)
		{
			window.status = err_noresponse;
			return;
		}
		var Result=HTTPReq.responseText.toString();
		var SpeedResult= Result.substring(Result.indexOf("=")+1);
		var_CameraPTZSpeed[PTZSpeedCam]= ModifiedPTZSpeedToTen(var_CameraPTZSpeedRange[PTZSpeedCam], parseInt(SpeedResult,10));
		PTZSpeedCam="";
	}
}

function timeText_increase(day, hourText, minText, secText)
{
	var Sel=EventTimeTextSel;
	if(hourText=="starttime_hh") Sel=StartTimeTextSel;
	
	var value;
	if(Sel==0)
	{
		document.getElementById(secText).style.backgroundColor="#cccccc";
		value=parseInt(document.getElementById(secText).value,10);
		if(value>=59) document.getElementById(secText).value="00";
		else
		{
			value++;
			value=(value<10?'0':'') +value.toString();
			document.getElementById(secText).value=value;
		}
	}
	if(Sel==1)
	{
		if(Sel==1) document.getElementById(minText).style.backgroundColor="#cccccc";
		value=parseInt(document.getElementById(minText).value,10);
		if(value>=59) document.getElementById(minText).value="00";
		else
		{
			value++;
			value=(value<10?'0':'') +value.toString();
			document.getElementById(minText).value=value;
		}
	}
	
	if(Sel==2)
	{
		if(Sel==2) document.getElementById(hourText).style.backgroundColor="#cccccc";
		value=parseInt(document.getElementById(hourText).value,10);
		if(value>=23) document.getElementById(hourText).value="00";
		else
		{
			value++;
			value=(value<10?'0':'') +value.toString();
			document.getElementById(hourText).value=value;
		}
	}
}

function timeText_decrease(day, hourText, minText, secText)
{
	var Sel=EventTimeTextSel;
	if(hourText=="starttime_hh") Sel=StartTimeTextSel;
	
	var value;
	if(Sel==0)
	{
		document.getElementById(secText).style.backgroundColor="#cccccc";
		value=parseInt(document.getElementById(secText).value,10);
		if(value<=0) document.getElementById(secText).value="59";
		else
		{
			value--;
			value=(value<10?'0':'') +value.toString();
			document.getElementById(secText).value=value;
		}
	}
	if(Sel==1)
	{
		if(Sel==1) document.getElementById(minText).style.backgroundColor="#cccccc";
		value=parseInt(document.getElementById(minText).value,10);
		if(value<=0) document.getElementById(minText).value="59";
		else
		{
			value--;
			value=(value<10?'0':'') +value.toString();
			document.getElementById(minText).value=value;
		}
	}

	if(Sel==2)
	{
		if(Sel==2) document.getElementById(hourText).style.backgroundColor="#cccccc";
		value=parseInt(document.getElementById(hourText).value,10);

		if(value<=0) document.getElementById(hourText).value="23";
		else
		{
			value--;
			value=(value<10?'0':'') +value.toString();
			document.getElementById(hourText).value=value;
		}
	}
}

function adjustTime(eve, type)
{
	var element=getEventTarget(eve);
	var value=element.value;
	if( check_number(value)==true )
	{
		value=parseInt(value,10);
		if(value<0) element.value="00";
		else
		{
			if(type==0)
			{
				if(value>=24) element.value="23";
			}
			else
			{
				if(value>=60) element.value="59";
			}
		}
	}
	else
	{
		var newValue="";
		if( check_number(value.substring(0,1))==true ) newValue=value.substring(0,1);
		if( check_number(value.substring(1,2))==true ) newValue+=value.substring(1,2);
		element.value= ((newValue.length==0)? "00":newValue );
	}
}

function mKeeprotation(mode)
{	
	if (SVRCamCount >= 16) for(mk=1;mk <= 16;mk++) document.getElementById("Video" +mk).KeepRatioOn(mode);
	else 
	{
		for(mk=1;mk <= 4;mk++) document.getElementById("Video" + mk).KeepRatioOn(mode);
		if (SVRCamCount == 8) for(mk=17;mk <= TotalVideoCom;mk++) document.getElementById("Video" +mk).KeepRatioOn(mode);
	}

	var videoRatio = startFDoc.getElementById("Video_Ratio");
	var mode1 = "none";
	var mode2 = "none";
	var mode0 = "none";

	if (mode == 0) 
	{
		videoRatio="0";
		mode1 = "";
	}
	else if (mode == 1) 
	{
		videoRatio="1";
		mode2 = "";
	}
	else if (mode == 2) 
	{
		videoRatio="2";
		mode0 = "";
	}	
	startFDoc.getElementById("Video_Ratio").value=videoRatio;
	document.getElementById("imgKeepRatio1").style.display = mode1;
	document.getElementById("imgKeepRatio2").style.display = mode2;
	document.getElementById("imgDontKeepRatio").style.display = mode0;	
}

function getcampreset()
{
	var cmbPresetList = document.getElementById("presetposlist");
	for(gCP=1;gCP<=10;gCP++) document.getElementById("ptzspeed" +gCP).className="NotSelPTZSpeed";
	var CamSEQStauts = startFDoc.getElementsByName("PresetSEQStart");
	for (i=0;i<=(SVRCamCount - 1);i++) var_CamPTZSeqStart[i+1] = CamSEQStauts[i].value;
	var cam=parseInt(MainForm.ptzcamera.value, 10);
	var HasPrePos=false;
	var SelPTZChenPosBefore=cmbPresetList.value;
	
	if(var_CameraPTZSpeed[cam]>0 && var_CameraPTZSpeed[cam]<11) document.getElementById("ptzspeed" +var_CameraPTZSpeed[cam]).className="SelPTZSpeed";

	while (cmbPresetList.length != 0)
	{
		cmbPresetList.options.remove(0); 
	}
	if (var_CameraPTZPresetCap[cam] == 0)
	{
		cmbPresetList.disabled="disabled";
		MainForm.gotopresetpos.disabled="disabled";
		MainForm.presetseqstart.disabled="disabled";
		MainForm.presetseqstop.disabled="disabled";
		return;
	}
	
	if (cam >=1 && cam <= SVRCamCount)
	{
		for(gCP=1;gCP<=8;gCP++)
		{	
			if(var_CameraPTZPresetPosName[cam][gCP].length!=0)
			{	
				cmbPresetList.options[cmbPresetList.length] = new Option(unescape(var_CameraPTZPresetPosName[cam][gCP]), gCP);	
				HasPrePos=true;
			}
		}
		
		cmbPresetList.disabled="";
		MainForm.gotopresetpos.disabled="";
		MainForm.presetseqstart.disabled="";
	}
	else
	{	
		MainForm.ptzcamera.disabled="disabled";
		cmbPresetList.disabled="disabled";
		MainForm.gotopresetpos.disabled="disabled";
		MainForm.presetseqstart.disabled="disabled";
	}
	
	if(SelPTZChenPosBefore!=0) cmbPresetList.value=SelPTZChenPosBefore;
	SelPTZChenPosBefore = null;
	//ptz preset sequence start or not
	if(var_CamPTZSeqStart[cam]==0) switpresetseqaction(1);
	else if(var_CamPTZSeqStart[cam]==1) switpresetseqaction(0);
	if(HasPrePos && var_CameraPTZPresetSeqList[cam].length!=0)
	{
		MainForm.presetseqstart.disabled="";
		MainForm.presetseqstop.disabled="";
	}
	else
	{
		MainForm.presetseqstart.disabled="disabled";
		MainForm.presetseqstop.disabled="disabled";
	}
	cam = null;
}

function RecordMethod(startstop, index)	//設定開始/停止錄影
{	//如果4/16分割的時候按下record只是錄一channel，則index可以用到
	if (startstop)
	{
		UICtrlManualRecordImg(index, cFunctionOn);
	}
	else
	{
		UICtrlManualRecordImg(index, cFunctionOff);
	}		
	RecPos=index;

	index=ComPlayingChan[index];
	if(var_CameraIP[index].length!=0) RecordCameras[index]=startstop;
	else return;
	RecChan=index;

	var query="system/manualrecord.cgi?uid=" +uid+ "&camera=" +index;
	if(startstop)
	{
		query+="&action=1";
		RecAction=1;
	}
	else if(!startstop)
	{
		query+="&action=0";
		RecAction=0;
	}
	
	HTTPCamRecReq=getHTTPReq();
	if(typeof(HTTPCamRecReq)=="undefined") return;
	HTTPCamRecReq.onreadystatechange=RecResult;
	HTTPCamRecReq.open("POST", "http://" +webipport+ "/" +query, true);
	HTTPCamRecReq.send(null);
}
function RecResult()
{
	if (HTTPCamRecReq.readyState == 4) 
	{	
		if (HTTPCamRecReq.status != 200)
		{
			window.status = err_noresponse;
			return;
		}
		
		blnServerResponse = true;
		if(HTTPCamRecReq.responseText.toString().substring(0,2)!="OK")
		{
			window.status=err_record;
			if(RecAction==1)
			{
				RecordCameras[RecChan]=false;
				document.getElementById("startrec"+RecPos).style.display="";
				document.getElementById("stoprec"+RecPos).style.display="none";
			}
			else if(RecAction==0)
			{
				RecordCameras[RecChan]=true;
				document.getElementById("startrec"+RecPos).style.display="none";
				document.getElementById("stoprec"+RecPos).style.display="";
			}
		}
		else
		{
			RecAction=-1;
			setTimeout("GetCamStatus(true)",1000);
		}
		if (typeof(CGIResponseTimer)== "number") clearTimeout(CGIResponseTimer);	
	}
}

function groupClickEvent(eve)
{
	var element=getEventTarget(eve);
	var id=element.getAttribute("id");
	if(id.length==0) return;
	if(id.indexOf("seqsel_g")==-1 && id.indexOf("seqsel_a")==-1) return;
	groupClick(id);
}

//****************************************************Playback****************************************************************************
function SelPbChan(CamNumber, checked)
{	
	var BtnChan = document.getElementsByName("pbSelChan");
	var color=BtnChan[CamNumber-1].style.backgroundColor;
	var PlayChan = document.getElementsByName("P_ID");
	var ChanNum = 0;
	if(color==chan_no || color==chan_nopbpri) return;
	if(color==selctedchan)
	{	
		if (!PlaybackPri[CamNumber])
		{
			BtnChan[CamNumber-1].style.background=chan_nopbpri;	
			BtnChan[CamNumber-1].disabled="disabled";
			BtnChan[CamNumber-1].style.cursor="default";
		}
		else BtnChan[CamNumber-1].style.background=chan_dis;	
	} 
	else 
	{	
		var selected=0;
		for(sPC=1;sPC <= SVRCamCount;sPC++)
		{	
			if(BtnChan[sPC-1].style.backgroundColor==selctedchan) selected++;
		}
		if (selected==4) return;
		else 
		{
			BtnChan[CamNumber-1].style.background=selctedchan;
			selected++;
		}
	}
	
	if (selected > 1) 
	{
		pb_partition=4;
		SetVideoArea(0, 1); 
	}
	ChanNum=0;
	for(sPC=1;sPC <= SVRCamCount;sPC++)
	{	
		if(BtnChan[sPC-1].style.backgroundColor==selctedchan)
		{
			replaceTextChild(PlayChan[ChanNum], sPC.toString());
			PlayChan[ChanNum].style.background="#333333";
			ChanNum++;
		}
	}
	
	if (ChanNum >0) 
	{
		MainForm.buttonPBGo.disabled="";
		MainForm.sel_search.disabled="";
	}
	else 
	{
		MainForm.buttonPBGo.disabled="disabled";
		MainForm.sel_search.disabled="disabled";	
	}
		
	ChanNum--;
	for(i=0; i<=3; i++)
	{
		if (i>ChanNum)
		{
			replaceTextChild(PlayChan[i], "");
			PlayChan[i].style.background="#CCCCCC";	
		}
	}

	for(i=0; i<=3; i++) SetPlaybackTitle(i, i+1);
}

function GetSelSearchChan()
{	
	var result='';
	var BtnCam = document.getElementsByName("pbSelChan");
	for(gSSC=1;gSSC <= SVRCamCount;gSSC++)
	{
		if(BtnCam[gSSC-1].style.backgroundColor==selctedchan)
		{
			if(result.length!=0) result+=",";
			result+=gSSC;
		}
	}
	return result;
}

function searchAt(byuser)
{
	if(MainForm.pbsearchyear.value<1 || MainForm.pbsearchmonth.value<1) 
	{	
		document.getElementById("pbguidetable").innerHTML='<table border="0" cellpadding="0" cellspacing="0" align="right" style="padding:5px 5px 0 0"><tr><td><input type="button" value="' +button_backtotop+ '" align="right" id="buttonLastStep3" name="buttonLastStep3" onclick="SearchOrSearchResult(0);" class="conceptText" style="height:25px; padding:1px 3px 1px 3px;" /></td></tr></table>';	
		return;	
	}
	var utcTime = new Date();
	utcTime.setFullYear(MainForm.pbsearchyear.value, MainForm.pbsearchmonth.value - 1, 1);
	utcTime.setHours(0, 0, 0);
	pbSearchYear=utcTime.getUTCFullYear();
	pbSearchMonth=(utcTime.getUTCMonth() + 1);	
	pbSearchDate=utcTime.getUTCDate();
	pbSearchHour=utcTime.getUTCHours(); 
	pbSearchMin=utcTime.getUTCMinutes();
	pbSearchSec=utcTime.getUTCSeconds();
	MainForm.buttonLastStep3.title = button_backtotop;
	searchpbByTime(2,30, byuser);
}

function PlayThisSec(eve)
{		
	var element=getEventTarget(eve);
	var id=element.getAttribute("id");	//5:2008_06_05, 5:2008_06_05_01_02 etc
	if(eve.button==1)	//IE: 左鍵-1, Firefox: 左鍵-0
	{
		if(id.length==0) return;
		if(element.getAttribute("bgcolor")=="#cccccc") return;
		if (PlaybackCommanding == true) return;
		PlaybackCommanding = true;
		document.getElementsByTagName('body')[0].style.cursor="wait";
		document.getElementById("PlayControlButton").style.display="";
		id=id.split(":")[1];
		searchbytimeplayingtime=id;
		if(PBActionNow==PbActionStop) playbystarttime(PbActionPlayPause);
		else
		{
			playbystarttime(PbActionStop);
			WaitMediaStop();
		}
	}
	else searchIn(eve);
}

function WaitMediaStop(){
	if (document.getElementById("Video1").TimeStamp==0 && document.getElementById("Video2").TimeStamp==0 && document.getElementById("Video3").TimeStamp==0 && document.getElementById("Video4").TimeStamp==0)
	{
		playbystarttime(PbActionPlayPause);
	}
	else setTimeout("WaitMediaStop();", 100);
}

function searchIn(eve)
{
	var elementId=getEventTarget(eve).getAttribute("id");
	var element=getEventTarget(eve);
	if(elementId.length==0) return;
	var searchType = parseInt(elementId.split(":")[0], 10);
	elementId = elementId.split(":")[1].split("_");
	//IE: 左鍵-1, 右鍵-2; Firefox: 左鍵-0, 右鍵-2;
	if(eve.button==2) PbPreNext();
	else if (element.getAttribute("bgcolor")!="#cccccc") 
	{	
		if(getEventTarget(eve).getAttribute("bgcolor")=="#cccccc") return;
		if(searchType==2) section=24;
		else if(searchType==3) section=60;
		else if(searchType==4) section=60;
		else return false;
		pbSearchYear=elementId[0]; 
		pbSearchMonth=elementId[1]; 
		pbSearchDate=elementId[2]; 
		pbSearchHour=elementId[3]; 
		pbSearchMin=elementId[4]; 
		pbSearchSec=elementId[5];
		searchpbByTime(searchType+1,section, true);
	}
}

function playbyevent(time)	//play when click the result image
{	
	if (PlaybackCommanding == true) return;
	EvePbTime="";
	if(time=="") return;
	PlaybackCommanding = true;
	document.getElementsByTagName('body')[0].style.cursor="wait";
	if(PBActionNow!=PbActionPause && PBActionNow!=PbActionStop)
	{
		if(time=="") return;
		playbackcontrol(PbActionStop,"");
		EvePbTime=time;
		setTimeout("WaitVideoStop();",100);
	}
	else
	{
		if(EvePbTime=="" && time=="") return;
		if(time=="")
		{
			time=EvePbTime;
			EvePbTime="";
		}
		tmpAddChan = "";
		var playChan = GetSelSearchChan().toString().split(",");
		for (ch = 0; ch < playChan.length; ch++)
		{
			var needAdd = true;
			if (needAdd) tmpAddChan += playChan[ch] + ",";
		}
		document.getElementsByTagName('body')[0].style.cursor="wait";
	
		getPbGid();
		tmpAddChan = tmpAddChan.substring(0, tmpAddChan.length - 1);
		tmpAction = PbActionPlay;
		tmpPbTime = time;
	}
}

function WaitVideoStop(){
	if (document.getElementById("Video1").TimeStamp==0 && document.getElementById("Video2").TimeStamp==0 && document.getElementById("Video3").TimeStamp==0 && document.getElementById("Video4").TimeStamp==0)
	{
		if(EvePbTime=="") return;
		tmpAddChan = "";
		var playChan = GetSelSearchChan().toString().split(",");
		for (ch = 0; ch < playChan.length; ch++)
		{
			var needAdd = true;
			if (needAdd) tmpAddChan += playChan[ch] + ",";
		}
		document.getElementsByTagName('body')[0].style.cursor="wait";
	
		getPbGid();
		tmpAddChan = tmpAddChan.substring(0, tmpAddChan.length - 1);
		tmpAction = PbActionPlay;
		tmpPbTime = EvePbTime;
		//playbackcontrol(PbActionPlay,EvePbTime);
	}
	else setTimeout("WaitVideoStop();", 100);
}

function waitServerReady()
{	
	if( PBActionNow==PbActionStop || PBActionNow==PbActionPause)
	{
		HTTPReq=getHTTPReq();
		if(typeof(HTTPReq)=="undefined") return;
		HTTPReq.onreadystatechange=setPbInfo;
		HTTPReq.open("POST", "http://" +webipport+ "/" +pbcgirequest, true);
		HTTPReq.send(null);
		waittimes=0;
		return;
	}
	if( document.getElementById("Video1").ConnectionStatus()>=48 )
	{	
		HTTPReq=getHTTPReq();
		if(typeof(HTTPReq)=="undefined") return;
		HTTPReq.onreadystatechange=setPbInfo;
		HTTPReq.open("POST", "http://" +webipport+ "/" +pbcgirequest, true);
		HTTPReq.send(null);
		waittimes=0;
	}
	else if(waittimes>99)
	{
		waittimes=0;
		document.getElementsByTagName('body')[0].style.cursor="default";
		PlaybackCommanding = false;
		if(PBActionNow==PbActionPlay) document.getElementById("PBPlayPause").src="Images/PB_Play_Pause.gif";
		else if(PBActionNow==PbActionPause) document.getElementById("PBPlayPause").src="Images/PB_Play_Pause.gif";
		else if(PBActionNow==PbActionStop) document.getElementById("PBStop").src="Images/PB_Stop.gif";
		else if(PBActionNow==PbActionForward) document.getElementById("PBForward").src="Images/PB_Forward.gif";
		else if(PBActionNow==PbActionReverse) document.getElementById("PBReverse").src="Images/PB_Reverse_Forward.gif";
		else if(PBActionNow==PbActionNextImg) document.getElementById("PBNextImg").src="Images/PB_Step_Right.gif";
		PBActionNow=PBActionBefore;
		if(PBActionNow==PbActionPlay) document.getElementById("PBPlayPause").src="Images/PB_Play_Pause_Run.gif";
		else if(PBActionNow==PbActionPause) document.getElementById("PBPlayPause").src="Images/PB_Play_Pause_Pause.gif";
		else if(PBActionNow==PbActionStop) document.getElementById("PBStop").src="Images/PB_Stop_Run.gif";
		else if(PBActionNow==PbActionForward) document.getElementById("PBForward").src="Images/PB_Forward_Run.gif";
		else if(PBActionNow==PbActionReverse) document.getElementById("PBReverse").src="Images/PB_Reverse_Forward_Play.gif";
		else if(PBActionNow==PbActionNextImg) document.getElementById("PBNextImg").src="Images/PB_Step_Right-Run.gif";
		if(live_seq_pb==pbsubmenu) window.status=err_nopb;
	}
	else
	{
		waittimes++;
		setTimeout("waitServerReady()",100);
	}
}

function ContinuousSearch()
{
	var rtime=getLastResultTime();
	if(rtime.length==0) return;
	
	var sdate=new Date();	//從格林威治時間調到時區時間
	sdate.setUTCFullYear(rtime.substring(0,4), parseInt(rtime.substring(5,7),10)-1, rtime.substring(8,10));
	sdate.setUTCHours(parseInt(rtime.substring(11,13),10), parseInt(rtime.substring(14,16),10), parseInt(rtime.substring(17,19), 10));

	var value=(sdate.getMonth()+1);
	value= (value<10?'0':'') +value;
	MainForm.jumpday.value=getMonthString(value);
	value=sdate.getDate();
	value= (value<10?'0':'') +value;
	MainForm.jumpday.value+=" " +value;
	MainForm.jumpday.value+=", " +sdate.getFullYear();
	value=sdate.getHours();
	value= (value<10?'0':'') +value;
	MainForm.eventtime_hh.value=value;
	value=sdate.getMinutes();
	value= (value<10?'0':'') +value;
	MainForm.eventtime_mm.value=value;
	value=sdate.getSeconds();
	value= (value<10?'0':'') +value;
	MainForm.eventtime_ss.value=value;
	SendPbEventSearch(true);
}

function SelectPlayback(sel)
{
	var init="none", byevent="none", bystart="none", bytime="none", play="none"; bylastest="none";
	if(sel==0) init="";
	else
	{
		if (blnGetPBStatTimeOK == false)
		{
			document.getElementsByTagName('body')[0].style.cursor="wait";
			setTimeout("SelectPlayback(" + sel +");", 500);
		}
		else
		{
			document.getElementsByTagName('body')[0].style.cursor="default";

			if(GetSelSearchChan().length==0) 
			{
				window.status=err_noselcamera;
				alert(err_noselcamera);
				return;
			}
			if (sel==1) 
			{
				byevent="";
				play="";
				SendPbEventSearch(false);
			}
			else if (sel==2) 
			{
				bystart="";
				play="";
			}
			else if (sel==3) 
			{
				bytime="";
				play="";
				searchAt(true);
			}
			else if (sel == 4)
			{
				bylastest="";
				play="";
				searchLastestEvent();
			}
		}
	}
	for (playChan=1; playChan <= SVRCamCount; playChan++) RecAudioOpen[playChan] = 0;

	PlayControlButton.style.display=play;
	TRpbLastestEvent.style.display=bylastest;
	trSearchLastEveResult.style.display=bylastest;
	SearchChanTab.style.display=init;
	SearchTypeSel.style.display=init;
	SearchResult.style.display=byevent;
	ResultJumpTime.style.display="none";
	SearchTime.style.display=bystart;
	guidedsel.style.display=bytime;
	TRpbguidetable.style.display=bytime;
}


//***********************************************Search Playback By Event**********************************************************
var cameras = new Array();
var eventtype = new Array();
var timestemp = new Array();
var listtype=true;

var CONST_playback_eventsearch_result_pic="pic";
var CONST_playback_eventsearch_result_text="text";

function switchIndex(num)
{	return ListResult(num)+LinkResult(num);	}

function getResult(result, type)
{	listtype=type;
	cameras = new Array(); timestemp = new Array(); eventtype=new Array();
	
	var qresult = result;	qresult=qresult.split("\n");	if(qresult.length<2) return;
	qresult=qresult[1].split(",");
	for(i=0;i<qresult.length;i++)	/*<camera ID>:<event type>:<yyyy:mm:dd:hh:mm:ss> [,<camera ID>:<event type>:<yyyy:mm:dd:hh:mm:ss>...]*/
	{	if(qresult[i].indexOf(":")!=-1)
		{	qresult[i]=qresult[i].split(":");
			cameras[cameras.length]=qresult[i][0];
			eventtype[eventtype.length]=qresult[i][1];
			timestemp[timestemp.length]=qresult[i][2]+ ":" +qresult[i][3]+ ":" +qresult[i][4]+ ":" +qresult[i][5]+ ":" +qresult[i][6]+ ":" +qresult[i][7];
		}
	}
	return ListResult(0)+LinkResult(0);
}

function ListResult(start)
{	var LResult=""; var time;	var viewTime;
	
	if(listtype==CONST_playback_eventsearch_result_text) LResult+='<table border="0" cellpadding="0" cellspacing="0" align="center" class="normalText"><tr><td height="8">&nbsp;</td></tr>';
	if(cameras.length!=0)
	{	for(i=start*16;(i<start*16+16 && i<cameras.length) ;i++)
		{	time=timestemp[i].split(":");
			
			var sdate=new Date();	//需從格林威治時間調回來
			sdate.setUTCFullYear(parseInt(time[0],10), parseInt(time[1],10)-1, parseInt(time[2],10));
			sdate.setUTCHours(parseInt(time[3],10), parseInt(time[4],10), parseInt(time[5],10), 0);
			
			var playTimeStamp = (sdate.getTime() / 1000);
			
			time[0]=sdate.getFullYear();
			time[1]=sdate.getMonth()+1;	time[1]=(time[1]<10?'0':'') +time[1];
			time[2]=sdate.getDate();		time[2]=(time[2]<10?'0':'') +time[2];
			time[3]=sdate.getHours();	time[3]=(time[3]<10?'0':'') +time[3];
			time[4]=sdate.getMinutes();	time[4]=(time[4]<10?'0':'') +time[4];
			time[5]=sdate.getSeconds();	time[5]=(time[5]<10?'0':'') +time[5];
			
			viewTime=time[0]+ '/' +time[1]+ '/' +time[2]+ ' ' +time[3]+ ':' +time[4]+ ':' +time[5];
			if(listtype==CONST_playback_eventsearch_result_pic)
			{	LResult+='<img src="' +cameras[i]+ "_" +time[0]+time[1]+time[2]+time[3]+time[4]+time[5]+ '.jpg" id="result' +(i+1)+ '" alt="' +eventtype[i]+ ' CH' +cameras[i]+ ' ' +viewTime+ '"';
				if(i%4==3) {	LResult+=' style="padding:1px 0 7px 0;" /> <br />';	}
				else {	LResult+=' style="padding:1px 1px 7px 0;" />';	}
			} else if(listtype==CONST_playback_eventsearch_result_text)
			{
				var imageSrc = "";
				var imageTitle = "";
				if (eventtype[i].toUpperCase().indexOf("OBJECT_LOSS_RESET") != -1)
				{
					imageSrc = "Images/16x16_ObjectLoss_Set.gif";
					imageTitle = pb_ResetObjectLos;
				}
				else if (eventtype[i].toUpperCase().indexOf("UNATTENDED_OBJECT_RESET") != -1)
				{
					imageSrc = "Images/16x16_Foreign_Set.gif";
					imageTitle = pb_ResetUnattendedObject;				
				}
				else if (eventtype[i].toUpperCase().indexOf("UNATTENDED_OBJECT") != -1)
				{
					imageSrc = "Images/16x16_Foreign.gif";
					imageTitle = pb_UnattendedObject;				
				}
				else if (eventtype[i].toUpperCase().indexOf("THREAT_RESET") != -1)
				{
					imageSrc = "Images/16x16_Attack_Set.gif";
					imageTitle = pb_ResetTamper;				
				}
				else if (eventtype[i].toUpperCase().indexOf("POS_USER_DEF") != -1)
				{
					imageSrc = "Images/16x16_POSEvent_Trigger.gif";
					imageTitle = pb_POSEvent;				
				}
				else if (eventtype[i].toUpperCase().indexOf("POS_DATA") != -1)
				{
					imageSrc = "Images/16x16_POSEvent.gif";
					imageTitle = pb_POSData;				
				}
				else if (eventtype[i].toUpperCase().indexOf("TRIPLE_WIRE") != -1)
				{
					imageSrc = "Images/16x16_OverLine.gif";
					imageTitle = pb_ResetTripwire;				
				}
				else if (eventtype[i].toUpperCase().indexOf("OBJECT_LOSS") != -1)
				{
					imageSrc = "Images/16x16_ObjectLoss.gif";
					imageTitle = pb_ObjectLossEvent;				
				}
				else if (eventtype[i].toUpperCase().indexOf("OBJECT_COUNT") != -1)
				{
					imageSrc = "Images/16x16_Counting.gif";
					imageTitle = pb_ObjectCount;				
				}

				else if (eventtype[i].toUpperCase().indexOf("FACE_COUNT") != -1)
				{
					imageSrc = "Images/16x16_Face.gif";
					imageTitle = pb_FaceCounting;				
				}
				else if (eventtype[i].toUpperCase().indexOf("MANUAL") != -1)
				{
					imageSrc = "Images/16x16_ManualREC.gif";
					imageTitle = pb_ManualTrigger;				
				}
				else if (eventtype[i].toUpperCase().indexOf("THREAT") != -1)
				{
					imageSrc = "Images/16x16_Attack.gif";
					imageTitle = pb_TamperEvent;				
				}
				else if (eventtype[i].toUpperCase().indexOf("MD") != -1)
				{
					imageSrc = "Images/16x16_MD.gif";
					imageTitle = pb_MDEvent;				
				}
				else if (eventtype[i].toUpperCase().indexOf("DI") != -1)
				{
					imageSrc = "Images/16x16_DI.gif";
					imageTitle = pb_DIEvent;				
				}
				else
				{
					imageSrc = "Images/16x16_GenEvent.gif";
					imageTitle = "";				
				}
				LResult+='<tr><td height="23" align="left"><img src="' + imageSrc + '" width="16" height="16" onclick="playbyevent( ' + playTimeStamp +');" title="' + imageTitle + '" /><a href="#" title="' +viewTime+'" onclick="playbyevent( ' + playTimeStamp +');" >CH' +cameras[i]+ " " +": " +viewTime+ '</a></td></tr>';
			}
		}
	}
	return LResult+'</table>';
}

function LinkResult(start)
{	var LinkResult=''; var i=0;
	for(i=0;i*16<cameras.length;i++)
	{	if(start==i) {	LinkResult+='<a>' +(i+1)+ '</a> &nbsp;';	}
		else {	LinkResult+='<a href="#">' +(i+1)+ '</a> &nbsp;';	}
	}
	
	if(LinkResult=="") return '<span> ' +pb_totalpage+ ': 0 </span>';
	else return '';
}

function getLastResultTime()
{	if(timestemp.length>0)	return timestemp[timestemp.length-1];	//yy:mm:dd:hh:mm:ss
	else	return "";
}

function PbPreNext(){
	var NowSearchData = MainForm.SearchInfo.value;
	NowSearchData = NowSearchData.split(":");  //0:年  1:月  2:日  3:時  4:分  5:秒
	var yy=NowSearchData[1]; month=NowSearchData[2]; dd="01"; hh="00"; mm="00"; ss="00"; var section=30;
	if(parseInt(NowSearchData[0], 10)==1) 
	{	
		SelectPlayback(0);	
		playbystarttime(PbActionStop);
		return;
	}
	else if (parseInt(NowSearchData[0], 10)==2) section = 30;
	else if (parseInt(NowSearchData[0], 10)==3) section = 24;
	else if (parseInt(NowSearchData[0], 10)==4) section = 60;

	var utcTime = new Date();
	utcTime.setUTCFullYear(parseInt(NowSearchData[1], 10), parseInt(NowSearchData[2] ,10) - 1, parseInt(NowSearchData[3], 10));
	utcTime.setUTCHours(parseInt(NowSearchData[4], 10), parseInt(NowSearchData[5] ,10), parseInt(NowSearchData[6], 10));

	pbSearchYear=utcTime.getUTCFullYear();	
	pbSearchMonth=(utcTime.getUTCMonth() + 1);	
	pbSearchDate=utcTime.getUTCDate();
	pbSearchHour=utcTime.getUTCHours(); 
	pbSearchMin=utcTime.getUTCMinutes();
	pbSearchSec=utcTime.getUTCSeconds();

	searchpbByTime(parseInt(NowSearchData[0], 10),section, true);
}

//*****************************************************Change Page**************************************************************************
function OpenEmap() {	window.parent.bottomFrame.location="Emap.html";	}
function OpenGmap() {	window.parent.bottomFrame.location="GoogleMap.html";	}

function OpenUserInfo(){
	var Param = new Array();
	Param[0] = var_lang;
	Param[1] = window.parent.bottomFrame;
	Param[2] = window.parent.startFrame.document.getElementById("def_lang");
	Param[3] = window.parent.startFrame.document.getElementById("language_type");
	Param[4] = startFDoc.getElementById("loginuser").value;
	Param[5] = "<!--#echo var="my.company" -->";
	Param[6] = "<!--#echo var="my.department" -->";
	Param[7] = "<!--#echo var="my.tel" -->";
	Param[8] = "<!--#echo var="my.mobile" -->";
	Param[9] = "<!--#echo var="my.email" -->";
	Param[10] = "<!--#echo var="my.group" -->";
	Param[11] = "<!--#echo var="my.description" -->";
	
	if (navigator.appName=="Microsoft Internet Explorer") window.showModalDialog("UserInfo.html", Param,'dialogWidth:400px;dialogHeight:450px;dialogLeft:' + (screen.width-500) + 'px;resizable:no;status:no;scrollbars:no');
	else window.open("UserInfo.html",'newWin','modal=yes,width=400,height=450,resizable=no,scrollbars=no');
	if (MainForm.sel_lang.value != startFDoc.getElementById("language_type").value ) window.location.reload();
}

function OpenSetup()
{
	window.parent.bottomFrame.location="Setup.html";
}

//************************************************UI Control*******************************************************
function UICtrlAudioImg(ImgId, AudioStatus) {
	var imgDisabled = "none";
	var imgOff = "none";
	var imgOn = "none";
	if (AudioStatus == cFunctionDisabled) imgDisabled = "";
	else if (AudioStatus == cFunctionOff) imgOff = "";
	else if (AudioStatus == cFunctionOn) imgOn = "";
	document.getElementById("img_NoSpeek"+ImgId).style.display = imgDisabled;
	document.getElementById("img_speek"+ImgId).style.display = imgOff;
	document.getElementById("img_speekdisplay"+ImgId).style.display = imgOn;
}

function UICtrlAudioPostImg(ImgId, AudioPostStatus) { 
	var imgDisabled = "none";
	var imgOff = "none";
	var imgOn = "none";
	if (AudioPostStatus == cFunctionDisabled) imgDisabled = "";
	else if (AudioPostStatus == cFunctionOff) imgOff = "";
	else if (AudioPostStatus == cFunctionOn) imgOn = "";
	document.getElementById("img_NoAudioPost"+ImgId).style.display = imgDisabled;
	document.getElementById("img_AudioPostOff"+ImgId).style.display = imgOff;
	document.getElementById("img_AudioPostOn"+ImgId).style.display = imgOn;
}

function UICtrlManualRecordImg(ImgId, RecordStatus) {
	var imgDisabled = "none";
	var imgOff = "none";
	var imgOn = "none";
	if (RecordStatus == cFunctionDisabled) imgDisabled = "";
	else if (RecordStatus == cFunctionOff) imgOff = "";
	else if (RecordStatus == cFunctionOn) imgOn = "";
	document.getElementById("img_norecord"+ImgId).style.display = imgDisabled;
	document.getElementById("img_record"+ImgId).style.display = imgOff;
	document.getElementById("img_recording"+ImgId).style.display = imgOn;
}

function UICtrlSnapshotImg(ImgId, SnapshotStatus) {
	var imgDisabled = "none";
	var imgOff = "none";
	if (SnapshotStatus == cFunctionDisabled) imgDisabled = "";
	else if (SnapshotStatus == cFunctionOff) imgOff = "";
	document.getElementById("img_noshapshot"+ImgId).style.display = imgDisabled;
	document.getElementById("img_shapshot"+ImgId).style.display = imgOff;
}

function UICtrlExportAVIImg(ImgId, ExportAVIStatus) {
	var imgDisabled = "none";
	var imgOff = "none";
	var imgOn = "none";
	if (ExportAVIStatus == cFunctionDisabled) imgDisabled = "";
	else if (ExportAVIStatus == cFunctionOff) imgOff = "";
	else if (ExportAVIStatus == cFunctionOn) imgOn = "";
	document.getElementById("img_noExportAVI"+ImgId).style.display = imgDisabled;
	document.getElementById("img_ExportAVIOff"+ImgId).style.display = imgOff;
	document.getElementById("img_ExportAVIing"+ImgId).style.display= imgOn;
}

//************************************************Media Control*******************************************************
function MediaOSD(objMeida, blnOSD, blnTimer, blnFps, blnText, strText, intPos, intPosX, intPosY, intFontSize, strFontName, intTextColR, intTextColG, intTextColB, blnBGTrans, intBGColR, intBGColG, intBGColB) {
	var showOSDMode=0;
	if(blnOSD==0) showOSDMode=0;
	else
	{
		if(blnTimer==1 && blnFps==1 && blnText==1 ) showOSDMode=7;
		else if(blnFps==1 && blnText==1 ) showOSDMode=6;
		else if(blnTimer==1 && blnFps==1) showOSDMode=5;
		else if(blnTimer==1&& blnText==1 ) showOSDMode=3;
		else if(blnFps==1) showOSDMode=4;
		else if(blnText==1 ) showOSDMode=2;
		else if(blnTimer==1) showOSDMode=1;
	}
	objMeida.SetOSDMethod(showOSDMode, strText, intPos, intPosX, intPosY, intFontSize, strFontName, intTextColR, intTextColG, intTextColB, blnBGTrans, intBGColR, intBGColG, intBGColB);
}

function DestroyMediaCOM(objMedia) {
	objMedia.PlayControlMethod(0, 1, 1);
	objMedia.DestroyMethod();
	objMedia.parentNode.removeChild(objMedia);
	delete objMedia;
}

function MediaPlayFunction(objMedia, playAction, playChan, PBId, Audio, AudioPost, KeepFrame) {
	objMedia.KeepFrameOn = KeepFrame;
	objMedia.PlayControlMethod(playAction, playChan, PBId);
	objMedia.AudioPostControlMethod(AudioPost);
	objMedia.AudioControlMethod(Audio);
}

//*******************************************************SEQ**********************************************************

function PreConnect(){
	if ( seqIndex>seqArray.length-1 ) seqIndex=0;
	var Preplay=seqArray[seqIndex];
	var GroupCamId = parseInt(Preplay.substring(1),10);
	if(Preplay.substring(0,1)=="a")
	{
		for (i = 1 ; i <= 16; i++)
		{
			if (TdListCamId[(GroupCamId-1)*16 + i] != 0 && LiveViewChanPri[TdListCamId[(GroupCamId-1)*16 + i]] && var_CameraIP[TdListCamId[(GroupCamId-1)*16 + i]].length != 0) 
			{
				document.getElementById("Video" + i).PlayStartMethod(var_comip, var_comport, "", "", (GroupCamId-1)*16 + i);
				document.getElementById("Video" + i).PreConnectMethod(TdListCamId[(GroupCamId-1)*16 + i]);
			}
		}
	}
	else if(Preplay.substring(0,1)=="g")
	{	
		for (i = 1; i <= 4; i++)
		{
			if (TdListCamId[(GroupCamId-1)*4 + i] != 0 && LiveViewChanPri[TdListCamId[(GroupCamId-1)*4 + i]] && var_CameraIP[TdListCamId[(GroupCamId-1)*4 + i]].length != 0) 
			{
				document.getElementById("Video" + i).PlayStartMethod(var_comip, var_comport, "", "", (GroupCamId-1)*4 + i);
				document.getElementById("Video" + i).PreConnectMethod(TdListCamId[(GroupCamId-1)*4 + i]);
			}
		}
	}
	else if(Preplay.substring(0,1)=="c")
	{	
		document.getElementById("Video1").PlayStartMethod(var_comip, var_comport, "", "", 1);
		document.getElementById("Video1").PreConnectMethod(TdListCamId[GroupCamId]);	
	}
}
