// JavaScript Document

/* r-de.net stylesheets
 *
 * update: 2008.01.26
 * code by Hidetake Kurihara
 * copyright (c)2008 R-design. all rights reserved.
 */


SiteURL="http://www.er-f.com/";


/*------------------------------------------------------------------------------------------
	スワップイメージ
------------------------------------------------------------------------------------------*/
function swapImg(str,num){
	document.images[str].src = SiteURL+'imgs/'+num;
}


/*------------------------------------------------------------------------------------------
	スワップバックグラウンド
------------------------------------------------------------------------------------------*/
function swapBgOver(str){
	str.style.background="#E7E7E7";
	str.style.color="#666";
}
function swapBgOut(str){
	str.style.background="#FFF";
	str.style.color="#666";
}


/*------------------------------------------------------------------------------------------
	検索ボックス フォーカス
------------------------------------------------------------------------------------------*/
function FormFocus() {
  document.SearchArea.query.focus();
}


/*------------------------------------------------------------------------------------------
	サブメニュー表示・非表示
------------------------------------------------------------------------------------------*/
function toggle( targetId ){
	if (document.getElementById){
		target = document.getElementById( targetId );
		if(target.style.display == "none"){target.style.display = "";
		}else{target.style.display = "none";}
	}
}


/*------------------------------------------------------------------------------------------
	ウィンドウオープン
------------------------------------------------------------------------------------------*/
function openWin(tgtU,wdt,hgt){
	subWin=window.open(tgtU,"subWin","width=" + wgt,"height=" + hgt);
	subWin.moveTo(0,0);
	subWin.focus;
}


/*------------------------------------------------------------------------------------------
	ウィンドウクローズ
------------------------------------------------------------------------------------------*/
function insertCloseBtn(){
	document.write('<a href="javascript:window.close()">閉じる</a>');
}
/* <script type="text/javascript">insertCloseBtn();</script>で呼び出し */


/*------------------------------------------------------------------------------------------
	Flash読み込み
------------------------------------------------------------------------------------------*/
function includeFlash( url, width, height, title, quality ){
	document.write( '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + width + '" height="' + height + '" title="' + title + '">' );
	document.write( '<param name="movie" value="' + url + '" />' );
	document.write( '<param name="quality" value="' + quality + '" />' );
	document.write( '<embed src="' + url + '" quality="' + quality + '" pluginspage="https://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed>' );
	document.write( '</object>' );
}
/* <script type="text/javascript" language="javascript">includeFlash( 'flash/main.swf', 750, 180, 'ホームページ制作 R-design WEBサイト', 'high' );</script>で呼び出し */


/*------------------------------------------------------------------------------------------
	styleswitcher.js （http://www.alistapart.com/stories/alternate/）※フォントサイズ変更
------------------------------------------------------------------------------------------*/
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
   if(a.getAttribute("rel") && a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel") && a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title"); 
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel") && a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);


/*------------------------------------------------------------------------------------------
	お気に入り追加　（WindowsIEのみ）
------------------------------------------------------------------------------------------*/
function myFavorite(){
	var agent=navigator.userAgent;
	var ie=agent.indexOf("MSIE");
	var iever=parseInt(agent.substring(ie+5, ie+6));
	var os=agent.indexOf("Windows");

	if((ie > 0) && (iever >= 5) && (os > 0) && !window.opera){
		var bookmarkURL=self.location; /* window.location.hrefでもOK */
		var bookmarkTITLE=document.title;
		window.external.AddFavorite(bookmarkURL, bookmarkTITLE);
	}else{
		alert("Internet Explorer のみのサポートとなります");
	}
}
