function showRace(str)
{
if (str=="" || str=="0")
  {
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	  //document.getElementById("AjaxTest").innerHTML=xmlhttp.responseText;
	  document.getElementById("raceDesc").innerHTML = xmlhttp.responseText;

    }
  }
xmlhttp.open("GET", "getRaceDesc.php?raceId="+str,true);
xmlhttp.send();
}

function copyNPC(id, name) {
  if (id == '' || id == '0')
    return;
  if (name == '' || name == '0')
    return;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	  
	  document.getElementById("NPCs").innerHTML = document.getElementById("NPCs").innerHTML + xmlhttp.responseText;

    }
  }
xmlhttp.open("GET", "copyNPC.php?id="+id+"&name="+name,true);
xmlhttp.send();	
	
}

function showClass(str)
{
if (str=="" || str=="0")
  {
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	  //document.getElementById("AjaxTest").innerHTML=xmlhttp.responseText;
	  document.getElementById("classInfo").innerHTML = xmlhttp.responseText;

    }
  }
xmlhttp.open("GET", "showClass.php?class_id="+str,true);
xmlhttp.send();
}

function showModDesc(str)
{
if (str=="")
  {
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	  //document.getElementById("AjaxTest").innerHTML=xmlhttp.responseText;
	  var data =  xmlhttp.responseText;
	  data = data.replace(/\s/g, '+');
	  data = data.replace(/'/g, "\\'");
	  data = data.replace(/"/g, '\\"');
	  
	  day = new Date();
	  id = day.getTime();

	  var URL = 'DialogPopUp.php?&data=' + data;
	  eval("page" + id + " = window.open('" + URL + "', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=400,left=150,top=150');");
    }
  }
xmlhttp.open("GET", "modDesc.php?mod_id="+str,true);
xmlhttp.send();
}

function showMobDesc(str)
{
if (str=="")
  {
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	  //document.getElementById("AjaxTest").innerHTML=xmlhttp.responseText;
	  var data =  xmlhttp.responseText;
	  data = data.replace(/\s/g, '+');
	  data = data.replace(/'/g, "\\'");
	  data = data.replace(/"/g, '\\"');
	  
	  day = new Date();
	  id = day.getTime();

	  var URL = 'DialogPopUp.php?&data=' + data;
	  eval("page" + id + " = window.open('" + URL + "', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=400,left=150,top=150');");
    }
  }
xmlhttp.open("GET", "getMobDesc.php?mob_id="+str,true);
xmlhttp.send();
}

function moveAjax(str)
{
if (str=="")
  {
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	  document.getElementById("roomInfo").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET", "move.php?room_id="+str,true);
xmlhttp.send();
}

function performFlee(str)
{
if (str=="")
  {
  return;
  }

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	  document.getElementById("fightMsgArchive").innerHTML = document.getElementById("fightMsg").innerHTML + document.getElementById("fightMsgArchive").innerHTML; 
	  document.getElementById("fightMsg").innerHTML=xmlhttp.responseText;
	 
    }
  }
xmlhttp.open("GET", "flee.php?combat_id="+str,true);
xmlhttp.send();
}

function getCombatStats(str)
{
if (str=="")
  {
  return;
  }
  
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttpCombat=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttpCombat=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttpCombat.onreadystatechange=function()
  {
  if (xmlhttpCombat.readyState==4 && xmlhttpCombat.status==200)
    {
	  document.getElementById("combatStats").innerHTML=xmlhttpCombat.responseText;
    }
  }
xmlhttpCombat.open("GET", "getCombatStats.php?combat_id="+str,true);
xmlhttpCombat.send();
}

function calc_cp(value) {

	if (value == 10) {
		return 0;
	}
	else if (value == 7) {
		return -4;
	}
	else if (value == 8) {
		return -2;
	}
	else if (value == 9) {
		return -1;
	}
	else if (value == 11) {
		return 1;
	}
	else if (value == 12) {
		return 2;
	}
	else if (value == 13) {
		return 3;
	}
	else if (value == 14) {
		return 5;
	}
	else if (value == 15) {
		return 7;
	}
	else if (value == 16) {
		return 10;
	}
	else if (value == 17) {
		return 13;
	}
	else if (value == 18) {
		return 17;
	}
	return 99;
	
	
}
 
 
function increaseStat(name){

  var cost = calc_cp(parseInt(document.getElementById(name).value) + 1) - calc_cp(parseInt(document.getElementById(name).value));

  var creationPoints = parseInt(document.getElementById('creationPoints').value);

  if (cost > creationPoints) {
    alertDialog('You do not have enough creation points to make that increase.');
    return;
  }

  var stat = parseInt(document.getElementById(name).value);

  if (stat == 18) {
    alertDialog('You cannot increase any stat above 18.');
    return;
  }

  document.getElementById('creationPoints').value = parseInt(document.getElementById('creationPoints').value) - cost;


  document.getElementById(name).value = parseInt(document.getElementById(name).value) + 1;

}

function decreaseStat(name) {

  var cost = calc_cp(parseInt(document.getElementById(name).value)) - calc_cp(parseInt(document.getElementById(name).value) - 1);

  var stat = parseInt(document.getElementById(name).value);

  if (stat == 7) {
    alertDialog('You cannot decrease any stat below 7.');
    return;
  }

  document.getElementById('creationPoints').value = parseInt(document.getElementById('creationPoints').value) + cost;


  document.getElementById(name).value = parseInt(document.getElementById(name).value) - 1;

}

function addMyGames(cid, lurker) {
	window.location = "add-my-games.php?cid="+cid+"&lurker="+lurker;
}
