function showsub(id){
	document.getElementById(id).style.display="block";
}

function hidesub(id){
	document.getElementById(id).style.display="none";
}

function switchvisible(id){
	if(document.getElementById(id).style.display=="none")
	{
		document.getElementById(id).style.display="block";
	}
	else
	{
		document.getElementById(id).style.display="none";
	}
}

function showclothe(url,id,img) {
	var name;
	name=document.getElementById(id);
	name=name.options[name.selectedIndex].id;
	name=name.split("µµ");
	var stock=name[2];
	name=name[1];
	document.getElementById(img).src=(url + name);
	if(id=="overall")
	{
		document.getElementById("imghead").src="images/clothes/head/empty.gif";
		document.getElementById("head").selectedIndex=0;
		document.getElementById("imgface").src="images/clothes/face/empty.gif";
		document.getElementById("face").selectedIndex=0;
		document.getElementById("imgbody").src="images/clothes/body/empty.gif";
		document.getElementById("body").selectedIndex=0;
	}
	else if(id=="head" || id=="face" || id=="body")
	{
		document.getElementById("imgoverall").src="images/clothes/overall/empty.gif";
		document.getElementById("overall").selectedIndex=0;
	}
	
	if(stock=='0')
	{
		stock='Sold out!';
		document.getElementById('submit').disabled=true;
	}
	else if(stock!=undefined)
	{
		stock=stock + ' pieces';
		document.getElementById('submit').disabled=false;
	}
	document.getElementById('stock').firstChild.nodeValue=stock;
}

function showclothe2(url,id,img) {
	if(document.getElementById("random"))
	{
		document.getElementById("random").value="0";
	}
	var name;
	name=document.getElementById(id);
	name=name.options[name.selectedIndex].id;
	name=name.split("µµ");
	name=name[1];
	document.getElementById(img).src=(url + name);
	if(id=="overall")
	{
		document.getElementById("imghead").src="images/clothes/head/empty.gif";
		document.getElementById("head").selectedIndex=0;
		document.getElementById("imgface").src="images/clothes/face/empty.gif";
		document.getElementById("face").selectedIndex=0;
		document.getElementById("imgbody").src="images/clothes/body/empty.gif";
		document.getElementById("body").selectedIndex=0;
	}
	else if(id=="head" || id=="face" || id=="body")
	{
		document.getElementById("imgoverall").src="images/clothes/overall/empty.gif";
		document.getElementById("overall").selectedIndex=0;
	}
}

function updategame() {
	if(document.getElementById("name").disabled==false)
	{
		document.getElementById("name").disabled="true";
		document.getElementById("category").disabled="true";
		document.getElementById("condsort").disabled="true";
		document.getElementById("condition").disabled="true";
		document.getElementById("available").disabled="true";
		document.getElementById("description").disabled="true";
	}
	else
	{
		document.getElementById("name").disabled=false;
		document.getElementById("category").disabled=false;
		document.getElementById("condsort").disabled=false;
		document.getElementById("condition").disabled=false;
		document.getElementById("available").disabled=false;
		document.getElementById("description").disabled=false;
	}
}

function veranderz(id,number) {
	document.getElementById(id).style.zIndex=document.getElementById(number).value+2;
	if(document.getElementById('imgface').style.zIndex>document.getElementById(id).style.zIndex) document.getElementById('imgface').style.zIndex=document.getElementById('imgface').style.zIndex;
	if(document.getElementById('imgbody').style.zIndex>document.getElementById(id).style.zIndex) document.getElementById('imgbody').style.zIndex=document.getElementById('imgbody').style.zIndex;
	if(document.getElementById('imghead').style.zIndex>document.getElementById(id).style.zIndex) document.getElementById('imghead').style.zIndex=document.getElementById('imghead').style.zIndex;
	if(document.getElementById('imgtool_left').style.zIndex>document.getElementById(id).style.zIndex) document.getElementById('imgtool_left').style.zIndex=document.getElementById('imgtool_left').style.zIndex;
	if(document.getElementById('imgtool_right').style.zIndex>document.getElementById(id).style.zIndex) document.getElementById('imgtool_right').style.zIndex=document.getElementById('imgtool_right').style.zIndex;
}

function smilie(adres) {
	document.getElementById('message').value=document.getElementById('message').value + '<img src="' + adres + '" />';
}

function insertsmilie(smilie) {
	document.getElementById('text').value=document.getElementById('text').value + " " + smilie + " ";
	document.getElementById('text').focus();
}

function resethighscore() {
	for(i=1;i<11;i++)
	{
		document.getElementById("nr"+i+"name").value="";
		document.getElementById("nr"+i+"points").value="";
	}
}

function openProfile(id)
{
	MyWindow=window.open("member.php?id=" + id,id,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=750,height=405");
}

function openCompany(id)
{
	MyWindow=window.open("company.php?id=" + id,"Company","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=750,height=405");
}

//For ajax function	
var xmlhttp;
var url;
	
function ajax()
{
	
	if(window.ActiveXObject){
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else if(window.XMLHttpRequest){
		xmlhttp = new XMLHttpRequest();
	}else{
		alert("Your browser does not support AJAX! Please download Firefox or use Internet Explorer.");
	}

}

function getMember(name)
{
	ajax();
	
	var memberInfo = document.getElementById("name").value;
	function stateChanged(){
		if(xmlhttp.readyState == 4){
			document.getElementById("results").innerHTML = xmlhttp.responseText;
		}
	}
	
	url = "functions/memInfo.php?user=" + memberInfo;
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function showMembers(query)
{
	ajax();
	
	function stateChanged(){
		if(xmlhttp.readyState == 4){
			document.getElementById("results").innerHTML = xmlhttp.responseText;
		}
	}
	
	url = "functions/showMems.php?sub=" + query;
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function tradePoints()
{
	ajax();
	
	var id = document.getElementById("id").value;
	var strength = document.getElementById("strength").value;
	var intelligence = document.getElementById("intelligence").value;
	var params = "strength=" + strength + "&intelligence=" +  intelligence + "&id=" + id;
	function stateChanged(){
		if(xmlhttp.readyState == 4){
			document.getElementById("points").innerHTML = xmlhttp.responseText;
		}
	}
	
	url = "functions/tradepoints.php";
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("POST",url,true);
	
	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.send(params);
}

function flagTopic(topic,id)
{
	ajax();
	$('#results').hide();
	
	var flagInfo = document.getElementById("flagtype").value;
	var params = "flag=" + flagInfo + "&topic=" + topic + "&id=" + id;
	function stateChanged(){
		if(xmlhttp.readyState == 4){
			document.getElementById("results").innerHTML = xmlhttp.responseText;
		}
	}
	
	url = "functions/flagTopic.php";
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("POST",url,true);
	
	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.send(params);
	
	$('#flag').slideUp(800, function(){
		$('#results').slideDown(800);
	});

}

function removeFlag(flag,id)
{
	ajax();
	
	var divID = "row" + flag;
	var params = "flag=" + flag + "&id=" + id;
	function stateChanged(){
		if(xmlhttp.readyState == 4){
			document.getElementById("results").innerHTML = xmlhttp.responseText;
		}
	}
	
	url = "functions/removeFlag.php";
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("POST",url,true);
	
	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.send(params);
	
	$('#' + divID).fadeOut(500);
}

function nodTopics(cat)
{
	ajax();
	$('#results').hide();
	
	var flagInfo = document.getElementById("flagtype").value;
	var params = "flag=" + flagInfo + "&topic=" + topic + "&id=" + id;
	function stateChanged(){
		if(xmlhttp.readyState == 4){
			document.getElementById("results").innerHTML = xmlhttp.responseText;
		}
	}
	
	url = "functions/flagTopic.php";
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("POST",url,true);
	
	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.send(params);
	
	$('#flag').slideUp(800, function(){
		$('#results').slideDown(800);
	});
}

function delTopic(tid,uid)
{
	ajax();
	$('#results').hide();
	
	var divID = tid;
	var params = "tid=" + tid + "&uid=" + uid;
	function stateChanged(){
		if(xmlhttp.readyState == 4){
			document.getElementById("results").innerHTML = xmlhttp.responseText;
		}
	}
	
	url = "functions/removeTopic.php";
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("POST",url,true);
	
	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.send(params);
	
	$('#results').slideDown(800);
	$('#' + divID).fadeOut(500);
}