<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="__MSG_chengyutitle__"
author="Wen Xue"
author_email="xuewen+chengyu@gmail.com"
author_location="Toronto, ON"
author_affiliation="zenofwen.com"
thumbnail="http://www.zenofwen.com/google/chengyu.gif"
screenshot="http://www.zenofwen.com/google/chengyuscreen.jpg"
height="200"
width="300"
description="__MSG_chengyutooldescription__"
scrolling="true">
<Locale messages="http://www.zenofwen.com/google/default.xml"/>
<Locale lang="en" messages="http://www.zenofwen.com/google/default.xml"/>
<Locale lang="zh-cn" messages="http://www.zenofwen.com/google/zh.xml"/>
<Locale lang="zh-tw" messages="http://www.zenofwen.com/google/tw.xml"/>
<Require feature="tabs" />
<Require feature="com.google.gadgets.analytics" />
</ModulePrefs>
<UserPref name="charset"

display_name="__MSG_charset__"
datatype="enum"
default_value="s">
<EnumValue value="s" display_value="__MSG_simp__"/>
<EnumValue value="t" display_value="__MSG_trad__"/>
</UserPref>
<Content type="html"><![CDATA[

<style>
   a:link              { color:black; text-decoration:underline;font-size:12px;font-weight:normal }
    a:visited           { color:black; text-decoration:underline;font-size:12px;font-weight:normal }
    a:hover             { color:black; text-decoration:underline;font-size:12px;font-weight:normal }
    a:active            { color:black; text-decoration:underline;font-size:12px;font-weight:normal }
	li            { color:black; text-decoration:underline;font-size:12px;font-weight:normal }
</style>


<div id="randomCTab" style="padding-top:5px;display:none"></div>

<div id="searchTab" style="padding-top:5px;display:none"></div>

<script>
        var ga = new _IG_GA("UA-12956282-1");
        ga.reportPageview('/google/chengyu');
	var prefs = new _IG_Prefs();
	var charset = prefs.getString("charset");

	var searchResult = "";
	var searchForm = "<form onsubmit=\"return search()\"><input type=\"text\" id=\"query\" name=\"query\"/><select id=\"type\"><option value=\"c\">__MSG_chengyuidiom__</option><option value=\"d\">__MSG_chengyudescription__</option><option value=\"b\">__MSG_chengyuboth__</option></select><input type=\"submit\" value=\"__MSG_chengyusubmit__\"/></form>";

	var dest = "";

	function process(responseText) {
		if (responseText == null) return;
			_gel(dest).innerHTML = responseText;
			if(dest!="randomCTab")
			{
				tabs.setSelectedTab(tabs.getTabs().length - 1);
			}
	}
	function processSearchResult(responseText) {
		if (responseText == null) return;
		
		else if (responseText == "000")
		{
			searchResult = "__MSG_chengyunothingfound__";
                        
                        ga.reportEvent("Chengyu Gadget", "Search", "Empty");
		}
		else
		{
			searchResult = responseText;
  
                        ga.reportEvent("Chengyu Gadget", "Search", "Fruitful");
		}
		showSearchTab("");
	}
	function openChengYu(cid, cname)
	{
		var tid = tabs.addTab(cname); 
		dest = tid;
		_gel(tid).style.paddingTop = "5px";
		_IG_FetchContent('http://www.zenofwen.com/google/chengyu.php?id='+cid+'&style='+ charset + '&uid=' + Math.random(), process);              
                ga.reportEvent("Chengyu Gadget", "Target View", charset);
	}

	function getChengYu(id)
	{
		if(_gel("randomCTab").innerHTML != "")
			return;
		_IG_FetchContent('http://www.zenofwen.com/google/chengyu.php?style='+ charset + '&uid=' + Math.random(), process);
	}
	function search()
	{
		_IG_FetchContent('http://www.zenofwen.com/google/chengyusearch.php?style='+ charset + '&type=' + _gel("type").value + '&query=' + _esc(_gel("query").value) + '&uid=' + Math.random(), processSearchResult);		
                return false;
	}
	function getRandomChengYu(id)
	{
		if(_gel("randomCTab").innerHTML != "")
			return;
		dest = "randomCTab";
		_IG_FetchContent('http://www.zenofwen.com/google/chengyu.php?style='+ charset + '&uid=' + Math.random(), process);
                ga.reportEvent("Chengyu Gadget", "Random View", charset);
	}
	function showSearchTab(id)
	{
		_gel("searchTab").innerHTML = searchForm + "<div>" + searchResult + "</div>";
  
	}
</script>
<script>
var tabs = new _IG_Tabs(__MODULE_ID__);
tabs.alignTabs("left", 5);
tabs.addTab("__MSG_chengyurandom__", {
contentContainer: _gel("randomCTab"),
callback: getRandomChengYu,
tooltip: ""

});
tabs.addTab("__MSG_chengyusearch__", {
contentContainer: _gel("searchTab"),
callback: showSearchTab,
tooltip: ""

});

</script>

]]></Content>

</Module>
