﻿

        function JumpToOtherPage(Path, IsOpen) {

            if (IsOpen == '0') {
                if (Path != '' && Path != null) location.href = Path; //導向指定網址
            }
            else {

                if (Path != '' && Path != null) {
                    if (Path.indexOf('/') == 0) {
                    }
                    else {
                        if (Path.toUpperCase().ReplaceAll(' ', '').indexOf('HTTP://') != 0) {
                            Path = 'http://' + Path;
                        }
                    }

                    window.open(Path); // 開啟新視窗
                }
            }
        }
        
        
        function AddHit(Id, Path, IsOpen) {
            if(Path != null && Path != '' 
                && Path.toUpperCase().ReplaceAll(' ', '').indexOf('HTTP://') != 0){
                Path = 'http://' + Path;
            }
            
            $.post(
                '/Default/AddHit/?a=' + encodeURI(new Date())
                , { Id : Id}
                , function(data) {
                  if(Path != '' 
                    && Path != null
                    && IsOpen == '1'
                    && Path.toUpperCase() != 'HTTP://'    
                        ) window.open(Path); // 開啟新視窗
                        
                   else if(Path != '' && Path != null) location.href = Path; //導向指定網址
            });
        }

        function initLoader() {
            var script = document.createElement("script");
            //script.src = "http://maps.google.com/maps?file=api&v=2&key=" + googleKey + "&callback=loadMaps";
            script.src = "http://www.google.com/jsapi?zh-TW=tw&key=" + googleKey + "&callback=loadMaps";
            script.type = "text/javascript";
            document.getElementsByTagName("head")[0].appendChild(script);
            
            
        }
            var geocoder = null;
            var map;
            var google = null;
            var googleMapAddress = null;
            function loadMaps() {
                google.load("maps", "2", { "callback": mapsLoaded });
                //google.load("search", "1", { "callback": searchLoaded });
        }

        function mapsLoaded() {
            map = new GMap2(document.getElementById("map"));
            //map.setMapType(G_SATELLITE_MAP) //空照圖
            map.addControl(new GMapTypeControl());
            map.addControl(new GSmallMapControl);
            geocoder = new GClientGeocoder();
            googleMapAddress = googleMapAddress.ReplaceAll('1段', '一段');
            googleMapAddress = googleMapAddress.ReplaceAll('2段', '二段');
            googleMapAddress = googleMapAddress.ReplaceAll('3段', '三段');
            googleMapAddress = googleMapAddress.ReplaceAll('4段', '四段');
            googleMapAddress = googleMapAddress.ReplaceAll('5段', '五段');
            googleMapAddress = googleMapAddress.ReplaceAll('6段', '六段');
            googleMapAddress = googleMapAddress.ReplaceAll('7段', '七段');
            googleMapAddress = googleMapAddress.ReplaceAll('8段', '八段');
            googleMapAddress = googleMapAddress.ReplaceAll('9段', '九段');
            
            // 取代刮號內容
            var regex = /\(\W+\)/gi;
            
            geocoder.getLocations("台灣" + googleMapAddress.replace(regex, ''), setAddress);

        }

        String.prototype.ReplaceAll = function(AFindText, ARepText) {
            raRegExp = new RegExp(AFindText, "g");
            return this.replace(raRegExp, ARepText)
        } 
  
        function setAddress(response) {
            map.clearOverlays();
            if (!response || response.Status.code != 200) {
                alert("無效的地址");
            } else {
                place = response.Placemark[0];
                point = new GLatLng(place.Point.coordinates[1],
                                place.Point.coordinates[0]);
                map.setCenter(point, 16);
                marker = new GMarker(point);
                map.addOverlay(marker);
                marker.openInfoWindowHtml(googleMapAddress);
                
            }
        }
        
        // addAddressToMap() is called when the geocoder returns an
        // answer.  It adds a marker to the map with an open info window
        // showing the nicely formatted version of the address and the country code.
        function addAddressToMap(response) {
            map.clearOverlays();
            if (!response || response.Status.code != 200) {
                alert("無效的地址");
            } else {
                place = response.Placemark[0];
                point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
                marker = new GMarker(point);
                map.addOverlay(marker);
                marker.openInfoWindowHtml(place.address);
            }
        }

        // showLocation() is called when you click on the Search button
        // in the form.  It geocodes the address entered into the form
        // and adds a marker to the map at that location.
        function showLocation(address) {
            googleMapAddress = address;
            
            //if (google == null) {
                initLoader();
            //} else {
            //    geocoder.getLocations(address, setAddress);
            //}
        }        
  
    <!--
        function MM_swapImgRestore() { //v3.0
            var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
        }
        function MM_preloadImages() { //v3.0
            var d = document; if (d.images) {
                if (!d.MM_p) d.MM_p = new Array();
                var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
                    if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
            }
        }

        function MM_findObj(n, d) { //v4.01
            var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
                d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
            }
            if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
            for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
            if (!x && d.getElementById) x = d.getElementById(n); return x;
        }

        function MM_swapImage() { //v3.0
            var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
                if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
        }
        function MM_showHideLayers() { //v9.0
            var i, p, v, obj, args = MM_showHideLayers.arguments;
            for (i = 0; i < (args.length - 2); i += 3)
                with (document) if (getElementById && ((obj = getElementById(args[i])) != null)) {
                v = args[i + 2];
                if (obj.style) { obj = obj.style; v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v; }
                obj.visibility = v;
            }
        }
    //-->

        $(document).ready(function() {

            //帳號、密碼 清空 //Joyce_Add(2010/04/01)
            $('#username').val(''); //帳號
            $('#password').val(''); //密碼


            $('#aJobFastSearch', '#fast_search').click(function() {
                var jsonString = getJsonstringFastSearch('#fast_search');
                $('input[id^="hid_SearchCondition_ascxPaging"]').each(function() {
                    $(this).val(jsonString);
                });

                if ($('#hidCurrentJobDisplayMode').val() == '1') {     //圖片模式.
                    $('#frmDefaultMaster')[0].action = "/job/SearchAdvanceResult";
                }
                else {                                           //文字模式
                    $('#frmDefaultMaster')[0].action = "/job/SearchAdvanceResultText";
                }
                $('#frmDefaultMaster')[0].method = 'post';
                $('#frmDefaultMaster').submit();
            });


        });                                      //$(document).ready()結尾.

        //TextArea欄位字數限制
        function wordRestrict(el, id, maxWords) {
            var temp = $(el)[0].value.length;
            
            if (temp > maxWords) {
                alert("超過字數限制");
                $(el)[0].scrollTop = $(el)[0].scrollHeight;
                $(el).val($(el)[0].value.substring(0, maxWords));
            }
        }

   
