﻿
        $(document).ready(function() {

           // $('#fontSmall').click(function() { $('body').removeClass().addClass('fontsizesmall'); });
           // $('#fontMiddle').click(function() { $('body').removeClass().addClass('fontsizemiddle'); });
           // $('#fontBig').click(function() { $('body').removeClass().addClass('fontsizebig'); });
           // $('#fontLarge').click(function() { $('body').removeClass().addClass('fontsizelarge'); });

            $('#WeatherUnit').change(function() {
                var item = $("option:selected", this).val();
                $.ajax({
                    cache: false,
                    type: 'post',
                    url: "/HandingWeatherInfo.ashx",
                    data: 'UID=' + item,
                    success: function(name) {
                        var arrWeather = name.split(":|:");
                        $("#ctl00_weatherimg").attr("src", arrWeather[0]).attr("alt", arrWeather[1]);
                        $('#ctl00_weathertxt').text(arrWeather[2]);

                    },
                    error: function() {  }
                })
            });

            $('#WeatherUnit').change();

            $("img[id^=search]").click(function() {
                $("img[id^=search]").each(function(i) {
                    $(this).attr("src", $(this).attr("unselectsrc"));
                });
                if ($(this).attr("searchtype") != "") {
                    $(this).attr("src", $(this).attr("selectsrc"));
                    $("#searchtype").val($(this).attr("searchtype"));
                }
                return false;
            });

            $("#qwords").focus(function() {
                if ($(this).val() == "請輸入您想查詢的關鍵字")
                    $(this).val("");
            });

            $.ajax({
            	cache: false,
            	url: "/Search/SearchHotKeywords.ashx",
		    	success: function(data) {
		        	$("#HotKeywords").html(data);
		    	},
		    	error: function() {  }
		    });

		    $("#topMenuLinkAddFavoriate").click(function () {
		    	addBookmarkForBrowser("中央健康保險局", "http://www.nhi.gov.tw/");
		      	return false;
		    });

		    $("#topMenuLinkAddFavoriate1").click(function () {
		    	addBookmarkForBrowser("中央健康保險局", "http://www.nhi.gov.tw/");
		      	return false;
		    });
        });

        $(function() {
            $.stylesheetInit();

            $('#toggler').bind(
			    'click',
			    function(e) {
			        $.stylesheetToggle();
			        return false;
			    }
		    );

            $('.styleswitch').bind(
			    'click',
			    function(e) {
			        $.stylesheetSwitch(this.getAttribute('rel'));
			        return false;
			    }
		    );


            $("img[id^=fontsize]").click(function() {
				return $.SetFontSize($(this).attr("id"));
            });

            $("a[id^=fontsize]").click(function () {
                return $.SetFontSize($(this).attr("id"));
            });

            $.FontSizeInit();
        });
        
        
        function addBookmarkForBrowser(sTitle, sUrl) {
            if (window.sidebar && window.sidebar.addPanel) {
                window.sidebar.addPanel(sTitle, sUrl, "");
            } else if (window.external) {
                window.external.AddFavorite(sUrl, sTitle);
            } else {
                alert("您的瀏覽器不支援此功能!");
            }
        }

        $(function () {
            $("#qwords").autocomplete("../AutoComplete.ashx",
            {
                delay: 5,
                width: 200,
                minChars: 1, //至少輸入幾個字元才開始給提示?
                matchSubset: false,
                matchContains: false,
                cacheLength: 0,
                noCache: false, //每次都重新連後端查詢(適用總資料筆數很多時)
                onItemSelect: findValue,
                onFindValue: findValue,
                formatItem: function (row) {        //若有ashx傳來多個值，可用row[0]、row[1]來抓取
                    return "<div style='height:12px'><div style='float:left'>" + row[0] + "</div></div>";
                },
                autoFill: false,
                mustMatch: false //是否允許輸入提示清單上沒有的值?
            });
            function findValue(li) {
                if (li == null) return alert("無符合搜尋項目!");
                $("#qwords").val(li.extra[0]);
            }
        });


