﻿if (location.href.toLowerCase().indexOf("go2web20-2.3/") > -1) {
	targetUrl = location.href.toLowerCase().replace("go2web20-2.3/", "");
	location.href = targetUrl;
}
if (location.href.toLowerCase().indexOf("://go2web20") > -1) {
	targetUrl = location.href.toLowerCase().replace("://go2web20", "://www.go2web20");
	location.href = targetUrl;
}


$(document).ready(function() {
	//updateBlogUpdates();
	checkIphoneVersion();
	$("#q").autocomplete("/data/suggest.aspx?tags=true", { minChars: 2, delay: 0, matchSubset: 1, matchContains: 1, cacheLength: 10, formatItem: formatSuggestion, onItemSelect: selectSuggestion });
	$("#q").focus(function() {
		$(this).addClass("focused");
	});
	$("#q").blur(function() {
		$(this).removeClass("focused");
	});
	$("#q").focus();

});

function formatSuggestion(row) {
	var s = row[0];
	//s = s.replace("_", " ");
	if (s.indexOf("tag:") > -1) {
		return s;
	} else {
		return "<b>" + s + "</b>";
	}
}
function selectSuggestion(selectedItem) {
	var s = selectedItem.innerHTML;
	if (s.indexOf("tag:") > -1) {
		location.href = "/#" + s;
	} else {
	location.href = "/app/?a=" + s.replace("<b>", "").replace("</b>", "");//.replace(" ", "_");
	}

}

function reportStats(path) {
	//pageTracker._trackPageview('/behavior/' + path);
	args = path.split("/");
	if (args.length<2) args[1] = '';
	if (args.length<3) args[2] = '';
	pageTracker._trackEvent(args[0],args[1],args[2]);
	//alert(path);
}


function updateBlogUpdates() {
		return;
	$("#blogUpdates ul").load("/data/blogUpdates.aspx",
			'',
			function() { $("#blogUpdates ul").newsticker(5000) }
			);
}

function setCookie(c_name, value, expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name + "=" + escape(value) +
((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()+";path=/");
}

function getCookie(c_name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1) {
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start, c_end));
		}
	}
	return "";
}


function installSearchEngine() {
	if (window.external && ("AddSearchProvider" in window.external)) {
		window.external.AddSearchProvider("http://files.go2web20.net/tools/openSearch.xml");
		reportStats("installSearch");
	} else {
		alert("No search engine support");
	}
}


function checkIphoneVersion() {
	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf('iphone') != -1) {
		//location.href="http://i.go2web20.net";

	}
}


  function showFeedback() {
  	$("#fdbk_tab").click();
  }
