/**
 * @author zerostyle _崔良_ 83226227 zerostyle@126.com
 */


var Namespace = new Object();

Namespace.register = function(path){     
    var arr = path.split(".");     
    var ns = "";     
    for(var i=0;i<arr.length;i++){     
        if(i>0) ns += ".";     
        ns += arr[i];     
        eval("if(typeof(" + ns + ") == 'undefined') " + ns + " = new Object();");     
    }     
}    
Namespace.register("JoveTech.VVSWeb.Function");


JoveTech.VVSWeb.Function=
{
	
	ActiveXContainer:"tdActiveX",
	

	/**
	 * _登陆前的屏蔽_
	 * @param {Object} loginHTML
	 */
	LoginShield:function(loginHTML)
	{
		try
		{
			var loading = document.createElement("div");
		 	loading.setAttribute("id", "loadingDiv");//设置ID
		 	loading.style.position = "absolute";//设置DIV为相对位置c
		 	loading.style.zIndex = "1000";
		 	loading.style.top = window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0 + "px";
		 	loading.style.left="0px";//居左c
		 	loading.style.right = "0px";//居右c
		 	loading.style.background="#f6f6f6";//背景颜色c
		 	loading.style.border="5 solid #77a";//边框c
			loading.style.fontFamily = "Arial,Helvetica,sans-serif";//DIV中的字体c
	
		 	loading.oncontextmenu=function(){return false;};//屏蔽右键c
		 	if(document.body.style.overflowY!="hidden")
			{
		 		document.body.style.overflowY="hidden";//设置页面的滑动块不可用c
		 		document.body.style.overflowX="hidden";//设置页面的滑动块不可用c
		 	}
	
		 	//防止DIV元素不在最上层而创建的iframe元素c
		 	var iframe = document.createElement("iframe");
			iframe.setAttribute("id","loadframe")
			//iframe.src="DownLoadActiveX.htm";
			iframe.style.position = "absolute";//设置DIV为相对位置c
		 	iframe.style.zIndex = "100";
		 	iframe.style.top = window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0 + "px";
		 	iframe.style.left="0px";//居左c
		 	iframe.style.right = "0px";//居右c
		 	iframe.style.background="#fff";//背景颜色c
		 	iframe.style.border="5 solid #000";//边框c
			iframe.style.padding = "0px";
			iframe.style.textAlign="center";//文字横向对齐方式c
			
		 	
		 	var br=document.createElement("br");
		 	loading.appendChild(br);
		 	var text = document.createTextNode("loading");//
			loading.appendChild(br);
		 	loading.innerHTML = loginHTML;
			
		 	//设置高度,宽度和透明度c
		 	iframe.style.width="100%";//框架的宽度c
		 	iframe.style.height="100%";//框架的高度c
		 	iframe.style.filter="alpha(opacity=1)";//透明度c
		 	
		 	loading.style.width="100%";
		 	loading.style.height="100%";
		 	loading.style.filter="alpha(opacity=1)";
		 	loading.style.textAlign="center";//文字横向对齐方式c
		 	loading.style.padding = "100px";
			document.getElementsByTagName("body")[0].appendChild(loading);
			document.getElementsByTagName("body")[0].appendChild(iframe);
			this.alpha_Change(iframe,1,15,5);
			this.alpha_Change(loading,1,15,5);
		}
		catch(e)
		{
			alert("Waiting.js function Shield err"+e.message)
		}
	},
	alpha_Change:function(control,nowValue,step,timeOut)
	{
		with(this)
		{
			if(step==undefined||nowValue==undefined)
			{
				return;
			}
			if(nowValue%10==0)
			{
				//alert(nowValue);
			}
			if(nowValue<=0||nowValue>=100)
			{
				return;
			}
			nowValue+=step;
			if(nowValue<0)nowValue=0;
			if(nowValue>100) nowValue=100;
			control.style.filter="alpha(opacity="+nowValue+")";
			window.setTimeout(function(){alpha_Change(control,nowValue,step,timeOut)},timeOut)
		}
	},
	
	LoginSuccUnShield:function (isShielding)
	{
		try
		{
			
			
			var loading=ZeroStyle.Web.UI.Helper.$("loadingDiv");
			var iframe=ZeroStyle.Web.UI.Helper.$("loadframe");
			document.body.style.overflowY="auto";
			ZeroStyle.Web.UI.Helper.$remove(iframe.id);
			ZeroStyle.Web.UI.Helper.$remove(loading.id);
			JoveTech.VVSWeb.Function.CreateGroupTree("CustomVideoGroupDiv");
				ZeroStyle.Web.UI.Helper.$("tdActiveX").onresize=function()
				{
					ZeroStyle.VVSWeb.API.RefreshWindow();
				}
			//_以下为渐显效果_
			/*if(!isShielding)
			{
				this.alpha_Change(iframe,99,-15,10)
				this.alpha_Change(loading,99,-15,10)
			}	
				
					
			if(loading.style.filter=="alpha(opacity=0)"&&iframe.style.filter=="alpha(opacity=0)")
			{
				iframe.src="";
				document.body.style.overflowY="auto";
				ZeroStyle.Web.UI.Helper.$remove(iframe.id);
				ZeroStyle.Web.UI.Helper.$remove(loading.id);
				//ZeroStyle.Web.UI.Helper.display(ZeroStyle.VVSWeb.API.controlId);
				//ZeroStyle.VVSWeb.API.RenderTo(JoveTech.VVSWeb.Function.ActiveXContainer);
				JoveTech.VVSWeb.Function.CreateGroupTree("CustomVideoGroupDiv");
				ZeroStyle.Web.UI.Helper.$("tdActiveX").onresize=function()
				{
					ZeroStyle.VVSWeb.API.RefreshWindow();
				}
				return;
			}
			window.setTimeout("JoveTech.VVSWeb.Function.LoginSuccUnShield(true)",100);
			*/
				
						
		}
		catch(e)
		{
			alert("Waiting.js function UnShield err"+e.message)
		}
	},
	
	Login:function (btnControl)
	{
		 try
		 {
			with(ZeroStyle.Web.UI.Helper)
			{
				
				hidden(btnControl.id);
				var _name=$v("txtUserName");
				if(_name=="")
				{
					throw new Error(JoveTech.VVSWeb.Language.Error.error1)
				}
				var _passwd=$v("txtUserPassWd");
				
				var succ=ZeroStyle.VVSWeb.API.Login(_name,_passwd,$v("selLanguage"));
				
				if(!succ)
				{
					throw new Error(JoveTech.VVSWeb.Language.Error.error3);
				}
				setCookie("userName",_name,1095);
				var btnParent=btnControl.parentElement;
				//alert(JoveTech.VVSWeb.Language.Text.LoginLoading)
				btnParent.innerHTML=JoveTech.VVSWeb.Language.Text.LoginLoading;
				//hidden(ZeroStyle.VVSWeb.API.controlId);
				this.LoginSuccUnShield();
				display("ContentDiv");
			}
		}
		catch(e)
		{
			alert(e.message);
			ZeroStyle.Web.UI.Helper.display(btnControl.id)
		}
	},
	ToolImgClick:function (control)
	{
		//control.parentNode.parentNode.nextSibling.cells[0]
		//var tmpControl=control.parentNode.parentNode.parentNode.parentNode;//;nextSibling;
		var tmpControl=control;
		while(tmpControl.tagName.toLowerCase()!="table")
		{
			tmpControl=tmpControl.parentNode
		}
		//alert(tmpControl.getAttribute("className"))
		if(tmpControl.getAttribute("class")=="tool toolHidden"||tmpControl.getAttribute("className")=="tool toolHidden")
		{
			tmpControl.setAttribute("class","tool");
			tmpControl.setAttribute("className","tool");
			//control.title=JoveTech.VVSWeb.Language.Text.toolTip_imgClose;
		}
		else
		{
			tmpControl.setAttribute("class","tool toolHidden");
			tmpControl.setAttribute("className","tool toolHidden");
			//control.title=JoveTech.VVSWeb.Language.Text.toolTip_imgOpen;
		}
	},
	ToolTrClick:function (control)
	{
		//control.parentNode.parentNode.nextSibling.cells[0]
		//var tmpControl=control.parentNode.parentNode.parentNode.parentNode;//;nextSibling;
		var tmpControl=control;
		while(tmpControl.tagName.toLowerCase()!="table")
		{
			tmpControl=tmpControl.parentNode
		}
		//alert(tmpControl.getAttribute("className"))
		if(tmpControl.getAttribute("class")=="tool toolHidden"||tmpControl.getAttribute("className")=="tool toolHidden")
		{
			tmpControl.setAttribute("class","tool");
			tmpControl.setAttribute("className","tool");
			//control.getElementsByName("toolImg")[0].title=JoveTech.VVSWeb.Language.Text.toolTip_imgClose;
			//control.title=JoveTech.VVSWeb.Language.Text.toolTip_imgClose;
		}
		else
		{
			tmpControl.setAttribute("class","tool toolHidden");
			tmpControl.setAttribute("className","tool toolHidden");
			//control.getElementsByName("toolImg")[0].title=JoveTech.VVSWeb.Language.Text.toolTip_imgOpen;
			//control.title=JoveTech.VVSWeb.Language.Text.toolTip_imgOpen;
		}
		
	},
	SearchesRECResult:function()
	{
		//alert()
		var tableList=ZeroStyle.Web.UI.Helper.$("SearchesRECResultTable");
		var count=tableList.rows.length;
		for(var i=count-1;i>0;i--)
		{
			tableList.deleteRow(i);
		}
		var timeStr=ZeroStyle.Web.UI.Helper.$v("SearchesREC_Date");
		if(timeStr=="")
		{
			alert(JoveTech.VVSWeb.Language.Text.ToolsTitle_SearchesREC_TimeNULL);
			return;
		}
		ZeroStyle.VVSWeb.API.SearchRECFile(timeStr);
	},
	CreateGroupTree:function(RenderControlId)
	{
		//alert("123");
		ZeroStyle.Web.UI.Helper.WriteTo("",RenderControlId);
		var node_prefix="tn_";
		//alert(JoveTech.VVSWeb.Language.Text.ToolsTitle_CustomVideoGroup)
		CustomVideoGroupTree = new dTree('CustomVideoGroupTree');
		CustomVideoGroupTree.icon.root='img/dTree/globe.gif';
		
		CustomVideoGroupTree.add(0,-1,JoveTech.VVSWeb.Language.Text.ToolsTitle_GroupTree_MyVideoGroup);//_创建一个顶层节点_
		
		var rootList=eval(ZeroStyle.VVSWeb.API.GetCustomVideoGroups("-1"));//_取分组根节点_
		//alert(ZeroStyle.VVSWeb.API.GetCustomVideoGroups("-1"))
		for(var i=0;i<rootList.length;i++)
		{	
			//alert(rootList[i])
			var date=rootList[i].split(',');
			var dateName=date[0].toString();
			var dateId=node_prefix+date[1].toString();
			//alert("date[1].toString()="+date[1].toString())
			var childrenNodes=eval(ZeroStyle.VVSWeb.API.GetCustomVideoGroups(date[1].toString()));
			if(childrenNodes.length==0)
			{
				CustomVideoGroupTree.add("'"+dateId+"'",0,dateName,"javascript:void(0)");
			}
			else
			{
				CustomVideoGroupTree.add("'"+dateId+"'",0,dateName);
				for(var j=0;j<childrenNodes.length;j++)
				{
					try
					{
					//alert()
					var date1=childrenNodes[j].split(",");
					var dateName1=date1[0].toString();
					var dateId1=node_prefix+dateId+date1[1].toString();
					CustomVideoGroupTree.add("'"+dateId1+"'","'"+dateId+"'",
					"<span onclick='ZeroStyle.VVSWeb.API.PlayCustomVideoGroupPoint("+parseInt(date[1])+","+parseInt(date1[1])+")'>"+dateName1+"</span>","javascript:void(0)",dateName1,'','img/dTree/ipcamera.gif');
					}
					catch(e){}
				}
			}
		}
		ZeroStyle.Web.UI.Helper.WriteTo(CustomVideoGroupTree,RenderControlId);
		//alert("000")
	},
	ChangeLanguage:function(lang)
	{
		window.location.href=ZeroStyle.Web.UI.Helper.SetArgsFromHref("lang",window.location.href,lang);
	}
}

/**
 * _检索录像文件时，检索到每一条录像文件将调用本函数_
 * @param {Object} resultStr
 */
ZeroStyle.VVSWeb.API.Events.OnSearchGetOneRECResult=function(resultStr)
{
	//alert(resultStr)
	var channel=resultStr.substr(0,2);
	var RECTime=resultStr.substr(2,8);
	RECTime=RECTime.toString();
	var hardDisk=resultStr.substr(10,1);
	var tableList=ZeroStyle.Web.UI.Helper.$("SearchesRECResultTable");
	var newrow=tableList.insertRow();
	newrow.title=JoveTech.VVSWeb.Language.Text.ToolsTitle_SearchesREC_ResultRowTip;
	newrow.PalyId=hardDisk+ZeroStyle.Web.UI.Helper.$v("SearchesREC_Date")+channel+RECTime;
	newrow.ondblclick=function()
	{
		//alert(newrow.PalyId);
		ZeroStyle.VVSWeb.API.PlayBackRECFile(newrow.PalyId.toString())
	}
	newrow.oncontextmenu=function()
	{
		ZeroStyle.Web.RightBtClick.HiddenRightMenu();
		ZeroStyle.Web.RightBtClick.txtArray=new Array(JoveTech.VVSWeb.Language.Text.ToolsTitle_SearchesREC_rightMenu1);
		ZeroStyle.Web.RightBtClick.funArray=new Array("ZeroStyle.VVSWeb.API.DownLoadRECFile('"+newrow.PalyId.toString()+"');");
		ZeroStyle.Web.RightBtClick.InitRightMenu();
		ZeroStyle.Web.RightBtClick.ShowRightMenu();
	}
	
	var channelTd=newrow.insertCell();
	channelTd.innerText=channel;
	var RECTimeTd=newrow.insertCell();
	RECTimeTd.innerText=RECTime;
	var hardDiskTd=newrow.insertCell();
	hardDiskTd.innerText=hardDisk;
}
ZeroStyle.VVSWeb.API.Events.OnCustomVideoGroupChange=function()
{
	JoveTech.VVSWeb.Function.CreateGroupTree("CustomVideoGroupDiv");
}



window.onload=function()
{
	var lang=ZeroStyle.FrameWork.RunningTime.CurrentLanguage;

	for(var i=0;i<ZeroStyle.Web.UI.Helper.$("selLanguage").options.length;i++)
	{
		if(ZeroStyle.Web.UI.Helper.$("selLanguage").options[i].value==lang)
		{
			ZeroStyle.Web.UI.Helper.$("selLanguage").options[i].selected=true;
		}
	}
	//alert(ZeroStyle.FrameWork.RunningTime.CurrentLanguage);
	document.title=JoveTech.VVSWeb.Language.Text.PageTitle;
	ZeroStyle.VVSWeb.API.Init();
	try
	{
		ZeroStyle.VVSWeb.API.Login("cuiliang","123456","zh_cn");
	}
	catch(e)
	{
		ZeroStyle.Web.UI.Helper.display("divSetupCOM")
	}

	var html=ZeroStyle.Web.UI.Helper.$("loginDiv").innerHTML;
	ZeroStyle.Web.UI.Helper.$remove("loginDiv");
	JoveTech.VVSWeb.Function.LoginShield(html);
	var userName=ZeroStyle.Web.UI.Helper.getCookie("userName");
	if(userName){ZeroStyle.Web.UI.Helper.$v("txtUserName",userName)}
	
}



window.onunload=function()
{
	try
	{
	ZeroStyle.VVSWeb.API.DisConnectAll();
	ZeroStyle.VVSWeb.API.Exit();
	}
	catch(e)
	{
		
	}

}

document.onkeydown=function(e)
{
	try
	{
		if(!ZeroStyle.Web.UI.Helper.$("btnLogin"))
		{
			return ;
		}
		if(window.event) // IE   
	    {   
			keynum = event.keyCode;
			 
	    }   
		else if(e.which) // Netscape/Firefox/Opera   
	    {   
	    	keynum = e.which;
			   
	    } 
		if(keynum==13)
		{
			JoveTech.VVSWeb.Function.Login(ZeroStyle.Web.UI.Helper.$("btnLogin"));
		}   
	}
	catch(err)
	{}


}


window.onerror=function(e)
{
	alert(e.message);
}
