common.js
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
var transport = {
xhr: new XMLHttpRequest(),
get: function (url) {
this.xhr.open('GET', xmlFile, false);
this.xhr.send(null);
return this.xhr.status == 200 ? this.xhr.responseText : null;
},
getXML: function (url) {
this.xhr.open('GET', url, false);
this.xhr.overrideMimeType("text/xml");
this.xhr.send(null);
return this.xhr.status == 200 ? this.xhr.responseXML : null;
},
getJSON: function (url) {
this.xhr.open('GET', url, false);
this.xhr.overrideMimeType("application/json");
this.xhr.send(null);
return this.xhr.status == 200 ? JSON.parse(this.xhr.responseText) : null;
}
};
function transformXML(xmlDoc, xslDoc, element) {
var XSLT = new XSLTProcessor;
XSLT.importStylesheet(xslDoc);
var e = document.getElementById(element);
if (e) {
e.innerHTML = "";
e.appendChild(XSLT.transformToFragment(xmlDoc, document));
}
}
function getNodeValue(xml, tagname)
{
var tags = xml.getElementsByTagName(tagname);
if (tags.length > 0)
return tags[0].firstChild ? tags[0].firstChild.nodeValue : null;
else
return null;
}
function showCtrl(id)
{
document.getElementById(id).style.display = "block";
}
function hideCtrl(id)
{
document.getElementById(id).style.display = "none";
}
function enableCtrl(id)
{
document.getElementById(id).disabled = false;
}
function disableCtrl(id)
{
document.getElementById(id).disabled = true;
}
function setValue(id, value)
{
document.getElementById(id).value = value;
}
function setContent(id, content)
{
document.getElementById(id).innerHTML = content;
}
function getUrlArg(name)
{
var idx=document.location.href.indexOf(name+'=');
if (idx<=0) return null;
var argstr=document.location.href.substring(idx+name.length+1);
idx = argstr.indexOf('&');
var token = idx>=0?argstr.substring(0, idx):argstr;
return token.replace('+', ' ', 'g');
}
function getTickCount()
{
var d = new Date();
return d.getTime();
}
function getHHMM(sec)
{
var hours = Math.floor(sec / 3600);
var minutes = Math.floor((sec - (hours * 3600)) / 60);
return hours > 0 ? (hours + "h " + minutes + "m") : (minutes + " mins");
}
function getHHMMSS(sec)
{
var hours = Math.floor(sec / 3600);
var minutes = Math.floor((sec - (hours * 3600)) / 60);
var seconds = sec - (hours * 3600) - (minutes * 60);
if (hours < 10) {hours = "0"+hours;}
if (minutes < 10) {minutes = "0"+minutes;}
if (seconds < 10) { seconds = "0" + seconds; }
return hours+':'+minutes+':'+seconds;
}
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return null;
}
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}