// ajax not implemented yet

function render()
{
	if(document.getElementById('q_id'))
	{
		document.getElementById('q_id').focus();
		document.getElementById('qform').onsubmit = function() {
			loadWait("Wait...");
		}
	}

	var links = document.getElementsByTagName("a");
	for(var i = 0; i < links.length; i++)
	{
		if(links[i].parentNode.id != "again") links[i].onclick = function() {window.open(this.href); return false;}
		if(links[i].parentNode.id == "reload") links[i].onclick = function() {
			alert("喔，那我找找看喔... (翻找翻找)");
			window.location = window.location;
			return false;
		}
		if(links[i].parentNode.id == "readme")
		{
			links[i].onmouseover = function() {setDisp("rtext", 'inline');}
			links[i].onmouseout = function() {setDisp("rtext", 'none');}
		}
	}

	if(document.getElementById('s_sub'))
	{
		var wretchid = document.getElementById('wretchid').innerHTML;
		document.title = wretchid + " 的" + document.title;
		var str = document.getElementById('s_kw').value;
		getSound(str);
		document.getElementById('s_sub').onclick = function() {
			var rand = Math.floor(Math.random()*4)+1;
/*			switch(rand)
			{
			case 1: getSound(str); break;
			case 2: alert("喵~"); break;
			case 3: window.open("http://www.google.com.tw/search?q=%E7%84%A1%E5%90%8D%20" + encodeURI(str)); break;
			case 4: window.location = window.location; break;
			}
*/			alert("喵~");
			return false;
		}
	}
}

function setDisp(id, value)
{
	if(document.getElementById(id)) document.getElementById(id).style.display = value;
}

function setText(element, text)
{
	element.innerHTML = text;
}

function loadWait(text)
{
	var element = document.getElementById("stat");
	setText(element, text);
	setDisp("qform", 'none');
	setDisp("stat", 'block');
}

function getSound(text)
{
//	var spath = "http://cornguo.atcity.org/espeak/?s=" + encodeURI(text);
	var spath = "http://cornguo.atcity.org/test/04/tai.php?t=" + encodeURI(text);
	document.getElementById('sound').innerHTML = "<embed src=\"" + spath + "\" type=\"application/x-mplayer2\" height=\"48\"></embed>";
}
