var responseSuccessCart = function(o) {
  var div = document.getElementById('cart');
  if (o.responseText !== undefined) {
    div.innerHTML = o.responseText;
    //if (o.responseText.substr(0,16) == "Login Successful") {
    //  location.href = "resource.list.do";
    //}
  } else {
    div.innerHTML = "[ERROR] Unable to update cart.  Try again later.";
  }
};

var responseFailure = function(o) {
  var div = document.getElementById('cart');
  div.innerHTML = "[ERROR] Unable to update cart.  Try again later.";
};

var callbackCart =
{
  success:responseSuccessCart, 
  failure:responseFailure, 
  timeout: 10000
};

function cart(itemID, qty, op) {
  var div = document.getElementById('cart');
  div.innerHTML += "<br/><br/><img src='/core/images/progress.gif' alt='Updating Cart' /> Updating Cart ...<br/><br/>";
  if (op == 0) {
    option = "";
    div = document.getElementById('optionFirstID_' + itemID); if (div != null) option = div.value;
    var transaction = YAHOO.util.Connect.asyncRequest('GET', '/cart.add.rpc?itemID=' + itemID + '&qty=' + qty + '&option=' + option, callbackCart);
  } else if (op == 1) {
    var transaction = YAHOO.util.Connect.asyncRequest('GET', '/cart.remove.rpc?itemID=' + itemID, callbackCart);
  } else {
    var transaction = YAHOO.util.Connect.asyncRequest('GET', '/cart.clear.rpc', callbackCart);
  }
}

function checkout(track) {
  if (track) pageTracker._trackPageview("/cart.checkout.do");
  document.checkoutform.submit();
}

var divtxt = "";

function whiteBox(imgno, width, height) {
	divtxt = "<div style='float:center; display: block; clear: both;'><img title='Close Button' alt='Close Button' src='/core/images/close-button.gif' onclick='document.getElementById(\"popup\").style.display=\"none\"; document.getElementById(\"fade\").style.visibility=\"hidden\";' align='right'><br/><br/>";
	divtxt += "<div id='imgdiv'>";
	divtxt += document.getElementById("lightimage" + imgno).innerHTML;
	divtxt += "</div>";
	divtxt += "</div>";
}

document.write("<div id='fade' class='black_overlay'></div>");

function lightBox(url, val, imgwidth, imgheight) {
  viewportwidth = window.innerWidth;
  viewportheight = window.innerHeight;
  imgwidth = viewportwidth - 200;
  imgheight = viewportheight - 200;
	whiteBox(val, imgwidth, imgheight);
	document.getElementById("fade").style.visibility="visible";
  itemimg = new Image();
  itemimg.src = url;
	width = screen.width;
	width = (width - 500)/2;
	height = screen.height;
	height = (height - 659)/2;
	lightDiv = document.getElementById("popup");
	lightDiv.style.display = "block";
  lightDiv.innerHTML  = divtxt;
	itemwidth = itemimg.width;
	itemheight = itemimg.height;
	lightDiv.style.width =  (imgwidth + 10) + "px";
	lightDiv.style.height = (imgheight + 50) + "px";
	//alert(viewportwidth + " - " + viewportheight);
	left = 100;
	top = 100;
	lightDiv.style.left = Number(left) + "px";
	lightDiv.style.top = Number(top) + "px";
}
