// JavaScript Document document.charset = "utf-8"; var streamlist; //getDeviceCap(); htmlobj=$.ajax({ url:"../DeviceCapTable.ini", async:false, error: function (xhr){ if(xhr.status == 404){ streamlist = [ {stream:str_vs_main, value :"1"}, {stream:str_vs_sub, value:"4"} ]; } } }); var StreamCount=parseInt(htmlobj.responseText.split("=")[1]); if(StreamCount=="1"){ streamlist = [ {stream:str_vs_main, value :"1"} ]; }else if(StreamCount=="2"){ streamlist = [ {stream:str_vs_main, value :"1"}, {stream:str_vs_sub, value:"4"} ]; }else if(StreamCount=="3"){ streamlist = [ {stream:str_vs_main, value :"1"}, {stream:str_vs_sub, value:"4"}, {stream:str_vs_mo, value:"5"} ]; } /********************************** 功能: 登陆 ***********************************/ function Login() { //用户名为空时提示 if ($('#username').val().length == 0) { $('#username').focus(); errorMsg(str_if_user,"umsg"); return false } if (JudgeTextLength($('#username').val()) > 32) { $('#username').focus(); $('#username').val(''); errorMsg(str_if_user_len,"umsg"); return false; } if (JudgeTextLength($('#passwd').val()) > 16) { $('#passwd').focus(); $('#passwd').val(''); errorMsg(str_if_pwd_len,"umsg"); return false; } var cyDate = 'Username=' + $('#username').val() + '&Password=' + $('#passwd').val(); $.ajax({ url:m_Http + m_HostName + ":" + m_HttpPort + "/Security/UserAuth", type:"PUT", timeout: 15000, data:cyDate, beforeSend: function (xhr) { xhr.setRequestHeader("If-Modified-Since", "0"); }, success:function (xmlDoc, textStatus, xhr){ var statusflg = $(xmlDoc).find('ResponseStatus').eq(0).find('statusCode').eq(0).text(); if (0 == statusflg){//成功登陆 loginLoad(); } else if (-17 == statusflg){//密码出错 errorMsg(str_if_uperror,"umsg"); } else if ("401" != xhr.status){//其它异常 if ("timeout" == textStatus) {//连接超时 errorMsg(str_if_nouttime,"umsg"); } else {//网络异常 errorMsg(str_if_abnormal,"umsg"); } } }, error:function (xhr, textStatus, errorThrown) { if ("401" != xhr.status){ if ("timeout" == textStatus) { errorMsg(str_if_nouttime,"umsg"); } else { errorMsg(str_if_abnormal,"umsg"); } } } }); } /************************************************* Function: loginLoad Description: 初始化登陆数据 **************************************************/ function loginLoad(){ $.ajax({ url:m_Http + m_HostName + ":" + m_HttpPort + "/Network/Port", type:"GET", username:$('#username').val(), password:$('#passwd').val(), timeout: 15000, beforeSend: function (xhr) { xhr.setRequestHeader("If-Modified-Since", "0"); xhr.setRequestHeader("Cache-Control:no-cache","must-revalidate"); xhr.setRequestHeader("keep-alive","timeout=0, max=1000"); }, success:function (xmlDoc, textStatus, xhr) { m_cyUserPwdValue = Base64.encode($('#username').val() + ":" + $('#passwd').val()); $.cookie('userInfo', m_cyUserPwdValue); for(var i = 0;i < streamlist.length;i++){ if($("#streamlist").val() == streamlist[i].stream){ var streamvalue = streamlist[i].value; } } $.cookie('strem', streamvalue); $.cookie('commandPort',$(xmlDoc).find('Port').eq(0).find('Command').eq(0).text()); $.cookie('rtspPort',$(xmlDoc).find('Port').eq(0).find('RTP').eq(0).text()); window.location.href = "main.html"; }, error:function (xhr, textStatus, errorThrown) { if ("401" != xhr.status){ if ("timeout" == textStatus) { errorMsg(str_if_nouttime,"umsg"); } else { errorMsg(str_if_abnormal,"umsg"); } } else{ errorMsg(str_if_uperror,"umsg"); } } }); } /********************************** 功能: 计算字符串的长度 参数: szString: 输入的字符串 ***********************************/ function JudgeTextLength(szString) { var iLength = 0; for (var i = 0; i < szString.length; i++) { if (szString.charCodeAt(i) > 255) { iLength += 2; } else { iLength += 1; } } return iLength } /********************************** 功能: 按回车键登录 ***********************************/ document.onkeydown = function (event) { event = event ? event : (window.event ? window.event : null); if (event.keyCode == 13) { Login() }; }; function getDeviceCap() { $.ajax({ url: m_Http + m_HostName + ":" + m_HttpPort + "/System/DeviceCap", type: "GET", async: false, username:$('#username').val(), password:$('#passwd').val(), timeout: 15000, beforeSend: function (xhr) { xhr.setRequestHeader("If-Modified-Since", "0"); }, success: function (xmlDoc) { StreamCount=$(xmlDoc).find("StreamCount").eq(0).text(); }, error: function (xhr, textStatus, errorThrown) { } }); };