/*
 * DEXTUploadX5 - common library
 * http://www.dextsolution.com
 *
 * Copyright ⓒ DEXTSolution Inc.
 */
function combinePath(prev, next) { var bpi = prev.lastIndexOf("/") == (prev.length - 1); var bni = next.indexOf("/") == 0; if (bpi && bni) return prev + next.substring(1); else if (bpi && !bni) return prev + next; else if (!bpi && bni) return prev + next; else return prev + "/" + next; } function AXFiltering() { if (false == (!!document.documentMode)) { return "unsupported"; }     if (typeof window.external.msActiveXFilteringEnabled == "unknown") {   if (window.external.msActiveXFilteringEnabled()) { return true;
} else { return false; } } else {   return false; } } function isDefined(t) { return typeof(t) != "undefined"; } function trim(str) {  return str ? str.replace(/(^\s*)|(\s*$)/gi, "") : ""; } function sformat(fmt, reps) { var s = fmt; for (var i = 0; i < reps.length; i++) { var rex = new RegExp("\\{" + i + "\\}", "gm"); s = s.replace(rex, reps[i]); } return s; }; function getIdSharp(id, use) { var sharp = (id && id.indexOf("#") == 0) ? true : false; if (sharp && use) return id; else if (sharp && !use) return id.substring(1); else if (!sharp && use) return "#" + id;
else return id; } function addClass(target, cname) { var tcls = target.className; var tokens = tcls.split(" "); tokens.push(cname); target.className = tokens.join(" "); } function removeClass(target, rname) { var tcls = target.className; var tokens = tcls.split(" "); for (var i = 0; i < tokens.length; i++) { if (rname == tokens[i]) { tokens.splice(i, 1); break; } } target.className = tokens.join(" "); } function compareVersion(vera, verb) { var tokenA = vera.split(/\./); var tokenB = verb.split(/\./); for (var i = 0, len = Math.max(tokenA.length, tokenB.length), va = 0, vb = 0; i < len; i++) {
va = i < tokenA.length ? parseInt(tokenA[i]) : 0; vb = i < tokenB.length ? parseInt(tokenB[i]) : 0; if (va < vb) return -1; else if (va > vb) return 1; else continue; } return 0; } var ResourceBundle = function () { this.bundle = null; }; ResourceBundle.prototype.init = function (bundle) { this.bundle = bundle; }; ResourceBundle.prototype.get = function (key, defVal) { if (this.bundle[key] != undefined) return this.bundle[key]; else if (defVal) return defVal; else return null; }; function isFileList(inst) { return (inst instanceof FileList || Object.prototype.toString.call(inst) === "[object FileList]");
} function isFile(inst) { return (inst instanceof File || inst instanceof Blob || Object.prototype.toString.call(inst) === "[object File]"); } function ab2str(ab, encoding) { if ("TextDecoder" in window) { var dataView = new DataView(ab); var decoder = new TextDecoder(encoding); return decoder.decode(dataView); } else {   console.log("Your browser doesn't support the text encoding API."); return String.fromCharCode.apply(null, new Uint8Array(ab)); } } function xml2str(src) { if (isDefined(src.xml)) return src.xml; else if (isDefined(src.innerHTML)) return src.innerHTML;
else if (isDefined(src.documentElement)) { if (isDefined(src.documentElement.xml)) return src.documentElement.xml; if (isDefined(src.documentElement.innerHTML)) return src.documentElement.innerHTML; else if ("XMLSerializer" in window) { var serializer = new XMLSerializer(); return serializer.serializeToString(src); } else return src; } else return src; } function dic2kvList(dic) { var lst = []; if (dic) { for (var key in dic) { lst.push(encodeURIComponent(key) + "=" + encodeURIComponent(dic[key])); }
} return lst; } function configureXHR(xhr, method, requestHeaders, returnType, callbackFunctions) { if (!xhr || !returnType || !callbackFunctions) return; if (method === "POST") xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); if (requestHeaders) for (var h in requestHeaders) { xhr.setRequestHeader(h, requestHeaders[h]); }   if (returnType == "blob") xhr.responseType = "blob"; else if (returnType == "json") xhr.responseType = "json"; else if (returnType == "xml") { xhr.overrideMimeType('text/xml'); xhr.responseType = "document";
} else if (returnType == "buffer") xhr.responseType = "arraybuffer"; else xhr.responseType = "text"; var funcReady = function (evt) {   if (xhr.readyState == this.HEADERS_RECEIVED) { if (callbackFunctions && typeof callbackFunctions.header == "function") { callbackFunctions.header(); }               } }; var funcStart = function (evt) { if (callbackFunctions && typeof callbackFunctions.start == "function") { callbackFunctions.start(evt); } }; var funcProgress = function (evt) { if (callbackFunctions && typeof callbackFunctions.progress == "function") { callbackFunctions.progress(evt);
} }; var funcAbort = function (evt) { if (callbackFunctions && typeof callbackFunctions.abort == "function") { callbackFunctions.abort(); } }; var funcError = function (evt) { if (callbackFunctions && typeof callbackFunctions.error == "function") {         callbackFunctions.error(xhr.status, evt.message); } }; var funcTimeout = function (evt) { if (callbackFunctions && typeof callbackFunctions.timeout == "function") { callbackFunctions.timeout(); } }; var funcLoad = function (evt) { if (xhr.status < 400) { if (callbackFunctions && typeof callbackFunctions.load == "function") {
if (method === "HEAD") {             callbackFunctions.load(""); } else {   switch (xhr.responseType) { case "arraybuffer": callbackFunctions.load(xhr.response); break; case "document": callbackFunctions.load(xhr.responseXML); break; case "json": callbackFunctions.load(xhr.response); break; case "blob": callbackFunctions.load(xhr.response); break; default: callbackFunctions.load(xhr.responseText); break; } } } } else { if (callbackFunctions && typeof callbackFunctions.error == "function") {     var contentType = xhr.getResponseHeader("Content-Type"); if (contentType && contentType.indexOf("text/") == 0) {
    if (xhr.responseType == "blob") { var fr = new FileReader(); var frLoad = function (frevt) { var errbody = frevt.target.result; fr.removeEventListener("load", frLoad); callbackFunctions.error(xhr.status, errbody); }; fr.addEventListener("load", frLoad); fr.readAsText(xhr.response); } else if (xhr.responseType == "arraybuffer") {   var errbody = ab2str(!xhr.response ? [] : xhr.response, "utf-8"); callbackFunctions.error(xhr.status, errbody); } else if (xhr.responseType == "json") {   callbackFunctions.error(xhr.status, !xhr.response ? "Check the response body from the browser network tab in development mode." : xhr.response); } else if (xhr.responseType == "document") {
callbackFunctions.error(xhr.status, xml2str(xhr.response)); } else { callbackFunctions.error(xhr.status, xhr.response); } } else { callbackFunctions.error(xhr.status, xhr.response); } } } }; var funcEnd = function (evt) { xhr.removeEventListener("readystatechange", funcReady); xhr.removeEventListener("loadstart", funcStart); xhr.removeEventListener("progress", funcProgress); xhr.removeEventListener("error", funcError); xhr.removeEventListener("abort", funcAbort); xhr.removeEventListener("timeout", funcTimeout); xhr.removeEventListener("load", funcLoad);
xhr.removeEventListener("loadend", funcEnd); }; xhr.addEventListener("readystatechange", funcReady, false); xhr.addEventListener("loadstart", funcStart, false); xhr.addEventListener("progress", funcProgress, false); xhr.addEventListener("abort", funcAbort, false); xhr.addEventListener("error", funcError, false); xhr.addEventListener("timeout", funcTimeout, false); xhr.addEventListener("load", funcLoad, false); xhr.addEventListener("loadend", funcEnd, false); } function AJAX(url, method, callbacks, ret, data, headers, credential, async) { var xhr = (typeof XMLHttpRequest !== "undefined") ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"),
  query = dic2kvList(data),   url = method.toUpperCase() != "POST" ? url + (query.length > 0 ? "?" + query.join("&") : "") : url;   xhr["method"] = method.toUpperCase(); xhr.open(xhr["method"], url, async);           xhr.withCredentials = (credential === true);   xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); configureXHR(xhr, xhr["method"], headers, ret, callbacks);   xhr.send((xhr["method"] == "POST" && query.length > 0) ? query.join("&") : null);   return xhr; } function getFileExtension(source) { if (!source) return "";
var lindex = source.lastIndexOf("."); return (lindex >= 0) ? source.substring(lindex) : ""; } function getLastPath(url) { if (!url) return ""; var lindex = url.lastIndexOf("/"); if (lindex < 0) return url; if (lindex == (url.length - 1)) return ""; else return url.substring(lindex + 1); } function getParentPath(url) { if (!url) return ""; var lindex = url.lastIndexOf("/"); if (lindex < 0) return url; return url.substring(0, lindex); } function clonejson(source, useFunc) { var cloned = {}; for (var p in source) { if (typeof source[p] == "function") {
if (useFunc) cloned[p] = source[p]; } else { cloned[p] = source[p]; } } return cloned; } function cloneArray(source) { var cloned = []; for (var i = 0, len = source.length; i < len; i++) { cloned.push(source[i]); } return cloned; } function getFriendlySize(size, points) { if (size == 0) return "0 byte"; points = points || 1; for (var units = [" bytes", " KB", " MB", " GB", " TB"], i = 0; i < units.length; i++) { if (parseInt(size / 1024) == 0) { return (i > 0 ? size.toFixed(points) : size) + units[i]; } else {
size = size / 1024; } } } function getFriendlySpeed(speed, points) { if (speed == 0) return "0 B/s"; points = points || 1; for (var units = [" B/s", " KB/s", " MB/s", " GB/s", " TB/s"], i = 0; i < units.length; i++) { if (parseInt(speed / 1024) == 0) { return (i > 0 ? speed.toFixed(points) : speed) + units[i]; } else { speed = speed / 1024; } } } function msecToTimeFormat(duration, useMillisec) { if (duration == Infinity) { return "Infinity"; } else if (duration == 0) { return "00:00:00" + (useMillisec ? ".000" : ""); } else {
var ms = duration % 1000; duration = duration === 0 ? 0 : (duration - ms) / 1000; var sec = duration % 60; duration = duration === 0 ? 0 : (duration - sec) / 60; var min = duration % 60; duration = duration === 0 ? 0 : (duration - min) / 60; var hr = duration; return "" + ("00" + hr).substring(hr.toString().length) + ":" + ("00" + min).substring(min.toString().length) + ":" + ("00" + sec).substring(sec.toString().length) + (useMillisec ? "." + ("000" + ms).substring(ms.toString().length) : ""); } }
function getRadians(degrees) { return degrees * Math.PI / 180; } function getDegrees(radians) { return radians * 180 / Math.PI; } function formatedDateTypeA(dt) { var y = "" + dt.getFullYear(), M = "" + (dt.getMonth() + 1), d = "" + dt.getDate(), h = "" + dt.getHours(), m = "" + dt.getMinutes(), s = "" + dt.getSeconds(); if (M.length < 2) M = '0' + M; if (d.length < 2) d = '0' + d; return [y, M, d].join('-') + " " + [h, m, s].join(":"); } var USER_DATA_TYPE = { UNDEFINED: "undefined", STRING: "string", BOOLEAN: "boolean",
NUMBER: "number", INTEGER: "integer", INTEGER_WITH_ZERO: "integer_zero", INTEGER_WITH_ONE: "integer_one", INTEGER_WITH_MINUSONE: "integer_minusone" }; function checkStrongDataType(hope, target) { if (typeof (target) === "undefined") { return (hope == USER_DATA_TYPE.UNDEFINED); } switch (hope) { case USER_DATA_TYPE.STRING: if (typeof(target) === "string" && target.length > 0) return true; else return false;     case USER_DATA_TYPE.STRING_WITH_EMPTY: if (typeof(target) === "string" && target.length >= 0) return true; else return false;
    case USER_DATA_TYPE.BOOLEAN: if (target === true || target === false) return true; else return false; case USER_DATA_TYPE.NUMBER: if (typeof(target) === "number" && isFinite(target)) return true; else return true;     case USER_DATA_TYPE.INTEGER_PLUS: if (typeof(target) === "number" && isFinite(target)) return (target - parseInt(target, 10)) == 0 && target > 0; else return false;       case USER_DATA_TYPE.INTEGER_WITH_ZERO: if (typeof(target) === "number" && isFinite(target)) return (target - parseInt(target, 10)) == 0 && target >= 0; else return false;
        case USER_DATA_TYPE.INTEGER_WITH_ONE: if (typeof(target) === "number" && isFinite(target)) return (target - parseInt(target, 10)) == 0 && target >= 1; else return false;         case USER_DATA_TYPE.INTEGER_WITH_MINUSONE: if (typeof(target) === "number" && isFinite(target)) return (target - parseInt(target, 10)) == 0 && target >= -1; else return false;         } return false; } var SETOPS = {   minus: function (a, b) { return a.filter(function (x) { return b.indexOf(x) < 0; }); },   union: function (a, b) {  var u = [];
a.forEach(function (v, i) {  if (b.indexOf(v) < 0) { u.push(v); } }); b.forEach(function (v, i) {  if (u.indexOf(v) < 0) { u.push(v); } }); return u; },   intersect: function (a, b) { return a.filter(function (x) { return b.indexOf(x) >= 0; }); } }; function isHexaColor(color) { return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color); } function hexColorToRgba(color, alpha) { var c = color.replace('#', '').split(''); var r, g, b; if (c.length == 3) { c = [c[0], c[0], c[1], c[1], c[2], c[2]]; } c = c.join(''); r = parseInt(c.substring(0, 2), 16);
g = parseInt(c.substring(2, 4), 16); b = parseInt(c.substring(4, 6), 16); return sformat("rgba({0}, {1}, {2}, {3})", [r, g, b, alpha]); } function compareNumber(a, b) { if (typeof a == "number" && typeof b == "number") return a - b;       a = parseFloat((a + "").replace(/[,\s\xA0]+/g, "")); b = parseFloat((b + "").replace(/[,\s\xA0]+/g, "")); if (isNaN(a) || isNaN(b)) throw new Error("DX5: The parameters passed to the 'sortByNumber' function are not numbers."); return a - b; } function compareString(a, b) { a = (a + "");
b = (b + ""); return a.localeCompare(b); } function getPageLang() { var lang = navigator.language || navigator.browserLanguage || navigator.systemLanguage; return lang ? lang.split("-")[0] : ""; } function applyParamToObject(objtag, name, value) { var paramtag = document.createElement("param"); paramtag.setAttribute("name", name); paramtag.setAttribute("value", value); objtag.appendChild(paramtag); } function extend(a, b, useFunc) { if (!b) return; for (var p in b) { if (typeof b[p] == "function") { if (useFunc) a[p] = b[p];
} else { a[p] = b[p]; } } } 