PageSourceSearch

https://www.northcom.no/js/global.js

js northcom.no collected 2026-10-04 03:31:27 UTC 14,909 bytes, 459 lines download raw bytes

1/// <reference path="jquery-1.4.1-vsdoc.js" />
2Number.prototype.calcCurrency = function () {
3    return this * window.currencyFormat.ex;
4};
5
6/*
7Format a number as currency based on the current server-side thread culture number format.
8This method should yield the same result as "123.32M.ToString("C");" in C#.
9*/
10Number.prototype.toMoney = function () {
11    var n = this, c = window.currencyFormat, i = parseInt(n = Math.abs(+n || 0).toFixed(c.d)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
12    return (c.p % 2 ? "" : c.s + (c.p ? " " : "")) + (j ? i.substr(0, j) + c.gs : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + c.gs) + c.ds + Math.abs(n - i).toFixed(c.d).slice(2) + (c.p % 2 ? (c.p == 1 ? "" : " ") + c.s : "");
13};
14
15/*
16String.format for javascript.
17Usage: 'My name is {0} and I work as a {1}'.format('Anders', 'Developer');
18*/
19if (!String.prototype.format) {
20    String.prototype.format = function () {
21        var args = arguments;
22        return this.replace(/{(\d+)}/g, function (match, number) {
23            return typeof args[number] != 'undefined'
24              ? args[number]
25              : match
26            ;
27        });
28    };
29}
30
31//Check typing in textbox, only numbers, comma and dot allowed, usage: txbAnything.Attributes["onkeypress"] = "decCheck(event)";
32function decCheck(evt) {
33    //Get the event
34    var theEvent = evt || window.event;
35
36    //Find the keycode
37    var key = theEvent.keyCode || theEvent.which;
38
39    //Convert the keycode to a string
40    var keyChar = String.fromCharCode(key);
41
42    //Declare the regex pattern
43    var regex = /[0-9]|\.|\,/;
44
45    //If key test is false then return false
46    if (!regex.test(keyChar) && !(key == 8 || key == 9 || key == 37 || key == 39 || key == 35 || key == 36 || key == 46)) {
47        theEvent.returnValue = false;
48        if (theEvent.preventDefault) theEvent.preventDefault();
49    }
50}
51
52//Check typing in textbox, only numbers allowed, usage: txbAnything.Attributes["onkeypress"] = "numCheck(event)";
53function numCheck(evt) {
54    //Get the event
55    var theEvent = evt || window.event;
56
57    //Find the keycode
58    var key = theEvent.keyCode || theEvent.which;
59
60    //Convert the keycode to a string
61    var keyChar = String.fromCharCode(key);
62
63    //Declare the regex pattern
64    var regex = /[0-9]/;
65
66    //If key test is false then return false
67    if (!regex.test(keyChar) && !(key == 8 || key == 9 || key == 37 || key == 39 || key == 35 || key == 36 || key == 46)) {
68        theEvent.returnValue = false;
69        if (theEvent.preventDefault) theEvent.preventDefault();
70    }
71}
72
73Array.prototype.chunk = function (n) {
74    if (!this.length || typeof n === 'undefined') {
75        return [];
76    }
77    return [this.slice(0, n)].concat(this.slice(n).chunk(n));
78};
79
80function numOnly(e)
81{
82   var key = window.event ? e.keyCode : e.which;
83   var keychar = String.fromCharCode(key);
84   reg = /\D/;
85   return !reg.test(keychar);
86}
87
88function GetXmlHttpObject(handler)
89{
90    var objXmlHttp = null;
91    if (navigator.userAgent.indexOf("MSIE")>=0)
92    {
93        var strName = "Msxml2.XMLHTTP";
94        if (navigator.appVersion.indexOf("MSIE 5.5") >= 0)
95        {
96            strName = "Microsoft.XMLHTTP";
97        }
98        try
99        {
100            objXmlHttp = new ActiveXObject(strName);
101            objXmlHttp.onreadystatechange = handler;
102            return objXmlHttp;
103        }
104        catch(e)
105        {
106            alert("Error. Scripting for ActiveX might be disabled");
107            return;
108        }
109    }
110    else if (navigator.userAgent.indexOf("Mozilla") >= 0)
111    {
112        objXmlHttp = new XMLHttpRequest();
113        objXmlHttp.onload = handler;
114        objXmlHttp.onerror = handler;
115        return objXmlHttp;
116    }
117}
118
119//Global stock text vars
120var waitImgUrl = R + "Startup/Pics/wait3.gif";
121var currentStockLabelID = "";
122var currentProdNoLabelID = "";
123var currentPriceLabelID = "";
124var currentDiscPriceLabelID = "";
125var currentOrigPriceLabelID = "";
126var currentItemID = "0";
127var currentDim1Value = "0";
128var currentDim2Value = "0";
129var currentDim3Value = "0";
130var currentLID = "3";
131var currentInclVAT = "True";
132var currentUserID = "0";
133var currentImageWidth = "80";
134var currentCrop = "crop=none";
135var currentBuyRowID = "";
136
137
138function UpdateDimProd(stockLabelID, prodNoLabelID, priceLabelID, discPriceLabelID, origPriceLabelID, itemID, dim1ID, dim2ID, dim3ID, lid, incVat, userID, imgWidth, crop, buyRowID, errMsgID)
139{
140    //Find the dropdowns
141    var dim1 = document.getElementById(dim1ID);
142    var dim2 = document.getElementById(dim2ID);
143    var dim3 = document.getElementById(dim3ID);
144
145    //Find all the values
146    var dim1value = '0';
147    if (dim1) dim1value = dim1.value;
148
149    var dim2value = '0';
150    if (dim2) dim2value = dim2.value;
151
152    var dim3value = '0';
153    if (dim3) dim3value = dim3.value;
154
155    //Set the global vars
156    currentStockLabelID = stockLabelID;
157    currentProdNoLabelID = prodNoLabelID;
158    currentPriceLabelID = priceLabelID;
159    currentDiscPriceLabelID = discPriceLabelID;
160    currentOrigPriceLabelID = origPriceLabelID;
161    currentItemID = itemID;
162    currentDim1Value = dim1value;
163    currentDim2Value = dim2value;
164    currentDim3Value = dim3value;
165    currentLID = lid;
166    currentInclVAT = incVat;
167    currentUserID = userID;
168    currentImageWidth = imgWidth;
169    currentCrop = crop;
170    currentBuyRowID = buyRowID;
171
172    //Fetch values
173    GetAllowBuy();
174    GetProdNo();
175    GetPrice();
176    GetStockText();
177    GetDiscountPrice();
178    GetOriginalPrice();
179    GetImageURL();
180
181    //Hide errMsg
182    var errMsg = document.getElementById(errMsgID);
183    if (errMsg) errMsg.style.display = 'none';
184}
185
186function GetAllowBuy()
187{
188    var buyRow = document.getElementById(currentBuyRowID);
189    if (buyRow != null) {
190        //Build the URL
191        var url = R + "Controls/Toolbox/GetAllowBuy.aspx?ItemID=" + currentItemID + "&Dim1=" + currentDim1Value + "&Dim2=" + currentDim2Value + "&Dim3=" + currentDim3Value + "&LID=" + currentLID;
192
193        //Perform the request
194        xmlHttp7 = GetXmlHttpObject(GetAllowBuyReturn);
195        xmlHttp7.open("GET", url, true);
196        xmlHttp7.send(null);
197    }
198}
199
200function GetAllowBuyReturn()
201{
202    //If xml http req is ready then inject
203    if (xmlHttp7.readyState == 4 || xmlHttp7.readyState == "complete")
204    {
205        var buyRow = document.getElementById(currentBuyRowID);
206
207        if (buyRow != null)
208            buyRow.style.display = xmlHttp7.responseText;
209    }
210}
211
212function GetStockText()
213{
214    var stockLabel = document.getElementById(currentStockLabelID);
215    if (stockLabel != null)
216    {
217        //Set the wait indicator
218        stockLabel.innerHTML = '<img src="' + waitImgUrl + '" alt="loading..." />';
219
220        //Build the URL
221        var url = R + "Controls/Toolbox/GetStockText.aspx?ItemID=" + currentItemID + "&Dim1=" + currentDim1Value + "&Dim2=" + currentDim2Value + "&Dim3=" + currentDim3Value + "&LID=" + currentLID;
222
223        //Perform the request
224        xmlHttp1 = GetXmlHttpObject(GetStockTextReturn);
225        xmlHttp1.open("GET", url, true);
226        xmlHttp1.send(null);
227    }
228}
229
230function GetStockTextReturn()
231{
232    //If xml http req is ready then inject
233    if (xmlHttp1.readyState == 4 || xmlHttp1.readyState == "complete")
234    {
235        var stockLabel = document.getElementById(currentStockLabelID);
236
237        if (stockLabel != null)
238            stockLabel.innerHTML = xmlHttp1.responseText;
239    }
240}
241
242function GetProdNo()
243{
244    var prodNoLabel = document.getElementById(currentProdNoLabelID);
245    if (prodNoLabel != null)
246    {
247        //Set the wait indicator
248        prodNoLabel.innerHTML = '<img src="' + waitImgUrl + '" alt="loading..." />';
249
250        //Build the URL
251        var url = R + "Controls/Toolbox/GetProdNo.aspx?ItemID=" + currentItemID + "&Dim1=" + currentDim1Value + "&Dim2=" + currentDim2Value + "&Dim3=" + currentDim3Value;
252
253        //Perform the request
254        xmlHttp2 = GetXmlHttpObject(GetProdNoReturn);
255        xmlHttp2.open("GET", url, true);
256        xmlHttp2.send(null);
257    }
258}
259
260function GetProdNoReturn()
261{
262    //If xml http req is ready then inject
263    if (xmlHttp2.readyState == 4 || xmlHttp2.readyState == "complete")
264    {
265        var prodNoLabel = document.getElementById(currentProdNoLabelID);
266
267        if (prodNoLabel != null)
268            prodNoLabel.innerHTML = xmlHttp2.responseText;
269    }
270}
271
272function GetPrice()
273{
274    var priceLabel = document.getElementById(currentPriceLabelID);
275    if (priceLabel != null)
276    {
277        //Set the wait indicator
278        priceLabel.innerHTML = '<img src="' + waitImgUrl + '" alt="loading..." />';
279
280        //Build the URL
281        var url = R + "Controls/Toolbox/GetPrice.aspx?ItemID=" + currentItemID + "&Dim1=" + currentDim1Value + "&Dim2=" + currentDim2Value + "&Dim3=" + currentDim3Value + "&LID=" + currentLID + "&InclVAT=" + currentInclVAT + "&UserID=" + currentUserID;
282
283        //Perform the request
284        xmlHttp3 = GetXmlHttpObject(GetPriceReturn);
285        xmlHttp3.open("GET", url, true);
286        xmlHttp3.send(null);
287    }
288}
289
290function GetPriceReturn()
291{
292    //If xml http req is ready then inject
293    if (xmlHttp3.readyState == 4 || xmlHttp3.readyState == "complete")
294    {
295        var priceLabel = document.getElementById(currentPriceLabelID);
296
297        if (priceLabel != null)
298            priceLabel.innerHTML = xmlHttp3.responseText;
299    }
300}
301
302function GetDiscountPrice()
303{
304    var discPriceLabel = document.getElementById(currentDiscPriceLabelID);
305    if (discPriceLabel != null)
306    {
307        //Set the wait indicator
308        discPriceLabel.innerHTML = '<img src="' + waitImgUrl + '" alt="loading..." />';
309
310        //Build the URL
311        var url = R + "Controls/Toolbox/GetPrice.aspx?ItemID=" + currentItemID + "&Dim1=" + currentDim1Value + "&Dim2=" + currentDim2Value + "&Dim3=" + currentDim3Value + "&LID=" + currentLID + "&InclVAT=" + currentInclVAT + "&UserID=" + currentUserID + "&Type=discount";
312
313        //Perform the request
314        xmlHttp4 = GetXmlHttpObject(GetDiscountPriceReturn);
315        xmlHttp4.open("GET", url, true);
316        xmlHttp4.send(null);
317    }
318}
319
320function GetDiscountPriceReturn()
321{
322    //If xml http req is ready then inject
323    if (xmlHttp4.readyState == 4 || xmlHttp4.readyState == "complete")
324    {
325        var discPriceLabel = document.getElementById(currentDiscPriceLabelID);
326
327        if (discPriceLabel != null)
328            discPriceLabel.innerHTML = xmlHttp4.responseText;
329    }
330}
331
332function GetOriginalPrice()
333{
334    var origPriceLabel = document.getElementById(currentOrigPriceLabelID);
335    if (origPriceLabel != null)
336    {
337        //Set the wait indicator
338        origPriceLabel.innerHTML = '<img src="' + waitImgUrl + '" alt="loading..." />';
339
340        //Build the URL
341        var url = R + "Controls/Toolbox/GetPrice.aspx?ItemID=" + currentItemID + "&Dim1=" + currentDim1Value + "&Dim2=" + currentDim2Value + "&Dim3=" + currentDim3Value + "&LID=" + currentLID + "&InclVAT=" + currentInclVAT + "&UserID=" + currentUserID + "&Type=original";
342
343        //Perform the request
344        xmlHttp5 = GetXmlHttpObject(GetOriginalPriceReturn);
345        xmlHttp5.open("GET", url, true);
346        xmlHttp5.send(null);
347    }
348}
349
350function GetOriginalPriceReturn()
351{
352    //If xml http req is ready then inject
353    if (xmlHttp5.readyState == 4 || xmlHttp5.readyState == "complete")
354    {
355        var origPriceLabel = document.getElementById(currentOrigPriceLabelID);
356        if (origPriceLabel != null)
357            origPriceLabel.innerHTML = xmlHttp5.responseText;
358    }
359}
360
361function GetImageURL()
362{
363    var imgImage = document.getElementById("img" + currentItemID);
364    if (imgImage != null)
365    {
366        //Build the URL
367        var url = R + "Controls/Toolbox/GetImageID.aspx?ItemID=" + currentItemID + "&Dim1=" + currentDim1Value + "&Dim2=" + currentDim2Value + "&Dim3=" + currentDim3Value;
368
369        //Perform the request
370        xmlHttp6 = GetXmlHttpObject(GetImageURLReturn);
371        xmlHttp6.open("GET", url, true);
372        xmlHttp6.send(null);
373    }
374}
375
376function GetImageURLReturn()
377{
378    //If xml http req is ready then inject
379    if (xmlHttp6.readyState == 4 || xmlHttp6.readyState == "complete")
380    {
381        var imgImage = document.getElementById("img" + currentItemID);
382        if (imgImage != null)
383        {
384            try
385            {
386                var iDimImageID = parseInt(xmlHttp6.responseText);
387                if (iDimImageID > 0)
388                {
389                    imgImage.src = R + "ViewImage.aspx?ItemID=" + iDimImageID.toString() + "&width=" + currentImageWidth + "&" + currentCrop;
390                }
391            }
392            catch (Err) { }
393        }
394    }
395}
396
397function openImageWindow(itemID)
398{
399	win = window.open(R + 'Image.aspx?itemID='+itemID,'Preview', 'width=600,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0');
400	win.focus;
401
402}
403
404function openFileWindow(itemID)
405{
406	win = window.open(R + 'ViewFile.aspx?itemID='+itemID,'Preview', 'width=650,height=650,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=0');
407	win.focus;
408}
409
410function openLinkWindow(itemID)
411{
412	win = window.open(R + 'Redirect.aspx?itemID='+itemID,'Preview', 'width=650,height=650,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=0');
413	win.focus;
414}
415
416function SwitchArea(id) {
417
418         if(!document.getElementById) return;
419
420         var Area= document.getElementById(id);
421
422         if(Area.className=='Area_on') {
423
424                 Area.className='Area_off';
425
426         }
427
428         else if(Area.className=='Area_off') {
429
430                 Area.className = 'Area_on';
431
432         }
433
434}
435
436function SessionStorageObject(objectName) {
437    this.objectName = objectName;
438    this.clear = function () {
439        sessionStorage.setItem(this.objectName, JSON.stringify({}));
440    }
441    this.setValue = function (key, value) {
442        var sessionState = JSON.parse(sessionStorage.getItem(this.objectName));
443        sessionState[key] = value;
444        sessionStorage.setItem(this.objectName, JSON.stringify(sessionState));
445    }
446    this.getValue = function (key) {
447        var sessionState = JSON.parse(sessionStorage.getItem(this.objectName));
448        if (sessionState) {
449            return sessionState[key];
450        }
451        return undefined;
452    }
453    this.clear();
454}
455
456function reloadPageAsGet() {
457    var loc = window.location;
458    window.location = loc.protocol + '//' + loc.host + loc.pathname + loc.search;
459}

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.