/* Using abbreviation YG for all YG content related*/
if (typeof YG == "undefined")
{
	var YG = {};
}

YG.SearchBox = function()
{
	this.Type = 1,
	this.BaseURL = 'http://aoc.yg.com/',
	this.OpenNewWindow = false,
	this.UseJavaScript = false
}

YG.SearchBox.prototype =
{
	Get: function()
	{
		var StyleSheet = 'http://aoc.yg.com/tools/css/yg_searchbox.css';
		var StylePrefixes = {1 : 'yg_aoc_search_120', 2 : 'yg_aoc_search_160', 3: 'yg_aoc_search_480', 4: 'yg_aoc_search_189'};
		var Style = StylePrefixes[this.Type] ? StylePrefixes[this.Type] : StylePrefixes[1];
		var Action = '', InputId = 'yg_aoc_search_' + Math.floor(Math.random() * 123456789);

		document.write('<link rel="stylesheet" type="text/css" media="all" href="' + StyleSheet + '">');
		document.write('<div class="yg_aoc_search ' + Style + '"><a href="' + this.BaseURL + '" title="Age of Conan Database"><div id="yg_aoc_link"></div></a>');

		if(this.OpenNewWindow)
			Action = 'target="_blank"';

		if(this.UseJavaScript)
		{
			if(this.OpenNewWindow)
				Action = "window.open('" + this.BaseURL + "search?s='+document.getElementById('" + InputId + "').value);";
			else
				Action = "window.location.href='" + this.BaseURL + "search?s='+document.getElementById('" + InputId + "').value;"

			document.write('<input type="text" name="s" title="Age of Conan Search" id="' + InputId + '" class="yg_aoc_search" maxlength="256" onkeydown="var e = e || event;if((e.keyCode||e.which)==13){ if(this.value == \'\') return false; else ' + Action + '}"/>');
			document.write('<button type="submit" onclick="if(document.getElementById(\'' + InputId + '\').value == \'\') return false; else ' + Action + '" id="yg_aoc_search_submit"></button></div>');
		}
		else
		{
			document.write('<form ' + Action +' method="GET" action="' + this.BaseURL + 'search" onsubmit="if(document.getElementById(\'' + InputId + '\').value == \'\') return false;" class="yg_aoc_search_form"><input name="s" maxlength="256" title="Age of Conan Search" id="' + InputId + '" class="yg_aoc_search"><button type="submit" id="yg_aoc_search_submit"></button></form></div>');
		}
	}
}

YG.Search = new YG.SearchBox();