function getById(id) {
	var obj = document.getElementById(id);
	return !!obj ? obj : {};
}

function initToc() {
	initStyleSwitch();

	$("#btnSubmit").click(btnSubmit);
	$("#frm3g3g1").bind("submit", btnSubmit);

	if (new RegExp("w=([^&]+)").test(location.search))
		getById("w").value = decodeURIComponent(RegExp.$1);
	// $("#w").val(decodeURIComponent(RegExp.$1));
}

function initStyleSwitch() {
	$(function() {
		// Call stylesheet init so that all stylesheet changing functions
		// will work.
		$.stylesheetInit();

		// When one of the styleswitch links is clicked then switch the
		// stylesheet to
		// the one matching the value of that links rel attribute.
		$('.styleswitch').bind('click', function(e) {
			$.stylesheetSwitch(this.getAttribute('rel'));
			styleImageSwitch(this.getAttribute('rel'))
			return false;
		});

		// show style image according to the cookie style
		styleImageSwitch(readCookie("style"));
	});
}

function styleImageSwitch(layout) {
	getById("bcol1").src = "http://www.hy123.com/images/bcol1.jpg";
	getById("bcol2").src = "http://www.hy123.com/images/bcol2.jpg";
	getById("bcol3").src = "http://www.hy123.com/images/bcol3.jpg";
	if (layout == "layout")
		getById("bcol1").src = "http://www.hy123.com/images/bcol1a.jpg";
	else if (layout == "layout2")
		getById("bcol2").src = "http://www.hy123.com/images/bcol2a.jpg";
	else if (layout == "layout3")
		getById("bcol3").src = "http://www.hy123.com/images/bcol3a.jpg";
	else
		getById("bcol1").src = "http://www.hy123.com/images/bcol1a.jpg";

	getById("w").focus();
}

function btnSubmit() {
	var uri = "http://www.hy123.com/s_hyindex.htm?type=1&site="
			+ $("input:radio[name=site]:checked").val() + "&word="
			+ encodeURI(getById('w').value);

	if ($.browser.msie) {
		$("#gt").get(0).href = uri;
		$("#gt").get(0).click();
	} else {
		window.location.href = uri;
	}

	return false;
}

function qiehuan(obj) {
	var uri = obj.href;
	var w = $("#w").val();
	if (w != "") {
		w = encodeURIComponent(w);
		if (uri.indexOf("w=") != -1)
			obj.href = uri.replace(new RegExp("w=[^&$]*"), "w=" + w);
		else
			obj.href += "?w=" + w;
	}
}

