function setPcType(){
  setCookie();
  location.reload();
}
function setSpType(){
  removeCookie();
  location.reload();
}
function setPcTypeRedirect(url){
  setCookie();
  //location.replace(url);
  location.href = url;
}

function setSpTypeRedirect(url){
  removeCookie();
  //location.replace(url);
  location.href = url;
}
function setCookie(){
  createCookie(730);
}

function removeCookie(){
  createCookie(-1);
}
function createCookie(expire){
  var delim = ";";
  var name = "CX_SMARTPHONE_VIEW_TYPE";
  var value = "";
  if (expire > 0) {
    value = "PC";
  }
  var hostname = location.hostname; //append
  var date = new Date();
  date.setDate(date.getDate() + expire);
  var cookie = name + "=" + value + delim;
  cookie += "expires=" + date.toGMTString() + delim;
  if(hostname.indexOf(".fujitv.co.jp") > 0){ //append
    cookie += "domain=" + ".fujitv.co.jp" + delim;
  } else {
    cookie += "domain=" + hostname + delim; //append
  }
  cookie += "path=" + "/" + delim;
  document.cookie = cookie;
}
function _getCookie(key) {
  var strCookie = document.cookie;
  var arrData = strCookie.split(";");
  var objExp = new RegExp(" ", "g");
  key = key.replace(objExp, "");
  var i = 0;
  while ( arrData[i] ) {
    var arrWord = arrData[i].split("=");
    arrWord[0] = arrWord[0].replace(objExp, "");
    if ( key == arrWord[0] ) return unescape(arrWord[1]);
    if ( ++i >= arrData.length ) break;
  }
  return "";
}
var uaChecker = new Object();
uaChecker.widthChange = function() {
	var devWidth = arguments[0];
	if ( typeof devWidth == "undefined" ) { devWidth = 566; }
	if ( navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) ) {
		if ( _getCookie("CX_SMARTPHONE_VIEW_TYPE") != "PC" ) {
			
			if ( navigator.userAgent.match(/Android/i) ) {
				/* $(window).bind('resize load', function(){$("html").css("zoom", $(window).width()/devWidth);}); */
				var meta = document.createElement("meta");
				meta.setAttribute("name", "viewport");
				meta.setAttribute("content","width=device-width;target-densitydpi=280;");
				document.getElementsByTagName("head")[0].appendChild(meta);
			}
			
			document.getElementById('csslink').href = "/css/1104renew/smart_t.css";
		}
	}
}
uaChecker.gbmenuCheck = function() {
	if ( navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) ) {
		if ( _getCookie("CX_SMARTPHONE_VIEW_TYPE") != "PC" ) { 
			return "smartphone";
		} else {
			return "pc";
		}
	} else {
		return "pc";
	}
}
uaChecker.sphoneMenuOut = function() {
	if ( navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) ) {
		document.write("<div id=\"switch_indication\" style=\"text-align: center;\"><dl><dt>表示</dt><dd><ul>");
		if ( _getCookie("CX_SMARTPHONE_VIEW_TYPE") == "PC" ) {
			document.write("<li><a href=\"javascript:void(0)\" onclick=\"setSpType()\">スマートフォン版</a></li>");
			document.write("<li><em>PC版</em></li>");
		} else {
			document.write("<li><em>スマートフォン版</em></li>");
			document.write("<li><a href=\"javascript:void(0)\" onclick=\"setPcType()\">PC版</a></li>");
		}
		document.write("</ul></dd></dl></div>");
	}
}
