      function preview(filename, width, height)
      {
        preview_window = window.open('', '_blank', 'width=' + width + ',height=' + height);
        preview_window.document.write('<html><head><style type="text/css">body { margin: 0; }</style></head><body onblur="window.close();">');
        preview_window.document.write('<img name="theimage" src="' + filename + '" width="' + width + '" height="' + height + '" />');
        preview_window.document.write('</body></html>');
        preview_window.document.close();      
      } 
      
      function tagExternalLinks()
      {
        var anchors = document.getElementsByTagName('A');
        for (var i = 0; i < anchors.length; i++)
        {
          if (anchors[i].rel == 'external')
          {
            anchors[i].onclick = function() { return confirm('You will now leave this website, are you sure?'); }
          }
        }
      }
      
  function qs_replace(qs, name, value)
  {
    name = name.toLowerCase();
    qs = qs.toLowerCase();
    loc = qs.indexOf('?' + name + '=') + 1;
    
    if (loc == 0)
      loc = qs.indexOf('&' + name + '=') + 1;
    var t;
    
    if (loc == 0)
    {
      // simplest case, the attribute does not exist in the qs
      if (value.length)
      {
        if (qs.length)
          t = qs + '&' + name + '=' + escape(value);
        else
          t = qs + name + '=' + escape(value);
      }
      else t = qs;
    }
    else
    {
      end_loc = qs.substr(loc, qs.length).indexOf('&') + loc;
      t = '';
      // if not the first item in the list, prepend the start of the list
      if (loc > 1)
        t += qs.substr(0, loc);
      
      if (value && value.length)
        t += name + '=' + escape(value);
      
      // if not the last item in the list, append the rest of the list
      if (end_loc > loc)
        t += qs.substr(end_loc);
    }
  
    while (t.indexOf('&&') != -1)
      t = t.replace('&&', '&');
      
    while (t.substr(t.length - 1) == '&')
      t = t.substr(0, t.length - 1);

    while (t.substr(t.length - 1) == '?')
      t = t.substr(0, t.length - 1);
      
    return t;
  }
  
  function sn_replace(sn, name, value)
  {
    name = name.toLowerCase();
    sn = sn.toLowerCase();
    loc = sn.indexOf('?' + name + '=') + 1;
        
    if (loc == 0)
      loc = sn.indexOf('&' + name + '=') + 1;
    
    if (!value) value = '';  
    
    value = value + '';
    
    var t;
    
    if (loc == 0)
    {
      // simplest case, the attribute does not exist in the sn

      if (value.length)
      {
        if (sn.length && (sn.indexOf('?') != -1))
        {
          t = sn + '&' + name + '=' + escape(value);
        }
        else if (sn.indexOf('?') == sn.length - 1)
          t = sn + name + '=' + escape(value);
        else
          t = sn + '?' + name + '=' + escape(value);
        
      }
      else 
        t = sn;
    }
    else
    {
        
      end_loc = sn.substr(loc, sn.length).indexOf('&') + loc;
      t = '';
      // if not the first item in the list, prepend the start of the list
      if (loc > 1)
        t += sn.substr(0, loc);
      
      if (value.length)
        t += name + '=' + escape(value);
      
      // if not the last item in the list, append the rest of the list
      if (end_loc > loc)
        t += sn.substr(end_loc);

    }
  
    while (t.indexOf('&&') != -1)
      t = t.replace('&&', '&');
      
    while (t.substr(t.length - 1) == '&')
      t = t.substr(0, t.length - 1);
      
    while (t.substr(t.length - 1) == '?')
      t = t.substr(0, t.length - 1);
    return t;
  }
  
  function checkboxes_value(form, name)
  {
    v = '';
    el = form.elements[name];
    if (!el) return '';
    if (!el.length && el.checked)
      v = el.value;
    else
    {
      for (i=0; i < el.length; i++)
      {
        if (el[i].checked)
          v += el[i].value + ',';
      }
      v = v.substring(0, v.length - 1);
    }
    return v;
  }  
  
  function validateEmail(str)
  {
    try
    {
      var regex = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
      return regex.test(str);
    }
    catch(er)
    {
      return true;
    }
  }
  
  function isWhitespace(str)
  {
    try
    {
      var regex = /^\s+$/;
      return regex.test(str);
    }
    catch(er)
    {
      return true;
    }
    
  }  

