﻿/*****************************************************************
/*
/* Flash表示の為のスクリプト
/* Quality, FlashVars, wModeには無ければデフォルト値を挿入
/*
/*****************************************************************/
function ShowFlash(Width, Height, Src, Quality, FlashVars, wMode, forceRefresh) {

	// 強制FLASH・リフレッシュフラグ
	var debugFlashReflesh = false;


	// Wmode="opaque" だと日本語が時々おかしくなります
/*
	//Flash8用
  var flashClassID = "D27CDB6E-AE6D-11cf-96B8-444553540000";
  var iePlugIn     = "//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0";
  var niePlugIn    = "//www.macromedia.com/go/getflashplayer";
*/
	//Flash9用
  var flashClassID = "d27cdb6e-ae6d-11cf-96b8-444553540000";
  var iePlugIn     = "//fpdownload.adobe.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0";
  var niePlugIn    = "//www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash";

	if( debugFlashReflesh || typeof(forceRefresh) != "undefined" && (forceRefresh=="true" || forceRefresh==true)  ) {
		var now    = new Date();
		var year   = now.getFullYear();
		var month  = now.getMonth();
		var day    = now.getDay();
		var hour   = now.getHours();
		var min  = now.getMinutes();

		Src += '?' + year + month + day + hour + min%5;
	}

	if( typeof(Quality) == "undefined" || Quality == "" ) {
		Quality = "autohigh";
	}

	if( typeof(wMode) == "undefined" || wMode== "" ) {
		wMode = "";
	}

	if( typeof(FlashVars) == "undefined" ) {
		FlashVars = "";
	}


	var LastTag = "<object classid='clsid:"+flashClassID+"' width='" + Width + "' height='" + Height + "' codebase='"+iePlugIn+"'>"
								+ "<param name='movie' value='" + Src + "'>"
								+ "<param name='quality' value='" + Quality + "'>"
								+ "<param name='menu' value='false'>"
								+ "<param name='wmode' value='" + wMode + "'>"
								+ "<param name='FlashVars' value='" + FlashVars + "'>"
								+ "<embed src='" + Src + "' quality='" + Height + "' width='" + Width + "' height='" + Height + "' menu='false' wmode='" + wMode + "' FlashVars='" + FlashVars + "' pluginspage='"+niePlugIn+"' type='application/x-shockwave-flash'></embed>"
								+ "</object>";

	document.write( LastTag );
	
	//alert(LastTag);
}


/*****************************************************************
/*
/* JavaScriptメニュー表示
/* 指定されたIDのBOXを表示したりしなかったり
/* 表示しない:hidden, none
/* 表示する:visible, block
/*
/*****************************************************************/
function ShowMenu(TagID, Visibility) {
  
  switch(Visibility) {

    case "block":
    case "none":
    case "inline":
    case "list-item":
    	document.getElementById(TagID).style.display = Visibility;
    	break;

    case "hidden":
    case "visible":
    default:
    	document.getElementById(TagID).style.visibility = Visibility;
    	break;
	}
	
}



/*****************************************************************
/*
/* 事前に用意された２つの画像
/* **_f1.*** と **_f2.*** をスワップ（入替）
/*
/* Stateの指定が無い場合はファイル名でStateを判断
/*
/*****************************************************************/
function SwapImg(TagID, State) {

  SwapImg = document.getElementById(TagID).src;

	if( typeof(State) == "undefined" ) {
    if(SwapImg.IndexOf("_f1.")>0) {
  		State = "normal";
    } else {
  		State = "over";
    }
	}

	if( State == "over" ) {
		document.getElementById(TagID).src = SwapImg.replace("_f1.", "_f2.");
	} else {
		document.getElementById(TagID).src = SwapImg.replace("_f2.", "_f1.");
	}

}

/*****************************************************************
/*
/* JavaScriptメニュー表示
/* 指定されたIDのBOXを表示したりしなかったり
/* 表示しない:hidden
/* 表示する:visible
/*
/*****************************************************************/
function NewBanner(RegDate, Term, Tag){

	if( typeof(Term) == "undefined" ) {
		Term = 2;
	}

	if( typeof(Tag) == "undefined" ) {
		Tag = "<img align='absmiddle' src='/images/new_icon.gif'>";
	}

	if( ((new Date()-new Date(RegDate)) / (24*60*60*1000)) <= Term) {
		document.write(Tag);
	}
}

/*****************************************************************
/*
/* ポップアップ表示用
/*
/*****************************************************************/
function popup(path, name, width, height, position, scrollbars, resizable) {

	if( typeof(position) == "undefined" ) {
		position = "center";
	}

	if( typeof(scrollbars) == "undefined" ) {
		scrollbars = "no";
	}

	if( typeof(resizable) == "undefined" ) {
		resizable = "yes";
	}

	if(position == "center") {
		lf= (window.screen.availWidth - width) / 2;
		tp = (window.screen.availHeight - height) / 2;
	} else if(position == "right") {
		lf = window.screen.availWidth - width - 10;
		tp= 0;
	} else {
		lf= 0;
		tp = 0;
	}

	window.open("/popup.html?src="+path, name, "top="+tp+",left="+lf+",width="+width+",height="+height+",resizable="+resizable+",scrollbars="+scrollbars+",status=no,toolbar=no,directories=no,menubar=no");
}


/*****************************************************************
/*
/* ソーシャルブックマークの登録用
/*
/*****************************************************************/
function addSocialBookmark(SMB, Link, Title) {

	var title;
	var link;
	var open_url;

	// タイトルの指定が無ければ現在のHTMLのタイトルを使用
	if( Title != undefined || Title=="" )
	{
		title = encodeURIComponent(Title);
	}
	else
	{
		title = encodeURIComponent(document.title);
	}

	// リンクの指定が無ければ現在のホスト名を利用
	if( Link != undefined || Link=="" )
	{
		link = encodeURIComponent(Link);
	}
	else
	{
		link = encodeURIComponent("http://" + window.location.hostname + "/");
	}


	switch( SMB )
	{
		case "Yahoo":
			open_url = "http://bookmarks.yahoo.co.jp/bookmarklet/showpopup"
									+ "?t=" + title
									+ "&u=" + link
									+ "&opener=bm&ei=UTF-8";
			break;

		case "Google":
			open_url = "http://www.google.com/bookmarks/mark"
									+ "?op=edit"
									+ "&title=" + title
									+ "&bkmk=" + link;

			break;

		case "Hatena":
			open_url = "http://b.hatena.ne.jp/append"
									+ "?" + link;
			break;

		case "Nifty":
			open_url = "http://clip.nifty.com/create"
									+ "?title=" + title
									+ "&url=" + link;
			break;
							

		case "livedoor":
			open_url = "http://clip.livedoor.com/redirect"
									+ "?title=" + title
									+ "&link=" + link;
			break;
							

		case "delicious":
			open_url = "http://del.icio.us/post"
									+ "?title=" + title
									+ "&url=" + link;
			break;

		
		default:
			open_url = ""
			break;
	}

	window.open(open_url);
	//alert(open_url);
}


/*****************************************************************
/*
/* ブックマークの登録用
/*
/*****************************************************************/
function addBookmark(URL, Title) {
	try {
		window.external.AddFavorite(URL, Title);
	} catch(e) {
		alert("このリンクはIE(Internet Exploler)専用です");
	}
}

/*****************************************************************
/*
/* 動きのあるTOPに戻る用
/*
/*****************************************************************/
var ReturnSpeed = 1;
// スクロールスピードを設定します。
// 値が大きくなればなるほど速くなります。

function ScrollTop() {

    // ページ最上部からの距離をピクセル単位でyに代入します。
    if(navigator.appName == "Microsoft Internet Explorer" && document.compatMode == "CSS1Compat"){
      var y = document.body.parentNode.scrollTop;
    }else{
      var y = document.body.scrollTop;
    }
	

    // ReturnSpeedの値が50未満且つyが0でない場合、以下の処理を行います。
    // ・yが2以上であるなら、y*1.2を四捨五入してyに代入。
    // 　以下ならば1を代入。つまりイージングの設定。
    // 　ReturnSpeedに1を加算し、ページをスクロール。
    // 　if文が真である間これを繰り返します。
    // ページ最上部までのスクロールが完了したら変数ReturnSpeedに1を代入しリセット。
    if(ReturnSpeed < 50 && y) {
      y = (y > 2) ? Math.ceil(y*.2) : 1;
      ReturnSpeed++;
      scrollBy(0,-y);
      setTimeout("ScrollTop()",10);
    }else{
      scrollTo(0,0);
      ReturnSpeed = 1;
    }
}


/*****************************************************************
/*
/* QuickTime表示の為のスクリプト
/* 
/*
/*****************************************************************/

function ShowQuickTime(Width, Height, Src, Control) {
	
	var CLASSID = "02BF25D5-8C17-4B23-BC80-D3488ABDDC6B";
	var iePlugIn     = "//www.apple.com/qtactivex/qtplugin.cab";
	var niePlugIn    = "//www.apple.com/quicktime/download/";
	
	if( typeof(Control) == "undefined" || Control=="" ) {
		Control = "true";
	}
	
	var LastTag = "<object classid='clsid:"+CLASSID+"' width='" + Width + "' height='" + Height + "' codebase='"+iePlugIn+"'>"
								 + "<param name='SRC' value='" + Src + "'>"
								 + "<PARAM name='AUTOPLAY' VALUE='true'>"
								 + "<PARAM name='TARGET' VALUE='QUICKTIMEPLAYER'>"
								 + "<PARAM name='SCALE' VALUE='TOFIT'>"
								 + "<PARAM name='HREF' VALUE='"+Src+"'>"
								 + "<PARAM name='CONTROLLER' VALUE='" + Control + "'>"
							   + "<embed src='" + Src + "' width='" + Width + "' height='" + Height + "' AUTOPLAY='true' SCALE='TOFIT' TARGET='QUICKTIMEPLAYER' CONTROLLER='"+Control+"' pluginspage='"+niePlugIn+"' href='"+Src+"'></embed>"
							   + "</object>";

	//alert(LastTag);

	document.write(LastTag);
}


/*****************************************************************
/*
/* ブラウザ強制閉じスクリプト
/*
/*****************************************************************/

function WindowForceClose() {

	window.opener = window;
	window.open(location.href,'_self');
	window.close();

}


/*****************************************************************
/*
/* XHTMLの為のIframe動的呼び出し
/*
/*****************************************************************/

function ShowIframe(Width, Height, Src, ID, Text, Scrolling) {
	
	if( typeof(Width) == "undefined" || Width=="" ) {
		Width = "100%";
	}

	if( typeof(Height) == "undefined" || Height=="" ) {
		Height = "100%";
	}

	if( typeof(Text) == "undefined" || Text=="" ) {
		Text = "ここはインラインフレームです";
	}

	if( typeof(Scrolling) == "undefined" || Scrolling=="" ) {
		Scrolling = "no";
	}

	var tag = "<iframe id='" + ID +"' src='" + Src +"' frameborder='0' width='" + Width + "' height='" + Height +"' scrolling='" + Scrolling + "'>"
							+ Text
							+ "</iframe>";
	
	document.write(tag);

}


/*****************************************************************
/*
/* クッキー操作
/*
/*****************************************************************/
function ReadCookie(key)
{
	var sCookie = document.cookie;    // Cookie文字列
	var aData = sCookie.split(";");       // ";"で区切って"キー=値"の配列にする
	var oExp = new RegExp(" ", "g");   // すべての半角スペースを表す正規表現
	key = key.replace(oExp, "");          // 引数keyから半角スペースを除去

	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 "";                                   // 見つからない時は空文字を返す
}


function WriteCookie(key, value, days)
{
	var str = key + "=" + escape(value) + ";";         // 書き出す値１ : key=value
	if (days != 0)
	{                                                 /* 日数 0 の時は省略 */
		var dt = new Date();                                   // 現在の日時
		dt.setDate(dt.getDate() + days);                   // days日後の日時
		str += "expires=" + dt.toGMTString() + ";"; // 書き出す値２ : 有効期限
	}
	document.cookie = str;                                   // Cookie に書き出し
}


/*****************************************************************
/*
/* 訪問済みの :visited 再現用スクリプト
/*
/*****************************************************************/

var m_AccessHistory = "";
var m_AccessHistory2 = "";

// 前回までの履歴を取得
m_AccessHistory = ReadCookie("access_history");
m_AccessHistory2 = ReadCookie("access_history2");


function CheckHistory( pubid, direction, history_name )
{
	var history = "";
	
	if( typeof(history_name) == "undefined" || history_name=="access_history" )
	{
		history = m_AccessHistory;
	}
	else
	{
		history = m_AccessHistory2;
	}
	
	if(history.indexOf(","+pubid)>=0)
	{
		if( direction == "prefix" )
		{
			document.write("<span class='visited'>");
		}
		else
		{
			document.write("</span>");
		}
	}
}

function LoggingHistory( pubid, object, history_name)
{
	if( typeof(history_name) == "undefined" || history_name=="access_history" )
	{
		if(m_AccessHistory.indexOf(","+pubid)<0)
		{
			m_AccessHistory += "," + pubid;
			object.className = "visited";
			WriteCookie("access_history", m_AccessHistory, 28);	
		}
	}
	else
	{
		if(m_AccessHistory2.indexOf(","+pubid)<0)
		{
			m_AccessHistory2 += "," + pubid;
			object.className = "visited";
			WriteCookie("access_history2", m_AccessHistory2, 28);	
		}
	}
	
	//alert(m_AccessHistory);
}

/*****************************************************************
/*
/* 画像付き広告の文字数対策
/*
/*****************************************************************/
function fix_panel_link()
{
	var i;
	var name_text;
	var field = $$("table.table_panel div.panel_title a.panel_name");
	var resize_len = 19 * 2;
	var width_len;

	for (i = 0; i < field.length; i++)
	{
		//alert(field[i].innerHTML.toLowerCase());
		//alert(name_text.length-name_text.lastIndexOf(text_br)-text_br.length);

		name_text = field[i].innerHTML;
		name_text = name_text.replace(/^\s+|\s+$/g, "");

		width_len = string_length(name_text);

		if(width_len > resize_len)
		{
			field[i].className = "panel_name_small";
		}
	}
}
/*
function fix_panel_link()
{
	var i;
	var name_text;
	var text_br = "<br />";
	var text_br2 = "<br>";
	var field = $$("table#table_panel div.panel_title a.panel_name");
	var resize_len = 10 * 2;
	var max_len = resize_len + (2 * 2);
	var width_len;
	var width_len2;

	for (i = 0; i < field.length; i++) {
			
			//alert(field[i].innerHTML.toLowerCase());
			//alert(name_text.length-name_text.lastIndexOf(text_br)-text_br.length);

			name_text = field[i].innerHTML.toLowerCase();
			name_text = name_text.replace(text_br, text_br2);

			arr_name = name_text.split(text_br2);

			arr_name[0] = arr_name[0].replace(/^\s+|\s+$/g, "");
			arr_name[1] = arr_name[1].replace(/^\s+|\s+$/g, "");

			width_len = string_length(arr_name[0]);
			width_len2 = string_length(arr_name[1]);

			if(width_len < width_len2){
				width_len = width_len2;
			}

			if(width_len >= max_len){
				field[i].className = "panel_name_tiny";
			}
			else if(width_len >= resize_len){
				field[i].className = "panel_name_small";
			}
	}
}
*/


/*****************************************************************
/*
/* テキスト広告の文字数対策
/*
/*****************************************************************/
function fix_table_link()
{
	var i;
	var name_text;
	var field = $$("table#table_charging td.office_name a.column_name");
	var resize_len = 26 * 2;
	var width_len;

	for (i = 0; i < field.length; i++)
	{
		//alert(field[i].innerHTML.toLowerCase());
		//alert(name_text.length-name_text.lastIndexOf(text_br)-text_br.length);

		name_text = field[i].innerHTML;
		name_text = name_text.replace(/^\s+|\s+$/g, "");

		width_len = string_length(name_text);

		if(width_len > resize_len)
		{
			field[i].className = "column_name_small";
		}
	}

	field = $$("table#table_free td.office_name a.column_name");

	for (i = 0; i < field.length; i++)
	{
		//alert(field[i].innerHTML.toLowerCase());
		//alert(name_text.length-name_text.lastIndexOf(text_br)-text_br.length);

		name_text = field[i].innerHTML;
		name_text = name_text.replace(/^\s+|\s+$/g, "");

		width_len = string_length(name_text);

		if(width_len > resize_len)
		{
			field[i].className = "column_name_small";
		}
	}
}
/*
function fix_table_link()
{
	var i;
	var name_text;
	var text_br = "<br />";
	var text_br2 = "<br>";
	var field = $$("table#table_charging td.office_name a.column_name");
	var resize_len = 13 * 2;
	var max_len = resize_len + (2 * 2);
	var width_len;
	var width_len2;

	for (i = 0; i < field.length; i++) {
			
			//alert(field[i].innerHTML.toLowerCase());
			//alert(name_text.length-name_text.lastIndexOf(text_br)-text_br.length);

			name_text = field[i].innerHTML.toLowerCase();
			name_text = name_text.replace(text_br, text_br2);

			arr_name = name_text.split(text_br2);

			arr_name[0] = arr_name[0].replace(/^\s+|\s+$/g, "");
			arr_name[1] = arr_name[1].replace(/^\s+|\s+$/g, "");

			width_len = string_length(arr_name[0]);
			width_len2 = string_length(arr_name[1]);

			if(width_len < width_len2){
				width_len = width_len2;
			}


			if(width_len >= max_len){
				field[i].className = "column_name_tiny";
			}
			else if(width_len >= resize_len){
				field[i].className = "column_name_small";
			}
	}

	field = $$("table#table_free td.office_name a.column_name");

	for (i = 0; i < field.length; i++) {
			
			//alert(field[i].innerHTML.toLowerCase());
			//alert(name_text.length-name_text.lastIndexOf(text_br)-text_br.length);

			name_text = field[i].innerHTML.toLowerCase();
			name_text = name_text.replace(text_br, text_br2);

			arr_name = name_text.split(text_br2);

			arr_name[0] = arr_name[0].replace(/^\s+|\s+$/g, "");
			arr_name[1] = arr_name[1].replace(/^\s+|\s+$/g, "");

			width_len = string_length(arr_name[0]);
			width_len2 = string_length(arr_name[1]);

			if(width_len < width_len2){
				width_len = width_len2;
			}

			if(width_len >= max_len){
				field[i].className = "column_name_tiny";
			}
			else if(width_len >= resize_len){
				field[i].className = "column_name_small";
			}
	}
}
*/

/*****************************************************************
/*
/* 2byte文字の字数カウント
/*
/*****************************************************************/
function string_length(str)
{
	var length = 0;
	str = escape(str);
	var i = 0;

	for(; i < str.length; i++)
	{
		if(str.charAt(i) == '%')
		{
			// UNICODE 対応 (IE)
			if(str.charAt(i + 1) == 'u')
			{
				i += 4;
				length++;
			}
			else
			{
				// IE 以外の場合
				i++;
			}
			
			i++;
		}
		
		length++;
	}
	
	return length;
}

/*****************************************************************
/*
/* 広告オープン用
/*
/*****************************************************************/
function OpenAd( site )
{
	switch( site )
	{
		default:
		case "profitad":
			window.open("http://www.profit-ad.com/", "profitad");
			break;
		
		case "hasan":
			window.open("http://www.navi-hasan.com/", "navihasan");
			break;
			
		case "kabarai":
			window.open("http://www.navi-kabaraikin.com/", "navikabaraikin");
			break;
			
		case "saimuseiri":
			window.open("http://www.navi-saimuseiri.com/", "navikabaraikin");
			break;

		case "yen":
			window.open("http://www.navi-yen.com/", "naviyen");
			break;

		case "saimu":
			window.open("http://www.navi-saimu.com/", "navisaimu");
			break;

		case "seiri":
			window.open("http://www.navi-seiri.com/", "naviseiri");
			break;

		case "saisei":
			window.open("http://www.navi-saisei.com/", "navisaisei");
			break;

		case "meisei":
			window.open("http://www.meisei-rs.co.jp/", "meisei");
			break;
	}
	
	return false;
}
