



















































































// <script type="text/javascript">document.location = 'http://ecommerce.shopintegrator.com:80/client/Amaethon/GetShopScriptClientVersion?CLIENT_ID=robust081002'; </script>



















































































var g_clientID = 'robust081002'; var g_baseURL = 'http://ecommerce.shopintegrator.com:80/'; var g_serverVersion = 'Amaethon'; var g_jsessionID = ';SID=pr3vMSZXjvnjTOYDL8YUaw**1283514968865399000';var g_sessionTimeOutInSeconds = 1200; 
//Plugin Types
var g_pluginSellItem = 'si'; var g_pluginSellItemButton = 'sib'; var g_pluginDisplayItemPriceAndOffer = 'dipao'; var g_pluginShowItemPrice = 'sip'; var g_pluginShowItemDescription = 'sid'; var g_pluginShowItemWeight = 'siw'; var g_pluginShowChangeCurrencyControl = 'scc'; var g_pluginCheckoutControl = 'sc'; var g_pluginCheckoutLinkControl = 'scl'; var g_pluginViewBasketControl = 'svb'; var g_pluginViewBasketLinkControl = 'svbl'; var g_pluginSellCategoryTable = 'sct'; var g_pluginSellCategoryTableBuyNow = 'sctbn'; var g_pluginSellItemBuyNow = 'sibn'; var g_pluginSellItemBuyNowButton = 'sibnb'; var g_pluginShowTotalQuantityItems = 'stqi'; var g_pluginShowTotalCostItems = 'stci'; var g_pluginShowMiniBasketList = 'smbl'; var g_pluginSellCategoryFullLayout = 'scfl'; var g_pluginSellCategoryFullLayoutSearch = 'scfls'; 
































//alert('Client ID:'+g_clientID);
//var g_baseURL = "http://localhost:9024/test/";
var g_shopintwin = null;
var g_checkForPaymentInitiated = null;
var g_existingPageSelectLists;
var g_existingPageSelectListsDisplaySettings;

//
//Success Images START
//
var tickAnimatedRemainsImg = "images/shopping/tick_animated_remains.gif";
var tickAnimatedRemainsImgURL = g_baseURL+tickAnimatedRemainsImg;

//var shoppingListSuccessImg = "images/shopping/tick_animated.gif";
var shoppingListSuccessImg = tickAnimatedRemainsImg;
var shoppingListSuccessImgURL = g_baseURL+shoppingListSuccessImg;
var shoppingListSuccessImgHTML = "<img src='"+shoppingListSuccessImgURL+"' height='25'>"

var createItemSuccessImg = "images/shopping/addedtobasket_tick_animated.gif";
var createItemSuccessImgURL = g_baseURL+createItemSuccessImg;
var createItemSuccessImgHTML = "<img src='"+shoppingListSuccessImgURL+"'"
                                                + " height='75'"
                                                + " border='10'"
                                                + " class='icon' />";

var itemSuccessAddToBasketImgHTML = "<table width='100%' border='0' cellpadding='0' cellspacing='0'><tr><td align='center'>"
                                                + "<img src='"+shoppingListSuccessImgURL+"'"
                                                + " height='50'"
                                                + " border='10'"
                                                + " class='icon' />"
                                                + "</td></tr></table>";

var createItemSuccessImgTwoOptionsHTML = "<img src='"+shoppingListSuccessImgURL+"'"
                                                + " height='50'"
                                                + " border='10'"
                                                + " class='icon' />";


//
//Success Images END
//

//
//Shopping Basket Images START
//

var waitImg = new Image();
waitImg.src = g_baseURL+"/images/wait.gif";	//Preload the wait image used as the splash page when the shopping basket launches

//
//Shopping Basket Images END
//

var g_targetPage;
var g_lastTheNode;
var g_lastItemTransientUniquePageID;
var g_lastFormName;
var g_sessionID;
var g_sessionIDTimerID;
var g_firstCallToServer = true;
var g_secondCallToServer = true;
var g_secondCallToServerDelay = 300;
var g_otherCallToServerDelay = g_secondCallToServerDelay;
var g_serverCallDelayIncrement = 200;
var g_registeredPluginType = new Array();
var g_registeredPluginID = new Array();
var g_registeredPluginUniqueNumber = new Array();
var g_registeredPluginURL = new Array();
var g_SID = 'none';

obtainSupportingScripts();

function buyItem(theNode, itemID, uniqueNumber, formName, plugin)
{
            //alert('buyItem called plugin:'+plugin+' itemID:'+itemID);
            var itemTransientUniquePageID = itemID+uniqueNumber;
            var itemRequiredQuantity = getItemRequiredQuantity(itemTransientUniquePageID);

            if(itemRequiredQuantity > 0)
            {
                        var itemRequiredQuantityKeyValuePair = '&QUANTITY='+itemRequiredQuantity;

                        var extraInfoValue = '';

                        var extraInfoObj = document.getElementById('EXTRA_INFO_'+itemTransientUniquePageID);
                        //alert('buyItem extraInfoObj: '+extraInfoObj)
                        if(extraInfoObj != 'undefined' && extraInfoObj != null && extraInfoObj != "")
                        {
                                    //The item may provide extra specific GET parameters in the call to the server
                                    extraInfoValue = extraInfoObj.value;
                                    //alert('buyItem extraInfoValue: '+extraInfoValue)
                        }


                        var buyerChoice0ListValueKeyValuePair = '';
                        var buyerChoice0ListValueKey = 'BUYER_CHOICE0_'+itemTransientUniquePageID;
                        var buyerChoice0ListValueObj = document.getElementById(buyerChoice0ListValueKey);

                        if(buyerChoice0ListValueObj != 'undefined' && buyerChoice0ListValueObj != null && buyerChoice0ListValueObj != "")
                        {
                                    //alert('buyItem buyerChoice0ListValueObj: '+buyerChoice0ListValueObj);
                                    buyerChoice0ListValueKeyValuePair = '&'+buyerChoice0ListValueKey+'='+buyerChoice0ListValueObj.value;
                        }

                        var buyerChoice1ListValueKeyValuePair = '';
                        var buyerChoice1ListValueKey = 'BUYER_CHOICE1_'+itemTransientUniquePageID;
                        var buyerChoice1ListValueObj = document.getElementById(buyerChoice1ListValueKey);

                        if(buyerChoice1ListValueObj != 'undefined' && buyerChoice1ListValueObj != null && buyerChoice1ListValueObj != "")
                        {

                                    //alert('buyItem buyerChoice1ListValueObj: '+buyerChoice1ListValueObj);
                                    buyerChoice1ListValueKeyValuePair = '&'+buyerChoice1ListValueKey+'='+buyerChoice1ListValueObj.value;
                        }

                        var URL = g_baseURL+'client/'+g_serverVersion+'/AddItemBasket?PLUGIN='+plugin+'&ID='+itemID+'&unique='+uniqueNumber+itemRequiredQuantityKeyValuePair+buyerChoice0ListValueKeyValuePair+buyerChoice1ListValueKeyValuePair+extraInfoValue;

        //Resets the communication mechanism back to the start.
        resetCallToServer();

        callToServer(plugin, itemID, uniqueNumber, URL);
    }
    else
    {
                return false;
    }
}




//Traverse the node tree upwards until we find
// the encapsulating form, then submit it.
function getForm(theNode)
{
            var theParent;
            var counter = 0;
            var theForm = null;

            //counter is safety measure
            while(theNode != null && theNode != 'undefined' && counter++ < 100)
            {
                        theNode = theNode.parentNode;
                        if(theNode != null && theNode != 'undefined' && theNode.nodeName == "FORM" )
                        {
                                    //We have found the form
                                    theForm = theNode;
                                    break;
                        }
            }

            if(theForm == null)
            {
                        alert("No form found, submit not possible.");
            }

            return theForm;
}


function submitVirtualForm(theNode, itemTransientUniquePageID, formName)
{
    var virtualForm = createVirtualForm(theNode, itemTransientUniquePageID, formName);
    if(virtualForm != null || virtualForm != 'undefined')
    {
            //Used for re-submission if required due to a shopper shopping with multiple shop integrator clients.
            //alert('submitVirtualForm before storing submission data g_lastTheNode:'+g_lastTheNode+' g_lastItemTransientUniquePageID:'+g_lastItemTransientUniquePageID+' g_lastFormName:'+g_lastFormName);
            g_lastTheNode = theNode;
            g_lastItemTransientUniquePageID = itemTransientUniquePageID;
            g_lastFormName = formName;
            //alert('submitVirtualForm after storing submission data g_lastTheNode:'+g_lastTheNode+' g_lastItemTransientUniquePageID:'+g_lastItemTransientUniquePageID+' g_lastFormName:'+g_lastFormName);

        //blockTargetUnloadPage();
        virtualForm.submit();
        cleanUpVirtualForm(virtualForm);
    }
}

function cleanUpVirtualForm(virtualFormWrapperObj)
{
    //Delete the virtual form to avoid HTML tag ID values being duplicate
    //alert('cleanUpVirtualForm data:'+virtualFormWrapperObj.parentNode.innerHTML);
    virtualFormWrapperObj.parentNode.innerHTML = "";
}

function createVirtualForm(theNode, itemTransientUniquePageID, formName)
{
    //alert('createVirtualForm called');
    var formToSubmit = getVirtualFormWrapper(theNode);
    //alert('createVirtualForm formToSubmit:'+formToSubmit.innerHTML);

    var formTagDetails = document.getElementById('formTagDetails'+itemTransientUniquePageID);
    //alert('createVirtualForm formTagDetails object:'+formTagDetails+ ' using formTagDetails'+itemTransientUniquePageID);


    //This is to avoid somebody shopping in multiple shops from Shop Integrator,
    // and the app getting confused and showing an empty shopping basket.
    //If we have any hidden session info, we will send this as well
    //var thisShopperSessionInfo = '';
    //if(g_sessionID != undefined && g_sessionID != 'undefined' && g_sessionID != '')
    //{
    //        //alert('createVirtualForm found g_sessionID:'+g_sessionID);
    //        thisShopperSessionInfo = '<input type=hidden name=SHOPPER_SESSION_ID value="'+g_sessionID+'">';
    //}


    //Create the virtual form and add it to the page.
    var formContent = formTagDetails.value+formToSubmit.innerHTML+thisShopperSessionInfo+"</form>";
    var virtualForm = addHiddenFormToPage(formName, formContent);


    return virtualForm;
}

//Traverse the node tree upwards until we find
// the encapsulating form, then submit it.
function getVirtualFormWrapper(theNode)
{
            //alert('getVirtualFormWrapper called');

    var theParent;
            var counter = 0;
            var theForm = null;

            //counter is safety measure
            while(theNode != null && theNode != 'undefined' && counter++ < 100)
            {
                        theNode = theNode.parentNode;
                        if(theNode != null && theNode != 'undefined' && theNode.nodeName == "SPAN" && theNode.className == "VIRTUALFORM")
                        {
                                    //We have found the form
                                    theForm = theNode;
                                    break;
                        }
            }

            if(theForm == null)
            {
                        alert("No VIRTUALFORM found, submit not possible.");
            }

            return theForm;
}



function submitForm(theNode)
{
            var formToSubmit = getForm(theNode);
            if(formToSubmit != null || formToSubmit != 'undefined')
            {
                        blockTargetUnloadPage();
                        formToSubmit.submit();
            }
}

function callToServerNoDelay(itemName, uniqueNumber, URL) {

    //alert('callToServerNoDelay for itemName:'+itemName);
            if (!document.createElement) {return true};

            var IFrameObj; // our IFrame object
            var IFrameDoc;

            //alert('callToServerNoDelay URL:'+URL);
            //
            //REMOTE URL
            //
            //The URL of where the service resides
            //example
            // var URL = "http://localhost:9024/test/client/Amaethon/GetShopControl?ID=CHECKOUT_CONTROL"+"&unique=1234&CLIENT_ID=xyz123";

            //Add the client ID to the request
            if( URL.indexOf("?") != -1)
            {
                        URL = URL + '&CLIENT_ID='+g_clientID+'&SID='+getSID();

                        var currentDate = new Date();
                        URL = URL + '&instancetime='+currentDate.getTime();
            }
            //alert('callToServerNoDelay after applying client ID URL:'+URL);


            //provide a "loading" message
            //var responseMessage = document.getElementById('responseMessage');
            //var responseMessage = document.getElementById('shopItem_'+itemName+uniqueNumber);
            //alert('callToServerNoDelay responseMessage obj:'+responseMessage);
            //alert('callToServerNoDelay responseMessage ID:'+responseMessage.id);
            //responseMessage.style.display = 'inline';
            //responseMessage.innerHTML = 'loading data...';


            //Load the response data script
            //alert('callToServerNoDelay Loading the response script');
            var head = document.getElementsByTagName("head")[0];
            script = document.createElement('script');
            //script.id = 'uploadScript';
            script.type = 'text/javascript';
            script.src = URL;
            head.appendChild(script);

            return false;
}

//TEST DEBUG CODE
var callToServerTestDelays = "";
//window.setTimeout('alert("callToServerTestDelays="+callToServerTestDelays)',10000);

function callToServer(plugin, itemName, uniqueNumber, URL) {
            //alert('callToServerNEW called');

            //Delay before making request to server.
            // This spreads out multiple requests from each tag on the same page.
            // This gives the server a chance to respond, otherwise the browser may just do nothing from time to time.
    if(g_firstCallToServer == false)
    {
        if(g_secondCallToServer == false)
        {
            //Gives the first call the time to obtain a session ID
            // otherwise subsequent calls are so close together, the same
            // browser window ends up with multiple session ID's in Internet Explorer!
            var myCallToServerDelay = g_otherCallToServerDelay;
            //Increase the delay for the next call so it happens after this call,
            // attempting to create a serial set of calls rather than a parallel set of calls from all
            // page plugins at once.
            g_otherCallToServerDelay = g_otherCallToServerDelay + g_serverCallDelayIncrement;
            window.setTimeout('callToServerNoDelay("'+itemName+'", '+uniqueNumber+',"'+URL+'")', myCallToServerDelay);
            //Test Debug Code
            callToServerTestDelays = callToServerTestDelays + ":"+itemName+" delay="+myCallToServerDelay;
        }
        else
        {
            //window.setTimeout('registerSecondCallToServer()', g_secondCallToServerDelay);
            registerSecondCallToServer();
            window.setTimeout('callToServerNoDelay("'+itemName+'", '+uniqueNumber+',"'+URL+'")', g_secondCallToServerDelay);
            //Test Debug Code
            callToServerTestDelays = callToServerTestDelays + ":"+itemName+" delay="+g_secondCallToServerDelay;
        }
    }
    else
    {
        //Subsequent calls will be delayed to ensure server session ID's are allocated
        // properly, otherwise a single web page may have mutliple server session ID's.
        g_firstCallToServer = false;
        callToServerNoDelay(itemName, uniqueNumber, URL);
        //Test Debug Code
        callToServerTestDelays = callToServerTestDelays + ":"+itemName+" no delay";
    }

            return false;
}


function registerSecondCallToServer()
{
    g_secondCallToServer = false;
}

function resetCallToServer()
{
    g_firstCallToServer = true;
    g_secondCallToServer = true;
    g_otherCallToServerDelay = g_secondCallToServerDelay;
}

function getIFrameDoc(IFrameObj)
{
            var IFrameDoc = null;

            if (IFrameObj.contentDocument) {
                        // For NS6
                        IFrameDoc = IFrameObj.contentDocument;
            } else if (IFrameObj.contentWindow) {
                        // For IE5.5 and IE6
                        IFrameDoc = IFrameObj.contentWindow.document;
            } else if (IFrameObj.document) {
                        // For IE5
                        IFrameDoc = IFrameObj.document;
            }

            return IFrameDoc;
}

function handleMultiListResponse(providedData, itemName, uniqueNumber, multiListName)
{
            //alert('handleMultiListResponse called');
            var itemCode = itemName + uniqueNumber;
            //alert('handleMultiListResponse itemCode:'+itemCode);

            var successSpanID = 'successImgArea'+itemCode;

            //alert('handleMultiListResponse successSpanID:'+successSpanID);
            var spanForSuccessAck = document.getElementById(successSpanID);
            //alert('handleMultiListResponse spanForSuccessAck obj:'+spanForSuccessAck);
            spanForSuccessAck.innerHTML = providedData;

            delayedRemoveSuccessImg(itemName, uniqueNumber);
}


function handleResponse(providedData, itemName, uniqueNumber) {
            //alert('handleResponse called');
            //handleResponseConfigured(providedData, doc, itemName, uniqueNumber, createItemSuccessImgHTML, 'successfullyAddedItem');

            //alert('handleResponse called for itemName:'+itemName+' uniqueNumber:'+uniqueNumber);
            var responseMessage = document.getElementById('shopItem_'+itemName+uniqueNumber);
            responseMessage.innerHTML = providedData;
            delayedRemoveSuccessImg(itemName, uniqueNumber);
}



function placeItemSuccessImgIfRequired(itemName, uniqueNumber, successImgHTML, itemSuccessAreaPrefix)
{
            return 0;
            //alert('placeItemSuccessImgIfRequired called');
            var itemSuccessAreaName = itemSuccessAreaPrefix+itemName+uniqueNumber;
            //alert('placeItemSuccessImgIfRequired itemSuccessAreaName:'+itemSuccessAreaName);
            var itemSuccessArea = document.getElementById(itemSuccessAreaName);
            //alert('placeItemSuccessImgIfRequired itemSuccessArea:'+itemSuccessArea);

            if(itemSuccessArea != null || itemSuccessArea != undefined)
            {
                        alert('placeItemSuccessImgIfRequired:'+successImgHTML);
                        itemSuccessArea.innerHTML = successImgHTML;
                        delayedRemoveSuccessImg(itemSuccessAreaName, 9000);
            }
}


<!--START Script Relative Positioning Without Placement Space-->
//function cropRelativeImageSpace(iconName, innerDivName, outerDivName)
function cropRelativeImageSpace(innerDivName, outerDivName)
{
            return 0;
            //alert('cropRelativeImageSpace called');
            var image;
            var innerDiv;
            var outerDiv;

            //image = document.getElementById(iconName);
            innerDiv = document.getElementById(innerDivName);
            outerDiv = document.getElementById(outerDivName);

            if(innerDiv != null && innerDiv != 'undefined' && outerDiv != null && outerDiv != 'undefined' )
            {

                        //alert(image.offsetHeight);
                        alert("innerDiv offsetHeight:" + innerDiv.offsetHeight + "innerDiv offsetWidth:" + innerDiv.offsetWidth);
                        alert("outerDiv offsetHeight:" + outerDiv.offsetHeight + "outerDiv offsetWidth:" + outerDiv.offsetWidth);


                        //The Outer div is set to overflow hidden
                        // so this crops away the space left by the image at the end caused
                        // by moving the image a relative amount into the inner div
                        outerDiv.style.height = innerDiv.offsetHeight;
                        outerDiv.style.width = innerDiv.offsetWidth;
            }
}
<!--END Script Relative Positioning Without Placement Space-->

<!--START Script Sell Item-->
//var scriptLoaded = new Object();
function shopActive()
{
}


function getUniqueNumber()
{
            var currentDate = new Date();
            var aNumber = 1000000;
            var randomOutcome = parseInt(Math.random() * aNumber);
            var uniqueNumber = randomOutcome + parseInt(Math.random() * randomOutcome);
            return uniqueNumber;
}

function invokeCallToServer(plugin, ID, uniqueNumber, URL)
{
        var itemTransientUniquePageID = ID + uniqueNumber;
        /*
        var uniqueNumber = "" + currentDate.getHours()
        + currentDate.getMinutes()
        + currentDate.getSeconds()
        + parseInt(Math.random() * aNumber);
        */

        //alert('invokeCallToServer plugin:'+plugin+' itemTransientUniquePageID:'+itemTransientUniquePageID+' uniqueNumber:'+uniqueNumber+ ' URL:'+URL);

        //document.write('<iframe src ="" id="RSIFrame'+itemTransientUniquePageID+'" name="RSIFrame'+itemTransientUniquePageID+'" style="border: #FF9900;            border-style: none;         border-top-width: 1px;      border-right-width: 10px;             border-bottom-width: 8px;           border-left-width: 1px; border:5px;width:100px;height:100px;"></iframe>');
        //document.write('<iframe src ="" id="RSIFrame'+itemTransientUniquePageID+'" name="RSIFrame'+itemTransientUniquePageID+'" style="border: #FF9900;            border-style: none;         border-top-width: 0px;      border-right-width: 0px;   border-bottom-width: 0px;           border-left-width: 0px; border:0px;width:0px;height:0px;"></iframe>');

        //document.write('<iframe src ="" id="DISCARDCONTENT'+itemTransientUniquePageID+'" name="DISCARDCONTENT'+itemTransientUniquePageID+'" style="border: #FF9900;         border-style: none;         border-top-width: 1px;        border-right-width: 10px;             border-bottom-width: 8px;           border-left-width: 1px; border:5px;width:100px;height:100px;"></iframe>');
        //If you do not set a src value in the IFRAME you get IE6 browser warnings about unsecure content because a blank src
        // is interpreted as http and not https
        document.write('<iframe src ="'+g_baseURL+'blank.html" id="DISCARDCONTENT'+itemTransientUniquePageID+'" name="DISCARDCONTENT'+itemTransientUniquePageID+'" style="border: 0; margin: 0; padding: 0; width:0; height:0; display: none;"></iframe>');

        //document.write("<div style='      id='shopItem_"+itemTransientUniquePageID+"' border: #000000;    border-style: none;            border-top-width: 1px;     border-right-width: 1px;   border-bottom-width: 1px;           border-left-width: 1px;'></div>");
        document.write("<span id='shopItem_"+itemTransientUniquePageID+"' style='border: 0; padding: 0; margin: 0;'></span>");

        //Register the plugin on this page.
        registerPlugin(plugin, ID, uniqueNumber, URL);

        //alert('About to callToServer for plugin:'+plugin+' item ID:'+ID+" uniqueNumber:"+uniqueNumber+" URL:"+URL);
        callToServer(plugin, ID, uniqueNumber, URL);
        //alert(ID);
}

//Tracks which plugins are on a page
function registerPlugin(plugin, ID, uniqueNumber, URL)
{
    var registeredPluginArrayPostion = g_registeredPluginID.length;
    //We want the data across each array to be located in the same position across
    // all the arrays.
    g_registeredPluginID[registeredPluginArrayPostion] = ID;
    g_registeredPluginType[registeredPluginArrayPostion] = plugin;
    g_registeredPluginUniqueNumber[registeredPluginArrayPostion] = uniqueNumber;
    g_registeredPluginURL[registeredPluginArrayPostion] = URL;
}

//
//sellCategoryTable may be overloaded and optional params sent with the request.
function sellCategoryTable(listName, params)
{
            //alert('sellCategoryTable called');
            pluginProductCategory(listName, params, g_pluginSellCategoryTable);
}

//
//sellCategoryTableBuyNow may be overloaded and optional params sent with the request.
function sellCategoryTableBuyNow(listName, params)
{
            //alert('sellCategoryTableBuyNow called');
            pluginProductCategory(listName, params, g_pluginSellCategoryTableBuyNow);
}


function pluginProductCategory(listName, params, plugin)
{
            //alert('pluginProductCategory called');

            var paramsURLANDKeyValue = '';
            if(params != null && params != '' && params != 'undefined')
            {
            	//alert('sellCategoryTable params found:'+params);
            	paramsURLANDKeyValue = '&PARAMS='+encodeURIComponent(params);
            }

            var uniqueNumber = getUniqueNumber();
            var URL = g_baseURL+'client/'+g_serverVersion+'/GetItemDetails?LIST_ID=' + listName + paramsURLANDKeyValue + '&PLUGIN='+plugin+'&unique='+uniqueNumber;
            invokeCallToServer(g_pluginSellCategoryTable, listName, uniqueNumber, URL);
}


function sellItem(itemID)
{
            //alert('sellItem called');
            pluginProduct(itemID,g_pluginSellItem);
}

function sellItemButton(itemID)
{
            //alert('sellItemButton called');
            pluginProduct(itemID, g_pluginSellItemButton);
}


function sellItemBuyNow(itemID)
{
            //alert('sellItemBuyNow called');
            pluginProduct(itemID,g_pluginSellItemBuyNow);
}

function sellItemBuyNowButton(itemID)
{
            //alert('sellItemBuyNowButton called');
            pluginProduct(itemID,g_pluginSellItemBuyNowButton);
}

function displayItemPriceAndOffer(itemID)
{
            //alert('displayItemPriceAndOffer called');
            pluginProduct(itemID, g_pluginDisplayItemPriceAndOffer);
}

function showItemPrice(itemID)
{
            //alert('showItemPrice called');
            pluginProduct(itemID, g_pluginShowItemPrice);
}

function showItemDescription(itemID)
{
            //alert('showItemDescription called');
            pluginProduct(itemID, g_pluginShowItemDescription);
}

function showItemWeight(itemID)
{
            //alert('showItemWeight called');
            pluginProduct(itemID, g_pluginShowItemWeight);
}

function pluginProduct(itemID, plugin)
{
            //alert('pluginProduct called');
            var uniqueNumber = getUniqueNumber();
            var URL = g_baseURL+'client/'+g_serverVersion+'/GetItemDetails?ID='+itemID+'&PLUGIN='+plugin+'&unique='+uniqueNumber;
            invokeCallToServer(plugin, itemID, uniqueNumber, URL);
}


function showTotalQuantityItems()
{
            //alert('showTotalQuantityItems called');
            pluginShopperDetails(g_pluginShowTotalQuantityItems);
}

function showTotalCostItems()
{
            //alert('showTotalCostItems called');
            pluginShopperDetails(g_pluginShowTotalCostItems);
}

function showMiniBasketList()
{
            //alert('showMiniBasketList called');
            pluginShopperDetails(g_pluginShowMiniBasketList);
}

function pluginShopperDetails(plugin)
{
            //alert('pluginShopperDetails called for plugin:'+plugin);
            var uniqueNumber = getUniqueNumber();
            var URL = g_baseURL+'client/'+g_serverVersion+'/GetShopperDetails?PLUGIN='+plugin+'&ID='+plugin+'&unique='+uniqueNumber;
            invokeCallToServer(plugin, plugin, uniqueNumber, URL);
}

//
//Successfully Added to Basket Image
//

function delayedRemoveSuccessImg(itemName, uniqueNumber)
{
            //alert('delayedRemoveSuccessImg called');
            var successImg=document.getElementById("successImg"+itemName+uniqueNumber);
            var itemSuccessAreaName = 'successImgArea'+itemName+uniqueNumber;

            if(successImg != null && successImg != 'undefined')
            {
                        //alert('delayedRemoveSuccessImg successImg:'+successImg);
                        window.setTimeout('removeSuccessImg("'+itemSuccessAreaName+'")', 9000);
            }
}

function removeSuccessImg(successSpanID)
{
            //alert('removeSuccessImg called');
            var successSpan=document.getElementById(successSpanID);
            //alert('removeSuccessImg span:'+successSpan);

            if(successSpan != null && successSpan != 'undefined')
            {
                        //alert('removeSuccessImg span innerHTML:'+successSpan.innerHTML);
                        //alert('removeSuccessImg hiding img');
                        //successSpan.style.visibility='hidden'; //Do not hide, as the img will only show the first time and not subsequent times.
                        successSpan.innerHTML='';
            }
}


function hideTickTimer(tickImgID)
{
            alert('hideTickTimer for:'+tickImgID);
            window.setTimeout('hideTick(tickImgID)',8000)
}

function hideTick(tickImgID)
{
            //alert(document.successfullyAddedItem);
            var tick=document.getElementById(tickImgID);
            var multiTick=document.getElementById('successfullyAddedMultiItem');
            alert('hideTick tick:'+tick);
            alert(multiTick);
            //tick.style.zIndex="-1";
            if(tick != null && tick != 'undefined'){tick.style.visibility='hidden';}
            if(multiTick != null && multiTick != 'undefined'){multiTick.style.display = 'none';}
}


//
//Basket Control Features
//e.g. Checkout, View Basket, Change Currency
function showCheckoutControl()
{
            //alert('showCheckoutControl called');
            pluginShopControl(g_pluginCheckoutControl);
}

function showCheckoutLinkControl()
{
            //alert('showCheckoutLinkControl called');
            pluginShopControl(g_pluginCheckoutLinkControl);
}

function showViewBasketControl()
{
            //alert('showViewBasketControl called');
            pluginShopControl(g_pluginViewBasketControl);
}

function showViewBasketLinkControl()
{
            //alert('showViewBasketLinkControl called');
            pluginShopControl(g_pluginViewBasketLinkControl);
}

function showChangeCurrencyControl()
{
            //alert('showChangeCurrencyControl called');
            pluginShopControl(g_pluginShowChangeCurrencyControl);
}


function pluginShopControl(plugin)
{
    var uniqueNumber = getUniqueNumber();
    //alert('pluginShopControl uniqueNumber:'+uniqueNumber);
    var URL = g_baseURL+'client/'+g_serverVersion+'/GetShopControl?PLUGIN='+plugin+'&ID='+plugin+'&unique='+uniqueNumber;
    invokeCallToServer(plugin, plugin, uniqueNumber, URL);
}

function changeCurrency(theNode, currency, ID, uniqueNumber, itemTransientUniquePageID, formName)
{
    //alert('changeCurrency called theNode:'+theNode+' itemTransientUniquePageID:'+itemTransientUniquePageID+ ' formName:'+formName);

    URL = g_baseURL+'client/'+g_serverVersion+'/ChangeDisplay?PLUGIN='+g_pluginShowChangeCurrencyControl+'&displayCurrency='+currency+'&unique='+uniqueNumber;

    //Resets the communication mechanism back to the start.
    resetCallToServer();

    callToServer(g_pluginShowChangeCurrencyControl, g_pluginShowChangeCurrencyControl, uniqueNumber, URL);
}


function changeCurrencyIFrame(theNode, currency, ID, uniqueNumber, itemTransientUniquePageID, formName)
{
            //alert('changeCurrencyIFrame called theNode:'+theNode+' itemTransientUniquePageID:'+itemTransientUniquePageID+ ' formName:'+formName);
    var virtualForm = createVirtualForm(theNode, itemTransientUniquePageID, formName);
    if(virtualForm != null || virtualForm != 'undefined')
    {
        //alert('changeCurrency submitting form to URL:'+virtualForm.action);

        virtualForm.target = "RSIFrame"+ID+uniqueNumber;
        //alert('changeCurrency submitting form to target:'+virtualForm.target);

        virtualForm.displayCurrency.value = currency;
        //alert('changeCurrency virtualForm.displayCurrency: '+virtualForm.displayCurrency.value);

        virtualForm.submit();

        cleanUpVirtualForm(virtualForm);
    }
}

function changeCurrencyWithForms(theNode, currency, ID, uniqueNumber)
{
            alert('changeCurrency called');
            var formToSubmit = getForm(theNode);

            if(formToSubmit != null || formToSubmit != 'undefined')
            {
                        //Append the currency to the request
                        //formToSubmit.action = formToSubmit.action + "?displayCurrency="+currency;
                        alert('changeCurrency submitting form to URL:'+formToSubmit.action);

                        formToSubmit.target = "RSIFrame"+ID+uniqueNumber;
                        alert('changeCurrency submitting form to target:'+formToSubmit.target);

                        formToSubmit.displayCurrency.value = currency;
                        alert('formToSubmit.displayCurrency: '+formToSubmit.displayCurrency.value);

                        formToSubmit.submit();
            }
}


function handleResponseChangeCurrency(ID, uniqueNumber)
{
    //alert('handleResponseChangeCurrency called for ID:'+ID+' uniqueNumber:'+uniqueNumber);
    var productPluginTypesWithPriceToRefershArray = new Array();
    productPluginTypesWithPriceToRefershArray[0] = g_pluginSellItem;
    productPluginTypesWithPriceToRefershArray[1] = g_pluginDisplayItemPriceAndOffer;
    productPluginTypesWithPriceToRefershArray[2] = g_pluginShowItemPrice;
    productPluginTypesWithPriceToRefershArray[3] = g_pluginSellItemBuyNow;
    productPluginTypesWithPriceToRefershArray[4] = g_pluginShowTotalCostItems;
    productPluginTypesWithPriceToRefershArray[5] = g_pluginSellCategoryTable;
    productPluginTypesWithPriceToRefershArray[6] = g_pluginShowMiniBasketList;

    refreshRegisteredPluginTypes(productPluginTypesWithPriceToRefershArray);
}


function refreshShopperBasketPlugins()
{
    //alert('refreshShopperBasketPlugins called');
    var shopperBasketPluginTypesToRefershArray = new Array();
    shopperBasketPluginTypesToRefershArray[0] = g_pluginShowTotalQuantityItems;
    shopperBasketPluginTypesToRefershArray[1] = g_pluginShowTotalCostItems;
    shopperBasketPluginTypesToRefershArray[2] = g_pluginShowMiniBasketList;

    refreshRegisteredPluginTypes(shopperBasketPluginTypesToRefershArray);
}


function refreshRegisteredPluginTypes(pluginTypesToRefreshArray)
{
    //alert('refreshRegisteredPluginTypes called');

    //Returns the communication mechanism back to the start.
    resetCallToServer();

    var registeredPluginType;
    var registeredPluginID;
    var registeredPluginUniqueNumber;
    var registeredPluginURL;
    var registeredPluginDebugText = "Regenerating Plugins ";

    //Debug: What plugintypes are we refreshing
    //var debugRefreshRegisteredPluginTypes = '';
    //for(var pluginTypeToRefreshPostion=0; pluginTypeToRefreshPostion < pluginTypesToRefreshArray.length; pluginTypeToRefreshPostion++)
    //{
    //    debugRefreshRegisteredPluginTypes = debugRefreshRegisteredPluginTypes + ' ' + pluginTypesToRefreshArray[pluginTypeToRefreshPostion];
    //}
    //alert('refreshRegisteredPluginTypes refresh plugin types:'+debugRefreshRegisteredPluginTypes);


    for(var registeredPluginArrayPostion=0; registeredPluginArrayPostion < g_registeredPluginID.length; registeredPluginArrayPostion++)
    {
        registeredPluginType = g_registeredPluginType[registeredPluginArrayPostion];
        registeredPluginID = g_registeredPluginID[registeredPluginArrayPostion];
        registeredPluginUniqueNumber = g_registeredPluginUniqueNumber[registeredPluginArrayPostion];
        registeredPluginURL = g_registeredPluginURL[registeredPluginArrayPostion];

        //Record debug information
        registeredPluginDebugText = registeredPluginDebugText + ": registeredPluginType="+registeredPluginType+" ID="+registeredPluginID+" UniqueNumber="+registeredPluginUniqueNumber;

        //Make each plug-in reload itself
        //TODO: What about ecommerce plug-ins that contain no pricing information and do not need to be refreshed?
        // Can we differenatiate these and not perform a callToServer?
        for(var pluginTypeToRefreshPostion=0; pluginTypeToRefreshPostion < pluginTypesToRefreshArray.length; pluginTypeToRefreshPostion++)
        {
            if(registeredPluginType == pluginTypesToRefreshArray[pluginTypeToRefreshPostion])
            {
                callToServer(registeredPluginType, registeredPluginID, registeredPluginUniqueNumber, registeredPluginURL);
                //We matched the plugin we were after
                continue;
            }
        }
    }

    //alert('refreshRegisteredPluginTypes Completed the regeneration of all plugins registered on this page.\n'+registeredPluginDebugText);
}

function findDocumentsInFrames(theFramesArray, masterListOfDocumentObjs)
{
            //alert('findDocumentsInFrames called');
            var foundFrameObj;
            var documentInFrame;

            if(theFramesArray != null && theFramesArray != 'undefined')
            {
                        for(var i=0; i < theFramesArray.length; i++)
                        {
                                    foundFrameObj = theFramesArray[i];
                                    if(foundFrameObj != null && foundFrameObj != 'undefined')
                                    {
                                                documentInFrame = foundFrameObj.document;

                                                if(documentInFrame != null && documentInFrame != 'undefined')
                                                {
                                                            //alert('document body:'+documentInFrame.body.innerHTML);
                                                            masterListOfDocumentObjs[masterListOfDocumentObjs.length] = documentInFrame;
                                                }

                                                //Recursively find if there are any frames in this frame.
                                                masterListOfDocumentObjs = findDocumentsInFrames(foundFrameObj.frames, masterListOfDocumentObjs);
                                    }

                        }
            }

            return masterListOfDocumentObjs;
}



//
//This will cause the script to pause execution of later statements by the number of milliseconds passed in.
//
function pausems(amount)
{
            var d = new Date() //today's date
            var mill;

    if(amount < 1)
    {
        //The delay should not be negative, incase it is due to an issue,
        // let us set it to 500 milli seconds as a default!
        amount = 500;
    }

    while (1)
    {
		mill=new Date() // Date Now
		diff = mill-d //difference in milliseconds
		if( diff > amount ) {break;}
    }
}

function obtainSupportingScripts()
{
    document.write('<script type="text/javascript" src="'+g_baseURL+'/dynascript/sid/'+g_clientID+'.js?CLIENT_ID='+g_clientID+'"></script>');

    document.write('<link rel="stylesheet" href="'+g_baseURL+'/css/dhtmlwindow.css" type="text/css" />');
    document.write('<script type="text/javascript" src="'+g_baseURL+'/script/dhtmlwindow.js"></script>');

    document.write('<link rel="stylesheet" href="'+g_baseURL+'/css/dhtmlwindowmodal.css" type="text/css" />');
    document.write('<script type="text/javascript" src="'+g_baseURL+'/script/dhtmlwindowmodal.js"></script>');

    document.write('<script type="text/javascript" src="'+g_baseURL+'/script/clientutilities.js"></script>');

    //Have the browser load and cache the splash page for the checkout screens which appears on opening the basket
    document.write('<iframe src ="'+g_baseURL+'loading.html" style="width: 0;height: 0;border: 0 none #fff;display: none;padding: 0;margin: 0;"></iframe>');

    document.write('<img src="'+g_baseURL+'servlets/GetShopScript.js?CLIENT_ID'+g_clientID+'" height="0px" width="0px" style="display: none" />');
}


//
//When a control function, like checkout or view basket opens a target window, this
// allows the opened window to send a reference object of itself back to the opener.
// This allows the opener to call functions on the target window.
//
function registerWithMeTheParent(yourself)
{
            //alert('registerWithMeTheParent called, yourself:'+yourself);
            g_targetPage = yourself;
}


function requestVirtualFormResubmission()
{
            //alert('requestVirtualFormResubmission called');
            //wait 2 seconds then try again
            window.setTimeout('resubmitVirtualForm()', 2000);
}

function resubmitVirtualForm()
{
            //alert('resubmitVirtualForm called');
            submitVirtualForm(g_lastTheNode, g_lastItemTransientUniquePageID, g_lastFormName);
}

function getSID()
{
    var sid = 'none';
    var sidFunction = 'getSID_'+g_clientID;

    eval('if(window.'+sidFunction+'){sid='+sidFunction+'();}');
    //alert('getSID sid:'+sid);
    return sid;
}

function storeSessionID(sessionID)
{
            //alert('storeSessionID called with sessionID:'+sessionID);
    if(g_sessionID == undefined || g_sessionID == '' || g_sessionID == 'undefined')
    {
        g_sessionID = sessionID;
    }
    else
    {
        //If we do not have this session ID we store it.
        if(g_sessionID.indexOf(sessionID) == -1)
        {
            g_sessionID = g_sessionID+","+sessionID;
        }
    }


    if(g_sessionIDTimerID != undefined && g_sessionIDTimerID != 'undefined' && g_sessionIDTimerID != '')
            {
                        window.clearTimeout(g_sessionIDTimerID);
            }

            g_sessionIDTimerID=window.setTimeout('clearSessionID()', (g_sessionTimeOutInSeconds * 1000));
}

function clearSessionID()
{
            g_sessionID = '';
}




//
//Stops the target page (e.g. view basket/checkout) from closing on the unload event.
// The target page has an unload event to close the window in case a user is in more than 1 client's shop.
// As they share the same target page when going to view basket e.t.c. If the named target window is already open
// when another client's shop has view basket or checkout clicked, if it tries to reuse the same named window,
// that window gets a new session rather than that of the opener. Therefore, the user appears as if there is nothing
// in their basket, even though there is. Closing the window forces a new one to be opened which gets the session of the opener as required.
//
function blockTargetUnloadPage()
{
            //alert('blockTargetUnloadPage called g_targetPage:'+g_targetPage);

            //Is the page we opened still there?
            if(g_targetPage != undefined && g_targetPage.closed == false && g_targetPage.blockUnloadPage)
            {
                        //alert('blockTargetUnloadPage calling blockUnloadPage on target page');
                        g_targetPage.blockUnloadPage();
            }
}


//
//LOADED TAG FUNCTIONS
//
// Helper functions for the loaded price tag components
//
function reconfigurePriceTagAfterReload(buyerChoice1OptionValue, buyerChoice2OptionValue, itemTransientUniquePageID)
{
    //alert('reconfigurePriceTagAfterReload called buyerChoice1OptionValue:'+buyerChoice1OptionValue+' buyerChoice2OptionValue:'+buyerChoice2OptionValue+' itemTransientUniquePageID:'+itemTransientUniquePageID);
    var atLeastOneChanged = false;

    if(buyerChoice1OptionValue == '' && buyerChoice2OptionValue == '')
    {
        //Check that the default option is not shown as out of stock and show an option combination that is in stock.
        var inspectedBuyerChoice0ListValueKey = '';
        var inspectedBuyerChoice1ListValueKey = '';
        var hiddenStockQty;
        var hiddenStockQtyObj;

        //Look up the buyer choice options lists
        var buyerChoice0ListObj = document.getElementById('BUYER_CHOICE_LIST0_'+itemTransientUniquePageID);
        var buyerChoice1ListObj = document.getElementById('BUYER_CHOICE_LIST1_'+itemTransientUniquePageID);
        //alert('reconfigurePriceTagAfterReload buyerChoice0ListObj:'+buyerChoice0ListObj+' buyerChoice1ListObj:'+buyerChoice1ListObj);

        if(buyerChoice0ListObj != null && buyerChoice1ListObj != null)
        {
            //alert('reconfigurePriceTagAfterReload two buyer choice options lists assigned');
            //Two buyer choice options list assigned
            searchForInStockOption:
            for(var i=0; i<buyerChoice0ListObj.length; i++)
            {
                for(var j=0; j<buyerChoice1ListObj.length; j++)
                {                    
                    //For every option value combination get the quantity
                    hiddenStockQtyObj = getHiddenStockQuantityObj('_'+buyerChoice0ListObj[i].value, '_'+buyerChoice1ListObj[j].value, itemTransientUniquePageID);
                    hiddenStockQty = hiddenStockQtyObj.value;
                    if(hiddenStockQty > 0)
                    {
                        //alert('reconfigurePriceTagAfterReload Found in stock option:'+ buyerChoice0ListObj[i].value + ' having quantity:'+hiddenStockQty);
                        //alert('reconfigurePriceTagAfterReload description:'+document.getElementById("hiddenStockQtyDesc_"+buyerChoice0ListObj[i].value+"_"+buyerChoice1ListObj[j].value+"_"+itemTransientUniquePageID).value);

                        //If the first option combination is in stock then this is how the plugin loaded so there is no
                        // need to do anything.
                        if(i != 0 || j != 0)
                        {
                            //We have found an option in stock so we will display this option in preference to an out of stock one
                            buyerChoice0ListObj[i].selected = true;
                            buyerChoice1ListObj[j].selected = true;
                            setRequiredBuyerChoiceOption(buyerChoice0ListObj[i].value, 0, itemTransientUniquePageID);
                            setRequiredBuyerChoiceOption(buyerChoice1ListObj[j].value, 1, itemTransientUniquePageID);
                            atLeastOneChanged = true;
                        }
                        //Break to outer loop to stop what we are doing
                        break searchForInStockOption;
                    }
                }
            }
        }
        else if(buyerChoice0ListObj != null)
        {
            //alert('reconfigurePriceTagAfterReload one buyer choice options list assigned');
            //Only one buyer choice options list assigned
            for(var i=0; i<buyerChoice0ListObj.length; i++)
            {
                hiddenStockQtyObj = getHiddenStockQuantityObj('_'+buyerChoice0ListObj[i].value, '', itemTransientUniquePageID);
                hiddenStockQty = hiddenStockQtyObj.value;
                if(hiddenStockQty > 0)
                {
                    //If the first option is in stock then this is how the plugin loaded so there is no
                    // need to do anything.
                    if(i != 0)
                    {
                        //We have found an option in stock so we will display this option in preference to an out of stock one
                        buyerChoice0ListObj[i].selected = true;
                        setRequiredBuyerChoiceOption(buyerChoice0ListObj[i].value, 0, itemTransientUniquePageID);
                        atLeastOneChanged = true;
                    }
                    break;
                }
            }
        }
    }
    else
    {
        //Select the specified buyer choice option
        var matchedBuyerChoice1OptionValue = selectBuyerChoiceOptionListDropDownValue(buyerChoice1OptionValue, 0, itemTransientUniquePageID);
        var matchedBuyerChoice2OptionValue = selectBuyerChoiceOptionListDropDownValue(buyerChoice2OptionValue, 1, itemTransientUniquePageID);

        if(matchedBuyerChoice1OptionValue == true)
        {
                    //BUYER CHOICE OPTIONS LIST 1
                    setRequiredBuyerChoiceOption(buyerChoice1OptionValue, 0, itemTransientUniquePageID);
                    atLeastOneChanged = true;
        }

        if(matchedBuyerChoice2OptionValue == true)
        {
                    //BUYER CHOICE OPTIONS LIST 2
                    setRequiredBuyerChoiceOption(buyerChoice2OptionValue, 1, itemTransientUniquePageID);
                    atLeastOneChanged = true;
        }
    }

    //If we have changed either of the selected list options we will then need to
    // update the hidden fields and displayed quantity values.
    if(atLeastOneChanged == true)
    {
                actOnProductQuantity(itemTransientUniquePageID, true);
    }
}

function selectBuyerChoiceOptionListDropDownValue(buyerChoiceOptionValue, listNumber, itemTransientUniquePageID)
{
            var buyerChoiceListObj = document.getElementById('BUYER_CHOICE_LIST'+listNumber+'_'+itemTransientUniquePageID);
            //In case the value that was selected does not exist any more and it is not possible to select the list option.
            var matchedBuyerChoiceOptionValue = false;

            //An empty buyerChoiceOptionValue means that nothing has been pre-selected. A pre-selected
            // buyer choice option happens after an add to basket for the product when the plugin reloads. 
            if(buyerChoiceListObj != null && buyerChoiceListObj != undefined && buyerChoiceListObj != 'undefined' && buyerChoiceOptionValue != "")
            {
                        for(var i=0; i<buyerChoiceListObj.length; i++)
                        {
                                    if(buyerChoiceListObj[i].value == buyerChoiceOptionValue)
                                    {
                                                buyerChoiceListObj[i].selected = true;
                                                matchedBuyerChoiceOptionValue = true;
                                                break;
                                    }
                        }
            }

            return matchedBuyerChoiceOptionValue;
}


function setRequiredBuyerChoiceOption(requiredBuyerChoiceOptionValue, listNumber, itemTransientUniquePageID)
{
    //alert('setRequiredHiddenQuantity requiredBuyerChoiceOptionValue: '+requiredBuyerChoiceOptionValue);
    var selectedBuyerChoiceListValueObj;

    //Update the hidden input which stores the selected buyer choice list value.
    selectedBuyerChoiceListValueObj = document.getElementById("BUYER_CHOICE"+listNumber+"_"+itemTransientUniquePageID);
    selectedBuyerChoiceListValueObj.value = requiredBuyerChoiceOptionValue;
}

function actOnProductQuantity(itemTransientUniquePageID, changeVisualIfRequired)
{
    //alert('actOnProductQuantity called for itemTransientUniquePageID:'+itemTransientUniquePageID);
    var requiredQuantity;

    var buyerChoice0ListValueObj = document.getElementById("BUYER_CHOICE0_"+itemTransientUniquePageID);
    //alert('actOnProductQuantity buyerChoice0ListValueObj: '+buyerChoice0ListValueObj)
    var buyerChoice1ListValueObj = document.getElementById("BUYER_CHOICE1_"+itemTransientUniquePageID);
    //alert('actOnProductQuantity buyerChoice1ListValueObj: '+buyerChoice1ListValueObj)

    //There may not be a buyerChoice0List, which changes how the key should look
    var buyerChoice0ListValueKey = getBuyerChoiceListValueKey(buyerChoice0ListValueObj);
    var buyerChoice1ListValueKey = getBuyerChoiceListValueKey(buyerChoice1ListValueObj);
    //alert('actOnProductQuantity buyerChoice0ListValueKey:'+buyerChoice0ListValueKey+' buyerChoice1ListValueKey:'+buyerChoice1ListValueKey);


    //e.g. 1 buyer choice option
    // hiddenStockQty_1_1_DEMO21037679
    //e.g. 2 buyer choice options
    // hiddenStockQty_1_1_2_6_DEMO21037679
    var hiddenStockQtyObj = getHiddenStockQuantityObj(buyerChoice0ListValueKey, buyerChoice1ListValueKey, itemTransientUniquePageID);
    var hiddenStockQty = hiddenStockQtyObj.value;
    //alert('actOnProductQuantity hiddenStockQty:'+hiddenStockQty);

    //e.g. 1 Buyer Choice Options List
    //          Red
    //e.g. 2 Buyer Choice Options Lists
    //          Large Red
    var hiddenStockQtyDescKey = "hiddenStockQtyDesc"+buyerChoice0ListValueKey+buyerChoice1ListValueKey+"_"+itemTransientUniquePageID;
    //alert('actOnProductQuantity hiddenStockQtyDescKey:'+hiddenStockQtyDescKey);

    var hiddenStockQtyDescObj = document.getElementById(hiddenStockQtyDescKey);

    //alert('actOnProductQuantity hiddenStockQtyObj:'+hiddenStockQtyObj+' hiddenStockQtyDescObj:'+hiddenStockQtyDescObj);


    var stockQtySelectListObj = document.getElementById('QUANTITY_LIST_'+itemTransientUniquePageID);
    //alert('actOnProductQuantity stockQtySelectListObj:'+stockQtySelectListObj);
    var currentValueStockQtySelectList = stockQtySelectListObj.value;
    //alert('actOnProductQuantity currentValueStockQtySelectList:'+currentValueStockQtySelectList);


    if(changeVisualIfRequired == true)
    {
        //Obtain the add to basket image so we may change its cursor between a hand and an arrow.
        var addToBasketImgKey = 'addToBasketImg_'+itemTransientUniquePageID;
        //alert('actOnProductQuantity addToBasketImgKey:'+addToBasketImgKey);

        var addToBasketImgObj = document.getElementById(addToBasketImgKey);
        //alert('actOnProductQuantity addToBasketImgObj:'+addToBasketImgObj);

        if(hiddenStockQty == 0)
        {
            requiredQuantity = 0;
            rebuildQuantitySelectList(stockQtySelectListObj, 0, 0, requiredQuantity);

            //This sets the 'Out Of Stock' content up for this item
            var outOfStockItemDescArea = 'outOfStockItemDescArea_'+itemTransientUniquePageID;
            //alert('actOnProductQuantity outOfStockItemDescArea:'+outOfStockItemDescArea);

            var outOfStockItemDescAreaObj = document.getElementById(outOfStockItemDescArea);
            //alert('actOnProductQuantity outOfStockItemDescAreaObj:'+outOfStockItemDescAreaObj);

            var hiddenOutOfStockDescArea = 'hiddenOutOfStockDescArea_'+itemTransientUniquePageID;
            var hiddenOutOfStockDescAreaObj = document.getElementById(hiddenOutOfStockDescArea);


            var addToBasketDescArea = "addToBasketDescArea_"+itemTransientUniquePageID;
            //alert('actOnProductQuantity addToBasketDescArea:'+addToBasketDescArea);

            var addToBasketDescAreaObj = document.getElementById(addToBasketDescArea);
            //alert('actOnProductQuantity addToBasketDescAreaObj:'+addToBasketDescAreaObj);

            addToBasketDescAreaObj.innerHTML = hiddenOutOfStockDescAreaObj.innerHTML;
            //If this item has buyer choice options then we show the description of what is out of stock, e.g. Large Red
            outOfStockItemDescAreaObj.innerHTML = hiddenStockQtyDescObj.value;

            //If it exists (it doesn't in an out of stock multi-list table)
            // Change the cursor of the ADD TO BASKET image to the default, often an arrow symbol
            if(addToBasketImgObj != undefined)
            {
                addToBasketImgObj.style.cursor = 'default';
            }
        }
        else
        {
            if(currentValueStockQtySelectList > hiddenStockQty)
            {
                //alert('actOnProductQuantity currentValueStockQtySelectList > hiddenStockQty hiddenStockQty:'+hiddenStockQty);
                requiredQuantity = hiddenStockQty;

                //There aren't as many in stock as the user had selected, set it to the most we have
                rebuildQuantitySelectList(stockQtySelectListObj, 1, hiddenStockQty, requiredQuantity);
            }
            else if(currentValueStockQtySelectList == 0)
            {
                //The last item buyer choice option value combination is out of stock so we set the quantity to 1 for this item.
                requiredQuantity = 1;
                rebuildQuantitySelectList(stockQtySelectListObj, 1, hiddenStockQty, requiredQuantity);
            }
            else
            {
                //alert('actOnProductQuantity else requiredQuantity = currentValueStockQtySelectList currentValueStockQtySelectList:'+currentValueStockQtySelectList);
                requiredQuantity = currentValueStockQtySelectList;

                //Set the quantity to what the user has already selected
                rebuildQuantitySelectList(stockQtySelectListObj, 1, hiddenStockQty, requiredQuantity);
            }

            //This sets the 'Add to Basket' content up for this item
            var hiddenAddToBasketDescArea = "hiddenAddToBasketDescArea_"+itemTransientUniquePageID;
            //alert('actOnProductQuantity hiddenAddToBasketDescArea:'+hiddenAddToBasketDescArea);

            var hiddenAddToBasketDescAreaObj = document.getElementById(hiddenAddToBasketDescArea);
            //alert('actOnProductQuantity hiddenAddToBasketDescAreaObj:'+hiddenAddToBasketDescAreaObj);


            var addToBasketDescArea = "addToBasketDescArea_"+itemTransientUniquePageID;
            //alert('actOnProductQuantity addToBasketDescArea:'+addToBasketDescArea);

            var addToBasketDescAreaObj = document.getElementById(addToBasketDescArea);
            //alert('actOnProductQuantity addToBasketDescAreaObj:'+addToBasketDescAreaObj);

            var outOfStockItemDescArea = 'outOfStockItemDescArea_'+itemTransientUniquePageID;
            //alert('actOnProductQuantity outOfStockItemDescArea:'+outOfStockItemDescArea);

            var outOfStockItemDescAreaObj = document.getElementById(outOfStockItemDescArea);
            //alert('actOnProductQuantity outOfStockItemDescAreaObj:'+outOfStockItemDescAreaObj);


            addToBasketDescAreaObj.innerHTML = hiddenAddToBasketDescAreaObj.innerHTML;

            outOfStockItemDescAreaObj.innerHTML = "";


            //alert('actOnProductQuantity qty greater than 0, addToBasketImgObj:'+addToBasketImgObj);

            //I think this may no longer be needed and may be related to the Classic button range (with a button image
            // and separate text ADD TO BASKET etc. It may no longer be relevant?
            if(addToBasketImgObj != null && addToBasketImgObj != undefined)
            {
                //Sometimes, the cursor setting doesn't work. It seems to work better when we get the image again here
                // before setting the cursor to a pointer.
                addToBasketImgObj = document.getElementById(addToBasketImgKey);

                //alert('actOnProductQuantity addToBasketImgObj != undefined where addToBasketImgObj:'+addToBasketImgObj+' and addToBasketImgKey:'+addToBasketImgKey);
                if(addToBasketImgObj != null)
                {
                    //alert('actOnProductQuantity setting addToBasketImgObj with a cursor pointer');
                    //Change the cursor to a click hand symbol
                    addToBasketImgObj.style.cursor = 'pointer';
                }                   
            }
        }
            }

    //Set the hidden quantity field which stores the selected value passed back to the server
            setItemRequiredQuantity(itemTransientUniquePageID, requiredQuantity);
}

function getBuyerChoiceListValueKey(buyerChoiceListValueObj)
{
    var buyerChoiceListValueKey = '';

    if(buyerChoiceListValueObj != null && buyerChoiceListValueObj != undefined)
    {
                buyerChoiceListValueKey = buyerChoiceListValueObj.value;

                if(buyerChoiceListValueKey != null && buyerChoiceListValueKey != undefined && buyerChoiceListValueKey != '')
                {
                            buyerChoiceListValueKey = "_"+buyerChoiceListValueKey;
                }
    }

    return buyerChoiceListValueKey;
}

function getHiddenStockQuantityObj(buyerChoice0ListValueKey, buyerChoice1ListValueKey, itemTransientUniquePageID)
{
    //e.g. 1 buyer choice option
    // hiddenStockQty_1_1_DEMO21037679
    //e.g. 2 buyer choice options
    // hiddenStockQty_1_1_2_6_DEMO21037679
    var hiddenStockQtyKey = "hiddenStockQty"+buyerChoice0ListValueKey+buyerChoice1ListValueKey+"_"+itemTransientUniquePageID;
    //alert('actOnProductQuantity hiddenStockQtyKey:'+hiddenStockQtyKey);
    var hiddenStockQtyObj = document.getElementById(hiddenStockQtyKey);

    return hiddenStockQtyObj;
}

function setItemRequiredQuantity(itemTransientUniquePageID, requiredQuantity)
{
            //alert('setItemRequiredQuantity requiredQuantity:'+requiredQuantity+' itemTransientUniquePageID:'+itemTransientUniquePageID);

            //Set the hidden quantity field which stores the selected value passed back to the server
            var hiddenQuantityObj = document.getElementById('QUANTITY_'+itemTransientUniquePageID);
            //alert('setItemRequiredQuantity hiddenQuantityObj:'+hiddenQuantityObj);

            hiddenQuantityObj.value = requiredQuantity;
            //alert('setItemRequiredQuantity hiddenQuantityObj.value:'+hiddenQuantityObj.value);
}

function getItemRequiredQuantity(itemTransientUniquePageID)
{
            var hiddenQuantityObj = document.getElementById('QUANTITY_'+itemTransientUniquePageID);
            if(hiddenQuantityObj != undefined)
            {
                        //alert('getItemRequiredQuantity hiddenQuantityObj:'+hiddenQuantityObj);
                        //alert('getItemRequiredQuantity hiddenQuantityObj.value:'+hiddenQuantityObj.value);
                        return hiddenQuantityObj.value;
            }
            else
            {
                        return -1;
            }
}


//
// As a user changes their buyer choice options, there is a different product quantity associated with each combination.
//  We therefore need to change the quantity of these items available to the user to reflect the quantity actually in stock.
//
function rebuildQuantitySelectList(stockQtySelectListObj, startingQuantity, endQuantity, selectedCurrentValueStockQty)
{
            //alert('rebuildQuantitySelectList called');
            //alert('rebuildQuantitySelectList stockQtySelectListObj:'+stockQtySelectListObj+' startingQuantity:'+startingQuantity+' endQuantity:'+endQuantity+' selectedCurrentValueStockQty:'+selectedCurrentValueStockQty);

            var currentQty = startingQuantity;

            //Delete all existing quantities before adding the new ones again.
            // Deletion compresses the options array. For example, if you delete options[0], the existing options[1] becomes options[0].
            // It's a good idea to delete options at the end of the array first.
            //alert('rebuildQuantitySelectList before deletion stockQtySelectListObj.options.length:'+stockQtySelectListObj.options.length);
            var stockQtySelectListLength = stockQtySelectListObj.options.length - 1;
            for(var i=stockQtySelectListLength; i>=0; i--)
            {
                        stockQtySelectListObj.options[i]=null;
            }

            //alert('rebuildQuantitySelectList after deletion stockQtySelectListObj.options.length:'+stockQtySelectListObj.options.length);


            //Show a max of 99 quantity options at one time.
            if(endQuantity > 99)
            {
                        endQuantity = 99;
            }


            for(var j=0; currentQty<=endQuantity; j++)
            {
                        stockQtySelectListObj.options[j] = new Option(currentQty, currentQty);

                        if(currentQty == selectedCurrentValueStockQty)
                        {
                                    stockQtySelectListObj.options[j].selected = true;
                        }

                        //Next quantity option
                        currentQty++;
            }
}



//
//Updates the product quantities for this item based on the server response after a multi list item has been added to the users basket
//
function updateProductQuantity(hiddenStockQtyKey, newStockQtyValue)
{
            //alert('updateProductQuantity called hiddenStockQtyKey:'+hiddenStockQtyKey+' newStockQtyValue:'+newStockQtyValue);

            var hiddenStockQtyObj = document.getElementById(hiddenStockQtyKey);
            hiddenStockQtyObj.value = newStockQtyValue;
}

function updateRequiredQuantity(requiredQuantityObj, hiddenQtyKey)
{
            //alert('updateRequiredQuantity called hiddenQtyKey:'+hiddenQtyKey+' requiredQuantityObj:'+requiredQuantityObj.value);

            var hiddenQtyKeyObj = document.getElementById(hiddenQtyKey);
            hiddenQtyKeyObj.value = requiredQuantityObj.value;
    //alert('updateRequiredQuantity hiddenQtyKeyObj.value '+hiddenQtyKeyObj.value+' requiredQuantityObj.value:'+requiredQuantityObj.value)
}


function openViewBasket()
{
	var selectListsStyle;
	var currentDate = new Date();
	var height = getBasketHeight();
	var width = getBasketWidth();

	//alert('openViewBasket height:'+height);

	performBeforeOpenBasketTasks();


	//alert('openViewBasket doc height:'+document.style);

	//Now open the new shopping basket window and store in the global g_shopintwin variable.
	// First open a quick holding page.
	//g_shopintwin=dhtmlmodal.open("paypal", "iframe", g_baseURL+"/loading.html", "Checkout Process", "width=700px,height=600px,resize=1,scrolling=1,center=1", "norecal");
	g_shopintwin=dhtmlmodal.open("paypal", "iframe", g_baseURL+"/loading.html", "Checkout Process", "width=" + width + "px,height=" + height + "px,resize=1,scrolling=1,center=1", "norecal");

	//Attach a custom close function to the basket.
	//alert('openViewBasket g_shopintwin:'+g_shopintwin);
	g_shopintwin.onclose=function(){closeBasket(); return true;}

	// Now load the actual required shopping basket page.
	//g_shopintwin=dhtmlmodal.open("paypal", "iframe", g_baseURL+"/client/Amaethon/ViewBasket?instancetime="+currentDate.getTime()+"&CLIENT_ID="+g_clientID, "Checkout Process", "width=700px,height=600px,scrolling=1,center=1", "norecal");
	//g_shopintwin=dhtmlmodal.open("paypal", "iframe", g_baseURL+"/client/Amaethon/ViewBasket?instancetime="+currentDate.getTime()+"&CLIENT_ID="+g_clientID, "Checkout Process", "width=400px,height=300px,scrolling=1,center=1", "norecal");
	var cancelReturnURL = encodeURIComponent(window.location.href);

	var thisShopperSessionInfoANDURLParameter = getShopperSessionInfoANDURLParameter();

	var realTargetURL = g_baseURL+"/client/Amaethon/ViewBasket?it="+currentDate.getTime()+"&CLIENT_ID="+g_clientID+thisShopperSessionInfoANDURLParameter+"&ret="+cancelReturnURL;
	window.setTimeout('g_shopintwin.load("iframe","'+realTargetURL+'", "Checkout Process")', 700);


	performAfterOpenBasketTasks();

	//alert('openViewBasket completed');
}


function openCheckout()
{
	var selectListsStyle;
	var currentDate = new Date();
	var height = getBasketHeight();
	var width = getBasketWidth();

	//alert('openCheckout height:'+height);

	performBeforeOpenBasketTasks();

	//Now open the new shopping basket window and store in the global g_shopintwin variable.
	// First open a quick holding page.
	g_shopintwin=dhtmlmodal.open("paypal", "iframe", g_baseURL+"/loading.html", "Checkout Process", "width=" + width + "px,height=" + height + "px,resize=1,scrolling=1,center=1", "norecal");
	//g_shopintwin=dhtmlmodal.open("paypal", "iframe", g_baseURL+"/loading.html", "Checkout Process", "width=400px,height=300px,resize=1,scrolling=1,center=1", "norecal");

	//Attach a custom close function to the basket.
	//alert('openCheckout g_shopintwin:'+g_shopintwin);
	g_shopintwin.onclose=function(){closeBasket(); return true;}

	// Now load the actual required shopping basket page.
	//g_shopintwin=dhtmlmodal.open("paypal", "iframe", g_baseURL+"/client/Amaethon/Checkout?instancetime="+currentDate.getTime()+"&CLIENT_ID="+g_clientID, "Checkout Process", "width=700px,height=600px,scrolling=1,center=1", "norecal");
	//g_shopintwin=dhtmlmodal.open("paypal", "iframe", g_baseURL+"/client/Amaethon/Checkout?instancetime="+currentDate.getTime()+"&CLIENT_ID="+g_clientID, "Checkout Process", "width=400px,height=300px,scrolling=1,center=1", "norecal");
	var cancelReturnURL = encodeURIComponent(window.location.href);

    var thisShopperSessionInfoANDURLParameter = getShopperSessionInfoANDURLParameter();

	var realTargetURL = g_baseURL+"/client/Amaethon/Checkout?it="+currentDate.getTime()+"&CLIENT_ID="+g_clientID+thisShopperSessionInfoANDURLParameter+"&ret="+cancelReturnURL;
	window.setTimeout('g_shopintwin.load("iframe","'+realTargetURL+'", "Checkout Process")', 1000);


	performAfterOpenBasketTasks();

	//alert('openCheckout completed');
}

function getShopperSessionInfoANDURLParameter()
{
    var thisShopperSessionInfoANDURLParameter = '&SID='+getSID();
//    if(g_sessionID != undefined && g_sessionID != 'undefined' && g_sessionID != '')
//    {
//            thisShopperSessionInfoANDURLParameter = '&SHOPPER_SESSION_ID='+g_sessionID;
//    }

    return thisShopperSessionInfoANDURLParameter;
}

//Fails to get href of IFRAME because of cross site scripting permission issues
function checkForPaymentInitiated()
{
	var reschedule = 1;


	if(g_shopintwin != 'undefined' && g_shopintwin != null)
	{
		//If a payment has been initiated, the window will be set to blank which means we need to close down the basket
		//alert("checkForPaymentInitiated window href="+g_shopintwin.href() );
		var checkoutHREF = g_shopintwin.href();

		if(checkoutHREF != 'undefined' && checkoutHREF.indexOf('payment-initiated.html') != -1)
		{
			//Do not reschedule ourselves now we have closed the basket.
			reschedule = 0;

			//alert("checkForPaymentInitiated payment-initiated");

			//g_shopintwin.close();
			//closeBasket();

			initiatePayment(checkoutHREF);
		}
	}

	if(reschedule == 1)
	{
		//Re-schedule ourself to check if the payment has been initiated
		//Every second, check if the payment has been initiated
		//alert("checkForPaymentInitiated rescheduling check");
		g_checkForPaymentInitiated = window.setTimeout('checkForPaymentInitiated()',1000);
	}
}

function cancelCheckForPaymentInitiated()
{
	clearTimeout(g_checkForPaymentInitiated);
}

function performBeforeOpenBasketTasks()
{
	//
	//IE6 does not correctly place SELECT lists below z-index div tags
	// so we have to hide the SELECT lists to avoid them being visible and accessible above our veil which the basket
	// sits on top of.
	//
	if(BrowserDetect.browser == "Explorer" && BrowserDetect.version <= 6)
	{
		g_existingPageSelectListsDisplaySettings = new Array();

		// check the alignment on a number of cells in a table.
		g_existingPageSelectLists = document.getElementsByTagName("select");

		if(g_existingPageSelectLists != 'undefined' && g_existingPageSelectLists != null)
		{
			for (var i = 0; i < g_existingPageSelectLists.length; i++)
			{
			    selectListsStyle = g_existingPageSelectLists[i].style;
			    //alert('openViewBasket g_existingPageSelectLists.display:'+g_existingPageSelectLists.display);

			    //Store the existing display setting
			    g_existingPageSelectListsDisplaySettings[i]=selectListsStyle.display;

			    //alert('openViewBasket g_existingPageSelectListsDisplaySettings['+i+']'+g_existingPageSelectListsDisplaySettings[i]);

			    //Now set the select list to none
			    selectListsStyle.display="none";
			}
		}
	}
}


function performAfterOpenBasketTasks()
{
	//Monitor the href of the target window
	//alert('performAfterOpenBasketTasks called');

	//The opened window starts off blank, so if we check straight away the window will get closed before the
	// new content opens!
	//window.setTimeout('checkForPaymentInitiated()',7000);

	//If the user resizes the browser window, we want to re-calculate the
	// position of the shoping basket window
	addEvent(window, "resize", recalculateBasketWindowPosition);
}

function recalculateBasketWindowPosition()
{
	//alert('recalculateBasketWindowPosition called');

	if(g_shopintwin != null)
	{
		g_shopintwin.centreWindow();
	}

	//alert('recalculateBasketWindowPosition completed');
}


function closeBasket()
{
	//If the shopper has removed any items or updated any quantities in the checkout screens
	// this will cause the shopper basket related plugins on the page to update.
	refreshShopperBasketPlugins();


	cancelCheckForPaymentInitiated();

	//De-register the event which monitors the window re-size to reposition
	// the shoping basket window.
	removeEvent(window, "resize", recalculateBasketWindowPosition);

	//
	//IE6 does not correctly place SELECT lists below z-index div tags
	// so we had to hide the SELECT lists to avoid them being visible and
	// accessible above our veil which the basket sits on top of.
	// Now they are closing the basket, we need to restore the display settings of
	// the SELECT lists which we hid.
	//
	if(BrowserDetect.browser == "Explorer" && BrowserDetect.version <= 6)
	{
		var selectListsStyle;

		if(g_existingPageSelectLists != 'undefined' && g_existingPageSelectLists != null)
		{
			//alert('closeBasket called g_existingPageSelectListsDisplaySettings:'+g_existingPageSelectListsDisplaySettings );
			//alert('closeBasket g_existingPageSelectLists.length:'+g_existingPageSelectLists.length);

			for (var i = 0; i < g_existingPageSelectLists.length; i++)
			{
			    selectListsStyle = g_existingPageSelectLists[i].style;
			    //alert('closeBasket selectListsStyle:'+selectListsStyle);

			    selectListsStyle.display = g_existingPageSelectListsDisplaySettings[i];
			}
		}
	}

	g_existingPageSelectLists = null;
	g_existingPageSelectListsDisplaySettings = null;

	//Clear the reference to this global basket window
	g_shopintwin = null;

	return true;
}

function addEvent(obj, evType, fn)
{
    //alert('addEvent evType:'+evType);

    if (obj.addEventListener)
    {
        obj.addEventListener(evType, fn, false);
        return true;
    }
    else if (obj.attachEvent)
    {
        var r = obj.attachEvent("on"+evType, fn);
        return r;
    }
    else
    {
        return false;
    }
}


function removeEvent(obj, evType, fn)
{
    //alert('removeEvent evType:'+evType);

    if (obj.removeEventListener)
    {
        obj.removeEventListener(evType, fn, false);
        return true;
    }
    else if (obj.detachEvent)
    {
        var r = obj.detachEvent("on"+evType, fn);
        return r;
    }
    else
    {
        return false;
    }
}

function addHiddenFormToPage(formName, formContent)
{
    //Make the page addition invisible
    var hiddenFormHTML = "<span style='display: none; width=0px; height=0px;'>"+formContent+"</span>";
    //alert('createVirtualForm hiddenFormHTML:'+hiddenFormHTML);

    var newSpan = document.createElement("span");
    //alert('createVirtualForm created wrapper span');

    newSpan.innerHTML = hiddenFormHTML;
    //alert('createVirtualForm set innerHTML on span:'+newSpan.innerHTML);

    var bodyRef = document.getElementsByTagName("body").item(0);
    //alert('createVirtualForm get page body:'+bodyRef);
    bodyRef.appendChild(newSpan);
    //alert('createVirtualForm append wrapper span into page');

    //alert('createVirtualForm formName:'+formName);
    var virtualForm = document.getElementById(formName);

    return virtualForm;
}

function initiatePayment(paymentInitiatedURL)
{
	//alert('initiatePayment called');

	//Find the payment gateway text start and end points
	var startOfPaymentGatewayText = paymentInitiatedURL.indexOf("pg=");
	var endOfPaymentGatewayText = paymentInitiatedURL.indexOf("&pgend=");

	if( startOfPaymentGatewayText != -1 && endOfPaymentGatewayText != -1)
	{
		//Extract the requierd payment method
		var paymentGateway = paymentInitiatedURL.substring(startOfPaymentGatewayText, endOfPaymentGatewayText);
		//e.g. paymentGateway will equal pg=paypal
		//alert('initiatePayment called for paymentGateway:'+paymentGateway);

		var uniqueNumber = getUniqueNumber();
		var URL = g_baseURL+'client/'+g_serverVersion+'/PaymentInitiator?'+paymentGateway+'&unique='+uniqueNumber;


		//Resets the communication mechanism back to the start.
		resetCallToServer();

		callToServer('PAYMENT_INITIATED', uniqueNumber, URL);
	}
	else
	{
		alert('Sorry, there is a problem attempting to initiate the payment process, the payment gateway is unknown!');
	}
}

function transferToPaymentGateway(paymentGatewayFormName, formData)
{
    //alert('transferToPaymentGateway called');
    var virtualForm = addHiddenFormToPage(paymentGatewayFormName, formData);

    var cancelReturnURL = document.getElementById('cancel_return_'+paymentGatewayFormName);
    //alert('transferToPaymentGateway cancelReturnURL: '+cancelReturnURL);
    if(cancelReturnURL != 'undefined' && cancelReturnURL != null)
    {
    	//Attempt to set the cancel return URL for Pay Pal to the current page location
    	cancelReturnURL.value = window.location.href;
    	//alert('transferToPaymentGateway set Payment Gateway form cancelReturnURL: '+cancelReturnURL);
    }


	virtualForm.submit();
	cleanUpVirtualForm(virtualForm);
}

function transferToPaymentGatewayFailure()
{
	//alert('transferToPaymentGatewayFailure called');
	alert('Sorry, there is a problem attempting to initiate the payment process, not all the items in your basket have a cost defined in the currency chosen!');

}

//http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
function getBasketHeight()
{
	//alert('getBasketHeight called');
	var adjustment = 75;
    	var height;

	try
	{
        if(BrowserDetect.OS == "iPhone/iPod")
        {
                //Set a long page compatible with iPhone scrolling for long pages.
                //Designed to work in landscape as well as portrait.
                height = 800;
        }
        else
        {
		  //http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
		  if( typeof( window.innerWidth ) == 'number' ) {
		    //Non-IE
		    height = window.innerHeight;
		  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		    //IE 6+ in 'standards compliant mode'
		    height = document.documentElement.clientHeight;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		    //IE 4 compatible
		    height = document.body.clientHeight;
		  }
        }
	}
	catch(err){
 	}

	if(height == 'undefined' || isNaN(height) == true || (height - adjustment) < 310)
	{
		//Minimum height we will accept
		height = 310 + adjustment;
	}

	height = height - adjustment;

	//alert('getBasketHeight height:'+height);

	return height;
}

//http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
function getBasketWidth()
{
	//alert('getBasketWidth called');
	var adjustment = 50;
    var width;

	try
	{
        if(BrowserDetect.platform == "iPhone")
        {
                //Set a smaller iPhone compatible size
                width = 320;
        }
        else
        {
            if( typeof( window.innerWidth ) == 'number' ) {
                //Non-IE
                width = window.innerWidth;
            } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
                //IE 6+ in 'standards compliant mode'
                width = document.documentElement.clientWidth;
            } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
                //IE 4 compatible
                width = document.body.clientWidth;
            }
        }
	}
	catch(err){
 	}

	if(width == 'undefined' || isNaN(width) == true || (width - adjustment) < 470)
	{
		//Minimum width we will accept
		width = 470 + adjustment;
	}
	else if( (width + adjustment) > 775)
	{
		//Max width we will want
		width = 725 + adjustment;
	}

	width = width - adjustment;

	//alert('getBasketWidth width:'+width);

	return width;
}

function testEcommerce()
{
    alert("Welcome "+g_clientID+" to the Shop Integrator ecommerce service");
}

