function showPopup(obj, url) {
  showIndicator();
  popupDisplay(obj);

  $jq.ajax({
    url: url,
    type: 'GET',
    dataType: 'html',
    timeout: 8000,
    error: function(err) {
      $jq('#popup').hide();
      $jq('#overlay').hide();
    },
    success: function(data) {
      Element.hide('indicator');
      $jq('#popup').show();
      var closeButton = '<span onclick="closePop()" id="popupSpan"><input type="image" src="'+$jq.path+'images/popup_close.png" alt="popup_close" class="popup_close" /></span>';
      $jq('#popup').html(closeButton+data);
      stylePopup(true);
    }
  });
}



jQuery.fn.extend({
  inputAutoTitles: function(options) {
    // stick all the titles
    this.find('input, textarea').each(function(i) {
      var title=$jq(this).attr('title');
      if ($jq(this).val()=='') {
        $jq(this).val(title).addClass('waiting')
        .blur(function(){
          $jq(this).removeClass('active');
          if ($jq(this).val()=='' || $jq(this).val()==title) $jq(this).addClass('waiting').val(title);
        })
        .focus(function(){

          $jq(this).removeClass('waiting').addClass('active');
          if ($jq(this).val()==title) 
          $jq(this).val('');
        });
      } else {
        $jq(this).unbind('click');
      }
    });
    // clear the titles on submit
    $jq(this).submit(function(){
      $jq(this).find('input').each(function(i){
        if ($jq(this).attr('title')==$jq(this).val()) 
        $jq(this).val('');
      });
    });
  }
});


function nl2br (str, is_xhtml) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Philip Peterson
    // +   improved by: Onno Marsman
    // +   improved by: Atli Þór
    // +   bugfixed by: Onno Marsman
    // +      input by: Brett Zamir
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: nl2br('Kevin\nvan\nZonneveld');
    // *     returns 1: 'Kevin<br />\nvan<br />\nZonneveld'
    // *     example 2: nl2br("\nOne\nTwo\n\nThree\n", false);
    // *     returns 2: '<br>\nOne<br>\nTwo<br>\n<br>\nThree<br>\n'
    // *     example 3: nl2br("\nOne\nTwo\n\nThree\n", true);
    // *     returns 3: '<br />\nOne<br />\nTwo<br />\n<br />\nThree<br />\n'
 
    var breakTag = '';
 
    breakTag = '<br />';
    if (typeof is_xhtml != 'undefined' && !is_xhtml) {
        breakTag = '<br>';
    }
 
    return (str + '').replace(/([^>]?)\n/g, '$1'+ breakTag +'\n');
}

function commentShowPreview() {
  showIndicator();
  $jq.ajax({
    url: $jq.path+'index.php/comment/apply_formatting',
    type: 'POST',
    data: {
      comment: $jq('#comment').val()
    },
    timeout: 8000,
    success: function(data) {
      $jq('#comment_preview').html(data).show();
      $jq('#indicator').hide();
    },
    error: function(err) {
      $jq('#indicator').hide();
    }
  });
}
