randomPassword = function(len) {
  if(len == null) { len = 8; }
  
  var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  var passwd = "";
  for(i = 0; i < len; i++) {
    pos = Math.floor(Math.random() * 62);
    passwd += chars.charAt(pos);
  }
  return passwd;
}

strtrim = function(str) {
  return str.replace(/^\s*/, "").replace(/\s*$/, "");
}

disableFCKeditor = function(instance) {
  if((!document.all && instance.EditorDocument.designMode.toLowerCase() != "off") || (document.all && instance.EditorDocument.body.disabled == false)) {
    if(document.all) {
      instance.EditorDocument.body.disabled = true;
    } else {
      instance.EditorDocument.designMode = "off";
    }
    instance.EditorWindow.parent.FCK.ToolbarSet.Disable();
		instance.EditorWindow.parent.FCKToolbarButton.prototype.RefreshState = function(){return false;};
	  instance.EditorWindow.parent.FCKToolbarSpecialCombo.prototype.RefreshState = function(){return false;};
  }
}

toggleFCKeditor = function(instance) {
  if((!document.all && instance.EditorDocument.designMode.toLowerCase() != "off") || (document.all && instance.EditorDocument.body.disabled == false)) {
    if(document.all) {
      instance.EditorDocument.body.disabled = true;
    } else {
      instance.EditorDocument.designMode = "off";
    }
    instance.EditorWindow.parent.FCK.ToolbarSet.Disable();
    buttonRefreshStateClone = instance.EditorWindow.parent.FCKToolbarButton.prototype.RefreshState;
    specialComboRefreshStateClone = instance.EditorWindow.parent.FCKToolbarSpecialCombo.prototype.RefreshState;
		instance.EditorWindow.parent.FCKToolbarButton.prototype.RefreshState = function(){return false;};
	  instance.EditorWindow.parent.FCKToolbarSpecialCombo.prototype.RefreshState = function(){return false;};
  } else {
    if(document.all) {
      instance.EditorDocument.body.disabled = false;
    } else {
      instance.EditorDocument.designMode = "on";
    }
    instance.EditorWindow.parent.FCK.ToolbarSet.Enable();
		instance.EditorWindow.parent.FCKToolbarButton.prototype.RefreshState = buttonRefreshStateClone;
		instance.EditorWindow.parent.FCKToolbarSpecialCombo.prototype.RefreshState = specialComboRefreshStateClone;
		instance.EditorWindow.parent.FCK.ToolbarSet.RefreshModeState();
  }
}

evalJSON = function(t) {
	return eval('(' + t + ')');
}

document.observe("dom:loaded", function() {
  if(/^#.*/.test(window.location.hash)) {
    hashChanged();
    startHashTimer();
  }
});

var startHashTimer = function() {
  var currHash = window.location.hash;
  var timer = setInterval(function() {
    if(window.location.hash != currHash) {
      currHash = window.location.hash; 
      hashChanged(); 
    }
  }, 500);
};

var hashChanged = function() {
  try {
    tag = window.location.hash.split('#')[1];
    new Effect.Highlight($$('a[name="' + tag + '"]')[0].up(), {duration: 3.0, startcolor: '#ff0000', endcolor: '#f8f8f8'});
  } catch(e) {}
};
