// 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];
}

function tabster (which, on, me){
	for (i=1;i<4;i++){
		document.getElementById( on+'_tab_'+i+'_c' ).style.display='none';
		document.getElementById( on+'_tab_'+i ).getElementsByTagName("a")[0].className = 'sdTabsunselecteda';
	}

	document.getElementById( on+'_tab_'+which+'_c' ).style.display='block';
	document.getElementById( on+'_tab_'+which ).getElementsByTagName("a")[0].className = 'sdTabsselecteda';

}

function psinit (){
	var initps = new revAjax('/site/playertracking/');
	initps.send('init=db&' + window.location.search.substring(1), 'initps');
}

function initps (data){
	dataset2 = eval( '(' + data + ')' );
	document.getElementById( 'psloader' ).style.display='none';
	if ( dataset2.servers <= 150 ) {
		loadStats(dataset2.pid);
		document.getElementById( 'serverData' ).style.display='block';
		document.getElementById( 'searchResult' ).style.display='none';
	}
	else {
		document.getElementById( 'psinfo' ).style.display='block';
		document.getElementById( 'psinfo' ).innerHTML = '' + 
			'<p>Unfortunatly we have decided not to load the data for the requested player.' +
			'<p>The player you requested statistics on has been tracked' +
			' on over 150 servers in the past week. In fact they have been tracked on ' +  dataset2.servers
			+ ' servers with over over ' + dataset2.time + ' minutes played! This most likley means that ' +
			' this player name is not unique. If you play under this name, you should probably use ' +
			' something more unique.</p> ' +
			'<p>Feel free to search for a different player. </p>'+
			'We\'re sorry for any inconvenience caused.</p>';
	}
}

function loadServerStats ( sid, pid ){
	tabster(2,'sd');
	Jemplate.process('serverstats.html', '/site/playertracking/?func=serverstats&sid='+ sid +'&pid=' + pid , '#sd_tab_2_c');
}

function changeStatImg(img,sid,pid){
	//alert(document.getElementById('prStatsDataHolder').innerHTML);
	//document.getElementById('prStatsDataHolder').innerHTML = 'test test <img src="/bin/'+img+'?pid='+pid+'&sid='+sid+''+'&_r=' + Math.random()+'" width="400" height="350">';
	document.pstatsg.src = '/bin/'+img+'?pid='+pid+'&sid='+sid+''+'&_r=' + Math.random() ;
	return(true);
}


function loadStats ( pid ){
	tabster(1,'sd');
	Jemplate.process('overview.html', '/site/playertracking/?func=overview&pid=' + pid, '#psSummary');
	Jemplate.process('servers.html',  '/site/playertracking/?func=servers&pid=' + pid , '#sd_tab_1_c');
	Jemplate.process('tools.html',    '/site/playertracking/?func=tools&pid=' + pid , '#sd_tab_3_c');
}



function sortResult (data) {
	var mydiv = document.getElementById('searchResult');
	mydiv.innerHTML = '';
	var obj = eval( '(' + data + ')' );
	eval(obj.javascript);
}

psinit();
/*
   This JavaScript code was generated by Jemplate, the JavaScript
   Template Toolkit. Any changes made to this file will be lost the next
   time the templates are compiled.

   Copyright 2006 - Ingy döt Net - All rights reserved.
*/

if (typeof(Jemplate) == 'undefined')
    throw('Jemplate.js must be loaded before any Jemplate template files');

Jemplate.templateMap['index.html'] = function(context) {
    if (! context) throw('Jemplate function called without context\n');
    var stash = context.stash;
    var output = '';

    try {
output += '\r\nasdasdasd';
    }
    catch(e) {
        var error = context.set_error(e, output);
        throw(error);
    }

    return output;
}

Jemplate.templateMap['online.html'] = function(context) {
    if (! context) throw('Jemplate function called without context\n');
    var stash = context.stash;
    var output = '';

    try {
output += '<table width="240" border="0" cellspacing="0" cellpadding="0">\r\n  <tr>\r\n    <th colspan="6" scope="col">Top 10 BF2 Maps </th>\r\n  </tr>\r\n  <tr>\r\n    <th scope="col">map</th>\r\n    <th scope="col">players</th>\r\n    <th scope="col">servers</th>\r\n  </tr>\r\n';
//line 16 "online.html"

// FOREACH 
(function() {
    var list = stash.get('ranks');
    list = new Jemplate.Iterator(list);
    var retval = list.get_first();
    var value = retval[0];
    var done = retval[1];
    var oldloop;
    try { oldloop = stash.get('loop') } finally {}
    stash.set('loop', list);
    try {
        while (! done) {
            stash.data['map'] = value;
output += '\r\n  <tr>\r\n    <td><a href="http://www.serverspy.net/site/search/?w=3&t=1&n=';
//line 12 "online.html"
output += stash.get(['map', 0, 0, 0]);
output += '&g=27&ty=gpm_cq" target="_blank">';
//line 12 "online.html"
output += stash.get(['map', 0, 0, 0]);
output += '</a></td>\r\n    <td>';
//line 13 "online.html"
output += stash.get(['map', 0, 1, 0]);
output += '</td>\r\n    <td>';
//line 14 "online.html"
output += stash.get(['map', 0, 2, 0]);
output += '</td>\r\n  </tr>\r\n';;
            retval = list.get_next();
            value = retval[0];
            done = retval[1];
        }
    }
    catch(e) {
        throw(context.set_error(e, output));
    }
    stash.set('loop', oldloop);
})();

output += '\r\n</table>\r\n';
    }
    catch(e) {
        var error = context.set_error(e, output);
        throw(error);
    }

    return output;
}

Jemplate.templateMap['overview.html'] = function(context) {
    if (! context) throw('Jemplate function called without context\n');
    var stash = context.stash;
    var output = '';

    try {
output += '<table border="0" cellpadding="0" cellspacing="0" width="550">\r\n  <tr>\r\n	<th colspan="10" class="main" align="center">';
//line 3 "overview.html"
output += stash.get('playername');
output += '<br><span class="submain">stats over last 7 days</span></th>\r\n  </tr>\r\n  <tr>\r\n	<th width="20%">games played</th>\r\n	<td width="30%">';
//line 7 "overview.html"
output += stash.get('games');
output += '</td>\r\n	<th width="20%">total score</th>\r\n	<td width="30%">';
//line 9 "overview.html"
output += stash.get('score');
output += '</td>\r\n  </tr>\r\n  <tr>\r\n	<th>servers played</th>\r\n	<td>';
//line 13 "overview.html"
output += stash.get('servers');
output += '</td>\r\n	<th>score per minute</th>\r\n	<td>';
//line 15 "overview.html"
output += stash.get('scm');
output += '</td>\r\n  </tr>\r\n  <tr>\r\n	<th>time played</th>\r\n	<td>';
//line 19 "overview.html"
output += stash.get('time');
output += '</td>\r\n	<th>rating</th>\r\n	<td>';
//line 21 "overview.html"
output += stash.get('rating');
output += '</td>\r\n  </tr>\r\n</table>';
    }
    catch(e) {
        var error = context.set_error(e, output);
        throw(error);
    }

    return output;
}

Jemplate.templateMap['servers.html'] = function(context) {
    if (! context) throw('Jemplate function called without context\n');
    var stash = context.stash;
    var output = '';

    try {
output += '<table width="550" border="0" cellspacing="0" cellpadding="0">\r\n  <tr>\r\n    <th colspan="6" class="main"> ';
//line 3 "servers.html"
output += stash.get('playername');
output += ' has been tracked on these servers</th>\r\n  </tr>\r\n  <tr>\r\n    <th scope="col">server</th>\r\n    <th scope="col">time played</th>\r\n    <th scope="col">totalscore</th>\r\n    <th scope="col">rank</th>\r\n  </tr>\r\n';
//line 18 "servers.html"

// FOREACH 
(function() {
    var list = stash.get('servers');
    list = new Jemplate.Iterator(list);
    var retval = list.get_first();
    var value = retval[0];
    var done = retval[1];
    var oldloop;
    try { oldloop = stash.get('loop') } finally {}
    stash.set('loop', list);
    try {
        while (! done) {
            stash.data['type'] = value;
output += '\r\n  <tr>\r\n    <td><a href="javascript:;" onclick="loadServerStats(';
//line 13 "servers.html"
output += stash.get(['type', 0, 1, 0]);
output += ', ';
//line 13 "servers.html"
output += stash.get('pid');
output += ')">';
//line 13 "servers.html"
output += stash.get(['type', 0, 0, 0]);
output += '</a></td>\r\n    <td>';
//line 14 "servers.html"
output += stash.get(['type', 0, 3, 0]);
output += '</td>\r\n    <td>';
//line 15 "servers.html"
output += stash.get(['type', 0, 2, 0]);
output += '</td>\r\n    <td>';
//line 16 "servers.html"
output += stash.get(['type', 0, 4, 0]);
output += '</td>\r\n  </tr>\r\n';;
            retval = list.get_next();
            value = retval[0];
            done = retval[1];
        }
    }
    catch(e) {
        throw(context.set_error(e, output));
    }
    stash.set('loop', oldloop);
})();

output += '\r\n</table>\r\n';
    }
    catch(e) {
        var error = context.set_error(e, output);
        throw(error);
    }

    return output;
}

Jemplate.templateMap['serverstats.html'] = function(context) {
    if (! context) throw('Jemplate function called without context\n');
    var stash = context.stash;
    var output = '';

    try {
output += '<table width="550" border="0" cellspacing="0" cellpadding="0">\r\n  <tr>\r\n    <th colspan="4" class="main">';
//line 3 "serverstats.html"
output += stash.get(['server', 0, 'name', 0]);
output += '<br><span class="submain">';
//line 3 "serverstats.html"
output += stash.get('playername');
output += '\'s statistics</span></th>\r\n  </tr>\r\n  <tr>\r\n	<th width="20%">player rank</th>\r\n	<td width="30%">';
//line 7 "serverstats.html"
output += stash.get(['rank', 0, 'current', 0]);
output += '</td>\r\n	<th width="20%">server</th>\r\n	<td width="30%"><a href="/site/search/server.html?a=';
//line 9 "serverstats.html"
output += stash.get(['server', 0, 'ip', 0]);
output += '&g=';
//line 9 "serverstats.html"
output += stash.get(['server', 0, 'game', 0]);
output += '">view server details</a></td>\r\n  </tr>\r\n  <tr>\r\n	<th>score per minute</th>\r\n	<td>';
//line 13 "serverstats.html"
output += stash.get(['player', 0, 'spm', 0]);
output += '</td>\r\n	<th>game</th>\r\n	<td>';
output += ' ';
//line 15 "serverstats.html"
output += stash.get(['server', 0, 'gamename', 0]);
output += '</td>\r\n  </tr>\r\n  <tr>\r\n	<th>total score</th>\r\n	<td>';
//line 19 "serverstats.html"
output += stash.get(['player', 0, 'score', 0]);
output += '</td>\r\n	<th>ip/address</th>\r\n	<td>';
//line 21 "serverstats.html"
output += stash.get(['server', 0, 'ip', 0]);
output += '</td>\r\n  </tr>\r\n  <tr>\r\n	<th>total time</th>\r\n	<td>';
//line 25 "serverstats.html"
output += stash.get(['player', 0, 'timeplayed', 0]);
output += '</td>\r\n	<th>type</th>\r\n	<td>';
//line 27 "serverstats.html"
output += stash.get(['server', 0, 'type', 0]);
output += '</td>\r\n  </tr>\r\n\r\n</table>\r\n<table width="550" border="0" cellspacing="0" cellpadding="0">\r\n  <tr>\r\n    <td colspan="2" id="prStatsDataHolder"><img name="pstatsg" src="/bin/graphPrStats3.mpl?pid=';
//line 33 "serverstats.html"
output += stash.get('pid');
output += '&sid=';
//line 33 "serverstats.html"
output += stash.get('sid');
output += '" width="400" height="350"></td>\r\n	<td  colspan="2" valign="top"><table width="125" border="0" cellspacing="0" cellpadding="0">\r\n      <tr><th scope="col">graphs</th></tr>\r\n	  <tr><td><a href="javascript:;" onmouseover="changeStatImg(\'graphPrStats3.mpl\', ';
//line 36 "serverstats.html"
output += stash.get('sid');
output += ' ,';
//line 36 "serverstats.html"
output += stash.get('pid');
output += ')">Score Per Minute</a></td></tr>\r\n	  <tr><td><a href="javascript:;" onmouseover="changeStatImg(\'graphPrStats1.mpl\', ';
//line 37 "serverstats.html"
output += stash.get('sid');
output += ' ,';
//line 37 "serverstats.html"
output += stash.get('pid');
output += ')">Time Played</a></td></tr>\r\n	  <tr><td><a href="javascript:;" onmouseover="changeStatImg(\'graphPrStats2.mpl\', ';
//line 38 "serverstats.html"
output += stash.get('sid');
output += ' ,';
//line 38 "serverstats.html"
output += stash.get('pid');
output += ')">Total Scores</a></td></tr>\r\n	  <tr><td><a href="javascript:;" onmouseover="changeStatImg(\'graphPrStats4.mpl\', ';
//line 39 "serverstats.html"
output += stash.get('sid');
output += ' ,';
//line 39 "serverstats.html"
output += stash.get('pid');
output += ')">Rankings</a></td></tr>\r\n	</table></td>\r\n  </tr>\r\n</table>\r\n\r\n';
    }
    catch(e) {
        var error = context.set_error(e, output);
        throw(error);
    }

    return output;
}

Jemplate.templateMap['tools.html'] = function(context) {
    if (! context) throw('Jemplate function called without context\n');
    var stash = context.stash;
    var output = '';

    try {
output += '<table width="550" border="0" cellspacing="0" cellpadding="0" align="center">\r\n<tr><th class="main" align="center">PlayerHandyMonitor</th></tr>\r\n<tr><th>for when you need a forum signature image or a banner for yourself</th></tr>\r\n<tr><td align="center"><img src="http://www.serverspy.net/bin/pmon.mpl?pid=';
//line 4 "tools.html"
output += stash.get('pidbase62');
output += '" width="525" height="80"></td></tr>\r\n<tr><th>your html code</th></tr>\r\n<tr>\r\n<td>\r\n<textarea name="null" style="position:relative;width:535;height:100px;text-align: left;" onclick="this.focus();this.select()">\r\n<a href="http://www.serverspy.net/site/playertracking/?pid=!';
//line 9 "tools.html"
output += stash.get('pidbase62');
output += '">\r\n<img src="http://www.serverspy.net/bin/pmon.mpl?pid=';
//line 10 "tools.html"
output += stash.get('pidbase62');
output += '" border="0">\r\n</a></textarea>\r\n</td>\r\n</tr>\r\n</table>';
    }
    catch(e) {
        var error = context.set_error(e, output);
        throw(error);
    }

    return output;
}

