var JMain = function () { return this.Init(); } JMain.Obj = JMain.prototype = { "Data": [], "Object": { "GetType": function (obj) { var regex = /function (.{1,})\(/; var results = (regex).exec((obj).constructor.toString()); return (results && results.length > 1) ? results[1] : ""; } }, "Events": { "Add": function (element, eventType, func) { if (element.addEventListener) element.addEventListener(eventType, func, false); else if (element.attachEvent) element.attachEvent("on" + eventType, func); else element["on" + eventType] = func; }, "Remove": function (element, eventType, func) { if (element.removeEventListener) element.removeEventListener(eventType, func, false); else if (element.detachEvent) element.detachEvent("on" + eventType, func); else element["on" + eventType] = null; } }, "Elements": { "GetById": function (elementId) { if (elementId == undefined || elementId == null) return null; return typeof (elementId) == "string" ? document.getElementById(elementId) : (typeof (elementId) == "object" ? elementId : null); }, "GetDimensions": function (element) { var el = jm.el(element); if (!el) return null; var width = el.offsetWidth, height = el.offsetHeight, left = 0, top = 0, scrollTop=0, scrollLeft=0, zIndex = 0, transXregex = /\.*translateX\((.*)px\)/i, transYregex = /\.*translateY\((.*)px\)/i; while (el) { var transX = 0, transY = 0; if (el.style.transform) { var x = transXregex.exec(el.style.transform), y = transYregex.exec(el.style.transform); if (x && x.length > 1) transX = parseInt(x[1]); if (y && y.length > 1) transY = parseInt(y[1]); if (isNaN(transX)) transX = 0; if (isNaN(transY)) transY = 0; } left += el.offsetLeft + transX; top += el.offsetTop + transY; if (el.tagName.toLowerCase() == "body") { scrollTop += jm.Window.Document.ScrollTop(); scrollLeft += jm.Window.Document.ScrollLeft(); } else { scrollTop += el.scrollTop; scrollLeft += el.scrollLeft; } if (el.style.zIndex > zIndex) zIndex = el.style.zIndex; el = el.offsetParent; } return { Width: width, Height: height, Left: left, Top: top, zIndex: zIndex, scrollTop: scrollTop, scrollLeft: scrollLeft }; }, "GetOpacity": function (element, nullIfNothing) { var el = jm.el(element); if (!el) return 0; if (el.style.opacity && el.style.opacity.length > 0) { var opacity = parseFloat(el.style.opacity); return isNaN(opacity) ? 1 : opacity; } else if (el.style.filter && el.style.filter.length > 0) { var opacity = parseFloat(el.style.filter.toLowerCase().Replace("alpha", "").Replace("opacity", "").Replace("=", "").Replace(" ", "").Replace("(", "").Replace(")", "").ToNumeric()); return isNaN(opacity) ? 1 : opacity / 100; } return nullIfNothing ? null : 1; }, "SetOpacity": function (element, value) { try { var el = jm.el(element); if (!el) return; if (jm.Browser.IE && jm.Browser.Version < 10) { if (value >= 1) el.style.removeAttribute("filter"); else el.style.filter = "alpha(opacity=" + jm.Text.Replace((value < 0 ? 0 : (value * 100)).toString(), ",", ".") + ")"; } else el.style.opacity = value < 0 ? 0 : (value > 1 ? 1 : value); } catch (ex) { } }, "RemoveOpacity": function (element) { try { var el = jm.el(element); if (!el) return; if (el.style.removeProperty) { el.style.removeProperty("opacity"); el.style.removeProperty("filter"); } if (el.style.removeAttribute) { el.style.removeAttribute("opacity"); el.style.removeAttribute("filter"); } } catch (ex) { } }, "AddAttribute": function (element, name, value) { if (element) { var attr = element.hasAttribute(name) ? element.getAttribute(name) : ""; attr = value + (attr != null && (attr.toString() != "" && (!attr.toString().trim || attr.toString().trim() != "")) ? attr : ""); element.setAttribute(name, attr); } }, "GetScrollingParent": function (element) { var el = jm.el(element); if (!el) return null; while (el != null) { if (el.style && (el.style.overflow == "auto" || el.style.overflow == "scroll" || el.style.overflowY == "auto" || el.style.overflowY == "scroll")) return el; el = el.parentElement; } return null; }, "PreventDefault": function (e) { if (!e) e = window.event; if (!e) return; if (e.preventDefault) e.preventDefault(); e.returnValue = false; } }, "Window": { "_windowFocused": true, "_anyRtbFocused": false, "Focused": function () { return jm.Window._windowFocused || jm.Window._anyRtbFocused; }, "Height": function () { var elHeight = 0, bodyHeight = 0; if (document.body) bodyHeight = document.body.offsetHeight; if (document.documentElement) elHeight = document.documentElement.offsetHeight; return Math.max(elHeight, bodyHeight); }, "Width": function () { var elWidth = 0, bodyWidth = 0; if (document.body) bodyWidth = document.body.offsetWidth; if (document.documentElement) elWidth = document.documentElement.offsetWidth; return Math.max(elWidth, bodyWidth); }, "Subscribe": { "Data": [], "Add": function (uniqueName, parameters) { this.Data[uniqueName] = parameters; }, "Delete": function (uniqueName) { this.Data[uniqueName] = null; }, "Scroll": function () { jm.Window.Subscribe.EventAct("scroll"); }, "Resize": function () { jm.Window.Subscribe.EventAct("resize"); }, "Focus": function () { jm.Window._windowFocused = true; if (jm.Window._anyRtbFocused) return; jm.Window.Subscribe.EventAct("focus"); }, "Blur": function () { setTimeout(function () { jm.Window._windowFocused = false; if (jm.Data["RTB"]) for (var id in jm.Data["RTB"]) { var rtb = jm.Data["RTB"][id]; if (rtb && rtb.Focused) { jm.Window._anyRtbFocused = true; return; } } jm.Window.Subscribe.EventAct("blur"); }, 20); }, "EventAct": function (type) { type = type.toLowerCase(); for (var uniqueName in this.Data) if (this.Data[uniqueName] != null) { var params = this.Data[uniqueName]; for (var n in params) if (params[n][0].toLowerCase() == type && params[n][1] != null) params[n][1](); } } }, "Document": { "Height": function () { var elHeight = 0, bodyHeight = 0; if (document.body) { bodyHeight = Math.max(document.body.scrollHeight, document.body.offsetHeight, document.body.clientHeight); } if (document.documentElement) { elHeight = Math.max(document.documentElement.scrollHeight, document.documentElement.offsetHeight, document.documentElement.clientHeight); } return Math.max(elHeight, bodyHeight); }, "Width": function () { var elWidth = 0, bodyWidth = 0; if (document.body) { bodyWidth = Math.max(document.body.scrollWidth, document.body.offsetWidth, document.body.clientWidth); } if (document.documentElement) { elWidth = Math.max(document.documentElement.scrollWidth, document.documentElement.offsetWidth, document.documentElement.clientWidth); } return Math.max(elWidth, bodyWidth); }, "ScrollTop": function () { var yOffset = window.pageYOffset; if (yOffset != undefined) return yOffset; var elTop = 0, bodyTop = 0; if (document.body) { bodyTop = document.body.scrollTop; } if (document.documentElement) { elTop = document.documentElement.scrollTop; } return Math.max(elTop, bodyTop); }, "ScrollLeft": function () { var xOffset = window.pageXOffset; if (xOffset != undefined) return xOffset; var elTop = 0, bodyTop = 0; if (document.body) { bodyLeft = document.body.scrollLeft; } if (document.documentElement) { elLeft = document.documentElement.scrollLeft; } return Math.max(elLeft, bodyLeft); }, "SubscriptionScrollX": [], "SubscriptionScrollY": [], "_prevPageOffsetX": 0, "_prevPageOffsetY": 0, "InitSubscription": function () { var obj = null; if (window && (typeof window.onscroll != "undefined")) obj = window; else if (document.body) obj = document.body; if (!obj) setTimeout("jm.Window.Document.InitSubscription();", 100); else jm.Events.Add(obj, "scroll", function () { var xOffset = jm.Window.Document.ScrollLeft(), yOffset = jm.Window.Document.ScrollTop(); if (xOffset != undefined && xOffset != jm.Window.Document._prevPageOffsetX) { jm.Window.Document._prevPageOffsetX = xOffset; for (var key in jm.Window.Document.SubscriptionScrollX) if (jm.Window.Document.SubscriptionScrollX[key] != null) jm.Window.Document.SubscriptionScrollX[key](xOffset); } if (yOffset != undefined && yOffset != jm.Window.Document._prevPageOffsetY) { jm.Window.Document._prevPageOffsetY = yOffset; for (var key in jm.Window.Document.SubscriptionScrollY) if (jm.Window.Document.SubscriptionScrollY[key] != null) jm.Window.Document.SubscriptionScrollY[key](yOffset); } }); } }, "ScrollTo": function (x, y, interval, element) { var timeouts = []; var xOffset = element ? element.scrollLeft : jm.Window.Document.ScrollLeft(), yOffset = element ? element.scrollTop : jm.Window.Document.ScrollTop(), n = 0; if (isNaN(xOffset) || isNaN(yOffset) || xOffset == undefined || yOffset == undefined || x == xOffset && y == yOffset) return; if (interval <= 0) { if (element) { element.scrollLeft = x; element.scrollTop = y; } else window.scrollTo(x, y); } else { var stepX = Math.round((xOffset - x) / (interval / 10)), stepY = Math.round((yOffset - y) / (interval / 10)); if (Math.abs(stepX) < 1 && Math.abs(stepY) < 1) { if (element) { element.scrollLeft = x; element.scrollTop = y; } else window.scrollTo(x, y); } else { while (true) { xOffset -= stepX; yOffset -= stepY; if (Math.abs(yOffset - y) <= Math.abs(stepY)) yOffset = y; if (Math.abs(xOffset - x) <= Math.abs(stepX)) xOffset = x; if (n == 0) { if (element) { element.scrollLeft = xOffset; element.scrollTop = yOffset; } else window.scrollTo(xOffset, yOffset); } else { timeouts[timeouts.length - 1] = element ? setTimeout(function (x, y) { element.scrollLeft = x; element.scrollTop = y; }, n * 10, xOffset, yOffset) : setTimeout("window.scrollTo(" + xOffset + "," + yOffset + ");", n * 10); } n++; if (xOffset == x && yOffset == y) break; } } } return timeouts; }, "Scrolling": { "Event": [], "ParendDisabled": false, "_wheel": function (e) { var canceled = false; if (jm.Window.Scrolling.ParendDisabled) { var obj = e.target; while (obj && obj.style && (obj.style.overflow != "scroll" && obj.style.overflow != "auto" && obj.style.overflowY != "scroll" && obj.style.overflowY != "auto")) obj = obj.parentElement; if (!obj) { jm.preventDefault(e); canceled = true; } else { var newScroll = obj.scrollTop - e.wheelDelta; if (newScroll < 0) { canceled = obj.scrollTop == 0; obj.scrollTop = 0; jm.preventDefault(e); } else { var top = parseInt(jm.Text.ToNumeric(obj.style.marginTop)), bottom = parseInt(jm.Text.ToNumeric(obj.style.marginBottom)); if (newScroll >= obj.scrollHeight - obj.offsetHeight - top - bottom) { canceled = obj.scrollTop == obj.scrollHeight - obj.offsetHeight - top - bottom; obj.scrollTop = obj.scrollHeight - obj.offsetHeight - top - bottom; jm.preventDefault(e); } } } } if (!canceled) for (var key in jm.Window.Scrolling.Event) if (jm.Window.Scrolling.Event[key]) jm.Window.Scrolling.Event[key](); }, "DisableParent": function () { jm.Window.Scrolling.ParendDisabled = true; }, "EnableParent": function () { jm.Window.Scrolling.ParendDisabled = false; }, "Init": function () { //if (window.addEventListener) window.addEventListener('DOMMouseScroll', jm.Window.Scrolling._wheel, false); jm.Events.Add(window, "mousewheel", jm.Window.Scrolling._wheel); //jm.Events.Add(document, "mousewheel", jm.Window.Scrolling._wheel); } } }, "Text": { "CapitalizeFirstLetter": function(str) { return str && str.charAt(0).toUpperCase() + str.slice(1); }, "Format": function(formatStr, args) { var lbpos, rbpos = -1, result = formatStr; while (1) { lbpos = result.indexOf('{', rbpos + 1); if (lbpos === -1) break; rbpos = result.indexOf('}', lbpos + 1); if (rbpos === -1) break; var placeholderValue = result.substring(lbpos + 1, rbpos); var substituteValue = args[placeholderValue]; if (substituteValue == null || substituteValue == undefined) substituteValue = ''; result = result.substring(0, lbpos) + substituteValue + result.substring(rbpos + 1); rbpos += substituteValue.length - (placeholderValue.length + 2); } return result; }, "Replace": function (value, token, newToken) { var result = ""; try { for (var i = 0; i < value.length; i++) { if (i + token.length <= value.length) { if (value.substring(i, i + token.length).toLowerCase() == token.toLowerCase()) { result += newToken; i += token.length - 1; } else result += value.substring(i, i + 1); } else result += value.substring(i, i + 1); } } catch (ex) { return ""; } return result; }, "ToHTML": function (value) { if (!value || value == "") return ""; if (value.length == 1) return value == "<" ? "<" : (value == ">" ? ">" : (value == '"' ? """ : (value == "'" ? "'" : (value == "&" ? "&" : value)))); //return value.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """).Replace("'", "'").Replace("\r\n", "
").Replace("\n", "
").Replace("\r", "
"); return value ? value.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\r\n/g, '
').replace(/\n/g, '
').replace(/\r/g, '
') : ''; }, "RemoveHTML": function (value) { //return value.replace(/(<\?[a-z]*(\s[^>]*)?\?(>|$)||]*?(>|$)||$)|<[a-z?!\/]([a-z0-9_:.])*(\s[^>]*)?(>|$))/gi, ''); return value.replace(/<(?:.|\n)*?>/gm, ''); }, "Trim": function (value) { return value.replace(/(^\s+)|(\s+$)/g, ""); }, "Escape": function (value) { return encodeURI(value).replace(new RegExp("\\+", "g"), "%2B").replace(new RegExp("\\&", "g"), "%26").replace(new RegExp("\\#", "g"), "%23").replace(new RegExp("\\/", "g"), "%2F"); }, "ToNumeric": function (value) { try { if (!value) return 0; var result = "", letters = "-0123456789.,"; value = value.toString(); for (var n = 0; n < value.length; n++) if (letters.indexOf(value.substring(n, n + 1)) == -1) break; else result += value.substring(n, n + 1); if (result == "") return 0; return parseFloat(jm.Text.Replace(result, ",", ".")); } catch (ex) { } return 0; }, "FormatMoney": function (value) { if (value == undefined || value == null) return "0"; var v = value.toString().Replace(".", ","); if (value >= 1000) { var pointFound = v.indexOf(",") < 0, n = 0, result = ""; for (var a = v.length - 1; a >= 0; a--) { if (!pointFound && v.substring(a, a + 1) == ",") pointFound = true; else if (pointFound) n++; result = (n == 3 ? "." : "") + v.substring(a, a + 1) + result; if (n == 3) n = 0; } return result.substring(0, 1) == "." ? result.substring(1, result.length) : result; } return v; }, "ExtractDigits": function (value, includeSymbols) { if (!value) return value; var result = "", digits = "0123456789" + (includeSymbols && includeSymbols.length > 0 ? includeSymbols : ""); value = value.toString(); for (var n = 0; n < value.length; n++) if (digits.indexOf(value.substring(n, n + 1)) >= 0) result += value.substring(n, n + 1); return result; }, "ExtractLatinLetters": function (value) { if (!value) return value; var result = "", letters = "abcdefghijklmnopqrstuvwxyz "; value = value.toString(); for (var n = 0; n < value.length; n++) if (letters.indexOf(value.substring(n, n + 1).toLowerCase()) >= 0) result += value.substring(n, n + 1); return result; }, "IsSimplePassword": function (value) { var simplePasswords = ["qwerty", "pass", "pass123", "password", "password123", "p@ssword", "123qwe", "qwe123", "123abc", "abc123", "abcdef", "admin", "adm", "admins", "@dmin", "admin123", "admin12345", "admin1", "admin2", "admin0", "admin111", "administrator", "administrators", "office", "manage", "manager", "username", "userinfo", "root", "roots", "server", "servers", "support", "login", "local", "guest", "q1w2e3", "delete", "computer", "virtual", "default", "!@#$%^", "test123", "test11", "test111", "russia", "script", "apples"]; if (!value || value == null || value.length == 0) return true; value = jm.Text.Trim(value).toLowerCase(); if (value.Length < 6 || jm.Text.ExtractDigits(value) == value) return true; for (var a = 0; a < simplePasswords.length; a++) if (simplePasswords[a] == value) return true; var symbols = [], symbolsCount = 0; for (var a = 0; a < value.length; a++) if (!symbols[value.substring(a, a + 1)]) { symbols[value.substring(a, a + 1)] = true; symbolsCount++; } return symbolsCount < 3; }, "ToDate": function (value) { if (!value) return null;//ddMMyyyyHHmmssfff function getNumber(from, length) { var v = value.substring(from, from + length); while (v.length > 1 && v.substring(0, 1) == "0") v = v.substring(1, v.length); return parseInt(v); } return value.length == 8 ? new Date(getNumber(4, 4), getNumber(2, 2) - 1, getNumber(0, 2)) : (value.length == 14 ? new Date(getNumber(4, 4), getNumber(2, 2) - 1, getNumber(0, 2), getNumber(8, 2), getNumber(10, 2), getNumber(12, 2)) : (value.length == 17 ? new Date(getNumber(4, 4), getNumber(2, 2) - 1, getNumber(0, 2), getNumber(8, 2), getNumber(10, 2), getNumber(12, 2), getNumber(14, 3)) : null)); }, "DateToSrvString": function (value) { if (!value || !value.getDate) return null; function part(val, size) { val = val.toString(); if (val.toString().length >= size) return val; while (val.length < size) val = "0" + val; return val; }; return part(value.getDate(), 2) + part(value.getMonth() + 1, 2) + value.getFullYear() + part(value.getHours(), 2) + part(value.getMinutes(), 2) + part(value.getSeconds(), 2) + part(value.getMilliseconds(), 3); }, "Measure": function (value, cssText, className) { if (!document.body) return null; var div = document.createElement("div"); if (cssText) div.style.cssText = cssText; if (className) div.className = className; div.style.position = "absolute"; div.style.left = "-10000px"; div.style.top = "-10000px"; div.innerHTML = value; document.body.appendChild(div); var result = { "Width": div.clientWidth, "Height": div.clientHeight }; document.body.removeChild(div); div = null; return result; }, validate: { email: function (value) { if (!value || value == "") return false; var value = jm.Text.Trim(value.toLowerCase()), alphabet = "abcdefghijklmnopqrstuvwxyz0123456789-_.@"; if (value == "") return false; for (var a = 0; a < value.length; a++) if (alphabet.indexOf(value.substring(a, a + 1)) < 0) return false; var re = /\S+@\S+\.\S+/;// [a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)\b; return re.test ? re.test(value) : true; }, creditCardNumber: function (value) { if (!value || value.length < 16 || /[^0-9-\s]+/.test(value)) return false; var nCheck = 0, bEven = false; value = value.replace(/\D/g, ""); for (var n = value.length - 1; n >= 0; n--) { var nDigit = parseInt(value.charAt(n), 10); if (bEven && (nDigit *= 2) > 9) nDigit -= 9; nCheck += nDigit; bEven = !bEven; } return (nCheck % 10) == 0; } }, "UnificateNewLines": function (value) { if (value == null || value.length == 0) return value; var result = ""; try { for (var i = 0; i < value.length; i++) { if (value.substring(i, i + 1) == "\r" && (i < value.length - 1 && value.substring(i + 1, i + 2) != "\n" || i == value.length - 1)) result += "\r\n"; else if (value.substring(i, i + 1) == "\n" && (i > 0 && value.substring(i - 1, i) != "\r" || i == 0)) result += "\r\n"; else result += value.substring(i, i + 1); } } catch (ex) { return ""; } return result; }, "Symbols": function (value) { var alphabet = "abcdefghijklmnopqrstuvwxyzабвгдеёжзийклмнопрстуфхцчшщъыьэюя", digits = "0123456789", lettersCount = 0, digitsCount = 0; if (value != null) { value = value.Trim(); for (var n = 0; n < value.length; n++) { if (alphabet.indexOf(value.substring(n, n + 1).toLowerCase()) >= 0) lettersCount++; if (digits.indexOf(value.substring(n, n + 1).toLowerCase()) >= 0) digitsCount++; } } return { lettersCount: lettersCount, digitsCount: digitsCount }; }, "FormatPhone": function (value, includeSymbols) { if (!value) return value; var digits = value.ExtractDigits(includeSymbols); if (digits.length >= 10) digits = "(" + digits.substring(0, 3) + ") " + digits.substring(3, 6) + "-" + digits.substring(6, digits.length); else if (digits.length == 9) digits = "(" + digits.substring(0, 2) + ") " + digits.substring(2, 5) + "-" + digits.substring(5, digits.length); return digits; } }, "DateTime": { _utcDT: null, _pageDT: new Date(), UTC: function () { var dt = jm.DateTime._utcDT; if (!dt || !jm.DateTime._pageDT) { dt = new Date(); return new Date(dt.getUTCFullYear(), dt.getUTCMonth(), dt.getUTCDate(), dt.getUTCHours(), dt.getMinutes(), dt.getUTCSeconds(), dt.getMilliseconds()); } var result = new Date(dt.getFullYear(), dt.getMonth(), dt.getDate(), dt.getHours(), dt.getMinutes(), dt.getSeconds(), dt.getMilliseconds()); result.setMilliseconds(result.getMilliseconds() + (new Date() - jm.DateTime._pageDT)); return result; }, cutTime: function (value) { return !value || !value.getFullYear ? null : new Date(value.getFullYear(), value.getMonth(), value.getDate()); }, ToString: function (value, type, grayTime) { if (!value) return ""; var minutesStr = (value.getMinutes().toString().length == 1 ? "0" : "") + value.getMinutes().toString(); var hoursStr = (value.getHours().toString().length == 1 ? "0" : "") + value.getHours().toString(); var secondsStr = (value.getSeconds().toString().length == 1 ? "0" : "") + value.getSeconds().toString(); if (type == 6 || type == 7 || type == 8 || type == 9) { var d = value.getDate(), m = value.getMonth() + 1; d = d < 10 ? "0" + d : d.toString(); m = m < 10 ? "0" + m : m.toString(); return type == 7 ? (d + "." + m + "." + value.getFullYear() + " " + hoursStr + ":" + minutesStr + ":" + secondsStr) : (type == 8 ? (d + "." + m + "." + value.getFullYear() + " (" + hoursStr + ":" + minutesStr + ")") : (type == 9 ? (d + "." + m + "." + value.getFullYear()) : (d + m + value.getFullYear()))); } var monthName = "", dayName = ""; switch (value.getMonth()) { case 0: monthName = type == 4 || type == 5 ? 'янв' : 'Января'; break; case 1: monthName = type == 4 || type == 5 ? 'фев' : 'Февраля'; break; case 2: monthName = type == 4 || type == 5 ? 'мар' : 'Марта'; break; case 3: monthName = type == 4 || type == 5 ? 'апр' : 'Апреля'; break; case 4: monthName = type == 4 || type == 5 ? 'мая' : 'Мая'; break; case 5: monthName = type == 4 || type == 5 ? 'июн' : 'Июня'; break; case 6: monthName = type == 4 || type == 5 ? 'июл' : 'Июля'; break; case 7: monthName = type == 4 || type == 5 ? 'авг' : 'Августа'; break; case 8: monthName = type == 4 || type == 5 ? 'сен' : 'Сентября'; break; case 9: monthName = type == 4 || type == 5 ? 'окт' : 'Октября'; break; case 10: monthName = type == 4 || type == 5 ? 'ноя' : 'Ноября'; break; case 11: monthName = type == 4 || type == 5 ? 'дек' : 'Декабря'; break; } monthName = monthName.toLowerCase(); if (type == 0) return value.getDate() + " " + monthName + " " + value.getFullYear(); if (type == 10) return value.getDate() + " " + monthName; if (type == 1) return value.getDate() + " " + monthName + " " + value.getFullYear() + (grayTime ? '' : '') + " (" + hoursStr + ":" + minutesStr + ")" + (grayTime ? '' : ''); if (type == 2) return value.getDate() + " " + monthName + " " + value.getFullYear() + (grayTime ? '' : '') + " в " + hoursStr + ":" + minutesStr + (grayTime ? '' : ''); if (type == 3) return value.getDate() + " " + monthName + " " + value.getFullYear() + (grayTime ? '' : '') + ", " + hoursStr + ":" + minutesStr + (grayTime ? '' : ''); if (type == 4 || type == 5) return value.getDate() + " " + monthName + (serverUtcDT.getFullYear() == val.getFullYear() ? "" : (" " + val.getFullYear())) + ", " + hoursStr + ":" + minutesStr; return ""; } }, "Math": { "Round": function (value, digits) { if (value == null || isNaN(value)) return 0; if (digits < 0 || isNaN(digits) || digits == null || digits == undefined) digits = 0; var d = Math.pow(10, digits); value *= d; if (Math.abs(value - Math.round(value)) == 0.5) value -= 0.01; return Math.round(value) / d; }, Average: function (array) { if (!array || !array.length) return 0; var sum = 0, count = 0; for (var n = 0; n < array.length; n++) if (array[n] != null && array[n] != undefined && !isNaN(parseFloat(array[n]))) { sum += parseFloat(array[n]); count++; } return count > 0 ? sum / count : 0; }, Min: function (array) { if (!array || !array.length) return null; var result = null; for (var n = 0; n < array.length; n++) if (array[n] != null && array[n] != undefined && !isNaN(parseFloat(array[n])) && (result == null || parseFloat(array[n]) < result)) result = parseFloat(array[n]); return result; }, Max: function (array) { if (!array || !array.length) return result; var result = null; for (var n = 0; n < array.length; n++) if (array[n] != null && array[n] != undefined && !isNaN(parseFloat(array[n])) && (result == null || parseFloat(array[n]) > result)) result = parseFloat(array[n]); return result } }, "Format": { "ToTime": function (totalSeconds) { if (totalSeconds == null || totalSeconds == undefined) return "0:00"; totalSeconds = Math.round(totalSeconds); var hours = Math.floor(totalSeconds / 3600); var minutes = Math.floor((totalSeconds - hours * 3600) / 60); var seconds = totalSeconds - hours * 3600 - minutes * 60; if (seconds.toString().length == 1) seconds = "0" + seconds.toString(); return hours == 0 ? (minutes + ":" + seconds) : (hours + ":" + (minutes.toString().length == 1 ? "0" : "") + minutes + ":" + seconds); } }, "Array": { "Contains": function (array, value) { if (!array || !value) return false; if (array.indexOf) return array.indexOf(value) >= 0; for (var v in array) if (v == value || array[v] == value) return true; return false; }, "Find": function(array, predicate, context) { if (!array || array.length == 0 || !predicate) return null; for (var i = 0; i < array.length; i++) if (predicate.call(context, array[i], i, array)) return array[i]; return null; }, "Clone": function (array) { return array.slice(0); }, "InsertAt": function (array, index, value) { return array.splice(index, 0, value); }, "RemoveAt": function (array, index, count) { return array.splice(index, count); } }, "Script": { "Add": function (params) { if (!params || !params.URL && !params.Text) return; var js = document.createElement("script"); js.setAttribute("type", "text/javascript"); js.setAttribute("language", "javascript"); if (params.URL) js.setAttribute("src", params.URL); if (params.Text) js.text = params.Text; if (params.Element) { var el = jm.el(params.Element); if (el) { if (params.RemoveAfterExecution && params.URL) js.onload = function () { el.removeChild(js); } el.appendChild(js); if (params.RemoveAfterExecution && !params.URL) el.removeChild(js); } } else { if (document.body) { if (params.RemoveAfterExecution && params.URL) js.onload = function () { document.body.removeChild(js); } document.body.appendChild(js); if (params.RemoveAfterExecution && !params.URL) document.body.removeChild(js); } else if (document) { if (params.RemoveAfterExecution && params.URL) js.onload = function () { document.removeChild(js); } document.appendChild(js); if (params.RemoveAfterExecution && !params.URL) document.removeChild(js); } } }, "Write": function (text, element, removeAfterExecution) { this.Add({ "Text": text, "Element": element, "RemoveAfterExecution": removeAfterExecution }); }, "LoadedScripts": [], "Load": function (url, element, loadAsync, removeAfterExecution) { if (loadAsync) this.Add({ "URL": url, "Element": element, "RemoveAfterExecution": removeAfterExecution }); else { var script = url.indexOf(".js") > 0 && jm.Script.LoadedScripts[url] ? jm.Script.LoadedScripts[url] : jm.AJAX({ "URL": url, "Type": "get", Async: false }).responseText; jm.Script.LoadedScripts[url] = script; jm.Script.Write(script, element, removeAfterExecution); } } }, "Style": { "Add": function (params) { var css = null; if (params.URL && params.URL != "") { css = document.createElement("link"); css.setAttribute("href", params.URL); css.setAttribute("rel", "stylesheet"); } else if (params.Text && params.Text != "") { css = document.createElement("style"); css.innerHTML = params.Text; } if (css != null) { css.setAttribute("type", "text/css"); if (params.Element) { var el = jm.el(params.Element); if (el) el.appendChild(css); } else { if (document.body) document.body.appendChild(css); else if (document) document.appendChild(css); } } }, "Write": function (text, element) { this.Add({ "Text": text, "Element": element }); }, "Load": function (url, element, loadAsync) { if (loadAsync == true) this.Add({ "URL": url, "Element": element }); else jm.Style.Write(jm.AJAX({ "URL": url, "Type": "get", Async: false }).responseText, element); } }, "AJAX": function (parameters) { var URL = null, IsPost = true, Asynchronous = true, Data = null, OnSuccess = null, IsAnswerScript = false; if (parameters.URL) URL = parameters.URL; if (parameters.Type && parameters.Type.toString().toLowerCase() == "get") IsPost = false; if (parameters.Async != null && parameters.Async != undefined) Asynchronous = parameters.Async; if (parameters.Data) Data = parameters.Data; if (parameters.OnSuccess) OnSuccess = parameters.OnSuccess; if (parameters.IsAnswerScript != null && parameters.IsAnswerScript != undefined) IsAnswerScript = parameters.IsAnswerScript; var httpRequest = false; if (!URL) return false; if (window.XMLHttpRequest) { httpRequest = new XMLHttpRequest(); if (httpRequest.overrideMimeType) httpRequest.overrideMimeType("text/html"); } else if (window.ActiveXObject) { try { httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (ex) { try { httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (ex) { } } } if (httpRequest) { if ((OnSuccess || IsAnswerScript) && Asynchronous == true) httpRequest.onreadystatechange = function () { if (this.readyState != 4) return; if (this.status == 200) { if (parameters.IsAnswerScript && this.responseText) jm.Script.Write(this.responseText, null, true); if (parameters.OnSuccess) if (jm.Object.GetType(parameters.OnSuccess) == "Function") parameters.OnSuccess(this.responseText); else jm.Script.Write(parameters.OnSuccess, null, true); } else if (parameters.OnError) parameters.OnError(); }; var params = ""; if (Data) for (var p in Data) if (Data[p] != null && Data[p] != undefined) { if (params != "") params += "&"; params += (p + "=" + this.Text.Escape(Data[p].toString())); } if (!IsPost && params != "") { if (URL.indexOf("?") >= 0) { URL += "&" + params; } else { URL += "?" + params; } params = ""; } httpRequest.open(IsPost ? "post" : "get", URL, Asynchronous); httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); //httpRequest.setRequestHeader("Content-length", params.length); //httpRequest.setRequestHeader("Connection", "close"); httpRequest.send(params); if (!Asynchronous && IsAnswerScript && httpRequest.responseText) jm.Script.Write(httpRequest.responseText, null, true); } return httpRequest; }, "WebSocket": function (host, params) { if (!params || !host || host.length == 0) return null; var _socket = null, _isEnd = false, _heartBeatTimer = null, _connectedDT = null; function _sendHeartBeat() { if (!_socket || _socket.readyState != WebSocket.OPEN || !params.heartBeat || !params.heartBeat.message || params.heartBeat.message.length == 0) return; _socket.send(params.heartBeat.message); } function _init() { try { _socket = new WebSocket(host); _socket.onopen = function (openEvent) { _connectedDT = new Date(); _sendHeartBeat(); if (!_heartBeatTimer && params.heartBeat && params.heartBeat.interval > 0) _heartBeatTimer = window.setInterval(_sendHeartBeat, params.heartBeat.interval); if (params.onopen) params.onopen(); }; _socket.onmessage = function (messageEvent) { if (messageEvent && messageEvent.data && params.onmessage) params.onmessage(messageEvent.data); }; _socket.onclose = function (closeEvent) { _connectedDT = null; if (params.onclose) params.onclose(); if (!_isEnd && params.reconnect) setTimeout(function () { if (!_isEnd) _init(); }, params.reconnectInterval > 0 ? params.reconnectInterval : 5000); }; return true; } catch (ex) { } return false; } this.Send = function (message) { if (!_socket || _socket.readyState != WebSocket.OPEN || !message || message.length == 0) return false; _socket.send(message); return true; }; this.Connected = function () { return _socket && _socket.readyState == WebSocket.OPEN; }; this.Uptime = function () { return _socket && _connectedDT && _socket.readyState == WebSocket.OPEN ? (new Date() - _connectedDT) : 0; }; this.Dispose = function () { _isEnd = true; if (_socket != null) _socket.close(); _socket = null; if (_heartBeatTimer != null) window.clearInterval(_heartBeatTimer); _heartBeatTimer = null; }; _init(); return this; }, "URL": { "QueryString": function (name, utf8) { if (name == null || name == "") return ""; var result = ""; var href = window.location.href; if (href.indexOf("?") != -1) { var query = href.substr(href.indexOf("?")); var queryParam = query.split("&"); for (var n = 0; n < queryParam.length; n++) if (queryParam[n].toLowerCase().indexOf(name.toLowerCase() + "=") != -1) { result = queryParam[n].split("=")[1]; break; } } return utf8 ? decodeURIComponent(result) : unescape(result); }, "Manager": { _onUrlChanged: [], _onBack: [], "Activate": function () { if (jm.Browser.IE && jm.Browser.Version < 10) jm.Events.Add(window, "hashchange", jm.URL.Manager._urlChanged); else jm.Events.Add(window, "popstate", jm.URL.Manager._urlChanged); }, "Deactivate": function () { if (jm.Browser.IE && jm.Browser.Version < 10) jm.Events.Remove(window, "hashchange", jm.URL.Manager._urlChanged); else jm.Events.Remove(window, "popstate", jm.URL.Manager._urlChanged); }, "_urlChanged": function (e) { if ((jm.Browser.Safari || jm.Browser.Chrome) && e != null && e.state == null) window.history.replaceState({ foo: "bar" }, "", jm.URL.Manager.Get()); else if (e == null || e != null && e.state != null || !jm.Browser.Safari && !jm.Browser.Chrome) { var url = jm.URL.Manager.Get(); if (e && e.state && e.state.foo == "bar") for (var n in jm.URL.Manager._onBack) if (jm.URL.Manager._onBack[n]) jm.URL.Manager._onBack[n](); for (var n in jm.URL.Manager._onUrlChanged) if (jm.URL.Manager._onUrlChanged[n]) jm.URL.Manager._onUrlChanged[n](url); } }, "Set": function (url, force) { if (!url) return; if (url[0] != '?' && !this._getLocale(url)) url = this._addLocale(url); var urlChanged = jm.URL.Manager.Get().toLowerCase() != url.toString().toLowerCase(); if (jm.Browser.IE && jm.Browser.Version < 10) { window.location.hash = url; /* if (urlChanged)*/ jm.URL.Manager._urlChanged(null); } else { if (urlChanged || force) window.history.pushState({ foo: "bar" }, "", url); jm.URL.Manager._urlChanged(null); } }, "ReplaceOrSet": function (url, onReplace) { if (!url) return; if (url[0] != '?' && !this._getLocale(url)) url = this._addLocale(url); if (window.history && window.history.replaceState) { window.history.replaceState({ foo: "bar" }, "", url); if (onReplace) onReplace(); } else jm.URL.Manager.Set(url); }, "Get": function () { var url = ""; if (jm.Browser.IE && jm.Browser.Version < 10) { url = window.location.hash; if (url.length > 0 && url.substring(0, 1) == "#") url = url.substring(1, url.length); } else url = (window.location.pathname && window.location.pathname.length > 0 ? window.location.pathname : "") + (window.location.search && window.location.search.length > 0 ? window.location.search : ""); if (url == "") url = "/"; return url; }, "UrlChanged": { "Subscribe": function (key, func) { jm.URL.Manager._onUrlChanged[key] = func; }, "Unsubscribe": function (key) { jm.URL.Manager._onUrlChanged[key] = null; }, }, "Back": { "Subscribe": function (key, func) { jm.URL.Manager._onBack[key] = func; }, "Unsubscribe": function (key) { jm.URL.Manager._onBack[key] = null; }, }, "_getLocale": function(url) { var localeLen = "ru-rub".length; if (url.length < localeLen) return null; var localePart = url[0] === '/' ? url.substr(1, 6) : url.substr(0, 6); var lang = DbCache.Language.GetByCode(localePart.substr(0, 2)); var curr = DbCache.Currency.GetByCode(localePart.substr(3, 3)); return lang && curr ? { "_language": lang, "_currency": curr } : null; }, "_addLocale": function(url) { if (!_state.locale.isDefined() || this._getLocale(url)) return url; return "/" + _state.locale.getLanguage()._code + '-' + _state.locale.getCurrency()._code + url; }, "_removeLocale": function(url) { if (!url || url.length == 0 || !_state.locale.isDefined() || !this._getLocale(url)) return url; return url.substring("/ru-rub".length) } } }, "Cookies": { "Set": function (name, value, expires, domain, secure) { if (!expires) { var dt = new Date(); dt.setFullYear(dt.getFullYear() + 30); expires = dt.toString(); } document.cookie = name + "=" + escape(value) + ";path=/;expires=" + expires + (domain ? ";domain=" + domain : "") + (secure ? ";secure" : ""); }, "Get": function (name) { try{ var cookie = " " + document.cookie, search = " " + name + "=", result = null, offset = 0, end = 0; if (cookie.length > 0) { offset = cookie.indexOf(search); if (offset >= 0) { offset += search.length; end = cookie.indexOf(";", offset) if (end < 0) end = cookie.length; return unescape(cookie.substring(offset, end)); } } } catch (ex) { } return null; }, "Remove": function (name, domain) { if (jm.Cookies.Get(name)) { var dt = new Date(); dt.setFullYear(dt.getFullYear() - 1); document.cookie = name + "=;path=/" + (domain ? ";domain=" + domain : "") + ";expires=" + dt.toString(); } } }, "OS": { Windows: false, Mac: false }, "Browser": { Name: "", Version: 0, IE: false, Firefox: false, Netscape: false, Opera: false, Chrome: false, Safari: false, FlashVersion: [0, 0, 0] }, "DocType": { XHTML: "", Version: 1, Importance: "" }, "Random": { "Guid": function () { var result = ""; var s4 = function () { return Math.floor(Math.random() * 0x10000).toString(16); }; while (result.length < 36) result = s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4(); return result; }, "Int": function () { return Math.round(Math.random() * 999999999); } }, "Locale": { "LocaleBtnClick": function (localeObj) { if (!localeObj) return; if (localeObj._languageId) { if (localeObj._languageId === _state.locale._languageId) return; if (jm.Data.DbCache.Language.GetById(localeObj._languageId) == null) return; _state.locale._languageId = localeObj._languageId; } if (localeObj._currencyId) { if (localeObj._currencyId === _state.locale._currencyId) return; if (jm.Data.DbCache.Currency.GetById(localeObj._currencyId) == null) return; _state.locale._currencyId = localeObj._currencyId; } if (!_auth.user) { // Just go to page with new locale this._userLocaleUpdated(); return; } jm.AJAX({ // Save user new locale preferences URL: "/user_AddOrUpdate.h?fName=jm.Locale._userLocaleUpdated&r=" + jm.Random.Int(), Type: "post", Data:{ "id": _auth.user ? _auth.user.id : null, "languageId": localeObj._languageId ? localeObj._languageId : _state.locale._languageId, "currencyId": localeObj._currencyId ? localeObj._currencyId : _state.locale._currencyId }, Async: true, IsAnswerScript: true }); }, "_userLocaleUpdated": function() { window.location.href = jm.URL.Manager._addLocale(jm.URL.Manager._removeLocale(_nav.lastLoadedUrl)); } }, "Init": function () { try { var nav = navigator; var ua = nav.userAgent.toLowerCase(), p = nav.platform.toLowerCase(); this.OS.Windows = p ? /win/.test(p) : /win/.test(ua); this.OS.Mac = p ? /mac/.test(p) : /mac/.test(ua); this.Browser.Opera = ua.indexOf("opera") != -1 || ua.indexOf("opr") != -1; this.Browser.IE = (ua.indexOf("msie") >= 0 || (!!ua.match(/trident\/7\./) && !!ua.match(/rv:/))) && !this.Browser.Opera && ua.indexOf("webtv") < 0; this.Browser.Netscape = ua.indexOf("netscape") != -1; this.Browser.Firefox = ua.indexOf("firefox") != -1; this.Browser.Safari = ua.indexOf("safari") != -1; this.Browser.Chrome = ua.indexOf("chrome") != -1; var nameVersion = /(webkit)[ \/]([\w.]+)/.exec(ua) || /(opera)(?:.*version)?[ \/]([\w.]+)/.exec(ua) || /(msie) ([\w.]+)/.exec(ua) || !/compatible/.test(ua) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec(ua) || []; this.Browser.Name = nameVersion[1]; try { this.Browser.Version = parseFloat(nameVersion[2]); } catch (ex) { this.Browser.Version = nameVersion[2]; } if ((this.Browser.Safari || this.Browser.Chrome) && this.Browser.Version > 500) this.Browser.Version /= 100; if (nav.plugins && typeof nav.plugins["Shockwave Flash"] == "object") { var d = nav.plugins["Shockwave Flash"].description; if (d && !(nav.mimeTypes && nav.mimeTypes["application/x-shockwave-flash"] && !nav.mimeTypes["application/x-shockwave-flash"].enabledPlugin)) { plugin = true; d = d.replace(/^.*\s+(\S+\s+\S+$)/, "$1"); this.Browser.FlashVersion[0] = parseInt(d.replace(/^(.*)\..*$/, "$1"), 10); this.Browser.FlashVersion[1] = parseInt(d.replace(/^.*\.(.*)\s.*$/, "$1"), 10); this.Browser.FlashVersion[2] = /[a-zA-Z]/.test(d) ? parseInt(d.replace(/^.*[a-zA-Z]+(.*)$/, "$1"), 10) : 0; } } else if (window.ActiveXObject) { try { var a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); if (a) { var d = a.GetVariable("$version"); if (d) { d = d.split(" ")[1].split(","); this.Browser.FlashVersion = [parseInt(d[0], 10), parseInt(d[1], 10), parseInt(d[2], 10)]; } } } catch (e) { } } } catch (ex) { } try { var ie_engine = null; if (this.Browser.IE) { if (document.documentMode) ie_engine = document.documentMode; else { ie_engine = 5 if (document.compatMode && document.compatMode == "CSS1Compat") ie_engine = 7; } } if (ie_engine != null) { try { this.Browser.Version = parseFloat(ie_engine); } catch (ex) { this.Browser.Version = ie_engine; } } } catch (ex) { } try { var doctype_re = /\s+(X?HTML)\s+([\d\.]+)\s*([^\/]+)*\//gi; var doctype_exp = null; if (typeof document.namespaces != "undefined") if (document.all[0].nodeType == 8) doctype_exp = doctype_re.exec(document.all[0].nodeValue); else if (document.doctype != null) doctype_exp = doctype_re.exec(document.doctype.publicId); if (doctype_exp != null) { this.DocType.XHTML = doctype_exp[1].toLowerCase(); try { this.DocType.Version = parseFloat(doctype_exp[2]); } catch (ex) { this.DocType.Version = doctype_exp[2]; } this.DocType.Importance = doctype_exp[3].toLowerCase(); } } catch (ex) { } this.Events.Add(window, "resize", this.Window.Subscribe.Resize); this.Events.Add(window, "scroll", this.Window.Subscribe.Scroll); this.Events.Add(window, "focus", this.Window.Subscribe.Focus); this.Events.Add(window, "blur", this.Window.Subscribe.Blur); setInterval(function () { if (!jm.Data["RTB"]) return; var wasFocused = jm.Window.Focused(), found = false; for (var id in jm.Data["RTB"]) { var rtb = jm.Data["RTB"][id]; if (rtb && rtb.Focused) { found = true; break; } } jm.Window._anyRtbFocused = found; if (wasFocused == jm.Window.Focused()) return; jm.Window.Subscribe.EventAct(wasFocused ? "blur" : "focus"); }, 200); //this.Locale.Init(); return this; } }; var jm = new JMain(); JMain.prototype.el = function (elementId) { return jm.Elements.GetById(elementId); } JMain.prototype.gDim = function (elementId) { return jm.Elements.GetDimensions(elementId); } JMain.prototype.preventDefault = function (e) { return jm.Elements.PreventDefault(e); } jm.Window.Document.InitSubscription(); jm.Window.Scrolling.Init(); Date.prototype.addDays = function (days) { var d = new Date(this.valueOf()); d.setDate(d.getDate() + days); return d; } String.prototype.CapitalizeFirstLetter = function () { return jm.Text.CapitalizeFirstLetter(this.valueOf()); } String.prototype.Format = function () { return jm.Text.Format(this.valueOf(), arguments); } String.prototype.Replace = function (token, newToken) { return jm.Text.Replace(this.valueOf(), token, newToken); } String.prototype.ToHTML = function () { return jm.Text.ToHTML(this.valueOf()); } String.prototype.RemoveHTML = function () { return jm.Text.RemoveHTML(this.valueOf()); } String.prototype.Trim = function () { return jm.Text.Trim(this.valueOf()); } String.prototype.Escape = function () { return jm.Text.Escape(this.valueOf()); } String.prototype.ToNumeric = function () { return jm.Text.ToNumeric(this.valueOf()); } String.prototype.ExtractDigits = function (includeSymbols) { return jm.Text.ExtractDigits(this.valueOf(), includeSymbols); } String.prototype.ExtractLatinLetters = function () { return jm.Text.ExtractLatinLetters(this.valueOf()); } String.prototype.IsSimplePassword = function () { return jm.Text.IsSimplePassword(this.valueOf()); } String.prototype.ToDate = function () { return jm.Text.ToDate(this.valueOf()); } String.prototype.Measure = function () { return jm.Text.Measure(this.valueOf()); } String.prototype.ValidateEMail = function () { return jm.Text.validate.email(this.valueOf()); } String.prototype.ValidateCreditCardNumber = function () { return jm.Text.validate.creditCardNumber(this.valueOf()); } String.prototype.UnificateNewLines = function () { return jm.Text.UnificateNewLines(this.valueOf()); } String.prototype.Symbols = function () { return jm.Text.Symbols(this.valueOf()); } String.prototype.FormatPhone = function (includeSymbols) { return jm.Text.FormatPhone(this.valueOf(), includeSymbols); } String.prototype.Left = function (index) { var value = this.valueOf(); if (!value || value.length < index) return ""; return value.substring(0, index); } String.prototype.Right = function (index) { var value = this.valueOf(); if (!value || value.length < index) return ""; return value.substring(value.length - index, value.length); } //# sourceURL=/jmain.js