var xmlHttp,xmlHttp2,xmlHttp3,xmlHttp4,xmlHttp5,xmlHttp6;
var temp_letter;

function search_phrase()
{
		xmlHttp4 = null;
		xmlHttp4=GetXmlHttpObject();
		if (xmlHttp4==null)
		{
			alert ("Browser does not support HTTP Request")
			return
		} 
		var url="search_phrase.php";
		var temp_word = document.getElementById('search_phrase').value;
		while(temp_word.match(' '))
			temp_word = temp_word.replace(' ','+');
		
		url=url+"?word="+temp_word;
		
		xmlHttp4.onreadystatechange=search_phrase_exe;
		xmlHttp4.open("GET",url,true);
		xmlHttp4.send(null);
}

function search_phrase_exe() 
{ 
	if (xmlHttp4.readyState==4 || xmlHttp4.readyState=="complete")
	{
		xmlDoc=xmlHttp4.responseXML;
		var htmlCODE = "";
		var y,yy;
		var x=xmlDoc.getElementsByTagName("RESULT");
		y  = x[0].getElementsByTagName("PHRASE")[0].childNodes[0].nodeValue;
		yy = x[0].getElementsByTagName("EXPLAIN")[0].childNodes[0].nodeValue;
		
		if( y == "nill" )
		{
			document.getElementById('word_explain').innerHTML = "";
			xmlHttp4 = null;
		}
		else
		{
			htmlCODE += "<b>"+y+"</b><br>";
			htmlCODE += "<div class=\"Arial_10 phrase_explain\">"+yy+"</div>";
			
			document.getElementById('word_explain').innerHTML = htmlCODE;
			xmlHttp4 = null;
		}
	}
}

function related_word_search()
{
		xmlHttp5 = null;
		xmlHttp5=GetXmlHttpObject();
		if (xmlHttp5==null)
		{
			alert ("Browser does not support HTTP Request")
			return
		} 
		var url="related_word.php";
		var temp_word = document.getElementById('search_phrase').value;
		while(temp_word.match(' '))
			temp_word = temp_word.replace(' ','+');
		
		url=url+"?word="+temp_word;
		xmlHttp5.onreadystatechange=related_word_search_exe;
		xmlHttp5.open("GET",url,true);
		xmlHttp5.send(null);
}

function related_word_search_exe() 
{ 
	if (xmlHttp5.readyState==4 || xmlHttp5.readyState=="complete")
	{
		xmlDoc=xmlHttp5.responseXML;
		var htmlCODE = "";
		var x=xmlDoc.getElementsByTagName("RESULT");
		
		if( x[0].getElementsByTagName("PHRASE")[0].childNodes[0].nodeValue == "nill" )
		{
			document.getElementById('related_word').innerHTML = "";
			xmlHttp5 = null;
		}
		else
		{
			for (i=0;i<x.length;i++)
			{
				var y,yy;
				y = yy = x[i].getElementsByTagName("PHRASE")[0].childNodes[0].nodeValue;
				yy = yy.replace(' ','&nbsp;');
				
				htmlCODE += " &nbsp; <a class=\"btn_relate_words\" href=# onClick=\"document.getElementById('search_phrase').value='"+y.replace('\'','\\\'')+"';search_phrase();close_word_search();related_word_search();\">"+yy+"</a>";
			}
			htmlCODE = htmlCODE.replace(' &nbsp; ','');
			
			document.getElementById('related_word').innerHTML = htmlCODE;
			xmlHttp5 = null;
		}
	}
}

function close_word_search()
{
		xmlHttp6 = null;
		document.getElementById('close_word').innerHTML = "<div align=center>LOADING<br><img src=\"http://www.asiabs.com/glossary/26-0.gif\"></div>";
		xmlHttp6=GetXmlHttpObject();
		if (xmlHttp6==null)
		{
			alert ("Browser does not support HTTP Request")
			return
		} 
		var url="close_word.php";
		var temp_word = document.getElementById('search_phrase').value;
		url=url+"?word="+temp_word.replace(' ','+');
		xmlHttp6.onreadystatechange=close_word_search_exe;
		xmlHttp6.open("GET",url,true);
		xmlHttp6.send(null);
}

function close_word_search_exe() 
{ 
	if (xmlHttp6.readyState==4 || xmlHttp6.readyState=="complete")
	{
		xmlDoc=xmlHttp6.responseXML;
		var htmlCODE = "";
		var x=xmlDoc.getElementsByTagName("RESULT");
		
		if( x[0].getElementsByTagName("PHRASE")[0].childNodes[0].nodeValue == "nill" )
		{
			document.getElementById('close_word').innerHTML = "";
			xmlHttp6 = null;
		}
		else
		{
			htmlCODE += "<ul class=\"Arial_10\" style=\"margin:0px;padding:0px;list-style-type:none\">";
			for (i=0;i<x.length;i++)
			{
				var y = x[i].getElementsByTagName("PHRASE")[0].childNodes[0].nodeValue;
				
				if( i%2 == 0 )
					htmlCODE += "<li style=\"padding:2px 0px 2px 4px;background-color:#FAFAFA\"><a href=# onClick=\"document.getElementById('search_phrase').value='"+y.replace('\'','\\\'')+"';search_phrase();close_word_search();related_word_search();\">"+y+"</a></li>";
				else
					htmlCODE += "<li style=\"padding:2px 0px 2px 4px\"><a href=# onClick=\"document.getElementById('search_phrase').value='"+y.replace('\'','\\\'')+"';search_phrase();close_word_search();related_word_search();\">"+y+"</a></li>";
			}
			htmlCODE += "</ul>";
			
			document.getElementById('close_word').innerHTML = htmlCODE;
			xmlHttp6 = null;
		}
	}
}

function GetXmlHttpObject()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}