/*
 * %付きUnicodeをdecodeする。
 */
function fromUnicode(str){

  var seq = "";

  var buf = str.split( "%" );

  for( var i=1 ; i<buf.length ; i++ ){

    seq += String.fromCharCode( parseInt( buf[i] , 16 ) );

  }


  return seq;

}


/*
 * %付きUnicodeにencodeする。
 */
function toUnicode(str){

  var seq = "";

  for( var i=1 ; i < str.length ; i++ ){
    
    seq = seq + "%" + str.charCodeAt(i); 

  }

  return seq;
}



/**

 * Cookieから履歴を取得し表示する

 */

function getHistory(){
//window.alert("ファンクション開始");
  var allCookies = document.cookie;

  //宿履歴の場所を探す

  var pos = allCookies.indexOf("history=");

  var kenCount = 0;

  var value = 0;

  if(pos != -1){

    var start = pos + 8;

    var end = allCookies.indexOf(";",start);

    if(end == -1) end = allCookies.length;

    value = allCookies.substring(start,end);

    if(value){

      var history = "";
      var restCount = 0;
      var histArray = value.split("]");
      var count = 0;
      var yadNoArray = new Array();
      
      for( var i=0 ; i<histArray.length ; i++){

		var histValueArray = histArray[i].split("#");
		
		var flg = true;
		for (var j = 0; j < yadNoArray.length; j++) {
		
			if(yadNoArray[j] == histValueArray[0]) {
			
				flg = false;
			}
		}

		if(flg == true) {
			if(count < 5) {
		        if(count == 0) {
		        	history += '<p>' + fromUnicode(histValueArray[1]) + '</P>';
		        } else {
		        	history += '<p>' + fromUnicode(histValueArray[1]) + '</P>';
		        }
	        }
	        yadNoArray.push(histValueArray[0]);
	        count += 1;
		}

      }
      
      kenCount = count;
      
      if(count > 5){
          //history += '<p>' + "……他" + '</P>';
          restCount = count;
      }

      if(value){
		//チェック履歴があるとき
        document.getElementById("myHistory").innerHTML = history;
        document.getElementById("check_btn_img").innerHTML =
        "<img src=\"/uw/images/header990_mitayado_btn.gif\""
        + " id=\"sono1\" alt=\"あなたが最近見た宿\" name=\"check\" onMouseOut=\"uaRO(this, '/uw/images/header990_mitayado_btn.gif');\" onMouseOver=\"uaRO(this, '/uw/images/header990_mitayado_btn_ovr.gif');\">";
 		document.getElementById("myHistory3").innerHTML = '<div id="mitayado_top"><p>最近見た宿<strong><span class="s16_F60b">' + kenCount +'</span>軒</strong>あります</p></div>';
      	document.getElementById("myHistory4").innerHTML = '<p class="come">友達にメールOK。MAPでも見られる。</p>';
      } else {
      	//チェック履歴がないとき
      	document.getElementById("myHistory").innerHTML = '<p class="none">' + "まだ履歴がありません" + '</P>';
      	document.getElementById("check_btn_img").innerHTML = "";
//      	document.getElementById("myHistory2").innerHTML = "まだ履歴がありません";
      	document.getElementById("check_btn_img2").innerHTML = "";
      	document.getElementById("myHistory4").innerHTML = "";
      }
    }
  }
  if(value == 0){
      document.getElementById("myHistory").innerHTML = '<p class="none">' + "まだ履歴がありません" + '</P>';
//      document.getElementById("myHistory3").innerHTML = '<span id="myHistory3" ><div id="mitayado_top"><p>最近見た宿</p></div></span>';
      document.getElementById("myHistory3").innerHTML = '<div id="mitayado_top"><p>最近見た宿</p></div>';
      document.getElementById("myHistory4").innerHTML = "";
  }
}

/******************************************************************************
関数名前  ： getHistoryNum
処理機能  ： Cookieから履歴を取得し件数を返却する
引数      ： なし
戻り値    ： チェック履歴件数
作成日    ： 2008/03/01
******************************************************************************/
function getHistoryNum(){

  var allCookies = document.cookie;

  //宿履歴の場所を探す

  var pos = allCookies.indexOf("history=");

  var count = 0;



  if(pos != -1){

    var start = pos + 8;



    var end = allCookies.indexOf(";",start);



    if(end == -1) end = allCookies.length;

    var value = allCookies.substring(start,end);



    if(value){
      var histArray = value.split("]");
      count = histArray.length;
    }
  }    
    return count;
  
}

/******************************************************************************
関数名前  ： latestYadDisp
処理機能  ： TOP画面「最近見た宿」専用の表示JS
引数      ： なし
戻り値    ： なし
作成日    ： 2008/03/01
******************************************************************************/
function latestYadDisp() {

	var num = getHistoryNum();
//	alert("チェック履歴件数：" + num);
	
	if( num > 0 ) {
		
		document.write("<div class=\"rightarea\">");
		document.write("<div id=\"mitayado\">");
		document.write("<p class=\"s12_30\">最近見た宿は<a href=\"/uw/uwp7000/uww7001.do\">こちら</a></p>");
		document.write("</div>");
		document.write("</div>");

	}
}

