PageSourceSearch

https://gripen.com/public/include/js/common.js

js gripen.com collected 2026-10-02 12:13:39 UTC 11,021 bytes, 416 lines download raw bytes

1//////////////////////////////////////////
2// LOGGING FUNCTIONS
3//////////////////////////////////////////
4
5var g_logindent = 0;
6
7//============================================================
8// Adds an log entry to 'consoleDIV' element if any.
9// Format:
10//   <time><message><br>
11//============================================================
12function addToLog(a_str)
13{
14  var console = document.getElementById('consoleDIV');
15  if(null != console) {
16    var date = new Date();
17    var str = "<br>" + date.getTime();
18    
19    for(i=0; i < g_logindent + 1; i++) {
20        str += "____";
21    }
22  
23    console.innerHTML += str + a_str;
24  }
25}
26
27//============================================================
28// Increases the current log entries indentation 
29// Adds an log entry to 'consoleDIV' element if any.
30//============================================================
31function addToLogEnter(a_str)
32{
33    addToLog(a_str);
34    g_logindent++;
35}
36
37//============================================================
38// Decreases the current log entries indentation 
39// Adds an log entry to 'consoleDIV' element if any.
40//============================================================
41function addToLogExit(a_str)
42{
43    g_logindent--;
44    addToLog(a_str);
45}
46
47
48//////////////////////////////////////////
49// String helper functions
50//////////////////////////////////////////
51
52//============================================================
53// Returns a hex representation of a given string
54// Example:
55//    "abc" => "616263"
56//============================================================
57function stringToHex(a_str)
58{
59    var res = "";
60    for (i=0; i<a_str.length; i++) {
61        res += a_str.charCodeAt(i).toString(16);
62    }
63    return res;
64}
65
66//============================================================
67// Performs Base64 encoding of the input string
68//
69// Input
70//    input - String, string to encode
71// Return
72//   String, Base64 encoded input string
73// Example:
74//    "abc" => "YWJj"
75//============================================================
76function Base64encode (input) 
77{
78    var output = "";
79    var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
80    var i = 0;
81    var  _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
82
83    while (i < input.length) {
84
85        chr1 = input.charCodeAt(i++);
86        chr2 = input.charCodeAt(i++);
87        chr3 = input.charCodeAt(i++);
88
89        enc1 = chr1 >> 2;
90        enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
91        enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
92        enc4 = chr3 & 63;
93
94        if (isNaN(chr2)) {
95            enc3 = enc4 = 64;
96        } else if (isNaN(chr3)) {
97            enc4 = 64;
98        }
99
100        output = output +
101        _keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
102        _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
103    }
104
105    return output;
106}
107
108//============================================================
109// Performs Base64 decoding of the input string
110//
111// Input
112//    input - String, string to decode
113// Return
114//   String, Base64 decoded input string
115//============================================================
116function Base64decode (input)
117{
118    var output = "";
119    var chr1, chr2, chr3;
120    var enc1, enc2, enc3, enc4;
121    var i = 0;
122    var  _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
123
124    input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
125 
126    while (i < input.length) {
127        enc1 = _keyStr.indexOf(input.charAt(i++));
128	enc2 = _keyStr.indexOf(input.charAt(i++));
129	enc3 = _keyStr.indexOf(input.charAt(i++));
130	enc4 = _keyStr.indexOf(input.charAt(i++));
131 
132	chr1 = (enc1 << 2) | (enc2 >> 4);
133	chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
134	chr3 = ((enc3 & 3) << 6) | enc4;
135 
136	output = output + String.fromCharCode(chr1);
137 
138	if (enc3 != 64) {
139		output = output + String.fromCharCode(chr2);
140	}
141	if (enc4 != 64) {
142		output = output + String.fromCharCode(chr3);
143	}
144 
145    }
146 
147    return output;
148}
149	
150
151//============================================================
152// Removes leading spaces from a given string
153// Example:
154//    "    abc" => "abc"
155//============================================================
156function ltrim(a_str)
157{
158    return a_str.replace(/^\s+/,"");
159}
160
161
162
163//////////////////////////////////////////
164// Misc functions
165//////////////////////////////////////////
166function getExternalBaseURL()
167{
168    var tokens = window.location.href.split("/"); 
169    var result = tokens[0] + "//" + tokens[2];
170    return result;
171}
172
173function getExternalBaseHost()
174{
175    var host = window.location.host;
176    if(host.indexOf(']') != -1) { // ipv6
177        host = host.substr(0, host.indexOf(']')+1);
178    } else if(host.indexOf(':') != -1) {
179        host = host.substr(0, host.indexOf(':'));
180    }
181    return host;
182}
183    
184function getExternalBasePort()
185{
186    var port = window.location.port;
187    if(!port) {
188        if(window.location.protocol == "https:")
189            port = 443;
190        else
191            port = 80;
192    }
193    return port;
194}
195
196/*
197 * Referenced from http://www.javascripter.net/faq/readingacookie.htm
198 */
199function escapeRegex(value)
200{
201    return value.replace(/([.\\+\-*:\/?!|^${}()\[\]])/g,'\\$1');
202}
203
204var ar4cmatch={
205        LastMRH_Session:'([0-9a-f]{5,12})',
206        apm_swg_LastMRH_Session:'([0-9a-f]{5,12})',
207        apm_swg_category:'([a-zA-Z0-9/_() -]{1,64})',
208        MRHSession:'([0-9a-f]{32})'
209};
210
211function get_cookie(a_cookie_name)
212{
213    var r4c='(.*?)';
214    a_cookie_name = escapeRegex(a_cookie_name);
215    if(a_cookie_name in ar4cmatch){
216        r4c=ar4cmatch[a_cookie_name];
217    }
218    var results = document.cookie.match('(^|;)\x20?' + a_cookie_name + '='+r4c+'(;|$)');
219
220    if(results){
221        return (decodeURIComponent(results[2]));
222    } else {
223        return null;
224    }
225}
226
227function set_cookie(name, value, expDays)
228{
229    var secure =  window.location.protocol.toLowerCase() == "https:";
230    if (secure) value += '; secure';
231    if (expDays != 0) {
232        var d = new Date();
233        d.setTime(d.getTime() + (expDays * 24 * 60 * 60 * 1000));
234        value += '; expires=' + d.toUTCString();
235    }
236    value += '; path=/';
237    document.cookie = name + "=" + value;
238}
239
240function delete_cookie(name, path, secure)
241{
242    document.cookie = name + "=" + (path ? ";path=" + path : "")
243    + (secure ? ";secure" : "") + "; expires=Thu, 01-Jan-1970 00:00:01 GMT";
244}
245
246function bind(obj, fn)
247{
248    return function() { return fn.apply(obj, arguments); }
249}
250
251function arrayContains(array, value) {
252    for (var i = 0; i < array.length; i++) {
253        if (array[i] == value) return true;
254    }
255    return false;
256}
257
258function isArray(arr)
259{
260    return !!arr && arr.constructor == Array;
261}
262
263function forEach(array, callback, thisArg) {
264    if (!isArray(array)) throw new Error('forEach called on something that is not Array');
265    for (var i = 0, len = array.length; i < len; ++i) {
266        callback.call(thisArg, array[i], i, array);
267    }
268}
269
270function parseJSON(text)
271{
272    if (typeof JSON == "object" && typeof JSON.parse == "function") {
273        return JSON.parse(text);
274    }
275
276    //Fallback for IE7, taken from json2.js library
277    if (/^[\],:{}\s]*$/.test(
278            text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
279                .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
280                .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
281        return eval('(' + text + ')');
282    }
283
284    throw new SyntaxError('Invalid JSON.');
285}
286
287//
288// Accepts XMLHttpRequest and returns XML object when possible or 'null'.
289// It also handles file:// protocol nuances in IE.
290//
291function getXmlDoc(xhr)
292{
293    var xmlDoc = null;
294    var isLocal = (xhr.status == 0);
295
296    if ((xhr.readyState == 4) && (xhr.status == 200 || isLocal) && (xhr.responseXML)) {
297        if (xhr.responseXML.document) {
298            xmlDoc = xhr.responseXML;
299        }
300        else {
301            if (!isLocal) {   // IE
302                return xhr.responseXML;
303            }
304            else {
305                // Local failure--always happens
306                var axDoc = new ActiveXObject("Microsoft.XMLDOM");
307                axDoc.async = false;
308                axDoc.loadXML(xhr.responseText);
309                if (axDoc.documentElement)
310                    xmlDoc = axDoc;
311            }
312        }
313    }
314    return xmlDoc;
315}
316
317function getHTTPRequestObject()
318{
319    var res = null;
320    try {
321        res = new XMLHttpRequest();
322    } catch(e) {
323        try {
324            res = new ActiveXObject('MSXML2.XMLHTTP.6.0');
325        } catch(e) {
326            res = null;
327        }
328    }
329    return res;
330}
331
332function objectToParams(obj)
333{
334  var result = '';
335  for (var key in obj) {
336      if (obj.hasOwnProperty(key)) {
337        if(result) {
338            result += '&';
339        }
340        result += key + '=' + obj[key];
341      }
342  }
343  return result;
344}
345
346function stripBrackets(str)
347{
348  if ((str.length >= 2) && (str[0] == '[') && (str[str.length - 1] == ']')) {
349    return str.substr(1, str.length - 2);
350  }
351  return str;
352}
353
354function getCustomProtocolLink(scheme, extraValues)
355{
356  var protocol = window.location.protocol;
357  if(protocol.indexOf(':') != -1) {
358      protocol = protocol.substr(0, protocol.indexOf(':'));
359  }
360
361  if (!extraValues || (typeof extraValues != "object")) {
362      extraValues = {};
363  }
364  extraValues["protocol"] = protocol;
365  extraValues["port"] = getExternalBasePort();
366
367  // In new implementation we retrieve session id with one time code generated
368  // during a resource launch process.
369  // Set session id to dummy sid. This is to support backward
370  // compatability.
371  // F5Vpn.exe(non upgraded client) bails out before upgradation when there is an
372  // empty sid. Having a dummy session id ensures that F5Vpn.exe  does not run
373  // into exceptions but passess through the inital check succesfully and
374  // upgrades(Newer version of Client is installed on BIG-IP).
375  if (scheme != "f5-vpn") {
376    extraValues["sid"] = get_cookie('MRHSession');
377  } else {
378    extraValues["sid"] = 'nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn';
379  }
380
381  var host = extraValues["server"];
382  if (host) {
383    extraValues["server"] = stripBrackets(host);
384  }
385  var result = scheme + '://' + window.location.host + '?';
386
387  return result + objectToParams(extraValues);
388}
389
390if (!Function.prototype.bind) {
391  Function.prototype.bind = function(oThis) {
392    if (typeof this !== 'function') {
393      // closest thing possible to the ECMAScript 5
394      // internal IsCallable function
395      throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
396    }
397
398    var aArgs   = Array.prototype.slice.call(arguments, 1),
399        fToBind = this,
400        fNOP    = function() {},
401        fBound  = function() {
402          return fToBind.apply(this instanceof fNOP
403                 ? this
404                 : oThis,
405                 aArgs.concat(Array.prototype.slice.call(arguments)));
406        };
407
408    if (this.prototype) {
409      // native functions don't have a prototype
410      fNOP.prototype = this.prototype;
411    }
412    fBound.prototype = new fNOP();
413
414    return fBound;
415  };
416}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.