(function($) {
  $.facebox2 = function(data, klass) {
    $.facebox2.loading()

    if (data.ajax) fillFaceboxFromAjax(data.ajax)
    else if (data.image) fillFaceboxFromImage(data.image)
    else if (data.div) fillFaceboxFromHref(data.div)
    else if ($.isFunction(data)) data.call($)
    else $.facebox2.reveal(data, klass)
  }

  /*
   * Public, $.facebox2 methods
   */

  $.extend($.facebox2, {
    settings: {
      opacity      : 0.2,
      overlay      : true,
      loadingImage : '/images/facebox/loading.gif',
      closeImage   : '/images/facebox/closelabel.gif',
      imageTypes   : [ 'png', 'jpg', 'jpeg', 'gif' ],
      faceboxHtml  : '\
    <div id="facebox" style="display:none;"> \
      <div class="popup"> \
        <table> \
          <tbody> \
            <tr> \
              <td class="tl"/><td class="b"/><td class="tr"/> \
            </tr> \
            <tr> \
              <td class="b"/> \
              <td class="body"> \
                <div class="content"> \
                </div> \
              </td> \
              <td class="b"/> \
            </tr> \
            <tr> \
              <td class="bl"/><td class="b"/><td class="br"/> \
            </tr> \
          </tbody> \
        </table> \
      </div> \
    </div>'
    },

    loading: function() {
      init()
      if ($('#facebox .loading').length == 1) return true
      showOverlay()

      $('#facebox .content').empty()
      $('#facebox .body').children().hide().end().
        append('<div class="loading"><img src="'+$.facebox2.settings.loadingImage+'"/></div>')

      $('#facebox').css({
        top:	getPageScroll()[1] + (getPageHeight() / 10),
        left:	385.5
      }).show()

      $(document).bind('keydown.facebox', function(e) {
        if (e.keyCode == 27) $.facebox2.close()
        return true
      })
      $(document).trigger('loading.facebox')
    },

    reveal: function(data, klass) {
      $(document).trigger('beforeReveal.facebox')
      if (klass) $('#facebox .content').addClass(klass)
      $('#facebox .content').append(data)
      $('#facebox .loading').remove()
      $('#facebox .body').children().fadeIn('normal')
      $('#facebox').css('left', $(window).width() / 2 - ($('#facebox table').width() / 2))
      $(document).trigger('reveal.facebox').trigger('afterReveal.facebox')
    },

    close: function() {
      $(document).trigger('close.facebox')
      return false
    }
  })

  /*
   * Public, $.fn methods
   */

  $.fn.facebox = function(settings) {
    init(settings)

    function clickHandler() {
      $.facebox2.loading(true)

      // support for rel="facebox.inline_popup" syntax, to add a class
      // also supports deprecated "facebox[.inline_popup]" syntax
      var klass = this.rel.match(/facebox\[?\.(\w+)\]?/)
      if (klass) klass = klass[1]

      fillFaceboxFromHref(this.href, klass)
      return false
    }

    return this.click(clickHandler)
  }

  /*
   * Private methods
   */

  // called one time to setup facebox on this page
  function init(settings) {
    if ($.facebox2.settings.inited) return true
    else $.facebox2.settings.inited = true
    try{
		$(window).scroll(function () { 
		      $('#facebox').css({
		        top:	getPageScroll()[1] + (getPageHeight() / 10),
		        left:$(window).width() / 2 - ($('#facebox table').width() / 2)
		      })
	    });
    }catch(e){};
    $(document).trigger('init.facebox')
    makeCompatible()

    var imageTypes = $.facebox2.settings.imageTypes.join('|')
    $.facebox2.settings.imageTypesRegexp = new RegExp('\.' + imageTypes + '$', 'i')

    if (settings) $.extend($.facebox2.settings, settings)
    $('body').append($.facebox2.settings.faceboxHtml)

    var preload = [ new Image(), new Image() ]
    preload[0].src = $.facebox2.settings.closeImage
    preload[1].src = $.facebox2.settings.loadingImage

    $('#facebox').find('.b:first, .bl, .br, .tl, .tr').each(function() {
      preload.push(new Image())
      preload.slice(-1).src = $(this).css('background-image').replace(/url\((.+)\)/, '$1')
    })

    //$('#facebox .fb_close').click($.facebox2.close)
    $('#facebox .close_image').attr('src', $.facebox2.settings.closeImage)
  }
  
  // getPageScroll() by quirksmode.com
  function getPageScroll() {
    var xScroll, yScroll;
    if (self.pageYOffset) {
      yScroll = self.pageYOffset;
      xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
      yScroll = document.documentElement.scrollTop;
      xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
      yScroll = document.body.scrollTop;
      xScroll = document.body.scrollLeft;	
    }
    return new Array(xScroll,yScroll) 
  }

  // Adapted from getPageSize() by quirksmode.com
  function getPageHeight() {
    var windowHeight
    if (self.innerHeight) {	// all except Explorer
      windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
      windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
      windowHeight = document.body.clientHeight;
    }	
    return windowHeight
  }

  // Backwards compatibility
  function makeCompatible() {
    var $s = $.facebox2.settings

    $s.loadingImage = $s.loading_image || $s.loadingImage
    $s.closeImage = $s.close_image || $s.closeImage
    $s.imageTypes = $s.image_types || $s.imageTypes
    $s.faceboxHtml = $s.facebox_html || $s.faceboxHtml
  }

  // Figures out what you want to display and displays it
  // formats are:
  //     div: #id
  //   image: blah.extension
  //    ajax: anything else
  function fillFaceboxFromHref(href, klass) {
    // div
    if (href.match(/#/)) {
      var url    = window.location.href.split('#')[0]
      var target = href.replace(url,'')
      $.facebox2.reveal($(target).clone().show(), klass)

    // image
    } else if (href.match($.facebox2.settings.imageTypesRegexp)) {
      fillFaceboxFromImage(href, klass)
    // ajax
    } else {
      fillFaceboxFromAjax(href, klass)
    }
  }

  function fillFaceboxFromImage(href, klass) {
    var image = new Image()
    image.onload = function() {
      $.facebox2.reveal('<div class="image"><img src="' + image.src + '" /></div>', klass)
    }
    image.src = href
  }

  function fillFaceboxFromAjax(href, klass) {
    $.get(href, function(data) { $.facebox2.reveal(data, klass) })
  }

  function skipOverlay() {
    return $.facebox2.settings.overlay == false || $.facebox2.settings.opacity === null 
  }

  function showOverlay() {
    if (skipOverlay()) return

    if ($('facebox_overlay').length == 0) 
      $("body").append('<div id="facebox_overlay" class="facebox_hide"></div>')

    $('#facebox_overlay').hide().addClass("facebox_overlayBG")
      .css('opacity', $.facebox2.settings.opacity)
      .click(function() {
      	  // $(document).trigger('close.facebox');
         })
      .fadeIn(100)
    return false
  }

  function hideOverlay() {
    if (skipOverlay()) return

    $('#facebox_overlay').fadeOut(200, function(){
      $("#facebox_overlay").removeClass("facebox_overlayBG")
      $("#facebox_overlay").addClass("facebox_hide") 
      $("#facebox_overlay").remove()
    })
    
    return false
  }

  /*
   * Bindings
   */

  $(document).bind('close.facebox', function() {
    $(document).unbind('keydown.facebox')
    $('#facebox').fadeOut(function() {
      $('#facebox .content').removeClass().addClass('content')
      hideOverlay()
      $('#facebox .loading').remove()
    })
  })

})//(jQuery);

var IframeID_1;
function reply_txt(id,d_reply,comments_id)
{
    for(i=0;i<20;i++)
    {
        try
        {
            document.getElementById("re_"+i).innerHTML="";
            jQuery("#re_"+i).hide();
        }catch(err)
        {}
    }
    //document.getElementById("re_"+id).style.display="";
    jQuery('#re_'+id).show();
    document.getElementById("re_"+id).innerHTML=" <table>"+
                                                 "<tr>"+
                                                 "<td height=100 width=330>"+
                                                  "<textarea id='remenu_1' cols=1 rows=1 style='left: 0px; visibility: hidden; position: absolute'></textarea>"+
                                                  "<img id=img_1 alt=\"插入表情\" src=../images/wbTextBox/em.gif align=absmiddle style=cursor:hand align=center onmouseover=\"this.style.borderWidth='1pt';this.style.borderColor='#000000';this.style.borderStyle='solid'\" style=\"BORDER-RIGHT: white 1pt solid; BORDER-TOP: white 1pt solid; BORDER-LEFT: white 1pt solid; BORDER-BOTTOM: white 1pt solid\" onmouseout=\"this.style.borderWidth='1pt';this.style.borderColor='white';\"  onclick=em_1()>"+
                                                  "<iframe ID=\"HtmlEditor_1\"  MARGINHEIGHT=5 MARGINWIDTH=5 width=100% height=100%></iframe>"+
                                                  "<input id=\"Button_Reply\" type=\"button\" onclick=\"if(CheckForm_1())startRequest_AddReply('"+comments_id+"','"+d_reply+"','"+id+"');\" value=\"回复\" /><input id=\"Button_Cancel\" type=\"button\" onclick=\"jQuery('#re_"+id+"').hide();\" value=\"取消\" />"+
                                                  "</td>"+"</tr>"+"</table>";
    if (document.all){IframeID_1=frames["HtmlEditor_1"];}else{IframeID_1=document.getElementById("HtmlEditor_1").contentWindow;}
    if (navigator.appVersion.indexOf("MSIE 6.0",0)==-1){IframeID_1.document.designMode="On"}
    IframeID_1.document.open();
    IframeID_1.document.write ('<script>i=0;function ctrlenterkey(eventobject){if(event.ctrlKey && window.event.keyCode==13 && i==0){i=1;parent.document.form1.remenu_1.value=document.body.innerHTML;parent.document.form1.submit();parent.document.form1.submit1.disabled=true;}}<\/script><body onkeydown=ctrlenterkey()>');
    IframeID_1.document.close();
    IframeID_1.document.body.contentEditable = "True";
    IframeID_1.document.body.innerHTML=document.getElementById("remenu_1").value;
    IframeID_1.document.body.style.fontSize="10pt";

//StyleEditorHeader='<script>i=0;function ctrlenterkey(eventobject){if(event.ctrlKey && window.event.keyCode==13 && i==0){i=1;parent.document.form1.remenu_1.value=document.body.innerHTML;parent.document.form1.submit();parent.document.form1.submit1.disabled=true;}}<\/script><body onkeydown=ctrlenterkey()>';
//if(navigator.appName == "Microsoft Internet Explorer") 
//{ 
//IframeID_1=frames["HtmlEditor_1"]; 
//if(navigator.appVersion.indexOf("MSIE 6.0",0)==-1){IframeID_1.document.designMode="On"} 
//IframeID_1.document.open(); 
//IframeID_1.document.write(StyleEditorHeader); 
//IframeID_1.document.close(); 
//IframeID_1.document.body.contentEditable = "True"; 
//IframeID_1.document.body.innerHTML=document.getElementById("remenu_1").value;
//IframeID_1.document.body.style.fontSize="10pt"; 
//}else 
//{ 
//var _FF = navigator.userAgent.indexOf("Firefox")>-1?true:false; 
//IframeID_1=getObject("HtmlEditor_1"); 
//HtmlEditor_1=IframeID_1.contentWindow; 
//HtmlEditor_1.document.designMode="On" 
//HtmlEditor_1.document.open(); 
//HtmlEditor_1.document.write(StyleEditorHeader); 
//HtmlEditor_1.document.close(); 
//HtmlEditor_1.document.body.contentEditable = "True"; 
//HtmlEditor_1.document.body.innerHTML=document.getElementById("remenu_1").value;
//}

    //document.getElementById("Button_Cancel").focus();
    //document.getElementById("Button_Cancel").select();
}
function em_1()
{
        var arr = showModalDialog("../js/inc/Emotion.htm", "", "dialogWidth:18em; dialogHeight:11em; status:0;help:0");
        if (arr != null){
        IframeID_1.focus()
        sel=IframeID_1.document.selection.createRange();
        sel.pasteHTML(arr);
           }
}
function CheckForm_1()
{//alert(IframeID_1.document.body.innerHTML);
if(IframeID_1.document.body.innerHTML=="" || IframeID_1.document.body.innerHTML=="<P>&nbsp;</P>" || IframeID_1.document.body.innerHTML=="<P></P>" || IframeID_1.document.body.innerHTML=="&nbsp;" )
{ alert("请输入回复内容！"); return false;}
else
{
document.getElementById("remenu_1").value=IframeID_1.document.body.innerHTML; 
return true;
}
}