  function swapCheckbox(theName,theObj,hCheck) {
    checkObj = $(theName);
    prevVal = checkObj.value;
    if (prevVal == 0) {
      $(theObj).setStyle('background-position','0 100%');
      newVal = 1;
    } else {
      $(theObj).setStyle('background-position','0 0');
      newVal = 0;
    }
    checkObj.value = newVal;
  }
  
  function generate_address(suffix, hostname, username) {
	var atsign = "&#64;";
	var addr = username + atsign + hostname + '.' + suffix;
	document.write( 
	"<" + "a" + " " + "href=" + "mail" + "to:" + addr + ">" +
	addr +
	"<\/a>");
  }
  	
  function viewport() {
    test = $(document.body).getSize();
    sw = parseInt(test.x);
    sh = parseInt(test.y);
    return {width: sw , height: sh}
  }

  function hidePop(action) {
    $('overlay').setStyle('display','none');
    $('popContent').set('html','');
    $('pop').setStyles({
      'display' : 'none',
      'top' : '-1000px'
    });
    if(action != null) eval(action);
  }
  
  function submitForm(form,method,target) {
    $(form).set('send',{
      method: method,
      //url: src,
      evalScripts: true,
      onComplete: function(data) {
        if (data) {
          $(target).set('html',data);
        }
      }
    });
    $(form).send();
  }
  
  function loadSrc(src,target) {
    if (target == null) target = 'popContent';
    var req = new Request({
      method: 'get',
      url: src,
      evalScripts: true,
      onComplete: function(data) {
        if (data) {
          $(target).set('html',data);
        }
      }
    }).send();
  }
  
  function postForm(form,target) {
    if (target == null) target = 'popContent';
    $(form).set('send',{
      method: 'post',
      //url: src,
      evalScripts: true,
      onComplete: function(data) {
        if (data) {
          $(target).set('html',data);
        }
      }
    });
    $(form).send();
  }
  
  function postSrc(src,target,form) {
    if (target == null) target = 'popContent';
    var req = new Request({
      method: 'post',
      url: src,
      evalScripts: true,
      onComplete: function(data) {
        if (data) {
          $(target).innerHTML = data;
        }
      }
    }).send();
  }
  
  function showPop(src,width) {
    vp = viewport();    
    if (width == null) width = 400;
    else {
      switch(width) {
        case 'full':
          width = vp.width - 60;
          break;
      }
    }
    $('overlay').setStyles({
      'position': 'absolute',
      'display' : 'block',
      'opacity' : 0.5,
      'width': vp.width + 'px',
      'height': vp.height + 'px'
    });

    var req = new Request({
      method: 'get',
      url: src,
      evalScripts: true,
      onComplete: function(data) {
        if (data) {
          $('popContent').set('html',data);
          $('pop').setStyles({
            'display' : 'block',
            'top' : '100px',
            'width' : width + 'px'
          });
          oh = $('pop').offsetHeight;
          ow = $('pop').offsetWidth;
          sp = $(document.body).getScroll();
          $('pop').setStyles({
            'left' : Math.round((vp.width - ow) / 2) + 'px',
            'top' : Math.max(0,Math.round((vp.height - oh) / 2) + sp.y) + 'px'
          });
        }
      }
    }).send();
  }
  
  function newWin(src,windowName) {
    if (windowName == null) windowName = '_blank';
    var newWindow = window.open(src, windowName);
    newWindow.focus();
  }
