// == SEARCH ENGINE ==

 var query = "";

 var INPUTFRAME  = parent.frames['head'];
 var OUTPUTFRAME = parent.frames['content'];

 var INPUT  = INPUTFRAME.document;
 var OUTPUT = OUTPUTFRAME.document;

function noumlaut( str )
{
	var l = 0; 		
	var i = 0; 		
	var newstr = ""; 	
	var a = "";		

	l = str.length;
	for (i=0; i<l;i++)
	{

		a = str.charAt(i);

		if ( a == "ä") { a = "&auml;" };
		if ( a == "ö") { a = "&ouml;" };
		if ( a == "ü") { a = "&uuml;" };
		if ( a == "Ä") { a = "&Auml;" };
		if ( a == "Ö") { a = "&Ouml;" };
		if ( a == "Ü") { a = "&Uuml;" };
		if ( a == "ß") { a = "&szlig;" };
		
		newstr = newstr + a ;
	}
	
	return newstr;
}

 function found( str )
 {

	 var isfound = false;
	 var s = "";
	 var q = "";
	
	 s = str.toLowerCase();	
	 q = query.toLowerCase();

	 q = noumlaut( q );

	 s = " " + s + " ";	

	 isfound = ( s.indexOf( q ) > -1 ) 

	 return( isfound );
}



function HTMLHeader()
{
	with ( OUTPUT )
	{
		writeln("<head>");
		writeln("<title>");
		writeln("</title>");
		writeln("</head>");
	}
}

function HTMLOpenBody()
{
	with ( OUTPUT )
	{
		with( INPUT.QueryForm )
		{

		write("<body");
		
		 if (bgcolor.value)
		  write(" bgcolor=\""+bgcolor.value+"\"");

		 if (text.value)
		  write(" text=\""+text.value+"\"");
		  
		 if (link.value)
		  write(" link=\""+link.value+"\"");
		  
		 if (alink.value)
		  write(" alink=\""+alink.value+"\"");

		 if (vlink.value)
		  write(" vlink=\""+vlink.value+"\"");

		 if (background.value)
		  write(" background=\""+background.value+"\"");

		writeln(">");

		}  

	{
		writeln("<table width=* border=0 cellpadding=4 cellspacing=0><tr><td>");
	}
		
	} 
}

function HTMLCloseBody()
{
	with ( OUTPUT )
	{
		writeln("</body>");
	}
}

function HTMLOpenFont()
{
	with ( OUTPUT )
	{
		with( INPUT.QueryForm )
		{
		 write("<font" );
		
		 if (font_face.value)
		  write(" face=\""+font_face.value+"\"");
		  
		 if (font_size.value)
		  write(" size=\""+font_size.value+"\"");

		writeln(">" );
		}
		
	}
}


function HTMLCloseFont()
{
	with ( OUTPUT )
	{
		writeln("</font>");
	}
}



function ListSearch()
{

	var count = 0;

	query = INPUT.QueryForm.query.value;

	with ( OUTPUT )
	{
		open();
		writeln("<html>");

		HTMLHeader();
		HTMLOpenBody();
		HTMLOpenFont();
		

		writeln("Search results for <u><i>", query, "</i></u>. We found the following games in our database:" );
		
		writeln("<ol>");
		
		for (var i=1 ; i<Entry.length; i++)
		{

			if ( found( Entry[i].Title )
			||   found( Entry[i].Keywords )
			||   found( Entry[i].Description )
			||   found( Entry[i].Status )
			   ) 
			{
				writeln("<li><p>");
				writeln( Entry[i].Format() );
				writeln("</p></li>");
				count++;
			}
		}
   		writeln("</ol>");


		if ( count == 0 )
	   	{
			writeln("<p>There are no search results for <u><i>", query, "</i></u> sorry!");
		}

		writeln("<p>No more search results. <a href='javascript:history.back()'><i>&gt; go back</i></a></p>" );
		HTMLCloseFont();
		writeln("</td></tr></table>");
		HTMLCloseBody();
		writeln('</html>');
		close();
   	}
}


function Validator()
{


	if ( INPUT.QueryForm.query.value.length < 3 )
	{
		alert( "You have to type more than two letters!" );
		INPUT.QueryForm.query.focus();
	}
	else
	{
		ListSearch();
	}
	
}


function QueryEnter()
{
	Validator();
	return (false);
}


function Help( url )
{
	OUTPUT.location = url;
}




function Format() 
 {

	with( this )
	{

	var e = "";

	e = e + "<a href=\"" + this.Url + "\" target=content>";
	e = e + "<b>" + Title + "</b>\n";
	e = e + "</a>\n";

	if ( Status && ( Status == "available" ))
	 e = e + " - <font color=#33c47e><i>" + Status + "</i></font>" + "\n";

	if ( Status && ( Status != "available" ))
	 e = e + " - <font color=red><i>" + Status + "</i></font>" + "\n";
	
	if ( Description && ( Description != "-" ))
		
	 e = e + "<br>" + Description + "\n";
 
	}
	return(e);
}



function Element(Url,Title,Description,Status,Keywords) 
{

	this.Url           = Url;
	this.Title         = Title;
	this.Description   = Description;
	this.Keywords      = Keywords;
	this.Status        = Status;
	
	this.Format        = Format;
}



Entry    = new Array();