/**
 * ユーザーエージェントを判断してスマートフォンサイトへ誘導する。
 */
function isAndroidTablet(ua) {
	var result = false;
	if (null != ua.toLowerCase().match(/android/)) {
		// 個別で機種を指定する 例） /SO01B|xxxx|/
		if (null != ua.match(/SC-01C|L-06C/)) {
			// 何もしない
		} else {
			result = true;
		}
	}
	return result;
}
// iphone, ipod, androidのものをチェックする。
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g, "");
}

function spRedirect() {
	if (null != navigator.userAgent.toLowerCase().match(/iphone|ipod/) || isAndroidTablet(navigator.userAgent)) {
		var cookieStr = String(document.cookie);
		console.log(cookieStr);
		var cookies = cookieStr.trim().split(';');
		var existSmartSite = false;
		var goSmartSite = false;
		for ( var i = 0; i < cookies.length; ++i) {
			var cookie = cookies[i].trim().split('=');
			if ('siteViewState' == cookie[0]) {
				existSmartSite = true;
				if ('pc' == cookie[1]) {
					// 何もしない
				} else {
					goSmartSite = true;
				}
				break;
			}
		}
		// console.log(goSmartSite);
		if (!existSmartSite || goSmartSite) {
			location.href = "/sp/";
		}
	}
}

/**
 * スマートフォンからへ遷移する
 * 
 * @returns
 */
function fromPcSite() {
	document.cookie = 'checkcookie=checked;'
	if (null == document.cookie || '' == document.cookie) {
		alert('cookieはONにしてください。');
	} else {
		var today = new Date();
		today.setSeconds(today.getSeconds() + (20 * 60));
		document.cookie = 'siteViewState=pc;path=/;expires=' + today.toGMTString();
		location.href = '../';
	}
}

