﻿
        var map;
        var aryoldMarker=[];
        function initPage() {
              if (GBrowserIsCompatible()) {
                    map = new GMap2(document.getElementById("divMap"));
                    map.setCenter(new GLatLng(25.048368,121.515827), 16); //預設台北車頭
                    map.addControl(new GLargeMapControl()); 
              }
              activeSearch='H'; 
        }    
    
         
         function onSucceeded(returnObject, userContext, methodName){
                $get('divBlockBackGround').style.display='none';
                $get('divPopUpMsg').style.display='none';
                if ((methodName=='gMap_House')||(methodName=='gMap_Land')||(methodName=='gMap_Car')){
                     if (returnObject==''){
                        reSearch();
                        var typeName='';
                        if (activeSearch=='H'){typeName='房屋';}if (activeSearch=='L'){typeName='土地';}if (activeSearch=='C'){typeName='車位';}
                        alert('在目前地圖可視範圍內，沒有任何' + typeName + '訊息，請重新調整搜查範圍');
                    }else{
//                        $get('divMap').style.height=860+'px';
                        $get('divMap').style.width=55+'%';
                        $get('divMapResult').style.width=44+'%';
                        $get('divMapResult').innerHTML=returnObject;
                        $get('btnReSearch').style.display='';
                        $get('divFilter').style.display='none';
                        var gLatLng;
                        gLatLng=map.getCenter();
                        var newLat, newLng;
                        newLat=gLatLng.lat();
                        newLng=gLatLng.lng();
                        map.setCenter(new GLatLng(newLat, newLng)); 
                    }
                }
         }
         
         
         function showCaseLocation(strLat, strLng, strHLCID){
            clearOldMarker();
            aryoldMarker[0] = createNewMarker(strLat, strLng, strHLCID);
            map.setCenter(new GLatLng(strLat, strLng));
            map.addOverlay(aryoldMarker[0]);
         }
         
        function clearOldMarker() {
	        if(aryoldMarker!=null) {
		        for(i=0;i<aryoldMarker.length ;i++) {
			        if(aryoldMarker[i]!=null) map.removeOverlay(aryoldMarker[i]);
		        }
	        }
        }
        
                
        function createNewMarker(lat, lng, HLCID){
	        var marker = null;
	        var point = null;
	        point = new GLatLng(parseFloat(lat),parseFloat(lng));
	        marker = new GMarker(point);
	        GEvent.addListener(marker, "click", function() {
	            showHLCDetailSub(HLCID);
	        });	        
	        return marker;                
        }
         
        var intPageIndex=0;
        var x1='';
        var x2='';
        var y1='';
        var y2='';
        function startSearch(blnFourCornerChange){
                if (map.getZoom()<=14){alert('您目前所調整的地圖比例太低，請先放大地圖比例後，再重新搜尋。'); return false;}
                $get('divPopUpMsg').style.display='block';
                setPopUpPosition('divPopUpMsg');
                SetBGDIVWH();
	            var bounds = map.getBounds();	
	            var southWest = bounds.getSouthWest();
	            var northEast = bounds.getNorthEast();
	            if (blnFourCornerChange==true){
	                x1 = southWest.lng();//南西lng;
	                x2 = northEast.lng();//北東lng;
	                y1 = southWest.lat();//南西lat;
	                y2 = northEast.lat();//北東lat;
	            }
	            if (activeSearch=='H'){
                    var strPriceStart=$get('ddlPriceS_House').value;
                    var strPriceBetween=$get('ddlPriceBetween_House').value;
                    var strPriceEnd=$get('ddlPriceE_House').value;
                    var strHouseType=$get('ddlHouseType_House').value;
                    var strHouseCarPark=$get('ddlCar_House').value;
                    var strPinSuStart=$get('ddlPinSuS_House').value;
                    var strPinSuBetween=$get('ddlPinSuBetween_House').value;
                    var strPinSuEnd=$get('ddlPinSuE_House').value;
                    var strForSale=$get('ddlSaleRent_House').value;
                    var strIsAgency=$get('ddlIsAgency_House').value;
                    var strIsCourt=$get('ddlIsCourt_House').value;
                    var strPicOnly=($get('chkPicOnly').checked==true)?'1':'0';
	                wsMapSearch.gMap_House(y2, x2, y1, x1, strPriceStart, strPriceBetween, strPriceEnd, strHouseType, strHouseCarPark, strPinSuStart, strPinSuBetween, strPinSuEnd, strForSale, strIsAgency, strIsCourt, intPageIndex, strPicOnly, onSucceeded, WSFailed);
	            }
	            if (activeSearch=='L'){
                    var strPriceStart=$get('ddlPriceS_Land').value;
                    var strPriceBetween=$get('ddlPriceBetween_Land').value;
                    var strPriceEnd=$get('ddlPriceE_Land').value;
                    var strLandType=$get('ddlLandType_Land').value;
                    var strPinSuStart=$get('ddlPinSuS_Land').value;
                    var strPinSuBetween=$get('ddlPinSuBetween_Land').value;
                    var strPinSuEnd=$get('ddlPinSuE_Land').value;
                    var strForSale=$get('ddlSaleRent_Land').value;
                    var strIsAgency=$get('ddlIsAgency_Land').value;
                    var strIsCourt=$get('ddlIsCourt_Land').value;
                    var strPicOnly=($get('chkPicOnly').checked==true)?'1':'0';
	                wsMapSearch.gMap_Land(y2, x2, y1, x1, strPriceStart, strPriceBetween, strPriceEnd, strLandType, strPinSuStart, strPinSuBetween, strPinSuEnd, strForSale, strIsAgency, strIsCourt, intPageIndex, strPicOnly, onSucceeded, WSFailed);
	            }
	            if (activeSearch=='C'){
                    var strPriceStart=$get('ddlPriceS_Car').value;
                    var strPriceBetween=$get('ddlPriceBetween_Car').value;
                    var strPriceEnd=$get('ddlPriceE_Car').value;
                    var strCarType=$get('ddlCarType_Car').value;
                    var strForSale=$get('ddlSaleRent_Car').value;
                    var strIsAgency=$get('ddlIsAgency_Car').value;
                    var strPicOnly=($get('chkPicOnly').checked==true)?'1':'0';
	                wsMapSearch.gMap_Car(y2, x2, y1, x1, strPriceStart, strPriceBetween, strPriceEnd, strCarType, strForSale, strIsAgency, intPageIndex, strPicOnly, onSucceeded, WSFailed);
	            }  
        }
        

        
        //點小圖顯示大圖
        function showSampleImage(str){
            $get('imgSample').src=str;
        }
        
        function showHLCDetailSub(HLCID){
                $get('divBlockBackGround').style.display='block';
                $get('divPublicPopUp').style.display='block';
                if (activeSearch=='H'){
                    $get('divPublicPopUp').style.width=755+ 'px';
                    $get('divPublicPopUp').style.height=475+ 'px';
                    wsMapSearch.get_HouseMapDetail(HLCID, getHLCDetailSucceed, WSFailed);
                }
                if (activeSearch=='L'){
                    $get('divPublicPopUp').style.width=755+ 'px';
                    $get('divPublicPopUp').style.height=475+ 'px';
                    wsMapSearch.get_LandMapDetail(HLCID, getHLCDetailSucceed, WSFailed);
                }
                if (activeSearch=='C'){
                    $get('divPublicPopUp').style.width=755+ 'px';
                    $get('divPublicPopUp').style.height=475+ 'px';
                    wsMapSearch.get_CarMapDetail(HLCID, getHLCDetailSucceed, WSFailed);
                }
                setPopUpPosition('divPublicPopUp');
                SetBGDIVWH();
        }
        
         function getHLCDetailSucceed(returnObject, userContext, methodName){
            if ((methodName=='get_HouseMapDetail')||(methodName=='get_LandMapDetail')||(methodName=='get_CarMapDetail')){$get('divPublicPopUp').innerHTML=returnObject;}
         }
         
        function reSearch(){
            $get('btnReSearch').style.display='none';
            $get('divFilter').style.display='';
            $get('divMap').style.width=100+'%';
//            $get('divMap').style.height=600+'px';
            $get('divMapResult').style.width=0+'%';
            $get('divMapResult').innerHTML='';
            clearOldMarker();
        }
                
        
        function changeMapLocation(strSelectRegionID){
            var strLong='';
            var strLat='';
            for (intI=0; intI<arystrRegion.length; intI++) {
                    if (parseInt(arystrRegion[intI].strRegID)==parseInt(strSelectRegionID)){
                        strLong=arystrRegion[intI].strLong;
                        strLat=arystrRegion[intI].strLat;
                        break;
                    }
            }
            map.setCenter(new GLatLng(strLat,strLong), 16);
        }
        
         function changePage(pIndex){
                intPageIndex=pIndex;
                startSearch(false);
         }        
        
        function mapTypeChange(){
                $get('spanHouse').className='House';    
                $get('spanLand').className='Land'; 
                $get('spanCar').className='Car';
                $get('spanHouse').innerHTML = '<a href="javascript:void(0);" title="地圖找房屋" onclick="activeSearch=\'H\'; mapTypeChange();">地圖找房屋</a> ';
                $get('spanLand').innerHTML = '<a href="javascript:void(0);" title="地圖找土地"  onclick="activeSearch=\'L\'; mapTypeChange();">地圖找土地</a> ';
                $get('spanCar').innerHTML = '<a href="javascript:void(0);" title="地圖找車位"  onclick="activeSearch=\'C\'; mapTypeChange();">地圖找車位</a> ';
                    
                if (activeSearch=='H'){
                    clientSideInclude('divBasic', 'Map-House.html');
                    $get('divFull').className='search_list inHouse_bg';
                    $get('spanHouse').className='inHouse';
                    $get('spanHouse').innerHTML='地圖找房屋';
                    $get('divForHouse').style.display='block';
                    fillCityValue('ddlCity_House', '請選擇縣市'); 
                    CityRegionCascade('請選擇鄉鎮市區', 'ddlCity_House', 'ddlRegion_House');
                    fillPrice('ddlPriceS_House', 'ddlPriceBetween_House', 'ddlPriceE_House'); 
                    FromToSub('ddlPriceS_House', 'ddlPriceBetween_House', 'ddlPriceE_House');
                    fillHouseType('ddlHouseType_House', '不拘'); 
                    fillPinSu('ddlPinSuS_House', 'ddlPinSuBetween_House', 'ddlPinSuE_House'); 
                    FromToSub('ddlPinSuS_House', 'ddlPinSuBetween_House', 'ddlPinSuE_House');
                }
                if (activeSearch=='L'){
                    clientSideInclude('divBasic', 'Map-Land.html');
                    $get('divFull').className='search_list inLand_bg';
                    $get('spanLand').className='inLand';
                    $get('spanLand').innerHTML='地圖找土地';
                    $get('divForLand').style.display='block';
                    fillCityValue('ddlCity_Land', '請選擇縣市'); 
                    CityRegionCascade('請選擇鄉鎮市區', 'ddlCity_Land', 'ddlRegion_Land');
                    fillPrice('ddlPriceS_Land', 'ddlPriceBetween_Land', 'ddlPriceE_Land'); 
                    FromToSub('ddlPriceS_Land', 'ddlPriceBetween_Land', 'ddlPriceE_Land');
                    fillLandType('ddlLandType_Land', '不拘');
                    fillPinSu('ddlPinSuS_Land', 'ddlPinSuBetween_Land', 'ddlPinSuE_Land'); 
                    FromToSub('ddlPinSuS_Land', 'ddlPinSuBetween_Land', 'ddlPinSuE_Land');
                }
                if (activeSearch=='C'){
                    clientSideInclude('divBasic', 'Map-Car.html');
                    $get('divFull').className='search_list inCar_bg';
                    $get('spanCar').className='inCar';
                    $get('spanCar').innerHTML='地圖找車位';
                    $get('divForCar').style.display='block';
                    fillCityValue('ddlCity_Car', '請選擇縣市'); CityRegionCascade('請選擇鄉鎮市區', 'ddlCity_Car', 'ddlRegion_Car');
                    fillPrice('ddlPriceS_Car', 'ddlPriceBetween_Car', 'ddlPriceE_Car'); FromToSub('ddlPriceS_Car', 'ddlPriceBetween_Car', 'ddlPriceE_Car');
                    fillCarType('ddlCarType_Car');
                }
        }
        
        if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
         