
var smpRedirectBnr = {
	"url" : "/m/", // 遷移させるURL
	"cName":"loadSite=pc", // クッキー名
	"domain":"kokuyo.co.jp" // ドメイン名
};

/*--------------------------------------------
  Cookie削除
--------------------------------------------*/

function smpDeleteCookie() {
	dTime = new Date();
	dTime.setFullYear(dTime.getFullYear() - 1);
	document.cookie = smpRedirectBnr["cName"] + "; domain=" + smpRedirectBnr["domain"] + ";  path=/; expires=" + dTime.toGMTString();
}


(function(){

/*--------------------------------------------
  OS別振り分け処理
--------------------------------------------*/

var smpRedirect = {
	"url" : "/m/" // リダイレクトさせるURL
};

smpRedirect["ua"] = navigator.userAgent; //ユーザーエージェント

if((smpRedirect["ua"].indexOf('iPhone') > 0 && smpRedirect["ua"].indexOf('iPad') == -1) || smpRedirect["ua"].indexOf('iPod') > 0 || smpRedirect["ua"].indexOf('Android') > 0){
	if(smpReadCookie("loadSite") != "pc"){
		location.href = smpRedirect["url"];
	}
}


/*--------------------------------------------
  Cookie読込
--------------------------------------------*/

function smpReadCookie(key){
	var sCookie = document.cookie;
	var aData = sCookie.split(";");
	var oExp = new RegExp(" ", "g");
	key = key.replace(oExp, "");

	var i = 0;
	while (aData[i]) {                  
		var aWord = aData[i].split("=");
		aWord[0] = aWord[0].replace(oExp, "");
		if (key == aWord[0]) return unescape(aWord[1]);
		if (++i >= aData.length) break; 
	}
	return "";
}



/*--------------------------------------------
  OS別振り分け処理
--------------------------------------------*/

smpRedirectBnr["ua"] = navigator.userAgent; //ユーザーエージェント

if((smpRedirectBnr["ua"].indexOf('iPhone') > 0 && smpRedirectBnr["ua"].indexOf('iPad') == -1) || smpRedirectBnr["ua"].indexOf('iPod') > 0 || smpRedirectBnr["ua"].indexOf('Android') > 0){
	var html = '<div id="smartdevice-header"><a href="'+smpRedirectBnr["url"]+'" onclick="smpDeleteCookie()"><img src="/cmn/img/btn_smartdevice.gif" alt="スマートフォン対応ページを表示される場合はこのボタンをタップしてください" /></a></div>'
	$(function(){
		$('body').prepend(html);
	});
}

})();

