/* SteamID Ajaxified */

function matchSteamID(steamid) {
	steamid = trim(steamid)
	var re = new RegExp("^STEAM_[0-2]:[0-2]:[0-9]{1,10}$", "gi")
	var validSI = document.getElementById("validSI");
	var invalidSI = document.getElementById("invalidSI");
	//if (document.vbform.fieldname.value.match(re)) {
	if (steamid.match(re)) {
		//alert("Successful match");
		invalidSI.style.display = 'none';
		validSI.style.display = '';
		new Ajax.Request("get_player_name.php",
		{
			method: 'post',
			postBody: 'report_player_id='+ steamid,
			onComplete: showResponse2
		});
	} else {
		invalidSI.style.display = '';
		validSI.style.display = 'none';
	}
}

function registerSteamID(steamid) {
	var re = new RegExp("^STEAM_[0-2]:[0-2]:[0-9]{1,10}$", "gi")
	var validSI = document.getElementById("validSI");
	var invalidSI = document.getElementById("invalidSI");
	if (steamid.match(re)) {
		invalidSI.style.display = 'none';
		validSI.style.display = '';
		new Ajax.Request("get_player_name.php",
		{
			method: 'post',
			postBody: 'register_player_id='+ steamid,
			onComplete: showResponse2
		});
	} else {
		invalidSI.style.display = '';
		validSI.style.display = 'none';
	}
}

function showResponse2(req){
	$('get_name').innerHTML= req.responseText;
}
function displayNames(){
	var div = document.getElementById("names_table");
	if (div.style.display == '') div.style.display = 'none';
	else div.style.display = '';
}
function copySubject(subject_name){
	document.vbform.subject.value=subject_name;
}
/* end SteamID Ajaxified */

/* toggle layers as in AMXBans */
function ToggleLayer(obj) {
	if(document.all) {
	  if(document.all[obj].style.display == 'none') {
			document.all[obj].style.display = 'block';
		} else {
			document.all[obj].style.display = 'none';
		}
	} else{
		if(document.getElementById(obj).style.display == 'none') {
			document.getElementById(obj).style.display = 'table-row';
		} else {
			document.getElementById(obj).style.display = 'none';
		}
  }
}

function openURI() {
	var control = document.navigator.nav;
	if (control.options[control.selectedIndex].value != 'no-url') {
		location.href = control.options[control.selectedIndex].value;
	}
}
/* end toggle layers as in AMXBans */

/* shoutbox start */
var xmlHttp

function pagination(page, hasj)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="modules/shoutbox_sub.php";
	url = url+"?starting="+page;
	url = url+"&hasj="+hasj;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged()
{
	if (xmlHttp.readyState==4)
	{
		document.getElementById("shoutbox").update(xmlHttp.responseText);
	}
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
/* shoutbox end */

/* trim strings */
function trim(str){
    var str = str.replace(/^\s\s*/, ''),
        ws = /\s/,
        i = str.length;
    while (ws.test(str.charAt(--i)));
    return str.slice(0, i + 1);
}
/* end trim strings */