﻿/*                                                             */
/*               刈谷市観光協会    WEBシステム                 */
/*                                                             */
/*                        公開ページ                           */
/*                 Javascript関数定義 [共通]                   */
/*                                                             */
/*         2011 (c) e-pokke Inc.  All rights reserved.         */
/*                                                             */


function init_page(type) {
  var fs = get_cookie('fontsize');
  if ( fs == 'large' ) {
    font_large();
  }
  else if ( fs == 'middle' ) {
    font_middle();
  }
  else if ( fs == 'small' ) {
    font_small();
  }

  if (type != '' && type > 0) {
    view_event_calendar(type,'');
  }
}

// ----- 文字サイズの変更 -----
function font_large() {
  document.body.style.fontSize = '120%';
  $('lf').style.backgroundImage = 'url(/imgs/large_on.gif)';
  $('mf').style.backgroundImage = 'url(/imgs/medium.gif)';
  $('sf').style.backgroundImage = 'url(/imgs/small.gif)';
  set_ookie('fontsize', 'large');
}

function font_middle() {
  document.body.style.fontSize = '100%';
  $('lf').style.backgroundImage = 'url(/imgs/large.gif)';
  $('mf').style.backgroundImage = 'url(/imgs/medium_on.gif)';
  $('sf').style.backgroundImage = 'url(/imgs/small.gif)';
  set_ookie('fontsize', 'middle');
}

function font_small() {
  document.body.style.fontSize = '80%';
  $('lf').style.backgroundImage = 'url(/imgs/large.gif)';
  $('mf').style.backgroundImage = 'url(/imgs/medium.gif)';
  $('sf').style.backgroundImage = 'url(/imgs/small_on.gif)';
  set_ookie('fontsize', 'small');
}


// ----- クッキーの読み込み -----
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 set_ookie(key, val, tmp) {
  tmp = key + "=" + escape(val) + "; ";
  tmp += "path=/; ";
  tmp += "expires=Tue, 31-Dec-2030 23:59:59; ";
  document.cookie = tmp;
}

// ----- サイト内検索 -----
function check_site_search() {
  if (document.getElementById('search_input2').value == '') {
    alert('検索キーワードを入力してください');
    document.getElementById('search_input2').focus();
    return false;
  }
  return true;
}

// ----- 祭・イベントカレンダーの表示 -----
// type
//   1 : トップページ用(ピックアップとミニカレンダーが横並び)
//   2 : 詳細ページ用(ピックアップとミニカレンダーが縦並び)
//   3 : ミニカレンダーのみ
function view_event_calendar(type,ym) {
  var target = (type == 1) ? 'event_pickup' : 'event_calendar';
  new Ajax.Updater(
    target ,
    '/search/event_calendar.cgi' ,
    { method     : 'post' ,
      parameters : 'type=' + type + '&ym=' + ym,
      onFailure  : function() {
        $( target ).innerHTML = '<div class="error_msg_title">通信エラーが発生しました。</div>';
      }
    }
  );
}

// ----- アクセスログ記録 -----
function access () {
  var now = new Date();
  document.write("<img src='/search/access_log.cgi?url=" + document.URL + "&t=" + now.getTime() + "' width='1' height='1' border='0' />");
}

// ----- 広告バナーの表示 -----
function view_banner() {
  new Ajax.Updater(
    'ad' ,
    '/search/banner_view.cgi' ,
    { method     : 'post' ,
      parameters : 'Mode=view',
      onFailure  : function() {
        $( 'ad' ).innerHTML = '<div class="error_msg_title">通信エラーが発生しました。</div>';
      }
    }
  );
}

// ----- 刈谷素材集ポップアップの表示 -----
function view_sozai(code) {
  $('popup_bg').show();
  new Ajax.Updater(
    'popup_box' ,
    '/sozai/index.cgi' ,
    { method     : 'post' ,
      parameters : 'Mode=popupAjax&code=' + code,
      onFailure  : function() {
        $( 'popup_box' ).innerHTML = '<div class="error_msg_title">通信エラーが発生しました。</div>';
      } ,
      onComplete : function() {
        var isIE = (navigator.appName.toLowerCase().indexOf('internet explorer')+1?1:0);
        var isOpera = (navigator.userAgent.toLowerCase().indexOf('opera')+1?1:0);
        if (isOpera) isIE = false;
        var isSafari = (navigator.appVersion.toLowerCase().indexOf('safari')+1?1:0);
        var window_height;
        if (!isSafari && !isOpera) {
          window_height = document.documentElement.clientHeight || document.body.clientHeight || document.body.scrollHeight;
        }
        else {
          window_height = window.innerHeight;
        }
        var scroll_y = document.documentElement.scrollTop || document.body.scrollTop;
        var top = parseInt(window_height/2) - parseInt($('popup_box').getHeight()/2) + scroll_y;
        $('popup_box').style.top = top + 'px';
        Effect.Appear('popup_box', { duration: 0.2 } );
      }
    }
  );
}

// ----- ポップアップエリアの表示・非表示 -----
function show_popup() {
  $('popup_bg').show();
  $('popup_box').show();
}

function hide_popup() {
  $('popup_bg').hide();
  Effect.Fade('popup_box', { duration: 0.2 , from: 1 , to: 0 } );
}

// ----- 刈谷素材集 ダウンロード計測 -----
function download_sozai(code) {
  new Ajax.Updater(
    'download_done' ,
    '/sozai/index.cgi' ,
    { method     : 'post' ,
      parameters : 'Mode=downloadAjax&code=' + code,
      onFailure  : function() {
        $( 'download_done' ).innerHTML = '<div class="error_msg_title">通信エラーが発生しました。</div>';
      }
    }
  );
}

// ----- 周辺その他スポットの表示 -----
function view_near_spot(code,lat,lng) {
  new Ajax.Updater(
    'near_spot' ,
    '/search/near_spot.cgi' ,
    { method     : 'post' ,
      parameters : 'Mode=view&code=' + code + '&lat=' + lat + '&lng=' + lng,
      onFailure  : function() {
        $( 'near_spot' ).innerHTML = '<div class="error_msg_title">通信エラーが発生しました。</div>';
      }
    }
  );
}

// ---------- End of File ----------

