// JavaScript Document
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;
}
function checkhints()
{
	var sqlid=document.getElementById("textfield").value;
	if(sqlid!="")
	{
		xmlHttp=GetXmlHttpObject();
		var parameters = "id=" + encodeURIComponent(sqlid);
		xmlHttp.onreadystatechange = getnewresponse;
		xmlHttp.open("POST", "checkhints.php", true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.send(parameters);
		return true;
	}
	else
	{
		resetclue();
	}
}
function getnewresponse() {
	if (xmlHttp.readyState == 4) {
       	if (xmlHttp.status == 200) {
           	var result = xmlHttp.responseText;
			if(result!="")
			{	
				var div=document.getElementById("clue");
				div.innerHTML=result;
				div.style.display="block";
			}
			else
			{
				resetclue();
			}
        } else {
           	alert("Server code error. Refresh this page.");
        }
     }
}
function changecolor(a)
{
	a.style.backgroundColor="#666666";
}
function resetcolor(a)
{
	a.style.backgroundColor="";
}
function sendvalue(a)
{
	document.getElementById("textfield").value=a.innerHTML;
	resetclue();
	submitform();
}
function resetclue()
{
	var divv=document.getElementById("clue");
	divv.innerHTML="";
	divv.style.display="none";
}
function submitform()
{
	window.location = "index.php?word="+document.getElementById("textfield").value;
}
var formm="";
function addd()
{
	num=document.getElementById('filenum').value;
	num++;
	var newdiv = document.createElement('div');
	newdiv.innerHTML = "<input name=\"word"+num+"\" type=\"text\" id=\"word"+num+"\" onfocus=\"if (this.value=='Word') this.value='';\" onblur=\"if (this.value=='') this.value='Word';\" value=\"Word\" />:<input type=\"text\" name=\"meaning"+num+"\" id=\"meaning"+num+"\" onfocus=\"if (this.value=='Meaning') this.value='';\" onblur=\"if (this.value=='') this.value='Meaning';\" value=\"Meaning\" /><br  />";
	document.getElementById('file_form').appendChild(newdiv);
	document.getElementById('filenum').value=num;
}
function deletthis(a)
{
	xmlHttpp=GetXmlHttpObject();
	xmlHttpp.onreadystatechange = showhintlist;
	var url="deletthis.php?id="+a;
	xmlHttpp.open("GET",url,true);
	xmlHttpp.send(null);
}
function deletthiss(a)
{
	xmlHttpp=GetXmlHttpObject();
	xmlHttpp.onreadystatechange = showall;
	var url="deletthis.php?id="+a;
	xmlHttpp.open("GET",url,true);
	xmlHttpp.send(null);
}
function showhintlist()
{
	document.getElementById("awordlist").innerHTML="Please wait...";
	var sqlid=document.getElementById("hint").value;
	if(sqlid!="")
	{
		xmlHttp=GetXmlHttpObject();
		var parameters = "id=" + encodeURIComponent(sqlid);
		xmlHttp.onreadystatechange = getnewresponse2;
		xmlHttp.open("POST", "checkhints.php", true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.send(parameters);
		return true;
	}
	else
	{
		document.getElementById("awordlist").innerHTML="";
	}
}
function showall()
{
	document.getElementById("awordlist").innerHTML="Please wait...";
	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange = getnewresponse2;
	var url="showall.php?";
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function getnewresponse2() {
	if (xmlHttp.readyState == 4) {
       	if (xmlHttp.status == 200) {
           	var result = xmlHttp.responseText;
			if(result!="")
			{	
				document.getElementById("awordlist").innerHTML=result;
			}
			else
			{
				document.getElementById("awordlist").innerHTML="<font color=red>No word found.</font>";
				
			}
        }
     }
}
function editthis(a)
{
	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange = editthis1;
	var url="getsinglerow.php?id="+a;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function editthis1() {
	if (xmlHttp.readyState == 4) {
       	if (xmlHttp.status == 200) {
           	var result = xmlHttp.responseText;
			if(result!="")
			{	
				var one=result.split("%#",3);
				document.getElementById("editword").value=one[0];
				document.getElementById("editmeaning").value=one[1];
				document.getElementById("editid").value=one[2];
				document.getElementById("editpop").style.display="block";
			}
			else
			{
				document.getElementById("awordlist").innerHTML="<font color=red>Error. try again...</font>";
				
			}
        }
     }
}
function editit()
{
	var word, meaning, id;
	word=document.getElementById("editword").value;
	meaning=document.getElementById("editmeaning").value;
	id=document.getElementById("editid").value;
	xmlHttpp=GetXmlHttpObject();
	var parameters = "id=" + encodeURIComponent(id) +"&word=" + encodeURIComponent(word) + "&meaning=" + encodeURIComponent(meaning);
	xmlHttpp.onreadystatechange = editit1;
	xmlHttpp.open("POST", "editthis.php", true);
	xmlHttpp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttpp.send(parameters);
}
function editit1() {
	if (xmlHttpp.readyState == 4) {
       	if (xmlHttpp.status == 200) {
           	var result = xmlHttpp.responseText;
			if(result=="true")
			{	
				document.getElementById("editpop").style.display="none";
				document.getElementById("awordlist").innerHTML="<font color=green>Editing successful.</font>";
			}
			else
			{
				document.getElementById("editpop").style.display="none";
				document.getElementById("awordlist").innerHTML="<font color=red>Error. try again...</font>";
			}
        }
     }
}
