window.onload = function() {
	try {
		var url = String(document.location).split("/");
		var sid = String(url[url.length-1]);
		if(sid != "") {
			document.getElementById("steam").value = sid.replace("#", "");
			doSubmit();
		}
	}
	catch(ex) {
		alert(ex);
	}
	
	// Cheating a bit to get this to pass w3 validator!
	document.getElementById("steam").setAttribute("autocomplete", "off");
	document.getElementById("center").setAttribute("align", "center");
}

function doSubmit() {
	
	if(document.getElementById("submitb").value == "Working..." || 
	(document.getElementById("ltxt").innerHTML == "Please enter a Steam ID.") && document.getElementById("steam").value == "") {
		return;
	}
	
	$("#ltxt").hide("fast");
	
	var steam = document.getElementById("steam").value;
	
	if(steam == "") {
		$("#ltxt").html("Please enter a Steam ID.");
		$("#ltxt").show("fast");
		return;
	}
	
	document.getElementById("submitb").value = "Working...";
	
	var http;
	if(window.XMLHttpRequest){
		http = new XMLHttpRequest();
	} else {
		http = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	http.onreadystatechange = function() {
		if(http.readyState == 4) {
			var rp = http.responseText;
			$("#ltxt").html(rp);
			
			document.getElementById("submitb").value = "Submit";
			
			$("#ltxt").show("fast");
		}
	}
	
	window.location.href = "http://www.steamlookup.com/#" + steam;
	
	http.open("GET", "lookup.php?steam=" + steam, true);
	http.send();
}

function enter(f,e) {
	if(e.keyCode == 13) {
		doSubmit();
	}
}
