﻿// 檔案目的: 處理英文版 "查詢輸入" 頁面相關動作
// 作者: Terry
//
// 相關檔案:
// ../searchInput.jsp .... 英文版 "查詢輸入" 頁面

$(document).ready(onBodyReady);

var nClickImageTitleTimes = 0; // 記錄點擊 logo 的次數

//onload
function onBodyReady()
{
	// check URL
	if (document.URL.indexOf("/IPOTechTerm") == -1)
	{
		location.replace("http://paterm.tipo.gov.tw/IPOTechTerm/");
	}

	// Message Mapping
	$("#IPCClassSelectAll").click(onClickIPCClassSelectAll);
	$("#imageTitle").click(onClickImageTitle);
	$(document.formSearchInput.IPCClass).click(onClickIPCClass);
	$(document.formSearchInput).submit(onSubmitSearchInput);
	
	$("#submitClearSearch").click(function(){
		$(document.formSearchInput.searchTerm).val("");
		document.formSearchInput.searchTerm.focus();
	});

	$("td a").css({cursor:"hand", color:"red"});

	// others
	$("#showWordMappingCount").hide();
	$("#WordMappingCount").hover(
			function(){$("#showWordMappingCount").fadeIn(300);},
			function(){$("#showWordMappingCount").fadeOut(300);}
	);

	// 設定左邊連結
	$("#showSourceLink").click(onClickShowSourceLink);
	$("#sourceLink_C1").attr({href: "http://twpat.tipo.gov.tw/"});
	$("#sourceLink_C2").attr({href: "http://www.tipo.gov.tw/ch/NodeTree.aspx?path=2787"});
	$("#sourceLink_C3").attr({href: "http://www.tipo.gov.tw/ch/AllInOne_Show.aspx?path=2792&guid=232c11ea-8a0b-4e98-aef0-f36137d56926&lang=zh-tw"});
	$("#sourceLink_C4").attr({href: "http://terms.nict.gov.tw/"});
	$("#sourceLink_C5").attr({href: "http://pesto.lib.nthu.edu.tw/k12/dictionary.asp"});
	$("#sourceLink_C6").attr({href: "http://www.ncc.gov.tw/chinese/bilingual.aspx"});
	$("#sourceLink_C7").attr({href: "http://www.terms.org.tw/phrase/query.jsp"});
	$("#sourceLink_C8").attr({href: "http://twpat.tipo.gov.tw/tipotwoc/tipotwsyn"});
	$("#sourceLink_E1").attr({href: "http://twpat1.tipo.gov.tw/twcgi/ttsweb?@0:0:1:twpat2_e@@0.374399099814386"});
	$("#sourceLink_E2").attr({href: "http://www.wipo.int/classifications/ipc/ipc8/?lang=en"});
	$("#sourceLink_E3").attr({href: "http://www.wipo.int/classifications/ipc/ipc8/?lang=en"});

	$("#showPRLink").click(onClickShowPRLink);
	$("#prLink_0").attr({href: "prStatistic.jsp"});
	$("#prLink_1").attr({href: "prSuggestion.jsp"});
	$("#prLink_2").attr({href: "prFurtherExpand.jsp"});

	$("#showTrainLink").click(onClickShowTrainLink);
	$("#trainLink_1").attr({href: "../IPOTechTermVideo/video.jsp"});
	$("#trainLink_2").attr({href: "../IPOTechTermVideo/poster.ppt"});
	//$("#trainLink_1").attr({href: "http://paterm.tipo.gov.tw/IPOTechTermVideo/video.jsp"});
	//$("#trainLink_2").attr({href: "poster.pptx"});

	// 動態改變 最新消息 的高度
	// 最多砍掉後兩條...
	if ($("#lastNewsContent").height() > 120) $("#lastNews_3").remove();
	if ($("#lastNewsContent").height() > 120) $("#lastNews_2").remove();

	// focus...
	document.formSearchInput.searchTerm.focus();
}

// 選擇 "查詢所有 IPC 類別"
function onClickIPCClassSelectAll()
{
	var clickStatus = $("#IPCClassSelectAll").attr("checked");
	$(document.formSearchInput.IPCClass).attr("checked", clickStatus);
	return;
}

// 按下左上方 logo...主要是為了可以快速進到管理頁面用的!
function onClickImageTitle()
{
	if ((++nClickImageTitleTimes) >= 3)
	{
		// 如果連點了三次以上的 logo, 就直接轉入後台登入頁
		nClickImageTitleTimes = 0;
		location.href = "management/login.jsp";
	}
}

// 選擇某個 "IPC 類別"
function onClickIPCClass()
{
	$("#IPCClassSelectAll").attr("checked", false);
	return;
}

// 按下查詢的時候要先做的事...
function onSubmitSearchInput()
{
	// check search term
	if (document.formSearchInput.searchTerm.value == "*") document.formSearchInput.searchTerm.value = "";
	if (document.formSearchInput.searchTerm.value == "") return false;

	// check IPC Class
	var selectedIPCClassString = "";
	var elemIPCClass = $(document.formSearchInput.IPCClass);
	for (var n=0; n<8; ++n)
	{
		var checkedStatus = elemIPCClass.eq(n).attr("checked");
		if (checkedStatus)
		{
			selectedIPCClassString += elemIPCClass.eq(n).val();
		}
	}

	document.formSearchInput.selectedIPCClass.value = selectedIPCClassString;
	document.formSearchInput.currentPage.value = "0";
	
	// refine action...
	//var strQEncode = encodeURI(document.formSearchInput.searchTerm.value);
	//document.formSearchInput.action = "search.jsp?q=" + strQEncode + "&c=" + selectedIPCClassString;

	return true;
}

// 按下顯示 IPC 細項
function onDisplayIPCL2(id)
{
	var strURL = "IPCDetail/showIPCDetail_" + id + ".html";
	window.open(strURL, "_blank", "top=100,left=100,width=800,height=600,scrollbars=yes");
}

// 按下顯示其他網頁連結
function onClickShowSourceLink()
{
	$("#sourceLink").slideToggle(500);
}

// 按下顯示輿情回應連結
function onClickShowPRLink()
{
	$("#prLink").slideToggle(200);
}

// 按下顯示訓練資源連結
function onClickShowTrainLink()
{
	$("#trainLink").slideToggle(200);
}


