// Basic JavaScript

/* OS振分け */
if (navigator.platform.indexOf('Mac') > -1) 
{
	//mac users
	document.write('<link href="http://www.i-trunk.jp/css/mac.css" rel="stylesheet" type="text/css">');
}
else
{
	//windows or others
	document.write('<link href="http://www.i-trunk.jp/css/win.css" rel="stylesheet" type="text/css">');
}


/* マップフラッシュ呼び出し */

function RunMap(){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="460" height="270">\n');
	document.write('<param name=movie value="http://www.i-trunk.jp/img/map.swf">\n');
	document.write('<param name=quality value=high>\n');
	document.write('<param name="LOOP" value="false">\n');
	document.write('<param name="BGCOLOR" value="#FFFFFF">\n');
	document.write('<embed src="http://www.i-trunk.jp/img/map.swf" quality=high pluginspage="http://www.macromedia.com/jp/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="460" height="270" loop="false" bgcolor="#FFFFFF">\n');
	document.write('</embed>\n');
	document.write('</object>\n');
}

function RunMapTest(){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="460" height="270">\n');
	document.write('<param name=movie value="http://www.i-trunk.jp/img/map.swf">\n');
	document.write('<param name=quality value=high>\n');
	document.write('<param name="LOOP" value="false">\n');
	document.write('<param name="BGCOLOR" value="#FFFFFF">\n');
	document.write('<embed src="http://www.i-trunk.jp/img/map.swf" quality=high pluginspage="http://www.macromedia.com/jp/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="460" height="270" loop="false" bgcolor="#FFFFFF">\n');
	document.write('</embed>\n');
	document.write('</object>\n');
}


function RunMapHiroshima(){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="460" height="270">\n');
	document.write('<param name=movie value="http://www.i-trunk.jp/img/hiroshima.swf">\n');
	document.write('<param name=quality value=high>\n');
	document.write('<param name="LOOP" value="false">\n');
	document.write('<param name="BGCOLOR" value="#FFFFFF">\n');
	document.write('<embed src="http://www.i-trunk.jp/img/hiroshima.swf" quality=high pluginspage="http://www.macromedia.com/jp/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="460" height="270" loop="false" bgcolor="#FFFFFF">\n');
	document.write('</embed>\n');
	document.write('</object>\n');
}

function RunMapMihara(){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="460" height="270">\n');
	document.write('<param name=movie value="http://www.i-trunk.jp/img/mihara.swf">\n');
	document.write('<param name=quality value=high>\n');
	document.write('<param name="LOOP" value="false">\n');
	document.write('<param name="BGCOLOR" value="#FFFFFF">\n');
	document.write('<embed src="http://www.i-trunk.jp/img/mihara.swf" quality=high pluginspage="http://www.macromedia.com/jp/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="460" height="270" loop="false" bgcolor="#FFFFFF">\n');
	document.write('</embed>\n');
	document.write('</object>\n');
}

function RunMapOnomichi(){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="460" height="270">\n');
	document.write('<param name=movie value="http://www.i-trunk.jp/img/onomichi.swf">\n');
	document.write('<param name=quality value=high>\n');
	document.write('<param name="LOOP" value="false">\n');
	document.write('<param name="BGCOLOR" value="#FFFFFF">\n');
	document.write('<embed src="http://www.i-trunk.jp/img/onomichi.swf" quality=high pluginspage="http://www.macromedia.com/jp/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="460" height="270" loop="false" bgcolor="#FFFFFF">\n');
	document.write('</embed>\n');
	document.write('</object>\n');
}

/* センターオープンウィンドウ */
function center_openBrWindow(theURL,winName,wx,wy,features) {
  x = (screen.width  - wx) / 2;
  y = (screen.height - wy) / 2;
  window.open(theURL,winName,"left="+x+",top="+y+",width="+wx+",height="+wy,features);
}


/* アドミン系に使うオープンウィンドウ */

function openSimpleWindow(wnd, url, left, top, width, height) {

	myWindow = window.open(url, wnd, 'resizable=yes,scrollbars=YES,menubar=no,toolbar=no,status=yes,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top);
	myWindow.focus();
}


/* らくらくリクエストの選択フィールド消去 */
function clearValue() {
	for (i = 0; i < clearValue.arguments.length; i++) {
		if (clearValue.arguments[i] && clearValue.arguments[i].value) {
			clearValue.arguments[i].value = "";
		}
	}
}


/* DWのロールオーバー */
function MM_swapImgRestore() {
  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_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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];}
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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) { //v3.0
  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); 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];}
}





/* クイック検索と詳細検索のセレクトテキスト排他 */
function ch_jyuusyo(){
	document.option_search.rosen_id1.value = "";
	document.option_search.eki_id1.value = "";
	document.option_search.terminal_eki.value = "";
}

function ch_rosen(){
	document.option_search.jyuusyo.value = "";
	document.option_search.eki_id1.value = "";
	document.option_search.terminal_eki.value = "";
}

function ch_eki(){
	document.option_search.rosen_id1.value = "";
	document.option_search.jyuusyo.value = "";
	document.option_search.terminal_eki.value = "";
}

function ch_terminal(){
	document.option_search.rosen_id1.value = "";
	document.option_search.jyuusyo.value = "";
	document.option_search.eki_id1.value = "";
}


/* お問合せフォーム必須項目チェック */

function contact_check(){
var	err_cnt=0;
var	msg = "";

if (document.contact.mail.value==""){
	msg = "『Eメール』\n"+ msg;
	err_cnt = err_cnt + 1;
	document.contact.mail.focus();
}

if (document.contact.toi_name.value==""){
	msg = "『氏名』\n"+ msg;
	err_cnt = err_cnt + 1;
	document.contact.toi_name.focus();
}

if (err_cnt==0){
	document.contact.submit();
}else{
	msg += "\n上記 " + err_cnt + " 項目が未入力です。\nこの項目は必ず入力をお願いします。";
	alert(msg);
	return;
	}
}

/* 借り上げフォーム必須項目チェック */

function tochi_check(){
var	err_cnt=0;
var	msg = "";

if (document.tochi.email.value==""){
	msg = "『EMAIL』\n"+ msg;
	err_cnt = err_cnt + 1;
	document.tochi.email.focus();
}

if (document.tochi.your_name.value==""){
	msg = "『ご氏名』\n"+ msg;
	err_cnt = err_cnt + 1;
	document.tochi.your_name.focus();
}

if (document.tochi.area.value==""){
	msg = "『土地エリア』\n"+ msg;
	err_cnt = err_cnt + 1;
	document.tochi.area.focus();
}

if (err_cnt==0){
	document.tochi.submit();
}else{
	msg += "\n上記 " + err_cnt + " 項目が未入力です。\nこの項目は必ず入力をお願いします。";
	alert(msg);
	return;
	}
}

/* ご意見フォーム必須項目チェック */

function opinion_check(){
var	err_cnt=0;
var	msg = "";


if (document.opinion.contena.checked==false && document.opinion.trunkroom.checked==false && document.opinion.bike_box.checked==false){
	msg = "『ボックスタイプ』\n"+ msg;
	err_cnt = err_cnt + 1;
}

if (document.opinion.area.value==""){
	msg = "『希望エリア』\n"+ msg;
	err_cnt = err_cnt + 1;
	document.opinion.area.focus();
}

if (err_cnt==0){
	document.opinion.submit();
}else{
	msg += "\n上記 " + err_cnt + " 項目が未入力です。\nこの項目は必ず入力をお願いします。";
	alert(msg);
	return;
	}
}


/* リクエストフォーム必須項目チェック */

function request_check(){
var	err_cnt=0;
var	msg = "";

if (document.request_input.email_pc.value=="" && document.request_input.email_mobile.value=="" && document.request_input.tel1.value=="" && document.request_input.tel2.value=="" && document.request_input.fax1.value=="" && document.request_input.fax2.value==""){
	msg = "『連絡先』\n"+ msg;
	err_cnt = err_cnt + 1;
	document.request_input.email_pc.focus();
}

if (document.request_input.customer_name.value==""){
	msg = "『氏名』\n"+ msg;
	err_cnt = err_cnt + 1;
	document.request_input.customer_name.focus();
}

if (document.request_input.nyuukyo_kiboubi_y.value=="" || document.request_input.nyuukyo_kiboubi_m.value=="" || document.request_input.nyuukyo_kiboubi_d.value==""){
	msg = "『入居希望日』\n"+ msg;
	err_cnt = err_cnt + 1;
	document.request_input.nyuukyo_kiboubi_y.focus();
}

if (document.request_input.kibou_area_text.value==""){
	msg = "『エリア1』\n"+ msg;
	err_cnt = err_cnt + 1;
	document.request_input.kibou_area_text.focus();
}

if (err_cnt==0){
	document.request_input.submit();
}else{
	msg += "\n上記 " + err_cnt + " 項目が未入力です。\nこの項目は必ず入力をお願いします。";
	alert(msg);
	return;
	}
}


/* 反響必須項目チェック */
//============================================================================//
//	日付の形式をチェックする
//============================================================================//
//	引数
//		y       年
//		m       月
//		d       日
//============================================================================//
function checkDate(y, m, d) {
	if ((y.value == "") || (m.value == "") || (d.value == "")) {
		return true;
	}
	else {
		year = "0000" + y.value;
		month = "00" + m.value;
		date = "00" + d.value;
		
		var year1 =  year.substr(year.length - 4, 4);
		var month1 = month.substr(month.length - 2, 2);
		var date1 = date.substr(date.length - 2, 2);
		
		var checkdate = new Date();
		
		checkdate.setDate(1);
		checkdate.setFullYear(year1);
		checkdate.setMonth(month1 - 1);
		checkdate.setDate(date1);
		
		var year2 = checkdate.getFullYear();
		var month2 = checkdate.getMonth() + 1;
		var date2 = checkdate.getDate();
		
		if (month2 < 10) month2 = "0" + month2;  
		if (date2 < 10) date2 = "0" + date2; 
		
		if ("" + year1 + month1 + date1 == "" + year2 + month2 + date2) { 
			y.value = year1; 
			m.value = month1;
			d.value = date1;
			return true;
		}
		else {
			alert("日付が正しくありません");
			d.focus();
			return false;
		}
	}
}

function mousikomi_check(){ 
			
			if (checkDate(document.mousikomi.nyuukyo_kiboubi_y, document.mousikomi.nyuukyo_kiboubi_m, document.mousikomi.nyuukyo_kiboubi_d)==false) return;

			if (checkDate(document.mousikomi.taishutsu_kiboubi_y, document.mousikomi.taishutsu_kiboubi_m, document.mousikomi.taishutsu_kiboubi_d)==false) return;

err_cnt=0;
msg="";
		

		if (document.mousikomi.nyuukyo_kiboubi_y.value!="" && document.mousikomi.nyuukyo_kiboubi_m.value!="" && document.mousikomi.nyuukyo_kiboubi_d.value!="" && document.mousikomi.taishutsu_kiboubi_y.value!="" && document.mousikomi.taishutsu_kiboubi_m.value!="" && document.mousikomi.taishutsu_kiboubi_d.value!=""){

		days = document.mousikomi.nyuukyo_kiboubi_y.value + document.mousikomi.nyuukyo_kiboubi_m.value + document.mousikomi.nyuukyo_kiboubi_d.value;

		dayf = document.mousikomi.taishutsu_kiboubi_y.value + document.mousikomi.taishutsu_kiboubi_m.value + document.mousikomi.taishutsu_kiboubi_d.value;

		if (days > dayf){

			msg = "『期間の日付が不正です』\n"+ msg;

			err_cnt = err_cnt + 1;

			document.mousikomi.nyuukyo_kiboubi_y.focus();

			alert(msg);

			return;

		}

	}

	if (document.mousikomi.tel1.value=="" && document.mousikomi.tel2.value=="" && document.mousikomi.email.value==""){
		msg = "『連絡先』\n"+ msg;
		err_cnt = err_cnt + 1;
		document.mousikomi.tel1.focus();
	}

	if (document.mousikomi.customer_name.value==""){
		msg = "『氏名』\n"+ msg;
		err_cnt = err_cnt + 1;
		document.mousikomi.customer_name.focus();
	}

	if (document.mousikomi.taishutsu_kiboubi_y.value=="" || document.mousikomi.taishutsu_kiboubi_m.value=="" || document.mousikomi.taishutsu_kiboubi_d.value==""){
		msg = "『退去希望日』\n"+ msg;
		err_cnt = err_cnt + 1;
		document.mousikomi.taishutsu_kiboubi_y.focus();
	}

	if (document.mousikomi.nyuukyo_kiboubi_y.value=="" || document.mousikomi.nyuukyo_kiboubi_m.value=="" || document.mousikomi.nyuukyo_kiboubi_d.value==""){
		msg = "『入居希望日』\n"+ msg;
		err_cnt = err_cnt + 1;
		document.mousikomi.nyuukyo_kiboubi_y.focus();
	}

	if (err_cnt==0){
		document.mousikomi.submit();
	}else{
		msg += "\n上記 " + err_cnt + " 項目が未入力です。\nこの項目は必ず入力をお願いします。";
		alert(msg);
		return;
	}
}


/* 年月日フィールドタイプチェック　*/

function singlebyte(s,file01) {
   cnst="1234567890";
   for (i=0;i<s.length;i++) {
      sw="ng";
      for (j=0;j<cnst.length;j++) {
         if (cnst.charAt(j)==(s.charAt(i))) sw="ok";
      }
      if (sw=="ng") {
         alert("半角数字以外の文字が入力されています。");
         file01.focus();
         break;
      }
   }
}


/* 電話番号フィールドタイプチェック　*/

function singlebyte2(s,file01) {
   cnst="1234567890-";
   for (i=0;i<s.length;i++) {
      sw="ng";
      for (j=0;j<cnst.length;j++) {
         if (cnst.charAt(j)==(s.charAt(i))) sw="ok";
      }
      if (sw=="ng") {
         alert("使用できない文字があります。");
         file01.focus();
         break;
      }
   }
}

/*その他*/
	//
	// rnd_graphics1 () : ランダムに違う画像を表示（場所１）
	//
	function rnd_graphics1 () {
		var	rnd = 0;		// 乱数格納用
		//////////////////////////////////////////////////////////
		// ***** ここからユーザーの設定箇所 (1) *****
		//
		// １． 画像データ数の設定
		//      graphic_dat_max に使用するデータの数を入力します。
		//
		var	graphic_dat_max = 3;
		//
		// ***** ここまでユーザーの設定箇所 (1) *****
		//////////////////////////////////////////////////////////
		var	graphic_dat	= new Array(graphic_dat_max);
		var	graphic_width	= new Array(graphic_dat_max);
		var	graphic_height	= new Array(graphic_dat_max);
		//////////////////////////////////////////////////////////
		// ***** ここからユーザーの設定箇所 (2) *****
		//
		// １． 画像ファイル設定
		//      画像ファイルを設定します。
		//          graphic_dat[?]	: 画像ファイル名
		//          graphic_width[?]	: 画像の幅   (単位 : dot)
		//          graphic_height[?]	: 画像の高さ (単位 : dot)
		//      をそれぞれ記入します。
		//      [?] の ? には 0 〜 (graphic_dat_max - 1) 
		//      までの数値が入ります。例えば graphic_dat_max = 5
		//      なら、 [0] 〜 [4] までの変数を設定します。
		//
		// 1 つ目
		graphic_dat[0]		= "img/randam1_1.jpg";
		graphic_width[0]	= "206";
		graphic_height[0]	= "104";
		// 2 つ目
		graphic_dat[1]		= "img/randam1_2.jpg";
		graphic_width[1]	= "206";
		graphic_height[1]	= "104";
		// 3 つ目
		graphic_dat[2]		= "img/randam1_3.jpg";
		graphic_width[2]	= "206";
		graphic_height[2]	= "104";
		//
		// ***** ここまでユーザーの設定箇所 (2) *****
		//////////////////////////////////////////////////////////
		//
		// 乱数発生
		//
		rnd = Math.floor(Math.random() * graphic_dat_max);
		//
		// 描画処理
		//
		if ((graphic_width[rnd] == "") || (graphic_height[rnd] == "")) {
			document.write('<IMG SRC="' + graphic_dat[rnd] + '">');
		}
		else if (graphic_dat[rnd] != "") {
			document.write('<IMG SRC="' + graphic_dat[rnd] + '" WIDTH=' + graphic_width[rnd] + " HEIGHT=" + graphic_height[rnd] + ">");
		}
	}


	//
	// rnd_graphics2 () : ランダムに違う画像を表示（場所２）
	//
	function rnd_graphics2 () {
		var	rnd = 0;		// 乱数格納用
		//////////////////////////////////////////////////////////
		// ***** ここからユーザーの設定箇所 (1) *****
		//
		// １． 画像データ数の設定
		//      graphic_dat_max に使用するデータの数を入力します。
		//
		var	graphic_dat_max = 3;
		//
		// ***** ここまでユーザーの設定箇所 (1) *****
		//////////////////////////////////////////////////////////
		var	graphic_dat	= new Array(graphic_dat_max);
		var	graphic_width	= new Array(graphic_dat_max);
		var	graphic_height	= new Array(graphic_dat_max);
		//////////////////////////////////////////////////////////
		// ***** ここからユーザーの設定箇所 (2) *****
		//
		// １． 画像ファイル設定
		//      画像ファイルを設定します。
		//          graphic_dat[?]	: 画像ファイル名
		//          graphic_width[?]	: 画像の幅   (単位 : dot)
		//          graphic_height[?]	: 画像の高さ (単位 : dot)
		//      をそれぞれ記入します。
		//      [?] の ? には 0 〜 (graphic_dat_max - 1) 
		//      までの数値が入ります。例えば graphic_dat_max = 5
		//      なら、 [0] 〜 [4] までの変数を設定します。
		//
		// 1 つ目
		graphic_dat[0]		= "img/randam2_1.jpg";
		graphic_width[0]	= "206";
		graphic_height[0]	= "104";
		// 2 つ目
		graphic_dat[1]		= "img/randam2_2.jpg";
		graphic_width[1]	= "206";
		graphic_height[1]	= "104";
		// 3 つ目
		graphic_dat[2]		= "img/randam2_3.jpg";
		graphic_width[2]	= "206";
		graphic_height[2]	= "104";
		//
		// ***** ここまでユーザーの設定箇所 (2) *****
		//////////////////////////////////////////////////////////
		//
		// 乱数発生
		//
		rnd = Math.floor(Math.random() * graphic_dat_max);
		//
		// 描画処理
		//
		if ((graphic_width[rnd] == "") || (graphic_height[rnd] == "")) {
			document.write('<IMG SRC="' + graphic_dat[rnd] + '">');
		}
		else if (graphic_dat[rnd] != "") {
			document.write('<IMG SRC="' + graphic_dat[rnd] + '" WIDTH=' + graphic_width[rnd] + " HEIGHT=" + graphic_height[rnd] + ">");
		}
	}



