// JavaScript Document for 'Bike Yard'
// charaset 'shift_jis'

/* -----------------------------------------------------
画像をポップアップ
<a href="javascript:void(0)" onclick="openImg('name','title',w,h)" onkeypress="openImg('name','title',w,h)">
----------------------------------------------------- */
// ↓初期設定
// ポップアップさせる画像ファイルの識別文字
var dist = '_l';
	
// 主に使う拡張子を指定
var ext = 'jpg';

// ポップアップさせる画像の縦横サイズを指定
var width = 400;
var height = 300;

// エンコードを指定
var enc = 'shift_jis';

// ↓ここからプログラム開始　編集しないこと。
function openImg(name,title,w,h){		
	// 画像ファイル格納ディレクトリを設定
	var img_dir;
	/*body_id = document.getElementsByTagName('body')[0].id;
	dir_num = body_id.substr(2,99);
	img_dir = 'img/' + dir_num + '/';*/
	img_dir = 'img/';

	// 画像ファイルの設定
	// nameがurlの場合はそのurlを表示、そうでなければ img/name_l.jpg を表示
	var img;
	if(name.indexOf('.') != -1){
		img = name;
		}else{
		img = img_dir + name + dist + '.' + ext;
	}
	
	// titleとaltの設定
	// nameがurlの場合はurlから画像名を取得。urlではない場合はnameを表示。	
	var title;
	if((title == "")||(title ==null)){
			if(name.indexOf('.') != -1){
						// @ nameで指定されたパスを'/'で分割、配列化
						// 例）img/kase_map_l.gif　→　[img][kase_map_l.gif]
						file_path = name.split('/');
						
						// A @の配列の一番最後の配列が拡張子を含めたファイル名
						// 例）[img][kase_map_l.gif]　→　kase_map_l.gif
						temp_filename = file_path[file_path.length - 1];
						
						// B ファイル名のうち、拡張子部分の直前まで（の文字）を取得
						// 例）kase_map_l.gif　→　kase_map_l
						filename = temp_filename.substr(0, temp_filename.indexOf('.'));	
						
						// C Bにポップアップさせる画像ファイルの識別文字（変数dist）が
						// 含まれていれば、その直前までを取得
						// 例）kase_map_l　→　kase_map
						if(filename.match(dist) == dist){ //Bfilenameにdistが含まれているかどうか
							title = filename.substr(0, filename.indexOf(dist)); //含まれる場合、distの直前までを取得
							}else{
							title = filename; //含まれない場合はfilename
						}
				}else{
				title = name; //urlではない場合
			}
		}else{
		title = title; //titleを指定した場合
	}
	
	// 長さと高さ
	// w,hの指定が無ければそれぞれ初期設定のwidth,heightで表示
	if ((w == "")||(w == null)){
		w = width;	
	}	
	if ((h == "")||(h == null)){
		h = height;	
	}	
	
	// 画像をポップアップ
	newWin = window.open(img,"openImg","width=" + w + "," + "height=" + h);
	
	// 新しいウィンドウへの書き出し
	newWin.document.open();
	newWin.document.writeln('<?xml version="1.0" encoding="' + enc + '"?>');
	newWin.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
	newWin.document.writeln('<html>');
	newWin.document.writeln('<head>');
	newWin.document.writeln('<title>- ' + title + ' -</title>');
	newWin.document.writeln('<meta http-equiv="Content-Type" content="text/html; charset=' + enc + '" />');
	newWin.document.writeln('<meta http-equiv="content-style-type" content="text/css" />');
	newWin.document.writeln('<style type="text/css">');
	newWin.document.writeln('body{margin:0px;padding:0px;}');
	newWin.document.writeln('img{border:0px;}');
	newWin.document.writeln('</style>');
	newWin.document.writeln('</head>');
	newWin.document.writeln('<body>');
	newWin.document.write('<a href="javascript:void(0);" onclick="self.window.close()">');
	newWin.document.write('<img src="../common/js/' + img + '" width="' + w + '" height="' + h + '" alt="' + title + '" />');
	newWin.document.writeln('</a>');
	newWin.document.writeln('</body>');
	newWin.document.writeln('</html>');
	newWin.document.close();
}



/* -----------------------------------------------------
mapをポップアップ
<a href="javascript:void(0)" onclick="openMap()" onkeypress="openMap()">
----------------------------------------------------- */
function openMap(no){
	// mapファイルを指定
	/*var mapfile;
	body_id = document.getElementsByTagName('body')[0].id;
	dir_num = body_id.substr(2,99);
	mapfile = 'map/m_' + dir_num + '.htm';*/
	
	//mapファイルをポップアップ
	var page = "../../list/map.php?no=" + no;
	mapWin = window.open(page,'map','width=440,height=620,scrollbars=yes');
}



/* -----------------------------------------------------
フォーカスが当たった時・外れた時にフォームの色を変化
<input type="text" name="" size="" onfocus="activeForm(this)" onblur="defaultForm(this)" />
----------------------------------------------------- */
function activeForm(id){
	id.style.backgroundColor = '#e6e6e6';
	id.style.borderTopColor = '#333';
	id.style.borderLeftColor = '#333';
	id.style.borderBottomColor = '#999';
	id.style.borderRightColor = '#999';
}

function defaultForm(id){
	id.style.backgroundColor = '#f6f6f6';
	id.style.borderTopColor = '#666';
	id.style.borderLeftColor = '#666';
	id.style.borderBottomColor = '#ccc';
	id.style.borderRightColor = '#ccc';
}



/* -----------------------------------------------------
お問い合わせフォームにて希望連絡開始時間が希望連絡終了時間よりも前だったら警告
----------------------------------------------------- */
function time(){
 var timeStart = document.getElementById('renraku1').value;
	var timeEnd = document.getElementById('renraku2').value;
	var theStart = document.readType.renraku1.selectedIndex;
	var theEnd = document.readType.renraku2.selectedIndex;
	var difference = (timeStart - timeEnd);
	if((theStart == null)||(theStart == '0')){
			'';	
		}else if((theEnd == null)||(theEnd == '0')){
			'';	
		}else if(difference < 0){
			'';	
		}else{
			window.alert('希望連絡時間が正しくありません');
	}
}



/* -----------------------------------------------------
前のページへ戻る
onclick="pageBack()" onkeypress="pageBack()"
----------------------------------------------------- */
function pageBack(){
		history.back();
}
	
	
	
/* end of this file */
