<!--
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function copybillingtoshipping() {
  var form = document.checkoutform;
  form.ship_firstname.value = form.bill_firstname.value;
  form.ship_lastname.value = form.bill_lastname.value;
  form.ship_company.value = form.bill_company.value;
  form.ship_address1.value = form.bill_address1.value;
  form.ship_address2.value = form.bill_address2.value;
  form.ship_city.value = form.bill_city.value;
  form.ship_country.value = form.bill_country.options[form.bill_country.selectedIndex].value;
  form.ship_stateprov.value = form.bill_stateprov.options[form.bill_stateprov.selectedIndex].value;
  form.ship_zipcode.value = form.bill_zipcode.value;
  form.ship_phone.value = form.bill_phone.value;
  form.ship_fax.value = form.bill_fax.value;
}

function post_checkout(anchor_name) {
  var form = document.checkoutform;
  if (anchor_name != "") { form.action = "/checkout.php#" + anchor_name; }
  // show working status
  show_working();
  form.submit();
}

function assign_id(value, use_value) {
  var form = document.addressbookform;
  if (use_value) {
    form.entry_id.value = value;
  } else {
    var index = form.addresslist.selectedIndex;
	if (index != -1) { form.entry_id.value = form.addresslist.options[index].value; }
  }
}

function post_addressbook(action) {
  var form = document.addressbookform;
  if (action == "") { action = "view"; }
  form.action.value = action;
  // show working status
  show_working();
  form.submit();
}

function post_register(anchor_name) {
  var form = document.registerform;
  if (anchor_name != "") { form.action = "/register.php#" + anchor_name; }
  // show working status
  show_working();
  form.submit();
}

function popup_window(mypage, myname, w, h, scroll, titlebar, resize) {
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable='+resize
  win = window.open(mypage, myname, winprops)
  if (parseInt(navigator.appVersion) >= 4) {
    win.window.focus();
  }
}

function show_status(message) {
  window.status = message;
  return true;
}

function show_working() {
  var target = document.getElementById('status');
  if (document.images) {
     // for FireFox and Opera, to hide the flicker because of dumb IE
	 document.images["statusimg"].src = statpic.src  
     // IE stupidity, once JS is involked, animations stop
	 // start the status image using setTimeout
     setTimeout('document.images["statusimg"].src = statpic.src', 1);
  }
  document.body.style.cursor = "wait";
  target.style.display="";
}

function select_existing_customer() {
  var form = document.frmlogin.custtype[1].checked = true;
}

function logoutPrompt() {
  if (confirm("Are you sure you want to end your session?")) {
    // show working status
    show_working();
    return true;
  } else {
    return false;
  }
}

function delAbookEntryPrompt() {
  if (confirm("Are you sure you want to delete this address book entry?")) {
    // show working status
    show_working();
    return true;
  } else {
    return false;
  }
}

function setStatusPosition() {
  var areawidth = 77; // status area width
  var areaheight = 59; // status area height
  // Safari sucks, use a different way of gathering info
  if (BrowserDetect.browser == "Safari") {
    innerW = "window.innerWidth";
    innerH = "window.innerHeight";
    offsetX = "window.pageXOffset";
    offsetY = "window.pageYOffset";
  } else {
    innerW = "document.body.clientWidth";
    innerH = "document.body.clientHeight";
    offsetX = "document.body.scrollLeft";
    offsetY = "document.body.scrollTop";
  }
  // calculate x/y positions
  var availableX = eval(innerW);
  var availableY = eval(innerH);
  var currentX = eval(offsetX);
  var currentY = eval(offsetY);
  x = (availableX - (areawidth) + currentX);
  y = (availableY - (areaheight) + currentY);
  // move the status position to the bottom right corner of the browser client screen
  document.getElementById("status").style.left = x;
  document.getElementById("status").style.top = y;
  // keep calling this function to keep status in corner
  setTimeout("setStatusPosition()", 10);
}

function GetXmlHttpObject() {
  var xmlHttp = null;
  try {
    // Firefox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
  } catch (e) {
    // Internet Explorer
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}

// preload animated status image
if (document.images) {
  var statpic = new Image(32, 32);
  statpic.src = "/images/status-grey.gif";
}

// insert into onload event
addLoadEvent(setStatusPosition);
// -->
