// JavaScript Document

function ApplyDiscount()
{
	window.location = serverpath + "/ecom/ApplyDiscount.php?g_strDiscount=" + document.getElementById('txtOfferCode').value + "&g_strScreen=Book.html";
}

function DeleteItem(p_strISBN, p_strScreen)
{
	window.navigate("/digitaltextbooks/DeleteItem.php?g_strISBN=" + p_strISBN + "&g_strScreen=" + p_strScreen);
}

function UpdateItem(p_strISBN, p_intQty, p_strTERM)
{ 

	window.navigate("/digitaltextbooks/UpdateItem.php?g_strISBN=" + p_strISBN + "&g_intQty=" + document.getElementById(p_intQty).value + "&g_strTERM=" + p_strTERM);
}

function AddItem(p_strISBN, p_strPromoCode, p_strTerm)
{
	makeRequest("/digitaltextbooks/AddItem.php?g_strISBN=" + p_strISBN + "&g_strPromoCode=" + p_strPromoCode + "&g_strTerm=" + p_strTerm);
}

//function AddItem(p_strISBN, p_strPromoCode)
//{
//	makeRequest("/digitaltextbooks/AddItem.php?g_strISBN=" + p_strISBN + "&g_strPromoCode=" + p_strPromoCode);
//}

function makeRequest(url) 
{
    var http_request = false;

    if (window.XMLHttpRequest) 
	{ // Mozilla, Safari, ...
        http_request = new XMLHttpRequest();
        
		if (http_request.overrideMimeType) 
		{
            http_request.overrideMimeType('text/xml');
             // See note below about this line
        }
     } 
	 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('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
    http_request.onreadystatechange = function() { alertContents(http_request); };
    http_request.open('GET', url, true);
    http_request.send(null);
}

function alertContents(http_request) 
{
    if (http_request.readyState == 4) 
	{
        if (http_request.status == 200) 
		{
			
           //added line to check object exists
			var objExist=document.getElementById('shoppingbasketview'); 
			if(objExist) 
			{ 
				
				document.getElementById('shoppingbasketview').innerHTML = http_request.responseText;
			}
         } 
		else
		{
            alert('There was a problem with the request.');
        }
    }
}

makeRequest('/digitaltextbooks/BasketCount.php');
