function Cookie() {
}

Cookie.prototype.set = 
  function(name, value, expires, path, domain, secure) {
    if (!path) {
      path = "/";
    }
    document.cookie = name + "=" + encodeURIComponent(value) +
                      ((expires) ? "; expires=" + expires : "") +
                      ((path) ? "; path=" + path : "") +
                      ((domain) ? "; domain=" + domain : "") +
                      ((secure) ? "; secure" : "");
  }

Cookie.prototype.get =
  function(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg) {
        var endstr = document.cookie.indexOf (";", j);
        if (endstr == -1) {
          endstr = document.cookie.length;
        }
        return unescape(document.cookie.substring(j, endstr));
      }
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) {
        break;
      }
    }
    return "";
  }

Cookie.prototype.remove = 
  function(name, path, domain) {
    if (!path) {
      path = "/";
    }
    if (this.getCookie(name)) {
      document.cookie = name + "=" +
                        ((path) ? "; path=" + path : "") +
                        ((domain) ? "; domain=" + domain : "") + 
                        "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
  }

function showMovie(name, width, height) {
  if (!width) {
    width = 640;
  }
  if (!height) {
    height = 500;
  }
  document.write("<embed src='http://www.jennifersoft.com/system/sjlec/flvplayer.swf'");
  document.write(" width='" + width + "' height='" + height + "' allowfullscreen='true'");
  document.write(" flashvars='&file=http://www.jennifersoft.com/system/sjlec/" + name + "&height=480&width=640&image=http://www.jennifersoft.com/system/sjlec/img_logo.gif'/>");
}

function toggleLoginForm() {
  if (!toggleLoginForm.called) {
    new Ajax.Updater("login_form", "/users/form", {onSuccess: function() {toggleLoginForm.called = true, toggleLoginForm()}});
  } else {
    $("login_form").toggle();
    if ($("login_form").getStyle("display") == "block") {
      setTimeout("$('login_id').focus();", 200);
    }
  }
}

function searchSite() {
  var text = $("search").value;
  if (text) {
    text = encodeURIComponent(text);
    window.location.href = "/3/search/1/" + text;
  }
}

function clickSearch(element) {
  if (element.value == 'Search') {
    element.value = "";
  }
}

var selectedEditTab = "edit";

function changeEditTab(name) {
  if (selectedEditTab) {
    $(selectedEditTab + "Tab").removeClassName("selected");
    $(selectedEditTab).hide();
  }
  selectedEditTab = name;
  $(selectedEditTab + "Tab").addClassName("selected");
  $(selectedEditTab).show();
}

function showDeleteForm(element, url, type) {
  if (!element.getAttribute("show")) {
    element = $(element);
    element.setAttribute("show", "true");
    var html = "<div>";
    html += "<label>Password</label> ";
    html += "<input type='password' name='password'/> ";
    html += "<button class='label' onclick='deleteTopic(this, \"" + url + "\", \"" + type + "\");'>Submit</button> ";
    html += "or <a href='#' class='label' onclick='$(this).up().previous().removeAttribute(\"show\"); $(this).up().remove(); return false;'>Cancel</a>";
    html += "</div>";
    new Insertion.After(element, html);
  }
}

function deleteTopic(element, url, type) {
  var password = $(element).previous().value;
  url += "?password=" + password
  if (type == "remote") {
    new Ajax.Request(url, {asynchronous:true, evalScripts:true}); return false;
  } else {
    window.location.href = url
  }
}
