function recomputeGiftTotal(stockIds) {
  var total = 0;
  var price;
  var amt;
  for (i = 0; i < stockIds.length; i++) {
    quantity = $("#quantity\\[" + stockIds[i] + "\\]").val();
    price = $("#price\\[" + stockIds[i] + "\\]").val();
    total = total + (quantity * price);
  }
  $("#dynamic-total").html(formatCurrency(total));
}

function formatCurrency(strValue)
{
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
		for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		    dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		    	     dblValue.substring(dblValue.length-(4*i+3));
			     return (((blnSign)?'':'-') + '$' + dblValue + '.' + strCents);
}

function popup(mylink, windowname) {
  if (! window.focus)return true;
  var href;
  if (typeof(mylink) == 'string') {
    href=mylink;
  } else {
    href=mylink.href;
  }
  window.open(href, windowname, 'width=500,height=450,scrollbars=yes');
  return false;
}
