function loadSiteTitle()
{
    sitetitle.filters[0].apply();
    sitetitle.src = "images/sitetitle_2.gif";
    sitetitle.filters[0].play();
}
/* This is used to update the P and P value when a different 
   destination is selected from the radio buttons.
   
   When more books are added we'll need to update each line
   either by adding each line or looping through them */
function UpdatePandP(amount) {

    document.getElementById("PandP1").value = amount;
    /*document.getElementsByName("handling_cart")[0].value = amount;*/
    UpdateTotal();
}
/* The following code was added by the ShoppingBasket class from C:\Data\SiteOne\Themes and Variations\SideTextMinimal\..\CommonFiles\PayPal.js */
function penceToPounds(amount)
{
	var i = parseFloat(amount/100);
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = "&pound;" + s;
	return s;
}

function utils_is_number_string (InString)
{
	if(InString.length==0) return (false);
	var RefString="1234567890";
	for (Count=0; Count < InString.length; Count++)
	{
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)
		return (false);
	}
	return (true);
}

/*  If any of the form objects are SELECTs, make them invisible if 
    there are no options to select. */
   
function maybeHide(objectIn)
{
    if (objectIn != null)
	{
		if (objectIn.tagName == "SELECT")
		{
			if (objectIn.children.length == 0)
			{
				objectIn.style.visibility="hidden";
			}
		}
		else
		{
			if (objectIn.tagName == "TEXTAREA")
			{
				if (objectIn.value.length == 0)
				{
					objectIn.style.visibility="hidden";
					objectIn.style.height="0";
				}
			}
		}
	}
}


/*  Update the 'Item' amounts, 'Postage and Packing' amounts and 'Total to Pay' amounts shown 
    on the screen and populate the PayPal hidden input fields ready for payment */
function UpdateTotal()
{
    var MaxItems = 1;
    var Count;
    var ppIndex = 1;
    if (!document.getElementById) return;
    //alert("Update Total");
    var totalValue = 0;
    var totalPandP = 0;
	for (Count=1; Count <= MaxItems; Count++)
	{
        maybeHide(document.getElementById("Options1Content" + Count));
        maybeHide(document.getElementById("Options2Content" + Count));
	
        itemQuantityObj = document.getElementById("Quantity" + Count);
        if (!utils_is_number_string(itemQuantityObj.value))
        {
            itemQuantityObj.value = "";
        }
        if (itemQuantityObj.value == "")
        {
            itemQuantity = 0;
        }
        else
        {
            itemQuantity = parseInt(itemQuantityObj.value);
        }
            
        itemPriceObj = document.getElementById("Price" + Count);
        itemValuePence = Math.round(parseFloat(itemPriceObj.innerHTML) * itemQuantity * 100);
        totalValue = totalValue + itemValuePence;
        itemValueObj = document.getElementById("Value" + Count);
        itemValueObj.innerHTML = penceToPounds(itemValuePence);

        
        itemPandPObj = document.getElementById("PandP" + Count);
        itemPandPPence = Math.round(parseFloat(itemPandPObj.value) * itemQuantity * 100);
        totalPandP = totalPandP + itemPandPPence;
        
        /* Update the current PayPal form item then increment the PayPal index */
        if (itemQuantity > 0)
        {
            document.getElementById("pp_item_name_" + ppIndex).value
                = document.getElementById("Item" + Count).innerHTML;
            document.getElementById("pp_amount_" + ppIndex).value
                = itemPriceObj.innerHTML;
            document.getElementById("pp_quantity_" + ppIndex).value
                = itemQuantity;
            document.getElementById("pp_shipping_" + ppIndex).value
                = document.getElementById("PandP" + Count).value;
            document.getElementById("pp_shipping2_" + ppIndex).value
                = document.getElementById("PandP" + Count).value;
            
             if (document.getElementById("Options1Name" + Count) == null)
            {    
                document.getElementById("pp_options1_name_" + ppIndex).value = "";
                document.getElementById("pp_options1_content_" + ppIndex).value = "";
            }
            else
            {  
               document.getElementById("pp_options1_name_" + ppIndex).value
                = document.getElementById("Options1Name" + Count).value;
            document.getElementById("pp_options1_content_" + ppIndex).value 
            = document.getElementById("Options1Content" + Count).value; 
            }
            if (document.getElementById("Options2Name" + Count) == null)
			{ 
			 document.getElementById("pp_options2_name_" + ppIndex).value = "";
             document.getElementById("pp_options2_content_" + ppIndex).value = "";
            }
            else
            {
             document.getElementById("pp_options2_name_" + ppIndex).value
                = document.getElementById("Options2Name" + Count).value;
            document.getElementById("pp_options2_content_" + ppIndex).value
                = document.getElementById("Options2Content" + Count).value;
             }  
            ppIndex++;
        }
	}
	
	/* Clear remaining items in PayPal form */
    for (Count=ppIndex; Count <= MaxItems; Count++)
    {
        document.getElementById("pp_item_name_" + ppIndex).value = "";
        document.getElementById("pp_amount_" + ppIndex).value = "";
        document.getElementById("pp_quantity_" + ppIndex).value = "";
    }

	/* If we haven't specified item level postage and packing, perhaps there is a flat rate 
	   postage and packing value specified somewhere on the page for the whole cart [cartPandP]3.80
	*/  
	/*     
	if (totalPandP == 0  && totalValue > 0)
	{
		handlingCartObj = document.getElementById("handling_cart");
		if (handlingCartObj != null)
		{
			totalPandP = Math.round(parseFloat(handlingCartObj.value) * 100);
			ppHandlingCartObj = document.getElementById("ppHandlingCart");
			ppHandlingCartObj.name = "handling_cart";
			ppHandlingCartObj.value = penceToPounds(totalPandP);
		}
    }
    */
	if (totalPandP == 0  && totalValue > 0)
	{
		handlingCartObj = document.getElementsByName("handling_cart")[0];
		if (handlingCartObj != null)
		{
			totalPandP = Math.round(parseFloat(handlingCartObj.value) * 100);
		}
    }
    
    /* Update the Postage and Packing amount and Total to Pay amounts on the screen (these
        values are not passed to PayPal, they are recalculated from the individual item values */
    document.getElementById("ValuePandP").innerHTML =  penceToPounds(totalPandP);
    totalValue = totalValue + totalPandP;
    document.getElementById("ValueTotal").innerHTML = "<b>" + penceToPounds(totalValue) + "</b>";
}

