function doUpload() {
  document.getElementById('uploadpop').style.display = 'block';
  document.getElementById('uploadframe').src = 'loading.html';
  setTimeout("document.getElementById('uploadform').submit();", 200);
}
function closePop() {
  document.getElementById('uploadframe').src = 'loading.html';
  document.getElementById('uploadpop').style.display = 'none';
}

// submit form named by ID, set hiddenid element to hiddenvalue, if given
function doform(formid) {
  document.getElementById(formid).submit();
}
function doform(formid, hiddenid, hiddenvalue) {
  document.getElementById(hiddenid).value = hiddenvalue;
  document.getElementById(formid).submit();
}

// update calendar for datapicker
function updatecal(dt) {
  loadExternalHtml('card_calendar.php?type=cal&dt='+dt, 'cal', false)
  loadExternalHtml('card_calendar.php?type=date&dt='+dt, 'date', '<div align=center><br>loading...</div>')
}
function updateEcardCal(dt) {
  loadExternalHtml('ecard_calendar.php?type=cal&dt='+dt, 'cal', false)
  //loadExternalHtml('ecard_calendar.php?type=date&dt='+dt, 'date', '<div align=center><br>loading...</div>')
}

// manage card picker rollover
var rolloverVisible = false;
function rolloverOn() {
  var layer = document.getElementById('rollover');
  rolloverVisible = true;              
  /* visibility set after loading */
}
function rolloverOff() {                          
  var layer = document.getElementById('rollover');
  rolloverVisible = false;
  layer.style.visibility = 'hidden';
  layer.style.top = '-1000px'; // for IE6/7
  layer.innerHTML = '';
}
function moveRollover(event) {
  if(!rolloverVisible) return;
  var layer = document.getElementById('rollover');
  var x = event.clientX + 20;
  var y = Math.min(document.body.clientHeight-325, event.clientY);
  layer.style.left = x+'px'; 
  layer.style.top = y+'px'; 
}

// generic ajax functions
function loadExternalHtml(url, targetid, loadingtext) {
  var tg = document.getElementById(targetid);
  if(loadingtext != false) tg.innerHTML = loadingtext;
  
  var http_request = false;

  if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
      http_request.overrideMimeType('text/html');
    }
  } else if (window.ActiveXObject) { // IE
    try {
      http_request = new ActiveXObject('Msxml2.XMLHTTP');
    } catch (e) {
      try {
        http_request = new ActiveXObject('Microsoft.XMLHTTP');
      } catch (e) {}
    }
  }

  if (!http_request) {
    alert('Error: Cannot create an XMLHTTP instance');
    return false;
  }
  http_request.onreadystatechange = function() { loadExternalHtmlResult(http_request, targetid); };
  http_request.open('GET', url, true);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(url);
}
function loadExternalHtmlResult(http_request, targetid) {  
  var tg = document.getElementById(targetid);
  if(http_request.readyState == 4) {
    if (http_request.status == 200) {
      tg.innerHTML = http_request.responseText;
      tg.style.visibility = 'visible';
    } else {
      tg.innerHTML = '<i>Error '+http_request.status+'</i>';
    }       
  }
}
