
$(function(){
  var Dialog = function() { this.init.apply(this, arguments); };
  Dialog.prototype = {
    type : '',
    buttons_close : $('a.close_confirmation'),
    button_yes : $('#confirmation_yes'),

    // 初期設定
    init : function(type) {
      this.type = type;
      $('#' + this.type).dialog({
        autoOpen: false,
        width: 420,
        //height: 151,
        modal: true
      });

      // 「はい」「いいえ」ボタン押下時
      var self = this;
      $('a.close_'+ this.type).click(function(){
        $('#'+ self.type).dialog('close');
      });
    },

    setMessage : function(msg){
      $('#'+ this.type+'_description').html(msg);
    },

    open : function(msg){
      if(msg)$('#'+ this.type+'_description').html(msg);
      $('#' + this.type).dialog('open');
    },

    setLink : function(text, url, target){
      if(text)$('#'+ this.type+'_linktext').text(text);
      if(url)$('#'+ this.type+'_linkurl').attr('href', url);
      if(target)$('#'+ this.type+'_linkurl').attr('target', target);
    },

    close : function(){
      $('#' + this.type).dialog('close');
    }
  }

  // notice
  html = '';
  html += '<div id="notice" >';
  html += ' <div class="ui-dialog-content-body">';
  html += '   <div class="ui-dialog-content-text"><p class="font_siz_14 tx_align_c"><strong id="notice_description"></strong></p></div>';
  html += '		<div class="btn_Cbox_03" style="position:relative">';
  html += '			<div class="btn_dialogue_close on_btndialogue flo_l" style="position:relative;left:25%"><a id="notice_yes" href="javascript:void(0);" class="close_notice"><strong>閉じる</strong></a></div>';
  html += '		</div>';
  html += ' </div>';
  html += ' <div class="ui-dialog-btm"></div>';
  html += '</div>';
  $(html).appendTo("body");
  var Notice = function() {};
  Notice.prototype = new Dialog('notice');

  // noticewithlink
  html = '';
  html += '<div id="noticewithlink">';
  html += ' <div class="ui-dialog-content-body">';
  html += '   <div class="ui-dialog-content-text"><p class="font_siz_14 tx_align_c"><strong id="noticewithlink_description"></strong></p></div>';
  html += '		<div class="btn_Cbox_06" style="position:relative">';
  html += '         <div class="btn_register_03 on_btndefault flo_l btn_mrgr"><a href="#" id="noticewithlink_linkurl"><strong><span class="fo_size" id="noticewithlink_linktext"></span></strong></a></div>';
  html += '			<div class="btn_cancel_01 flo_l on_btndefault"><a href="javascript:void(0);" class="close_noticewithlink"><strong>閉じる</strong></a></div>';
  html += '		</div>';
  html += ' </div>';
  html += ' <div class="ui-dialog-btm"></div>';
  html += '</div>';
  $(html).appendTo("body");
  var NoticeWithLink = function() {};
  NoticeWithLink.prototype = new Dialog('noticewithlink');

  // confirmation
  html = '';
  html += '<div id="confirmation" >';
  html += ' <div class="ui-dialog-content-body">';
  html += '   <div class="ui-dialog-content-text"><p class="font_siz_14 tx_align_c"><strong id="confirmation_description"></strong></p></div>';
  html += '		<div class="btn_Cbox_03">';
  html += '			<div class="btn_pop_question on_btndefault flo_l btn_mrgr"><a id="confirmation_yes" href="javascript:void(0);" class="close_confirmation"><strong>はい</strong></a></div>';
  html += '     <div class="btn_home on_btndefault flo_l"><a href="javascript:void(0);" class="close_confirmation"><strong>いいえ</strong></a></div>';
  html += '		</div>';
  html += ' </div>';
  html += ' <div class="ui-dialog-btm"></div>';
  html += '</div>';
  $(html).appendTo("body");

  var Confirm = function() {};
  Confirm.prototype = new Dialog('confirmation');
  Confirm.prototype.onYesClicked = function(run){
      var self = this;
      $('a#confirmation_yes', '#confirmation').unbind('click');
      $('a#confirmation_yes', '#confirmation').click(function(){
        self.close();
        return run();
      });
  };

  // 確認ダイアログをJQueryのプロトタイプに配置
  $.fn.okwave.ui.notice = new Notice();
  $.fn.okwave.ui.noticewithlink = new NoticeWithLink();
  $.fn.okwave.ui.confirm = new Confirm();
});



