﻿var Tesla = { UI: {}, Enums: { Get: function (a) { a = a.Split("."); var b = Tesla.Enums[a[0]]; if (!b) return null; return b.Get(a[1]) } }, Debug: function () { }, EnableDebug: function () { Tesla.Debug = $F("i=>alert(i)") } }; window.Ajax = { Callback: {} }; Collections = {}; if (!window.console) window.console = {}; if (!console.log) { console._log = ""; console.log = function (a) { console._log = console._log + a + "\r\n" }; console.dump = function () { alert(console._log) }; console.clear = function () { console._log = "" } } function $Get(b) { var a = document.getElementById(b); if (!a) return a; (a.tagName || "").toLowerCase() == "select" && Tesla.UI.ListControl.BindFunctions(a); return a } function $GetValue(b) { var a = $Get(b); if (!a) return String.Empty; if (a.tagName && (a.tagName.toLowerCase() == "table" || a.tagName.toLowerCase() == "ul")) { var c = 0; a = $Get(b + "_" + c); while (a != null) { if (a.tagName && a.tagName.toLowerCase() == "input" && a.type == "radio" && a.checked) return a.value || String.Empty; c++; a = $Get(b + "_" + c) } return String.Empty } if (a.tagName && a.tagName.toLowerCase() == "select") { var d = ($GetAttr(a, "IgnoreFirstItem") || "").toString().toLowerCase() == "true"; if (d && a.options[0].text == a.value) return String.Empty } if (a.tagName && a.tagName.toLowerCase() == "input" && a.type == "checkbox") return a.checked; return a.value || String.Empty } function $escape(a) { a = escape(a); for (var c = "", b = 0; b < a.length; b++) { var d = a.charAt(b); if (d == "+") c += "%2b"; else if (d == "%" && a.charAt(b + 1) != "u") { c += "%"; if (a.charAt(b + 1).toLowerCase() >= "a") c += "u00"; c += a.charAt(b + 1).toLowerCase(); c += a.charAt(b + 2).toLowerCase(); b += 2 } else c += a.charAt(b) } return c } function $GetAttr(a, b) { if (!a) return null; if (a[b]) return a[b]; if (a.attributes && a.attributes[b]) return a.attributes[b].value } function $SetAttr(a, b, c) { if (!a || !a.attributes) return; if (a.attributes && a.attributes[b]) a.attributes[b].value = c; else { var b = document.createAttribute(b); b.value = c; a.attributes.setNamedItem(b) } } function $CreateEnum(d, b) { for (var a = {}, c = 0; c < b.length; c++) a[b[c].Name] = b[c].Value; a.__Names = b.Select("i => i.Name"); a.__Values = b.Select("i => i.Value"); a.__Descriptions = b.Select("i => i.Description"); a.Get = function (c) { var a = this, b = Math.max(a.__Names.IndexOf(c), a.__Values.IndexOf(c)); return { Name: a.__Names[b], Value: a.__Values[b], Description: a.__Descriptions[b], toString: function () { return JSON.ToString(this) } } }; a.GetNames = function () { return this.__Names }; a.GetValues = function () { return this.__Values }; a.GetDescriptions = function () { return this.__Descriptions }; a.GetDescription = function (a) { return this.__Descriptions[Math.max(this.__Names.IndexOf(a), this.__Values.IndexOf(a))] }; a.GetInfo = function () { var b = this; for (var c = [], a = 0; a < b.__Names.length; a++) c.push({ Name: b.__Names[a], Value: b.__Values[a], Description: b.__Descriptions[a] }); return c }; Tesla.Enums[d] = a } Function.Empty = function () { }; Function.prototype.GetName = function () { var a = this; if (a.name) return a.name; var c = a.toString(); if (c == "[function]") { var b = a; if (b == String) a.name = "String"; else if (b == Number) a.name = "Number"; else if (b == Function) a.name = "Function"; else if (b == Date) a.name = "Date"; else if (b == Error) a.name = "Error"; else if (b == Boolean) a.name = "Boolean"; else if (b == Array) a.name = "Array"; else a.name = "Object"; return a.name } for (var d = c.indexOf("function") + 9; c.charAt(d) == " "; ) d++; var e = d; while (c.charAt(e) != " " && c.charAt(e) != "(") e++; a.name = c.substring(d, e); return a.name }; Function.prototype.CreateDelegate = function (a) { if (a === undefined || a === null) return this; return $D(a, this) }; function $GetType(a) { if (a instanceof Function) return "Function"; if (a !== null && a !== undefined && a.constructor && a.constructor.GetName) return a.constructor.GetName(); return null } Tesla.CookieManager = new function () { var a = this; a.Set = function (c, a, b) { if (!b) a = escape(a); document.cookie = String.Format("{0}={1};expires=Fri, 31 Dec 2099 23:59:59 GMT;path={2};", c, a, "/" + page.ApplicationName) }; a.Get = function (c) { for (var b = document.cookie.split("; "), d = null, a = 0; a < b.length; a++) { var e = b[a].split("="); if (c == e[0]) { d = unescape(b[a].substring(c.length + 1)); break } } return d }; a.Delete = function (a) { document.cookie = a + "=; expires=Fri, 21 Dec 1976 04:31:24 GMT;" }; a.SaveObject = function (a, b) { this.Set(a, JSON.ToString(b)) }; a.LoadObject = function (a) { return JSON.Parse(this.Get(a)) } }; window.JSON = { Parse: function (text) { return eval("(" + text + ")") } }; JSON.ToEscapedString = function (c, a, b) { return JSON.ToString(c, a, b, JSON.DefaultEscapeFunction) }; JSON.ToString = function (a, e, i, c, d) { var j = "dd/MM/yyyy HH:mm:ss"; d = d || 0; if (d > 10) return null; c = c || function (a) { return a }; var l = function (b) { for (var c = "", a = 0; a < b.length; a++) c += b.charAt(a) == "\\" ? "\\\\" : b.charAt(a); return c.Replace("'", "\\'") }; Tesla.Debug(a + "::" + $GetType(a)); switch ($GetType(a)) { case "Number": case "Boolean": return a.toString(); case "String": if (i) return "'" + c(l(a.toString())) + "'"; return c(a.toString()); case "Date": if (e && i) return "'" + a.ToString("MM/dd/yyyy HH:mm:ss") + "'"; if (e) return a.ToString(j); return String.Format("$Date('{0}')", a.ToString(j)); case "Array": if (!a.length) return "[]"; for (var b = "[", f = 0; f < a.length; f++) { var k = a[f]; if (k) b += JSON.ToString(a[f], e, typeof k == "string", c, d + 1); else b += "null"; b += "," } return b.Left(b.length - 1) + "]" } var b = "{"; for (var h in a) try { var g = a[h]; if (g && !(g instanceof Function)) b += h + ":" + JSON.ToString(g, e, true, c, d + 1) + "," } catch (m) { Tesla.Debug("Erro na propriedade JSON (" + h + "):" + (m.message || m)) } if (b.length > 2) b = b.Left(b.length - 1); return b + "}" }; window.MessageBox = new function () { var a = null, b = this, f = 0, e = a, d = a, c = b; b.Type = { Alert: 1, Boolean: 2, Waiting: 3, Prompt: 4 }; b.Show = function (d, c, b, a) { f++; this.Close(true); page.Hide(); b = b || MessageBox.Type.Alert; if (a) e = typeof a === "string" ? $L("rt => " + a + "(rt)") : a; else e = Function.Empty; g(d, c, b) }; b.Close = function (b) { if (!d) return; !b && page.Show(); document.body.removeChild(d[0]); d = a }; b.CloseWithReturn = function (b) { var a = f; e(b); a == f && this.Close() }; function h(b) { switch (b) { case MessageBox.Type.Alert: return "alert"; break; case MessageBox.Type.Boolean: return "boolean"; break; case MessageBox.Type.Waiting: return "waiting"; break; case MessageBox.Type.Prompt: return "prompt" } return a } function g(j, b, g) { var e = "<button />", f = "absolute"; b = b || ""; if ($GetType(b) == "String") b = b.Replace("\r\n", "<br />"); var a = $('<div class="teslaAlert" />').css({ "z-index": "60001", position: f }); a.css({ position: page.IsIE6 ? f : "fixed" }); a.addClass(h(g)); $(window).resize(function () { page.SetCenter(a[0]) }); page.IsIE6 && $(window).scroll(function () { page.SetCenter(a[0]) }); g != MessageBox.Type.Waiting && a.append($('<button class="fechar" />').html("x").click(function () { c.CloseWithReturn() })); !String.IsNullOrEmpty(j) && a.append($('<strong class="titulo" />').html(j)); if (typeof "" == "string") a.append($("<p />").html(b)); else a.append(b); switch (g) { case MessageBox.Type.Prompt: var i = $('<input type="text" />'); a.append(i); a.append($(e).html("OK").click(function () { c.CloseWithReturn(i.val()) })); break; case MessageBox.Type.Alert: a.append($(e).html("OK").click(function () { c.CloseWithReturn(true) })); break; case MessageBox.Type.Boolean: a.append($('<button class="btSim" />').html("Sim").click(function () { c.CloseWithReturn(true) })); a.append($('<button class="btNao" />').html("Não").click(function () { c.CloseWithReturn(false) })) } d = a; $(document.body).append(a); page.SetCenter(a[0]); return a } }; String.Empty = ""; String.Space = " "; String.None = "none"; String.prototype.Capitalize = function () { !String.Accents && String.InitializeAccents(); for (var e = this, b = "", a = null, d = 0; d < e.length; d++) { var c = e.charAt(d); if (a && (a >= "a" && a <= "z" || a >= "A" && a <= "Z" || a >= "0" && a <= "9" || String.Accents[a])) b += c.toLowerCase(); else b += c.toUpperCase(); a = c } return b }; String.prototype.Left = function (b, c) { var a = this; if (b < a.length) return a.substr(0, b) + (c || String.Empty); return a }; String.prototype.Right = function (b) { var a = this; if (a.length < b) return a; return a.substr(a.length - b, b) }; String.prototype.PadLeft = function (b, a) { return (String.New(b, a) + this).Right(a) }; String.prototype.PadRight = function (b, a) { return (this + String.New(b, a)).Left(a) }; String.prototype.TrimStart = function (b, c) { b = b || String.Space; var a = this; if (!c && b.length > 1) while (b.indexOf(a.substring(0, 1)) >= 0) a = a.substring(1, a.length); else while (a.substring(0, b.length) == b) a = a.substring(b.length, a.length); return a }; String.prototype.TrimEnd = function (b, c) { b = b || String.Space; var a = this; if (!c && b.length > 1) while (b.indexOf(a.substring(a.length - 1, a.length)) >= 0) a = a.substring(0, a.length - 1); else while (a.substring(a.length - b.length, a.length) == b) a = a.substring(0, a.length - b.length); return a }; String.prototype.Trim = function (b, a) { return this.TrimEnd(b, a).TrimStart(b, a) }; String.prototype.RemoveAccent = function () { String.InitializeAccents(); for (var c = this, d = "", b = 0; b < c.length; b++) { var a = c.charAt(b); a = String.Accents[a] || a; d += a } return d }; String.New = function (c, b) { var a = ""; while (b-- > 0) a += c; return a }; String.InitializeAccents = function () { if (String.Accents) return; var b = {}, a = function (d, c) { for (var a = 0; a < c.length; a++) { b[c.charAt(a)] = d; b[c.charAt(a).toUpperCase()] = d.toUpperCase() } }; a("a", "áàãâä"); a("e", "éèêë"); a("i", "íìîï"); a("o", "óòõôö"); a("u", "úùûü"); a("n", "ñ"); a("c", "ç"); a("y", "ýÿý"); String.Accents = b }; String.WhenNullOrEmpty = function (a, c, b) { if (String.IsNullOrEmpty(a)) return c; if (b) return String.Format(b, a); return a }; String.prototype.ToString = function () { return this }; String.Parse = function (a) { if (a === null || a === undefined) return a; if (a.ToString) return a.ToString(); return a.toString() }; String.Concat = function () { for (var b = "", a = 0; a < arguments.length; a++) { if (arguments[a] === null || arguments[a] === undefined) continue; b += arguments[a].toString() } return b }; String._Formats = {}; String.Format = function () { var e = '"'; if (!arguments.length) return ""; var g = arguments; if (arguments.length == 1 && arguments[0].length) g = arguments[0]; var a = g[0]; if (String._Formats[a]) return String._Formats[a](g); a = a.Replace("\n", "\\n").Replace("\r", "\\r"); for (var i = a.length - 1, d = 0, c = [], b = 0; b < a.length; b++) if (a.charAt(b) == "{" && b < i && a.charAt(b + 1) != "{") { c.push((c.length ? '+"' : e) + a.substring(d, b).Replace(e, '\\"') + e); d = b; while (a.charAt(d) != "}") d++; var f = a.substring(b + 1, d).split(":"); if (f.length == 1) c.push("+args[" + (parseInt(f[0]) + 1) + "]"); else c.push("+args[" + (parseInt(f[0]) + 1) + '].ToString("' + f[1] + '")'); d++ } c.push((c.length ? '+"' : e) + a.substring(d, a.length).Replace(e, '\\"') + e); var h = "return " + c.join("") + ";"; String._Formats[a] = new Function("args", h); return String._Formats[a](g) }; String.prototype.Split = function (e) { for (var h = 0, b = this, i = false, a = 0; a < b.length; a++) for (var c = 0; c < e.length; c++) if (b.charAt(a) == e.charAt(c)) { if (a == b.length - 1) i = true; h++ } for (var g = new Array(h + 1), d = 0, f = 0, a = 0; a < b.length; a++) for (var c = 0; c < e.length; c++) if (b.charAt(a) == e.charAt(c)) { g[f] = b.substr(d, a - d); d = a + 1; f++ } if (!i) g[f] = b.substr(d, b.length - d); return g }; String.prototype.ToNumber = function (a) { if (!Validadores.ValidaNumero(this)) return a || 0; return parseInt(this) }; String.prototype.Replace = function (a, b) { a = new RegExp(a, "g"); var c = this.replace(a, b); return c }; String.IsNullOrEmpty = function (a, b) { if (b && a != null) a = a.toString().Trim(); return a == null || a.length == 0 }; String.prototype.StartsWith = function (b, c) { if (this.length < b.length) return false; for (var e = c ? this.toLowerCase() : this, d = c ? b.toLowerCase() : b, a = 0; a < d.length; a++) if (e.charAt(a) != d.charAt(a)) return false; return true }; String.prototype.EndsWith = function (a, d) { if (this.length < a.length) return false; for (var e = d ? this.toLowerCase() : this, b = d ? a.toLowerCase() : a, f = e.length - b.length, c = 0; c < b.length; c++) if (e.charAt(f++) != b.charAt(c)) return false; return true }; String.prototype.IsDigit = function (a) { a = a || 0; var b = this.charAt(a) || " "; return b >= "0" && b <= "9" }; String.prototype.IsLetter = function (a) { a = a || 0; var b = this.charAt(a).toLowerCase() || " "; return b >= "a" && b <= "z" }; String.prototype.IsLetterOrDigit = function (a) { return this.IsLetter(a) || this.IsDigit(a) }; String.UTF8 = new function () { this.Encode = function (c) { c = c.replace(/\r\n/g, "\n"); for (var b = "", d = 0; d < c.length; d++) { var a = c.charCodeAt(d); if (a < 128) b += String.fromCharCode(a); else if (a > 127 && a < 2048) { b += String.fromCharCode(a >> 6 | 192); b += String.fromCharCode(a & 63 | 128) } else { b += String.fromCharCode(a >> 12 | 224); b += String.fromCharCode(a >> 6 & 63 | 128); b += String.fromCharCode(a & 63 | 128) } } return b }; this.Decode = function (c) { var d = "", a = 0, b = c1 = c2 = 0; while (a < c.length) { b = c.charCodeAt(a); if (b < 128) { d += String.fromCharCode(b); a++ } else if (b > 191 && b < 224) { c2 = c.charCodeAt(a + 1); d += String.fromCharCode((b & 31) << 6 | c2 & 63); a += 2 } else { c2 = c.charCodeAt(a + 1); c3 = c.charCodeAt(a + 2); d += String.fromCharCode((b & 15) << 12 | (c2 & 63) << 6 | c3 & 63); a += 3 } } return d } }; JSON.DefaultEscapeFunction = String.UTF8.Encode; Tesla.StringBuilder = function () { var b = this, d = 0, c = [], a = ""; b.AppendFormat = function () { return this.Append(String.Format(arguments)) }; b.Append = function (b) { if (b === null || b === undefined) return this; b = b.toString(); if (!b.length) return this; a += b; if (a.length >= 2800) { c.push(a); d = a.length; a = "" } return this }; b.Clear = function () { c.length = 0; d = 0 }; b.GetLength = function () { return d + a.length }; b.ToString = b.toString = function () { if (a.length) { c.push(a); a = "" } var b = c.join(""); c = [b]; return b } }; var Validator = {}; Validator.TestRequired = function (a) { if (a === false || a === true) return a; return !String.IsNullOrEmpty(a, true) }; Validator.IsEmail = function (a) { return !a || !a.length || a.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$") != null }; Validator.IsNumber = function (a) { if (String.IsNullOrEmpty(a)) return false; for (var b = 0; b < a.length; b++) if (!a.IsDigit(b)) return false; return true }; Validator.IsDate = function (h) { var g = "0", c = null; if ($GetType(h) == "Date") return h; if (String.IsNullOrEmpty(h)) return c; var e = h.Split("/-."); if (e.length != 3) return c; if (!Validator.IsNumber((e[0] || ".").TrimStart(g)) || !Validator.IsNumber((e[1] || ".").TrimStart(g)) || !Validator.IsNumber((e[2] || ".").TrimStart(g))) return c; var d = parseInt(e[0].TrimStart(g)), f = parseInt(e[1].TrimStart(g)), a = parseInt(e[2].TrimStart(g)); if (d > 1900) { var i = a; a = d; d = i } if (a <= 60) a += 2e3; else if (a > 60 && a <= 99) a += 1900; if (d == 0 || f == 0 || a == 0 || f > 12) return c; if (a > 99 && a < 1900 || a > 2099) return c; try { f--; var b = new Date(a, f, d, 9); if (b.getDate() != d || b.getMonth() != f || b.getFullYear() != a) return c; b.setHours(0); if (b.getDate() != d || b.getMonth() != f || b.getFullYear() != a) { b = new Date(a, f, d, 9); b.setHours(1) } return b } catch (j) { return c } }; Validator.IsDateTime = function (h) { var a = null, f = h.Split(" "); if (f.length != 2) return a; var c = Validator.IsDate(f[0]); if (!c) return a; var b = f[1].Split(":"); if (b.length < 2 || b.length > 3) return a; var g = 0, e = 0, d = 0, g = parseInt(b[0].TrimStart("0")) || 0, e = parseInt(b[1].TrimStart("0")) || 0, d = (b.length == 3 ? b[2].TrimStart("0") : 0) || 0; if (g < 0 || g > 23) return a; if (e < 0 || e > 59) return a; if (d < 0 || d > 59) return a; c.setHours(g); c.setMinutes(e); c.setSeconds(d); return c }; Validator.IsDecimal = function (a, e) { if (String.IsNullOrEmpty(a)) return false; var c = e ? "." : ",", d = 0, b = 0; if (a.charAt(0) == "-") b = 1; for (; b < a.length; b++) { if (a.charAt(b) == c) d++; if (a.charAt(b) != c && !a.IsDigit(b)) return false } return d <= 1 }; Validator.IsCPF = function (a) { return Validator.IsCPF_CNPJ(a, 1) }; Validator.IsCNPJ = function (a) { return Validator.IsCPF_CNPJ(a, 2) }; Validator.IsCPF_CNPJ = function (a, b) { if (String.IsNullOrEmpty(a, true) || !Validator.IsNumber(a)) return false; b = b || 0; if (b == 0) return Validator.__checkCPF(a) || Validator.__checkCNPJ(a); if (b == 1) return Validator.__checkCPF(a); return Validator.__checkCNPJ(a) }; Validator.__checkCNPJ = function (c) { var f = false; c = c || ""; var h, j, d, a, g, e, b, i; i = 1; if (c.length < 14 && c.length < 15) return f; for (a = 0; a < c.length - 1; a++) if (c.charAt(a) != c.charAt(a + 1)) { i = 0; break } if (!i) { b = c.length - 2; h = c.substring(0, b); j = c.substring(b); d = 0; e = b - 7; for (a = b; a >= 1; a--) { d += h.charAt(b - a) * e--; if (e < 2) e = 9 } g = d % 11 < 2 ? 0 : 11 - d % 11; if (g != j.charAt(0)) return f; b = b + 1; h = c.substring(0, b); d = 0; e = b - 7; for (a = b; a >= 1; a--) { d += h.charAt(b - a) * e--; if (e < 2) e = 9 } g = d % 11 < 2 ? 0 : 11 - d % 11; if (g != j.charAt(1)) return f; return true } return f }; Validator.__checkCPF = function (b) { b = b || ""; if (b.length != 11) return false; var c = "", e = 2, d = 10, a = 0; for (j = 1; j <= 2; j++) { mSoma = 0; for (i = e; i <= d; i++) mSoma = mSoma + b.substring(i - j - 1, i - j) * (d + 1 + j - i); if (j == 2) mSoma = mSoma + 2 * a; a = mSoma * 10 % 11; if (a == 10) a = 0; mControle1 = c; c = a; e = 3; d = 11 } return mControle1 * 10 + c == b.substring(9, 11) }; Math.Round = function (b, a) { return b.toFixed(a || 0) }; Number.prototype.GetInteger = function () { return Math.floor(this) }; Number.prototype.GetDecimal = function () { return this - Math.floor(this) }; Number.prototype.ToString = function (a) { var e = this; if (a.toLowerCase() == "c") { for (var f = e.GetInteger().toString(), g = "", c = f.length - 1; c >= 0; c--) { if (c != f.length - 1 && (f.length - c - 1) % 3 == 0) g = "." + g; g = f.charAt(c) + g } return String.Format("R$ {0},{1}", g, ("0" + Math.round(e.GetDecimal() * 100)).Right(2)) } else if (a) { var f = e.GetInteger().toString(), k = e.GetDecimal(), h = a.indexOf("."), l = a.indexOf(","), i = a.length, d = ""; if (h != -1) { d = "," + Math.round(k * Math.pow(10, i - h - 1)).toString().PadLeft("0", i - h - 1); a = a.substring(0, h) } var j = a.replace(/0/g, "").length, b = f.ToString(); b = b.PadLeft("0", Math.max(b.length, a.length - j)); if (b.length % 3 != 0) b = String.New(" ", 3 - b.length % 3) + b; for (var c = 0; c < b.length; c += 3) { if (l != -1 && c > 0) d = "." + d; d = b.Right(3 + c).Left(3) + d } return d.Trim() } return e.toString() }; Number.prototype.ToNumber = function () { return this }; Date.DayValue = 1e3 * 60 * 60 * 24; Date.Months = ["jan", "fev", "mar", "abr", "mai", "jun", "jul", "ago", "set", "out", "nov", "dez"]; Date.MonthsLong = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"]; Date.prototype.ToString = function (a) { var d = "0", b = this, c = 1900 + b.getYear(); c = c >= 2e3 ? c - 2e3 : c - 1900; if (c < 0) c = 0; c = (d + c.toString()).Right(2); a = a.Replace("yyyy", b.getFullYear()); a = a.Replace("yy", c); a = a.Replace("MMMM", Date.MonthsLong[b.getMonth()]); a = a.Replace("MMM", Date.Months[b.getMonth()]); a = a.Replace("MM", (d + (b.getMonth() + 1)).Right(2)); a = a.Replace("dd", (d + b.getDate().toString()).Right(2)); a = a.Replace("hh", (d + Math.abs(b.getHours() - 12).toString()).Right(2)); a = a.Replace("HH", (d + b.getHours().toString()).Right(2)); a = a.Replace("mm", (d + b.getMinutes().toString()).Right(2)); a = a.Replace("ss", (d + b.getSeconds().toString()).Right(2)); return a }; Date.prototype.ToLongString = function () { return this.ToString("dd de MMMM de yyyy") }; Date.Now = function () { return new Date }; Date.prototype.IsBetween = function (a, b) { return this >= Date.Parse(a) && this <= Date.Parse(b) }; Date.Parse = function (a) { if ($GetType(a) === "Date") return a; return Validator.IsDateTime(a) || Validator.IsDate(a) }; Date.GetFirstDayInMonth = function (a, c) { var b = "1/{0}/{1}"; if ($GetType(a) === "Date") return Date.Parse(String.Format(b, a.getMonth() + 1, a.getYear())); return Date.Parse(String.Format(b, a, c)) }; Date.IsValidInterval = function (a, b) { return Date.Parse(a) <= Date.Parse(b) }; Date.DaysInMonth = function (b, a) { return (new Date(b + parseInt(a / 12), a % 12, 1)).SubtractDays(1).getDate() }; Date.prototype.AddMonths = function (b) { if (!b) return; for (var a = this, c = 0; c < b; c++) a = a.AddDays(Date.DaysInMonth(a.getFullYear(), a.getMonth() + 1)); return a }; Date.prototype.SubtractMonths = function (b) { if (!b) return; for (var a = this, c = 0; c < b; c++) a = a.SubtractDays(Date.DaysInMonth(a.getFullYear(), a.getMonth())); return a }; Date.prototype.SubtractDays = function (a) { if (!a) return; return new Date(this.valueOf() - Date.DayValue * a) }; Date.prototype.AddDays = function (a) { if (!a) return; return new Date(this.valueOf() + Date.DayValue * a) }; Date.prototype.Subtract = function (c) { var d = this, a = d - c, b = {}, a = a / 60 / 60 / 1e3 / 24; b.Days = a.GetInteger(); a = a.GetDecimal() * 24; b.Hours = a.GetInteger(); a = a.GetDecimal() * 60; b.Minutes = a.GetInteger(); a = a.GetDecimal() * 60; b.Seconds = a.GetInteger(); return b }; Tesla.Enumerator = function (c, b) { var a = this; a._MoveNext = c; a._CurrentItem = b; a.MoveNext = function () { this.Current = this._CurrentItem(); return this._MoveNext() }; a.GetEnumerator = function () { return this } }; Collections.Stack = function () { this.Index = 0; this.Push = function (a) { this[this.Index++] = a }; this.Pop = function () { var a = this, b = a[--a.Index]; if (a.Index < 0) a.Index = 0; return b } }; Collections.Stack.name = "Collections.Stack"; Collections.Create = function (a, c, b) { if (!a || !a.length) return []; c = c || 0; b = b || a.length; if (a.length >= 0) b = Math.min(b, a.length); for (var e = [], d = c; d < b; d++) e[d - c] = a[d]; return e }; Array.Create = Collections.Create; Array.prototype.GetEnumerator = function () { var b = this, a = 0, c = new Tesla.Enumerator(function () { if (a >= b.length) return false; a++; return true }, function () { return b[a] }); return c }; Array.prototype.Add = function (a) { var b = this.length; this[this.length] = a; return b }; Array.prototype.IndexOf = function (b) { for (var a = 0; a < this.length; a++) if (this[a] == b) return a; return -1 }; Array.prototype.Contains = function (a) { if (a && $GetType(a) == "Function") { for (var b = 0; b < this.length; b++) if (a(this[b])) return true; return false } return this.IndexOf(a) >= 0 }; Array.prototype.RemoveAt = function (c) { var a = this; if (c >= a.length || c < 0) return; for (var b = c; b < a.length; b++) a[b] = a[b + 1]; a.length = a.length - 1 }; Array.prototype.Remove = function (a) { this.RemoveAt(this.IndexOf(a)) }; Array.prototype.Clear = function () { this.length = 0 }; Array.prototype.ForEach = function (c, b) { c = $F(c); b = $L(b, Array.Create(arguments, 1)); for (var a = 0; a < this.length; a++) b(this[a]) && c(this[a]) }; Array.prototype.Clone = function () { for (var b = [], a = 0; a < this.length; a++) b.Add(this[a]); return b }; Array.prototype.__Clone = Array.prototype.Clone; Array.prototype.ListRange = function (c, a) { var b = c; a = Math.min(this.length, a); var d = this, e = new Tesla.Enumerator(function () { b++; return b <= a }, function () { return d[b] }); return e }; Array.prototype.FindByProperty = function (b, a) { return this.First("i => i[p1] == p2", b, a) }; Object.CompareTo = function (a) { if (this > a) return 1; else if (this < a) return -1; return 0 }; String.prototype.CompareTo = Object.CompareTo; Number.prototype.CompareTo = Object.CompareTo; Date.prototype.CompareTo = Object.CompareTo; function $D(b, a) { if ($GetType(a) == "String") if (a.indexOf("=") > 0) a = $L.apply(b, Array.Create(arguments, 1)); else a = b[a] || window[a]; var c = new Function("return arguments.callee.fn.apply(arguments.callee.obj, arguments)"); c.fn = a; c.obj = b; return c } window.SystemLambdas = {}; function $F(a) { if (!a) return Function.Empty; if ($GetType(a) != "String") return a; if (a.indexOf("=>") < 0) return new Function(a); if (arguments.length == 1 && SystemLambdas[a]) return SystemLambdas[a]; var c = a.split("=>"), f = c[0].Trim().TrimStart("(").TrimEnd(")").Trim(); c.RemoveAt(0); c = c.join("=>"); var d = String.Format("{0};", c); if (arguments.length > 1) { for (var b = 1; b < arguments.length; b++) d = "var p" + b + " = arguments.callee.p" + b + ";\r\n" + d; for (var e = new Function(f, d), b = 1; b < arguments.length; b++) e["p" + b] = arguments[b]; return e } var e = new Function(f, d); SystemLambdas[a] = e; return e } function $L(a) { if (!a) return new Function("return true;"); if ($GetType(a) != "String") return a; if (a.indexOf("=>") < 0) return new Function(a); if (arguments.length == 1 && SystemLambdas[a]) return SystemLambdas[a]; var d = a.split("=>"), f = d[0].Trim().TrimStart("(").TrimEnd(")").Trim(); d.RemoveAt(0); d = d.join("=>"); var e = String.Format("return {0};", d); if (arguments.length > 1) { for (var b = 1; b < arguments.length; b++) e = "var p" + b + " = arguments.callee.p" + b + ";\r\n" + e; var c = new Function(f, e); window.LastL = c; for (var b = 1; b < arguments.length; b++) c["p" + b] = arguments[b]; return function () { return c.apply(c.p1, arguments) } } var c = new Function(f, e); SystemLambdas[a] = c; return c } Array.prototype.Skip = function (a) { return Array.Create(this, a) }; Array.prototype.SkipWhile = function (c) { var b = this; c = $L.apply(null, arguments); for (var d = [], a = 0, a = 0; a < b.length; a++) if (!c(b[a])) break; for (; a < b.length; a++) d.push(b[a]); return d }; Array.prototype.Where = function (b) { b = $L.apply(null, arguments); for (var c = [], a = 0; a < this.length; a++) b(this[a]) && c.push(this[a]); return c }; Array.GetComparator = function (a) { if (!a) return $L("i1,i2 => i1.CompareTo(i2)"); if ($GetType(a) == "Function") return a; if (a.indexOf("=>") < 0) { var c = a.Trim().Split(","); if (c.length == 1) { var b = c[0].Trim().split(" "); if (b.length > 1 && b[1].toLowerCase() == "desc") a = String.Format("i1, i2 => i2.{0}.CompareTo(i1.{0})", b[0]); else a = String.Format("i1, i2 => i1.{0}.CompareTo(i2.{0})", b[0]) } else { for (var d = "i1, i2 => ", e = 0; e < c.length; e++) { var b = c[e].Trim().split(" "); if (b.length > 1 && b[1].toLowerCase() == "desc") d += String.Format("( i2.{0}.CompareTo(i1.{0}) ? i2.{0}.CompareTo(i1.{0}) : ", b[0]); else d += String.Format("( i1.{0}.CompareTo(i2.{0}) ? i1.{0}.CompareTo(i2.{0}) : ", b[0]) } d += "0"; for (var e = 0; e < c.length; e++) d += ")"; a = d } } return $L(a) }; Array.prototype.OrderBy = function (c) { for (var a = [], b = 0; b < this.length; b++) a.push(this[b]); a.sort(Array.GetComparator(c)); return a }; Array.prototype.Select = function (a) { a = a || $L("i => i"); if ($GetType(a) == "String") { if (a.indexOf("=>") < 0) a = "i => i." + a; a = $L.apply(null, arguments) } for (var c = [], b = 0; b < this.length; b++) c.push(a(this[b])); return c }; Array.prototype.First = function (c) { var a = this; if (!a.length) return null; if (!c) return a[0]; c = $L.apply(null, arguments); for (var b = 0; b < a.length; b++) if (c(a[b])) return a[b]; return null }; Array.prototype.Last = function (c) { var a = this; if (!a.length) return null; if (!c) return a[a.length - 1]; c = $L.apply(null, arguments); for (var b = a.length - 1; b >= 0; b--) if (c(a[b])) return a[b]; return null }; Array.prototype.Count = function (b) { var a = this; if (!a.length) return 0; if (!b) return a.length; b = $L.apply(null, arguments); for (var d = 0, c = 0; c < a.length; c++) if (b(a[c])) d++; return d }; Array.prototype.Distinct = function (c, e) { if (!this.length) return []; var a = this; if (e) a = this.OrderBy(c); var d = []; c = Array.GetComparator(c); if (a.length > 1) c(a[0], a[1]) && d.push(a[0]); for (var b = 0; b < a.length; b++) a[b + 1] && c(a[b], a[b + 1]) != 0 && d.push(a[b + 1]); return d }; Array.prototype.Min = function (b) { var a = null; if (!b) b = $L.apply(a, ["i => i"]); else b = $L.apply(a, arguments); for (var d = a, f = a, e = this, c = 0; c < e.length; c++) { var g = b(e[c]); if (d == a || g < d) { d = g; f = e[c] } } return f }; Array.prototype.Max = function (b) { var a = null; if (!b) b = $L.apply(a, ["i => i"]); else b = $L.apply(a, arguments); for (var d = a, f = a, e = this, c = 0; c < e.length; c++) { var g = b(e[c]); if (d == a || g > d) { d = g; f = e[c] } } return f }; Array.prototype.Sum = function (a) { if (!a) a = $L.apply(null, ["i => i"]); else a = $L.apply(null, arguments); for (var c = this, d = 0, b = 0; b < c.length; b++) d += a(c[b]); return d }; Array.prototype.Avg = function (a) { if (!a) a = $L.apply(null, ["i => i"]); else a = $L.apply(null, arguments); var b = this; return this.Sum(a) / b.length }; Array.prototype.GetPage = function (c, b, f) { var a = this; if (f) a = a.Where(f); for (var h = c * b, j = Math.min((c + 1) * b, a.length), g = [], d = 0; d < j - h; d++) g[d] = a[d + h]; var e = Math.floor(a.length / b + (a.length % b > 0 ? 1 : 0)), i = c + 1 < e; return { Page: g, CurrentPage: c, ItemsPerPage: b, TotalItems: a.length, TotalPages: e, HasNextPage: i, HasPreviousPage: c > 0} }; Collections.Dictionary = function (c) { var b = this, a = b; a.Keys = []; a.Values = []; b.Add = function (b, c) { a.Remove(b); a.Keys.Add(b); a.Values.Add(c); a[b] = c }; b.AddRange = function () { var b = arguments; if (arguments.length == 1 && arguments[0] && arguments[0].length) b = arguments[0]; if (b.length == null || b.length == undefined) return; for (var c = 0; c < b.length; c++) { if (!b[c] || !b[c].Key) continue; a.Add(b[c].Key, b[c].Value) } }; b.RemoveAt = function (b) { var c = a.Keys[b]; a[c] = null; a.Keys.RemoveAt(b); a.Values.RemoveAt(b) }; b.Remove = function (c) { var b = a.Keys.IndexOf(c); if (b < 0) return; a.RemoveAt(b) }; b.ToString = function () { for (var c = "", b = 0; b < a.Keys.length; b++) c += String.Format("{0}={1}&", escape(a.Keys[b]), escape(a.Values[b])); return c.substr(0, c.length - 1) }; if ($GetType(c) == "String" && !String.IsNullOrEmpty(c)) for (var f = c.Split("&"), d = 0; d < f.length; d++) { var g = f[d].Split("="); a.Add(unescape(g[0]), unescape(g[1])) } else if (c) for (var e in c) { if ($GetType(e) == "Function") continue; a.Add(e, c[e]) } }; Collections.Dictionary.name = "Collections.Dictionary"; Collections.Dictionary.Create = function (d) { var c = new Collections.Dictionary; if (!d || !d.length) return c; for (var b = d.Split("&"), a = 0; a < b.length; a++) { if (!b[a] || b[a].length == 0) continue; var e = b[a].Split("="); c.Add(e[0], e[1]) } return c }; function $R() { page.RegisterControl.apply(page, arguments) } function $IE6(a, b) { return page.IsIE6 ? a : b } function $IE(b, c, d, a) { if (page.IsIE6) return b; if (page.IsIE7) return c; if (page.IsIE8) return d; return a } function NameValueCollection(h, k) { var b = this, a = b; b.AllKeys = []; b.Values = []; function f(c, b) { if (b === null || b === undefined) b = ""; else if ($GetType(b) !== "String") b = JSON.ToEscapedString(b); a[c] = b; a.AllKeys.Add(c); a.Values.Add(b); a.OnChanged && a.OnChanged(a) } function c() { if (k) throw { message: "A coleção está marcada como ReadOnly." }; } b.Add = function (b, d) { c(); a.Remove(b); f(b, d); return a }; b.Remove = function (d) { c(); if (d) d = d.toLowerCase(); for (var b = 0; b < a.AllKeys.length; b++) if (a.AllKeys[b].toLowerCase() == d) { a.AllKeys.RemoveAt(b); a.Values.RemoveAt(b); a.OnChanged && a.OnChanged(a); return a } return a }; b.Clear = function () { c(); for (var b = 0; b < a.AllKeys.length; b++) a[a.AllKeys[b].toLowerCase()] = null; a.AllKeys = []; a.Values = []; a.OnChanged && a.OnChanged(a); return a }; b.Clone = function (a) { return new NameValueCollection(h, a || false) }; b.ToString = function () { return this.toString() }; b.toString = function (e) { for (var c = e ? $L("i => i") : $escape, d = "", b = 0; b < a.AllKeys.length; b++) d += String.Format("&{0}={1}", c(a.AllKeys[b]), c(a.Values[b])); return d.substring(1) }; for (var g = (h || "").split("&"), e = 0; e < g.length; e++) { var i = g[e].split("="), d = (i[0] || "").toLowerCase(); if (!d || !d.length) continue; var j = unescape("%uffff"), l = unescape(i[1] || "").Replace(j, " "); f(unescape(d), l) } } function __lc() { window.page && page.__SetLoadCompleted && setTimeout("page.__SetLoadCompleted()", 10) } Tesla.UI.Page = function () { var f = "absolute", c = true, e = false, b = null, a = this; a.Binder = {}; a.IsIE = /MSIE/.test(navigator.userAgent); a.IsIE6 = /MSIE 6.0/.test(navigator.userAgent); a.IsIE7 = /MSIE 7.0/.test(navigator.userAgent); a.IsIE8 = /MSIE 8.0/.test(navigator.userAgent); var n = b, p = [], k = e, h = [], i = [], g = [], l = [], d = [], q = a, o = e; a.Controls = []; a.GetUrl = function () { return decodeURIComponent(location.search.substring(1).replace(/\+/g, "%20")) }; a.QueryString = new NameValueCollection(a.GetUrl(), e); a.__SetLoadCompleted = function () { var a = this; if (a.IsLoaded()) return; a.OnLoad && a.OnLoad(); a.OnLoadCore() }; a.IsLoaded = function () { if (k) return c; return e }; a.OnLoadCore = function () { var a = "i => i()", b = this; k = c; b.ClientItemsField = $Get("tesla_clientitems"); if (b.ClientItemsField) { b.ClientItems = new NameValueCollection(b.ClientItemsField.value); b.ClientItems.OnChanged = function (a) { page.ClientItemsField.value = a.toString() } } page.Performance = {}; var d = new Date; h.ForEach(a); page.Performance.ControlLoaders = new Date - d; d = new Date; i.ForEach(a); page.Performance.LoadMethods = new Date - d; d = new Date; g.ForEach(a); page.Performance.PosLoadMethods = new Date - d }; a.__RegisterControl = function (a) { if (!a || !a.length) return; for (var e = (a[0] || String.Empty).Trim(), a = Collections.Create(a, 1), d = 0; d < a.length; d++) { var g = a[d].Split("|"), b = g[0], f = g[1] || b, c = $Get(b); !c && Tesla.Debug("Controle não encontrado: " + b); if (String.IsNullOrEmpty(e)) page[f] = c; else page[e + "_" + f] = c } }; function j() { for (var a = 0; a < d.length; a++) d[a]() } a.AddOnClick = function (a) { d.push(a); if (d.length == 1) if (this.IsIE) document.onclick = j; else { window.captureEvents(Event.Click); window.onclick = j } }; a.RemoveOnClick = function (a) { d.Remove(a); if (!d.length) if (this.IsIE) document.onclick = b }; a.GetEventKeyCode = function (a) { if (a) return parseInt(a.which || a.keyCode); if (window.event) return parseInt(event.keyCode); return b }; a.IsNumber = function (e, a) { var d = String.fromCharCode(m(e)); numcheck = /\d/; a = a || []; for (var b = 0; b < a.length; b++) if (keynum == a.charCodeAt(b)) return c; return numcheck.test(d) }; function m(c) { var a = window.event || c, b; if (a.type && a.type.indexOf("key") != -1) { if (page.IsIE || a.type.indexOf("keypress") != -1) b = a.keyCode || a.charCode || a.which; else b = a.charCode; return b } return a.keyCode || a.charCode || a.which } a.CheckNumbers = function (a, b) { if (!a) var a = window.event; if (a.keyCode == 8 || a.keyCode == 9 || a.keyCode == 46) return c; if (a.keyCode == 37 || a.keyCode == 8 || a.keyCode == 39 || a.keyCode == 40) return c; return this.IsNumber(a, b) }; a.CreateForm = function (e, b, c, d) { var a = document.createElement("form"); a.action = b || window.location; a.method = c || "post"; a.name = e || "defaultForm"; a.target = d || "_self"; document.body.appendChild(a); a.AddField = function (c, b) { a.appendChild(page.CreateInput(c, b)) }; return a }; a.CreateInput = function (c, b, d) { var a = document.createElement("input"); a.type = d || "hidden"; a.name = c; a.value = b; return a }; a.CreateIFrame = function () { var a = document.createElement("iframe"); document.body.appendChild(a); a.style.display = "none"; return a }; a.CreateSpan = function (b) { var a = document.createElement("span"); a.name = b; a.id = b; return a }; a.Redirect = function (a) { window.location.href = this.ResolveUrl(a) }; a.AddControl = function (c, b) { b = b || c; var a = {}; a.ID = c; a.Name = b; l.Add(a); if (this.IsLoaded()) RegisterControls_Internal(); else this.__ListenForOnLoad() }; a.RegisterControl = function () { var a = $L("() => page.__RegisterControl(p1)", arguments); if (this.IsLoaded()) a(); else h.push(a) }; a.AddOnLoad = function (a) { a = $F.apply(b, arguments); if (this.IsLoaded()) a(); else i.push(a) }; a.AddOnPosLoad = function (a) { a = $F.apply(b, arguments); if (this.IsLoaded()) a(); else g.push(a) }; a.ResolveUrl = function (a, c) { var b = "/"; if (a.charAt(0) == "~") { a = a.substr(1); if (a.charAt(0) == b) a = a.substr(1); if (page.ApplicationName.length > 0) a = page.ApplicationName + b + a } else if (a.charAt(0) != b) a = location.pathname.Left(location.pathname.lastIndexOf(b) + 1) + a; if (a.charAt(0) == b) a = a.substr(1); if (c) return b + a; return String.Format("{0}//{1}/{2}", location.protocol, location.host, a) }; a.FindControl = function (d) { for (var c = d.Split("."), a = page, b = 0; b < c.length; b++) a = a[c[b]]; return a }; a.AjaxUpload = function (c, f) { var d = "multipart/form-data"; c.onupload = f; var a = document.forms[0]; a.oldMethod = a.method; a.oldTarget = a.target; a.target = "TeslaAjaxUpload"; a.method = "post"; a.enctype = d; a.encoding = d; var g = (c.Items || "").ToString(); a.oldAction = a.action; var e = this.ResolveUrl("~/AjaxFileUpload/AjaxFileUpload.ashx?"); if (String.IsNullOrEmpty(c.HandlerMethod)) e += "handlerType=" + c.HandlerType; else e += "handlerMethod=" + c.HandlerMethod; e += String.Format("&ctrlName={0}&objectId={1}&{2}", c.name, $GetAttr(c, "CtrlId"), g); a.action = e; a.submit(); a.method = a.oldMethod; a.target = a.oldTarget; a.action = a.oldAction; c.value = b }; a.AddOnMouseMove = function (a) { document.onmousemove = function () { a(event.clientX + document.body.scrollLeft, event.clientY + document.body.scrollTop) } }; a.RemoveOnMouseMove = function () { document.onmousemove = b }; a.GetPosition = function (c) { var b = curtop = 0; if (!c.Top || !c.Left) { var a = c; if (a.offsetParent) { b = a.offsetLeft; curtop = a.offsetTop; while (a = a.offsetParent) { b += a.offsetLeft; curtop += a.offsetTop } } } return [curtop, b] }; a.SetCenter = function (a, e) { if (a == b) return; a.style.position = e || f; a.style.display = ""; a.style.zIndex = 60001; var d = parseInt(document.documentElement.scrollTop) || parseInt(document.body.scrollTop); d += (document.documentElement.clientHeight - a.clientHeight) / 2; var c = parseInt(document.documentElement.scrollLeft) || parseInt(document.body.scrollLeft); c += (document.documentElement.clientWidth - a.clientWidth) / 2; a.style.top = d + "px"; a.style.left = c + "px" }; a.CaptureMouseMove = function (a) { document.onmousemove = function (c) { var b = window.event || c; a(b.clientX + document.body.scrollLeft, b.clientY + document.body.scrollTop) } }; a.StopCaptureMouseMove = function () { document.onmousemove = b }; a.SetDebugData = function (b, a) { try { window.parent && window.parent.frames[0] && window.parent.frames[0].ShowStatistics && window.parent.frames[0].ShowStatistics(b, a) } catch (c) { } }; a.AddAjaxMethodStatistics = function (a) { try { window.parent && window.parent.frames[0] && window.parent.frames[0].AddAjaxMethodStatistics && window.parent.frames[0].AddAjaxMethodStatistics(a) } catch (b) { } }; a.Hide = function (b, a) { b = b || this.FatalityBackground || "#000"; a = a || this.FatalityOpacity || 80; var e = { "background-color": b, opacity: (a / 100).toString(), filter: "alpha(opacity=" + a + ")", "z-index": "60000", top: "0px", left: "0px", width: $(document.body).outerWidth(c), height: $(document).height(), position: this.IsIE6 ? f : "fixed" }; if (page.hider) { $(page.hider).css(e).show(); return } var d = $("<div />"); d.css(e); page.hider = d[0]; document.body.appendChild(page.hider) }; a.Show = function () { if (page.hider) page.hider.style.display = "none" } }; window.page = new Tesla.UI.Page; Tesla.UI.Page.Current = page; page.Validators = {}; var SeoManager = {}; SeoManager.Show = function (j, c, a, b) { if (!c || !c.length) c = document.title; var e = Array.Create(document.getElementsByTagName("meta")), h = (e.First('i => i.name =="description"') || {}).content, i = (e.First('i => i.name =="keywords"') || {}).content; if (!a || !a.length) a = h || ""; if (!b || !b.length) b = i || ""; var k = 50, f = { backgroundColor: "#FFFFAA", border: "solid 1px", width: "100%", paddingBottom: "10px" }, d = document.createElement("div"); d.className = "seoManager"; for (var g in f) d.style[g] = f[g]; d.innerHTML = String.Format('<table border="0" style="width:100%"><tr align="center"><td colspan="4"><b>SEO Manager</b></td></tr><tr><td valign="top"><div><b>Url Key: </b><br /><span id="txtTSEOUrlKey">{0}</span></div></td><td style="width:610px;padding-left:15px"><b>Title</b></div><div><input id="txtTSEOMetaTitle" type="text" style="width:600px" value="{1}" /></td><td valign="top" rowspan="2" style="padding-left:15px;"><b>MetaDescription</b></div><div><textarea id="txtTSEOMetaDescription" style="width:400px;height:60px">{2}</textarea></td></tr><tr><td><input type="button" value="Salvar" onclick="SeoManager.Update()" /></td><td style="padding-left:15px"><b>MetaKeywords</b></div><div><input id="txtTSEOMetaKeywords" value="{3}" type="text" style="width:600px;" /></td></tr></table>', j, c, a, b); document.body.insertBefore(d, document.body.childNodes[0]) }; SeoManager.Update = function () { var a = {}; a.UrlKey = $Get("txtTSEOUrlKey").innerHTML; a.Title = $Get("txtTSEOMetaTitle").value; a.MetaDescription = $Get("txtTSEOMetaDescription").innerHTML; a.MetaKeywords = $Get("txtTSEOMetaKeywords").value; Ajax.Callback.UpdateMetadata(a, $F("window.location.href = window.location.href")) }; page.ApplicationName = ""; function AjaxRepeater(f, g) { var c = "span", a = null, b = this, d = a, i = b, h = f, e = []; b.Id = f; b.ItemTemplate = a; b.AlternatingItemTemplate = a; b.HeaderTemplate = a; b.FooterTemplate = a; b.SeparatorTemplate = a; b.ContentPlaceHolder = a; AjaxRepeater[h] = i; b.constructor.BindMethod = { Sync: 0, Async: 1, Fast: 2 }; b.constructor.BindItem = function (c, a) { var b = AjaxRepeater[c]; b.__BindItem(a || 0) }; b.DataBind = function (b, h, g) { var c = this; if (!c.ContentPlaceHolder) c.ContentPlaceHolder = $Get(f); if (!c.ContentPlaceHolder) throw new Error("Elemento container não encontrado para o AjaxRepeater: " + f); if (b == a) b = ""; if (d != a) { for (var e in d) if (d[e] && d[e].length) c[e] = new Tesla.UI.Template(d[e]); d = a } if ($GetType(b) != "Array" && b.GetEnumerator) { var i = b.GetEnumerator(), j = []; while (i.MoveNext()) j.push(i.Current); b = j } b.__Repeater = c; if (!g) c.__BindSync(b, h); else g == AjaxRepeater.BindMethod.Async && c.__BindAsync(b, h) }; b.__BindSync = function (c, h) { var d = this, e = new Tesla.StringBuilder; d.HeaderTemplate && e.Append(d.HeaderTemplate.DataBind(a, a, c)); for (var f = 0, b = 0; b < c.length; b++) { if (!String.IsNullOrEmpty(g) && (b == 0 || c[b][g] != c[b - 1][g])) { f = 0; e.Append(d.GroupTemplate.DataBind(c[b], b, c)) } if (b % 2 == 0 || !d.AlternatingItemTemplate) e.Append(d.ItemTemplate.DataBind(c[b], b, c, f)); else e.Append(d.AlternatingItemTemplate.DataBind(c[b], b, c, f)); b < c.length - 1 && d.SeparatorTemplate && e.Append(d.SeparatorTemplate.DataBind(c[b], b, c)); f++ } d.FooterTemplate && e.Append(d.FooterTemplate.DataBind(a, a, c)); if (h) d.ContentPlaceHolder.innerHTML += e.toString(); else d.ContentPlaceHolder.innerHTML = e.toString(); d.ContentPlaceHolder.style.display = "" }; b.__BindAsync = function (d, g) { var b = this; if (b.__SyncObject) { clearTimeout(b.__SyncObject); b.__SyncObject = a } b.ClearContent(); for (var f = 0; f < e.length; f++) e[f].innerHTML = ""; b.DataSource = d; b.SlotIndex = 0; b.ContentPlaceHolder.style.display = ""; b.ItemsPerThreshold = g || 10; if (!b.ContentPlaceHolder.HeaderPH) { b.ContentPlaceHolder.HeaderPH = document.createElement(c); b.ContentPlaceHolder.appendChild(b.ContentPlaceHolder.HeaderPH) } if (!b.ContentPlaceHolder.ContentPH) { b.ContentPlaceHolder.ContentPH = document.createElement(c); b.ContentPlaceHolder.appendChild(b.ContentPlaceHolder.ContentPH) } if (!b.ContentPlaceHolder.FooterPH) { b.ContentPlaceHolder.FooterPH = document.createElement(c); b.ContentPlaceHolder.appendChild(b.ContentPlaceHolder.FooterPH) } if (b.HeaderTemplate) b.ContentPlaceHolder.HeaderPH.innerHTML = b.HeaderTemplate.DataBind(a, a, d); if (b.FooterTemplate) b.ContentPlaceHolder.FooterPH.innerHTML = b.FooterTemplate.DataBind(a, a, d); b.__SyncObject = setTimeout(String.Format('AjaxRepeater.BindItem("{0}");', h), 1) }; b.__BindItem = function (d) { var b = this; if (d >= b.DataSource.length) { b.OnBindCompleted && b.OnBindCompleted(); b.__SyncObject = a; return } var g = e[b.SlotIndex]; if (!g) { g = document.createElement(c); e[b.SlotIndex] = g; b.ContentPlaceHolder.ContentPH.appendChild(g) } for (var i = new Tesla.StringBuilder, f = 0; f < b.ItemsPerThreshold && d + f < b.DataSource.length; f++) i.Append(b.ItemTemplate.DataBind(b.DataSource[d + f], d + f, b.DataSource)); g.innerHTML = i.toString(); if (b.OnItemDataBound) for (var f = 0; f < b.ItemsPerThreshold && d + f < b.DataSource.length; f++) b.OnItemDataBound(g, b.DataSource[d + f]); b.SlotIndex = b.SlotIndex + 1; d = d + Math.min(b.ItemsPerThreshold, b.DataSource.length - d || 1); b.__SyncObject = setTimeout(String.Format('AjaxRepeater.BindItem("{0}", {1});', h, d), 1) }; b.ClearContent = function () { var a = this; if (!a.ContentPlaceHolder) return; if (!e.length) a.ContentPlaceHolder.innerHTML = ""; if (a.ContentPlaceHolder.HeaderPH) a.ContentPlaceHolder.HeaderPH.innerHTML = ""; if (a.ContentPlaceHolder.FooterPH) a.ContentPlaceHolder.FooterPH.innerHTML = ""; a.ContentPlaceHolder.style.display = "none" }; b.SetTemplate = function (a) { d = a }; b.InnerHTML = function () { if (!this.ContentPlaceHolder) return a; return this.ContentPlaceHolder.innerHTML }; b.Render = function (b) { var a = this; a.ClearContent(); a.DataBind(b); var c = a.InnerHTML(); a.ClearContent(); return c } } AjaxRepeater.Render = function (d, c, b) { var a = new AjaxRepeater; a.ContentPlaceHolder = page.CreateSpan("ajaxRpt"); a.ItemTemplate = new Tesla.UI.Template(c); if (b) a.AlternatingItemTemplate = new Tesla.UI.Template(b); return a.Render(d) }; AjaxRepeater.Create = function (a, c, b) { page[a] = new AjaxRepeater(a, b); page[a].SetTemplate(c); return page[a] }; Tesla.UI.Template = function (a) { var b = null; if (a instanceof Function) b = a; function c(a) { return a.Replace("\n", "\\n").Replace("\r", "\\r").Replace("\t", "\\t").Replace('"', '\\"') } function d() { for (var f = 0, e = 'return ""', d = 0; d < a.length; d++) { d = a.indexOf("(%", d); if (d < 0) { e += '+"' + c(a.substring(f, a.length)) + '";'; break } e += '+"' + c(a.substring(f, d)) + '" '; e += "+Tesla.UI.Template.GetString(" + a.substring(d + 2, a.indexOf("%)", d)) + ")"; d = f = a.indexOf("%)", d) + 2 } b = new Function("DataItem, ItemIndex, DataSource, GroupIndex", e) } this.DataBind = function (f, e, a, c) { !b && d(); return b(f, e, a, c) } }; Tesla.UI.Template.GetString = function (a) { if (a === null || a === undefined) return String.Empty; return a }; Tesla.UI.Template.DataBind = function (b, a) { var c = new Tesla.UI.Template(b); return c.DataBind(a, null, null) }; Tesla.UI.ClientTemplate = function (d, e) { var a = "px", b = "absolute", c = this; c.Show = function (e, d) { var c = this; c.Configure(); c.Container.innerHTML = c.Template.DataBind(e, null, null); if (d) { c.Container.style.position = b; c.Container.style.top = document.body.scrollTop + 210 + a; c.Container.style.left = document.body.scrollLeft + 340 + a } c.Container.style.display = "block"; c.OnShow && c.OnShow() }; c.Configure = function () { var a = this; if (a.IsReady) return; a.IsReady = true; if (d) a.Container = $Get(d); else { a.Container = document.createElement("div"); a.Container.style.display = "none"; document.body.appendChild(a.Container) } if (!a.Container) throw "Container não encontrado: " + (d || ""); a.Template = new Tesla.UI.Template(e || a.Container.innerHTML) }; c.Hide = function () { var a = this; a.Configure(); a.Container.style.display = "none"; a.OnClose && a.OnClose() }; c.SetCenter = function (e, d) { var c = this; c.Configure(); c.Container.style.position = b; c.Container.style.top = e - c.Container.offsetHeight + a; c.Container.style.left = d + a } }; function $NewOption(c, b) { var a = new Option(c, b); a.AddAttribute = function (b, a) { $SetAttr(this, b, a) }; a.GetAttribute = function (a) { return $GetAttr(this, a) }; return a } Tesla.UI.ListControl = {}; Tesla.UI.ListControl.Functions = {}; Tesla.UI.ListControl.Functions.SetSelectedValue = function (c) { var a = this; if (String.IsNullOrEmpty(c)) { a.selectedIndex = 0; return } var b = 0; while (b < a.options.length && a.options[b].value != c) b++; if (a.options[b].value == c) a.selectedIndex = b }; Tesla.UI.ListControl.Functions.SetSelectedIndex = function (a) { this.selectedIndex = a }; Tesla.UI.ListControl.Functions.SelectedValue = function () { var a = this; if (a.length <= 0 || a.selectedIndex < 0) return ""; return a.options[a.selectedIndex].value }; Tesla.UI.ListControl.Functions.SelectedText = function () { var a = this; if (a.length <= 0 || a.selectedIndex < 0) return ""; return a.options[a.selectedIndex].text }; Tesla.UI.ListControl.Functions.SelectedItem = function () { if (this.length <= 0) return null; return this.options[this.selectedIndex] }; Tesla.UI.ListControl.Functions.GetSelectedItemAttribute = function (c) { var a = this.SelectedItem(); if (!a) return null; var b = a.attributes[c]; if (!b) return null; return b.value }; Tesla.UI.ListControl.Functions.Clear = function () { this.length = 0 }; Tesla.UI.ListControl.Functions.Add = function (b, a) { if (a === undefined || a === null) a = b; var c = $NewOption(b, a); this.options[this.options.length] = c; return c }; Tesla.UI.ListControl.Functions.AddAt = function (a, f, d) { var b = this; if (a < 0) a = 0; var e = b.length; if (a < e) for (var c = e; c > a; c--) b.options[c] = $NewOption(b.options[c - 1].text, b.options[c - 1].value); a = Math.min(e, a); if (d === undefined || d === null) d = f; var g = $NewOption(f, d); b.options[a] = g; return g }; Tesla.UI.ListControl.Functions.DataBind = function (i, c, b, a) { var h = "Function", e = "String"; if (a && $GetType(a) == e) a = $F(a); else if (!a) a = Function.Empty; drop = this; drop.options.length = 0; if (!i.GetEnumerator) return; if (a && $GetType(a) == e) a = $L(a); if (c && $GetType(c) == e && c.indexOf("=>") > 0) c = $L(c); if (b && $GetType(b) == e && b.indexOf("=>") > 0) b = $L(b); var d = i.GetEnumerator(); while (d.MoveNext()) { var g = null, f = null; if ($GetType(c) == h) g = c(d.Current); else g = d.Current[c] || d.Current; if ($GetType(b) == h) f = b(d.Current); else f = d.Current[b] || d.Current; var j = drop.Add(g, f); a(j, d.Current) } return drop }; Tesla.UI.ListControl.Functions.CopyTo = function (f, d, c) { for (var a = 0; a < this.options.length; a++) { if (d && !this.options[a].selected) continue; var b = this.options[a], e = f.Add(b.value, b.text); c && c(b, e) } }; Tesla.UI.ListControl.Functions.GetValue = function () { for (var a = new Tesla.StringBuilder, b = 0; b < this.options.length; b++) { a.Append(this.options[b].value); a.Append(",") } var a = a.ToString(); return a.Left(a.length - 1) }; Tesla.UI.ListControl.Functions.SetDisabled = function () { this.disabled = true }; Tesla.UI.ListControl.Functions.SetEnabled = function () { this.disabled = false }; Tesla.UI.ListControl.Functions.Hide = function () { this.style.display = "none" }; Tesla.UI.ListControl.Functions.Show = function () { this.style.display = "" }; Tesla.UI.ListControl.BindFunctions = function (a) { for (var b in Tesla.UI.ListControl.Functions) a[b] = Tesla.UI.ListControl.Functions[b]; return a }; function $Date(a) { if ($GetType(a) == "Number") return new Date(a); return Date.Parse(a) } function $Clone(source) { return eval(String.Format("({0})", JSON.ToString(source))) } Ajax.__Execute = function (b, c, a, d) { Ajax.BeginInvoke && Ajax.BeginInvoke(b, c, d); a = a || 0; var g = (a & 1) === 1, i = (a & 2) !== 2, h = (a & 4) === 4, k = d["__calback"] || Function.Empty, j = new Collections.Dictionary(d), f = null; if (!String.IsNullOrEmpty(c)) f = String.Format("{0}.{1}", b, c); else f = b; var e = new AjaxMethod(f, j, g, i, h); e.Component = b; e.Method = c; e.Execute() }; function AjaxMethod(i, a, h, b, k, c) { var f = "__functionName", e = "__callback", d = this, j = a[e] || Function.Empty, g = a[f]; a.Remove(e); a.Remove(f); d.XmlHttp = window.XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP"); d.GetURL = function () { var c = i.StartsWith("Callback."); if (c && b) return page.ResolveUrl(String.Format("~/ClientCallback/ClientCallback.ashx?__ajax=2010&__method={0}", g)); else if (c) { var d = String.Format("~/ClientCallback/ClientCallback.ashx?__ajax=2010&__method={0}&{2}", g, (new Date).valueOf(), this.GetData()); if (!h) d += "nc={0}" + (new Date).valueOf(); return page.ResolveUrl(d) } var a = page.ResolveUrl(String.Format("~/AjaxMethod/{0}.ashx?__ajax=2011&", i)); if (!b) a += this.GetData(); if (!b && !h) a += "nc=" + (new Date).valueOf(); return a }; d.GetData = function () { for (var c = "", b = 0; b < a.Keys.length; b++) if (a.Values[b] !== null && a.Values[b] !== undefined) c += String.Format("{0}={1}&", a.Keys[b], JSON.ToString(a.Values[b], true, false, encodeURIComponent)); return c }; d.SetHeaderData = function () { if (c && c.Values.length) for (var a = 0; a < c.Keys.length; a++) this.XmlHttp.setRequestHeader("TESLA_AJAX_PARAM_" + c.Keys[a], JSON.ToString(c.Values[a], true, false, encodeURIComponent)) }; d.Execute = function () { var a = this, d = a.XmlHttp, h = a.GetURL(), c = a.Component, e = a.Method, g = a.Parameters; if (c == "ClientCallback") c = "Callback"; a.XmlHttp.onreadystatechange = function () { if (d.readyState != 4) return; var b = Ajax[c].OnError || Ajax.OnError || Function.Empty; if (e && Ajax[c][e]) b = Ajax[c][e].OnError || b; var a = d.responseText; if (parseInt(d.status) >= 500 && parseInt(d.status) < 600) { Ajax.LastException = a; b(a); return } AjaxMethod.ShowResponse && alert(a); try { if (!String.IsNullOrEmpty(a)) a = JSON.Parse(a) } catch (f) { Ajax.LastException = f; b(a); return } Ajax.EndInvoke && Ajax.EndInvoke(a, c, e, g); page.AddAjaxMethodStatistics({ Name: c + "." + e, ElapsedTime: parseFloat(d.getResponseHeader("Tesla.WebHandler.Elapsed")).toFixed(4) }); j(a) }; a.XmlHttp.open(b ? "POST" : "GET", a.GetURL(), true); a.SetHeaderData(); var f = b ? a.GetData() : null; a.XmlHttp.setRequestHeader("X-Content-Type", (f || "").length); a.XmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); a.XmlHttp.setRequestHeader("charset", "utf-8"); a.XmlHttp.send(f) } } function $NCB(d, g, b, c) { c = c || 0; var f = String.IsNullOrEmpty(b) ? [] : b.Split(","), a = "var ps = {};\r\n"; a += String.Format('ps.__metadata = "{0}";\r\n', g); a += String.Format('ps.__functionName = "{0}";\r\n', d); a += String.Format("ps.__callback = arguments[{0}];\r\n", f.length); for (var e = 0; e < f.length; e++) a += String.Format('ps["{0}"] = {0};\r\n', f[e]); a += String.Format('Ajax.__Execute("Callback", "{0}", {1}, ps)', d, c); var h = new Function(b, a); Ajax.Callback[d] = h } function AjaxPanel(i, g, h, e, f) { var b = "SemiAuto", a = this; a.Id = i; a.Mode = g; a.ControlType = h; a.ClientCacheMinutes = e; a.Data = f; function c(f, d, c, g, e) { var b = "GetAjaxPanelHtml", a = {}; a["controlId"] = f; a["controlType"] = d; a["clientCacheMinutes"] = c; a["data"] = g; a["__callback"] = e; a["__metadata"] = AjaxPanel.Hash; a["__functionName"] = b; Ajax.__Execute("Callback", b, 3, a) } function d(c) { var a = page[c.Id]; if (a.Mode == b) { a.LastHtml = c.Html; a.OnContentLoaded && a.OnContentLoaded() } else { a.OnContentLoaded && a.OnContentLoaded(); var d = $Get(a.Id); ApplyContentToElement(d, c.Html); a.OnLoad && a.OnLoad(d) } } a.Load = function () { var a = this; if (a.LastHtml) { var b = $Get(a.Id); ApplyContentToElement(b, a.LastHtml); a.OnLoad && a.OnLoad(b) } else c(a.Id, a.ControlType, a.ClientCacheMinutes, a.Data, d) }; a.Reload = function (b) { var a = this; if (b) a.Data.hash = (new Date).valueOf(); a.Mode == "Auto"; c(a.Id, a.ControlType, a.ClientCacheMinutes, a.Data, d) }; ApplyContentToElement = function (b, d) { if (b.innerHTML) b.innerHTML = ""; var c = document.createElement("div"); c.innerHTML = d; while (c.childNodes.length > 0) { var a = c.childNodes[0]; a.parentNode.removeChild(a); if (FindScriptNode(a)) continue; b.appendChild(a) } }; TestScriptNode = function (a) { if ((a.nodeType || 0) != 1 || (a.tagName || "").toUpperCase() != "SCRIPT") return false; var c = document.getElementsByTagName("head")[0], b = document.createElement("script"); b.type = "text/javascript"; b.language = "javascript"; if (a.src) b.src = a.src; b.text = a.innerHTML; c.appendChild(b); return true }; FindScriptNode = function (a) { if (TestScriptNode(a)) { a.parentNode && a.parentNode.removeChild(a); return true } if (a.childNodes) for (var b = 0; b < a.childNodes.length; b++) if (FindScriptNode(a.childNodes[b])) b--; return false }; (a.Mode == "Auto" || a.Mode == b) && a.Load() } Ajax.Tesla = {}; Ajax.Tesla.NewGuid = function (b) { var a = {}; a["__callback"] = b; a["__functionName"] = "NewGuid"; Ajax.__Execute("Tesla", "NewGuid", 4, a) }; Ajax.ImageCropper = {}; Ajax.ImageCropper.GetImageData = function (d, c) { var b = "GetImageData", a = {}; a["path"] = d; a["__callback"] = c; a["__functionName"] = b; Ajax.__Execute("ImageCropper", b, 0, a) }; Ajax.ImageCropper.GenerateImage = function (j, d, g, i, k, h, e, c, f) { var b = "GenerateImage", a = {}; a["source"] = j; a["destination"] = d; a["cropType"] = g; a["height"] = i; a["width"] = k; a["startAt"] = h; a["ctrlHeight"] = e; a["destinationPathBuilder"] = c; a["__callback"] = f; a["__functionName"] = b; Ajax.__Execute("ImageCropper", b, 4, a) }; function CreateAjaxUpload(b) { var a = $Get(b.ClientID); a.CtrlId = b.ID; a.HandlerType = b.HandlerType; a.HandlerMethod = b.HandlerMethod; a.Items = new Collections.Dictionary; a.Items.AddRange(b.Items); page[b.ID] = a; return a } Tesla.Twitter = new function () { var b = 0; function a(d, c, i) { c = c || {}; var g = (c.Page || 0) + 1, f = c.SinceTweetId; d = d.Replace("#", "%23"); var j = ++b, e = "TwitterCallback" + j, h = $F("(rt) => arguments.callee.Callback(Tesla.Twitter.GetResult(rt))"); h.Callback = i || Function.Empty; window[e] = h; var a = document.createElement("script"); if (f) a.src = String.Format("http://search.twitter.com/search.json?callback={0}&page={2}&since_id={3}&q={1}", e, d, g, f); else a.src = String.Format("http://search.twitter.com/search.json?callback={0}&page={2}&q={1}", e, d, g); a.language = "javascript"; document.body.appendChild(a) } this.Search = function (d, b, c) { a(d, c, b) }; this.SearchFromUser = function (d, b, c) { a("from%3A" + d, c, b) }; this.GetResult = function (b) { var a = b.results || [], a = a.Select("i => {Id:i.id,Text:i.text,User:i.from_user,UserId:i.from_user_id,UserImageUrl:i.profile_image_url,CreatedAt:new Date(i.created_at)}"); return a } }
