//BEGIN thx to Weedpacket 04-25-2010, 06:13 PM
function urlEncodeCharacter(c)
{
	return '%' + c.charCodeAt(0).toString(16);
};
function urlDecodeCharacter(str, c)
{
	return String.fromCharCode(parseInt(c, 16));
};
function urlEncode( s )
{
	return escape( s ).replace( /\%20/g, '+' ).replace( /[!'()*~]/g, urlEncodeCharacter );
};
function urlDecode( s )
{
	return unescape(s.replace( /\+/g, '%20' )).replace( /\%([0-9a-f]{2})/g, urlDecodeCharacter);
};
function htmlentities(str,typ) {
if(typeof str=="undefined") str="";
if(typeof typ!="number") typ=2;
typ=Math.max(0,Math.min(3,parseInt(typ)));
var html=new Array();
html[38]="&amp;"; html[60]="&lt;"; html[62]="&gt;";
if(typ==1 || typ==3) html[39]="&#039;";
if(typ==2 || typ==3) html[34]="&quot;";
for(var i in html) eval("str=str.replace(/"+String.fromCharCode(i)+"/g,\""+html[i]+"\");");
var entity=new Array(
"&nbsp;","&iexcl;","&cent;","&pound;","&curren;","&yen;","&brvbar;","&sect;",
"&uml;","&copy;","&ordf;","&laquo;","&not;","&shy;","&reg;","&macr;",
"&deg;","&plusmn;","&sup2;","&sup3;","&acute;","&micro;","&para;","&middot;",
"&cedil;","&sup1;","&ordm;","&raquo;","&frac14;","&frac12;","&frac34;","&iquest;",
"&Agrave;","&Aacute;","&Acirc;","&Atilde;","&Auml;","&Aring;","&AElig;","&Ccedil;",
"&Egrave;","&Eacute;","&Ecirc;","&Euml;","&Igrave;","&Iacute;","&Icirc;","&Iuml;",
"&ETH;","&Ntilde;","&Ograve;","&Oacute;","&Ocirc;","&Otilde;","&Ouml;","&times;",
"&Oslash;","&Ugrave;","&Uacute;","&Ucirc;","&Uuml;","&Yacute;","&THORN;","&szlig;",
"&agrave;","&aacute;","&acirc;","&atilde;","&auml;","&aring;","&aelig;","&ccedil;",
"&egrave;","&eacute;","&ecirc;","&euml;","&igrave;","&iacute;","&icirc;","&iuml;",
"&eth;","&ntilde;","&ograve;","&oacute;","&ocirc;","&otilde;","&ouml;","&divide;",
"&oslash;","&ugrave;","&uacute;","&ucirc;","&uuml;","&yacute;","&thorn;","&yuml;"
);
for(var i in entity) eval("str=str.replace(/"+String.fromCharCode(i*1+160)+"/g,\""+entity[i]+"\");");
return str;
}

//END thx to Weedpacket 04-25-2010, 06:13 PM

function simpleURL(url)
{
	//TODO: LOCALHOST-CHANGE
	//return "http://localhost/anne/" + url;
	return "http://www.anneroessler.de/" + url;
}
function getLang()
{
	var lang = 'de';
	//alert(location.href);
	var pattern = /(.*)(\/(de|en)\/)(.*)/;
	var results = pattern.exec(location.href);
	
	if (results != null && results.length >= 2)
	{
		//get third (inner lang) subpattern out of it
		//remember, 0 = all, 1 = first, 2 = /lang/ 3 = lang
		lang = results[3];
	}
	return lang;
	/*
	for (var i = 1; i < results.length; i++) {
		alert(results[i]);
	}*/
}
$("#search_input").focus(function() {
	if ($("#search_input").val() == "Suche...")
		$("#search_input").val("");
});
$("#search_input").focusout(function() {
	if ($("#search_input").val() == "")
	{
		$("#search_input").val("Suche...");
		$("#search_button").attr("href", "#search_input");
	}
});
$("#search_input").keyup(function (event) {
	var value = $(this).val();
	if (event.keyCode != 13)
	{
		$("#search_button").attr(
				"href",
				simpleURL(
						getLang()
						+"/7_search/q_"
						+urlEncode(htmlentities(value,2))
					)
		);
	} else {
		window.location = $("#search_button").attr('href');
	}
	//alert(String.fromCharCode(event.charCode));
	//alert(String.fromCharCode(event.keyCode));
});
