// JavaScript Document var m_Http = "http://"; var m_HostName = location.hostname; //获取当前地址栏主机名 var m_HttpPort = location.port || "80"; var m_RtspPort = 554; var m_cyUserPwdValue = ""; var g_iSaveResTimer = 0; //保存结果清空timer的索引 var m_cyReInfo = ""; var iePlugVersion = "2.1.50.7278"; //插件版本 var webVersion = "19.12.04.7576"; //web版本 var streamCount = 2; var deviceCap = {}; m_Http = location.protocol + "//"; //获取当前地址栏协议 if (location.port != "") { m_HttpPort = location.port; //获取当前地址样端口 } var userAgent = navigator.userAgent.toLowerCase(); //取得浏览器的userAgent字符串 var g_bIsIE = !(/(msie\s|trident.*rv:)([\w.]+)/.exec(navigator.userAgent.toLowerCase()) == null); var isChrome = userAgent.indexOf("chrome") > -1 && userAgent.indexOf("safari") > -1; //判断Chrome浏览器 var chromeVer = (userAgent.match(/chrome\/([\d.]+)/)) ? userAgent.match(/chrome\/([\d.]+)/)[1] : " "; var isFF = userAgent.indexOf("firefox") > -1; //判断是否Firefox浏览器 var firefoxVer = (userAgent.match(/firefox\/([\d.]+)/)) ? userAgent.match(/firefox\/([\d.]+)/)[1] : " "; var isSafari = userAgent.indexOf("safari") > -1; //判断是否Safari浏览器 var safariVer = (userAgent.match(/version\/([\d.]+)/)) ? userAgent.match(/version\/([\d.]+)/)[1] : " "; var ie8 = navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/8./i)=="8."; /************************************************* Function: SaveState Description: 保存后返回的状态 Input: xhr XMLHttpRequest 对象 Output: 无 return: 无 *************************************************/ function SaveState(xhr,type) { var xml = xhr.responseXML; var state = $(xml).find('statusCode').eq(0).text(); if ("0" === state) { switch (type){ //保存 case 0: m_cyReInfo = $.i18n.prop("i18n-save-success"); break; //切换wifi模式 case 1: m_cyReInfo = $.i18n.prop("i18n-switch-wifi-success"); break; //测试email case 2: m_cyReInfo = $.i18n.prop("i18n-test-email-success"); break; //测试ftp case 3: m_cyReInfo = $.i18n.prop("i18n-test-ftp-success"); break; //重启 case 4: m_cyReInfo = $.i18n.prop("i18n-reboot-success"); break; default: m_cyReInfo = $.i18n.prop("i18n-save-success"); break } } else { switch (type){ case 0: m_cyReInfo = $.i18n.prop("i18n-save-failed"); break; case 1: m_cyReInfo = $.i18n.prop("i18n-switch-wifi-failed"); break; case 2: m_cyReInfo = $.i18n.prop("i18n-test-email-failed"); break; case 3: m_cyReInfo = $.i18n.prop("i18n-test-ftp-failed"); break; case 4: m_cyReInfo = $.i18n.prop("i18n-reboot-failed"); break; default: m_cyReInfo = $.i18n.prop("i18n-save-failed"); break } } $("#saveTip").html(m_cyReInfo); $("#saveTip").fadeIn(1000); if (0 !== g_iSaveResTimer) { clearTimeout(g_iSaveResTimer); } //3秒后自动清除 g_iSaveResTimer = setTimeout(function () { $("#saveTip").fadeOut(1000); $("#saveTip").html(""); }, 3000); } /************************************************* Function: Logout Description: 注销用户 Input: 无 Output: 无 return: 无 *************************************************/ function Logout() { clearTimeout(gs_interval); $.cookie('userInfo', null); $.cookie('commandPort', null); $.cookie('strem', null); $.cookie('rtspPort', null); m_cyUserPwdValue = ""; window.location.href = "/"; } /************************************************* Function: Base64 Description: Base64编码解码 Input: 无 Output: 无 return: 无 *************************************************/ var Base64 = { // private property _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", // public method for encoding encode: function (input) { var output = ""; var chr1, chr2, chr3, enc1, enc2, enc3, enc4; var i = 0; input = Base64._utf8_encode(input); while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4); } return output; }, // public method for decoding decode: function (input) { var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (i < input.length) { enc1 = this._keyStr.indexOf(input.charAt(i++)); enc2 = this._keyStr.indexOf(input.charAt(i++)); enc3 = this._keyStr.indexOf(input.charAt(i++)); enc4 = this._keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } } output = Base64._utf8_decode(output); return output; }, // private method for UTF-8 encoding _utf8_encode: function (string) { string = string.replace(/\r\n/g, "\n"); var utftext = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { utftext += String.fromCharCode(c); } else if ((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); } } return utftext; }, // private method for UTF-8 decoding _utf8_decode: function (utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0; while (i < utftext.length) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if ((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i + 1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i + 1); c3 = utftext.charCodeAt(i + 2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; } }; /************************************************* Function: showMsg Description: 错误信息提示 *************************************************/ function showMsg(msg, cyID) { $("#" + cyID).html(msg); $("#" + cyID).fadeIn(1000); if (0 != g_iSaveResTimer) { clearTimeout(g_iSaveResTimer); } //3秒后自动清除 g_iSaveResTimer = setTimeout(function () { $("#" + cyID).fadeOut(1000); $("#" + cyID).html(""); }, 3000); } /********************************** 功能: 计算字符串的长度 参数: szString: 输入的字符串 ***********************************/ function strlen(str) { var len = 0; for (var i = 0; i < str.length; i++) { var c = str.charCodeAt(i); //单字节加1 if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) { len++; } else { len += 2; } } return len; } function checkStr(str) { var string = /[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/; if (string.test(str)) { return true } else { return false } } /************************************************* Function: CheckKeyDown Description: 输入时按下空格时,不允许输入 Input: iSetValue: 需要验证的值 Output: 无 return: 无 *************************************************/ function CheckKeyDown(event) { event = event ? event : (window.event ? window.event : null); if (event.keyCode == 32) { if (navigator.appName == "Netscape" || navigator.appName == "Opera") { event.preventDefault(); } else { event.returnValue = false; //非ie浏览器event无returnValue属性 } return; } } /************************************************* Function: checkVal Description: 检测端口值 **************************************************/ function checkVal(tipsId) { if ($("#" + tipsId).val() > 65535) { $("#" + tipsId).val(65535); } if ($("#" + tipsId).val() < 1) { $("#" + tipsId).val(1); } } /************************************************* Function: execI18n Description: 翻译页面语言 **************************************************/ function execI18n(lang) { jQuery.i18n.properties({ name: 'message', path: 'i18n/', //资源文件路径 mode: 'map', //用Map的方式使用资源文件中的值 language: lang, callback: function () {//加载成功后设置显示内容 //初始化页面元素 $('[data-i18n-text]').each(function () { $(this).text($.i18n.prop($(this).data('i18n-text'))); }); $('[data-i18n-title]').each(function () { $(this).attr("title", $.i18n.prop($(this).data('i18n-title'))); }); } }); } /********************************** 功能: 计算字符串的长度 参数: 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 } /************************************************* Function: parseXmlFromStr Description: 从xml字符串中解析xml Input: szXml xml字符串 Output: 无 return: xml文档 *************************************************/ function parseXmlFromStr(szXml) { if (null == szXml || '' === szXml) { return null; } var xmlDoc = new createxmlDoc(); if (g_bIsIE) {// IE xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = "false"; xmlDoc.loadXML(szXml); } else {// Other var parser = new DOMParser(); xmlDoc = parser.parseFromString(szXml, "text/xml"); } return xmlDoc; } /************************************************* Function: createxmlDoc Description: 创建xml DOM对象 Input: 无 Output: 无 return: 无 *************************************************/ function createxmlDoc() { var xmlDoc; var aVersions = ["MSXML2.DOMDocument", "MSXML2.DOMDocument.5.0", "MSXML2.DOMDocument.4.0", "MSXML2.DOMDocument.3.0", "Microsoft.XmlDom"]; for (var i = 0; i < aVersions.length; i++) { try { xmlDoc = new ActiveXObject(aVersions[i]); break; } catch (oError) { xmlDoc = document.implementation.createDocument("", "", null); break; } } xmlDoc.async = "false"; return xmlDoc; } /************************************************* Function: getDeviceCap Description: 获取设备能力 Input: 无 Output: 无 return: 无 *************************************************/ function getDeviceCap() { $.ajax({ url: m_Http + m_HostName + ":" + m_HttpPort + "/System/DeviceCap", type: "GET", async: false, timeout: 15000, beforeSend: function (xhr) { xhr.setRequestHeader("If-Modified-Since", "0"); }, success: function (xmlDoc) { /* 与通道无关的功能 */ deviceCap.streamCount = parseInt($(xmlDoc).find('StreamCount').text()); //支持的码流个数 deviceCap.alarmoutCount = parseInt($(xmlDoc).find('AlarmOutCount').text()); //报警输出个数 deviceCap.alarminCount = parseInt($(xmlDoc).find('AlarmInCount').text()); //报警输入个数 deviceCap.diskEnable = $(xmlDoc).find('SD').text().toLowerCase(); //是否支持SD卡 deviceCap.wifiEnable = $(xmlDoc).find('WIFI').text().toLowerCase(); //是否支持wifi if(deviceCap.wifiEnable === "true"){ $("#net_wifi").show(); } deviceCap.intercomEnable = $(xmlDoc).find('TwoWayAudio').text().toLowerCase(); //是否支持对讲 deviceCap.apEnable = $(xmlDoc).find('AP').text().toLowerCase(); //是否支持AP模式 deviceCap.wavelinkEnable = $(xmlDoc).find('Wavelink').text().toLowerCase(); deviceCap.smartlinkEnable = $(xmlDoc).find('Smartlink').text().toLowerCase(); deviceCap.emailEnable = $(xmlDoc).find('Email').text().toLowerCase(); //是否支持Email deviceCap.ftpEnable = $(xmlDoc).find('FTP').text().toLowerCase(); //是否支持FTP deviceCap.remoteEnable = $(xmlDoc).find('RemoteReboot').text().toLowerCase(); //是否支持远程重启 deviceCap.restoreEnable = $(xmlDoc).find('Restore').text().toLowerCase(); //是否支持恢复出厂设置 deviceCap.modifyPasswordEnable = $(xmlDoc).find('PasswordModify').text().toLowerCase(); //是否支持修改密码 deviceCap.autoIPEnable = $(xmlDoc).find('AutoIP').text().toLowerCase(); //是否支持自适应IP deviceCap.audioAlarm = $(xmlDoc).find('AudioAlarm').text().toLowerCase(); //是否支持声音报警 deviceCap.AlarmOutCount=$(xmlDoc).find('Device').eq(0).find("AlarmOutCount").eq(0).text() if(deviceCap.audioAlarm === "true"){ $("#arm_voice").show(); } deviceCap.timeSnapshot = $(xmlDoc).find('TimeSnapshot').text().toLowerCase(); //是否支持定时抓图 deviceCap.snapshotEnable = $(xmlDoc).find('Snapshot').text().toLowerCase(); //是否支持抓图配置 if(deviceCap.snapshotEnable === "true"){ $("#code_capture").show(); } deviceCap.paramFixedEnable = $(xmlDoc).find('ParamFixed').text().toLowerCase(); //是否支持参数固化 if(deviceCap.paramFixedEnable === "true"){ $("#sys_config").show(); } /* 与通道有关的功能 */ deviceCap.rtmpEnable = $(xmlDoc).find('RTMP').text().toLowerCase(); //是否支持RTMP if(deviceCap.rtmpEnable === "true"){ $("#net_rtmp").show(); } deviceCap.audioEnable = $(xmlDoc).find('Audio').text().toLowerCase(); //是否支持音频 deviceCap.motionEnable = $(xmlDoc).find('Motion').text().toLowerCase(); //是否支持移动侦测 deviceCap.colorNightEnable = $(xmlDoc).find('ColorNight').text().toLowerCase(); //是否支持全彩白光 deviceCap.intelligentNightEnable = $(xmlDoc).find('IntelligentNight').text().toLowerCase(); //是否支持智能双光 deviceCap.aviEnabel = $(xmlDoc).find('AVI').text().toLowerCase(); //是否支持AVI deviceCap.prvEnabel = $(xmlDoc).find('PRV').text().toLowerCase(); //是否支持PRV deviceCap.highestEnable = $(xmlDoc).find('Highest').text().toLowerCase(); //移动侦测灵敏度等级,是否支持多个等级(最高-高-中-低-最低) deviceCap.higherEnable = $(xmlDoc).find('Higher').text().toLowerCase(); //移动侦测灵敏度等级,是否支持多个等级(最高-较高-高-中-低-较低-最低) deviceCap.multiEnable = $(xmlDoc).find('multi_osd').text().toLowerCase(); //是否支持多行OSD deviceCap.mosd_cnt = $(xmlDoc).find('mosd_cnt').text().toLowerCase(); //支持的多行OSD具体个数 deviceCap.mosd_cord = $(xmlDoc).find('mosd_cord').text().toLowerCase(); deviceCap.variableInfrared = $(xmlDoc).find('VariableInfrared').text().toLowerCase(); //是否支持无极红外 deviceCap.variableWhite = $(xmlDoc).find('VariableWhite').text().toLowerCase(); //是否支持无极白光 deviceCap.imageMode = $(xmlDoc).find('ImageMode').attr("enable") ? $(xmlDoc).find('ImageMode').attr("enable").toLowerCase() : $(xmlDoc).find('ImageMode').attr("enable"); //是否支持图像模式 deviceCap.normal = $(xmlDoc).find('Normal').text().toLowerCase(); //是否支持标准模式 deviceCap.faceNoExposure = $(xmlDoc).find('FaceNoExposure').text().toLowerCase(); //是否支持人脸无曝光 deviceCap.licensePlate = $(xmlDoc).find('LicensePlate').text().toLowerCase(); //是否支持车牌模式 deviceCap.ptzCruise = $(xmlDoc).find('PTZ_Advance_Cruise').text().toLowerCase(); //是否支持高级巡航功能 deviceCap.ptzWatch = $(xmlDoc).find('PTZ_Advance_Watch').text().toLowerCase(); //是否支持高级守望功能 deviceCap.peopleDetect = $(xmlDoc).find('PeopleDetect').text().toLowerCase(); //是否支持人形检测 deviceCap.ai265 = $(xmlDoc).find('Ai265Plus').text().toLowerCase(); //是否支持ai265跟aiface deviceCap.aiface = $(xmlDoc).find('AiFace').text().toLowerCase(); if(deviceCap.peopleDetect === "true"){ $("#arm_detect").show(); }; deviceCap.mobeil = $(xmlDoc).find('_4G').text().toLowerCase();//是否支持4g页面 if(deviceCap.mobeil === "true"){ $("#net_mobile").show(); }else{ $("#net_mobile").hide(); } }, error: function (xhr) { } }) } function getParameter(callback,url,flag) { $.ajax({ url:url, type:"GET", async:false, timeout: 15000, beforeSend: function(xhr) { xhr.setRequestHeader("If-Modified-Since", "0"); }, success:function(xml,xhr){ callback(xml,xhr); }, error:function (xhr) { } }) } function setParameter(callback,url,type,xml,flag,nFlag){ $.ajax({ url:url, type:type, async:true, data:xml, processData: false, timeout: 15000, complete:function(xhr){ if(flag === 1){ callback(xhr,nFlag) } }, success:function(xhr){ if(flag === 0){ callback(xhr,nFlag) } }, error:function (xhr) { } }) } function browserRedirect() { var sUserAgent = navigator.userAgent.toLowerCase(); var bIsIpad = sUserAgent.match(/ipad/i) == "ipad"; var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os"; var bIsMidp = sUserAgent.match(/midp/i) == "midp"; var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4"; var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb"; var bIsAndroid = sUserAgent.match(/android/i) == "android"; var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce"; var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile"; if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) { return false } else { return true } } function IsPC() { var userAgentInfo = navigator.userAgent; var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"]; var flag = true; for (var v = 0; v < Agents.length; v++) { if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; } } return flag; } function getStreamCount(){ $.ajax({ url: m_Http + m_HostName + ":" + m_HttpPort + "/DeviceCapTable.ini", type: "GET", timeout: 15000, beforeSend: function (xhr) { xhr.setRequestHeader("If-Modified-Since", "0"); }, success: function (xmlDoc) { streamCount = parseInt(xmlDoc.toString().split("StreamTypeCount=")[1]); if(streamCount === 3){ $("").appendTo("#streamList"); $("#third-stream").show(); } } }) }