// JavaScript Document
var pix=0
var t
function hideAddress()
{
	window.scrollBy(0,1);
	pix++
	if(pix<10){
    	t=setTimeout(hideAddress, 100)
	}
	else
	{
		clearTimeout(t)	
	}
}

//get xmlHTTP object
var xmlHttp

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;
}

//generate search list
function getList() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 { 
		 if (xmlHttp.responseText!="")
		 {
			 document.getElementById('cnt_list').innerHTML=xmlHttp.responseText
			 document.getElementById('index').style.top = document.getElementById('cnt_list').offsetHeight+85+'px'
			 
			 window.location.href="#1"
		 }
	 } 
	 if (xmlHttp.readyState==3)
	 {
	 	document.getElementById('cnt_list').innerHTML="<div class='listitem'>Loading ...</div>"
	 }
	 if (xmlHttp.readyState==2)
	 {
	 	document.getElementById('cnt_list').innerHTML="<div class='listitem'>Loading ...</div>"
	 }
	 if (xmlHttp.readyState==1)
	 {
	 	document.getElementById('cnt_list').innerHTML="<div class='listitem'>Loading ...</div>"
	 }
}

//search by index
function searchByIndex(str,cate)
{ 
	document.getElementById('s_txt').value=""
	document.getElementById('cnt_result').innerHTML=""
	document.getElementById('cnt_result').style.visibility='hidden'
	document.getElementById('cnt_list').style.visibility='visible'
	
	switch (cate)
	{
		case "gl_molebio":
			cate="Molecular%20Biology"
			break
		case "gl_chem":
			cate="Chemistry"
			break
	}
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request")
		 return
	 }
	var url="phplib/gl_j_searchlist.php?q_str="+str+"&q_cat="+cate
	xmlHttp.onreadystatechange=getList
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

//search by string
function searchByString(str,cate)
{ 
	if(str=="")
	{
		return
	}
	
	document.getElementById('s_txt').value=""
	document.getElementById('cnt_result').innerHTML=""
	document.getElementById('cnt_result').style.visibility='hidden'
	document.getElementById('cnt_list').style.visibility='visible'
	switch (cate)
	{
		case "gl_molebio":
			cate="Molecular%20Biology"
			break
		case "gl_chem":
			cate="Chemistry"
			break
	}
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request")
		 return
	 }
	var url="phplib/gl_j_searchwordlist.php?q_str="+str+"&q_cat="+cate
	xmlHttp.onreadystatechange=getList
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

//search single word
function searchOneWord(id)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request")
		 return
	 }
	var url="phplib/gl_j_searchword.php?id="+id
	xmlHttp.onreadystatechange=getWordDescr
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

//show search single word result
function getWordDescr() 
{ 
	document.getElementById('cnt_result').style.visibility='visible'
	document.getElementById('cnt_list').style.visibility='hidden'
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 { 
		 if (xmlHttp.responseText!="")
		 {
			 var arr=xmlHttp.responseText.split("|")
			 var strtmp=""
			 strtmp=strtmp+"<h4 class='result_txt'>"+arr[0]+"</h4>"
			 strtmp=strtmp+"<p class='result_txt'>"+arr[1]+"</p>"
			 //ads links
			 strtmp=strtmp+"<div class='ads'>See also:&nbsp;&nbsp;&nbsp;&nbsp;"
			 strtmp=strtmp+"<a href='http://www.google.com/cse?cx=partner-pub-5042102399833742%3Af5dcn3-8x3c&ie=ISO-8859-1&q=biology+dictionary&sa=Search' target='_blank' class='ads-link'>Biological dictionary</a>&nbsp;&nbsp;&nbsp;&nbsp;"
			 strtmp=strtmp+"<a href='http://www.google.com/cse?cx=partner-pub-5042102399833742%3Af5dcn3-8x3c&ie=ISO-8859-1&q=gene+chip+diagnosis&sa=Search' target='_blank' class='ads-link'>Gene chip</a>&nbsp;&nbsp;&nbsp;&nbsp;"			
			 strtmp=strtmp+"</div>"
			 //go back
			 strtmp=strtmp+"<p align='center'><a href='javascript:backToList()'>Back</a></p>"
			 if(arr[3]!="")
			 {
			 	 strtmp=strtmp+"<div class='img_audio'><embed src='dbc/glossary/aud/"+arr[3]+".mp3' width='0' height='0' autoplay='true' loop='false' controller='false' pluginspage='http://www.apple.com/quicktime/' /></div>"
			 }
			 document.getElementById('cnt_result').innerHTML=strtmp
			 
			 document.getElementById('index').style.top = document.getElementById('cnt_result').offsetHeight+85+'px'
			 window.location.href="#1"
		 }
	 } 
	 if (xmlHttp.readyState==3)
	 {
		document.getElementById('cnt_result').innerHTML="<div class='listitem'>Loading ...</div>"
	 }
	 if (xmlHttp.readyState==2)
	 {
		document.getElementById('cnt_result').innerHTML="<div class='listitem'>Loading ...</div>"
	 }
	 if (xmlHttp.readyState==1)
	 {
		document.getElementById('cnt_result').innerHTML="<div class='listitem'>Loading ...</div>"
	 }
}

function backToList()
{
	document.getElementById('cnt_result').innerHTML=""
	document.getElementById('index').style.top = document.getElementById('cnt_list').offsetHeight+85+'px'
	document.getElementById('cnt_result').style.visibility='hidden'
	document.getElementById('cnt_list').style.visibility='visible'
}

function share()
{
	if(confirm("Would you like to share this Web App with your friends?"))
	{
		var tmp="mailto:?subject="+encodeURI("New iPhone Web App recommended from your friend!");
		tmp=tmp+"&body="+encodeURI("Bio Dictionary<br>>> <a href='http://www.biocourseware.com/iphone/biodict/'>Look at it now</a>");	
		window.location.href=tmp;
	}
}