//<!--

var RowSlider;
var RowCount = 0;
var AjaxURL = "";
var ContentID = 0;
var BasketElementID = 'BasketHolder';
var IsUpdate;
var TempButton = "";

function CreateLoader(noOfRows, mainUrlPart)
{
    RowCount = noOfRows;
    AjaxURL = mainUrlPart;
    document.write('<div id="TempHolder"></div>');
}

function SetVariables(itemID, isUpdateBool)
{
    ContentID = itemID;
    IsUpdate = isUpdateBool;
    
    if (IsUpdate)
    {
        UpdateQuantity();
    }
    else
    {
        RemoveProduct();
    }
}


function UpdateQuantity()
{
    var quantity = document.getElementById("Quantity" + ContentID).value;
    
    if (quantity < 1 || !IsNumeric(quantity))
    {
        SetVariables(ContentID, false)
    }
    else
    {
        var thisAjaxURL = AjaxURL + ContentID + "&Quantity" + ContentID + "=" + quantity;
        fnAjaxRequest('TempHolder', thisAjaxURL);
    }
}

function RemoveProduct()
{
    var thisAjaxURL = AjaxURL + ContentID + "&Remove" + ContentID + "=" + ContentID;
    RowSlider = new Fx.Slide('Row' + ContentID);
    fnAjaxRequest('TempHolder', thisAjaxURL);
}

function MainBasketCompletion()
{
    if (IsUpdate)
    {
        UpdateTotals();
    }
    else
    {
        HideRow()
    }
}

function HideRow()
{
    RowSlider.toggle();
    RowCount--;
    
    if (RowCount == 0)
    {
        document.getElementById(BasketElementID).className = "notSet";
        fnAjaxRequest(BasketElementID, AjaxURL);
    }
    else
    {
        UpdateTotals();
    }
}


function UpdateTotals()
{
    if (IsUpdate)
    {
        if (TempButton == "")
        {
            var buttonHolder = document.getElementById("UpdateHolder" + ContentID);
            TempButton = buttonHolder.innerHTML;
            setTimeout("ChangeText()",1500);
            buttonHolder.innerHTML = '<strong class="error">Item Updated</strong>';
        }
        document.getElementById("LinePrice" + ContentID).innerHTML = document.getElementById("AjaxLinePrice").innerHTML;
    }
    
    if (document.getElementById("TotalPrice") != null && document.getElementById("AjaxTotalPrice") != null)
    {
        document.getElementById("TotalPrice").innerHTML = document.getElementById("AjaxTotalPrice").innerHTML;
    }
}

function IsNumeric(strString)
{
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0)
   {
        return false;
   }

   for (i = 0; i < strString.length && blnResult == true; i++)
   {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1)
        {
            blnResult = false;
        }
   }
   return blnResult;
}

function ChangeText()
{
    document.getElementById("UpdateHolder" + ContentID).innerHTML = TempButton;
    TempButton = "";
}
//-->