
function gameOnChange()
{
	var ports = port_arr[$('#game').val()];
	$('#join_port').val(ports[0]);
	$('#query_port').val(ports[1]);
	if ($('#game').val() == 'quake2')//QUAKE 2
	{
		$('#query_port_p').css('display', 'block');
	}
	else if (ports[0] == ports[1])
	{
		$('#query_port_p').css('display', 'none');
	}
	else
	{
		$('#query_port_p').css('display', 'block');
	}
}
function joinPortOnChange()
{
	var game = $('#game').val();
	if (game == 62)//TEAMSPEAK
	{
		//$('#query_port').val(51234);
		return;
		
	}
	if (game == 16)//TEAMSPEAK3
	{
		return;
	}	
	else if(parseInt($('#join_port').val()) == parseInt(port_arr[game][0]))
	{
		$('#query_port').val(parseInt(port_arr[game][1])); //selected join port plus port offset		
	}	
	else
	{
		$('#query_port').val(parseInt($('#join_port').val()) + parseInt(port_arr[game][2])); //selected join port plus port offset
	}
}
function confirmation()
{
	//JOIN PORT
	if(!checkPort($('#join_port').val()))
	{
		alert('The join port you have entered is invalid.');
		$('#join_port').focus();
		return false;
	}
	//QUERY PORT
	if(!checkPort($('#query_port').val()))
	{
		alert('The query port you have entered is invalid.');
		$('#query_port').focus();
		return false;
	}
	//DOTTED IP
	var ipAddress = document.getElementById('ip_address').value;
	var ipPattern = /^ *(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}) *$/;
	var ipArray = ipAddress.match(ipPattern);
	if (ipArray != null)
	{
		//PRIVATE IP
		// 10.0.0.0 тАУ 10.255.255.255
		if (ipArray[1] == 10)
		{
			alert('Private IP addresses cannot be scanned by GameTracker. Please enter a public IP address.');
			return false;
		}
		// 172.16.0.0 тАУ 172.31.255.255
		if ((ipArray[1] == 172) && (ipArray[2] >= 16) && (ipArray[2] <= 31))
		{
			alert('Private IP addresses cannot be scanned by GameTracker. Please enter a public IP address.');
			return false;
		}
		// 192.168.0.0 тАУ 192.168.255.255
		if ((ipArray[1] == 192) && (ipArray[2] == 168))
		{
			alert('Private IP addresses cannot be scanned by GameTracker. Please enter a public IP address.');
			return false;
		}
		//alert("dotted ip");
	}
	//DOTTED IP PLUS PORT
	var ipPattern = /^ *(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}):\d+ *$/;
	var ipArray = ipAddress.match(ipPattern);
	if (ipArray != null)
	{
		alert('You have entered both an IP address and port into the IP address box.');
		return false;
	}
	return true;
	document.form.submit();
}
function checkPort(port)
{
	re = new RegExp("^[0-9]+$");
	if (!port.match(re))
		return false;
	if (port <= 1)
		return false;
	if (port > 65535)
		return false;
	return true;
}
