

$(document).ready(function () {
	$("#topLogo").css("cursor","pointer");
	$("#topLogo").click(function () {
		location.href = "/";
	});
	$("#topmenuButton li#btn2").hover(
			function () { $("#topmenuSub").fadeIn("fast"); },
			function () { }
	);
	$("#topmenuButton li[id!='btn2']").hover(
			function () { $("#topmenuSub").fadeOut("fast"); },
			function () { }
	);
	$("#topmenuSub").hover(
		function () { },
		function () { $(this).fadeOut("fast"); }
	);

	$("#selectLang").change(changeLangAjax);

	function changeLangAjax() {
		var allData;
		allData = {
			Lang_code: $("#selectLang").val()
		};
		$.ajax({
			type: "POST",
			url: 'do_changeLang.aspx',
			data: allData,
			error: function (xhr) { alert("error:" + xhr.responseText); },
			success: function (response) {
				//alert(response);
				//location.reload();
				if ($("#selectLang").val() == "de-DE") {
					location.href = "http://de.moshimonde.com" + location.pathname + location.search + location.hash;
				} else if ($("#selectLang").val() == "es-ES") {
					location.href = "http://es.moshimonde.com" + location.pathname + location.search + location.hash;
				} else if ($("#selectLang").val() == "fr-FR") {
					location.href = "http://fr.moshimonde.com" + location.pathname + location.search + location.hash;
				} else if ($("#selectLang").val() == "jp-JP") {
					location.href = "http://jp.moshimonde.com" + location.pathname + location.search + location.hash;
				} else if ($("#selectLang").val() == "zh-TW") {
					location.href = "http://tw.moshimonde.com" + location.pathname + location.search + location.hash;
				} else if ($("#selectLang").val() == "zh-CN") {
					location.href = "http://cn.moshimonde.com" + location.pathname + location.search + location.hash;
				} else {
					location.href = "http://www.moshimonde.com" + location.pathname + location.search + location.hash;
				}
			}
		});
	}

	$("#search_form").submit(function () {
		if ($("input:first").val() != "") {
			return true;
		}
		return false;
	});

	$("#dataLoadingImg").ajaxStart(function () {
		$(this).show();
	});
	$("#dataLoadingImg").ajaxStop(function () {
		$(this).hide();
	});
});

function WireAutoTab(CurrentElementID, NextElementID, FieldLength) {
	var CurrentElement = $('#' + CurrentElementID);
	var NextElement = $('#' + NextElementID);

	CurrentElement.keyup(function (e) {
		var KeyID = (window.event) ? event.keyCode : e.keyCode;

		if (CurrentElement.val().length >= FieldLength
            && ((KeyID >= 48 && KeyID <= 90) ||
            (KeyID >= 96 && KeyID <= 105)))
			NextElement.focus();
	});
}
