/* | |
*Login Variables | |
*/ | |
var AuthQop,username="",passwd="",GnCount=1,Authrealm,Gnonce,nonce; | |
var _resetTimeOut=600000; | |
var authHeaderIntervalID = 0; | |
/* | |
* clear the Authheader from the coockies | |
*/ | |
function clearAuthheader() { | |
//clearing coockies | |
Authheader = ""; | |
AuthQop = ""; | |
username = ""; | |
passwd = ""; | |
GnCount = ""; | |
Authrealm = ""; | |
//window.location.reload(); | |
window.location="index.html"; | |
} | |
/* | |
* Reset the authHeader | |
*/ | |
function resetInterval() { | |
if(authHeaderIntervalID > 0) | |
clearInterval(authHeaderIntervalID); | |
authHeaderIntervalID = setInterval( "clearAuthheader()", _resetTimeOut); | |
} | |
/* | |
* Check the login responce as the 200 OK or not. | |
*/ | |
function login_done(urlData) { | |
if(urlData.indexOf("200 OK") != -1 ) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
function getValue(authstr) { | |
var arr=authstr.split("="); | |
return arr[1].substring(1,arr[1].indexOf('\"',2) ); | |
} | |
/* | |
* as name suggest it is function which does the authentication | |
* and put the AuthHeader in the Cookies. Uses Digest Auth method | |
*/ | |
function doLogin(username1,passwd1) { | |
var url = window.location.protocol + "//" + window.location.host + "/login.cgi"; | |
var loginParam = getAuthType(url); | |
//alert(loginParam); | |
if(loginParam!=null) { | |
var loginParamArray = loginParam.split(" "); | |
if(loginParamArray[0] =="Digest") { | |
//nonce="718337c309eacc5dc1d2558936225417", qop="auth" | |
Authrealm = getValue(loginParamArray[1]); | |
nonce = getValue(loginParamArray[2]); | |
AuthQop = getValue(loginParamArray[3]); | |
// alert("nonce :" + nonce); | |
// alert("AuthQop :" + AuthQop); | |
// alert("Authrealm :" + Authrealm); | |
username = username1; | |
passwd = passwd1; | |
var rand, date, salt, strResponse; | |
Gnonce = nonce; | |
var tmp, DigestRes; | |
var HA1, HA2; | |
HA1 = hex_md5(username+ ":" + Authrealm + ":" + passwd); | |
HA2 = hex_md5("GET" + ":" + "/cgi/xml_action.cgi"); | |
rand = Math.floor(Math.random()*100001) | |
date = new Date().getTime(); | |
salt = rand+""+date; | |
tmp = hex_md5(salt); | |
AuthCnonce = tmp.substring(0,16); | |
var strhex = hex(GnCount); | |
var temp = "0000000000" + strhex; | |
var Authcount = temp.substring(temp.length-8); | |
DigestRes = hex_md5(HA1 + ":" + nonce + ":" + Authcount + ":" + AuthCnonce + ":" + AuthQop + ":" + HA2); | |
url = window.location.protocol + "//" + window.location.host + "/login.cgi?Action=Digest&username="+username+"&realm="+Authrealm+"&nonce="+nonce+"&response="+DigestRes+"&qop="+AuthQop+"&cnonce="+AuthCnonce + "&nc="+Authcount+"&temp=marvell"; | |
if(login_done(authentication(url))) { | |
strResponse = "Digest username=\"" + username + "\", realm=\"" + Authrealm + "\", nonce=\"" + nonce + "\", uri=\"" + "/cgi/protected.cgi" + "\", response=\"" + DigestRes + "\", qop=" + AuthQop + ", nc=00000001" + ", cnonce=\"" + AuthCnonce + "\"" ; | |
return 1; | |
} else { | |
// show error message... | |
return 0; | |
} | |
return strResponse; | |
} | |
} | |
return -1; | |
} | |
function getAuthHeader(requestType,file) { | |
var rand, date, salt, strAuthHeader; | |
var tmp, DigestRes,AuthCnonce_f; | |
var HA1, HA2; | |
HA1 = hex_md5(username+ ":" + Authrealm + ":" + passwd); | |
HA2 = hex_md5( requestType + ":" + "/cgi/xml_action.cgi"); | |
rand = Math.floor(Math.random()*100001) | |
date = new Date().getTime(); | |
salt = rand+""+date; | |
tmp = hex_md5(salt); | |
AuthCnonce_f = tmp.substring(0,16); | |
//AuthCnonce_f = tmp; | |
var strhex = hex(GnCount); | |
var temp = "0000000000" + strhex; | |
var Authcount = temp.substring(temp.length-8); | |
DigestRes =hex_md5(HA1 + ":" + nonce + ":" + Authcount + ":" + AuthCnonce_f + ":" + AuthQop + ":"+ HA2); | |
GnCount++; | |
strAuthHeader = "Digest " + "username=\"" + username + "\", realm=\"" + Authrealm + "\", nonce=\"" + nonce + "\", uri=\"" + "/cgi/xml_action.cgi" + "\", response=\"" + DigestRes + "\", qop=" + AuthQop + ", nc=" + Authcount + ", cnonce=\"" + AuthCnonce_f + "\"" ; | |
DigestHeader = strAuthHeader ; | |
return strAuthHeader; | |
} | |
function logOut() { | |
var host = window.location.protocol + "//" + window.location.host + "/"; | |
var url = host+'xml_action.cgi?Action=logout'; | |
$.ajax( { | |
type: "GET", | |
url: url, | |
dataType: "html", | |
async:false, | |
complete: function() { | |
clearAuthheader(); | |
} | |
}); | |
} | |
function getHeader (AuthMethod , file) { | |
var rand, date, salt, setResponse; | |
var tmp, DigestRes,AuthCnonce_f; | |
var HA1, HA2; | |
HA1 = hex_md5(username + ":" + Authrealm + ":" + passwd); | |
HA2 = hex_md5(AuthMethod + ":" + "/cgi/xml_action.cgi"); | |
/*Generate random sequence for Cnonce*/ | |
// Integer random = new Integer(Random.nextInt(2097152)); | |
// Integer date = new Integer((int)(System.currentTimeMillis() + 24)); | |
rand = Math.floor(); | |
date = new Date().getTime(); | |
salt = rand+""+date; | |
tmp = hex_md5(salt); | |
AuthCnonce = tmp.substring(0,16); | |
AuthCnonce_f = tmp; | |
var strhex = hex(GnCount); | |
var temp = "0000000000" + strhex; | |
var Authcount = temp.substring(temp.length-8); | |
DigestRes =hex_md5(HA1 + ":" + Gnonce + ":" + Authcount + ":" + AuthCnonce_f + ":" + AuthQop + ":"+ HA2); | |
++GnCount; | |
if("GET" == AuthMethod) { | |
if("upgrade" == file) { | |
//setResponse = "/login.cgi?Action=Upload&file=" + file + "&username=" + username + "&realm=" + Authrealm + "&nonce=" + Gnonce + "&response=" + DigestRes + "&cnonce=" + AuthCnonce_f + "&nc=" + Authcount + "&qop=" + AuthQop + "&temp=marvell"; | |
setResponse= "/xml_action.cgi?Action=Upload&file=upgrade&command=" | |
} else if("config_backup" == file) { | |
setResponse= "/xml_action.cgi?Action=Upload&file=backfile&config_backup=" | |
} else { | |
setResponse = "/login.cgi?Action=Download&file=" + file + "&username=" + username + "&realm=" + Authrealm + "&nonce=" + Gnonce + "&response=" + DigestRes + "&cnonce=" + AuthCnonce_f + "&nc=" + Authcount + "&qop=" + AuthQop + "&temp=marvell"; | |
} | |
} | |
if("POST"==AuthMethod) { | |
setResponse = "/login.cgi?Action=Upload&file=" + file + "&username=" + username + "&realm=" + Authrealm + "&nonce=" + Gnonce + "&response=" + DigestRes + "&cnonce=" + AuthCnonce_f + "&nc=" + Authcount + "&qop=" + AuthQop + "&temp=marvell"; | |
} | |
return setResponse; | |
} | |
/* | |
* return the cookie parameter is Coockie name | |
*/ | |
function GetCookie(c_name) { | |
if (document.cookie.length>0) { | |
c_start=document.cookie.indexOf(c_name + "="); | |
if (c_start!=-1) { | |
c_start=c_start + c_name.length+1; | |
c_end=document.cookie.indexOf(";",c_start); | |
if (c_end==-1) c_end=document.cookie.length; | |
return unescape(document.cookie.substring(c_start,c_end)); | |
} | |
} | |
return ""; | |
} | |
/* | |
* set cookie of browser it has expiry days after which it expires | |
*/ | |
function SetCookie(c_name,value,expiredays) { | |
var exdate=new Date(); | |
exdate.setDate(exdate.getDate()+expiredays); | |
document.cookie=c_name+ "=" +escape(value)+ | |
((expiredays==null) ? "" : ";expires="+exdate.toGMTString()); | |
} | |
function ElementLocaliztion(pElementArray) { | |
for(var i=0; i<pElementArray.length; i++) { | |
if(jQuery.i18n.prop(pElementArray[i].id)!=null) | |
document.getElementById(pElementArray[i].id).innerHTML = jQuery.i18n.prop(pElementArray[i].id); | |
} | |
} | |
function LocalElementById(elementId) { | |
if("input" == document.getElementById(elementId).tagName.toLowerCase()) { | |
document.getElementById(elementId).value = jQuery.i18n.prop(elementId); | |
} else { | |
document.getElementById(elementId).innerHTML = jQuery.i18n.prop(elementId); | |
} | |
} | |
function LocalElementByTagName(elementTagName) { | |
if("button" == elementTagName) { | |
$(":button").each(function() { | |
$(this).val(jQuery.i18n.prop($(this).attr("id"))) | |
}) | |
} else { | |
$(elementTagName).each(function() { | |
$(this).text(jQuery.i18n.prop($(this).attr("id"))) | |
}) | |
} | |
} | |
function LocalAllElement(){ | |
$("[id^='lt_']").each(function() { | |
if("input" == document.getElementById($(this).attr("id")).tagName.toLowerCase()) { | |
$(this).val(jQuery.i18n.prop($(this).attr("id"))); | |
}else{ | |
$(this).text(jQuery.i18n.prop($(this).attr("id"))); | |
} | |
}); | |
} | |
function hex(d) { | |
var hD="0123456789ABCDEF"; | |
var h = hD.substr(d&15,1); | |
while(d>15) { | |
d>>=4; | |
h=hD.substr(d&15,1)+h; | |
} | |
return h; | |
} | |
function clearTabaleRows(tableId) { | |
var i=document.getElementById(tableId).rows.length; | |
while(i!=1) { | |
document.getElementById(tableId).deleteRow(i-1); | |
i--; | |
} | |
} | |
/* Converts timezone offset expressed in minutes to string */ | |
function GetMachineTimezoneGmtOffsetStr(tzGmtOffset ) { | |
var gmtOffsetStr =""+ getAbsValue(tzGmtOffset/60); | |
var tempInt = tzGmtOffset; | |
if(tempInt < 0) { | |
tempInt = 0 - tempInt; | |
} | |
if(( tempInt % 60 ) != 0 ) { | |
gmtOffsetStr += ":" + ( tempInt % 60 ); | |
} | |
//new XDialog("Error","gmt offset" + gmtOffsetStr ).alert(); | |
return gmtOffsetStr; | |
} | |
/* Find out timezone offset settings from connected device. If dst is observed we should see | |
* difference in Jan and July timezone offset.Pick the max one */ | |
function GetMachineTimezoneGmtOffset() { | |
var rightNow = new Date(); | |
var JanuaryFirst= new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0,0); | |
var JulyFirst= new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0,0); | |
var JanOffset,JulyOffset; | |
var tzGmtOffset; | |
JanOffset = JanuaryFirst.getTimezoneOffset(); | |
JulyOffset = JulyFirst.getTimezoneOffset(); | |
if(JulyOffset > JanOffset) { | |
tzGmtOffset= JulyOffset; | |
} else { | |
tzGmtOffset = JanOffset; | |
} | |
return tzGmtOffset; | |
} | |
/* Get the connected device's day light saving settings in string format e.g. M3.5.0 or J81 */ | |
function GetMachineTimezoneDstStartStr(StandardGMToffset) { | |
var rightNow = new Date(); | |
var JanuaryFirst = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0,0); | |
var JulyFirst= new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0,0); | |
var HoursInSixMonths =((JulyFirst.getTime() - JanuaryFirst.getTime()) / (1000 * 60 * 60)); | |
var dstStartStr = ""; | |
var i ; | |
var JanOffset, JulyOffset; | |
var hourStart, hourEnd; | |
/* If there are dst settings to be considered we should get them by checking in 6 months time interval */ | |
JanOffset = JanuaryFirst.getTimezoneOffset(); | |
JulyOffset = JulyFirst.getTimezoneOffset(); | |
if(JanOffset > JulyOffset) { | |
hourStart = 0; | |
hourEnd = HoursInSixMonths; | |
} else { | |
hourStart = HoursInSixMonths; | |
hourEnd = HoursInSixMonths * 2; | |
} | |
var tempDate = getDstStartTime(hourStart,hourEnd, rightNow.getYear(),StandardGMToffset); | |
if(tempDate != null) { | |
/* Dst setting string : M3.5.0 (Month of the year).(Week Of Month).(Day of Week) | |
* So We need to iterate over six months period for few years and find which week of month it is */ | |
var changeWeek = getChangeWeek(hourStart,hourEnd, tempDate.getYear(),StandardGMToffset); | |
switch(changeWeek) { | |
case -1: | |
break; | |
case -2: // Some regions have fixed day for start of dst setting which is expressed with J | |
dstStartStr ="J" + (((tempDate.getTime()-JanuaryFirst.getTime())/(24 * 60 * 60* 1000) ) + 1); | |
break; | |
default: | |
dstStartStr = "M" + (tempDate.getMonth() + 1) + "." + changeWeek + "." + tempDate.getDay(); | |
break; | |
} | |
} | |
return dstStartStr; | |
} | |
function getDstStartTime(hourStart,hourEnd, year,StandardGMToffset) { | |
/* Check at which hour timezone offset is different from standard timezone | |
* offset for that region. Thats the start of dst */ | |
var i; | |
for(i = hourStart; i < hourEnd; i++) { | |
var dSampleDate = new Date(year,0, 1, 0, 0, 0,0); | |
dSampleDate.setHours(i); | |
var CurrentGMToffset = dSampleDate.getTimezoneOffset(); | |
if(CurrentGMToffset < StandardGMToffset) { | |
return dSampleDate; | |
} | |
} | |
return null; | |
} | |
function setConnectedDeviceTimezoneStr(gmtOffset,dstStart,timezoneStringArray) { | |
var i,j; | |
var startIndex = -1; | |
var count = 0; | |
var index = -1; | |
var tempGmtString; | |
var tempDstString; | |
for(j = 0; j < timezoneStringArray[1].length ; j++) { | |
var charArr = toCharArray(timezoneStringArray[1][j]); | |
count = 0; | |
tempGmtString = ""; | |
tempDstString = ""; | |
startIndex = -1; | |
for(i = 0; i < timezoneStringArray[1][j].split(",",3)[0].length; i++) { | |
if(((charArr[i] >= '0') && (charArr[i] <= '9')) ||(charArr[i] == '-') || (charArr[i] == ':')) { | |
count++; | |
if(startIndex == -1) { | |
startIndex = i; | |
} | |
tempGmtString = tempGmtString + charArr[i]; | |
} | |
} | |
if(tempGmtString == gmtOffset) { | |
if(timezoneStringArray[1][j].split(",",3).length > 1) { | |
tempDstString = timezoneStringArray[1][j].split(",",3)[1]; | |
} else { | |
tempDstString = ""; | |
} | |
if((dstStart.length == 0) && (tempDstString.length != 0)) { | |
//new XDialog("Error","gmt offset matched but dst settings did not match!" + dstStart + "__" + tempDstString).alert(); | |
continue; | |
} | |
if(tempDstString.substring(0,dstStart.length) == dstStart) { | |
//new XDialog("Error","Found perfect timezone match with gmt and dst" + timezoneStringArray[1][j]).alert(); | |
index = j; | |
break; | |
} else { | |
//new XDialog("Error","gmt offset matched but dst settings did not match!" + dstStart + "__" + tempDstString).alert(); | |
continue; | |
} | |
} else { | |
//new XDialog("Error","gmt offset did not match!" + tempGmtString + "__" + gmtOffset).alert(); | |
continue; | |
} | |
} | |
if(index == -1) { | |
//new XDialog("Error","Failed to get timezone settings from connected device").alert(); | |
//new XDialog("Error","Failed_ " + gmtOffset +"_" + dstStart).alert(); | |
//GetPCTimeZoneString.setText(""); | |
return -1; | |
} else { | |
//GetPCTimeZoneString.setText(timezoneStringComboBox.getItemText(index)); | |
//timezoneString.setText(timezoneStringArray[1][index]); | |
return index; | |
} | |
} | |
function toCharArray(str) { | |
var charArray = new Array(0); | |
for(var i=0; i<str.length; i++) | |
charArray[i]=str.charAt(i); | |
return charArray; | |
} | |
/* We know the day of month but not the week. We can find day of the month for few years | |
* and guess which week of the month it would be */ | |
function getChangeWeek( hourStart, hourEnd, year, StandardGMToffset) { | |
var i; | |
var min = 32 , max = 0, dom = 0; | |
for(i = year; i < year + 20 ; i++) { | |
dom =(getDstStartTime(hourStart,hourEnd,i,StandardGMToffset)).getDate(); | |
if(dom > max) { | |
max = dom; | |
} | |
if(dom < min) { | |
min = dom; | |
} | |
} | |
if(max == min) { | |
return -1; | |
} | |
/* Some regions have fixed day for start of dst settings. e.g 1 April | |
* We handle it as special case */ | |
if(max - min != 6) { | |
return -2; | |
} | |
//new XDialog("Error","max " + max + "min " + min + " dom " + dom).alert(); | |
return getAbsValue((((max + 6)/7))); | |
} | |
function getAbsValue(i) { | |
return i.toString().split(".")[0]; | |
} | |
function getHelp(helpPage) { | |
if(GetCookie('locale')=='') | |
htmlFilename = "help_en.html"; | |
else | |
htmlFilename = "help_" + GetCookie('locale')+".html"; | |
var host = window.location.protocol + "//" + window.location.host + "/"; | |
var url = host + htmlFilename + "#" + helpPage; | |
var helpWindow = window.open(url, 'newwindow'); | |
helpWindow.focus(); | |
} | |
function getMainHelp() { | |
getHelp(""); | |
} | |
function showAlert(msgLanguageID) { | |
ShowDlg("alertMB",350,150); | |
document.getElementById("lAlertMessage").innerHTML = jQuery.i18n.prop(msgLanguageID); | |
document.getElementById("lAlert").innerHTML = jQuery.i18n.prop("lAlert"); | |
LocalElementById("btnModalOk"); | |
} | |
function UniEncode(string) { | |
if (undefined == string) { | |
return ""; | |
} | |
var code = ""; | |
for (var i = 0; i < string.length; ++i) { | |
var charCode = string.charCodeAt(i).toString(16); | |
var paddingLen = 4 - charCode.length; | |
for (var j = 0; j < paddingLen; ++j) { | |
charCode = "0" + charCode; | |
} | |
code += charCode; | |
} | |
return code; | |
} | |
function GetSmsTime() { | |
var date = new Date(); | |
var fullYear = new String(date.getFullYear()); | |
var year = fullYear.substr(2, fullYear.length - 1); | |
var month = date.getMonth() + 1; | |
var day = date.getDate(); | |
var hour = date.getHours(); | |
var mimute = date.getMinutes(); | |
var second = date.getSeconds(); | |
var timeZone = 0 - date.getTimezoneOffset() / 60; | |
var timeZoneStr = ""; | |
if (timeZone > 0) { | |
timeZoneStr = "%2B" + timeZone; | |
} else { | |
timeZoneStr = "-" + timeZone; | |
} | |
var smsTime = year + "," + month + "," + day + "," + hour + "," + mimute + "," + second + "," + timeZoneStr; | |
return smsTime; | |
} | |
function UniDecode(encodeString) { | |
if (undefined == encodeString) { | |
return ""; | |
} | |
var deCodeStr = ""; | |
var strLen = encodeString.length / 4; | |
for (var idx = 0; idx < strLen; ++idx) { | |
deCodeStr += String.fromCharCode(parseInt(encodeString.substr(idx * 4, 4), 16)); | |
} | |
return deCodeStr; | |
} | |
function showMsgBox(title, message) { | |
ShowDlg("alertMB", 350, 150); | |
document.getElementById("lAlertMessage").innerHTML = message; | |
document.getElementById("lAlert").innerHTML = title; | |
document.getElementById("btnModalOk").value = jQuery.i18n.prop("btnModalOk"); | |
} | |
function GetBrowserType() { | |
var usrAgent = navigator.userAgent; | |
if (navigator.userAgent.indexOf("MSIE") > 0) { | |
var b_version = navigator.appVersion | |
var version = b_version.split(";"); | |
var trim_Version = version[1].replace(/[ ]/g, ""); | |
if (trim_Version == "MSIE6.0") { | |
return "IE6"; | |
} else if(trim_Version == "MSIE7.0") { | |
return "IE7"; | |
} else if (trim_Version == "MSIE8.0") { | |
return "IE8"; | |
} else if (trim_Version == "MSIE9.0") { | |
return "IE9"; | |
} | |
} | |
if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) { | |
return "Firefox"; | |
} | |
if (isSafari = navigator.userAgent.indexOf("Safari") > 0) { | |
return "Safari"; //google | |
} | |
if (isCamino = navigator.userAgent.indexOf("Camino") > 0) { | |
return "Camino"; | |
} | |
if (isMozilla = navigator.userAgent.indexOf("Gecko/") > 0) { | |
return "Gecko"; | |
} | |
} | |
function IsGSM7Code(str) { | |
var len = 0; | |
for( var i = 0; i < str.length; i++) { | |
var chr = str.charCodeAt(i); | |
if(((chr>=0x20&&chr<=0x7f)||0x20AC==chr||0x20AC==chr||0x0c==chr||0x0a==chr||0x0d==chr||0xa1==chr||0xa3==chr||0xa5==chr||0xa7==chr | |
||0xbf==chr||0xc4==chr||0xc5==chr||0xc6==chr||0xc7==chr||0xc9==chr||0xd1==chr||0xd6==chr||0xd8==chr||0xdc==chr||0xdf==chr | |
||0xe0==chr||0xe4==chr||0xe5==chr||0xe6==chr||0xe8==chr||0xe9==chr||0xec==chr||0xf11==chr||0xf2==chr||0xf6==chr||0xf8==chr||0xf9==chr||0xfc==chr | |
||0x3c6==chr||0x3a9==chr||0x3a8==chr||0x3a3==chr||0x3a0==chr||0x39e==chr||0x39b==chr||0x398==chr||0x394==chr||0x393==chr) | |
&& 0x60 != chr) { | |
++len; | |
} | |
} | |
return len == str.length; | |
} | |
function EditHrefs(s_html) { | |
var s_str = new String(s_html); | |
s_str = s_str.replace(/\bhttp\:\/\/www(\.[\w+\.\:\/\_]+)/gi, | |
"http\:\/\/¬¸$1"); | |
s_str = s_str.replace(/\b(http\:\/\/\w+\.[\w+\.\:\/\_]+)/gi, | |
"<a target=\"_blank\" href=\"$1\">$1<\/a>"); | |
s_str = s_str.replace(/\b(www\.[\w+\.\:\/\_]+)/gi, | |
"<a target=\"_blank\" href=\"http://$1\">$1</a>"); | |
s_str = s_str.replace(/\bhttp\:\/\/¬¸ (\.[\w+\.\:\/\_]+)/gi, | |
"<a target=\"_blank\" href=\"http\:\/\/www$1\">http\:\/\/www$1</a>"); | |
s_str = s_str.replace(/\b(\w+@[\w+\.?]*)/gi, | |
"<a href=\"mailto\:$1\">$1</a>"); | |
return s_str; | |
} | |
function RemoveHrefs(str) { | |
str = str.replace(/<a.*?>/ig,""); | |
str = str.replace(/<\/a>/ig,""); | |
return str; | |
} | |
function GetIpAddr(elementId){ | |
var ipAddr=""; | |
for(var idx = 1; idx < 5; ++idx){ | |
var selectorId = "#" + elementId + idx; | |
ipAddr = ipAddr + $(selectorId).val() + "."; | |
} | |
return ipAddr.substr(0,ipAddr.length-1); | |
} | |
function SetIpAddr(elementId, ipAddr){ | |
var IpAddrArr = ipAddr.split("."); | |
for(var idx = 1; idx < 5; ++idx){ | |
var selectorId = "#" + elementId + idx; | |
$(selectorId).val(IpAddrArr[idx-1]); | |
} | |
} | |
//time format: hh:mm:ss | |
function GetTimeFromElement(elementId){ | |
var strTime=""; | |
for(var idx = 1; idx < 4; ++idx){ | |
var selectorId = "#" + elementId + idx; | |
strTime = strTime + $(selectorId).val() + ":"; | |
} | |
return strTime.substr(0,strTime.length-1); | |
} | |
//time format: hh:mm:ss | |
function SetTimeToElement(elementId,time){ | |
var timeArr = time.split(":"); | |
for(var idx = 1; idx < 4; ++idx){ | |
var selectorId = "#" + elementId + idx; | |
$(selectorId).val(timeArr[idx-1]); | |
} | |
} | |
//date format: yyyy-mm-dd | |
function SetDateToElement(elementId,date){ | |
var timeArr = date.split("-"); | |
for(var idx = 1; idx < 4; ++idx){ | |
var selectorId = "#" + elementId + idx; | |
$(selectorId).val(timeArr[idx-1]); | |
} | |
} | |
//date format: yyyy-mm-dd | |
function GetDateFromElement(elementId){ | |
var strDate = ""; | |
for(var idx = 1; idx < 4; ++idx){ | |
var selectorId = "#" + elementId + idx; | |
strDate = strDate + $(selectorId).val() + "-"; | |
} | |
return strDate.substr(0,strDate.length-1); | |
} | |
//time format: hh:mm | |
function GetTimeFromElementEx(elementId) { | |
var strTime = ""; | |
for (var idx = 1; idx < 3; ++idx) { | |
var selectorId = "#" + elementId + idx; | |
strTime = strTime + $(selectorId).val() + ":"; | |
} | |
return strTime.substr(0, strTime.length - 1); | |
} | |
//time format: hh:mm | |
function SetTimeToElementEx(elementId, timectrl) { | |
var timeArr = timectrl.split(":"); | |
for (var idx = 1; idx < 3; ++idx) { | |
var selectorId = "#" + elementId + idx; | |
$(selectorId).val(timeArr[idx - 1]); | |
} | |
} | |
function GetPortFromElement(elementId){ | |
var strPort=""; | |
for(var idx = 1; idx < 3; ++idx){ | |
var selectorId = "#" + elementId + idx; | |
strPort = strPort + $(selectorId).val() + ":"; | |
} | |
return strPort.substr(0,strPort.length-1); | |
} | |
//port format: xxxx:yyyy | |
function SetPortToElement(elementId,port){ | |
var portArr = port.split(":"); | |
for(var idx = 1; idx < 3; ++idx){ | |
var selectorId = "#" + elementId + idx; | |
$(selectorId).val(portArr[idx-1]); | |
} | |
} | |
function FormatSeconds(longTime) { | |
var time = parseFloat(longTime); | |
var d=0; | |
var h=0; | |
var m=0; | |
var s=0; | |
if (time != null && time != ""){ | |
if (time < 60) { | |
s = time; | |
} else if (time > 60 && time < 3600) { | |
m = parseInt(time / 60); | |
s = parseInt(time % 60); | |
} else if (time >= 3600 && time < 86400) { | |
h = parseInt(time / 3600); | |
m = parseInt(time % 3600 / 60); | |
s = parseInt(time % 3600 % 60 % 60); | |
} else if (time >= 86400) { | |
d = parseInt(time / 86400); | |
h = parseInt(time % 86400 / 3600); | |
m = parseInt(time % 86400 % 3600 / 60) | |
s = parseInt(time % 86400 % 3600 % 60 % 60); | |
} | |
} | |
time = d+" - "+fix(h,2)+":"+fix(m,2)+":"+fix(s,2)+("(Days - hh:mm:ss)"); | |
return time; | |
} | |
function fix(num, length) { | |
return ('' + num).length < length ? ((new Array(length + 1)).join('0') + num).slice(-length) : '' + num; | |
} | |