var info = null;
//IE用ラジオクリック時
function clickInput(label){
    if(navigator.userAgent.indexOf("MSIE") != -1){
        //forの指すidのinputタグがあるか探す
        var e = null;
        try{
            e = document.getElementById(label.htmlFor);
        }
        catch(exception){}
        if(e == null){
            //labelタグ以下のinputタグを探す
            var node;
            for(var i=0; i<label.childNodes.length; i++){
                node = label.childNodes.item(i);
                if(node.nodeName == 'INPUT'){
                    e = node;
                    break;
                }
            }
        }
        if(e != null){
    
            //inputタグにクリックされたときと同じ動作をさせる
            switch(e.type){
                case 'radio':
                    e.checked = true;
                    return false;
            }
        }
    }
}
(function($){
    $(document).ready(function() {
        info = new jNextraGMaps2.Info();
        $(".searchFreeword").submit( function(){
            var searchType = $('form.searchFreeword input:radio:checked[name="freewordCategory"]').val();
            $(".fwBtn").attr("disabled","disabled");
            switch(searchType){
                case '1':
                //住所で検索
                info.getGeoAddrByFreeword(
                    {frewd: $('#searh_text').val(), cnt: 101},
                    info.getGeoAddrByFreewordDialog
                );
                break;
    
                case '2':
                //駅名で検索
                info.getGeoEkiInfoByFreeword(
                    {s: $('#searh_text').val()},
                    info.getGeoEkiInfoByFreewordDialog
                );
                break;
            }
            
        });

        $("#img01").click( function(){
            $("#img01").attr("src", $("#img01").attr("src").replace('_o', '_c'));
            $("#img02").attr("src", $("#img02").attr("src").replace('_c', '_d'));
            if($("#searh_text").val() == '例）渋谷駅など'){
                $("#searh_text").val('例）新宿区など');
            }
        });

        $("#img02").click( function(){
            $("#img02").attr("src", $("#img02").attr("src").replace('_o', '_c'));
            $("#img01").attr("src", $("#img01").attr("src").replace('_c', '_d'));
            if($("#searh_text").val() == '例）新宿区など'){
                $("#searh_text").val('例）渋谷駅など');
            }
        });
        
        $("#searh_text").focus( function(){
            var searchType = $('form.searchFreeword input:radio:checked[name="freewordCategory"]').val();
            var self = this;
            switch(searchType){
                case'1':
                    self._defaultValue = '例）新宿区など';
                    break;
                case'2':
                    self._defaultValue = '例）渋谷駅など';
                    break;
            }
            if( self.value === self._defaultValue ) {
                self.value = '';
            }
        });        
        $("#searh_text").blur( function() {
            var self = this;
            if(self.value === '') {
                self.value = self._defaultValue;
            }
        });
    });
})(jQuery);