if (typeof(QLife) == 'undefined') {
    var QLife = {};
}

Event.observe(window, 'load', function()
{
    QLife.Toppage.init();
});

QLife.Toppage = {

    // {{{ 科目検索
    ID_KAMOKU_SUBJECT : 'kamoku_sbj',
    ID_KAMOKU_PREF : 'kamoku_pref',
    ID_KAMOKU_CITY : 'kamoku_city',
    // }}}
    // {{{ 郵便番号検索
    /**
     * 郵便番号検索 外枠(div)
     */
    ID_ZIPCODE_RESULT : 'zipcode_result',
    /**
     * 住所一覧リスト(ul)
     */
    ID_ADDRESS_LIST : 'address_list',
    /**
     * エラーメッセージ: 7桁でない
     */
    ID_ZIPCODE_EMPTY : 'zipcode_empty',
    // }}}
    
    // {{{ 地図
    /**
     * Google地図
     */
    ID_GMAP : 'indexmap',
    /**
     * 地図部頂点(スクロール用)
     */
    ID_INDEXMAP_TOP : 'index_search_map_top',
    /**
     * 病院一覧表示領域 (地図連動)
     */
    ID_INDEXMAP_HOSPITALS : 'indexmap_hospital_list',
    /**
     * 病院検索タイトル
     */
    ID_INDEXMAP_TITLE : 'indexmap_title',
    /**
     * 病院検索タイトル (病院なし)
     */
    ID_INDEXMAP_TITLE0 : 'indexmap_title0',
    /**
     * 病院検索タイトル (1件以上病院あり)
     */
    ID_INDEXMAP_TITLE1 : 'indexmap_title1',
    /**
     * 地域キーワード(郵便番号の地名、または駅名)表示部
     */
    ID_INDEXMAP_AREA : 'indexmap_area',
    /**
     * 病院件数表示部
     */
    ID_INDEXMAP_COUNT_CAPTION : 'indexmap_count_caption',
    /**
     * 病院件数(hidden)
     */
    ID_INDEXMAP_HIDDEN_COUNT : 'indexmap_hidden_count',
    // }}}
    // {{{ ブラウザ履歴
    /**
     * 
     */
    PARAM_STATE : 'st',
    
    STIDENT_KAMOKU : 'kamoku',
    STIDENT_MAP : 'map',
    /**
     * 初期状態
     */
    _initState : '',
    // }}}
    /**
     * 初期zoomレベル
     */
    ZOOM : 15,
    /**
     * 現在の郵便番号に対応する住所
     */
    _currentAddress : '',
    /**
     * 現在選択中の駅名
     */
    _currentStation : '',
    /**
     * 路線・駅一覧の検索結果
     */
    _stations : null,
    // {{{ 地図
    /**
     * Google地図オブジェクト
     */
    _map : null,
    /**
    * 地図アイコン: 病院
    */
    _iconHospital : null,
    /**
     * 地図アイコン: 歯科
     */
    _iconDental : null,
    // }}}

    init : function()
    {
        try {
            $('balloonbase').className = (Prototype.Browser.IE ? 'b0_ie' : 'b0');
            // 感動口コミローテーション開始
            QLife.Kandou.init('div#kandou img', 'div#balloonbase p', function(enableIndex){
                $('balloonbase').className = 'b' + enableIndex + (Prototype.Browser.IE ? '_ie' : '');
            });
            $(this.ID_KAMOKU_PREF).selectedIndex    = 0;
            $(this.ID_KAMOKU_SUBJECT).selectedIndex = 0;
            $(this.ID_KAMOKU_CITY).selectedIndex    = 0;
            
            // 状態文字列をアドレスから取得 (Firefox以外対応)
            if (this._initState == null || this._initState.length == 0) {
                this._initState = location.href.replace(/^[^#]+#st=(.+)$/, '$1');
            }
            // 状態復帰処理
            if (this._initState != null && this._initState.length > 0) {
                // 地図の状態復帰
                this.updateMapByState(this._initState);
            }
        } catch (e) {
            this.log(e);
        }
    },
    // {{{ ブラウザ履歴
    /**
     * ブラウザ履歴管理の初期化
     */
    initHistory : function(idField, idIframe)
    {
        var initState = YAHOO.util.History.getBookmarkedState(this.PARAM_STATE); // 初期状態
        var doRestore = (initState != null && initState.length > 0); // 状態復帰を行うか(URL「#」以降に状態が保存されているか)
        // #以降に状態がない: URL自身から初期状態を取得
        if (! doRestore) {
            initState = '';
        }
        // 状態変更時の処理 (YAHOO.util.History.navigate()でコール)
        YAHOO.util.History.register(this.PARAM_STATE, initState, function(state){
            QLife.Toppage.updateMapByState(state);
        });
        // ページ表示時の復帰処理
        YAHOO.util.History.onReady(function () {
            var currentState = YAHOO.util.History.getCurrentState(QLife.Toppage.PARAM_STATE);
            if (doRestore) {
                // Update the UI of your module according to "myModuleCurrentState"
                QLife.Toppage.restore(currentState);
            }
        });
        YAHOO.util.History.initialize(idField, idIframe);
    },
    /**
     * ブラウザ履歴: 状態復帰処理
     */
    restore : function(state){
        // 初期状態を一時保存し、init()で状態復帰する
        this._initState = state;
    },
//    /**
//     * 状態文字列から科目検索フォームの状態を戻す
//     */
//    updateKamokuByState : function(state)
//    {
//        try {
//            var vals = state.split(/_/);
//            var ident = (vals.length > 0 ? decodeURIComponent(vals[0]) : null);
//            if (ident != this.STIDENT_KAMOKU) {
//                return;
//            }
//            var subject = (vals.length > 1 ? decodeURIComponent(vals[1]) : '');
//            var pref    = (vals.length > 2 ? decodeURIComponent(vals[2]) : '');
//            var city    = (vals.length > 3 ? decodeURIComponent(vals[3]) : '');
//    
//            this._updateSelect(this.ID_KAMOKU_SUBJECT, subject);
//            this._updateSelect(this.ID_KAMOKU_PREF, pref);
//            
//            this._updateKamokuCities(subject, pref, city);
//        } catch (e) {
//            this.log(e);
//        }
//    },
    /**
     * selectの選択値を変更
     */
    _updateSelect : function(idSelect, val)
    {
        // 現在の値が選択済みのとき: 終了
        var formVal = $F(idSelect);
        if (formVal == val) {
            return;
        }
        
        var select = $(idSelect);
        for (var i = 0 ; i < select.options.length ; i++) {
            var optVal = select.options[i].value;
            if (optVal == val) {
                select.options[i].selected = true;
                break;
            }
        }
    },
//    /**
//     * 科目検索のフォーム状態を記録
//     */
//    saveKamokuHistory : function(subject, pref, city)
//    {
//        try {
//            var state = this.STIDENT_KAMOKU +
//                '_' + (subject == null ? '' : encodeURIComponent(subject)) +
//                '_' + (pref    == null ? '' : encodeURIComponent(pref)) +
//                '_' + (city    == null ? '' : encodeURIComponent(city));
//
//            YAHOO.util.History.navigate(this.PARAM_STATE, state);
//        } catch (e) {
//            this.log(e);
//        }
//    },
    /**
     * 状態文字列から地図を更新
     */
    updateMapByState : function(state)
    {
        try {
            var vals = state.split(/_/);
            var ident = (vals.length > 0 ? decodeURIComponent(vals[0]) : '');
            // 状態識別子が地図でないとき: 終了
            if (ident != this.STIDENT_MAP) {
                return;
            }
            var mapLat  = (vals.length > 1 ? decodeURIComponent(vals[1]) : null);
            var mapLon  = (vals.length > 2 ? decodeURIComponent(vals[2]) : null);
            if (mapLat == null || mapLon == null) {
                return;
            }
            this._initMap(mapLat, mapLon, this.ZOOM);

            // 2: zoom
            var page    = (vals.length > 4 ? decodeURIComponent(vals[4]) : 1);
            var address = (vals.length > 5 ? decodeURIComponent(vals[5]) : '');
            var station = (vals.length > 6 ? decodeURIComponent(vals[6]) : '');
            this.updateMap(mapLat, mapLon, page, address, station);
        } catch (e) {
            this.log(e);
        }
    },
    /**
     * 
     */
    updateMapWithHistory : function(mapLat, mapLon, mapZoom, page, address, station)
    {
       try {
           // 地図を初期化
           this._initMap(mapLat, mapLon, mapZoom);
           // 中心座標の指定があるとき: 変更
           if (mapLat != null && mapLon != null) {
               this._map.setCenter(new GLatLng(mapLat, mapLon), this.ZOOM);
           } else if (this._map != null) {
               // 中心座標の指定なし: 現在の中心を取得
               var pos = this._map.getCenter();
               mapLat = pos.lat();
               mapLon = pos.lng();
           }
           // ズームレベルの指定があるとき: 変更
           if (mapZoom != null && this._map.getZoom() != mapZoom) {
               this._map.setZoom(mapZoom);
           } else if (this._map != null) {
               mapZoom = this._map.getZoom();
           }
           // 地域キーワード(駅名)を特定
           if (address == null || address.length == 0) {
               address = this._currentAddress;
           }
           if (station == null || station.length == 0) {
               station = this._currentStation;
           }
           if (address == null) {
               address = '';
           }
           if (station == null) {
               station = '';
           }
           // 状態文字列を作成
           var state = this.STIDENT_MAP +
               '_' + encodeURIComponent(mapLat) +
               '_' + encodeURIComponent(mapLon) +
               '_' + encodeURIComponent(mapZoom) +
               '_' + encodeURIComponent(page) +
               '_' + encodeURIComponent(address) +
               '_' + encodeURIComponent(station);

           YAHOO.util.History.navigate(this.PARAM_STATE, state);
       } catch (e) {
           this.log(e);
       }
    },
    // }}}
    /**
     * コンソールに出力
     */
    log : function(output)
    {
        if (typeof(console) != 'undefined' && console && console.log) {
            console.log(output);
        }
    },

    // {{{ 最近のキーワード
    /**
     * 最近のキーワードをクリックしたとき
     */
    clickKeyword : function(keyword)
    {
        if (keyword != null && keyword.length > 0) {
            this.trackEvent('recentlyword', keyword, null, null);
        }
        return true;
    },
    // }}}

    // {{{ 検索テキストボックス
    /**
     * 
     */
    textCleared : false,
    /**
     * テキストボックスを初期化
     *
     * @param string txtId テキストボックスid属性値
     */
    clearTextbox : function(txtId, defaultVal){
        if (this.textCleared) {
            return;
        }
        var txt = $(txtId);
        if (txt != null && txt.value == defaultVal) {
            txt.value = '';
            txt.setStyle({color : '#000'});
            this.textCleared = true;
        }
    },
    /**
     * キーワードで検索するとき(イベント記録)
     */
    searchByKeyword : function(idKeyword)
    {
        var keyword = $F(idKeyword);
        if (keyword != null && keyword.length > 0) {
            this.trackEvent('form_count', 'fa_search', keyword, null);
        }
    },
    // }}}
    /**
     * selectのoptionsをクリア
     */
    removeOptions : function(idSelect)
    {
        // 既存selectから先頭項目以外のoptionを除去
        var select = $(idSelect);
        for (var i = 0, maxlen = select.options.length ; i < maxlen ; i++) {
            select.options[1] = null;
        }
    },
    // {{{ 診療科目検索 (科目＋都道府県＋市区町村)
    /**
     * 科目・都道府県が変更されたとき
     */
    kamokuUpdated : function()
    {
        try {
            var subject = $F(this.ID_KAMOKU_SUBJECT);
            var pref    = $F(this.ID_KAMOKU_PREF);
            // 片方が未入力: 何もしない
            if (subject.length == 0 || pref.length == 0) {
                return;
            }
//            // 状態を保存
//            this.saveKamokuHistory(subject, pref, null);
            //
            this._updateKamokuCities(subject, pref, null);
        } catch (e) {
            this.log(e);
        }
    },
    /**
     * 市区町村プルダウンを更新
     */
    _updateKamokuCities : function(subject, pref, city)
    {
        try {
            // 片方が未入力: 何もしない
            if (subject.length == 0 || pref.length == 0) {
                return;
            }
            new Ajax.Request('2009qlife_js/top_city.php', {
                method : 'get',
                parameters : {sbj : subject, pref : pref},
                onSuccess : function(transport) {
                    // 市区町村selectを更新
                    var json = transport.responseText.evalJSON();
                    // optionsクリア
                    QLife.Toppage.removeOptions(QLife.Toppage.ID_KAMOKU_CITY);
                    // optionを追加
                    var select = $(QLife.Toppage.ID_KAMOKU_CITY);
                    for (var i = 0, maxlen = json.length ; i < maxlen ; i++) {
                        var caption = String(json[i].name + ' (' + json[i].num + ')').escapeHTML();
                        var val     = String(json[i].name).escapeHTML();
                        select.options[i + 1] = new Option(caption, val);
                        // 選択状態
                        if (json[i].name == city) {
                            select.options[i + 1].selected = true;
                        }
                    }
                }
            });
        } catch (e) {
            this.log(e);
        }
    },
//    /**
//     * 市区町村が更新されたとき: 
//     */
//    cityUpdated : function()
//    {
//        var subject = $F(this.ID_KAMOKU_SUBJECT);
//        var pref    = $F(this.ID_KAMOKU_PREF);
//        var city    = $F(this.ID_KAMOKU_CITY);
//        
//        this.saveKamokuHistory(subject, pref, city);
//    },
    /**
     * 診療科目検索: 検索キーワードを作成し、検索実行
     */
    searchByKamoku : function()
    {
        try {
            // イベント追跡
            this.trackEvent('form_count', 'medical_search', null, null);
            
            var subject = this._getSelectedText(this.ID_KAMOKU_SUBJECT);
            var pref    = this._getSelectedText(this.ID_KAMOKU_PREF);
            var city    = $F(this.ID_KAMOKU_CITY);
            // 検索キーワードを作成
            var keyword = '';
            if (subject.length > 0) {
                keyword += subject + ' ';
            }
            if (pref.length > 0) {
                keyword += pref + ' ';
            }
            if (city.length > 0) {
                keyword += city + ' ';
            }
            keyword = keyword.replace(/\s+$/, '');
            // hiddenフィールドにキーワードを出力
            $('kamoku_keyword').value = keyword;
        } catch (e) {
            this.log(e);
        }
        return true;
    },
    /**
     * selectで選択されたoptionのテキストを返す
     */
    _getSelectedText : function(idSelect)
    {
        var select = $(idSelect);
        if (select != null && select.selectedIndex && select.options) {
            var text = select.options[select.selectedIndex].text
            return text;
        } else {
            return '';
        }
        
    },
    // }}}
    // {{{ 郵便番号検索
    /**
     * 郵便番号→緯度経度取得・地図表示
     */
    searchByZipcode : function(idZip3, idZip4)
    {
        try {
            var zip3 = $F(idZip3);
            var zip4 = $F(idZip4);
            var zip7 = zip3 + zip4;
            // 郵便番号の入力桁数、入力文字が不正: エラー表示・終了
            if (zip3.length != 3 || zip4.length != 4 || zip7.match(/[^\d０-９]+/)) {
                $(this.ID_ZIPCODE_EMPTY).setStyle({display : 'block'});
                return false;
            }
            $(this.ID_ZIPCODE_EMPTY).setStyle({display : 'none'});
            // 郵便番号から緯度経度を取得
            new Ajax.Request('/index_zipcode', {
                method : 'get',
                parameters : {zip : zip7},
                onSuccess : function(transport) {
                    // 住所一覧を更新
                    $(QLife.Toppage.ID_ZIPCODE_RESULT).innerHTML = transport.responseText;
                }
            });
            // イベント
            this.trackEvent('form_count', 'zip_search', null, null);
        } catch (e) {
            this.log(e);
        }
        // submit遮断
        return false;
    },
    /**
     * 住所から地図を更新
     */
    searchByAddr : function(lat, lon, addr)
    {
        this._currentStation = '';
        this.updateMapWithHistory(lat, lon, this.ZOOM, 1, addr, '');
        this.scrollToMap();
    },
    // }}}
    // {{{ 路線・駅検索
    /**
     * 都道府県が変更された
     */
    trainPrefUpdated : function(idPref, idRail, idStation)
    {
        try {
            var pref = $F(idPref);
            // 都道府県が選択されていないとき: 終了
            if (pref.length == 0) {
                return;
            }
            // 路線、駅をクリア
            QLife.Toppage.removeOptions(idRail);
            QLife.Toppage.removeOptions(idStation);
            // 路線を要求
            new Ajax.Request('2009qlife_js/top_train.php', {
                method : 'get',
                parameters : {pref : pref},
                onSuccess : function(transport) {
                    var json = transport.responseText.evalJSON();
                    // 路線一覧を更新
                    var select = $(idRail);
                    for (var i = 0, maxlen = json.length ; i < maxlen ; i++) {
                        select.options[i + 1] = new Option(json[i].name, json[i].code);
                    }
                }
            });
        } catch (e) {
            this.log(e);
        }
    },
    /**
     * 路線が変更されたとき
     */
    trainRailUpdated : function(idRail, idStation)
    {
        try {
            var rail = $F(idRail);
            if (rail.length == 0) {
                return;
            }
            // 駅をクリア
            QLife.Toppage.removeOptions(idStation);
            // 駅一覧を要求
            new Ajax.Request('2009qlife_js/top_train.php', {
                method : 'get',
                parameters : {rail : rail},
                onSuccess : function(transport) {
                    var json = transport.responseText.evalJSON();
                    QLife.Toppage._stations = json;
                    // 駅一覧を更新
                    var select = $(idStation);
                    for (var i = 0, maxlen = json.length ; i < maxlen ; i++) {
                        // 表示内容: 駅名、病院数
                        var caption = json[i].name + (json[i].num ? ' (' + json[i].num + ')' : '');
                        select.options[i + 1] = new Option(caption, json[i].code);
                    }
                }
            });
        } catch (e) {
            this.log(e);
        }
    },
    /**
     * 駅周辺の病院検索
     */
    searchByStation : function(idPref, idRail, idStation)
    {
        try {
            var pref   = $F(idPref); // 駅
            var noPref = (pref == null || pref.length == 0); // 駅 未選択
            var rail   = $F(idRail); // 路線
            var noRail = (rail == null || rail.length == 0); // 路線 未選択
            var stCode = $F(idStation); // 駅
            var noSt   = (stCode == null || stCode.length == 0); // 駅 未選択
            //
            $('railerr3').setStyle({display : (noPref ? 'block' : 'none')});
            $('railerr2').setStyle({display : (noRail && ! noPref ? 'block' : 'none')});
            $('railerr1').setStyle({display : (noSt && ! noPref && ! noRail ? 'block' : 'none')});
            // 未選択のとき: 終了
            if (noPref || noRail || noSt) {
                return false;
            }
            
            for (var i = 0, maxlen = this._stations.length ; i < maxlen ; i++) {
                var st = this._stations[i];
                if (stCode == st.code) {
                    this._currentAddress = '';
                    this.updateMapWithHistory(st.lat, st.long, this.ZOOM, 1, '', st.name);
                    this.scrollToMap();
                    // イベント
                    this.trackEvent('form_count', 'train_search', null, null);
                    break;
                }
            }
        } catch (e) {
            this.log(e);
        }
        return false;
    },
    // }}}
    
    /**
     * 地図を初期化する
     */
    _initMap : function(mapLat, mapLon, mapZoom)
    {
        // すでに初期化済み: 終了
        if (this._map != null) {
            return;
        }
        // 地図を表示
        $(this.ID_INDEXMAP_TOP).setStyle({display : 'block'});
        this._map = new GMap2(document.getElementById(this.ID_GMAP));
        this._map.addControl(new GSmallMapControl()); // 縮尺等操作
        this._map.addControl(new GMapTypeControl()); // 地図種類切り替え
        //
        this._map.setCenter(new GLatLng(mapLat, mapLon), mapZoom);
        // イベント(ドラッグ終了)
        GEvent.addListener(this._map, 'dragend', function(){
            QLife.Toppage.updateMapWithHistory(null, null, null, 1, '', '');
        });
        // イベント(ズーム終了)
        GEvent.addListener(this._map, 'zoomend', function(oldLevel, newLevel){
            QLife.Toppage.updateMapWithHistory(null, null, null, 1, '', '');
        });

        // アイコン(病院)
        this._iconHospital = new GIcon(G_DEFAULT_ICON);
        this._iconHospital.image = '/2009qlife_images/map/map_red.png';
        this._iconHospital.iconSize = new GSize(20, 30);
        this._iconHospital.shadow = '/2009qlife_images/map/map_shadow.png';
        // アイコン(歯科)
        this._iconDental = new GIcon(G_DEFAULT_ICON);
        this._iconDental.image = '/2009qlife_images/map/map_blue.png';
        this._iconDental.iconSize = new GSize(20, 30);
        this._iconDental.shadow = '/2009qlife_images/map/map_shadow.png';
    },
    /**
     * 地図部までスクロールする
     */
    scrollToMap : function()
    {
        Element.scrollTo($(QLife.Toppage.ID_INDEXMAP_TOP));
    },
    /**
     * 地図の表示範囲が変わったとき: 病院一覧更新
     */
    updateMap : function(mapLat, mapLon, page, currentAddress, currentStation)
    {
        try {
            // 広域表示(<15)の時: 終了
            var zoom = this._map.getZoom();
            if (zoom < this.ZOOM) {
                return;
            }

            var areaKeyword = '';
            if (currentAddress != null && currentAddress.length > 0) {
                // 郵便番号検索
                this._currentAddress = currentAddress;
                areaKeyword = currentAddress;
            } else if (currentStation != null && currentStation.length > 0) {
                // 路線検索
                this._currentStation = currentStation;
                areaKeyword = currentStation;
            }
            // 地域キーワードを更新
            $(this.ID_INDEXMAP_AREA).innerHTML = String(areaKeyword).escapeHTML();
    
            var bounds = this._map.getBounds();
            var ne = bounds.getNorthEast();
            var sw = bounds.getSouthWest();
            //
            new Ajax.Request('/index_hospital', {
                method : 'get',
                parameters : {map_lat : mapLat, map_lon : mapLon,
                    addr : currentAddress, st : currentStation,
                    // TODO 要注意
                    lat1 : sw.lat(), lon1 : sw.lng(), lat2 : ne.lat(), lon2 : ne.lng(), p : page
                },
                onSuccess : function(transport) {
                    QLife.Toppage._updateMapCallback(transport);
                }
            });
        } catch (e) {
            this.log(e);
        }
    },
    /**
     * 病院一覧更新コールバック
     */
    _updateMapCallback : function(transport)
    {
        try {
            // 病院一覧を出力
            $(this.ID_INDEXMAP_HOSPITALS).innerHTML = transport.responseText;
            // 病院件数を取得
            var hospitalCount = $F(this.ID_INDEXMAP_HIDDEN_COUNT);
            var dispNoresults = 'none', dispExists = 'none';
            if (hospitalCount == 0) {
                // 病院なし
                dispNoresults = 'inline';
            } else {
                // 病院あり: 病院件数更新
                dispExists = 'inline';
                $(this.ID_INDEXMAP_COUNT_CAPTION).innerHTML = hospitalCount;
            }
            // 見出し部を表示
            $(this.ID_INDEXMAP_TITLE0).setStyle({display : dispNoresults});
            $(this.ID_INDEXMAP_TITLE1).setStyle({display : dispExists});
            $(this.ID_INDEXMAP_TITLE).setStyle({display : 'block'});
            // 病院マーカーを更新
            this._map.clearOverlays();
            var dataList = $$('input.indexmap_hospital_data');
            for (var i = 0, maxlen = dataList.length ; i < maxlen ; i++) {
                var vals = dataList[i].value.split(/\t/);
                if (vals.length < 6) {
                    continue;
                }
                var hid    = vals[0];
                var name   = vals[1];
                var addr   = vals[2];
                var lat    = vals[3];
                var lon    = vals[4];
                var dental = (vals[5] == 1);
                this._setMapMarker(dental, lat, lon, hid, name, addr);
            }
        } catch (e) {
            this.log(e);
        }
    },
    /**
    * 地図マーカーを設置
    */
    _setMapMarker : function(isDental, lat, lng, hid, name, addr)
    {
        // アイコン画像を決定
        var icon = (isDental ? this._iconDental : this._iconHospital);
        // 
        var marker = new GMarker(new GLatLng(lat, lng), {icon : icon});
        var html = 
            '<a href="http://www.qlife.jp/hospital_detail_' + hid + '_1">' +
            name + '</a><br />' + addr;
        GEvent.addListener(marker, 'click', function(){
            this.openInfoWindowHtml(html);
        });
        this._map.addOverlay(marker);
    },
    /**
     * gaイベント追跡
     */
    trackEvent : function(category, action, label, value)
    {
        try {
//            alert('category=' + category + ' action=' + action + ' label=' + label);
            if (pageTracker._trackEvent) {
                pageTracker._trackEvent(category, action, label, value);
            }
        } catch (e) {
            this.log(e);
        }
        return true;
    }
};

