///
Number.prototype.calcCurrency = function () {
return this * window.currencyFormat.ex;
};
/*
Format a number as currency based on the current server-side thread culture number format.
This method should yield the same result as "123.32M.ToString("C");" in C#.
*/
Number.prototype.toMoney = function () {
var n = this, c = window.currencyFormat, i = parseInt(n = Math.abs(+n || 0).toFixed(c.d)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
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 : "");
};
/*
String.format for javascript.
Usage: 'My name is {0} and I work as a {1}'.format('Anders', 'Developer');
*/
if (!String.prototype.format) {
String.prototype.format = function () {
var args = arguments;
return this.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};
}
//Check typing in textbox, only numbers, comma and dot allowed, usage: txbAnything.Attributes["onkeypress"] = "decCheck(event)";
function decCheck(evt) {
//Get the event
var theEvent = evt || window.event;
//Find the keycode
var key = theEvent.keyCode || theEvent.which;
//Convert the keycode to a string
var keyChar = String.fromCharCode(key);
//Declare the regex pattern
var regex = /[0-9]|\.|\,/;
//If key test is false then return false
if (!regex.test(keyChar) && !(key == 8 || key == 9 || key == 37 || key == 39 || key == 35 || key == 36 || key == 46)) {
theEvent.returnValue = false;
if (theEvent.preventDefault) theEvent.preventDefault();
}
}
//Check typing in textbox, only numbers allowed, usage: txbAnything.Attributes["onkeypress"] = "numCheck(event)";
function numCheck(evt) {
//Get the event
var theEvent = evt || window.event;
//Find the keycode
var key = theEvent.keyCode || theEvent.which;
//Convert the keycode to a string
var keyChar = String.fromCharCode(key);
//Declare the regex pattern
var regex = /[0-9]/;
//If key test is false then return false
if (!regex.test(keyChar) && !(key == 8 || key == 9 || key == 37 || key == 39 || key == 35 || key == 36 || key == 46)) {
theEvent.returnValue = false;
if (theEvent.preventDefault) theEvent.preventDefault();
}
}
Array.prototype.chunk = function (n) {
if (!this.length || typeof n === 'undefined') {
return [];
}
return [this.slice(0, n)].concat(this.slice(n).chunk(n));
};
function numOnly(e)
{
var key = window.event ? e.keyCode : e.which;
var keychar = String.fromCharCode(key);
reg = /\D/;
return !reg.test(keychar);
}
function GetXmlHttpObject(handler)
{
var objXmlHttp = null;
if (navigator.userAgent.indexOf("MSIE")>=0)
{
var strName = "Msxml2.XMLHTTP";
if (navigator.appVersion.indexOf("MSIE 5.5") >= 0)
{
strName = "Microsoft.XMLHTTP";
}
try
{
objXmlHttp = new ActiveXObject(strName);
objXmlHttp.onreadystatechange = handler;
return objXmlHttp;
}
catch(e)
{
alert("Error. Scripting for ActiveX might be disabled");
return;
}
}
else if (navigator.userAgent.indexOf("Mozilla") >= 0)
{
objXmlHttp = new XMLHttpRequest();
objXmlHttp.onload = handler;
objXmlHttp.onerror = handler;
return objXmlHttp;
}
}
//Global stock text vars
var waitImgUrl = R + "Startup/Pics/wait3.gif";
var currentStockLabelID = "";
var currentProdNoLabelID = "";
var currentPriceLabelID = "";
var currentDiscPriceLabelID = "";
var currentOrigPriceLabelID = "";
var currentItemID = "0";
var currentDim1Value = "0";
var currentDim2Value = "0";
var currentDim3Value = "0";
var currentLID = "3";
var currentInclVAT = "True";
var currentUserID = "0";
var currentImageWidth = "80";
var currentCrop = "crop=none";
var currentBuyRowID = "";
function UpdateDimProd(stockLabelID, prodNoLabelID, priceLabelID, discPriceLabelID, origPriceLabelID, itemID, dim1ID, dim2ID, dim3ID, lid, incVat, userID, imgWidth, crop, buyRowID, errMsgID)
{
//Find the dropdowns
var dim1 = document.getElementById(dim1ID);
var dim2 = document.getElementById(dim2ID);
var dim3 = document.getElementById(dim3ID);
//Find all the values
var dim1value = '0';
if (dim1) dim1value = dim1.value;
var dim2value = '0';
if (dim2) dim2value = dim2.value;
var dim3value = '0';
if (dim3) dim3value = dim3.value;
//Set the global vars
currentStockLabelID = stockLabelID;
currentProdNoLabelID = prodNoLabelID;
currentPriceLabelID = priceLabelID;
currentDiscPriceLabelID = discPriceLabelID;
currentOrigPriceLabelID = origPriceLabelID;
currentItemID = itemID;
currentDim1Value = dim1value;
currentDim2Value = dim2value;
currentDim3Value = dim3value;
currentLID = lid;
currentInclVAT = incVat;
currentUserID = userID;
currentImageWidth = imgWidth;
currentCrop = crop;
currentBuyRowID = buyRowID;
//Fetch values
GetAllowBuy();
GetProdNo();
GetPrice();
GetStockText();
GetDiscountPrice();
GetOriginalPrice();
GetImageURL();
//Hide errMsg
var errMsg = document.getElementById(errMsgID);
if (errMsg) errMsg.style.display = 'none';
}
function GetAllowBuy()
{
var buyRow = document.getElementById(currentBuyRowID);
if (buyRow != null) {
//Build the URL
var url = R + "Controls/Toolbox/GetAllowBuy.aspx?ItemID=" + currentItemID + "&Dim1=" + currentDim1Value + "&Dim2=" + currentDim2Value + "&Dim3=" + currentDim3Value + "&LID=" + currentLID;
//Perform the request
xmlHttp7 = GetXmlHttpObject(GetAllowBuyReturn);
xmlHttp7.open("GET", url, true);
xmlHttp7.send(null);
}
}
function GetAllowBuyReturn()
{
//If xml http req is ready then inject
if (xmlHttp7.readyState == 4 || xmlHttp7.readyState == "complete")
{
var buyRow = document.getElementById(currentBuyRowID);
if (buyRow != null)
buyRow.style.display = xmlHttp7.responseText;
}
}
function GetStockText()
{
var stockLabel = document.getElementById(currentStockLabelID);
if (stockLabel != null)
{
//Set the wait indicator
stockLabel.innerHTML = '';
//Build the URL
var url = R + "Controls/Toolbox/GetStockText.aspx?ItemID=" + currentItemID + "&Dim1=" + currentDim1Value + "&Dim2=" + currentDim2Value + "&Dim3=" + currentDim3Value + "&LID=" + currentLID;
//Perform the request
xmlHttp1 = GetXmlHttpObject(GetStockTextReturn);
xmlHttp1.open("GET", url, true);
xmlHttp1.send(null);
}
}
function GetStockTextReturn()
{
//If xml http req is ready then inject
if (xmlHttp1.readyState == 4 || xmlHttp1.readyState == "complete")
{
var stockLabel = document.getElementById(currentStockLabelID);
if (stockLabel != null)
stockLabel.innerHTML = xmlHttp1.responseText;
}
}
function GetProdNo()
{
var prodNoLabel = document.getElementById(currentProdNoLabelID);
if (prodNoLabel != null)
{
//Set the wait indicator
prodNoLabel.innerHTML = '';
//Build the URL
var url = R + "Controls/Toolbox/GetProdNo.aspx?ItemID=" + currentItemID + "&Dim1=" + currentDim1Value + "&Dim2=" + currentDim2Value + "&Dim3=" + currentDim3Value;
//Perform the request
xmlHttp2 = GetXmlHttpObject(GetProdNoReturn);
xmlHttp2.open("GET", url, true);
xmlHttp2.send(null);
}
}
function GetProdNoReturn()
{
//If xml http req is ready then inject
if (xmlHttp2.readyState == 4 || xmlHttp2.readyState == "complete")
{
var prodNoLabel = document.getElementById(currentProdNoLabelID);
if (prodNoLabel != null)
prodNoLabel.innerHTML = xmlHttp2.responseText;
}
}
function GetPrice()
{
var priceLabel = document.getElementById(currentPriceLabelID);
if (priceLabel != null)
{
//Set the wait indicator
priceLabel.innerHTML = '';
//Build the URL
var url = R + "Controls/Toolbox/GetPrice.aspx?ItemID=" + currentItemID + "&Dim1=" + currentDim1Value + "&Dim2=" + currentDim2Value + "&Dim3=" + currentDim3Value + "&LID=" + currentLID + "&InclVAT=" + currentInclVAT + "&UserID=" + currentUserID;
//Perform the request
xmlHttp3 = GetXmlHttpObject(GetPriceReturn);
xmlHttp3.open("GET", url, true);
xmlHttp3.send(null);
}
}
function GetPriceReturn()
{
//If xml http req is ready then inject
if (xmlHttp3.readyState == 4 || xmlHttp3.readyState == "complete")
{
var priceLabel = document.getElementById(currentPriceLabelID);
if (priceLabel != null)
priceLabel.innerHTML = xmlHttp3.responseText;
}
}
function GetDiscountPrice()
{
var discPriceLabel = document.getElementById(currentDiscPriceLabelID);
if (discPriceLabel != null)
{
//Set the wait indicator
discPriceLabel.innerHTML = '';
//Build the URL
var url = R + "Controls/Toolbox/GetPrice.aspx?ItemID=" + currentItemID + "&Dim1=" + currentDim1Value + "&Dim2=" + currentDim2Value + "&Dim3=" + currentDim3Value + "&LID=" + currentLID + "&InclVAT=" + currentInclVAT + "&UserID=" + currentUserID + "&Type=discount";
//Perform the request
xmlHttp4 = GetXmlHttpObject(GetDiscountPriceReturn);
xmlHttp4.open("GET", url, true);
xmlHttp4.send(null);
}
}
function GetDiscountPriceReturn()
{
//If xml http req is ready then inject
if (xmlHttp4.readyState == 4 || xmlHttp4.readyState == "complete")
{
var discPriceLabel = document.getElementById(currentDiscPriceLabelID);
if (discPriceLabel != null)
discPriceLabel.innerHTML = xmlHttp4.responseText;
}
}
function GetOriginalPrice()
{
var origPriceLabel = document.getElementById(currentOrigPriceLabelID);
if (origPriceLabel != null)
{
//Set the wait indicator
origPriceLabel.innerHTML = '';
//Build the URL
var url = R + "Controls/Toolbox/GetPrice.aspx?ItemID=" + currentItemID + "&Dim1=" + currentDim1Value + "&Dim2=" + currentDim2Value + "&Dim3=" + currentDim3Value + "&LID=" + currentLID + "&InclVAT=" + currentInclVAT + "&UserID=" + currentUserID + "&Type=original";
//Perform the request
xmlHttp5 = GetXmlHttpObject(GetOriginalPriceReturn);
xmlHttp5.open("GET", url, true);
xmlHttp5.send(null);
}
}
function GetOriginalPriceReturn()
{
//If xml http req is ready then inject
if (xmlHttp5.readyState == 4 || xmlHttp5.readyState == "complete")
{
var origPriceLabel = document.getElementById(currentOrigPriceLabelID);
if (origPriceLabel != null)
origPriceLabel.innerHTML = xmlHttp5.responseText;
}
}
function GetImageURL()
{
var imgImage = document.getElementById("img" + currentItemID);
if (imgImage != null)
{
//Build the URL
var url = R + "Controls/Toolbox/GetImageID.aspx?ItemID=" + currentItemID + "&Dim1=" + currentDim1Value + "&Dim2=" + currentDim2Value + "&Dim3=" + currentDim3Value;
//Perform the request
xmlHttp6 = GetXmlHttpObject(GetImageURLReturn);
xmlHttp6.open("GET", url, true);
xmlHttp6.send(null);
}
}
function GetImageURLReturn()
{
//If xml http req is ready then inject
if (xmlHttp6.readyState == 4 || xmlHttp6.readyState == "complete")
{
var imgImage = document.getElementById("img" + currentItemID);
if (imgImage != null)
{
try
{
var iDimImageID = parseInt(xmlHttp6.responseText);
if (iDimImageID > 0)
{
imgImage.src = R + "ViewImage.aspx?ItemID=" + iDimImageID.toString() + "&width=" + currentImageWidth + "&" + currentCrop;
}
}
catch (Err) { }
}
}
}
function openImageWindow(itemID)
{
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');
win.focus;
}
function openFileWindow(itemID)
{
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');
win.focus;
}
function openLinkWindow(itemID)
{
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');
win.focus;
}
function SwitchArea(id) {
if(!document.getElementById) return;
var Area= document.getElementById(id);
if(Area.className=='Area_on') {
Area.className='Area_off';
}
else if(Area.className=='Area_off') {
Area.className = 'Area_on';
}
}
function SessionStorageObject(objectName) {
this.objectName = objectName;
this.clear = function () {
sessionStorage.setItem(this.objectName, JSON.stringify({}));
}
this.setValue = function (key, value) {
var sessionState = JSON.parse(sessionStorage.getItem(this.objectName));
sessionState[key] = value;
sessionStorage.setItem(this.objectName, JSON.stringify(sessionState));
}
this.getValue = function (key) {
var sessionState = JSON.parse(sessionStorage.getItem(this.objectName));
if (sessionState) {
return sessionState[key];
}
return undefined;
}
this.clear();
}
function reloadPageAsGet() {
var loc = window.location;
window.location = loc.protocol + '//' + loc.host + loc.pathname + loc.search;
}