function moveObject( eid, e ) 
{
  // step 1
  var tempX = 0;
  var tempY = 0;
  var offset = 5;

  // step 2
  var obj = document.getElementById(eid);
  if (obj==null) return;

  // step 3
  if (document.all) {
    tempX = event.clientX + document.body.scrollLeft;
    tempY = event.clientY + document.body.scrollTop;
  } else {
    tempX = e.pageX;
    tempY = e.pageY;
  }

  // step 4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}

  // step 5
  obj.style.top  = (tempY + offset) + 'px';
  obj.style.left = (tempX + offset - 200) + 'px';

}


function hidePop()
{
	document.getElementById("popup0").style.visibility = "hidden";
}

var xmlHttp;

function changeIL(e)
{
	moveObject("popup0", e);
	document.getElementById("popup0t").innerHTML = document.getElementById("ailcontent").innerHTML;
	document.getElementById("popup0").style.visibility = "visible";	
}

function changeIL2()
{	
	xmlHttp=GetXmlHttpObject()
	
	if (xmlHttp==null)
	{
	  alert ("Your browser does not support AJAX!");
	  return;
	} 
	
	var newail = document.getElementById("newail");
	
	var url="farmstuff.php";
	url=url+"?qid="+Math.random();
	url=url+"&rtype=newail";
	url=url+"&lid="+newail.options[newail.selectedIndex].value;

	xmlHttp.onreadystatechange=ilstateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function ilstateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("abox").innerHTML = xmlHttp.responseText;
		
		if (document.getElementById("error"))
		{
			document.getElementById("popup0t").innerHTML = "<br><center><b>Error: </b>"+document.getElementById("error").innerHTML+"<br><br><span class=\"spanClick\" onClick=\"hidePop()\" >[x] Close Window</span>";
		}
		else
		{
			location.href = "farm.php";
		}
	}
}

function editName(e)
{
	moveObject("popup0", e);
	document.getElementById("popup0t").innerHTML = document.getElementById("namecontent").innerHTML;
	document.getElementById("popup0").style.visibility = "visible";
}

function editName2()
{	
	xmlHttp=GetXmlHttpObject()
	
	if (xmlHttp==null)
	{
	  alert ("Your browser does not support AJAX!");
	  return;
	} 

	document.getElementById("changename").disabled = true;
	document.getElementById("changename").value="Loading...";
	
	var url="farmstuff.php";
	url=url+"?qid="+Math.random();
	url=url+"&rtype=name";
	url=url+"&name="+escape(document.getElementById("newname").value);

	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("abox").innerHTML = xmlHttp.responseText;
		
		if (document.getElementById("error"))
		{
			document.getElementById("popup0t").innerHTML = "<br><center><b>Error: </b>"+document.getElementById("error").innerHTML+"<br><br><span class=\"spanClick\" onClick=\"hidePop()\" >[x] Close Window</span>";
		}
		else
		{
			document.getElementById("pasturename").innerHTML = document.getElementById("nname").innerHTML;
			document.getElementById("popup0").style.visibility = "hidden";
		}
	}
}


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;
}