/*==============================================================================
 *
 * パッケージ名  :
 * ファイル名    :judgeUA.js
 * 名称          :UserAgent判定Javascript
 * 概要          :クライアントのUserAgentを判定します。
 * 作成日・作成者:2008/12/06 jf
 * 変更履歴      :
 *
 * Copyright(c)2008 ChaseSystems Co.,Ltd.
 =============================================================================*/
function judgeUA(){

    /** 
     * 変数
     */
    // UserAgent定義用変数宣言
    var ua;

    // navigatorオブジェクトのuserAgentプロパティの全文字列を小文字化
    // ※後の処理記述を楽にする為の準備
    var agt = navigator.userAgent.toLowerCase();

    // UserAgentのメジャーバージョンとマイナーバージョンの取得
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);



    // UserAgentがNETSCAPE
    this.nav = ((agt.indexOf("mozilla") != -1) && (agt.indexOf("spoofer") == -1) &&
                (agt.indexOf("compatible") == -1) && (agt.indexOf("opera") == -1) &&
                (agt.indexOf("webtv") == -1) && (agt.indexOf("hotjava") == -1));

    // NETSCAPEバージョン取得
    this.nav2    = (this.nav && (this.major == 2));
    this.nav3    = (this.nav && (this.major == 3));
    this.nav4    = (this.nav && (this.major == 4));
    this.nav4up  = (this.nav && (this.major >= 4));
    this.navonly = (this.nav && ((agt.indexOf(";nav") != -1) ||
                   (agt.indexOf("; nav") != -1)) );
    this.nav6    = (this.nav && (this.major == 5));
    this.nav6up  = (this.nav && (this.major >= 5));
    this.gecko   = (agt.indexOf('gecko') != -1);



    // UserAgentがINTERNET EXPLORER
    this.ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

    // INTERNET EXPLORERバージョン取得
    this.ie3     = (this.ie && (this.major < 4));
    this.ie4     = (this.ie && (this.major == 4) && (agt.indexOf("msie 4") != -1));
    this.ie4up   = (this.ie && (this.major >= 4));
    this.ie5     = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0") != -1));
    this.ie5_5   = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.5") != -1));
    this.ie5up   = (this.ie && !this.ie3 && !this.ie4);
    this.ie5_5up = (this.ie && !this.ie3 && !this.ie4 && !this.ie5);
    this.ie6     = (this.ie && (this.major == 4) && (agt.indexOf("msie 6.") != -1));
    this.ie6up   = (this.ie && !this.ie3 && !this.ie4 && !this.ie5 && !this.ie5_5);
    this.ie7     = (this.ie && (this.major == 4) && (agt.indexOf("msie 7.") != -1));
    this.ie7up   = (this.ie && !this.ie3 && !this.ie4 && !this.ie5 && !this.ie5_5 &&
                               !this.ie6);



    // UserAgentがOPERA
    this.opera = (agt.indexOf("opera") != -1);

    // OPERAバージョン取得
    this.opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    this.opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    this.opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    this.opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    this.opera5up = (this.opera && !this.opera2 && !this.opera3 && !this.opera4);
    this.opera6 = (agt.indexOf("opera 6") != -1 || agt.indexOf("opera/6") != -1);
    this.opera7 = (agt.indexOf("opera 7") != -1 || agt.indexOf("opera/7") != -1);
    this.opera8 = (agt.indexOf("opera 8") != -1 || agt.indexOf("opera/8") != -1);
    this.opera9 = (agt.indexOf("opera 9") != -1 || agt.indexOf("opera/9") != -1);
    this.opera9up = (this.opera && !this.opera2 && !this.opera3 && !this.opera4 &&
                     this.opera5 && !this.opera6 && !this.opera8 && !this.opera8);



    // UserAgentがAOL
    this.aol   = (agt.indexOf("aol") != -1);

    // AOLバージョン取得
    this.aol3  = (this.aol && this.ie3);
    this.aol4  = (this.aol && this.ie4);
    this.aol5  = (agt.indexOf("aol 5") != -1);
    this.aol6  = (agt.indexOf("aol 6") != -1);



    // UserAgentがWEBTV
    this.webtv = (agt.indexOf("webtv") != -1);

    // UserAgentがTVNavigator
    this.TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 

    // UserAgentがAOLTV
    this.AOLTV = this.TVNavigator;



    // UserAgentがhotjava
    this.hotjava = (agt.indexOf("hotjava") != -1);

    // hotjavaバージョン取得
    this.hotjava3 = (this.hotjava && (this.major == 3));
    this.hotjava3up = (this.hotjava && (this.major >= 3));



    /** 
     * UserAgent定義
     */
    // NETSCAPE
    if(this.nav && this.nav6up){
        ua = "NS6";   
    }
    else if(this.nav && !this.nav6up){
        ua = "NS6";  
    }

    // INTERNET EXPLORER
    else if(this.ie && this.ie7up){
        ua = "MSIE7";   
    }
    else if(this.ie && !this.ie7up){
        ua = "MSIE6";
    }

    // OPERA
    else if(this.opera && this.opera5up){
        ua = "NS6";
    }
    
    // その他のUserAgent
    else{
        ua = "ETC";
    }

    // 定義したUserAgent名を返却します。
    return ua;
}
