// JavaScript Document

//var chkCookie = document.cookie;
//if(chkCookie.indexOf("cookieon=yes") < 0) {
//	document.location.href="/oudan/access_error.html";
//}

var __lockObject = false;

function changeMode(ua){
	var flag = ua.indexOf("Peece",0);
	if(flag == -1){
	 document.getElementById('browseronly').style.display = 'block';
	}
	else{
	 document.getElementById('browseronly').style.display = 'none';
	}
}


function appl_download(pptvUrl) {
//   document.location.href="http://peece.tv/download.html";
//     alert(pptvUrl);
//     window.open('http://peece.net/oudan/download/peece_dowm_click.html', 'PeeceTV', 'width=1024, height=600, menubar=no, toolbar=no, location=no, status=no, resizable=no, scrollbars=no');
//	var url = encodeURIComponent(pptvUrl.substring(pptvUrl.indexOf("?")+5, pptvUrl.length));
//honnbann start
	window.open('/oudan/download/peece_dowm_click.html?url=' + url, 'PeeceTV', 'width=1024, height=600, menubar=no, toolbar=no, location=no, status=no, resizable=no, scrollbars=no');
	var url = encodeURIComponent(pptvUrl.substring(pptvUrl.indexOf("?")+5, pptvUrl.length));
	document.location.href="/oudan/play/play.html?url=" + url;
//honnbann end
//     window.open('http://peece.tv/download.html', 'PeeceTV', 'width=1024, height=600, menubar=no, toolbar=no, location=no, status=no, resizable=no, scrollbars=no');
//
//LOCAL_DEBUG start
//	content_download(pptvUrl);
//LOCAL_DEBUG end
}

function content_download(pptvUrl) {
//honnbann start
	if(getCookie("CONFIRM_MSG").length>0 && location.href.indexOf('play.html')==-1){
	    var url = encodeURIComponent(pptvUrl.substring(pptvUrl.indexOf("?")+5, pptvUrl.length));
		location.href="/oudan/play/play.html?url="+url;
		document.cookie = "CONFIRM_MSG=true;";
	} else 
	if(pptvUrl.indexOf('youtube') > -1 && location.href.indexOf('play.html')==-1) {
//		alert('現在Youtube側の仕様変更の為、インポート出来なくなっております。\nご迷惑おかけ致しますが、ご理解いただけますようお願い申し上げます。');
		var msg = 'Youtube動画インポートの挙動変更により、インポート方法が変更になっております。以下の手順にて操作願います。\n１．「OK」ボタンクリック\n２．詳細画面へ遷移されたら、下部のインポートをクリック\n※遷移時に自動的に再生が始まりますのでご注意ください。';
		if(window.confirm(msg)){
		    var url = encodeURIComponent(pptvUrl.substring(pptvUrl.indexOf("?")+5, pptvUrl.length));
			location.href="/oudan/play/play.html?url="+url;
			document.cookie = "CONFIRM_MSG=true;";
		} else {
		}
	} else {
		if(pptvUrl.indexOf('nicovideo') > -1){
			window.open('/oudan/download_alert.html', 'PeeceTV', 'width=1024, height=600, menubar=no, toolbar=no, location=no, status=no, resizable=no, scrollbars=no');
		}
		checkMovieOnClick(pptvUrl);
	}
//honnbann end
//
//LOCAL_DEBUG start
//    var url = encodeURIComponent(pptvUrl.substring(pptvUrl.indexOf("?")+5, pptvUrl.length));
//    document.location.href="http://localhost/oudan/download/download.pptv?url=" + url;
//LOCAL_DEBUG end
//    document.location.href="http://172.16.1.198/oudan/download/download.pptv?url=" + url;
//    document.location.href="http://peece.net/oudan/download/download.pptv?url=" + url;
}

//DEBUG
function logger(value) {
	var userAgent=navigator.userAgent.toLowerCase();
	if(userAgent.indexOf("safari")>=0) {
		console.log(value);
	}
}

function keywordSearch(param) {
	if(!__lockObject) {
		_lock();
		showProgressDialog();
		document.location.href = "/oudan/search/search.html?q="+encodeURIComponent(param);
	}
}

function keywordSearch2(param) {
	if(!__lockObject) {
		_lock();
		showProgressDialog();
		document.location.href = "/oudan/search/search.html?q="+encodeURIComponent(param)+"&type=1";
	}
}

function keywordSearch3(param) {
	if(!__lockObject) {
		_lock();
		showProgressDialog();
		document.location.href = "/oudan/search/search.html?q="+encodeURIComponent(param)+"&all=1&site_kind=1&site_kind=3&site_kind=5&idol=idol";
	}
}

function _lock() {
	if(!__lockObject) {
		__lockObject = true;
		return true;
	}
	return false;
}

function _unlock() {
	__lockObject = false;
}

function dummyJS(url){
}

function getCookie(key){

  // クッキーデータを取得します
  // データを識別するためのクッキーIDが必要です
  // 取得したデータは連想配列で返されます
  // 第一引数：クッキーID
  // 戻り値
  // 取得したデータ（連想配列） / null
  
  var cookieArr = document.cookie.split(" ");
  var max       = cookieArr.length;
  // 全てのクッキーをチェック
  var oneCookie;
  for(var i = 0; i < max; i++){
    // 目的のクッキーIDをもつデータを探す
    if (key == cookieArr[i].substr(0 , key.length)){
      // 同じだったら
      var temp = cookieArr[i].split("=");
      // エスケープ文字を元に
      temp[1]  = decodeURI(temp[1]);
      // 末尾に「;」が付いてるモノは削除
      if ((temp[1].length -1) == temp[1].lastIndexOf(";"))
        temp[1] = temp[1].slice(0 , temp[1].length - 1);
      // 各データを分割
      var cookie = temp[1].split("&");
     var cMax = cookie.length;
     var arr = new Array();
     var tmp  = new Array();
     for(var j = 0; j < cMax; j++){
        tmp = cookie[j].split("=");
        arr[tmp[0]] = tmp[1];
     }
    return arr;
    }
  }
  return null;
}
