﻿//******************************************************************************
// システム名	：	高岡市観光ＨＰ
// 機能名		：	共通関数
// ファイル名	：	common.js
//******************************************************************************

/* fadeIn or fadeOut 用 */
var timerID = null;		// タイマ変数初期化
var clarity = 0;		// 透明度の初期値
var interval = 5;		// 透過の間隔
var speed = 15;			// 透過スピード

var PopUpWin			// サブウインドウ

/** ****************************************************************************
//	関数名	：	jsCountDown
//	機能	：	高岡市開町４００年(2009年9月13日)までの残日数を計算し
//				ＴＯＰページのカウントダウンエリアに表示
//-----------------------------------------------------------------------------
//	引数	：	なし
// 	戻り値	：	なし
***************************************************************************** */
function jsCountDown(){

	// 開町日設定(月は0～11 なので"8"を設定)
	var OpenTown = new Date(2009,8,13);
	var today = new Date();
	var days;
	var msg;

	days = Math.floor((OpenTown-today)/(24*60*60*1000))+1;

	if((OpenTown - today) > 0){
		msg = "２００９年９月１３日まで<br>あと " +  jsCnvDobleByte(days+"") + " 日";
	}else{
		msg = "<br>開町４００年を迎えました！";
	}

	document.getElementById('info_top').innerHTML = msg;

}

/** ****************************************************************************
//	関数名	：	jsCnvDobleByte
//	機能	：	半角数値を全角数値へ変換
//-----------------------------------------------------------------------------
//	引数	：	変換元半角数値
// 	戻り値	：	変換後全角数値
***************************************************************************** */
function jsCnvDobleByte(strNum){
	
	var sb;
	var db;
	var c;
	var pos;
	var str;

	sb = "0123456789";
	db = "０１２３４５６７８９";

	str = "";
	for (i=0; i<strNum.length; i++)	{
		c = strNum.charAt(i);
		pos = sb.indexOf(c,0);
		if (pos >= 0) {
			c = db.charAt(pos);
		}
		str += c;
	}
	return str;
}

/** ****************************************************************************
//	関数名	：	fadeIn
//	機能	：	引数で指定されたdivタグにフェードイン効果を与える
//-----------------------------------------------------------------------------
//	引数	：	フェードイン効果を行うdivタグのID名
// 	戻り値	：	なし
***************************************************************************** */
function fadeIn(str)
{
	clarity += interval;
	document.getElementById(str).filters["alpha"].opacity = clarity;

	// タイマーの初期化
	clearTimeout(timerID);
	if (clarity < 100) {
		timerID = setTimeout("fadeIn('" + str + "')", speed);
	}
}

/** ****************************************************************************
//	関数名	：	fadeOut
//	機能	：	引数で指定されたdivタグにフェードアウト効果を与える
//-----------------------------------------------------------------------------
//	引数	：	フェードアウト効果を行うdivタグのID名
// 	戻り値	：	なし
***************************************************************************** */
function fadeOut(str)
{
	clarity -= interval;
	document.getElementById(str).filters["alpha"].opacity = clarity;

	// タイマーの初期化
	clearTimeout(timerID);
	if (clarity > 0) {
		timerID = setTimeout("fadeOut('" + str + "')", speed);
	}else{
		document.getElementById(str).style.display = "none";
	}
}

/** ****************************************************************************
/	関数名	：	onSubMenu()
/	機能	：	サブメニュー表示
//-----------------------------------------------------------------------------
/	引数	：	高さ取得項目名
/			：	サブメニュー項目名
/	戻り値	：	なし
***************************************************************************** */
function onSubMenu(str1, str2){

	//	スタイル設定後、表示
	if(document.getElementById(str2).style.display != "block")
	{
		document.getElementById(str2).style.top = document.getElementById(str1).offsetTop + "px";
		document.getElementById(str2).style.display = "block";
	}
}

/** ****************************************************************************
/	関数名	：	offSubMenu()
/	機能	：	非表示する
//-----------------------------------------------------------------------------
/	引数	：	サブメニュー項目名
/	戻り値	：	なし
***************************************************************************** */
function offSubMenu(str2){

	//	非表示にする
	if(document.getElementById(str2).style.display != "none")
	{
			document.getElementById(str2).style.display = "none";
	}
}

/** ****************************************************************************
//	関数名	：	LoadMovie
//	機能	：	ＴＯＰページのＦＬＡＳＨ表示
//-----------------------------------------------------------------------------
//	引数	：	なし
// 	戻り値	：	なし
***************************************************************************** */
function LoadMovie(){

	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"  ');
	document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" ');
	document.write('width="564" height="278" title="高岡の観光スポット">');
	document.write('<param name="movie" value="../info/swf/top.swf"><param name="quality" value="high">');
	document.write('<param name="bgcolor" value="#ffffff">');
	document.write('<embed src="../info/swf/top.swf" quality="high" bgcolor="#ffffff" width="564" height="278" ');
	document.write('name="top" align="middle" ');
	document.write('type="application/x-shockwave-flash"   pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object><br>');

}

/** ****************************************************************************
//	関数名	：	ChangeItem
//	機能	：	【甘】ページの画像を切り替える
//-----------------------------------------------------------------------------
//	引数	：	なし
// 	戻り値	：	なし
***************************************************************************** */
function ChangeItem(source, destination)
{
	var brows = navigator.appName.toUpperCase();

	var prefix;
	var alt;

	if(brows.indexOf("EXPLORER") >= 0)
	{
		// ie
		prefix = "img";
		document.images[prefix + destination].filters.item(0).Apply();
		document.images[prefix + destination].src = document.images[prefix + source].src;
		document.images[prefix + destination].alt = document.images[prefix + source].alt;
		document.images[prefix + destination].filters.item(0).Play();
		alt = document.images[prefix + source].alt;
	
		prefix = "tit";
		document.all[prefix + destination].innerHTML = alt;
	
		prefix = "txt";
		document.all[prefix + destination].innerHTML = document.all[prefix + source].innerHTML;
	}else{
		// Mozila
		prefix = "img";
		document.images[prefix + destination].src = document.images[prefix + source].src;
		document.images[prefix + destination].alt = document.images[prefix + source].alt;
		alt = document.images[prefix + source].alt;
	
		prefix = "tit";
		document.getElementById(prefix + destination).innerHTML = alt;
	
		prefix = "txt";
		document.getElementById(prefix + destination).innerHTML = document.getElementById(prefix + source).innerHTML;
	}
}

/** ****************************************************************************
//	関数名	：	jsMap
//	機能	：	googleマップリンク表示
//-----------------------------------------------------------------------------
//	引数	：	住所
// 	戻り値	：	なし
***************************************************************************** */
function jsMap(Address,file)
{
	var add;

	add= "<a href=\"http://maps.google.co.jp/maps?hl=ja&tab=wl&q=" + encodeURI(Address) + "\" target=\"_blank\"><img src=\"" + file + "\" alt=\"\" border=\"0\"></a>";

	document.write(add);
}
/** ****************************************************************************
/	関数名	：	openWin()
/	機能	：	ポップアップウインドウ表示
//-----------------------------------------------------------------------------
/	引数	：	なし
/	戻り値	：	なし
***************************************************************************** */
function openWin(theURL, asize) {

/*
	if (PopUpWin == null) {
	} else {
		if (!PopUpWin.closed) {
			PopUpWin.close;
		}
	}
*/

	switch (asize){
		case null:
		case "":
			PopUpWin=window.open(theURL,'theWin','scrollbars=1, left=0,top=0,width=850,height=320,resizable=1,directories=0, toolbar=0,status=1,location=0');
			break;

		case "1":
			PopUpWin=window.open(theURL,'theWin','scrollbars=1, left=0,top=0,width=920,height=650,resizable=1,directories=0, toolbar=0,status=1,location=0');
			break;

		default:
			PopUpWin=window.open(theURL,'theWin','scrollbars=1, left=0,top=0,width=850,height=320,resizable=1,directories=0, toolbar=0,status=1,location=0');
			break;
	}	
	//PopUpWin.focus();
}
/** ****************************************************************************
/	関数名	：	linkParent()
/	機能	：	親画面へのリンク
//-----------------------------------------------------------------------------
/	引数	：	なし
/	戻り値	：	なし
***************************************************************************** */
function linkParent(theURL) {

	if ((navigator.userAgent.indexOf("Mac") > -1)){
		if (window.opener) {
		} else {
			return;
		}
	} else {
		if (!window.opener.closed) {
		} else {
			return;
		}
	}
	window.opener.location.href = theURL;
	window.opener.focus()
}

/** ****************************************************************************

//	以下、DreameWeaver 自動生成

***************************************************************************** */

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
