// JavaScript Document
var http = false;
var ajaxurl = 'ajax.aspx';

function createRequestObject()
{
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

var currentID = 0;
var currentPrice = 0.00;

function addItem(pID,pName,pISBN,pCat,pAuthorID,pAuthor,pPrice, pStatus)
{
    http = createRequestObject(); 
    if(http)
    {
		currentID = pID;
		currentPrice = pPrice;

		http.open("GET", "addToBasket.asp?pID=" + pID + "&pName=" + pName + "&pISBN=" + pISBN + "&pCat=" + pCat + "&pAuthorID=" + pAuthorID + "&pAuthor=" + pAuthor + "&pPrice=" + pPrice + "&pStatus=" + pStatus, true);
        http.onreadystatechange = handleAddProduct;
        http.send(null);
    }
}

function handleAddProduct()
{
	if(http.readyState == 4)
	{
	    var elem = document.getElementById('addedToBasket' + currentID);
		if(elem != null)
		{
			elem.style.display = '';
		}
		var elem2 = document.getElementById('basketTotal');
		elem2.innerHTML = CurrencyFormatted(Number(elem2.innerHTML) + Number(currentPrice));
	}
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}


function cursorOver() {
    document.body.style.cursor = 'pointer';
}

function cursorClear() {
    document.body.style.cursor = 'default';
}
