var visitortime = new Date();
document.cookie = 'gmtoffset='+visitortime.getTimezoneOffset()/60+'; expires=Thu, 2 Aug 2009 20:00:00 UTC; path=/'


// DFA Dialog
var DIALOG_ANIMATION = true;
var DIALOG_DONE = false;
var DIALOG_HEIGHT = 400;
var DIALOG_WIDTH = 400;

$(document).ready(function(){

  // cbb here creates the ie operation aborted error
  // in cb.js it messes with comments "reply" adding of new div??
  // now being loaded via script call at footer of every page
  //cbb.init();

  // ajax the form no matter what
  var bind_ajax_forms = function() {
       $("#ajax_form").ajaxForm({
         target: '#ajax_form_update',
         beforeSend: function(xhr) { $("#ajax_form_update").html('Loading new information.....'); xhr.setRequestHeader("Accept", "text/javascript");}
       });
   }
  bind_ajax_forms();

// ajax the form only if its added via ajax (must add bind_ajax_forms_xhr in success portion of ajax call)
 var bind_ajax_forms_xhr = function() {
    
    //multi select is not playing kindly with ajax
    $('form').submit(function(event) {
      var pwd = $("#ajax_form_xhr :input");
        pwd.each( function(){
          if (this.id == 'select_left') {
            for (opt in this.options) { this.options[opt].selected=true }
          }
          if (this.id == 'select_right') {
            for (opt in this.options) { this.options[opt].selected=true }
          }
        }); 
    });

     $("#ajax_form_xhr,.ajax_form_xhr").ajaxForm({
       dataType: 'script',
       beforeSend: function(xhr) {
        $("#ajax_form_xhr :submit").attr(  { disabled : 'disabled' } );
        $("#DIALOG_buttons").prepend("<b>Submitting.. please wait </b>");
        xhr.setRequestHeader("Accept", "text/javascript");}
     });
     
 }

$('body').click(function(event) {
//debugger;

        
  // I don't want the linked image I want the A tag
  if ($(event.target).is("img")) { event.target = event.target.parentNode; }
  
	if ($(event.target).is("a.remote")) {
    $.ajax({
                        url: addFormatToURL('js',event.target.href),
                        dataType: 'script',
                        beforeSend: function(xhr) { ajax_show(); xhr.setRequestHeader("Accept", "text/javascript");},
                        success: function() { ajax_hide(); }
		      });
	        return false;
	}
	if ($(event.target).is("a.toggleid")) {

    // icons
    if ($(event.target).is("a.collapsed") || $(event.target).is("a.expanded")) {
      $(event.target).toggleClass('collapsed');
      $(event.target).toggleClass('expanded');     
    }
    
    $("#" + event.target.id + "_toggle" ).slideToggle('normal');
		$("." + event.target.id + "_toggle" ).slideToggle('normal');
    
    
    return false;
	}

	if ($(event.target).is("a.commentall")) {  
		$(".commentBody" ).slideDown('normal');
		$(".commentChildren" ).slideDown('normal');
    $(".togglecomment").text('-');
    return false;
	}  

	if ($(event.target).is("a.togglecomment")) {

    if ($("." + event.target.id + "_toggle:hidden").length > 0) {
     $(event.target).text('-');
    }
    else {
      $(event.target).text('+');
    }
		$("." + event.target.id + "_toggle" ).slideToggle('normal');

    return false;
	}
  
  if ($(event.target).is("a.dialog_m")) {  
	        var t = event.target.title || $(event.target).text() || event.target.href;
	        DIALOG_show(t,300,400);
		      $.ajax({
		          url: event.target.href,
		          dataType: "html",
		          beforeSend: function(xhr) { xhr.setRequestHeader("Accept", "text/html");},
		          success: function(data) {$("#DIALOG_container").html("<div id='DIALOG_content'>" + data + "</div>"); bind_ajax_forms_xhr(); stripeIt(); }
			 
		      });
	        return false;
	}

  if ($(event.target).is("a.dialog_a")) {  
	        var t = event.target.title || $(event.target).text() || event.target.href;
	        DIALOG_show(t,300,640);
		      $.ajax({
		          url: event.target.href,
		          dataType: "html",
		          beforeSend: function(xhr) { xhr.setRequestHeader("Accept", "text/html");},
		          success: function(data) {$("#DIALOG_container").html("<div id='DIALOG_content'>" + data + "</div>"); bind_ajax_forms_xhr(); stripeIt(); }
			 
		      });
	        return false;
	}  
  
  if ($(event.target).is("a.dialog_w")) {  
	        var t = event.target.title || $(event.target).text() || event.target.href;
	        DIALOG_show(t,300,860);
		      $.ajax({
		          url: event.target.href,
		          dataType: "html",
		          beforeSend: function(xhr) { xhr.setRequestHeader("Accept", "text/html");},
		          success: function(data) {$("#DIALOG_container").html("<div id='DIALOG_content'>" + data + "</div>"); bind_ajax_forms_xhr(); stripeIt(); }
			 
		      });
	        return false;
	}  

  if ($(event.target).is("a.dialog_s")) {  
          var t = event.target.title
	        var data = $("#" + event.target.id + "_content" ).html();
	        DIALOG_show(t,300,400);
          $("#DIALOG_container").html("<div id='DIALOG_content'>" + data + "</div>");
          return false;
	} 

  
  if ($(event.target).is("a.hqLoad")) {  
          $("#hq").slideDown('normal');
          if ($("#hq").html().length > 50) {
            return false;
		      }
		      $.ajax({
		          url: event.target.href,
		          dataType: "html",
		          beforeSend: function(xhr) { xhr.setRequestHeader("Accept", "text/html");},
		          success: function(data) {$("#hq").html("<div id='hq_content'>" + data + "</div>"); bind_ajax_forms_xhr(); stripeIt(); }
			 
		      });
	        return false;
	}
 
  if ($(event.target).is("a.scroll")) {
            var $target = event.target.hash;
            if ($target.length) {
              var targetOffset = $($target).offset().top;
              $('html,body').animate({scrollTop: targetOffset}, 1000);
              return false;
            }
          return false;
  }
  
  if ($(event.target).is("a.comment_reply")) {
    var $eth = event.target.hash;
    $eth = $eth.replace(/#/,'');
    var $replyto = $eth.split("-");

    tinyMCE.execCommand('mceRemoveControl', false, 'comment_body_reply');
    $("#comment_reply_id").show();
    $("#comment_reply_subject").html($("#comment_subject_" + $replyto[1]).html());
    $("#comment_reply_id").appendTo("#comment_" + $replyto[1]);   
    tinyMCE.execCommand('mceAddControl', false, 'comment_body_reply');

    
    $('#comment_root_id').val($replyto[0]);
    $('#comment_child_of').val($replyto[1]);

    return false;
  }  
  
});

var stripeIt = function () {
  // Table striping 
  $(".stripeIt tr").removeClass("alt");
  $(".stripeIt tr").mouseover(function(){$(this).addClass("over");}).mouseout(function(){$(this).removeClass("over");});
  $(".stripeIt tr:even").addClass("alt");
  // Div striping 
  //$(".stripeIt div").removeClass("alt");
  //$(".stripeIt div").mouseover(function(){$(this).addClass("over");}).mouseout(function(){$(this).removeClass("over");});
  //$(".stripeIt div:even").addClass("alt");

  // li striping 
  $(".stripeIt li").removeClass("alt");
  $(".stripeIt li").mouseover(function(){$(this).addClass("over");}).mouseout(function(){$(this).removeClass("over");});
  $(".stripeIt li:even").addClass("alt");


  if ($('#datestart').get(0)) {
    $('#datestart').datepicker({ 
  	  showOn: 'button', 
  	  buttonImage: '/images/icons/calendar.png', 
  	  buttonImageOnly: true,
      closeAtTop: false,
      beforeShow: customRange,
      //beforeShow: readLinked, 
      onSelect: updateLinked 
    }); 

    $('#dateend').datepicker({ 
  	  showOn: 'button', 
  	  buttonImage: '/images/icons/calendar.png', 
  	  buttonImageOnly: true,
      closeAtTop: false,
      beforeShow: customRange,
      //beforeShow: readLinked, 
      onSelect: updateLinked 
    });
  }
  
  // TODO - make this only when needed
   $(function() {
			$("#select_left").multiSelect("#select_right", {trigger: "#options_right"});
			$("#select_right").multiSelect("#select_left", {trigger: "#options_left"});
   });
  
}
stripeIt();
  
});
/* END DOC READY */

function quickStripeIt() {
  // Table striping 
  $(".stripeIt tr:not(:hidden)").removeClass("alt");
  $(".stripeIt tr:not(:hidden)").mouseover(function(){$(this).addClass("over");}).mouseout(function(){$(this).removeClass("over");});
  $(".stripeIt tr:not(:hidden):even").addClass("alt");
}

function ajax_form_submit() {
  $('#ajax_form').ajaxSubmit({
    target: '#ajax_form_update',
    beforeSend: function(xhr) { $("#ajax_form_update").html('Loading new information.....'); xhr.setRequestHeader("Accept", "text/javascript");}
  }); 
  return false; 
}

function ajax_show(text) {
  var ajax_text = text || 'Working...';
  $("#ajax_progress").show();
}

function ajax_hide() {
  $("#ajax_progress").hide();
}


function DIALOG_show(caption, height, width, offset_left, offset_top) {
  DIALOG_HEIGHT = height || 400;
  DIALOG_WIDTH = width || 400;
  if(!DIALOG_DONE) {
    $(document.body).append("<div id='DIALOG_overlay'></div><div id='DIALOG_window'><div id='DIALOG_caption'></div><div id='DIALOG_container'><p align=center><img src='/images/spinner.gif' width='16' height='16'> <strong>Loading....</strong></p></div></div>");

    $("#DIALOG_overlay").click(DIALOG_hide);
    $(window).resize(DIALOG_position(offset_left,offset_top));
    DIALOG_DONE = true;
  }

  var close_img = "<span class='fr' id='DIALOG_close'><img src='/images/icons/close.png' width=16 height=16 border=0></span>";
  $("#DIALOG_caption").html(close_img + caption);
  
  $("#DIALOG_close img").click(DIALOG_hide);
  $("#DIALOG_overlay").show();
  
  DIALOG_position(offset_left,offset_top);

  if(DIALOG_ANIMATION)
    $("#DIALOG_window").slideDown("slow");
  else
    $("#DIALOG_window").show();
}

function DIALOG_hide() {
  $("#DIALOG_window,#DIALOG_overlay").remove();
  DIALOG_DONE = false
}

function DIALOG_positiono(offset_left,offset_top) {
  var de = document.documentElement;
  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  if (offset_left > 0 && offset_top > 0) {
    $("#DIALOG_window").css({width:DIALOG_WIDTH+"px",left: offset_left+"px",top: offset_top+"px" });
  	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
  		$("#DIALOG_window").css({marginTop: '-' + parseInt(((DIALOG_HEIGHT / 2) - 30),10) + 'px'});
    }
  }
  else {
    $("#DIALOG_window").css({width:DIALOG_WIDTH+"px",left: ((w - DIALOG_WIDTH)/2)+"px" });
    $("#DIALOG_frame").css("height",DIALOG_HEIGHT - 32 +"px");
  	//if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
  		$("#DIALOG_window").css({marginTop: '-' + parseInt(((DIALOG_HEIGHT / 2) - 30),10) + 'px'});
    //}
  }

}

function DIALOG_position(offset_left,offset_top) {
  var de = document.documentElement;
  var h = self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
  var w = self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
  var iebody = (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
  var dsocleft = document.all? iebody.scrollLeft : pageXOffset;
  var dsoctop = document.all? iebody.scrollTop : pageYOffset;
    
  var height = h < DIALOG_HEIGHT ? h - 32 : DIALOG_HEIGHT;
  var top = (h - height)/2 + dsoctop;

  //$("#DIALOG_window, #DIALOG_frame").css({ width: DIALOG_WIDTH +"px", height: height +"px", left: ((w - DIALOG_WIDTH)/2) +"px", top: top +"px" });
  $("#DIALOG_window, #DIALOG_frame").css({ width: DIALOG_WIDTH +"px", left: ((w - DIALOG_WIDTH)/2) +"px", top: top +"px" });
  
  $("#DIALOG_frame").css("height", height - 32 +"px");
  
  var wh = $(window).height();
  var ww = $(window).width();
  dsoctop = 0;
  $("#DIALOG_overlay").css({ height: wh, top: dsoctop +"px", width: w });

  if ( (jQuery.browser.msie && jQuery.browser.version > 7)) { 
    h = dsoctop;
    dsoctop = 0;
    $("#DIALOG_overlay").css({ height: hb, top: dsoctop +"px", width: w });
  }
}


function addToSelect(model,id,name) {
  $("p#selected_to_none").remove();
  var asd = $("#selected_to");
  var s_icon = 'user_green'
  if (model == 'group') 
    s_icon = 'group'
  if (model == 'event') 
    s_icon = 'calendar'  
  $("div#" + model + "_" + id + "_selected").remove();
  if ($("#s_" + model + "_" + id + ":checked").val() !== undefined) {
    $("#selected_to").append("<div class='selected_to' id='" + model + "_" + id + "_selected'><a href='javascript:void(0);' onClick=' $(\"#" + model + "_" + id + "_selected\").remove();' class='iconedBoxed iconed' style=\"background-image: url(/images/icons/" + s_icon + ".png);\">" + name + "</a><input class=\"checkedUserSelect\" id=\"message_to_" + model + "s\" type=\"hidden\" value=\"" + id + "\" name=\"message[to_" + model + "s][]\"/></div>");
  }
}


function filterSelected(model,filter) {

filter = filter.toLowerCase();
$('table#selecttable tr').each( function( x ){
  var item_name = $("table#selecttable tr:eq("+x+")").attr("i_name");
  var item_name_array = item_name.split(" ");
  var xu = 0;
  var matched = 0;
  while (xu < item_name_array.length) {
    charstomatch = item_name_array[xu].substring(0, filter.length).toLowerCase();
    if (charstomatch == filter) { matched = 1; }
    xu+=1;
  }
  
  if (matched == 1) { $("table#selecttable tr:eq("+x+")").show() }
  else { $("table#selecttable tr:eq("+x+")").hide() }
  
  // ppthhh so cool... but did simple overflow instead... leaving here cause i like it...
  //$('table#userselecttable tr:not(:hidden):gt(3)').hide()
});

  $(".stripeIt tr").removeClass("alt");
  $(".stripeIt tr:not(:hidden):even").addClass("alt");
    
}

function checkSelected(model) {
  $('input.checkedSelect').each( function( x ){
      var usid = $("input.checkedSelect:eq("+x+")").val();
      $("#s_" + model + "_" + usid ).attr("checked","checked");
    });
}

function checkAllSelected(model) {
  $('table#selecttable tr:not(:hidden)').each( function( x ){
      var item_name = $("table#selecttable tr:not(:hidden):eq("+x+")").attr("i_name");
      var item_id = $("table#selecttable tr:not(:hidden):eq("+x+")").attr("i_id");
      $("#s_" + model + "_" + item_id ).attr("checked","checked");
      addToSelect(model, item_id,item_name);
    });
}


function addToSelectRaw(email_in,name_in,zip_in) {
  if ($("#gotv_table").length > 0) { // GOTV SPECIFIC STYLE
    n = 0;
    w = 0
    $('table#gotv_table tr.gotv_tr').each( function( x ){
      n=n+1;

      if (w == 0) {
        if ($("#invite_email_" + n).val().length > 0) {

        }
        else {
          $("#invite_email_" + n).val(email_in);
          // first/last

          if (name_in.length > 0) {
            if (name_in == email_in) { name_in= ''; }
            na = name_in.split(" ");
            $("#invite_name_f_" + n).val(na.shift());
            $("#invite_name_l_" + n).val(na.join(' '));
          }
          
          $("#invite_zip_" + n).val(zip_in);          
          $("table#gotv_table tr#gotv_tr_" + n).show();
          w=1;
        }
      }
      
      
    });
  }
  else {

    var s_icon = 'email'
    $("p#selected_to_none").remove();
    var email = $("#invite_email").val();
    if (email.length > 5) {
      email = $("#invite_email").val();
      name = $("#invite_name").val();
      zip = $("#invite_zip").val();
    }
    else {
      email = email_in;
      name = name_in;
      zip = zip_in;
    }
    
    if (email.length < 5) { return; } 
    var id = email;
    id = replaceAll( id, "\\@", '', 1);
    id = replaceAll( id, "\\.", '', 1);


    $("#invite_message").html(email + " added to recipients list. Another address can now be entered below");
    $("#invite_email").val('');
    $("#invite_name").val('');
    $("#invite_zip").val('');
    
    $("#selected_to").append("<div class='selected_to' id='raw_" + id + "_selected'><a href='javascript:void(0);' onClick=' $(\"#raw_" + id + "_selected\").remove();' class='iconedBoxed iconed' style=\"background-image: url(/images/icons/" + s_icon + ".png);\">" + email + "</a><input type=\"hidden\" value=\"" + email + "\" name=\"message[to_raw_email][]\"/><input type=\"hidden\" value=\"" + name + "\" name=\"message[to_raw_name][]\"/><input type=\"hidden\" value=\"" + zip + "\" name=\"message[to_raw_zip][]\"/></div>");
  }
  
}

function parseSelectRaw() {
  var raw = $("#select_raw").val();
  raw = replaceAll( raw, ' ', ',', 1 )
  raw = replaceAll( raw, "\\n", ',', 1 )
  raw = replaceAll( raw, "\\r", '', 1 )  
  var raw_array = raw.split(",");
  var xu = 0;
  while (xu < raw_array.length) {
    addToSelectRaw(raw_array[xu],'','')
    xu+=1;
  }  
  
  DIALOG_hide()
}

// Plaxo widget.. 
function onABCommComplete(data) {
// called when user completes the widget; data is [[name1, email1], [name2, email2], ...]

if (data) {
  var cnt = 0;
  while (cnt < data.length) {
    var nameAndEmail = data[cnt];
    if (nameAndEmail.length > 0) {
      if ($("#selected_to").length > 0) {
        addToSelectRaw(nameAndEmail[1],nameAndEmail[0],'');
      }
      else {
        var current_emails = $("#emails").val();
        $("#emails").val(current_emails + nameAndEmail[1] + ' <' + nameAndEmail[0] + ">\n");
      }
    } 
    cnt+=1;
  } 
} 
  DIALOG_hide();

}


function comments_reset() {
  var ub_level = $("#user_preferences_comment_level").val();
  $(".commentBody,.commentChildren").show();
  $(".togglecomment").text('-');

  ub_level = ub_level - 1;
  for (x = ub_level; x >= -10; x = x-1) {
    $(".commentRated_" + x).hide();
    $("#ub_level").html(x);
    $(".commentRatedSpan_" + x).text('+');
  }
}

function calendar_over(cd) {
  $("." + cd).removeClass("over");
  $("." + cd).addClass("over");
}

/* multiSelect form */
jQuery.fn.multiSelect=function(e,f){if(typeof f=="string")f={trigger:"#"+f};f=$.extend({trigger:null,autoSubmit:true,beforeMove:null,afterMove:null},f);var g=this;if(f.autoSubmit)this.parents("form").submit(function(){ selectChildOptions(g)});var h=function(){moveOptions(g,e,f.beforeMove,f.afterMove)};this.dblclick(h);if(f.trigger)jQuery(f.trigger).click(h);return this;function moveOptions(a,b,c,d){if(c&&!c())return;jQuery("option:selected",a).each(function(){jQuery(this).attr("selected",false).appendTo(b)});d&&d()}function selectChildOptions(a){a.children("option").each(function(){this.selected=true})}};


// Prepare to show a date picker linked to three select controls 
function readLinked(dfield) {
    dateid = dfield.id; 
    $('#' + dateid + '').val( 
        $('#' + dateid + '_month').val() + '/' + 
        $('#' + dateid + '_day').val() + '/' +  
        $('#' + dateid + '_year').val() 
    ); 
    return {}; 
} 
 
// Update three select controls to match a date picker selection 
function updateLinked(date,dfield) { 
    dateid = dfield._input[0].id; 
    $('#' + dateid + '_month').val(parseInt(date.substring(0, 2))); 
    $('#' + dateid + '_day').val(parseInt(date.substring(3, 5))); 
    $('#' + dateid + '_year').val(date.substring(6, 10)); 
} 

function customRange(input) { 
  readLinked(input);
  return {minDate: (input.id == 'dateend' ? getDate($('#datestart').val()) : null),  maxDate: (input.id == 'datestart' ? getDate($('#dateend').val()) : null)}; 
} 

function replaceAll( str, searchTerm, replaceWith, ignoreCase )
{
var regex = "/"+searchTerm+"/g";
if( ignoreCase ) regex += "i";

return str.replace( eval(regex), replaceWith );
}

// this function adds .js to remote calls.. so rails knows to respond with js template
function addFormatToURL(format, url) {
	var urlArray = url.split('?');
	urlArray[0] = urlArray[0].replace( 'http://127.0.0.1:3000', '' );
	urlArray[0] = urlArray[0].replace( 'http://10.10.1.3', '' );
	urlArray[0] = urlArray[0].replace( 'http://beta.democracyforamerica.com', '' );	
	urlArray[0] = urlArray[0].replace( 'http://democracyforamerica.com', '' );	
	// add extension to url, unless it's already there
	if ( urlArray[0].search('.' + format + '$') == -1 ) { urlArray[0] = urlArray[0] + '.' + format; }
	return urlArray.join('?');
}


// NEWS TICKER
/*
 *
 * Copyright (c) 2006/2007 Sam Collett (http://www.texotela.co.uk)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * Version 2.0
 * Demo: http://www.texotela.co.uk/code/jquery/newsticker/
 *
 * $LastChangedDate$
 * $Rev$
 *
 */
//eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(1($){$.9.D=$.9.g=1(b){b=b||p;i=1(a){j(a);a.4=$("r",a);a.4.q(":o(0)").l().C();a.5=0;h(a)};h=1(a){a.m=t(1(){f(a)},b)};j=1(a){s(a.m)};8=1(a){a.3=7};d=1(a){a.3=c};f=1(a){e(a.3)6;a.3=7;$(a.4[a.5]).n("k",1(){$(2).l();a.5=++a.5%(a.4.B());$(a.4[a.5]).z("k",1(){a.3=c})})};2.y(1(){e(2.x.w()!="A")6;i(2)}).v("g").u(1(){8(2)},1(){d(2)});6 2}})(E);',41,41,'|function|this|pause|items|currentitem|return|true|pauseTicker|fn|||false|resumeTicker|if|doTick|newsticker|startTicker|initTicker|stopTicker|slow|hide|tickfn|fadeOut|eq|4000|not|li|clearInterval|setInterval|hover|addClass|toLowerCase|nodeName|each|fadeIn|ul|size|end|newsTicker|jQuery'.split('|'),0,{}))

function convertWord(type, content) {
	switch (type) {
		// Gets executed before the built in logic performes it's cleanups
		case "before":
			//content = content.toLowerCase(); // Some dummy logic
			break;

		// Gets executed after the built in logic performes it's cleanups
		case "after":
			//content = content.toLowerCase(); // Some dummy logic
			break;
	}

	return content;
}


function checkMsgSelected(select_type) {
    $(":checkbox").attr("checked","");
          
    $(":checkbox").each( function( x ){
    	switch (select_type) {
    		case "all":
          $(":checkbox:eq("+x+")").attr("checked","checked");
    			break;
    		case "unread":
          $(".unread:checkbox:eq("+x+")").attr("checked","checked");
    			break;
    		case "read":
          $(".read:checkbox:eq("+x+")").attr("checked","checked");
    			break;
      }
      
    });
}

function tinymcesize(inst) {
  var tl = stripHtmlTags(inst.getBody().innerHTML).length;
  var tid = inst.id;
       $("#" + tid + "_limit").html(tl);
  if (tl > 1500) {
    $("#" + tid + "_limit_error").show();
    $("#" + tid + "_submit").attr("disabled", "true"); 
    $("#" + tid + "_limit_error").html("<h4 class='red'>Comment too long. Max is 1500 characters</h4>");
  }
  else if (tl == 0) {
       $("#" + tid + "_limit").html('0');
    $("#" + tid + "_limit_error").show();
    $("#" + tid + "_submit").attr("disabled", "true"); 
    $("#" + tid + "_limit_error").html("<h4 class='red'>Comment body can not be empty</h4>"); 
  }
  else {
    $("#" + tid + "_limit_error").hide();
    $("#" + tid + "_submit").removeAttr('disabled');
  }
}

// Event fired for any normal UI event such as a key or mouse press.
function tinymcesize_event(e){
    switch (e.type) {
        case 'keyup': tinymcesize(tinyMCE.activeEditor); break;
    }
    return true;
}

// Strips all html tags from a given string, leaving only plain text
function stripHtmlTags(strContent) { return strContent.replace(/(<([^>]+)>)/ig, ""); }


