  //Shortcuts are always handy.
  function Shortcut(location) {
    if(location != "valitse") {
      window.location = "?p=" + location
    }
  }
  
  //What would you do with BBCode, if you can't use it? ;)
  function BBCodePopup()
  {
    var margins = countmargin(400, 300);
    window.open("misc/BBCode_taglist.html", "Taglist", 
    "width=400, height=300, status=no, toolbar=no, location=no, menubar=no, copyhistory=no, resizable=yes, directories=no, scrollbars=yes, left=" + margins[0] + ", top=" + margins[1] + ", screenX=" + margins[0] + ", screenY=" + margins[1] + "")
  }
  
  //Commonly used when centering popups.
  function countmargin(width, height)
  {
    var left = screen.availWidth - width;
    var top = screen.availHeight - height;
    if(left > 1) left = left / 2
    else left = 0
    if(top > 1) top = top / 2
    else top = 0
    var return_this = new Array(left, top);
    return return_this
  }
  
  function NewRegisterImage()
  {
    var string = randstring(6);
    document.getElementById('registerimage').src = "img/regimage.php?regcode=" + string;
    document.getElementById('hiddenreg').value = string;
  }

  function openwindow(link, x, y, width, height, name)
  {
    defaults = new Array;
    defaults['width'] = 640;
    defaults['height'] = 480;
    defaults['xmargin'] = 0;
    defaults['ymargin'] = 30;
    defaults['name'] = "Popup";
    
    x = (x===undefined || x===false) ? defaults['xmargin'] : x;
    y = (y===undefined || y===false) ? defaults['ymargin'] : y;
    width = (width===undefined || width===false) ? defaults['width'] : width;
    height = (height===undefined || height===false) ? defaults['height'] : height;
    name = (name===undefined || name===false) ? defaults['name'] : name;
    
    window.open(link, name, "width=" + width + ",height=" + height + "status=no, toolbar=no, " +
    "location=no, menubar=no, copyhistory=no, resizable=no, directories=no, scrollbars=yes, " +
    "left=" + x + ", top=" + y + ", screenX=" + x + ", screenY=" + y);  
  }

  function randstring(length)
  {
    if(typeof length == "undefined") length = 8;
    characters = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    random = "";
    for(x=0;x<length;x++)
    {
      subn = Math.floor(Math.random() * characters.length);
      random += characters.substr(subn,1);
    }
    return random;
  }
  
  function easycopy(id)
  {
    var data = countmargin(640, 480);
    x = data[0];
    y = data[1];
    openwindow("misc/easycopy.php?id="+id, x, y, 640, 480);
  }
  
  