var debugParts = new Array('sessions', 'posts', 'get', 'server', 'db', 'cookies', 'memory');
function loadgame()
{
	// alert('test');
	window.open('/game.html','game','scrollbars=0,resizable=0,width=770,height=580');
}

function switchDebug(debugpart)
{
	for(var x=0; x<debugParts.length; x++)
	{
		if(document.getElementById(debugParts[x] + '_debug'))
		{
			document.getElementById(debugParts[x] + '_debug').style.display = 'none';
		}
	}
	
	if(document.getElementById(debugpart))
	{
		document.getElementById(debugpart).style.display = 'block';
	}
}

function switchOffDebug(debugpart)
{
	if(document.getElementById(debugpart))
	{
		document.getElementById(debugpart).style.display = 'none';
	}
}

function contestList(pageurl, counter)
{
	$.ajax(
	  {
		type: 'POST',
		url: '/ajax',
		data: 'type=' + pageurl + '&page=' + counter,
		success:function(response)
		{
			if(response != '')
			{
				$('#' + pageurl + '_list_slider').html('');
				$('#' + pageurl + '_list_slider').append(response);
			}
		}
	  });
}

function checkPrefill(jquery_element, prefilled, fill)
{
	if(fill == 1)
	{
		if(jquery_element.val() == prefilled)
		{
			jquery_element.val('');
			jquery_element.removeClass('prefill');
		}
	}
	else
	{
		if(jquery_element.val() == '')
		{
			jquery_element.val(prefilled);
			jquery_element.addClass('prefill');
		}
	}
}

function openPopupDialog(id)
{
	$('#' + id).show();
}
function closePopupDialog(id)
{
	$('#' + id).hide();
} 

function isValidEmailAddress(emailAddress)
{
	if(trim(emailAddress, " ") == "")
	{
		return false;
	}

	return new RegExp(/^[^@]+@[^@]+\.[^@]{2,}$/).test(trim(emailAddress));
}


function trim(str, chars)
{
	return ltrim(rtrim(str, chars), chars);
}


function ltrim(str, chars)
{
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}


function rtrim(str, chars)
{
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
