// Downloaded from https://repo.progsbase.com - Code Developed Using progsbase. function generateBarcode(chars, height){ var w, h, i, barcodeNr, checksum; var c; var counterReference; var image; h = height; w = calculateWidth(chars); image = createImage(w, h, getWhite()); counterReference = {}; counterReference.doubleValue = 10; /* 128B start */ drawBarcodeSymbol(image, 104, h, counterReference); for(i = 0; i < chars.length; i = i + 1){ c = chars[i]; barcodeNr = asciiToNr(c); drawBarcodeSymbol(image, barcodeNr, h, counterReference); } /* Checksum */ checksum = calculateChecksum(chars); drawBarcodeSymbol(image, checksum, h, counterReference); /* Stop symbol */ drawBarcodeSymbol(image, 108, h, counterReference); counterReference.doubleValue = counterReference.doubleValue + 10; return image; } function calculateWidth(chars){ var width; width = 10 + 11 + chars.length*11 + 11 + 13 + 10; return width; } function calculateChecksum(chars){ var checksum, i, position, value; var c; checksum = 104*1; for(i = 0; i < chars.length; i = i + 1){ position = i + 1; c = chars[i]; value = asciiToNr(c); checksum = checksum + position*value; } return checksum%103; } function drawBarcodeSymbol(image, barcodeNr, h, counterReference){ var j, k, width; var widthCharacter; var widths; var next; var nextColor; widths = getWidths(barcodeNr); nextColor = getBlack(); next = true; for(j = 0; j < widths.length; j = j + 1){ widthCharacter = widths[j]; width = getDecimalFromSingleDecimalDigit(widthCharacter, 10); for(k = 0; k < width; k = k + 1){ drawVerticalLine1px(image, counterReference.doubleValue, 0, h - 1, nextColor); counterReference.doubleValue = counterReference.doubleValue + 1; } if(next){ nextColor = getWhite(); }else{ nextColor = getBlack(); } next = !next ; } } function getWidths(code){ var spaces; spaces = "".split(''); if(code == 0){ spaces = "212222".split(''); } if(code == 1){ spaces = "222122".split(''); } if(code == 2){ spaces = "222221".split(''); } if(code == 3){ spaces = "121223".split(''); } if(code == 4){ spaces = "121322".split(''); } if(code == 5){ spaces = "131222".split(''); } if(code == 6){ spaces = "122213".split(''); } if(code == 7){ spaces = "122312".split(''); } if(code == 8){ spaces = "132212".split(''); } if(code == 9){ spaces = "221213".split(''); } if(code == 10){ spaces = "221312".split(''); } if(code == 11){ spaces = "231212".split(''); } if(code == 12){ spaces = "112232".split(''); } if(code == 13){ spaces = "122132".split(''); } if(code == 14){ spaces = "122231".split(''); } if(code == 15){ spaces = "113222".split(''); } if(code == 16){ spaces = "123122".split(''); } if(code == 17){ spaces = "123221".split(''); } if(code == 18){ spaces = "223211".split(''); } if(code == 19){ spaces = "221132".split(''); } if(code == 20){ spaces = "221231".split(''); } if(code == 21){ spaces = "213212".split(''); } if(code == 22){ spaces = "223112".split(''); } if(code == 23){ spaces = "312131".split(''); } if(code == 24){ spaces = "311222".split(''); } if(code == 25){ spaces = "321122".split(''); } if(code == 26){ spaces = "321221".split(''); } if(code == 27){ spaces = "312212".split(''); } if(code == 28){ spaces = "322112".split(''); } if(code == 29){ spaces = "322211".split(''); } if(code == 30){ spaces = "212123".split(''); } if(code == 31){ spaces = "212321".split(''); } if(code == 32){ spaces = "232121".split(''); } if(code == 33){ spaces = "111323".split(''); } if(code == 34){ spaces = "131123".split(''); } if(code == 35){ spaces = "131321".split(''); } if(code == 36){ spaces = "112313".split(''); } if(code == 37){ spaces = "132113".split(''); } if(code == 38){ spaces = "132311".split(''); } if(code == 39){ spaces = "211313".split(''); } if(code == 40){ spaces = "231113".split(''); } if(code == 41){ spaces = "231311".split(''); } if(code == 42){ spaces = "112133".split(''); } if(code == 43){ spaces = "112331".split(''); } if(code == 44){ spaces = "132131".split(''); } if(code == 45){ spaces = "113123".split(''); } if(code == 46){ spaces = "113321".split(''); } if(code == 47){ spaces = "133121".split(''); } if(code == 48){ spaces = "313121".split(''); } if(code == 49){ spaces = "211331".split(''); } if(code == 50){ spaces = "231131".split(''); } if(code == 51){ spaces = "213113".split(''); } if(code == 52){ spaces = "213311".split(''); } if(code == 53){ spaces = "213131".split(''); } if(code == 54){ spaces = "311123".split(''); } if(code == 55){ spaces = "311321".split(''); } if(code == 56){ spaces = "331121".split(''); } if(code == 57){ spaces = "312113".split(''); } if(code == 58){ spaces = "312311".split(''); } if(code == 59){ spaces = "332111".split(''); } if(code == 60){ spaces = "314111".split(''); } if(code == 61){ spaces = "221411".split(''); } if(code == 62){ spaces = "431111".split(''); } if(code == 63){ spaces = "111224".split(''); } if(code == 64){ spaces = "111422".split(''); } if(code == 65){ spaces = "121124".split(''); } if(code == 66){ spaces = "121421".split(''); } if(code == 67){ spaces = "141122".split(''); } if(code == 68){ spaces = "141221".split(''); } if(code == 69){ spaces = "112214".split(''); } if(code == 70){ spaces = "112412".split(''); } if(code == 71){ spaces = "122114".split(''); } if(code == 72){ spaces = "122411".split(''); } if(code == 73){ spaces = "142112".split(''); } if(code == 74){ spaces = "142211".split(''); } if(code == 75){ spaces = "241211".split(''); } if(code == 76){ spaces = "221114".split(''); } if(code == 77){ spaces = "413111".split(''); } if(code == 78){ spaces = "241112".split(''); } if(code == 79){ spaces = "134111".split(''); } if(code == 80){ spaces = "111242".split(''); } if(code == 81){ spaces = "121142".split(''); } if(code == 82){ spaces = "121241".split(''); } if(code == 83){ spaces = "114212".split(''); } if(code == 84){ spaces = "124112".split(''); } if(code == 85){ spaces = "124211".split(''); } if(code == 86){ spaces = "411212".split(''); } if(code == 87){ spaces = "421112".split(''); } if(code == 88){ spaces = "421211".split(''); } if(code == 89){ spaces = "212141".split(''); } if(code == 90){ spaces = "214121".split(''); } if(code == 91){ spaces = "412121".split(''); } if(code == 92){ spaces = "111143".split(''); } if(code == 93){ spaces = "111341".split(''); } if(code == 94){ spaces = "131141".split(''); } if(code == 95){ spaces = "114113".split(''); } if(code == 96){ spaces = "114311".split(''); } if(code == 97){ spaces = "411113".split(''); } if(code == 98){ spaces = "411311".split(''); } if(code == 99){ spaces = "113141".split(''); } if(code == 100){ spaces = "114131".split(''); } if(code == 101){ spaces = "311141".split(''); } if(code == 102){ spaces = "411131".split(''); } if(code == 103){ spaces = "211412".split(''); } if(code == 104){ spaces = "211214".split(''); } if(code == 105){ spaces = "211232".split(''); } if(code == 106){ spaces = "233111".split(''); } if(code == 107){ spaces = "211133".split(''); } if(code == 108){ spaces = "2331112".split(''); } return spaces; } function asciiToNr(c){ var nr; nr = c.charCodeAt(0); return getAsciiToNrTable()[nr]; } function getAsciiToNrTable(){ var c; c = []; c.length = 210 + 1; c[32] = 0; c[33] = 1; c[34] = 2; c[35] = 3; c[36] = 4; c[37] = 5; c[38] = 6; c[39] = 7; c[40] = 8; c[41] = 9; c[42] = 10; c[43] = 11; c[44] = 12; c[45] = 13; c[46] = 14; c[47] = 15; c[48] = 16; c[49] = 17; c[50] = 18; c[51] = 19; c[52] = 20; c[53] = 21; c[54] = 22; c[55] = 23; c[56] = 24; c[57] = 25; c[58] = 26; c[59] = 27; c[60] = 28; c[61] = 29; c[62] = 30; c[63] = 31; c[64] = 32; c[65] = 33; c[66] = 34; c[67] = 35; c[68] = 36; c[69] = 37; c[70] = 38; c[71] = 39; c[72] = 40; c[73] = 41; c[74] = 42; c[75] = 43; c[76] = 44; c[77] = 45; c[78] = 46; c[79] = 47; c[80] = 48; c[81] = 49; c[82] = 50; c[83] = 51; c[84] = 52; c[85] = 53; c[86] = 54; c[87] = 55; c[88] = 56; c[89] = 57; c[90] = 58; c[91] = 59; c[92] = 60; c[93] = 61; c[94] = 62; c[95] = 63; c[96] = 64; c[97] = 65; c[98] = 66; c[99] = 67; c[100] = 68; c[101] = 69; c[102] = 70; c[103] = 71; c[104] = 72; c[105] = 73; c[106] = 74; c[107] = 75; c[108] = 76; c[109] = 77; c[110] = 78; c[111] = 79; c[112] = 80; c[113] = 81; c[114] = 82; c[115] = 83; c[116] = 84; c[117] = 85; c[118] = 86; c[119] = 87; c[120] = 88; c[121] = 89; c[122] = 90; c[123] = 91; c[124] = 92; c[125] = 93; c[126] = 94; c[200] = 95; c[201] = 96; c[202] = 97; c[203] = 98; c[204] = 99; c[205] = 100; c[206] = 101; c[207] = 102; c[208] = 103; c[209] = 104; c[210] = 105; return c; } function getBlack(){ var black; black = {}; black.a = 1; black.r = 0; black.g = 0; black.b = 0; return black; } function getWhite(){ var white; white = {}; white.a = 1; white.r = 1; white.g = 1; white.b = 1; return white; } function createImage(w, h, color){ var image; var i, j; image = {}; image.x = []; image.x.length = w; for(i = 0; i < w; i = i + 1){ image.x[i] = {}; image.x[i].y = []; image.x[i].y.length = h; for(j = 0; j < h; j = j + 1){ image.x[i].y[j] = {}; dp(image, i, j, color); } } return image; } function dp(image, x, y, color){ image.x[x].y[y].a = color.a; image.x[x].y[y].r = color.r; image.x[x].y[y].g = color.g; image.x[x].y[y].b = color.b; } function drawHorizontalLine1px(image, x, y, lengthx, color){ var i; for(i = 0; i < lengthx; i = i + 1){ dp(image, x + i, y, color); } } function drawVerticalLine1px(image, x, y, height, color){ var i; for(i = 0; i < height; i = i + 1){ dp(image, x, y + i, color); } } function drawRectangle1px(image, x, y, height, width, color){ drawHorizontalLine1px(image, x, y, width, color); drawVerticalLine1px(image, x, y, height, color); drawHorizontalLine1px(image, x, y + height, width, color); drawVerticalLine1px(image, x + width, y, height, color); } function decimalToString(decimal){ return numberToString(decimal, 10); } function numberToString(decimal, base){ var string; var digits; var digitPosition; var hasPrintedPoint; var i, d; string = []; string.length = 0; digits = getDigits(base); /* Find digitPosition: */ digitPosition = getDigitPosition(decimal, base); decimal = Math.round(decimal*Math.pow(base, -digitPosition + digits - 1)); hasPrintedPoint = false; /* Print leading zeros. */ if(digitPosition < 0){ string = appendCharacter(string, '0'); string = appendCharacter(string, '.'); hasPrintedPoint = true; for(i = 0; i < -digitPosition - 1; i = i + 1){ string = appendCharacter(string, '0'); } } /* Print number. */ for(i = 0; i < digits; i = i + 1){ d = Math.floor(decimal/Math.pow(base, digits - i - 1)); if( !hasPrintedPoint && digitPosition - i + 1 == 0){ if(decimal != 0){ string = appendCharacter(string, '.'); } hasPrintedPoint = true; } if(decimal == 0 && hasPrintedPoint){ }else{ string = appendCharacter(string, getSingleDigitFromNumber(d, base)); } decimal = decimal - d*Math.pow(base, digits - i - 1); } /* Print trailing zeros. */ for(i = 0; i < digitPosition - digits + 1; i = i + 1){ string = appendCharacter(string, '0'); } /* Done */ return string; } function getDigits(base){ var t; t = Math.pow(10, 15); return Math.floor(Math.log10(t)/Math.log10(base)); } function getDigitPosition(decimal, base){ var power; var t; power = Math.ceil(Math.log10(decimal)/Math.log10(base)); t = decimal*Math.pow(base, -power); if(t < base && t >= 1){ }else if(t >= base){ power = power + 1; }else if(t < 1){ power = power - 1; } return power; } function getSingleDigitFromNumber(c, base){ var numberTable; var retc; numberTable = getNumberTable(); if(c > base - 1){ retc = '?'; }else{ retc = numberTable[c]; } return retc; } function getNumberTable(){ var numberTable; numberTable = []; numberTable.length = 16; numberTable[0] = '0'; numberTable[1] = '1'; numberTable[2] = '2'; numberTable[3] = '3'; numberTable[4] = '4'; numberTable[5] = '5'; numberTable[6] = '6'; numberTable[7] = '7'; numberTable[8] = '8'; numberTable[9] = '9'; numberTable[10] = 'A'; numberTable[11] = 'B'; numberTable[12] = 'C'; numberTable[13] = 'D'; numberTable[14] = 'E'; numberTable[15] = 'F'; return numberTable; } function stringToDecimal(string){ return stringToDecimalForBase(string, 10); } function stringToDecimalForBase(string, base){ var stringToDecimalResult; var c; var i, j; var isPositive; var beforeDecimalPoint; var afterDecimalPoint; var n; var validCharacters; var d; stringToDecimalResult = {}; stringToDecimalResult.success = true; i = 0; isPositive = true; beforeDecimalPoint = 0; afterDecimalPoint = 0; n = 0; validCharacters = 0; if(base >= 2 && base <= 16){ for(j = 0; j < string.length; j = j + 1){ c = string[j]; if(isNumber(c, base) || c == '.' || c == '-'){ validCharacters = validCharacters + 1; } } if(validCharacters == string.length){ if(string.length > 0){ c = string[i]; if(c == '-'){ isPositive = false; i = i + 1; } if(i < string.length){ c = string[i]; if(isNumber(c, base)){ for(; isNumber(c, base) && (i < string.length); ){ beforeDecimalPoint = beforeDecimalPoint + 1; i = i + 1; if(i < string.length){ c = string[i]; } } if(i < string.length){ c = string[i]; if(c == '.'){ i = i + 1; if(i < string.length){ c = string[i]; for(; isNumber(c, base) && (i < string.length); ){ afterDecimalPoint = afterDecimalPoint + 1; i = i + 1; if(i < string.length){ c = string[i]; } } }else{ stringToDecimalResult.success = false; stringToDecimalResult.feilmelding = "Number must have digits after the decimal point.".split(''); } } } }else{ stringToDecimalResult.success = false; stringToDecimalResult.feilmelding = "Number must start with digits (for negative numbers, after the optional negative sign).".split(''); } } if(stringToDecimalResult.success != false){ i = 0; if( !isPositive ){ i = 1; } for(j = 0; j < beforeDecimalPoint; j = j + 1){ c = string[i]; i = i + 1; d = getDecimalFromSingleDecimalDigit(c, base); n = n + d*Math.pow(base, beforeDecimalPoint - j - 1); } if(afterDecimalPoint > 0){ i = i + 1; for(j = 0; j < afterDecimalPoint; j = j + 1){ c = string[i]; i = i + 1; d = getDecimalFromSingleDecimalDigit(c, base); n = n + d*Math.pow(base, 0 - j - 1); } } if( !isPositive ){ n = -n; } stringToDecimalResult.result = n; stringToDecimalResult.success = true; } }else{ stringToDecimalResult.success = false; stringToDecimalResult.feilmelding = "String has no content.".split(''); } }else{ stringToDecimalResult.success = false; stringToDecimalResult.feilmelding = "String contains invalid character.".split(''); } }else{ stringToDecimalResult.success = false; stringToDecimalResult.feilmelding = "Base must be from 2 to 16.".split(''); } return stringToDecimalResult; } function getDecimalFromSingleDecimalDigit(c, base){ var numberTable; var i; var position; numberTable = getNumberTable(); position = 0; for(i = 0; i < base; i = i + 1){ if(numberTable[i] == c){ position = i; } } return position; } function isNumber(c, base){ var numberTable; var i; var found; numberTable = getNumberTable(); found = false; for(i = 0; i < base; i = i + 1){ if(numberTable[i] == c){ found = true; } } return found; } function stringToNumberArray(string){ var i; var array; array = []; array.length = string.length; for(i = 0; i < string.length; i = i + 1){ array[i] = string[i].charCodeAt(0); } return array; } function numberArrayToString(array){ var i; var string; string = []; string.length = array.length; for(i = 0; i < array.length; i = i + 1){ string[i] = String.fromCharCode(array[i]); } return string; } function stringsEqual(data1, data2){ var equal; var nrEqual, i; equal = false; if(data1.length == data2.length){ nrEqual = 0; for(i = 0; i < data1.length; i = i + 1){ if(data1[i] == data2[i]){ nrEqual = nrEqual + 1; } } if(nrEqual == data1.length){ equal = true; } }else{ equal = false; } return equal; } function numberArraysEqual(data1, data2){ var equal; var nrEqual, i; equal = false; if(data1.length == data2.length){ nrEqual = 0; for(i = 0; i < data1.length; i = i + 1){ if(data1[i] == data2[i]){ nrEqual = nrEqual + 1; } } if(nrEqual == data1.length){ equal = true; } }else{ equal = false; } return equal; } function substring(string, from, to){ var n; var i; n = []; n.length = to - from; for(i = from; i < to; i = i + 1){ n[i - from] = string[i]; } return n; } function appendString(string, s){ var newString; var i; newString = []; newString.length = string.length + s.length; for(i = 0; i < string.length; i = i + 1){ newString[i] = string[i]; } for(i = 0; i < s.length; i = i + 1){ newString[string.length + i] = s[i]; } delete(string); return newString; } function appendCharacter(string, c){ var newString; var i; newString = []; newString.length = string.length + 1; for(i = 0; i < string.length; i = i + 1){ newString[i] = string[i]; } newString[string.length] = c; delete(string); return newString; } function split(toSplit, splitBy){ var splitt; var next; var i; var c; var n; splitt = []; splitt.length = 0; next = []; next.length = 0; for(i = 0; i < toSplit.length; i = i + 1){ c = toSplit[i]; if(c == splitBy){ n = {}; n.string = next; splitt = addString(splitt, n); next = []; next.length = 0; }else{ next = appendCharacter(next, c); } } if(next.length > 0){ n = {}; n.string = next; splitt = addString(splitt, n); } return splitt; } function addDecimal(list, a){ var newlist; var i; newlist = []; newlist.length = list.length + 1; for(i = 0; i < list.length; i = i + 1){ newlist[i] = list[i]; } newlist[list.length] = a; delete(list); return newlist; } function addDecimalRef(list, i){ list.list = addDecimal(list.list, i); } function removeDecimal(list, n){ var newlist; var i; newlist = []; newlist.length = list.length - 1; for(i = 0; i < list.length; i = i + 1){ if(i < n){ newlist[i] = list[i]; } if(i > n){ newlist[i - 1] = list[i]; } } delete(list); return newlist; } function getDecimalRef(list, i){ return list.list[i]; } function removeDecimalRef(list, i){ list.list = removeDecimal(list.list, i); } function addString(list, a){ var newlist; var i; newlist = []; newlist.length = list.length + 1; for(i = 0; i < list.length; i = i + 1){ newlist[i] = list[i]; } newlist[list.length] = a; delete(list); return newlist; } function addStringRef(list, i){ list.list = addString(list.list, i); } function removeString(list, n){ var newlist; var i; newlist = []; newlist.length = list.length - 1; for(i = 0; i < list.length; i = i + 1){ if(i < n){ newlist[i] = list[i]; } if(i > n){ newlist[i - 1] = list[i]; } } delete(list); return newlist; } function getStringRef(list, i){ return list.list[i]; } function removeStringRef(list, i){ list.list = removeString(list.list, i); }