/*************************************************************************
 $Id$
 ua.js - User Agent Database

 - Add terminal name as a "Most Access Order".
 - Test new terminal at http://weathernews.jp/s/test/ua.html

 Copyright(C) 2011 Weathernews Inc. / yuh@wni.com
*************************************************************************/

var smart_platform = "", smart_hardware = "", smart_carrier = "", smart_tablet = false ;
var smart_webview = "";
function subscribe_url(callbackurl){
	if (smart_webview == "webview"){
		return 'weathernews://weathernews.jp/member';
	}
	else if (smart_webview == "browser"){
		if (callbackurl != "") {
			return 'http://weathernews.jp/s/pivot/regist.html?url=' + callbackurl;
		}
		else {
			return 'http://weathernews.jp/s/pivot/regist.html';
		}
	}
	else {
		return "";
	}
}

//String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g, ""); }
function useragent_parse(ua){
    if ((ua.indexOf("iPhone") >= 0) || (ua.indexOf("iPod") >= 0)) {
	smart_platform = "iOS";
	var hi = (ua.match(/\(.*?\)/)||[])[0];
	var t0 = hi.split(";");
	var hw = t0[0].slice(1);
	smart_hardware = hw;
	smart_tablet = false;
	smart_webview = (ua.indexOf("Safari") >= 0) ? "browser" : "webview";
    }
    else if (ua.indexOf("iPad") >= 0) {
	smart_platform = "iOS";
	var hi = (ua.match(/\(.*?\)/)||[])[0];
	var t0 = hi.split(";");
	var hw = t0[0].slice(1);
	smart_hardware = hw;
	smart_tablet = true;
	smart_webview = (ua.indexOf("Safari") >= 0) ? "browser" : "webview";
    }
    else if (ua.indexOf("Android") >= 0) {
	smart_platform = "android";
	var hi = (ua.match(/\(.*?\)/)||[])[0];
	var t0 = hi.split(";");
	var t1 = t0[4].indexOf(" Build");
	var hw = t0[4].slice(1,t1);
	smart_hardware = hw;
	smart_webview = (! window.wni) ? "browser" : "webview";	// window.wni is GPS extension module for WNI application

	switch(hw){
	// test terminal block;
	case "SGH-N034":	/* SC-03D GALAXY S II LTE */
	case "SGH-N024":	/* SC-02D Galaxy Tab 7.0 */
	case "f11apo":	/* F-07D ARROWS */
	case "f11sha":	/* F-05D ARROWS */
	    smart_carrier = "docomo";
	    smart_tablet  = false;
	    break;
	case "SC-04D":	/* GALAXY NEXUS */
	case "SC-03D":	/* GALAXY S II LTE */
	case "SC-02C":	/* GALAXY S II */
	case "SC-02B":	/* GALAXY S */
	case "N-01D":	/* MEDIAS PP */
	case "P-01D":	/* 2011-10-18 */
	case "P-02D":	/* 2011-12-25 */
	case "HT-03A":
	case "Docomo HT-03A":
	case "SonyEricssonSO-01B":
	case "SH-10B":	/* LYNX */
	case "SH-03C":	/* LYNX 3D */
	case "T-01C":	/* REGZA Phone */
	case "T-01D":	/* REGZA Phone */
	case "L-01D":	/* Optimus LTE */
	case "L-02D":	/* PRADA phone */
	case "L-04C":	/* Optimus chat */
	case "N-04C":	/* MEDIAS */
	case "N-04D":	/* MEDIAS LTE */
	case "SonyEricssonSO-01C": /* Xperia arc */
	case "SonyEricssonSO-02C": /* Xperia acro */
	case "SO-02C": /* Xperia acro */
	case "SonyEricssonSO-03C": /* Xperia ray */
	case "SonyEricssonSO-01D": /* Xperia play */
	case "SH-01D": /* AQUOS PHONE 2011-10-18 */
	case "SH-02D": /* AQUOS PHONE 2011-10-18 */
	case "SH-04D": /* Q-Pot PHONE */
	case "SH-06D": /* AQUOS PHONE 2012-03 */
	case "SH-12C": /* AQUOS PHONE */
	case "SH-13C": /* AQUOS PHONE f */
	case "L-07C": /* Optimus bright */
	case "N-06C": /* MEDIAS WP */
	case "F-12C":
	case "P-07C":
	case "F-07D":	/* ARROWS X μ 2011-10-18 */
	case "F-05D":	/* ARROWS X LTE */
	case "F-03D":	/* ARROWS Kiss */
	case "SC-02D":	/* Galaxy Tab 7.0 */
	case "SC-01C":	/* Galaxy Tab */
	    smart_carrier = "docomo";
	    smart_tablet  = false;
	    break;
	case "SC-01D": /* Galaxy Tab 10.1 */
	case "Sony Tablet S":
	case "Sony Tablet P":
	case "L-06C": /* Optimus Pad */
	case "F-01D": /* ARROWS */
	    smart_carrier = "docomo";
	    smart_tablet  = true;
	    break;
	case "ISW11SC":		/* GALAXY S II WiMAX 2012-01-16 */
	case "INFOBAR C01":	/* INFOBAR 2012-01-16 */
	case "IS11LG":		/* optimus X 2012-01-16 */
	case "IS12S":		/* Xperia acro HD 2012-01-16 */
	case "IS12M":		/* MOTOROLA RAZAR 2012-01-16 */
	case "INFOBAR A01":
	case "IS11PT":
	case "IS11CA": /* NEC Casio */
	case "IS11S": /* Sony Ericsson */
	case "IS11SH": /* SHARP */
	case "IS12SH": /* SHARP */
	case "IS11T": /* Fujitsu Toshiba */
	case "ISW11HT":
	case "ISW12HT":
	case "ISW11K":
	case "ISW11M": /* MOTOROLA */
	case "IS11LG":
	case "ISW11F": /* Arrows Z */
	case "IS12F":  /* Arrows ES */
	case "IS13SH": /* SHARP */
	case "IS14SH": /* SHARP */
	case "IS11N":  /* MEDIAS */
	case "SonyEricssonIS11S":
	case "IS06":
	case "IS05":
	case "IS04":
	case "IS03":
	case "IS01":
	    smart_carrier = "kddi";
	    smart_tablet  = false;
	    break;
	case "MZ604":
	case "SMT-i9100":
	    smart_carrier = "kddi";
	    smart_tablet  = true;
	    break;
	case "HTCX06HT":
	case "001DL":
	case "001HT":
	case "003Z":
	case "SBM003SH":
	case "SBM005SH":
	case "SBM006SH":
	case "DM012SH":  /* Disney */
	case "DM011SH":   /* Disney */
	case "DM010SH":  /* Disney */
	case "DM009SH":  /* Disney */
            smart_carrier = "softbank";
	    smart_tablet  = false;
	    break;
	}
    }
}

function useragent_detect(){
    useragent_parse(navigator.userAgent);
}

try{
	window.addEventListener("load",useragent_detect,false);
}
catch(e){
	window.attachEvent("onload",useragent_detect);
}

