/*
***************************************
www.serverspy.net

Search Result v1

Author:	Pierre Smolarek <pierre@smolarek.com>
Date:	06 January 2002
***************************************
*/

var resultsData = '';

// QUERY_STRING parser by Pierre Smolarek
// email: pierre@smolarek.com
// Version: 2000.12.01.01
var queryString = location.search;
var pairs = new Array();
var splitpairs = new Array();
var form = new Array();
queryString = queryString.substring(1);
pairs = queryString.split('&');
pairsCount = pairs.length;

for (loop=0;loop<pairsCount;loop++){
	splitpairs = pairs[loop].split('=');
	splitpairs[0] = unescape(splitpairs[0]);
	splitpairs[1] = unescape(splitpairs[1]);
	form[splitpairs[0]] = splitpairs[1];
}
//-----

/*
var ssgames = new Array ();
ssgames['g0'] = new Array ();
ssgames['g0']['name'] = 'Half-Life';
ssgames['g0']['launcher'] = 'halflife';

ssgames['g9'] = new Array ();
ssgames['g9']['name'] = 'Meda of Honour';
ssgames['g9']['launcher'] = 'mohaa';

ssgames['g7'] = new Array ();
ssgames['g7']['name'] = 'Battlefield 1942';
ssgames['g7']['launcher'] = 'bf1942';

ssgames['g12'] = new Array ();
ssgames['g12']['name'] = 'Call Of Duty';
ssgames['g12']['launcher'] = 'cod';

ssgames['g13'] = new Array ();
ssgames['g13']['name'] = 'Unreal Tournament 2004';
ssgames['g13']['launcher'] = 'ut2k4';

ssgames['g14'] = new Array ();
ssgames['g14']['name'] = 'Battlefield Vietnam';
ssgames['g14']['launcher'] = 'bfv';
*/

// Start Search Draw
function start (){
	thisObject('results').innerHTML = "";
	drawResults(0);
	thisObject('results').innerHTML=resultsData;
	if (DL < 1) thisObject('results').innerHTML += '<BR><CENTER style="color:'+rpgcss['noMatch']['color']+';">Sorry, there are no results to your search.</CENTER><BR><BR>';
	window.location.href='#searcherArea';
}

// Initial Animation
function drawResults (loop){
	if (DL > 0){

		if (loop < DL) {
			id = 'R'+loop;
			resultsData = resultsData + '<DIV ID="'+id+'" STYLE="position:relative; text-align: left; width: 500; height:15; background-color: '+rpgcss[SCB(loop)]['background-color']+'; font-family: '+rpgcss[SCB(loop)]['font-family']+'; font-size: '+rpgcss[SCB(loop)]['font-size']+'; color: '+rpgcss[SCB(loop)]['color']+'; overflow: hidden; z-index:1001">'+insertData(loop)+'</DIV>';
			window.status = loop;
			count = loop +1;
			drawResults(count);

		} 
	} else {
		thisObject('results').innerHTML += '<BR><CENTER style="color:'+rpgcss['noMatch']['color']+';">Sorry, there are no results to your search.</CENTER><BR><BR>';
	}
}

// Secondary anim + insert data
function insertData(loop){
	id = 'R'+loop;
	return(createShortResult(id,loop));
}

// Mini Search results 
function createShortResult(id,loop){
	detail = 'detail'+id;
	mini = 'mini'+id;
	return('<DIV ID="'+mini+'" STYLE="position:absolute; left:0; top:0; width:500; height:15; z-index:1010; text-align: left; cursor: help;" onmouseover="style.backgroundColor=\''+rpgcss[SCB(loop)]['hover-background-color']+'\'" onmouseout="style.backgroundColor=\''+rpgcss[SCB(loop)]['background-color']+'\'" onclick="info(\''+loop+'\')">'+
			'<DIV STYLE="position:absolute: top:0; left:0; width:150; z-index:1005;text-align: left; overflow:hidden;color:'+rpgcss[SCB(loop)]['namecolor']+'"> &nbsp;'+ data[loop][0] +'</DIV>' +
			'<DIV STYLE="position:absolute; top:0; left:150; width:250; z-index:1005;text-align: left; overflow:hidden;">'+ data[loop][1] +'</DIV>' +
			'<DIV STYLE="position:absolute; top:0; left:400; width:80; z-index:1005; overflow:hidden;">'+ data[loop][5] +'</DIV>' +
			'<DIV STYLE="position:absolute; top:3; left:480; width:20; z-index:1005;"><input name="" style="border:0" type="image" border="0" height=10 width=15 src="http://img.serverspy.net/mapper/'+ data[loop][6].toLocaleLowerCase() +'.gif"></DIV>'+
		'</DIV>'+
		'<DIV ID="'+detail+'" STYLE="position:absolute; top:0; left:0; width:500; z-index:1006;"></DIV>');
}

// Show extended info
function info (uin,show){
	id = 'R'+uin;
	detail = 'detail'+id;
	mini = 'mini'+id;

	if (show){
		infoResizeDown(id,250,uin);
		return(0);

	} else {
		thisObject(mini).style.visibility = 'hidden';

		thisObject(id).style.border=rpgcss[SCB(uin)]['info-border'];
		thisObject(id).style.borderStyle='solid'; 
		thisObject(id).style.borderWidth = 1; 

		detail = 'detail'+id;
		joinIN = "joinIn(\'"+data[uin][2]+"\',\'"+data[uin][9]+"\',\'"+data[uin][4]+"\',0);";

		thisObject(detail).innerHTML = '<DIV style="position:absolute;width:500;height:15;cursor:hand;background-color:'+rpgcss[SCB(uin)]['infoheader-background-color']+';z-index:2000" onclick="info(\''+uin+'\',1);">&nbsp;<B>'+data[uin][0]+'</B></DIV>'+
			'<DIV STYLE="position:absolute;top:15;width:500;background-color: '+rpgcss[SCB(uin)]['background-color']+';"><table width="500" style="font-family: '+rpgcss[SCB(uin)]['font-family']+'; font-size: '+rpgcss[SCB(uin)]['font-size']+'; color: '+rpgcss[SCB(uin)]['color']+';" border="0"><tr>'+
			'<td colspan="2"><font class="title">Player name: </font> '+data[uin][0]+'</td>'+
			'<td colspan="2"><div align="right" class="title">Server location: <img border="0" height=10 width=15 style="border:0" src="http://img.serverspy.net/mapper/'+ data[uin][6].toLocaleLowerCase() +'.gif"></font></div>'+
			'</td></tr><tr> <td class="seen"> '+
			'<div align="right"><font size="1">last seen '+data[uin][9]+' seconds ago in:</div></td>'+
			'<td colspan="3"><a STYLE="font-family: '+rpgcss['link']['font-family']+'; font-size: '+rpgcss['link']['font-size']+'; color: '+rpgcss['link']['color']+';" HREF="http://www.serverspy.net/site/search/server.html?a='+data[uin][2]+'&g='+data[uin][3]+'">'+data[uin][1]+'</a></font></td>'+
			'</tr></table><br><table width="250" style="font-family: '+rpgcss[SCB(uin)]['font-family']+'; font-size: '+rpgcss[SCB(uin)]['font-size']+'; color: '+rpgcss[SCB(uin)]['color']+';" border="0" align="left"><tr> '+
			'<td width="50%" valign="middle"><font class="title">game :</font> <A STYLE="font-family: '+rpgcss['link']['font-family']+'; font-size: '+rpgcss['link']['font-size']+'; color: '+rpgcss['link']['color']+';" HREF="/site/stats/mods.html?g='+data[uin][3]+'">'+data[uin][11]+'</a></td></tr><tr> '+
			'<td width="50%" valign="middle"><font class="title">map :</font> '+data[uin][5]+'</td></tr><tr> '+
			'<td width="50%" valign="middle"><font class="title">game type :</font> <A STYLE="font-family: '+rpgcss['link']['font-family']+'; font-size: '+rpgcss['link']['font-size']+'; color: '+rpgcss['link']['color']+';" HREF="/site/stats/modstats.html?g='+data[uin][3]+'&mod='+data[uin][4]+'">'+data[uin][4]+'</A></td></tr><tr>'+ 
			'<td width="50%" valign="middle"><font class="title">ip address:</font> '+data[uin][2]+'</td></tr><tr> '+
			'<td width="50%" valign="middle"><font class="title">players :</font> '+data[uin][7]+'/'+data[uin][8]+'</td>'+
			'</tr><tr><td width="50%" valign="middle"> </td></tr></table><table width="250" border="0"><tr> '+
			'<td rowfont="4" width="50%" valign="middle" align="center"><A STYLE="font-family: '+rpgcss['link']['font-family']+'; font-size: '+rpgcss['link']['font-size']+'; color: '+rpgcss['link']['color']+';" HREF="http://www.serverspy.net/site/mapinfo/upload.html?g='+data[uin][3]+'&m='+data[uin][4]+'&u='+data[uin][5]+'" alt="Click to upload a new Map Pic for '+data[uin][5]+'"><img border="0" src="http://www.serverspy.net/bin/map.mpl?m='+data[uin][5]+'&g='+data[uin][3]+'" width="150"height="113"></A></td>'+
			'</tr></table><br><table width="500" border="0" style="font-family: '+rpgcss[SCB(uin)]['font-family']+'; font-size: '+rpgcss[SCB(uin)]['font-size']+'; color: '+rpgcss[SCB(uin)]['color']+';"><tr> '+
			'<td ALIGN="CENTER"><A STYLE="font-family: '+rpgcss['link']['font-family']+'; font-size: '+rpgcss['link']['font-size']+'; color: '+rpgcss['link']['color']+';" HREF="http://www.serverspy.net/site/search/server.html?a='+data[uin][2]+'&g='+data[uin][3]+'">Click here for LIVE Server Details</A></td>'+
			'<td> <A STYLE="font-family: '+rpgcss['link']['font-family']+'; font-size: '+rpgcss['link']['font-size']+'; color: '+rpgcss['link']['color']+';" HREF="javascript:;" ONCLICK="'+joinIN+'">Click \'n Join</A> '+
			'</td></tr></table></DIV>';
		
		infoResizeUp(id,0,0);
		return(1);
	}
}

// Odd \ even colors
function SCB(x){
	if (( x % 2 ) == 0){
		return('row1');
	} else {
		return('row2');
	}

}

// Animation of drop down of extended info
function infoResizeUp(id,by,speed){
	if (by < 230){
		count = by+speed;
//		if (speed <=10) speed2 = speed+4;
		speed2 = 30;
		thisObject(id).style.height = count;
		setTimeout("infoResizeUp(id,count,speed2)",10);
	} else {
		thisObject(id).style.height=230;
	}
	return(1);
}

// Animation of drop back up of extended info
function infoResizeDown(id,by,uin){
	myUin = uin;
	if (by > 15){
		newBy = by - 30;
		thisObject(id).style.height = by;
		setTimeout("infoResizeDown(id,newBy,myUin)",1);
	} else {
		thisObject(id).style.height=15;
		thisObject(id).style.borderWidth = 0; 
		thisObject(id).innerHTML = createShortResult(id,uin);
		return(1);
	}
}

// Minimize search reults ready for new data
function shrinkWrap (loop){
	if (loop != 0) {
		count = loop -1;
		id = 'R'+count;
		thisObject(id).style.height=0;
		setTimeout("shrinkWrap(count)",20);
	
	} else {
		thisObject('results').innerHTML = "";
		return(1);
	}
}

function submitSearch (){
	if (document.form1.n.value == ""){
		alert('Rumor has it that if your searching for something,\nthat you need to actually search FOR something.\n\nTIP: Try entering something into the \'name\' field.');
	} else {
		document.form1.submit();
	}
}

function joinIn (ip,game,mod,password){
//	'hls','t2s','q3s','q2s','q3s'
	
	if (confirm("To join this server you'll need to install some software.\n\n"+
		"The software is FREE, so don't worry about that.\n\n"+
		"If you know that the GameLauncher is installed then \n"+
		"click 'OK' and i'll launch the game for you.\n\n"+
		"If you need to download and install the software \n"+
		"(only 1.5 min download on a 56k, ~700kB)\n"+
		"then click 'Cancel' and i'll take you to a website.")){

		var pass;
		if (password){
			pass = prompt(
			'The server you wish to join - $General[2] - needs a password.\\n'+
			'Please enter the password below.\\n');
		}
//		window.location.href='gamelauncher://'+ip+';'+game+';'+mod+';'+pass+';';
		win2 = window.open('gamelauncher://'+ip+';'+game+';'+mod+';'+pass+';', "gamelauncher",'width=100,height=100,top=1000');
		setTimeout("window.win2.close();",2000);

	} else {

		win = window.open("http://www.serverspy.net/gamelauncher/?ref=sm", "gamelauncher");
	}
}

function thisObject(id){
	// current standard for IE5+ Mozilla/NS6+
	if (document.getElementById) {
		return(document.getElementById(id));
	
	// IE 4 compatible
	} else if (document.all) {
		return(document.all[id]);
	} 
}

