
var colWidth = 180;
var extWidth = 200;

function OnColorChanged (uniqueId, index, color)
{	
	var i = 0;
	while (true)
	{				    
		var divId = uniqueId + '_' + i;
		var o = (document.all) ? document.all[divId] : document.getElementById (divId);		    		    
		if (o == null)
			break;

		o.style.visibility = (i == index) ? 'visible' : 'hidden';
			
		i++;
	}
	
	if (color == '')
		color = ' '; // this is not an space character, it is an ALT-255		
	SetLayerText ('cl_' + uniqueId, color);
}

function OnFilterBySerie (serie, postBack)
{	
	try
	{
		var sysArr = new Array ();	
		var o1 = (document.all) ? document.all['tbSerie'] : document.getElementById ('tbSerie');
		var o2 = (document.all) ? document.all['tbSystem'] : document.getElementById ('tbSystem');
		if (o1 != null && o2 != null)
		{
			o1.style.display = 'none';
			o2.style.display = '';
			
			for (var i=0; i < pSystemList.length; i++)	
			{
				var pSystem = pSystemList[i];
				var sysKey = pSystem.SysCode + ':' + pSystem.SubCode;				
				var display = (pSystem.Serie == serie.toUpperCase () && !ArrayContainsValue (sysArr, sysKey)) ? '' : 'none';
				if (display == '')
					sysArr[sysArr.length] = sysKey;
					
				for (var j=0; j < 15; j++)
				{
					var rowId = pSystem.UniqueId + '_' + i + '_' + j;
					var o = (document.all) ? document.all[rowId] : document.getElementById (rowId);
					if (o != null)
					{	
						if (o.style.diplay == display)
							break;
						o.style.display = display;	
					}
				}
			}		
			
			var o = (document.all) ? document.all['compare-all'] : document.getElementById ('compare-all');	
			if (o != null)
				o.style.width = ((sysArr.length * colWidth) + extWidth) + 'px';							
		}
		
		if (postBack)
		{
			var frame = document.getElementById ("control-frame");			
			if (frame != null)
			{			
				var doc = frame.contentWindow.document;
						
				var o = (doc.all) ? doc.all['_ctl2_htmlInputHidden_Systems'] : doc.getElementById ('_ctl2_htmlInputHidden_Systems');	
				if (o != null)
					o.value = sysArr.join (';');									
					
				var o = (doc.all) ? doc.all['_ctl2_htmlInputHidden_Event'] : doc.getElementById ('_ctl2_htmlInputHidden_Event');
				if (o != null)
					o.value = 'window.onload = new function () { window.top.OnFilterBySerie (\'' + serie + '\', false); }';							

				frame.contentWindow.__doPostBack ('', '');
			}
		}
	}
	catch (e)
	{
		//alert ('OnFilterBySerie Error: \n\n' + s);
	}	
}

function OnFilterByPlatform (cpuType, postBack)
{	
	try
	{
		var sysArr = new Array ();	
		var o1 = (document.all) ? document.all['tbSerie'] : document.getElementById ('tbSerie');
		var o2 = (document.all) ? document.all['tbSystem'] : document.getElementById ('tbSystem');
		if (o1 != null && o2 != null)
		{
			o1.style.display = 'none';
			o2.style.display = '';
			
			for (var i=0; i < pSystemList.length; i++)	
			{
				var pSystem = pSystemList[i];
				var sysKey = pSystem.SysCode + ':' + pSystem.SubCode;				
				var display = (pSystem.CpuType == cpuType && !ArrayContainsValue (sysArr, sysKey)) ? '' : 'none';
				if (display == '')
					sysArr[sysArr.length] = sysKey;
					
				for (var j=0; j < 15; j++)
				{		
					var rowId = pSystem.UniqueId + '_' + i + '_' + j;
					var o = (document.all) ? document.all[rowId] : document.getElementById (rowId);
					if (o != null)
					{	
						if (o.style.diplay == display)
							break;
						o.style.display = display;	
					}
				}
			}		
					
			var o = (document.all) ? document.all['compare-all'] : document.getElementById ('compare-all');	
			if (o != null)
				o.style.width = ((sysArr.length * colWidth) + extWidth) + 'px';			
		}	
		
		if (postBack)
		{
			var frame = document.getElementById ("control-frame");			
			if (frame != null)
			{			
				var doc = frame.contentWindow.document;
						
				var o = (doc.all) ? doc.all['_ctl2_htmlInputHidden_Systems'] : doc.getElementById ('_ctl2_htmlInputHidden_Systems');	
				if (o != null)
					o.value = sysArr.join (';');									
					
				var o = (doc.all) ? doc.all['_ctl2_htmlInputHidden_Event'] : doc.getElementById ('_ctl2_htmlInputHidden_Event');
				if (o != null)
					o.value = 'window.onload = new function () { window.top.OnFilterByPlatform (' + cpuType + ', false); }';							
			}
		}				
	} 
	catch (e)
	{
		//alert ('OnFilterByPlatform Error: ' + e.message);
	}
	
	return postBack;
}

function OnFilterByPriceRange (minPrice, maxPrice, postBack)
{
	try 
	{
		var sysArr = new Array ();	
		var o1 = (document.all) ? document.all['tbSerie'] : document.getElementById ('tbSerie');
		var o2 = (document.all) ? document.all['tbSystem'] : document.getElementById ('tbSystem');
		if (o1 != null && o2 != null)
		{
			o1.style.display = 'none';
			o2.style.display = '';
					
			for (var i=0; i < pSystemList.length; i++)	
			{
				var pSystem = pSystemList[i];
				var sysKey = pSystem.SysCode + ':' + pSystem.SubCode;				
				var display = (pSystem.Price >= minPrice && pSystem.Price <= maxPrice && !ArrayContainsValue (sysArr, sysKey)) ? '' : 'none';
				if (display == '')
					sysArr[sysArr.length] = sysKey;		
					
				for (var j=0; j < 15; j++)
				{		
					var rowId = pSystem.UniqueId + '_' + i + '_' + j;
					var o = (document.all) ? document.all[rowId] : document.getElementById (rowId);
					if (o != null)
					{	
						if (o.style.diplay == display)
							break;
						o.style.display = display;	
					}
				}
			}		
			
			var o = (document.all) ? document.all['compare-all'] : document.getElementById ('compare-all');	
			if (o != null)
			{
				o.style.width = ((sysArr.length * colWidth) + extWidth) + 'px';	
				o.style.backgroundcolor='#FF0000';
			}
		}
			
		if (postBack)
		{	
			var frame = document.getElementById ("control-frame");			
			if (frame != null)
			{
				var doc = frame.contentWindow.document;

				var o = (doc.all) ? doc.all['_ctl2_htmlInputHidden_Systems'] : doc.getElementById ('_ctl2_htmlInputHidden_Systems');
				if (o != null)
					o.value = sysArr.join (';');
					
				var o = (doc.all) ? doc.all['_ctl2_htmlInputHidden_Event'] : doc.getElementById ('_ctl2_htmlInputHidden_Event');
				if (o != null)
					o.value = 'window.onload = new function () { window.top.OnFilterByPriceRange (' + minPrice + ', ' + maxPrice + ', false); }';			
			}
		}
	}
	catch (e)
	{
		//alert ('OnFilterByPriceRange Error: ' + e.message);
	}	
	
	return postBack;
}

function OnFilterByPerformance (performance, postBack)
{
	try
	{
		var sysArr = new Array ();	
		var o1 = (document.all) ? document.all['tbSerie'] : document.getElementById ('tbSerie');
		var o2 = (document.all) ? document.all['tbSystem'] : document.getElementById ('tbSystem');
		if (o1 != null && o2 != null)
		{
			o1.style.display = 'none';
			o2.style.display = '';

			for (var i=0; i < pSystemList.length; i++)	
			{
				var pSystem = pSystemList[i];
				var sysKey = pSystem.SysCode + ':' + pSystem.SubCode;				
				var display = (pSystem.Performance == performance && !ArrayContainsValue (sysArr, sysKey)) ? '' : 'none';
				if (display == '')
					sysArr[sysArr.length] = sysKey;
					
				for (var j=0; j < 15; j++)
				{		
					var rowId = pSystem.UniqueId + '_' + i + '_' + j;
					var o = (document.all) ? document.all[rowId] : document.getElementById (rowId);
					if (o != null)
					{	
						if (o.style.diplay == display)
							break;
						o.style.display = display;	
					}
				}
			}
			
			var o = (document.all) ? document.all['compare-all'] : document.getElementById ('compare-all');	
			if (o != null)
				o.style.width = ((sysArr.length * colWidth) + extWidth) + 'px';							
		}
		
		if (postBack)
		{	
			var frame = document.getElementById ("control-frame");			
			if (frame != null)
			{
				var doc = frame.contentWindow.document;
		
				var o = (doc.all) ? doc.all['_ctl2_htmlInputHidden_Systems'] : doc.getElementById ('_ctl2_htmlInputHidden_Systems');
				if (o != null)
					o.value = sysArr.join (';');
					
				var o = (doc.all) ? doc.all['_ctl2_htmlInputHidden_Event'] : doc.getElementById ('_ctl2_htmlInputHidden_Event');
				if (o != null)
					o.value = 'window.onload = new function () { window.top.OnFilterByPerformance (' + performance + ', false); }';				
			}		
		}
	}
	catch (e)
	{
		//alert ('OnFilterByPerformance Error: ' + e.message);
	}	
	
	return postBack;
}

function OnFilterByFormFactor (formFactor, postBack)
{
	try
	{			
		var sysArr = new Array ();
		var o1 = (document.all) ? document.all['tbSerie'] : document.getElementById ('tbSerie');
		var o2 = (document.all) ? document.all['tbSystem'] : document.getElementById ('tbSystem');
		if (o1 != null && o2 != null)
		{
			o1.style.display = 'none';
			o2.style.display = '';
												
			for (var i=0; i < pSystemList.length; i++)	
			{
				var pSystem = pSystemList[i];						
				var sysKey = pSystem.SysCode + ':' + pSystem.SubCode;	
				var display = (pSystem.FormFactor == formFactor && !ArrayContainsValue (sysArr, sysKey)) ? '' : 'none';
				if (display == '')
					sysArr[sysArr.length] = sysKey;
				
				for (var j=0; j < 15; j++)
				{		
					var rowId = pSystem.UniqueId + '_' + i + '_' + j;
					var o = (document.all) ? document.all[rowId] : document.getElementById (rowId);
					if (o != null)
					{	
						if (o.style.diplay == display)
							break;
						o.style.display = display;	
					}
				}			
			}	
						
			var o = (document.all) ? document.all['compare-all'] : document.getElementById ('compare-all');	
			if (o != null)
				o.style.width = ((sysArr.length * colWidth) + extWidth) + 'px';	
		}
		
		if (postBack)
		{	
			var frame = document.getElementById ("control-frame");			
			if (frame != null)
			{
			
				var doc = frame.contentWindow.document;
			
				var o = (doc.all) ? doc.all['_ctl2_htmlInputHidden_Systems'] : doc.getElementById ('_ctl2_htmlInputHidden_Systems');
				if (o != null)
					o.value = sysArr.join (';');
					
				var o = (doc.all) ? doc.all['_ctl2_htmlInputHidden_Event'] : doc.getElementById ('_ctl2_htmlInputHidden_Event');
				if (o != null)
					o.value = 'window.onload = new function () { window.top.OnFilterByFormFactor (' + formFactor + ', false); }';		
			}
		}
	}
	catch (e)
	{
		//alert ('OnFilterByFormFactor Error: ' + e.message);
	}
	
	return postBack;
}

function OnFilterByScreenSize (screenSize, postBack)
{
	try
	{
		var sysArr = new Array ();
		var o1 = (document.all) ? document.all['tbSerie'] : document.getElementById ('tbSerie');
		var o2 = (document.all) ? document.all['tbSystem'] : document.getElementById ('tbSystem');
		if (o1 != null && o2 != null)
		{
			o1.style.display = 'none';
			o2.style.display = '';
			
			for (var i=0; i < pSystemList.length; i++)	
			{
				var pSystem = pSystemList[i];
				var sysKey = pSystem.SysCode + ':' + pSystem.SubCode;				
				var display = (pSystem.ScreenSize == screenSize && !ArrayContainsValue (sysArr, sysKey)) ? '' : 'none';
				if (display == '')
					sysArr[sysArr.length] = sysKey;
					
				for (var j=0; j < 15; j++)
				{		
					var rowId = pSystem.UniqueId + '_' + i + '_' + j;
					var o = (document.all) ? document.all[rowId] : document.getElementById (rowId);
					if (o != null)
					{	
						if (o.style.diplay == display)
							break;
						o.style.display = display;	
					}
				}			
			}	
			
			var o = (document.all) ? document.all['compare-all'] : document.getElementById ('compare-all');	
			if (o != null)
				o.style.width = ((sysArr.length * colWidth) + extWidth) + 'px';	
		}

		if (postBack)
		{	
			var frame = document.getElementById ("control-frame");			
			if (frame != null)
			{
			
				var doc = frame.contentWindow.document;
			
				var o = (doc.all) ? doc.all['_ctl2_htmlInputHidden_Systems'] : doc.getElementById ('_ctl2_htmlInputHidden_Systems');
				if (o != null)
					o.value = sysArr.join (';');
					
				var o = (doc.all) ? doc.all['_ctl2_htmlInputHidden_Event'] : doc.getElementById ('_ctl2_htmlInputHidden_Event');
				if (o != null)
					o.value = 'window.onload = new function () { window.top.OnFilterByScreenSize (' + screenSize + ', false); }';		
			}
		}
	}
	catch (e)
	{
		//alert ('OnFilterByScreenSize Error: ' + e.message);
	}
	
	return postBack;
}

function OnFilterBySystemType (systemType, postBack)
{
	try
	{
		var sysArr = new Array ();
		var o1 = (document.all) ? document.all['tbSerie'] : document.getElementById ('tbSerie');
		var o2 = (document.all) ? document.all['tbSystem'] : document.getElementById ('tbSystem');
		if (o1 != null && o2 != null)
		{
			o1.style.display = 'none';
			o2.style.display = '';
			
			for (var i=0; i < pSystemList.length; i++)	
			{
				var pSystem = pSystemList[i];
				var sysKey = pSystem.SysCode + ':' + pSystem.SubCode;				
				var display = (pSystem.SystemType == systemType && !ArrayContainsValue (sysArr, sysKey)) ? '' : 'none';
				if (display == '')
					sysArr[sysArr.length] = sysKey;
					
				for (var j=0; j < 15; j++)
				{		
					var rowId = pSystem.UniqueId + '_' + i + '_' + j;
					var o = (document.all) ? document.all[rowId] : document.getElementById (rowId);
					if (o != null)
					{	
						if (o.style.diplay == display)
							break;
						o.style.display = display;	
					}
				}			
			}	
			
			var o = (document.all) ? document.all['compare-all'] : document.getElementById ('compare-all');	
			if (o != null)
				o.style.width = ((sysArr.length * colWidth) + extWidth) + 'px';	
		}

		if (postBack)
		{	
			var frame = document.getElementById ("control-frame");			
			if (frame != null)
			{
			
				var doc = frame.contentWindow.document;
			
				var o = (doc.all) ? doc.all['_ctl2_htmlInputHidden_Systems'] : doc.getElementById ('_ctl2_htmlInputHidden_Systems');
				if (o != null)
					o.value = sysArr.join (';');
					
				var o = (doc.all) ? doc.all['_ctl2_htmlInputHidden_Event'] : doc.getElementById ('_ctl2_htmlInputHidden_Event');
				if (o != null)
					o.value = 'window.onload = new function () { window.top.OnFilterBySystemType (' + systemType + ', false); }';		
			}
		}
	}
	catch (e)
	{
		//alert ('OnFilterBySystemType Error: ' + e.message);
	}
	
	return postBack;
}

function OnViewAllSeries ()
{
	var o1 = (document.all) ? document.all['tbSerie'] : document.getElementById ('tbSerie');
	var o2 = (document.all) ? document.all['tbSystem'] : document.getElementById ('tbSystem');
	if (o1 != null && o2 != null)
	{
		o1.style.display = '';
		o2.style.display = 'none';
										
		var o = (document.all) ? document.all['compare-all'] : document.getElementById ('compare-all');	
		if (o != null)
		{
			o.style.width = ((GetSeriesCount () * colWidth) + extWidth) + 'px';
		}
	}
}

function OnViewAllSystems ()
{
	var o1 = (document.all) ? document.all['tbSerie'] : document.getElementById ('tbSerie');
	var o2 = (document.all) ? document.all['tbSystem'] : document.getElementById ('tbSystem');
	if (o1 != null && o2 != null)
	{
		o1.style.display = 'none';
		o2.style.display = '';
				
		var o = (document.all) ? document.all['compare-all'] : document.getElementById ('compare-all');	
		if (o != null)
			o.style.width = ((pSystemList.length * colWidth) + extWidth) + 'px';					
	}
}

function GetQueryString ()
{
	return "gaming_sortby.aspx";
	var queryString = '';
	var url = window.top.location.toString ();
	var idx = url.indexOf ('?');
	if (idx != -1)
		queryString = url.substr (idx, url.length - idx + 1);
	return queryString;	
}

function ArrayContainsValue (arr, value)
{
	for (var i=0; i < arr.length; i++)
	{
		if (arr[i] == value)
			return true;
	}
	
	return false;
}

function GetSeriesCount ()
{
	var cnt = 0;
	
	var arr = new Array ();
	for (var i=0; i < pSystemList.length; i++)
	{
		var serie = pSystemList[i].Serie;
		if (!arr[serie])
		{
			arr[serie] = serie;
			cnt++;
		}				
	}
	
	return cnt;
}