// JavaScript Document
var pix=0
var t
function hideAddress()
{
	window.scrollBy(0,1);
	pix++
	if(pix<6){
    	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)
{ 
	document.getElementById('cnt_result').innerHTML=""
	document.getElementById('cnt_result').style.visibility='hidden'
	document.getElementById('cnt_list').style.visibility='visible'
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request")
		 return
	 }
	var url="phplib/searchlist.php?q_str="+str
	xmlHttp.onreadystatechange=getList
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

//search by string
function searchByString(str)
{ 
	document.getElementById('cnt_result').innerHTML=""
	document.getElementById('cnt_result').style.visibility='hidden'
	document.getElementById('cnt_list').style.visibility='visible'
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request")
		 return
	 }
	var url="phplib/searchwordlist.php?q_str="+str
	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/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+"<p class='result_maintitle'>"+arr[0]+"</p>"
			 strtmp=strtmp+"<p class='result_title'>Description</p>"
			 strtmp=strtmp+"<div class='result_box'>"+arr[1]+"</div>"
			 if (arr[2]!="")
			 {
			 	strtmp=strtmp+"<p class='result_title'>Differences Between HTML 4.01 and HTML 5</p>"
			 	strtmp=strtmp+"<div class='result_box'>"+arr[2]+"</div>"
			 }
			 if (arr[3]!="")
			 {
			 	strtmp=strtmp+"<p class='result_title'>Notes and Tips</p>"
			 	strtmp=strtmp+"<div class='result_box'>"+arr[3]+"</div>"
			 }
			 if (arr[4]!="")
			 {
			 	strtmp=strtmp+"<p class='result_title'>New attributes in HTML 5</p>"
			 	strtmp=strtmp+"<div class='result_box'>"+arr[4]+"</div>"
			 }
			 if (arr[5]!="")
			 {
			 	strtmp=strtmp+"<p class='result_title'>Example</p>"
			 	strtmp=strtmp+"<p class='result_subtitle'>Source</p>"
				strtmp=strtmp+"<div class='result_code_box'>"+arr[5]+"</div>"
				strtmp=strtmp+"<p class='result_subtitle'>Output</p>"
				strtmp=strtmp+"<div class='result_box'>"+arr[6]+"</div>"
			 }
			 //add ads link
			 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=HTML+guide&sa=Search' target='_blank'>HTML Guide</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=learn+javascript&sa=Search' target='_blank'>Learn Javascript</a>"
			 strtmp=strtmp+"</div>"
			 strtmp=strtmp+"<p align='center'><a href='javascript:backToList()'>Back</a></p>"
			 
			 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("HTML 5 Reference<br>>> <a href='http://www.biocourseware.com/iphone/html5/'>Look at it now</a>");	
		window.location.href=tmp;
	}
}

//trace menu actions
function menuAction(str)
{
	var obj=document.getElementById("menu")
	if (str=="new")
	{
		obj.style.backgroundPosition='0px -80px'
		searchByString(str)
	}
	else if (str=="all")
	{
		obj.style.backgroundPosition='0px -40px'
		searchByIndex(str)
	}
	else if (str=="HTML")
	{
		obj.style.backgroundPosition='0px -120px'
		searchByString(str)
	}
	else
	{
		obj.style.backgroundPosition='0px 0px'
		searchByIndex(str)
	}
}

