// <![CDATA[
/**
 * °Ë»ö ÀÏÀÚ È®ÀÎ
 *
 * include: lib.date.js
 */

var rsvConfirm = Class.create({
  initialize: function(options)
  {
    this.options = {
      frmID:  'frmRsv'
      , syy:  'syy'
      , smm:  'smm'
      , sdd:  'sdd'
      , shh:  'shh'
      , sii:  'sii'
      , eyy:  'eyy'
      , emm:  'emm'
      , edd:  'edd'
      , ehh:  'ehh'
      , eii:  'eii'
      , stay: 'stay'
      , days: 'days'
      , hours:  'hours'
      , rsvSDate: new Date()
      , rsvEDate: new Date()
    }
    this.setOptions(options);
  }


  // setOption
  , setOptions: function(options)
  {
    Object.extend(this.options, options || {});
  }

  // ¸¶Áö¸· ÀÏÀÚ º¯°æ  
  , setLastDate: function(gubun)
  {
    var tmp   = null;
    var eleYY = eleMM = eleDD = null;
    var lastDay = 0;

    gubun = String(gubun).toUpperCase();

    if (gubun == 'START') {
      eleYY = !$(this.options.syy) ? null : $(this.options.syy);
      eleMM = !$(this.options.smm) ? null : $(this.options.smm);
      eleDD = !$(this.options.sdd) ? null : $(this.options.sdd);
    }
    else if (gubun == 'END') {
      eleYY = !$(this.options.eyy) ? null : $(this.options.eyy);
      eleMM = !$(this.options.emm) ? null : $(this.options.emm);
      eleDD = !$(this.options.edd) ? null : $(this.options.edd);
    } // end if

    if (!eleYY || !eleMM || !eleDD) {
      this._initPeriod();
      return false;
    } // end if

    lastDay = getLastDay(new Date($F(eleYY), $F(eleMM)-1, $F(eleDD)));  // lib.date.js: getLastDay()

    if (eleDD.length > lastDay) { // Á¦°Å
      for (var i=eleDD.length-1; i>=lastDay; i--) {
        eleDD.options[i] = null;
      }
    }
    else if (eleDD.length < lastDay) {  // Ãß°¡
      for (var i=eleDD.length; i<lastDay; i++) {
        eleDD.options[i] = new Option(i+1, i+1);
      }
    } // end if

    this.getPeriod();
  }


  // ¿¹¾à°¡´É ±â°£ È®ÀÎ
  , chkDate: function()
  {
    var errMsg = null;
    var sdate = new Date($F(this.options.syy),$F(this.options.smm)-1,$F(this.options.sdd));

    if (this.options.rsvSDate > sdate || this.options.rsvEDate < sdate) {
      // lib.date.js: getDateFmt()
      alert('¿¹¾à °¡´É ±â°£À» ¹þ¾î³³´Ï´Ù.\n\n'
          + '¿¹¾à °¡´É ±â°£:\n'
          + getDateFmt(this.options.rsvSDate, 'Y³â m¿ù dÀÏºÎÅÍ ')
          + getDateFmt(this.options.rsvEDate, 'Y³â m¿ù dÀÏ±îÁö '));

      return false;
    } // end if

    return true;
  }


  // ±â°£
  , _initPeriod: function(s,d,h) {
    if ($(this.options.stay) != null) {
        $(this.options.stay).value = (typeof s == 'undefined' ? '' : s);
    } // end if

    if ($(this.options.days) != null) {
        $(this.options.days).value = (typeof d == 'undefined' ? '' : d);
    } // end if

    if ($(this.options.hours) != null) {
        $(this.options.hours).value = (typeof h == 'undefined' ? '' : h);
    } // end if
  }
  , getPeriod: function() {
    if (!$(this.options.syy) || !$(this.options.smm) || !$(this.options.sdd)
      || !$(this.options.eyy) || !$(this.options.emm) || !$(this.options.edd)
    ) {
      stay  = '';
      days  = '';
      hours = '';

      this._initPeriod(stay, days, hours);

      return;
    } // end if

    var sdate = new Date($F(this.options.syy),$F(this.options.smm)-1,$F(this.options.sdd));
    var edate = new Date($F(this.options.eyy),$F(this.options.emm)-1,$F(this.options.edd));
    var stay, days, hours;

    if ($(this.options.shh) != null) {
      sdate.setHours($F(this.options.shh));
    } // end if
    if ($(this.options.ehh) != null) {
      edate.setHours($F(this.options.ehh));
    } // end if

    stay  = getDateDiff(sdate, edate, 'd');
    days  = stay + 1;
    hours = getDateDiff(sdate, edate, 'h') || '';

    if (stay === false) {
        stay  = '';
        days  = '';
        hours = '';
    }
    else {
        days = stay + 1;
    } // end if

    this._initPeriod(stay, days, hours);
  }

});


// ]]>