/**
 * Google Analytics非同期コード用トラッキング
 */
if (typeof(QLife) == 'undefined') {
    var QLife = {};
}

QLife.Trc = {
    /**
     * 開発テストモードかどうか
     */
    _isTestStatus : null,
    /**
     * Google Analyticsトラッキング
     * http://code.google.com/intl/ja/apis/analytics/docs/tracking/eventTrackerGuide.html
     * 
     * @param string category   カテゴリー(必須)
     * @param string action     アクション(必須)
     * @param string optLabel   ラベル(オプション)
     * @param int    optValue   値(オプション)
     */
    track : function(category, action, optLabel, optValue)
    {
        if (this._isTestMode()) {
            // 開発テストモード: 引数を表示
            console.log(category, action, optLabel, optValue);
            alert(
                'categry: ' + category + "\n" +
                'action: ' + action + "\n" +
                'optLabel: ' + optLabel + "\n" +
                'optValue: ' + optValue
            );
        } else if (typeof(_gaq) != 'undefined' && _gaq != null) {
            // 新(非同期)コード
            _gaq.push(['_trackEvent', category, action, optLabel, optValue]);
        } else if (typeof(pageTracker) != 'undefined' && pageTracker != null) {
            // 旧コード
            pageTracker._trackEvent(category, action, optLabel, optValue);
        }
    },
    /**
     * 開発テストモード(http://qlifejp/…)の場合trueを返す
     * 
     * @return bool 開発テストモードのときtrue
     */
    _isTestMode : function()
    {
        if (this._isTestStatus != null) {
            return this._isTestStatus;
        }
        this._isTestStatus = (location.hostname == 'qlifejp');
        return this._isTestStatus;
    },
    /**
     * inputのvalue属性値をラベルの値にするトラッキング
     * 
     * @param string category      カテゴリー(必須)
     * @param string action        アクション(必須)
     * @param string inputSelector ラベルにするinputのセレクタ(必須)
     */
    trackByInput : function (category, action, inputSelector)
    {
        var keyword = null;
        if (inputSelector.length > 0) {
            //キーワード検索
            keyword = document.getElementById(inputSelector).value; 
        }
        //
        this.track(category, action, keyword, null);
    },
    /**
     * inputのvalue属性値をラベルの値にするトラッキング（診療科目検索）
     * 
     * @param string category      カテゴリー(必須)
     * @param string action        アクション(必須)
     * @param string inputSelector ラベルにするinputのセレクタ(必須)
     * @param string inputSelector2 ラベルにするinputのセレクタ2(必須)
     */
    trackByInputKamoku : function (category, action, inputSelector, inputSelector2)
    {
        var sbj = null;
        if (inputSelector.length > 0) {
            //診療科目コード
            sbj = document.getElementById(inputSelector).value; 
        }
        var pref = null;
        if (inputSelector2.length > 0) {
            //都道府県コード
            pref = document.getElementById(inputSelector2).value; 
        }
        //
        this.track(category, action, sbj, pref);
    }
};
