{% load i18n %}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="{{ LANGUAGE_CODE }}" xml:lang="{{ LANGUAGE_CODE }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}><head>
    {% include "site_medias_js.html" %}
    <script type="text/javascript">
    var user_id=-1
    function get_query_string(sprop) 
    {
        var re = new RegExp("[&,?]"+sprop + "=([^\\&]*)", "i");
        var a = re.exec(document.location.search);   
        if (a == null) return ""; 
        return a[1];
    }
    function set_video_state(curch)
    {
        var k=window.dialogArguments; 
        var video_state=k.document.getElementById("id_video_state").value; 
        video_state=video_state.substr(0,curch)+'0'+video_state.substr(curch+1,video_state.length-1-curch);
        k.document.getElementById("id_video_state").value=video_state
        window.returnValue=video_state; 
        window.close(); 
    }
    function get_link_num(xml_str,curch) //获取硬盘录像机当前通道的已连接个数
    {
        var members = 0;
        //var maxRes = 0;

        if(!window.DOMParser && window.ActiveXObject){
            var xml_dom_versions = ['MSXML.2.DOMDocument.6.0','MSXML.2.DOMDocument.3.0','Microsoft.XMLDOM'];
            for(var i=0;i<xml_dom_versions.length;i++){
                try //Internet Explorer
                {
                      xmlDoc=new ActiveXObject(xml_dom_versions[i]);
                      xmlDoc.async="false";
                      xmlDoc.loadXML(xml_str);
                }
                catch(e)
                {
                    
                }
            }
        }
        else if (window.DOMParser && document.implementation && document.implementation.createDocument)
        {
            try{
                domParser = new DOMParser();
                xmlDoc = domParser.parseFromString(xml_str, 'text/xml');
            }
            catch(e)
            {
            }
        }
        else{   
        }
        
        if(xmlDoc==null){
            alert(gettext("解析xml文件出错"));
        }
        members= xmlDoc.getElementsByTagName("ChannelState");
        var cur_link_num = members[curch].getElementsByTagName("LinkNum")[0].firstChild.nodeValue;
        return cur_link_num;
        
    }
    
    window.onload = function() { 
        var vid_ip = get_query_string("vid_ip");
        var vid_port = get_query_string("vid_port");
        var vid_login = get_query_string("vid_login");
        var vid_pwd = get_query_string("vid_pwd");
        var vid_ch = get_query_string("vid_ch");
        var netocx1 = document.getElementById("NetOCX1");
        user_id = netocx1.Login(vid_ip, vid_port, vid_login, vid_pwd);
        var str = netocx1.GetServerWorkState();
        var cur_link_num = get_link_num(str,vid_ch);
        if(cur_link_num < '6'){
            var i=0 
            netocx1.StartRealPlay(vid_ch, 0, 0);
        }
        else{
            alert(gettext('该通道已达最大访问量！'));
        }
    
    }
    window.onbeforeunload = function()  {
        document.getElementById("NetOCX1").logout();
        var vid_ch = get_query_string("vid_ch");
        set_video_state(vid_ch);
    }
        
    </script>    
</head>
<body class="indexBody">
<table>
<tr>
  <td align="center"><object classid="clsid:CAFCF48D-8E34-4490-8154-026191D73924" codebase="/media/ActiveX/NetVideoActiveX23.cab#version=2,3,9,1"
  standby="Waiting..." id="NetOCX1" width="400" height="300" name="ocx1" align="center" >
  </object>
  </td>
</tr>
</table>
</body>
</html>
