﻿//                                                        //
//           toyotetsu.jp Javascript関数定義              //
//                        [共通]                          //
//                                                        //
//  Copyright 2008 豊鉄バス株式会社 All rights reserved.  //
//                                                        //


// ----- 送信・変更時の確認 -----
var send_flag = 0;

function check_submit() {
  if ( send_flag == 1 ) {
    alert('ただいま送信中です。\n「OK」ボタンをクリックしてお待ちください。');
    return false;
  }

  send_flag = 1;

  return true;
}

// ----- 検索時の入力フォームチェック -----
function check_search_submit() {
  if ( document.search_keyword_form.Sword.value == '' ) {
    alert('検索キーワードを入力してください。');
    return false;
  }

  send_flag = 1;

  return true;
}

// ----- 削除の確認 -----
function check_delete(url,name) {
  if ( confirm('「 ' + name + ' 」を削除してもよろしいですか？') == false ) {
    return false;
  }
  location.href = url;
}

// ----- 路線地図検索 -----
function search_station(type,name) {
  location.href = './?Mode=searchStation&Type=' + type + '&name=' + encodeURI(name);
}

// ----- カレンダーの表示 -----
function view_calendar(idno) {
  var ym = '';
  if ( $( 'Date' + idno ).value ) ym = $( 'Date' + idno ).value.substring(0,7);

  $( 'calendar_area' + idno ).innerHTML = '';

  change_calendar(ym,idno);
  change_visibility('calendar_area' + idno );
}

// ----- カレンダーの切替え -----
function change_calendar(ym,idno) {
  new Ajax.Updater(
    'calendar_area' + idno ,
    './calendar.cgi' ,
    { method     : 'post' ,
      parameters : 'ym=' + ym + '&idno=' + idno,
      onFailure  : function() {
        $( 'calendar_area' + idno ).innerHTML = '<div class="error_msg_title">通信エラーが発生しました。</div>';
      }
    }
  );
}

// ----- 日付のセット -----
function set_date(date_view,date,idno) {
  $( 'Date' + idno ).value = date;
  $( 'Date_View' + idno ).value = date_view;
  change_visibility('calendar_area' + idno);
}

// ----- 時刻選択欄の表示変更 -----
function change_timeform() {
  if ( document.input_form.dtype[0].checked || document.input_form.dtype[1].checked ) {
    document.input_form.hour.disabled = false;
    document.input_form.min.disabled = false;
  }
  else if ( document.input_form.dtype[2].checked || document.input_form.dtype[3].checked ) {
    document.input_form.hour.disabled = true;
    document.input_form.min.disabled = true;
  }
}



// ----- オブジェクトの取得 -----
function get_object(id) {
  if (document.getElementById) {
    return document.getElementById(id);
  }
  else if (document.all) {
    return document.all(id);
  }
  return null;
}

// ----- 背景色の変更 -----
function change_bgcolor(obj,bgcolor){
  if(obj) {
    if (obj.style) obj.style.backgroundColor = bgcolor;
  }
}

// ----- クッキーの読み込み -----
function get_cookie(key){
  tmp = document.cookie+";";
  tmp1 = tmp.indexOf(key, 0);
  if( tmp1 != -1 ){
    tmp = tmp.substring( tmp1, tmp.length );
    start = tmp.indexOf("=", 0 ) + 1;
    end = tmp.indexOf( ";", start );
    return( unescape( tmp.substring( start, end )));
  }
  return("");
}


// ----- 別ウィンドウの表示 -----
function openwin(url,width,height,target) {
  if (url != '') {
//    var tg = ( target == '' ) ? '_blank' : target;
    var x = parseInt( window.screen.width/2-width/2 );
    var y = parseInt( window.screen.height/2-height/2 );
    window.open(url,target,"toolbar=no,location=yes,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width="+width+",height="+height+",left="+x+",top="+y+",screenX="+x+",screenY="+y);
  }
}

// ----- 指定エリアの表示・非表示(display) -----
function change_display(id) {
  obj = get_object(id);
  if ( obj ) {
    if ( obj.style.display == 'none' || obj.style.display == '' ) {
      obj.style.display = 'block';
    }
    else {
      obj.style.display = 'none';
    }
  }
}

// ----- 指定エリアの表示・非表示(visibility) -----
function change_visibility(id) {
  obj = get_object(id);
  if ( obj ) {
    if ( obj.style.visibility == 'hidden' || obj.style.visibility == '' ) {
      obj.style.visibility = 'visible';
    }
    else {
      obj.style.visibility = 'hidden';
    }
  }
}


// ----- その他 -----
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}



// ---------- End of File ----------
