var searchWidget;if (searchWidget == null){searchWidget ={settingsRegistry: {},hostName: null,staticHostName: null,label: null,stylesheetId: "infiniteSports.stylesheet",init: function(){if ((document.links.length == 0) || (document.links[document.links.length - 1].id != "__infiniteSports"))return;var widgetId = "infiniteSearchWidget." + Math.random();var widgetNode = document.links[document.links.length - 1];this.hostName = this.getHostName(widgetNode.href);if ((this.hostName.toLowerCase().indexOf("infinite") != 0) && (this.hostName.toLowerCase().indexOf("localhost") != 0))return;this.settingsRegistry[widgetId] = {widgetId: widgetId,games: null,teams: null};this.staticHostName = this.getStaticHostName(widgetNode.href);this.label = widgetNode.innerHTML;this.attachOnLoad( function() { searchWidget.load(widgetId); } );widgetNode.id = widgetId;},getHostName: function(href){var i = href.indexOf(".com");return (i > -1) ? href.substring(7, i + 4) : "localhost";},getStaticHostName: function(href){var i = href.indexOf(".com");return (i > -1) ? "s." + href.substring(7, i + 4) : "localhost";},load: function(widgetId){this.attachStylesheet();this.render(widgetId, null);},render: function(widgetId, search){var settings = this.settingsRegistry[widgetId];var html = "<div id=\"" + widgetId + "\" class=\"infiniteSportsWidget\"><h2>" + this.label + "</h2>" +"<input type=\"text\" onkeydown=\"searchWidget.onKeyDown(event,'" + widgetId + "');\" " +"onfocus=\"searchWidget.onFocus('" + widgetId + "');\" value=\"" +(search == null ? "Enter Your City" : this.htmlEncode(search)) +"\" /><input type=\"button\" class=\"button\" onclick=\"searchWidget.onClick('" + widgetId + "');\" value=\"Go\" />" +this.getTeamsHtml(settings.teams) +this.getGamesHtml(settings.games) +"</div>";var tempNode = document.createElement("div");tempNode.innerHTML = html;var widgetNode = this.$(widgetId);widgetNode.parentNode.replaceChild(tempNode.childNodes[0], widgetNode);},renderSearchResults: function(data){var setting = this.settingsRegistry[data.widgetId];setting.games = data.games;setting.teams = data.teams;this.render(data.widgetId, data.search);},onFocus: function(widgetId){this.$(widgetId).childNodes[1].select();},onClick: function(widgetId){this.search(this.$(widgetId).childNodes[1].value, widgetId);},onKeyDown: function(event, widgetId){if (event.keyCode != 13)return;this.search(this.$(widgetId).childNodes[1].value, widgetId);},attachOnLoad: function(fn){if (typeof(window.addEventListener) != "undefined") {window.addEventListener("load", fn, false);} else if (typeof(window.attachEvent) != "undefined") {window.attachEvent("onload", fn);} else {if (window.onload != null) {var oldOnload = window.onload;window.onload = function(e) {oldOnload(e);fn();};} else {window.onload = fn;}}},attachStylesheet: function() {if (document.getElementById(this.stylesheetId) != null) {return;}var link = document.createElement("link");link.id = this.stylesheetId;link.rel = "stylesheet";link.type = "text/css";link.href = "http://" + this.staticHostName + "/SearchWidget.css";var heads = document.getElementsByTagName("head");if (heads && (heads.length > 0)) {heads[0].appendChild(link);} else {document.body.appendChild(link);}},search: function(s, widgetId){if (this.trim(s).length == 0)return;var settings = this.settingsRegistry[widgetId];settings.games = [];settings.teams = [];settings.searchValue = s;var script = document.createElement("script");script.src = "http://" + this.hostName + "/SearchWidget.ashx?q=" + s + "&tz=" +(new Date()).getTimezoneOffset() + "&wid=" + widgetId;document.body.appendChild(script);},getTeamsHtml: function(teams){if (teams == null)return "";if (teams.length == 0)return "<ul><li>No groups found.</li></ul>";var html = "<ul>";for (var i = 0; i < teams.length; i++){var team = teams[i];html += "<li><div><a href=\"http://" + this.hostName + "/Groups/" + team.tid + "\">" + team.tn + "</a></div><div>in " +team.c;if (!this.isNullOrEmpty(team.s))html += ", " + team.s;html += "</div></li>";}html += "</ul>";return html;},getGamesHtml: function(games){if ((games == null) || (games.length == 0))return "";var html = "<ul>";for (var i = 0; i < games.length; i++){var game = games[i];html += "<li><div><a href=\"http://" + this.hostName + "/Groups/" + game.gid + "\">" + game.tn +"</a></div><div>in " + game.c;if (!this.isNullOrEmpty(game.s))html += ", " + game.s;html += " for " + game.st + "</div></li>";}html += "</ul>";return html;},$: function(id){return document.getElementById(id);},isNullOrEmpty: function(s){return (s == null) || (s.length == 0);},trim: function(s) {return s.replace(/^\s+|\s+$/g, "");},htmlEncode: function(s){return s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace("\"", "&quot;");}}}searchWidget.init();