function vote (content_type, content_id, vote_type, user_session) {
  var url = base_url + '/voting/'; 
  url += content_type + '/'; 
  url += content_id + '/';
  url += vote_type + '/';
  url += '?';

  return url;
}

function open_instructions (content_type, content_id) {
  var url = base_url;
  url += '/instructions/';
  url += content_type;
  url += '/';
  url += content_id;
  url += '?';

  var window = 'location=no,';
  window += 'status=yes,';
  window += 'menubar=no,';
  window += 'scrollbars=yes,';
  window += 'resizable=yes,';
  window += 'width=400,';
  window += 'height=300,';
  window += 'modal=yes,';
  window += 'dependent=yes';
  
  b=open(url,'instructions', window);
  setTimeout('b.focus()',1000)
}

function open_url(url) {
  var options = '';
  options += 'dependent=no,';
  options += 'resizable=yes,';
  options += 'scrollbars=yes,';
  options += 'status=yes,';
  options += 'toolbar=yes,';
  options += 'location=yes,';
  options += 'menubar=yes';
  
  b=open(url,'', options);
  setTimeout('window.focus()',1000)
}

var Cookie = {
  set: function(name, value, daysToExpire) {
    var expire = '';
    if (daysToExpire != undefined) {
      var d = new Date();
      d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
      expire = '; expires=' + d.toGMTString();
    }
    return (document.cookie = escape(name) + '=' + escape(value || '') + expire);
  },
  get: function(name) {
    var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
    return (cookie ? unescape(cookie[2]) : null);
  },
  erase: function(name) {
    var cookie = Cookie.get(name) || true;
    Cookie.set(name, '', -1);
    return cookie;
  },
  accept: function() {
    if (typeof navigator.cookieEnabled == 'boolean') {
      return navigator.cookieEnabled;
    }
    Cookie.set('_test', '1');
    return (Cookie.erase('_test') === '1');
  }
};

function show (id) {
  var elem = document.getElementById(id);
  elem.style.display = '';
}

function hide (id) {
  var elem = document.getElementById(id);
  elem.style.display = 'none';
}

function change_class (id, class_name) {
  var elem = document.getElementById(id);
  elem.className = class_name;
}

function toggle_comments(content_type, content_id) {
  var comment_id = '#comments-' + content_type + '-' + content_id;
  $(comment_id).toggle();
  var comment_link = '.comment-link-' + content_type + '-' + content_id;
  $(comment_link).toggle();

  return(false);
}

function add_comment_chars_left() {
  var max_chars = 200;

  var char_count = $("#add-comment-dialog-comment").val().length;
  var chars_left  = max_chars - char_count;

  if (chars_left < 0) {
    var text = $("#add-comment-dialog-comment").val().substring(0,max_chars-1);
    $("#add-comment-dialog-comment").val(text);
    chars_left = 0;
  }

  $("#add-content-dialog-chars-left").text(chars_left);
  
  return false;
}

function set_up_add_comment_dialog(content_type, content_id) {
  $('#add-comment-dialog-content-type').val(content_type);
  $('#add-comment-dialog-content-id').val(content_id);
  $('#add-comment-dialog-store-logo').html($('.websitelogo a').html());
  $('#add-comment-dialog-discount-description').text($('#discount_' + content_id + ' p.couponbody a').text());
  $('#add-comment-dialog-discount-code').text($('#discount_' + content_id + ' span.code').text());
  return false;
}