/*
* 2007.06.07 - Juan González-Vallinas
*              Indented and pretty printed the code, trying to fight the madness
* 
*
*/
function BasketViewDeliveryCharges ()
{
    document.location.href = 'dynamiccontent.aspx?loc=DL&subloc=1&menuId=55&pmenuId=0'
}


function clearField (field)
{
    if (field.value.substring(0, 3) == "***")
        field.value = ""
}

function GetProductID()
{
    return document.getElementById("hProductID").getAttribute("value");
}
function GetCatID()
{
    return document.getElementById("hCatID").getAttribute("value");
}
function GetImageLocation()
{
    return document.getElementById("hImageLocation").getAttribute("value");
}
function GetEnlargedImage()
{
    return document.getElementById("hEnlargedImage")
}
function GetLargeImage()
{
    return document.getElementById("hLargeImage")
}
function GetFocusType()
{
    return document.getElementById("FocusType")
}
function GetLargeButton()
{
    return document.getElementById("enlargeImageLink")
}
function IsImageEnlarged()
{
    return document.getElementById("IsImageEnlarged").getAttribute("value");
}

function fnEnlargeImage()
{
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;
    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (document && document.forms[formIndex] && document.forms[formIndex].b4nfindform)
            {
                cformIndex = formIndex;
            }
        }
    }
    var url = "";
    var imageUrl, buttonImage, isEnlarged, newimagename;
    buttonImage = GetLargeButton();
   
    if (IsImageEnlarged() == "false")
    {
        newimagename = GetEnlargedImage();
        buttonImage.src = "../images/bttnReduceImage.gif";
        buttonImage.alt = "Reduce Image"
        document.getElementById("IsImageEnlarged").setAttribute("value","true");
    }
    else 
    {
        newimagename = GetLargeImage();
        buttonImage.src = "../images/bttnEnlargeImage.gif";
        buttonImage.alt = "Enlarge Image"
        document.getElementById("IsImageEnlarged").setAttribute("value","false");
    }
    imageUrl = eval("document.images.largeImage_" + GetProductID());
    imageUrl.src = GetImageLocation() + newimagename.value;
}

function fnReduceImage ()
{
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;

    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (!(document && document.forms[formIndex] && document.forms[formIndex].b4nfindform))
                {
                }

            else
            {
                cformIndex = formIndex;
            }
        }
    }
    var obj, obj2, obj3, obj4, x, url = "";
    obj = eval("document.forms[cformIndex].largeImage_" + GetProductID());
    obj.src = imageloc + imagename;
  //  obj2 = eval("document.forms[cformIndex].enlargedImage_" + productid);
 //   obj2.src = "../images/spacer.gif";
    obj3 = eval("document.forms[cformIndex].enlargeImageLink");
    obj3.src = "../images/bttnEnlargeImage.gif";
    obj4 = eval("document.forms[cformIndex].reduceImageLink");
    obj4.src = "../images/spacer.gif";
    url = (document.location.href);
    var re = new RegExp('#linkReduce', 'gi');
    var re2 = new RegExp('#linkEnlarge', 'gi');
    var re3 = new RegExp('#Top', 'gi');
    url = url.replace(re, '');
    url = url.replace(re2, '');
    url = url.replace(re3, '');

    if (focusType == 1)
    {
        url = url + "#linkEnlarge";
    }

    else
    {
        url = url + "#Top";
    }

    document.location.href = url;
}

function HTMLPopup (path, width, height)
{
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;
    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (!(document && document.forms[formIndex] && document.forms[formIndex].b4nfindform))
                {
                }

            else
            {
                cformIndex = formIndex;
            }
        }
    }
    
            window.open(path, "", 'dependent=1,height=' + height + ',width=' + width
                    + ',titlebar=no,toolbar=0,resizable=0,left=100,top=150,scrollbars=1');
}

function catchKeyPress (code, sender)
{
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;

    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (!(document && document.forms[formIndex] && document.forms[formIndex].b4nfindform))
                {
                }

            else
            {
                cformIndex = formIndex;
            }
        }
    }

    var ret = null;
    testForEnterAndEsc();

    if (code == '13')
    {
        switch (sender.name)
        {
            case 'searchtext':
                ret = document.getElementById("btnSearch");

                break;

            case 'txtEmail':
                ret = document.getElementById("bttnSubscribe");

                break;
        }

        if (ret)
        {
            ret.click();
        }
    }

    else if (code == '27')
    {
        ret = document.getElementById("btnCancel");

        if (ret)
        {
            ret.click();
        }
    }
}

function testForEnterAndEsc ()
{
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;

    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (!(document && document.forms[formIndex] && document.forms[formIndex].b4nfindform))
                {
                }

            else
            {
                cformIndex = formIndex;
            }
        }
    }

    if (event.keyCode == 13 || event.keyCode == 27)
    {
        event.cancelBubble = true;
        event.returnValue = false;
    }
}

/*function ChooseDelivery ()
{
    document.forms[0].delid.value = document.forms[0].deliveryType.value;
    document.forms[0].action = "checkout3.aspx?&loc=t";
    document.forms[0].submit(this);
}*/

function ChooseDelivery()
{
var delId;
var deliveryType;
var currValue;
delId = document.getElementById('_ctl0_CenterContentPlaceHolder_delid');
deliveryType = document.getElementById("deliveryType");

if(delId == null)
{
    delId = document.getElementById("delid");
}
if(delId && deliveryType)
{
    delId.value = deliveryType.value;
}

     document.forms[0].action = "checkout3.aspx?&loc=t";
     document.forms[0].submit(this);
}

function ChooseSpecialDelivery ()
{
    document.forms[0].delid.value = document.forms[0].deliveryType.value;
    var btn = document.forms[0].SpecialDel;

    for (var i = 0; i < btn.length; i++)
    {
        if (btn[i].checked)
        {
            specialdeliveryTypeId = btn[i].value;
        }
    }

    document.forms[0].action = "checkout3.aspx?&loc=t&spdid=" + specialdeliveryTypeId;
    document.forms[0].submit(this);
}

function fnBuy4NowSearch ()
{
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;

    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (!(document && document.forms[formIndex] && document.forms[formIndex].b4nfindform))
                {
                }

            else
            {
                cformIndex = formIndex;
            }
        }
    }

    var searchword;

    if (!(document && document.forms[cformIndex] && document.forms[cformIndex].b4nSearch))
        {
        }

    else
    {
        searchword = document.forms[cformIndex].b4nSearch.value;
        document.location.href = "http://www.buy4now.ie/index.asp?st=1&stid=ALL&sv=" + searchword;
    }
}

function BuyButton (productID)
{
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;

    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (!(document && document.forms[formIndex] && document.forms[formIndex].b4nfindform))
                {
                }

            else
            {
                cformIndex = formIndex;
            }
        }
    }

    var noRows, validchoice;
    validchoice = true;

    if (!(document && document.forms[cformIndex] && document.forms[cformIndex].hMVCount))
        {
        }

    else
    {
        noRows = document.forms[cformIndex].hMVCount.value;
    }

    if (!(document && document.forms[cformIndex] && document.forms[cformIndex].hCanBuy))
    {
        document.forms[cformIndex].action = "productdetail.aspx?pid=" + productID + "&loc=P&add=1";
        document.forms[cformIndex].submit(this);
    }

    else
    {
        if (document.forms[cformIndex].hCanBuy.value == "N")
        {
            alert('There is no product available for these options.\n\nPlease choose again.');
        }

        else
        {
            for (i = 0; i < noRows; i++)
            {
                thisDropDown = "document.forms[cformIndex].mv_" + i + "[document.forms[cformIndex].mv_" + i
                    + ".selectedIndex].value";
                thisDropDown = eval(thisDropDown);

                if (thisDropDown == "none")
                {
                    validchoice = false;
                }
            }

            if (validchoice == true)
            {
                document.forms[cformIndex].action = "productdetail.aspx?pid=" + productID + "&loc=P&add=1";
                document.forms[cformIndex].submit(this);
            }

            else
            {
                alert('Please select your preferred option(s)');
            }
        }
    }
}

function MoreDetail (productID, catID)
{
    var catpage = "", url = "", target = "";
    url = document.location.href;

    if (url.indexOf("aspx") != - 1)
    {
        target = "productdetail.aspx?pid=";
    }

    else
    {
        target = "aspx/productdetail.aspx?pid=";
    }

    if (!(document && document.forms[0] && document.forms[0].hCatId))
        {
        }

    else
    {
        catpage = document.forms[0].hCatId.value;
    }

    if (catID == "")
    {
        catID = catpage;
    }
    document.location.href = target + productID + "&loc=P&catid=" + catID;
}

function BuyButtonCategory (productID, catid)
{
    var noRows, validchoice, url = "", target = "";
    validchoice = true;
    url = document.location.href;

    if (url.indexOf("aspx") != - 1)
    {
        target = "productdetail.aspx?pid=";
    }

    else
    {
        target = "aspx/productdetail.aspx?pid=";
    }

    if (!(document && document.forms[0] && document.forms[0].hMVCount))
        {
        }

    else
    {
        noRows = document.forms[0].hMVCount.value;
    }

    if (!(document && document.forms[0] && document.forms[0].hCanBuy))
    {
        document.forms[0].action = target + productID + "&loc=P&add=1&catid=" + catid;
        document.forms[0].submit(this);
    }

    else
    {
        if (document.forms[0].hCanBuy.value == "N")
        {
            alert('There is no product available for these options.\n\nPlease choose again.');
        }

        else
        {
            for (i = 0; i < noRows; i++)
            {
                thisDropDown = "document.forms[0].mv_" + i + "[document.forms[0].mv_" + i + ".selectedIndex].value";
                thisDropDown = eval(thisDropDown);

                if (thisDropDown == "none")
                {
                    validchoice = false;
                }
            }

            if (validchoice == true)
            {
                document.forms[0].action = target + productID + "&loc=P&add=1&catid=" + catid;
                document.forms[0].submit(this);
            }

            else
            {
                alert('Please select your preferred option(s)');
            }
        }
    }
}

function MoreFromCategory (productID)
{
    var url = "", target = "";
    url = document.location.href;

    if (url.indexOf("aspx") != - 1)
    {
        target = "shopping.aspx?catid=";
    }

    else
    {
        target = "aspx/shopping.aspx?catid=";
    }

    document.location.href = target + productID + "&loc=C";
}

function ReturnToPrevious ()
{
    history.go(- 1);
}

function BasketRemove (basketid)
{
    document.location.href = "basket.aspx?loc=B&a=1&bid=" + basketid;
}

function SmallBasketRemove (basketid)
{
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;

    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (!(document && document.forms[formIndex] && document.forms[formIndex].b4nfindform))
                {
                }

            else
            {
                cformIndex = formIndex;
            }
        }
    }

    var rExp = /&/gi;
    var url = document.location.href;
    url = url.replace(rExp, "||");
    document.location.href = "basket.aspx?loc=B&a=4&bid=" + basketid + "&url=" + url;
}

function BasketChangeQuantity (basketid, qty)
{
    document.location.href = "basket.aspx?loc=B&a=2&bid=" + basketid + "&qty=" + qty;
}


function SaveGiftNotes (loc, url)
{
    var frm = document.forms[0];
    var strNote = "";

    for (i = 0; i < frm.length; i++)
    {
        e = frm.elements[i];

        if (e.type == 'textarea' && e.name.indexOf("note_") != - 1)
        {
            if (e.value.length > 1800)
            {
                alert('Please keep your note less than 1800 characters. \nYou currently have ' + e.value.length
                          + ' characters');
            }

            else
            {
                strNote += e.id + ":" + e.value + "|";
            }
        }
    }

    document.forms[0].action = url;
    document.forms[0].submit(this);
}

function BasketGiftNote (basketid, act)
{
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;

    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (!(document && document.forms[formIndex] && document.forms[formIndex].b4nfindform))
                {
                }

            else
            {
                cformIndex = formIndex;
            }
        }
    }

    var frm = document.forms[cformIndex];
    var note;
    note = "note_" + basketid;

    if (act == "0")
    {
        for (i = 0; i < frm.length; i++)
        {
            e = frm.elements[i];

            if (e.type == 'textarea' && e.name.indexOf(note) != - 1)
            {
                e.disabled = false;
                e.value += "|";
                document.forms[cformIndex].action = "basket.aspx?loc=B&a=5&bid=" + basketid + "&act=" + act;
                document.forms[cformIndex].submit(this);
            }
        }
    }

    else if (act == "1")
    {
        document.forms[cformIndex].action = "basket.aspx?loc=B&a=5&bid=" + basketid + "&act=" + act;
        document.forms[cformIndex].submit(this);
    }

    else if (act == "2")
    {
        for (i = 0; i < frm.length; i++)
        {
            e = frm.elements[i];

            if (e.type == 'textarea' && e.name.indexOf(note) != - 1)
            {
                e.disabled = false;
                document.forms[cformIndex].action = "basket.aspx?loc=B&a=5&bid=" + basketid + "&act=" + act;
                document.forms[cformIndex].submit(this);
            }
        }
    }
}

function CheckoutGiftNote (basketid, act)
{
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;

    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (!(document && document.forms[formIndex] && document.forms[formIndex].b4nfindform))
                {
                }

            else
            {
                cformIndex = formIndex;
            }
        }
    }

    var frm = document.forms[cformIndex];
    var note;
    note = "note_" + basketid;

    if (act == "0")
    {
        for (i = 0; i < frm.length; i++)
        {
            e = frm.elements[i];

            if (e.type == 'textarea' && e.name.indexOf(note) != - 1)
            {
                e.disabled = false;
                e.value += "|";
                document.forms[cformIndex].action = "checkout3.aspx?loc=B&a=5&bid=" + basketid + "&act=" + act;
                document.forms[cformIndex].submit(this);
            }
        }
    }

    else if (act == "1")
    {
        document.forms[cformIndex].action = "checkout3.aspx?loc=B&a=5&bid=" + basketid + "&act=" + act;
        document.forms[cformIndex].submit(this);
    }

    else if (act == "2")
    {
        for (i = 0; i < frm.length; i++)
        {
            e = frm.elements[i];

            if (e.type == 'textarea' && e.name.indexOf(note) != - 1)
            {
                e.disabled = false;
                document.forms[cformIndex].action = "checkout3.aspx?loc=B&a=5&bid=" + basketid + "&act=" + act;
                document.forms[cformIndex].submit(this);
            }
        }
    }
}

function BasketRemoveAll ()
{
    document.location.href = "basket.aspx?loc=B&a=3";
}

function BasketContinueShopping ()
{
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;
    
    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (!(document && document.forms[formIndex] && document.forms[formIndex].b4nfindform))
                {
                }

            else
            {
                cformIndex = formIndex;
            }
        }
    }

    var sUrl;
    var index = 0;
    var index2 = 0;
    var index3 = 0;

    if (document != null && document.referrer != null)
    {            
        var previousUrl = document.getElementById("_hiddenReferrer");
        var previousUrlLink = previousUrl.innerHTML;

        var amp = new RegExp("&amp;", "g");
        var updatedUrl = previousUrlLink.replace(amp, "&");

        previousUrlLink = updatedUrl;

        if (previousUrlLink != "" || previousUrl != null)
        { 
            sUrl = previousUrlLink;
        } 
        else
        {
            sUrl = "home.aspx?loc=H";
        }
        

        index2 = sUrl.indexOf("productdetail.aspx");
        
        if (index2 != - 1)
        {
            index3 = sUrl.indexOf("catid=");

            if (index3 != - 1)
            {
                sUrl = sUrl.replace(/productdetail/gi, "shopping");
                sUrl = sUrl.replace(/loc=P/gi, "loc=C");
            }
        }
        
        document.location.href = sUrl;
    }

    else
    {
        document.location.href = "home.aspx?loc=H";
    }
}

function BasketGoToCheckout (url)
{
    SaveGiftNotes('', url)
}

 // VS. 2007.03.14, Bug 3876. Made many changes. 
 // Now supporting calculation of promotion and changing Was and Ex. PRF price
function ChangeDropDown (m_mvCount, m_imagePath, m_currencySymbol)
{
     /* changed 01.02.2005 to include thisProductWasPrice*/
    var hProductID, thisDropDown, splitString, noRows, BasePriceRunningTotal, RRPPriceRunningTotal, p_affectsBase,
        p_affectsRRP, thisProductBasePrice, thisProductRRPPrice, promotionBasePrice, promotionRRPPrice,
        promotionBaseAttributeId, promotionRewardTypeId, promotionReward, currencyRate, promotionWasPrice,
        EXPRFPrice, PRFPrice, thisProductEXPRFPrice, thisProductPRFPrice, promotionApplies;
    p_affectsBase = "";
    p_affectsRRP = "";
    noRows = document.forms[0].hMVCount.value;
    hProductID = document.forms[0].hProductID.value;
    thisDropDown = "document.forms[0].mv_" + m_mvCount + "[document.forms[0].mv_" + m_mvCount + ".selectedIndex].value";
    thisDropDown = eval(thisDropDown);
    
    thisProductBasePrice = eval("document.forms[0].productBasePrice_" + hProductID);
    thisProductRRPPrice = eval("document.forms[0].productRRPPrice_" + hProductID);
   
    thisProductEXPRFPrice = eval(document.getElementById("ExEMCPrice_" + hProductID));
    
    thisProductPRFPrice = eval(document.getElementById("EMCPrice_" + hProductID));
    
    thisProductWasPrice = eval(document.getElementById("WasPrice_" + hProductID));
    promotionBasePrice = parseFloat(eval("document.forms[0].promotionBasePrice.value"));
    
    promotionRRPPrice = parseFloat(eval("document.forms[0].promotionRRPPrice.value"));
    
    promotionBaseAttributeId = parseInt(eval("document.forms[0].promotionBaseAttributeId.value"));
    
    promotionRewardTypeId = parseInt(eval("document.forms[0].promotionRewardTypeId.value"));
    
    promotionReward = parseFloat(eval("document.forms[0].promotionReward.value"));
    
    currencyRate = parseFloat(eval("document.forms[0].promotionCurrencyRate.value"));
    
    
    var promoId = document.forms[0].promotionId;
    
    if (!isNaN(promotionReward))
    {
        promotionApplies = true;
    }
    else
    {
        promotionApplies = false;
    }
   
 
    if (thisProductPRFPrice)
    {
        EXPRFPrice = parseFloat(thisProductEXPRFPrice.innerText.replace(m_currencySymbol, ''));
        PRFPrice = parseFloat(thisProductPRFPrice.innerText.replace(m_currencySymbol, ''));
    }
    
    BasePriceRunningTotal = promotionBasePrice * currencyRate;
    RRPPriceRunningTotal = promotionRRPPrice * currencyRate;
    if (thisDropDown != "none")
    {
         //hide "From" text 
        if (document.forms[0].fromText)
        {
            document.forms[0].fromText.value = "";
        }
        splitString = thisDropDown.split("|");
        if (splitString[3] != "")
        {
            document.forms[0].LargeProductImage.src = m_imagePath + splitString[3];
        }
    }
    for (i = 0; i < noRows; i++)
    {
        thisDropDown = "document.forms[0].mv_" + i + "[document.forms[0].mv_" + i + ".selectedIndex].value";
        thisDropDown = eval(thisDropDown);

        if (thisDropDown != "none")
        {
            splitString = thisDropDown.split("|");
            p_affectsBase = parseFloat(splitString[1]);
            p_affectsRRP = parseFloat(splitString[2]);
            if ((thisDropDown != "none") && (!(isNaN(p_affectsBase))))  // && thisProductWasPrice_obj
            {
                BasePriceRunningTotal = BasePriceRunningTotal + p_affectsBase;
             //thisProductWasPrice_obj.value = m_currencySymbol + FormatNum((WasPriceRunningTotal + p_affectsBase),2);//change	
            }
            if ((thisDropDown != "none") && (!(isNaN(p_affectsRRP))))
            {
                RRPPriceRunningTotal = RRPPriceRunningTotal + p_affectsRRP;
            }
        }
    }
     //base price
    if (promotionBaseAttributeId == 19)
    {
        if (thisProductWasPrice)
        {
            promotionWasPrice = BasePriceRunningTotal;
        }
         
        BasePriceRunningTotal = PromotionCalculation(BasePriceRunningTotal, promotionRewardTypeId, promotionReward, promotionApplies);

        if (thisProductPRFPrice)
        {
            EXPRFPrice = BasePriceRunningTotal - PRFPrice;
        }
    }

     //RRP price
    if (promotionBaseAttributeId == 20)
    {
        if (thisProductWasPrice)
        {
            promotionWasPrice = RRPPriceRunningTotal;
        }

        RRPPriceRunningTotal = PromotionCalculation(RRPPriceRunningTotal, promotionRewardTypeId, promotionReward, promotionApplies);

        if (thisProductPRFPrice)
        {
            EXPRFPrice = RRPPriceRunningTotal - PRFPrice;
        }
    }

    if (ValidateExclusions(noRows) == true)
    {
        if (thisProductBasePrice)
        {
            thisProductBasePrice.value = m_currencySymbol + FormatNum(BasePriceRunningTotal, 2);
        }

        if (thisProductRRPPrice)
        {
            thisProductRRPPrice.value = "RRP " + m_currencySymbol + FormatNum(RRPPriceRunningTotal, 2);
        }

        if (thisProductPRFPrice)
        {
            thisProductEXPRFPrice.innerText = m_currencySymbol + FormatNum(EXPRFPrice, 2);
        }

        if (thisProductWasPrice)
        {
            thisProductWasPrice.innerText = m_currencySymbol + FormatNum(promotionWasPrice, 2);
        }
    }

    if (ValidateExclusions(noRows) == false)
    {
        thisProductBasePrice.value = "Not Available";
        alert('There is no product available for these options.\n\nPlease choose again.');
        document.forms[0].hCanBuy.value = "N";
    }
}

function PromotionCalculation (price, rewardTypeID, reward, promotionApplies)
{
    if (promotionApplies)
    {
        if (rewardTypeID == "1") // money off
        {
            price = price - reward;
        }
        if (rewardTypeID == "2") // percent off
        {
            price = price * (1 - (reward / 100));
        }
    }
    return price;
}

function ValidateExclusions (noRows)
{
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;

    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (!(document && document.forms[formIndex] && document.forms[formIndex].b4nfindform))
                {
                }

            else
            {
                cformIndex = formIndex;
            }
        }
    }

    var exCount, p_exID, p_attID, p_attRowID;
    var arrAttValues = new Array(noRows);
    var isValid = true;
    exCount = parseFloat(eval("document.forms[cformIndex].hExCount.value"));
    exTotal = parseFloat(eval("document.forms[cformIndex].hExTotal.value"));

    for (i = 0; i < noRows; i++)
    {
        thisDropDown = "document.forms[cformIndex].mv_" + i + "[document.forms[cformIndex].mv_" + i
            + ".selectedIndex].value";
        thisDropDown = eval(thisDropDown);
        splitString = thisDropDown.split("|");
        p_attRowID = parseFloat(splitString[0]);

        if (!(isNaN(p_attRowID)))
        {
            arrAttValues[i] = p_attRowID;
        }
    }

    var currentExID = 0;
    var matchCount = 0;
    var recCount = 0;

    for (j = 0; j < exCount; j++)
    {
        thisDropDown = "document.forms[cformIndex].ex_" + j + ".value";
        thisDropDown = eval(thisDropDown);
        splitString = thisDropDown.split("|");
        p_exID = parseFloat(splitString[0]);
        p_attID = parseFloat(splitString[1]);
        p_attRowID = parseFloat(splitString[2]);

        if (currentExID != 0)
        {
            currentExID = p_exID;
        }

        for (k = 0; k < noRows; k++)
        {
            if (arrAttValues[k] == p_attRowID)
            {
                matchCount = matchCount + 1;
            }

            if (currentExID != p_exID)
            {
                currentExID = p_exID;
                matchcount = 0;
                recCount = 0;
            }
        }

        if (matchCount == exCount)
        {
            isValid = false;
            break;
        }

        matchcount = 0;
        recCount = 0;
    }

    return isValid;
}

function FormatNum (expr, decplaces)
{
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;

    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (!(document && document.forms[formIndex] && document.forms[formIndex].b4nfindform))
                {
                }

            else
            {
                cformIndex = formIndex;
            }
        }
    }

    var str = "" + Math.round(eval(expr) * Math.pow(10, decplaces));

    while (str.length <= decplaces)
    {
        str = "0" + str
    }

    var decpoint = str.length - decplaces;
    return str.substring(0, decpoint) + "." + str.substring(decpoint, str.length);
}

function IncreaseQty (productID)
{
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;

    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (!(document && document.forms[formIndex] && document.forms[formIndex].b4nfindform))
                {
                }

            else
            {
                cformIndex = formIndex;
            }
        }
    }

    var obj, x;
    obj = eval("document.forms[cformIndex].qty_" + productID);
    x = obj.value;
    x = parseInt(x) + 1;

    if (x > 999)
    {
        x = 999;
    }

    obj.value = x;
}

function DecreaseQty (productID)
{
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;

    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (!(document && document.forms[formIndex] && document.forms[formIndex].b4nfindform))
                {
                }

            else
            {
                cformIndex = formIndex;
            }
        }
    }

    var obj, x;
    obj = eval("document.forms[cformIndex].qty_" + productID);
    x = obj.value;

    if (x > 1)
    {
        x = parseInt(x) - 1;
    }

    obj.value = x;
}

 /*
 * Event launched when the quantity of products in the basket changes
 *
 */
function BasketChangeQty (productID, qty)
{
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;
    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (document && document.forms[formIndex] && document.forms[formIndex].b4nfindform)
            {
                cformIndex = formIndex;
            }
        }
    }
    var obj, x;
    obj = eval("document.forms[cformIndex].qty_" + productID);
    x = obj.value;
    x = parseInt(x) + parseFloat(qty);
    if (x > 999)
    {
        x = 999;
    }
    if (x < 1)
    {
        BasketRemove(productID);
    }

    else
    {
        obj.value = x;
        BasketChangeQuantity(productID, x);
    }
}


function BasketGiftWrap (origin, productID, action)
{
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;

    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (!(document && document.forms[formIndex] && document.forms[formIndex].b4nfindform))
                {
                }

            else
            {
                cformIndex = formIndex;
            }
        }
    }

    var obj, cbox, x, wraptype;
    obj = eval("document.forms[cformIndex].qty_" + productID);
    x = obj.value;
    cbox = eval("document.forms[cformIndex].gifttype_" + productID);
    wraptype = cbox.value;
    document.forms[cformIndex].action
        = "modify.aspx?loc=B&origin=" + origin + "&bid=" + productID + "&qty=" + x + "&action=" + action
        + "&wraptype=" + wraptype;
    document.forms[cformIndex].submit(this);
}

function UpdateVoucher ()
{
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;

    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (!(document && document.forms[formIndex] && document.forms[formIndex].b4nfindform))
                {
                }

            else
            {
                cformIndex = formIndex;
            }
        }
    }

    var vCode = "";
    vCode = document.forms[cformIndex].txtVoucherCode.value;

    if (vCode != "")
    {
        document.location.href = "checkout3.aspx?loc=T&vc=" + vCode;
    }
}

function ViewRange (categoryID, type)
{
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;

    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (!(document && document.forms[formIndex] && document.forms[formIndex].b4nfindform))
                {
                }

            else
            {
                cformIndex = formIndex;
            }
        }
    }

    if (type == "cat")
    {
        document.location.href = "category.aspx?catid=" + categoryID + "&loc=R";
    }

    if (type == "list")
    {
        document.location.href = "shopping.aspx?catid=" + categoryID + "&loc=C";
    }
}

 //checkout 1b
function CheckForSignUpEnter (inputbutton, evt)
{
    var key;
    var newkey;
    var obj;
    var nkey;
    var tempkeyword;
    var rExp;
    var netscapekey;

    if (navigator.appName == 'Netscape')
    {
        netscapekey = evt.which;
        key = netscapekey;
    }

    else
    {
        key = window.event.keyCode;
    }

    if (key == 13)
    {
        if (navigator.appName == 'Netscape')
        {
            evt.cancelBubble = true;
            evt.returnValue = false;
        }

        else
        {
            event.cancelBubble = true;
            event.returnValue = false;
        }

        var ret = null;
        ret = document.getElementById(inputbutton);

        if (ret)
        {
            ret.focus();
            ret.click();
        }
    }
}

 //checkout 1b
 //used on homepage
 //gift cert sections
var g_nStep = 5;
var g_nMax = 5000;
var g_nMin = 5;

function fnIncr ()
{
    if (! fnValidate())
        return false;

    var txtAmount = fnFindCtrl("txtAmount");
    var nAmount = eval(txtAmount.value);
    nAmount = nAmount + g_nStep;

    if (nAmount <= g_nMax)
    {
        txtAmount.value = nAmount.toString();
    }

    return false;
}

function fnDcr ()
{
    if (! fnValidate())
        return false;

    var txtAmount = fnFindCtrl("txtAmount");
    var nAmount = eval(txtAmount.value);
    nAmount = nAmount - g_nStep;

    if (nAmount >= g_nMin)
    {
        txtAmount.value = nAmount.toString();
    }

    return false;
}

function Option_Select (amt)
{
    var nAmount = eval(amt);
    var txtAmount = fnFindCtrl("txtAmount");

    if (nAmount == 0)
    {
        txtAmount.value = "";
        txtAmount.focus();
    }

    else
        txtAmount.value = nAmount;
}

function fnValidate ()
{
    var txtAmount = fnFindCtrl("txtAmount");
    var nAmount = parseInt(txtAmount.value, 10);

    if (isNaN(nAmount) == true)
    {
        alert("Sorry, Invalid Amount");
        txtAmount.focus();
        return false;
    }

    else if ((nAmount % g_nStep) > 0)
    {
        alert("Amount must be a multiple of \u20AC" + g_nStep.toString());
        txtAmount.focus();
        return false;
    }

    else if (nAmount < g_nMin || nAmount > g_nMax)
    {
        alert("Amount must be between \u20AC" + g_nMin.toString() + " and \u20AC" + g_nMax.toString());
        txtAmount.focus();
        return false;
    }

    else
    {
        return true;
    }
}

function fnBuy ()
{
    return;
}

function fnFindCtrl (strCtrlID)
{
    for (var i = 0; i < document.forms[0].elements.length; i++)
    {
        if (document.forms[0].elements[i].name.indexOf(":" + strCtrlID) > - 1)
        {
            return document.forms[0].elements[i];
        }
    }

    return null;
}

 //gift cert sections
function CheckIsNumeric (source, args)
{
    var tstr;
    var arrStr;
    var arrCount;
    tstr = args.Value;
    arrStr = tstr.split("\r\n");
    arrCount = arrStr.length;

    for (var i = 0; i < arrCount; i++)
    {
        if (arrStr[i].length > 0)
        {
            if (isNaN(arrStr[i]))
            {
                args.IsValid = false;
                return;
            }
        }
    }

    args.IsValid = true;
    return;
}

 //from payment control
function showsecurityhelp ()
{
    window.open("securitycode.htm", "", "dependent=1, titlebar=0, toolbar=0, resizable=0, width=500, height=450");
}

function checkPayment (i)
{
    if (i == 1)
    {
        if (!(document && document.forms[0] && document.forms[0].b4nPayment_ddlUserCards))
            {
            }

        else
        {
            document.forms[0].b4nPayment_ddlUserCards.disabled = false;
        }

            document.forms[0]._ctl0_CenterContentPlaceHolder_b4nPayment_cboCardType.disabled = false;
            document.forms[0]._ctl0_CenterContentPlaceHolder_b4nPayment_cboMonth.disabled = false;
            document.forms[0]._ctl0_CenterContentPlaceHolder_b4nPayment_cboYear.disabled = false;
            document.forms[0]._ctl0_CenterContentPlaceHolder_b4nPayment_txtSecurityCode.disabled = false;
            document.forms[0]._ctl0_CenterContentPlaceHolder_b4nPayment_txtCardNumber.disabled = false;
    }

    else
    {
        if (!(document && document.forms[0] && document.forms[0].b4nPayment_ddlUserCards))
            {
            }

        else
        {
            document.forms[0].b4nPayment_ddlUserCards.disabled = true;
        }

            document.forms[0]._ctl0_CenterContentPlaceHolder_b4nPayment_cboCardType.disabled = false;
            document.forms[0]._ctl0_CenterContentPlaceHolder_b4nPayment_cboMonth.disabled = false;
            document.forms[0]._ctl0_CenterContentPlaceHolder_b4nPayment_cboYear.disabled = false;
            document.forms[0]._ctl0_CenterContentPlaceHolder_b4nPayment_txtSecurityCode.disabled = false;
            document.forms[0]._ctl0_CenterContentPlaceHolder_b4nPayment_txtCardNumber.disabled = false;
    }
}
 //from payment control

function MM_openBrWindow (theURL, winName, features)
{
    window.open(theURL, winName, features);
}

function MM_swapImgRestore ()
{
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;
    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (document && document.forms[formIndex] && document.forms[formIndex].b4nfindform)
            {
                cformIndex = formIndex;
            }
        }
    }
    var i, x, a = document.MM_sr;
    for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++)
    {    
        x.src = x.oSrc;
    }
}

function MM_preloadimages ()
{
    var d = document;

    if (d.images)
    {
        if (! d.MM_p)
            d.MM_p = new Array();

        var i, j = d.MM_p.length, a = MM_preloadimages.arguments;

        for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0)
            {
                d.MM_p[j] = new Image;
                d.MM_p[j++].src = a[i];
            }
    }
}

function MM_findObj (n, d)
{
    var p, i, x;

    if (! d)
        d = document;

    if ((p = n.indexOf("?")) > 0 && parent.frames.length)
    {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }

    if (!(x = d[n]) && d.all)
        x = d.all[n];

    for (i = 0; ! x && i < d.forms.length; i++)
        x = d.forms[i][n];

    for (i = 0; ! x && d.layers && i < d.layers.length; i++)
        x = MM_findObj(n, d.layers[i].document);

    if (! x && d.getElementById)
        x = d.getElementById(n);

    return x;
}

function MM_swapImage ()
{
    var i, j = 0, x, a = MM_swapImage.arguments;
    document.MM_sr = new Array;
    
    for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null)
        {
            document.MM_sr[j++] = x;

            if (! x.oSrc)
                x.oSrc = x.src;

            x.src = a[i + 2];
        }
}

 //search
function CheckForEnterReturnSearch (inputbutton)
{
    var key;
    var newkey;
    var obj;
    var nkey;
    var tempkeyword;
    var rExp;

var netscapekey;


    if (navigator.appName == 'Netscape')
    {
	    netscapekey = evt.which;
        key = netscapekey;
    }

    else
    {
        key = window.event.keyCode;
    }

    if (key == 13)
    {
        event.cancelBubble = true;
        event.returnValue = false;
        var ret = null;
        ret = document.getElementById(inputbutton);

        if (ret)
        {
            ret.click();
        }
    }
}

function GoSearch ()
{
    if (document.forms[0].searchtext.value != "")
    {
        document.location.href = "./aspx/search.aspx?loc=S&sv=" + document.forms[0].searchtext.value;
    }
}

 //search
 //voucher control
function CheckForEnterReturnSearch (inputbutton)
{
    var key;
    var newkey;
    var obj;
    var nkey;
    var tempkeyword;
    var rExp;

    if (navigator.appName == 'Netscape')
    {
        key = netscapekey
    }
    else
    {
        key = window.event.keyCode;
    }

    if (key == 13)
    {
        event.cancelBubble = true;
        event.returnValue = false;
        var ret = null;
        ret = document.getElementById(inputbutton);

        if (ret)
        {
            ret.click();
        }
    }
}
 //voucher control
 function ChangeUPPMText(m_currencySymbol,pid)
{

	
	var uppm_obj, base_uppm_obj, thisDropDown, m_mvCount, noRows, unit, p_UPPM, p_UNIT, splitString, m_mvCount_obj;
	
	thisDropDown = "";
	m_mvCount = "";
	noRows = 0;
	unit = "";
	p_UPPM = "";
	p_UNIT = "";
	
	//pid = document.forms[0].hProductID.value;
	uppm_obj = eval("document.forms[0].uppmText_" + pid); //UPPM column in b4nattributeproductfamily
	
	base_uppm_obj = eval("document.forms[0].baseUPPM_" + pid); 
	unit_obj = eval("document.forms[0].unitType_" + pid); //Kg, L, M, Each

	m_mvCount_obj = document.forms[0].hMVCount;
	
	if (!m_mvCount_obj && m_mvCount_obj != null && m_mvCount_obj != "undefined")
	{	
		m_mvCount = document.forms[0].hMVCount.value;
		noRows = document.forms[0].hMVCount.value;
	}
	
	for(i=0; i < noRows; i++)
	{
		thisDropDown = "document.forms[0].mv_" + i + "[document.forms[0].mv_" + i + ".selectedIndex].value";
		thisDropDown = eval(thisDropDown);
		
		if (thisDropDown && thisDropDown != "none")
		{
			splitString = thisDropDown.split("|");
			p_UPPM = parseFloat(splitString[4]);
		}
	}
	
	if (!p_UPPM || p_UPPM == "" || p_UPPM == "NaN")
	{
		if (base_uppm_obj && base_uppm_obj != null && base_uppm_obj != "undefined")
			p_UPPM = parseFloat(base_uppm_obj.value);
		else
			p_UPPM = 0;
	}

	if (unit_obj && unit_obj.value)
	{
		p_UNIT = unit_obj.value;
	}
	
	/*
	0	Each
	1	Kg
	2	Litre
	3	Metre
	4	SQ Metre
	*/
		

	if (p_UNIT == "0")
	{p_UNIT = "None";}
	else if (p_UNIT == "1")
	{p_UNIT = "Kg";}
	else if (p_UNIT == "2")
	{p_UNIT = "Litre";}
	else if (p_UNIT == "3")
	{p_UNIT = "Metre";}
	else if (p_UNIT == "4")
	{p_UNIT = "SQ Metre";}
	else
	{p_UNIT = "";}
	
	/*
		for (i=0;i<1000;i++)
		{
			if (document.forms[0].elements[i])
			{
				var x = document.forms[0].elements[i];
				if (x.name == 'uppmText_774')
					alert(x.name)s
			
			}
		}
	*/
	if (!(p_UNIT == "None" || p_UNIT == ""))
	{
		
		uppm_obj.value = "(" + m_currencySymbol + FormatNum(p_UPPM,2) + " per " + p_UNIT + ")";
		uppm_obj.height = 15;
	}
	else
	{
		uppm_obj.height = 0;
	}
}

 function ShowProductGallery(filename,filenameenlarged,productId)
 {
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;
    if (numberForms > 1)
    {
        for (formIndex = 0; formIndex < numberForms; formIndex++)
        {
            if (document && document.forms[formIndex] && document.forms[formIndex].b4nfindform)
            {
                cformIndex = formIndex;
            }
        }
    }
    var isEnlarged;
    buttonImage = eval("document.forms[cformIndex].enlargeImageLink");
    isEnlarged = eval("document.forms[cformIndex].IsImageEnlarged");
    if (isEnlarged.value == "true")
    {     
        buttonImage.src = "../images/bttnEnlargeImage.gif";
        isEnlarged.value = "false";
    }
    var el;
    el = document.getElementsByName('largeImage_' + productId)[0];
 
    if(el)
    {
    el.src = filename;
    }
    else
    {
    el = document.getElementById('largeImage_' + productId);

    if(el)
    {
    el.src = filename;
    }
    }
    
 }
 
//My Account 
 function CheckForEnterReturn(inputbutton) 
{var key; var newkey; var obj; 
var nkey; var tempkeyword; var rExp; 
	if (navigator.appName == 'Netscape') 
	{ key = netscapekey } 
	else { key = window.event.keyCode; } 
	if (key == 13) { event.cancelBubble = true; event.returnValue = false; var ret=null; 
		ret=document.geenterButtontElementById(inputbutton); 
		if(ret) { ret.click(); } 
	} 
} 



