PageSourceSearch

https://nasdaqtrader.com/js/utilities.js

js nasdaqtrader.com collected 2026-10-02 03:51:05 UTC 16,384 bytes, 583 lines download raw bytes

1function checkEnter(cmd, evt)
2{   
3    var keyCode = (window.event)?event.keyCode:evt.which
4    if (keyCode == 13) 
5    {
6        if (window.event) 
7        {
8            window.event.cancelBubble = true;
9            window.event.returnValue = false;
10        }
11        else 
12        {
13            evt.cancelBubble = true;
14            evt.returnValue = false;
15        }
16        setTimeout(cmd,1);
17        return false;
18    }
19}
20
21function loadSelectFromObj(ctrl, obj, val, txt, preset) 
22{
23	// clear control first
24	ctrl.length = 0;
25	var offset = 0;
26	if (preset != undefined && preset != null) 
27    {
28		ctrl.options[0] = new Option(preset,preset);
29		++offset;
30	}
31    for (var i = 0; i < obj.length; ++i) 
32    {
33		ctrl.options[i+offset] = new Option(obj[i][txt], obj[i][val]);
34	}            
35	ctrl.selectedIndex = 0;
36	return ctrl.length;
37}
38
39// Removes leading whitespaces
40function LTrim(value) 
41{
42    var re = /\s*((\S+\s*)*)/;
43    return value.replace(re, "$1");
44}
45 
46// Removes ending whitespaces
47function RTrim(value) 
48{
49    var re = /((\s*\S+)*)\s*/;
50    return value.replace(re, "$1");
51}
52 
53// Removes leading and ending whitespaces
54function trim(value) 
55{
56    return LTrim(RTrim(value));
57}
58
59//////STATUS BAR
60var StatusTimer=new Object();
61function updateStatusBar(elementID, status, message)
62{
63    //status 1 = success
64    //status 2 = error
65    //status else = no action
66    var persists=(arguments[3]!=undefined)?arguments[3]:5000; /// optional persistence time passed as fourth argument
67    
68    clearTimeout(StatusTimer[elementID]);
69    
70    var statusBar = document.getElementById(elementID);
71    var statusBarMsg = document.getElementById(elementID + 'Message');
72
73    switch (status) 
74    {
75        case 1:
76            statusBar.className = "status_bar_green";
77            statusBarMsg.className = "status_bar_msg_other"; //set style for span too.
78            break;
79        case 2:
80            statusBar.className = "status_bar_red";
81            statusBarMsg.className = "status_bar_msg_red"; //set style for span too.
82            break;
83        default:
84            statusBar.className = "status_bar_grey";
85            statusBarMsg.className = "status_bar_msg_other"; //set style for span too.
86            break;
87    }
88   
89    statusBarMsg.innerHTML=message;
90
91    if (status == 1 || status == 2)
92    {
93        StatusTimer[elementID] = setTimeout("updateStatusBar('"+elementID+"',3,'&nbsp;')", persists);
94    }
95    return StatusTimer[elementID];
96}
97
98////GET A VALUE FROM THE QUERY STRING
99////variable must match the name of the Query String
100////returns value on success and false if there is no such variable
101// Modified by A. Receveur on 8/27/2013: string comparison now sets strings to lowercase first
102//      and the comparison is now in a try...catch block.
103function getQueryVariable(variable) 
104{
105    var query = window.location.search.substring(1);
106    var vars = query.split("&");
107    for (var i = 0; i < vars.length; i++) 
108    {
109        var pair = vars[i].split("=");
110        try
111        {
112            if (pair[0].toLowerCase() == variable.toLowerCase()) 
113            {
114                return pair[1];
115            }
116        }
117        catch(err)
118        {
119          return false;
120        }
121    } 
122    return false;
123}
124
125////GET A VALUE FROM THE QUERY STRING
126////variable must match the name of the Query String
127////returns value on success and false if there is no such variable
128//// case insensitive
129function iGetQueryVariable(variable) 
130{
131    var lcVariable = variable.toLowerCase();
132    var query = window.location.search.substring(1);
133    var vars = query.split("&");
134    for (var i = 0; i < vars.length; i++) 
135    {
136        var pair = vars[i].split("=");
137        if (pair[0].toLowerCase() == lcVariable) { return pair[1]; }
138    } 
139    return false;
140}
141
142////GET A VALUE FROM THE QUERY STRING
143////variable must match the name of the Query String
144////returns value on success and false if there is no such variable
145//// case insensitive
146function iGetQueryVariableMulti(variable) 
147{
148    var lcVariable = variable.toLowerCase();
149    var query = window.location.search.substring(1);
150    var vars = query.split("&");
151    var ret_val = new Array();
152    for (var i = 0; i < vars.length; i++) 
153    {
154        var pair = vars[i].split("=");
155        if (pair[0].toLowerCase() == lcVariable) {  ret_val.push(pair[1]); }
156    } 
157    if(ret_val.length > 0) 
158      return ret_val;
159    else
160      return false;
161}
162
163
164////GET A VALUE FROM THE QUERY STRING
165////variable must match the name of the Query String
166////returns value on success and false if there is no such variable
167function getPageIdName() 
168{
169    try
170    {
171        var pagename = window.location.search.substring(1);
172        pagename = pagename.replace("id=", "");
173    }
174    catch(err)
175    {
176       return false;
177    }
178
179    return pagename;
180}
181
182
183function getIFrameId(str) 
184{
185    var pos = 0;
186    var lastpos = 0;
187    var strId = "";
188    var count = 0;
189    if (str.indexOf("<iframe") != -1) 
190    {
191        while (pos > -1)
192        {            
193            var pos = str.indexOf("<iframe", lastpos);
194            if (pos > -1)
195            {
196                var idPos = str.indexOf("id=",pos);
197                lastpos = idPos;
198                if (idPos > -1) 
199                {
200                    idPos += "id='".length;
201                    // now we're positioned right on first letter of frame id
202                    if(count > 0)
203                    {
204                        strId += "|";
205                    }
206                    while (str.charAt(idPos) != "\"") 
207                    {
208                        strId += str.charAt(idPos);
209                        ++idPos;
210                    }
211                    count++;
212                }
213                else
214                {
215                    pos = -1;
216                }
217            }
218        }
219    }
220    else
221    {
222        return null;
223    }
224    return strId;
225}    
226
227//Creates an HTML Element of any type.
228//Takes Properties and Style Attribute Arrays as third and fourth parameters.
229function CreateHTMLElement(type, append)
230{
231    var text=(arguments[2]!=undefined && arguments[2]!="")?arguments[2]:null;
232    var attributes=(arguments[3]!=undefined)?arguments[3]:Array();
233    var styles=(arguments[4]!=undefined)?arguments[4]:Array();
234    
235    //alert(arguments[2]+":"+text);
236    var element=document.createElement(type);
237    for (var att in attributes) {if(typeof(attributes[att])!="function")element[att]=attributes[att];}
238    for (var style in styles) {if(typeof(styles[style])!="function")element.style[style]=styles[style];}
239    
240    var textElement=null;
241    if(text!=null)var textElement=document.createTextNode(text);
242    
243    if(!append)return element;
244
245    if (type == "text") 
246    {
247        append.appendChild(textElement); return textElement;  
248    }
249    else
250    {
251        if(textElement!=null)element.appendChild(textElement);
252        if(append!=undefined)append.appendChild(element);
253        return element;
254    }    
255}
256
257//Updates the cell with a new value and updates it with the appropriate style
258function ChangeCell(cell, newVal, upStyle, downStyle, normStyle)
259{
260    if (isNaN(newVal))
261    { 
262        if(cell.tagName=="INPUT")cell.value=newVal;
263        else cell.innerHTML=newVal;
264        return; 
265    }
266    
267    var CurrencyFlag=(arguments[5]!=undefined && arguments[2]!="")?arguments[5]:false;
268    
269    var valRef=(cell.tagName=="INPUT")?cell.value:cell.innerHTML;
270        
271    var curVal=Math.round(Number(valRef)*100)/100;
272    var newVal=Math.round(Number(newVal)*100)/100;    
273    var reverse=(arguments[5]!=undefined)? Boolean(arguments[5]):false;
274            
275    if(cell.tagName=="INPUT")cell.value=(CurrencyFlag)?formatAsMoney(newVal):newVal;
276    else cell.innerHTML=(CurrencyFlag)?formatAsMoney(newVal):newVal;
277    
278    if(curVal<newVal)var styles=(!reverse)?downStyle:upStyle;
279    else if(curVal>newVal)var styles=(!reverse)?upStyle:downStyle;
280    else var styles=normStyle;
281    
282    for (var style in styles) {if(typeof(styles[style])!="function")cell.style[style]=styles[style];}
283    
284    return;        
285}
286
287
288//Returns the x and y coordiantes of and HTML Node
289function findPosition(HTMLNode) 
290{
291   if (HTMLNode.offsetParent) 
292   {
293      for (var posX = 0, posY = 0; HTMLNode.offsetParent; HTMLNode = HTMLNode.offsetParent) 
294      {
295        posX += HTMLNode.offsetLeft;
296        posY += HTMLNode.offsetTop;
297      }
298      return [ posX, posY ];
299  } else 
300  {
301    return [ HTMLNode.x, HTMLNode.y ];
302  }
303}
304
305function loopTillOptionsLoad(cmd, cnt, ddlName) 
306{
307    var objDdl = document.getElementById(ddlName)
308    alert(objDdl.selectedIndex);
309
310    if (objDdl.selectedIndex == -1) 
311    {
312        cnt++;
313        setTimeout("loopTillOptionsLoad('" + cmd + "'," + cnt + ",'" + ddlName + "');",100);
314    }
315    else if (cnt > 20) 
316    {
317        return;
318    }
319    else 
320    {
321        setTimeout(cmd,100);
322    }
323}
324
325function IsNumber(val)
326{
327	var ValidChars = "0123456789";
328	var Char;
329	for (i = 0; i < val.length; i++) 
330	{ 
331		Char = val.charAt(i); 
332		if (ValidChars.indexOf(Char) == -1) 
333		 return false;
334	}
335	return true;
336}
337
338function SetListboxSelectedValue(selBox, val)
339{
340    for (i = 0; i < selBox.options.length; i++) 
341    {
342       if (selBox.options[i].value == val) {  selBox.selectedIndex = i; }
343	}
344}
345
346function ListboxSelectedValue(selBox)
347{
348    if(selBox.selectedIndex==-1)
349        return "";
350    else
351        return selBox.options[selBox.selectedIndex].value;
352}
353
354function ListboxSelectedText(selBox)
355{
356    if(selBox.selectedIndex==-1)
357        return "";
358    else
359        return selBox.options[selBox.selectedIndex].text;
360}
361
362//Used when using parseInt(parseVal(val))
363//In JavaScript passing a number with a leading 0 to the parseInt() function designates that number as octal. 
364//In octal, there is no 08 or 09. Therefore, these numbers are interpreted as 0.
365function parseVal(val)
366{
367   while (val.charAt(0) == '0')
368      val = val.substring(1, val.length); 
369   return val;
370}
371
372//Cookies
373function setCookie(c_name, value, expiredays) 
374{
375    var exdate = new Date();
376    exdate.setDate(exdate.getDate() + expiredays);
377    document.cookie = c_name + "=" + escape(value)+ ((expiredays==null) ? "" : "; expires=" + exdate.toGMTString());
378}
379
380function setCookieRoot(c_name, value, expiredays) 
381{
382    var exdate = new Date();
383    exdate.setDate(exdate.getDate() + expiredays);
384    document.cookie = c_name + "=" + escape(value)+ ((expiredays==null) ? "" : "; expires=" + exdate.toGMTString()) + "; path=/";
385}
386
387function getCookie(c_name)
388{
389    if (document.cookie.length>0)
390    {
391        c_start=document.cookie.indexOf(c_name + "=");
392        if (c_start!=-1)
393        { 
394            c_start=c_start + c_name.length+1; 
395            c_end=document.cookie.indexOf(";",c_start);
396            if (c_end==-1) 
397                c_end=document.cookie.length;
398            return unescape(document.cookie.substring(c_start,c_end));
399        } 
400      }
401    return "";
402}
403
404//ML 06/02/2008
405//call for TextArea onkeydown to limit the length
406//EXAMPLE: <textarea id="test" onkeydown="textAreaMax(this, 500)"></textarea>
407function textAreaMax(object, max)
408{
409    if (object.value.length >= max)
410        object.value = object.value.substring(0,max);                
411}
412
413function checkIfBlank(text)
414{
415    if (text == null || trim(text) == "")
416        return false;
417    else
418        return true;
419}
420
421function isBlank(text)
422{
423    if (text == null || trim(text) == "")
424        return true;
425    else
426        return false;
427}
428
429//addr= email value
430//man= 1 mandatory, 0 not mandatory
431//db= 1 alert reasons 0 no alerts
432function validateEmail(addr, man, db) 
433{
434    if (addr == '' && man) 
435    {
436        if (db) alert('email address is mandatory');
437        return false;
438    }
439    if (addr == '') return true;
440
441    var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
442    for (i = 0; i < invalidChars.length; i++) 
443    {
444        if (addr.indexOf(invalidChars.charAt(i), 0) > -1) 
445        {
446            if (db) alert('email address contains invalid characters');
447            return false;
448        }
449    }
450
451    for (i = 0; i < addr.length; i++) 
452    {
453        if (addr.charCodeAt(i) > 127) 
454        {
455            if (db) alert("email address contains non ascii characters.");
456            return false;
457        }
458    }
459
460    var atPos = addr.indexOf('@',0);
461    if (atPos == -1) {
462       if (db) alert('email address must contain an @');
463       return false;
464    }
465    if (atPos == 0) {
466       if (db) alert('email address must not start with @');
467       return false;
468    }
469    if (addr.indexOf('@', atPos + 1) > - 1) {
470       if (db) alert('email address must contain only one @');
471       return false;
472    }
473    if (addr.indexOf('.', atPos) == -1) {
474       if (db) alert('email address must contain a period in the domain name');
475       return false;
476    }
477    if (addr.indexOf('@.',0) != -1) {
478       if (db) alert('period must not immediately follow @ in email address');
479       return false;
480    }
481    if (addr.indexOf('.@',0) != -1){
482       if (db) alert('period must not immediately precede @ in email address');
483       return false;
484    }
485    if (addr.indexOf('..',0) != -1) {
486       if (db) alert('two periods must not be adjacent in email address');
487       return false;
488    }
489    
490    var suffix = addr.substring(addr.lastIndexOf('.')+1);
491    suffix = suffix.toLowerCase();
492
493    if (suffix.length != 2 
494        && suffix != 'com' && suffix != 'net' && suffix != 'org'
495        && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' 
496        && suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name'
497        && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') 
498    {
499            if (db) alert('invalid primary domain in email address');
500            return false;
501    }
502    return true;
503}
504
505
506function xtractJsFile(data)
507{
508    data = data.replace(/^\s|\s$/g, ""); //trims string
509
510    //var m = data.match(/([^\/\\]+)\.(asp|html|htm|shtml|php)$/i);
511    var m = data.match(/([^\/\\]+)\.(js)$/i);
512    if (m)
513        return {filename: m[1], ext: m[2]};
514    else
515        return null;
516}
517
518function IncludeJs(file)
519{
520  var head = document.getElementsByTagName('head').item(0)
521  var scriptTagInfo = xtractJsFile(file);
522  if (!scriptTagInfo)
523    return;
524  var scriptTagId = scriptTagInfo.filename + scriptTagInfo.ext;
525  var scriptTag = document.getElementById(scriptTagId);
526  if(scriptTag) head.removeChild(scriptTag);
527  script = document.createElement('script');
528  script.src = file;
529	script.type = 'text/javascript';
530	script.id = scriptTagId;
531	head.appendChild(script)
532}
533
534// set the radio button with the given value as being checked
535// do nothing if there are no radio buttons
536// if the given value does not exist, all the radio buttons
537// are reset to unchecked
538function setCheckedValue(radioObj, newValue) 
539{
540	if(!radioObj)
541		return;
542	var radioLength = radioObj.length;
543	if (radioLength == undefined) 
544    {
545		radioObj.checked = (radioObj.value == newValue.toString());
546		return;
547	}
548    for (var i = 0; i < radioLength; i++) 
549    {
550		radioObj[i].checked = false;
551		if (radioObj[i].value == newValue.toString())
552			radioObj[i].checked = true;
553	}
554}
555
556function getQueryStringParams()
557{
558    var vars = [], hash;
559    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
560    for(var i = 0; i < hashes.length; i++)
561    {
562        hash = hashes[i].split('=');
563        vars.push(hash[0]);
564        vars[hash[0]] = hash[1];
565    }
566    return vars;
567}
568
569function getQueryStringParam(name, url) {
570    if (!url) {
571      url = window.location.href;
572    }
573    name = name.replace(/[\[\]]/g, "\\$&");
574    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)");
575    var results = regex.exec(url);
576    if (!results)
577		return null;
578
579    if (!results[2]) 
580		return '';
581
582    return decodeURIComponent(results[2].replace(/\+/g, " "));
vendor: 3 bytes, line 583
583}

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.