﻿    var server="http://www.17ball.net/sport/";
//var server="http://localhost/bbsxp/sport/";
    var oTimerId;

    function RefreshPage(){
      clearTimeout(oTimerId);
      oTimerId = setTimeout('location=location;', 25 * 60 * 1000);
    }

   function getCanvasXY(caurrentLatLng){
       var scale = Math.pow(2, Ext.getCmp("maingmap").gmap.getZoom());
      var nw = new google.maps.LatLng(
          Ext.getCmp("maingmap").gmap.getBounds().getNorthEast().lat(),
          Ext.getCmp("maingmap").gmap.getBounds().getSouthWest().lng()
      );
      var worldCoordinateNW = Ext.getCmp("maingmap").gmap.getProjection().fromLatLngToPoint(nw);
      var worldCoordinate = Ext.getCmp("maingmap").gmap.getProjection().fromLatLngToPoint(caurrentLatLng);
      var caurrentLatLngOffset = new google.maps.Point(
          Math.floor((worldCoordinate.x - worldCoordinateNW.x) * scale),
          Math.floor((worldCoordinate.y - worldCoordinateNW.y) * scale)
      );
      return caurrentLatLngOffset;
   }

    function showEnAddress(address,city,sporttype,sportzip,member,accesstime,encrypdata,username) {
      var tempaddress="";
      if(address.length>0){
           tempaddress= address + "," + city;
      }else{
           tempaddress=city;
      }
      if(tempaddress.length>40){
         Ext.Msg.alert('Msg','address too long!');
         return;
      }else if(sporttype<=0){
         Ext.Msg.alert('Msg','Error!');
         return;
      }

      RefreshPage();
      setCookie('sportType',sporttype); 
      setCookie('sportCity',city);
      setCookie('sportAddress',tempaddress); 
      saddress= tempaddress;
      tempaddress= tempaddress + ", Taiwan"
      var geocoder = new google.maps.Geocoder();
   
      if (geocoder) {
         geocoder.geocode( { 'address': tempaddress}, function(results, status) {
             if (status != google.maps.GeocoderStatus.OK) {
              Ext.Msg.alert('Msg',(tempaddress + " Not Found!"));
            } else {
              Ext.getCmp("maingmap").gmap.setCenter(results[0].geometry.location);
 
              Ext.getDom("lnglat").innerHTML=Ext.getCmp("maingmap").gmap.getCenter().lng()+"、"+Ext.getCmp("maingmap").gmap.getCenter().lat();
              setCookie('sportLng',Ext.getCmp("maingmap").gmap.getCenter().lng());   
              setCookie('sportLat',Ext.getCmp("maingmap").gmap.getCenter().lat()); 
                        showAllMarker(Ext.getCmp("maingmap").gmap.getCenter(),sporttype,2,member,accesstime,encrypdata,username); 
                   
            }
          }
        );
        Ext.getDom("address").innerHTML=saddress;
      } 
    }

    function showAddress(address,sporttype,sportzip,member,accesstime,encrypdata,username) {
      if(address.length>40){
         Ext.Msg.alert('訊息','查詢地址過長!');
         return;
      }else if(sporttype<=0 ){
         Ext.Msg.alert('訊息','錯誤!');
         return;
      }
      RefreshPage();
      setCookie('sportType',sporttype); 
      setCookie('sportZip',sportzip);
      setCookie('sportAddress',address);   
      var geocoder = new google.maps.Geocoder();
     
      if (geocoder) {
         geocoder.geocode( { 'address': address}, function(results, status) {
             if (status != google.maps.GeocoderStatus.OK) {
              Ext.Msg.alert('訊息',(address + "找不到!"));
            } else {
			
              Ext.getCmp("maingmap").gmap.setCenter(results[0].geometry.location);
 
              Ext.getDom("lnglat").innerHTML=Ext.getCmp("maingmap").gmap.getCenter().lng()+"、"+Ext.getCmp("maingmap").gmap.getCenter().lat();
              setCookie('sportLng',Ext.getCmp("maingmap").gmap.getCenter().lng());   
              setCookie('sportLat',Ext.getCmp("maingmap").gmap.getCenter().lat()); 
                        showAllMarker(Ext.getCmp("maingmap").gmap.getCenter(),sporttype,1,member,accesstime,encrypdata,username);      
            }
          });
        saddress=getSportCookie('sportAddress');
        Ext.getDom("address").innerHTML=saddress;
      } 
    }

     function afterNewMarker(gLatLng,sporttype,member,accesstime,encrypdata,username){
         if(sporttype<=0 ){
            Ext.Msg.alert('訊息','錯誤!');
            return;
         }

            if(ajaxflag ){
                   Ext.getDom("load").style.visibility='visible';

                var ds = new Ext.data.Store({
                  proxy:new Ext.data.HttpProxy({
                   url: server + 'testtest.asp?type='+sporttype+'&center=' + gLatLng.lng() +'_'+ gLatLng.lat() +'&at=' + accesstime + '_' + encrypdata
                  }),
                reader:new Ext.data.JsonReader({root:'players'},[
                  {name:'location'},
                  {name:'Name'},
                  {name:'ID'},
                  {name:'Address'},
                  {name:'intro'},
                  {name:'place'},
                  {name:'night'},
                  {name:'type'},
                  {name:'userid'}
                ])
             });
              ds.load();
         
              var markers_array=new Array();
              ds.on('load',function(ds){
                    
                         Ext.Msg.alert('訊息',"修改新增成功!");
                
                     for (var kk = 0; kk < ds.getTotalCount(); kk++) {

                           var arecord = ds.getAt(kk);
                           temArray=arecord.get('location').split(",");
                           var updatedelete=0;
                           if(username.length>0){
                             if(arecord.get('userid')==username  ){
                               updatedelete=1;
                             } 
                           }
                      var marker =createSportMarker(Ext.getCmp("maingmap").gmap,temArray[1],temArray[0],arecord.get('ID'),arecord.get('Name'),arecord.get('Address'),arecord.get('intro'),arecord.get('night'),arecord.get('type'),arecord.get('place'),1,member,updatedelete,0,arecord.get('userid'));

                    markers_array.push(marker);
               }
               mgr.clearMarkers();
               if(markers_array.length>0){
                   mgr.addMarkers(markers_array,12);
                   mgr.refresh();
               }
               Ext.getDom("load").style.visibility='hidden';
           }); 
         }
     }

    function reverseGeocoding(lat,lng,lan){
      var latlng=new google.maps.LatLng(lat,lng);
      var geocoder = new google.maps.Geocoder();

      if(lan==0){
	    geocoder.geocode({'latLng': latlng}, function(results, status) {
             if (status != google.maps.GeocoderStatus.OK) {
                 Ext.Msg.alert('Msg','Reverse Geocoding Fail');
             } else {
                 Ext.Msg.alert('Reverse Geocoding','Address:' + results[0].formatted_address + '<br>ps. Note:Reverse Geocoding is not an exact science!');             }
           }
         );
      }else{
        var markeree = new google.maps.Marker({
		   position: latlng,
           map: Ext.getCmp("maingmap").gmap});
	    geocoder.geocode({'latLng': latlng}, function(results, status) {
             if (status != google.maps.GeocoderStatus.OK) {
               if(lan==1){
                 Ext.Msg.alert('提示','反查不到地址');
               }else{
                 Ext.Msg.alert('Msg','Reverse Geocoding Fail');
               }
             } else {
                   var word='地址:<br>' + results[0].formatted_address + '<br>ps. 注意：反查地址並非完全精準!';
               if(lan==2){
                   word='Address:<br>' + results[0].formatted_address + '<br>ps. Note:Reverse Geocoding is not an exact science!';
               } 
                var infowindow = new google.maps.InfoWindow({
                     content: word
                });
                infowindow.open(Ext.getCmp("maingmap").gmap,markeree);
                google.maps.event.addListener(markeree, 'click', function() {
                     infowindow.open(Ext.getCmp("maingmap").gmap,markeree);
                });
             
              }
         });
        mgr.addMarker(markeree,6);
        mgr.refresh();
       
   }
  }
     function showAllMarker(gLatLng,sporttype,lan,member,accesstime,encrypdata,username){
         if(sporttype<=0 || lan<=0){
            Ext.Msg.alert('訊息','錯誤!');
            return;
         }
            if(ajaxflag ){
                   Ext.getDom("load").style.visibility='visible';

                var ds = new Ext.data.Store({
                  proxy:new Ext.data.HttpProxy({
                   url: server + 'testtest.asp?type='+sporttype+'&center=' + gLatLng.lng() +'_'+ gLatLng.lat() +'&at=' + accesstime + '_' + encrypdata
                  }),
                reader:new Ext.data.JsonReader({root:'players'},[
                  {name:'location'},
                  {name:'Name'},
                  {name:'ID'},
                  {name:'Address'},
                  {name:'intro'},
                  {name:'place'},
                  {name:'night'},
                  {name:'type'},
                  {name:'userid'}
                ])
             });
              ds.load();
              var markers_array=new Array();
              ds.on('load',function(ds){
                     if(lan==1){
                         Ext.Msg.alert('訊息',("總共找到 "+ds.getTotalCount()+" 個場地!"));
                     }else if(lan==2){
                         Ext.Msg.alert('Msg',(ds.getTotalCount()+" Courts Found!"));
                     }
                     for (var kk = 0; kk < ds.getTotalCount(); kk++) {

                           var arecord = ds.getAt(kk);
                           temArray=arecord.get('location').split(",");
                            var updatedelete=0;
                           if(username.length>0){
                             if(arecord.get('userid')==username  ){
                               updatedelete=1;
                             } 
                           }
                            //alert(updatedelete); 
                     var marker =createSportMarker(Ext.getCmp("maingmap").gmap,temArray[1],temArray[0],arecord.get('ID'),arecord.get('Name'),arecord.get('Address'),arecord.get('intro'),arecord.get('night'),arecord.get('type'),arecord.get('place'),lan,member,updatedelete,0,arecord.get('userid'));
                    //Ext.getCmp("maingmap").gmap.addOverlay(marker);
                    markers_array.push(marker);
               }
               mgr.clearMarkers();
               addGMarker(gLatLng.lat(),gLatLng.lng(), lan);
               if(markers_array.length>0){
                   mgr.addMarkers(markers_array,12);
                   mgr.refresh();
               }
 
               Ext.getDom("load").style.visibility='hidden';
           }); 
         }
     }

     function translation(text){ 
           google.language.translate(text, "zh-TW", "en",
                      function(result) {
                 Ext.Msg.alert('Translation',result.translation);
          });
     }

    function createSportMarker(map,lat,lng,ID,Name,Address,intro,night,type,place,lan,member,updatedelete,power,userid){ 
       var image = "http://www.17ball.net/sport/basketballcourt.png";
       if(type==1){
           image = "http://www.17ball.net/sport/basketballcourt.png";
       }else if(type==2){
           image = "http://www.17ball.net/sport/baseballcourt.png";
       }else if(type==3){
           image = "http://www.17ball.net/sport/bikecourt.png";
       }else if(type==4){
           image = "http://www.17ball.net/sport/badmintoncourt.png";
       }else if(type==5){
           image = "http://www.17ball.net/sport/hikingcourt.png";
       }
	   
              var light=(night==0)?"":"<img src=http://www.17ball.net/map/light.gif align=absmiddle />"; 
              var lightword=(night==0)?"無":"有"; 
              var placeimg="";
              var alt="";
                if(lan==1){
                                 alt=sport[type-1];
                }else if(lan==2){
                                 alt=enSport[type-1];
                              lightword=(night==0)?"No":"";             
                } 
                 if(type=="1"){
                          placeimg="<img src=ballcourt.gif align=absmiddle alt=" +alt+ " />"; 
                 }else if(type=="2"){
                          placeimg="<img src=baseballcourt.gif align=absmiddle alt=" +alt+ " />"; 
                 }else if(type=="3"){
                          placeimg="<img src=bikingcourt.gif align=absmiddle alt=" +alt+ " />"; 
                 }else if(type=="4"){
                          placeimg="<img src=badmintoncourt.gif align=absmiddle alt=" +alt+ " />"; 
                 }else if(type=="5"){
                          placeimg="<img src=hikingcourt.gif align=absmiddle alt=" +alt+ " />"; 
                 }
              var placetype="";
                 if(lan==1){
                                 placetype=getPlacetype(type,place);
                 }else if(lan==2){
                                 placetype=getEnPlacetype(type,place);
                 } 
              var city=Address.substring(0,2);
              var qword=city +" "+Name; 
              var edit="";
              var myHtml ="";
                 if(lan==1){
                       if(updatedelete==1 && member==1){
                           edit="<a href=court.asp?ID=" + ID + ">嵌入地圖</a>　<a href=mailto:ballboy@pchome.com.tw?subject=id" + ID + "_" + type + " >回報意見</a>　<a href=http://www.google.com.tw/search?ie=utf-8&oe=utf-8&hl=zh-TW&q=" + encodeURI(qword) + " target=_blank >相關網頁</a>　<a href=http://images.google.com.tw/images?imgtype=photo&q=" + encodeURI(qword) + " target=_blank >相關照片</a>　<a href=javascript:editCourt('" + ID + "') >修改場地</a>　<a href=javascript:delCourt('" + ID + "')>刪除場地</a>";
                       }else if(member==1){
                         edit="<a href=court.asp?ID=" + ID + ">嵌入地圖</a>　<a href=mailto:ballboy@pchome.com.tw?subject=id" + ID + "_" + type + " >回報意見</a>　<a href=http://www.google.com.tw/search?ie=utf-8&oe=utf-8&hl=zh-TW&q=" + encodeURI(qword) + " target=_blank >相關網頁</a>　<a href=http://images.google.com.tw/images?imgtype=photo&q=" + encodeURI(qword) + " target=_blank >相關照片</a>";
                       }else{
                          edit="<a href=# onclick=Ext.Msg.alert('訊息','請先登入會員!'); >嵌入地圖</a>　<a href=mailto:ballboy@pchome.com.tw?subject=id" + ID + "_" + type + " >回報意見</a>　<a href=http://www.google.com.tw/search?ie=utf-8&oe=utf-8&hl=zh-TW&q=" + encodeURI(qword) + " target=_blank >相關網頁</a>　<a href=http://images.google.com.tw/images?imgtype=photo&q=" + encodeURI(qword) + " target=_blank >相關照片</a>";
                       }
                      myHtml = light + placeimg + ' <font color=#c40000>' + placetype + '</font>' + Name + '<br/>'+ Address + '(夜晚'+lightword+'燈)<br/><font color=#446D8C>'+ intro +'</font><br/>' + edit;
                       
                 }else if(lan==2){
                       if(member==0){
                         edit="<a href=#  onclick=Ext.Msg.alert('Msg','Please_Login!'); >Detail</a>　<a href=mailto:ballboy@pchome.com.tw?subject=id" + ID + "_" + type + " >ErrorReport</a>　<a href=http://www.google.com.tw/search?ie=utf-8&oe=utf-8&hl=en&q=" + encodeURI(qword) + " target=_blank >Search</a>　<a href=http://images.google.com.tw/images?imgtype=photo&hl=en&q=" + encodeURI(qword) + " target=_blank >Photo</a>";
                       }else{
                         edit="<a href=court.asp?ID=" + ID + ">Detail</a>　<a href=mailto:ballboy@pchome.com.tw?subject=id" + ID + "_" + type + " >ErrorReport</a>　<a href=http://www.google.com.tw/search?ie=utf-8&oe=utf-8&hl=en&q=" + encodeURI(qword) + " target=_blank >Search</a>　<a href=http://images.google.com.tw/images?imgtype=photo&hl=en&q=" + encodeURI(qword) + " target=_blank >Photo</a>";
                       }
                   
                      myHtml = light + placeimg + ' <font color=#c40000>' + placetype + '</font>' + Name + '<br/>'+ Address +'<a href=javascript:reverseGeocoding('+lat+','+lng+',0) ><img src=question.gif align=absmiddle alt="I_can\'t_read_Chinese" /></a>' +'('+lightword+'Light)<br/><font color=#446D8C>'+ intro + '</font>' +'<a href=javascript:translation("'+intro.replace(/<br>/g,"")+'") ><img src=question.gif align=absmiddle alt="I_can\'t_read_Chinese" /></a> '+'<br/>' + edit +'<br/>';  
                 } 
              if(power==1){
                myHtml = light + placeimg + ' <font color=#c40000>' + placetype + '</font>' + Name + '<br/>'+ Address + '(夜晚'+lightword+'燈)<br/><font color=#446D8C>'+ intro +'</font><br/><a href="http://www.17ball.net/sport/" target="_blank"><img src="powerby17ball.gif" alt="power by 17ball.net"/></a>' ;
              }
	   
	   
       var myLatLng = new google.maps.LatLng(lat,lng);
	   
	   var marker;  
	   //alert(updatedelete + '' +member);
	   if(updatedelete==1 && member==1){
	     marker = new google.maps.Marker({
           position: myLatLng,
           map: map,
           title: Name		   
         });
 
		 google.maps.event.addListener(marker, 'dblclick', function() {
		       marker.setOptions({draggable:true});
               Ext.Msg.alert('訊息','可以開始移動場地至正確位置!'); 
         });
		 
		 google.maps.event.addListener(marker, 'dragend', function(MouseEvent) {
           Ext.Msg.confirm('提示', '是否為正確位置?', function(btn, text){
              if (btn == 'yes'){
                  document.location= server + 'index2.asp?id=' + ID+'&userid='+userid+'&lat='+MouseEvent.latLng.lat()+'&lng='+MouseEvent.latLng.lng()+'&type='+type;
               } 
            });
         });
	   }else{
	     marker = new google.maps.Marker({
           position: myLatLng,
           map: map,
           icon: image,
           title: Name		   
         });

	   }
	    marker.infowindow = new google.maps.InfoWindow({
                 content: myHtml
        });
		 google.maps.event.addListener(marker, 'click', function() {
               marker.infowindow.close();
			   marker.infowindow.open(map,marker);
         });
		 google.maps.event.addListener(map, 'click', function() {
               marker.infowindow.close(); 
         });

       return marker;
    }

   function addGMarker(lat,lng,lan){
       var image = "http://www.google.com/mapfiles/marker_green.png";
       var myLatLng = new google.maps.LatLng(lat,lng);
       var markeree = new google.maps.Marker({
           position: myLatLng,
           map: Ext.getCmp("maingmap").gmap,
           icon: image,
           draggable:true
       });
               var contentString="";
               if(lan==1){
                 contentString="<center>設定位置</center>";
               }else{
                 contentString="<center>Location</center>";
               }

       var infowindow = new google.maps.InfoWindow({
           content: contentString
       });

       google.maps.event.addListener(markeree, 'click', function() {
	       infowindow.close();
           infowindow.open(Ext.getCmp("maingmap").gmap,markeree);
       });
 
      mgr.addMarker(markeree,6);
      mgr.refresh();
   }

     function delCourt(id)  { 
 
           Ext.Msg.confirm('提示', '確定刪除?', function(btn, text){
              if (btn == 'yes'){
                 document.location= server + 'del.asp?id=' + id;
               } 
            });
 
      }

     function editCourt(id)  { 
             BBSXP_Modal.Open('editcourt.asp?placetype=<%=placetype%>&id='+id+'&azip='+document.frm.Zip.value,560,490);
      }

     function addCourt(lat,lng)  { 
       if (getCookie('UserName')==""){  
           Ext.Msg.confirm('提示', '我們建議您先登入會員!<br>未來可以維護您所建立的球場!<br><br>若您還不是會員!加入會員只要10秒!', function(btn, text){
              if (btn == 'yes'){
                 document.location='http://www.17ball.net/Login.asp';
               }else{
                 BBSXP_Modal.Open('addcourt.asp?placetype=<%=placetype%>&lat='+lat+'&lng='+lng+'&azip='+document.frm.Zip.value,560,490);
               }
            });
        }else{
             BBSXP_Modal.Open('addcourt.asp?placetype=<%=placetype%>&lat='+lat+'&lng='+lng+'&azip='+document.frm.Zip.value,560,490);
        }  
      }

    function logout(){
	ht = document.getElementsByTagName("html");
	ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";

           Ext.Msg.confirm('提示', '你確定要退出？', function(btn, text){
              if (btn == 'yes'){
                 UrlPost("../authLogin.asp?Menu=OUT");
               }else{
                 ht[0].style.filter = "";
		 return false;
               }
            });

    }

    function setCookie(name,value) 
    {
      var Days = 10;  
      var exp  = new Date();    
      exp.setTime(exp.getTime() + Days*24*60*60*1000);
	  var NewCookie = name + '=' + escape(value) + (';expires=' + exp.toGMTString()) +';path=/';
      document.cookie = NewCookie;
    }
  
     function getSportCookie(cookieName)  {  
 
	   var regex = new RegExp( ("(^| )" + cookieName + "=([^;]*)(;|$)") );
	   var Matchs = document.cookie.match( regex );
	   if( Matchs ) return unescape( Matchs[2] );  
	   if(cookieName=='sportLat'){
	     return "24.9772803"; 
          }else if(cookieName=='sportLng'){
	     return "121.4570447"; 
          }else if(cookieName=='sportZip'){
	     return "236"; 
          }else if(cookieName=='sportAddress'){
	     return "臺北縣土城市"; 
          }else if(cookieName=='sportType'){
	     return "1"; 
          }else if(cookieName=='sportlan'){
	     return "1"; 
          }else if(cookieName=='sportCity'){
	     return "Taipei County"; 
          }else{
             return ""; 
	  }
      }


<!--
//==================== for ensport code begin =========================
enSport = new Array("Basketball","Baseball","Cycling","Badminton","Hiking");
enSportType = new Array(5);
enSportType[0] = new Array("School BasketballCourt","Street BasketballCourt");
enSportType[1] = new Array("Formal BaseballCourt","Normal BaseballCourt");
enSportType[2] = new Array("Cycleway","BikeShop");
enSportType[3] = new Array("BadmintonCourt");
enSportType[4] = new Array("Hiking Trailhead");

function getEnPlacetype(sportType,placeType){
	if (sportType>0 && placeType>=0) {
	  return enSportType[sportType-1][placeType];
        }else{
          return "";
        }
}

function initEnSportType(sportTypeInput){
	sportTypeInput.length = enSport.length;
	for (i = 0; i < enSport.length; i++) {
		sportTypeInput.options[i].value = i+1;
		sportTypeInput.options[i].text = enSport[i];
	}
}

//==================== for sport code begin =========================
sport = new Array("籃球運動","棒球運動","自行車運動","羽球運動","登山運動");
sporttype = new Array(5);
sporttype[0] = new Array("學校籃球場","一般籃球場");
sporttype[1] = new Array("棒球正式場地","棒球練習場");
sporttype[2] = new Array("自行車道","自行車店");
sporttype[3] = new Array("羽球場");
sporttype[4] = new Array("登山口");

function getPlacetype(sportType,placeType){
	if (sportType>0 && placeType>=0) {
	  return sporttype[sportType-1][placeType];
        }else{
          return "";
        }
}

function initSportType(sportTypeInput){
	sportTypeInput.length = sport.length;
	for (i = 0; i < sport.length; i++) {
		sportTypeInput.options[i].value = i+1;
		sportTypeInput.options[i].text = sport[i];
	}
}


function initsport(countyInput, zoneInput){
	countyInput.length = sport.length;
	for (i = 0; i < sport.length; i++) {
		countyInput.options[i].value = i+1;
		countyInput.options[i].text = sport[i];
	}
	countyInput.selectedIndex = 0;
        changesporttype(countyInput, zoneInput);
}

function changesporttype(countyInput, zoneInput) {
	selectedCountyIndex = countyInput.selectedIndex;
	zoneInput.length = sporttype[selectedCountyIndex].length;
	for (i = 0; i < sporttype[selectedCountyIndex].length; i++) {
		zoneInput.options[i].value = i;
		zoneInput.options[i].text = sporttype[selectedCountyIndex][i];
	}
	zoneInput.selectedIndex = 0;	
}
 
function findsport(countyInput,value){
	countyInput.length = sport.length;
	for (i = 0; i < sport.length; i++) {
		countyInput.options[i].value = i+1;
		countyInput.options[i].text = sport[i];
            if(i==value-1){
                 countyInput.options[i].selected=true;
            } 
	}
}

function findplacetype(placeInput,sport,place){
	placeInput.length = sporttype[sport-1].length;
	for (i = 0; i < sporttype[sport-1].length; i++) {
		placeInput.options[i].value = i;
		placeInput.options[i].text = sporttype[sport-1][i];
            if(i==place){
                 placeInput.options[i].selected=true;
            } 
	}
}

function findsporttype(countyInput, zoneInput, index){
	selectedCountyIndex = countyInput.selectedIndex;
	zoneInput.length = sporttype[selectedCountyIndex].length;
	for (i = 0; i < sporttype[selectedCountyIndex].length; i++) {
		zoneInput.options[i].value = sporttype[selectedCountyIndex][i];
		zoneInput.options[i].text = sporttype[selectedCountyIndex][i];
        }
			zoneInput.selectedIndex = index;	
}
 
// -->


<!--
//==================== for en begin =========================
enCounty = new Array("Taipei City", "KeeLung City", "Taipei County", "Yilan County", "HsinChu City", 
		"HsinChu County", "TaoYuan County", "MiaoLi County", "TaiChung City", "TaiChung County", "ChangHua County",
		"NanTou County", "ChiaYi City", "ChiaYi County", "YunLin County", "TaiNan City", "TaiNan County",
		"KaoHsiung City", "KaoHsiung County", "PengHu County", "PingTung County", "TaiTung County", "HuaLien County");

function initEnCounty(countyInput){
	countyInput.length = enCounty.length;
	for (i = 0; i < enCounty.length; i++) {
		countyInput.options[i].value = enCounty[i];
		countyInput.options[i].text = enCounty[i];
	}
}
 

//==================== for zip code begin =========================

County = new Array("臺北市", "基隆市", "臺北縣", "宜蘭縣", "新竹市", 
		"新竹縣", "桃園縣", "苗栗縣", "臺中市", "臺中縣", "彰化縣",
		"南投縣", "嘉義市", "嘉義縣", "雲林縣", "臺南市", "臺南縣",
		"高雄市", "高雄縣", "澎湖縣", "屏東縣", "臺東縣", "花蓮縣");

Zone = new Array(23);
// for "臺北市"
Zone[0] = new Array("中正區","大同區","中山區","松山區","大安區",
	"萬華區","信義區","士林區","北投區","內湖區","南港區",
	"文山區");
// for "基隆市"
Zone[1] = new Array("仁愛區","信義區","中正區","中山區","安樂區",
	"暖暖區","七堵區");
// for "臺北縣"
Zone[2] = new Array("萬里鄉","金山鄉","板橋市","汐止鎮","深坑鄉","石碇鄉","瑞芳鎮",
	"平溪鄉","雙溪鄉","貢寮鄉","新店市","坪林鄉","烏來鄉","永和市","中和市","土城市",
	"三峽鎮","樹林市","鶯歌鎮","三重市","新莊市","泰山鄉","林口鄉","蘆洲市","五股鄉",
	"八里鄉","淡水鎮","三芝鄉","石門鄉");
// for "宜蘭縣"
Zone[3] = new Array("宜蘭市","頭城鎮","礁溪鄉","壯圍鄉","員山鄉","羅東鎮","三星鄉",
	"大同鄉","五結鄉","冬山鄉","蘇澳鎮","南澳鄉");
// for "新竹市"
Zone[4] = new Array("東區　","北區　","香山區");
// for "新竹縣"
Zone[5] = new Array("竹北市","湖口鄉","新豐鄉","新埔鄉","關西鎮","芎林鄉","寶山鄉",
	"竹東鎮","五峰鄉","橫山鄉","尖石鄉","北埔鄉","峨嵋鄉");
// for "桃園縣"
Zone[6] = new Array("中壢市","平鎮市","龍潭鄉","楊梅鎮","新屋鄉","觀音鄉","桃園市",
	"龜山鄉","八德市","大溪鎮","復興鄉","大園鄉","蘆竹鄉");
// for "苗栗縣"
Zone[7] = new Array("竹南鎮","頭份鎮","三灣鄉","南庄鄉","獅潭鄉","後龍鎮","通霄鎮",
	"苑裡鎮","苗栗市","造橋鄉","頭屋鄉","公館鄉","大湖鄉","泰安鄉","鉰鑼鄉","三義鄉",
	"西湖鄉","卓蘭鄉");
// for "臺中市"
Zone[8] = new Array("中區　","東區　","南區　","西區　","北區　","北屯區",
	"西屯區","南屯區");
// for "臺中縣"
Zone[9] = new Array("太平市","大里市","霧峰鄉","烏日鄉","豐原市","后里鄉","石岡鄉",
	"東勢鎮","和平鄉","新社鄉","潭子鄉","大雅鄉","神岡鄉","大肚鄉","沙鹿鎮","龍井鄉",
	"梧棲鎮","清水鎮","大甲鎮","外圃鄉","大安鄉");
// for "彰化縣"
Zone[10] = new Array("彰化市","芬園鄉","花壇鄉","秀水鄉","鹿港鎮","福興鄉","線西鄉",
	"和美鎮","伸港鄉","員林鎮","社頭鄉","永靖鄉","埔心鄉","溪湖鎮","大村鄉","埔鹽鄉",
	"田中鎮","北斗鎮","田尾鄉","埤頭鄉","溪州鄉","竹塘鄉","二林鎮","大城鄉","芳苑鄉",
	"二水鄉");
// for "南投縣"
Zone[11] = new Array("南投市","中寮鄉","草屯鎮","國姓鄉","埔里鎮","仁愛鄉","名間鄉",
	"集集鄉","水里鄉","魚池鄉","信義鄉","竹山鎮","鹿谷鄉");
// for "嘉義市"
Zone[12] = new Array("東區　","西區　");
// for "嘉義縣"
Zone[13] = new Array("番路鄉","梅山鄉","竹崎鄉","阿里山","中埔鄉","大埔鄉",
"水上鄉","鹿草鄉","太保市","朴子市","東石鄉","六腳鄉","新港鄉","民雄鄉","大林鎮","漢口鄉",
"義竹鄉","布袋鎮");
// for "雲林縣"
Zone[14] = new Array("斗南鎮","大埤鄉","虎尾鎮","土庫鎮","褒忠鄉","東勢鄉","臺西鄉",
	"崙背鄉","麥寮鄉","斗六市","林內鄉","古坑鄉","莿桐鄉","西螺鎮","二崙鄉","北港鎮",
	"水林鄉","口湖鄉","四湖鄉","元長鄉");
// for "臺南市"
Zone[15] = new Array("中區　","東區　","南區　","西區　","北區　","安平區",
	"安南區");
// for "臺南縣"
Zone[16] = new Array("永康市","歸仁鄉","新化鎮","左鎮鄉","玉井鄉","楠西鄉","南化鄉",
	"仁德鄉","關廟鄉","龍崎鄉","官田鄉","麻豆鎮","佳里鎮","西港鄉","七股鄉","將軍鄉",
	"學甲鎮","北門鄉","新營市","後壁鄉","白河鎮","東山鄉","六甲鄉","下營鄉","柳營鄉",
	"鹽水鎮","善化鎮","大內鄉","山上鄉","新市鄉","安定鄉");
// for "高雄市"
Zone[17] = new Array("新興區","前金區","苓雅區","鹽埕區","鼓山區",
	"旗津區","前鎮區","三民區","楠梓區","小港區","左營區");
// for "高雄縣"
Zone[18] = new Array("仁武鄉","大社鄉","岡山鎮","路竹鄉","阿蓮鄉","田寮鄉","燕巢鄉",
	"橋頭鄉","梓官鄉","彌陀鄉","永安鄉","湖內鄉","鳳山市","大寮鄉","林園鄉","鳥松鄉",
	"大樹鄉","旗山鎮","美濃鎮","六龜鄉","內門鄉","杉林鄉","甲仙鄉","桃源鄉","三民鄉",
	"茂林鄉","茄萣鄉");
// for "澎湖縣"
Zone[19] = new Array("馬公市","西嶼鄉","望安鄉","七美鄉","白沙鄉","湖西鄉");
// for "屏東縣"
Zone[20] = new Array("屏東市","三地門鄉","霧臺鄉","瑪家鄉","九如鄉","里港鄉","高樹鄉",
	"鹽埔鄉","長治鄉","麟洛鄉","竹田鄉","內埔鄉","萬丹鄉","潮州鎮","泰武鄉","來義鄉",
	"萬巒鄉","嵌頂鄉","新埤鄉","南州鄉","林邊鄉","東港鎮","琉球鄉","佳冬鄉","新園鄉",
	"枋寮鄉", "枋山鄉","春日鄉","獅子鄉","車城鄉","牡丹鄉","恆春鎮","滿州鄉");
// for "臺東縣"
Zone[21] = new Array("臺東市","綠島鄉","蘭嶼鄉","延平鄉","卑南鄉","鹿野鄉","關山鎮",
	"海端鄉","池上鄉","東河鄉","成功鎮","長濱鄉","太麻里鄉","金峰鄉","大武鄉","達仁鄉");
// for "花蓮縣"
Zone[22] = new Array("花蓮市","新城鄉","秀林鄉","吉安鄉","壽豐鄉","鳳林鎮","光復鄉",
	"豐濱鄉","瑞穗鄉","萬榮鄉","玉里鎮","卓溪鄉","富里鄉");
 

ZipCode = new Array(23);
// for "臺北市"
ZipCode[0] = new Array("100","103","104","105","106","108","110","111",
	"112","114","115","116");
// for "基隆市"
ZipCode[1] = new Array("200","201","202","203","204","205","206");
// for "臺北縣"
ZipCode[2] = new Array("207","208","220","221","222","223","224","226",
	"227","228","231","232","233","234","235","236","237","238","239",
	"241","242","243","244","247","248","249","251","252","253");
// for "宜蘭縣"
ZipCode[3] = new Array("260","261","262","263","264","265","266","267",
	"268","269","270","272");
// for "新竹市"
ZipCode[4] = new Array("300","300","300");
// for "新竹縣"
ZipCode[5] = new Array("302","303","304","305","306","307","308","310",
	"311","312","313","314","315");
// for "桃園縣"
ZipCode[6] = new Array("320","324","325","326","327","328","330","333",
	"334","335","336","337","338");
// for "苗栗縣"
ZipCode[7] = new Array("350","351","352","353","354","356","357",
	"358","360","361","362","363","364","365","366","367","368","369");
// for "臺中市"
ZipCode[8] = new Array("400","401","402","403","404","406","407","408");
// for "臺中縣"
ZipCode[9] = new Array("411","412","413","414","420","421","422","423",
	"424","426","427","428","429","432","433","434","435","436","437",
	"438","439");
// for "彰化縣"
ZipCode[10] = new Array("500","502","503","504","505","506","507","508",
	"509","510","511","5112","513","514","515","516","520","521","522",
	"523","524","525","526","527","528","530");
// for "南投縣"
ZipCode[11] = new Array("540","541","542","544","545","546","551","552",
	"553","555","556","557","558");
// for "嘉義市"
ZipCode[12] = new Array("600","600");
// for "嘉義縣"
ZipCode[13] = new Array("602","603","604","605","606","607","608","611",
	"612","613","614","615","616","621","622","623","624","625");
// for "雲林縣"
ZipCode[14] = new Array("630","631","632","633","634","635","636","637",
	"638","640","643","646","647","648","649","651","652","653","654",
	"655");
// for "臺南市"
ZipCode[15] = new Array("700","701","702","703","704","708","709");
// for "臺南縣"
ZipCode[16] = new Array("710","711","712","713","714","715","716","717",
	"718","719","720","721","722","723","724","725","726","727","730",
	"731","732","733","734","735","736","737","741","742","743","744",
	"745");
// for "高雄市"
ZipCode[17] = new Array("800","801","802","803","804","805","806","807",
	"811","812","813");
// for "高雄縣"
ZipCode[18] = new Array("814","815","820","821","822","823","824","825",
	"826","827","828","829","830","831","832","833","840","842","843",
	"844","845","846","847","848","849","851","852");
// for "澎湖縣"
ZipCode[19] = new Array("880","881","882","883","884","885");
// for "屏東縣"
ZipCode[20] = new Array("900","901","902","903","904","905","906","907",
	"908","909","911","912","913","920","921","922","923","924","925",
	"926","927","928","929","931","932","940","941","942","943","944",
	"945","946","947");
// for "臺東縣"
ZipCode[21] = new Array("950","951","952","953","954","955","956","957",
	"958","959","961","962","963","964","965","966");
// for "花蓮縣"
ZipCode[22] = new Array("970","971","972","973","974","975","976","977",
	"978","979","981","982","983");

function initCounty(countyInput){
     
	countyInput.length = County.length;
	for (i = 0; i < County.length; i++) {
		countyInput.options[i].value = County[i];
		countyInput.options[i].text = County[i];
	}
	countyInput.selectedIndex = 0;
}

function initZone(countyInput, zoneInput, post){
	changeZone(countyInput, zoneInput, post);
}

function initCounty2(countyInput, countyValue){
	countyInput.length = County.length;
	for (i = 0; i < County.length; i++) {
		countyInput.options[i].value = County[i];
		countyInput.options[i].text = County[i];

		if (countyValue == County[i])
			countyInput.selectedIndex = i;
	}
}

function initZone2(countyInput, zoneInput, post, zoneValue){
	selectedCountyIndex = countyInput.selectedIndex;
	zoneInput.length = Zone[selectedCountyIndex].length;
	for (i = 0; i < Zone[selectedCountyIndex].length; i++) {
		zoneInput.options[i].value = Zone[selectedCountyIndex][i];
		zoneInput.options[i].text = Zone[selectedCountyIndex][i];
		if (zoneValue == Zone[selectedCountyIndex][i])
			zoneInput.selectedIndex = i;	
	}
	showZipCode(countyInput, zoneInput, post);
}

function changeZone(countyInput, zoneInput, post) {
	selectedCountyIndex = countyInput.selectedIndex;
	zoneInput.length = Zone[selectedCountyIndex].length;
	for (i = 0; i < Zone[selectedCountyIndex].length; i++) {
		zoneInput.options[i].value = Zone[selectedCountyIndex][i];
		zoneInput.options[i].text = Zone[selectedCountyIndex][i];
	}
	zoneInput.selectedIndex = 0;	
	showZipCode(countyInput, zoneInput, post);
}

function showZipCode(countyInput, zoneInput, post) {
	post.value = ZipCode[countyInput.selectedIndex][zoneInput.selectedIndex];
}


function findZip(postnum) {
        key="";
        for (i = 0; i < ZipCode.length; i++) {
            for (j = 0; j < ZipCode[i].length; j++) {
		if (postnum==ZipCode[i][j])  {
                     key=i+","+j;
                 }
            }
	}
	return key;
}


function findCounty(countyInput, index){
           countyInput.length = County.length;
	for (i = 0; i < County.length; i++) { 

		countyInput.options[i].value = County[i];
		countyInput.options[i].text = County[i];
	}
	countyInput.selectedIndex = index;
}

function findZone(countyInput, zoneInput, index){
	selectedCountyIndex = countyInput.selectedIndex;
	zoneInput.length = Zone[selectedCountyIndex].length;
	for (i = 0; i < Zone[selectedCountyIndex].length; i++) {
		zoneInput.options[i].value = Zone[selectedCountyIndex][i];
		zoneInput.options[i].text = Zone[selectedCountyIndex][i];
        }
			zoneInput.selectedIndex = index;	
}

// -->

