//allows mouseover of images on buttons. store_image is an array of the button images stored in javascript_buttons.js
//x - image index in store_image
//y - 0 for mouseover, 1 for mouseout
//t - img name index in the page.  = -1 if only once occurrence of button on page.
//Called by most pages in code
function fimg_swap(x,y,t)
{
    if (t > -2)
    {
        imgname = store_image[x][2]
        if (!(t == -1))
        {
            imgname = imgname + t
        }
        document [imgname].src = "images/" + store_image[x][y]
    }
    top.status=""
    if (y == 0)
    {
        top.status = store_image[x][2]
    }
}


//Used in productsumlist.htm for paging through products
function newpage(xaction, xtype, parameters)
{
    if (parameters.length > 0)
        document.DoMoveNext.action = "search.asp?" + parameters;
    if (xaction == 'increment')
        document.DoMoveNext ["MoveNext"].value = xtype;
    else
        document.DoMoveNext ["AbsPage"].value = xtype;
    document ["DoMoveNext"].submit();
}

       
//Clears viewcart.  Called by left.htm and viewcart.asp
function yescancel()
{
    if (window.confirm("Clicking on OK will cancel your order"))
    {
        document.yescancel.submit()
    }
}


// fires product page refresh on change in partnolist select box
function partnochange(xxx)
{
    eval("document ['order" + xxx + "top'].action='products.asp'")
    eval("document ['order" + xxx + "top'].submit()")
}


//Validates product before allowing ordering - (was in products.asp)
function dosubmit(x)
{
    if (isNaN(parseInt(eval("document ['" + x + "'].quantity.value"))))
    {
        alert("Please enter a valid number in quantity ");
        return;
        eval("document ['" + x + "'].quantity.focus()");
    }
    else 
    {
        if (eval("document ['" + x + "'].quantity.value") <= 0 )
        {
            alert("Quantity cannot be zero or less");
            return;
            eval("document ['" + x + "'].quantity.focus()");
        }
    }

    if (eval("document ['" + x + "'].Fabric_Colour"))
    {
        tempz = eval("document ['" + x + "'].Fabric_Colour.value")
        if (tempz.replace(/ /g,"") == "")
        {
            alert("Please select a colour first")
            return
        }
    }

    eval("document ['" + x + "'].submit()"); 
}


//Submits gift wrapping in shopping  cart
function submitGiftWrapping(x)
{
    //alert(x.AutoGiftWrapping1234-x-giftwrapping.checked);
    //alert(eval(x.mpmpAutoGiftWrapping-x-giftwrapping.value);
    /*
        if(x.AutoGiftWrapping1234-x-giftwrapping.checked == true)
        {
            x.mpmpAutoGiftWrapping-x-giftwrapping.value = 10;   
        }
        else
        {
            x.mpmpAutoGiftWrapping-x-giftwrapping.value = 0;
        }
    */
    eval("document ['" + x + "'].submit()"); 
}


// Used to toggle between different classes/ backgrounds when related products are ticked
function dorelrow(tpq, ttpartno)
{
    if (tpq) 
    {   
        document.all['relcomprow' + ttpartno].className='relcomprowsel'
    }
    else
    {
        document.all['relcomprow' + ttpartno].className='relcomproword'
    }
}


function updateprice2(fb,tb)
{
    ttb = "spsp" + tb

    // current base unit price
    var yq = fb ["all"].pricetag.innerText
    yq = yq.replace(/,/g,'')

    var yy = new Number(yq)

    // new part number of component  selected
    zpp = fb [tb].value
    //extract price of this choice and put it into zz
    var zi1 = zpp.lastIndexOf('-x-') + 3
    var zq = zpp.slice(zi1)
    zq = zq.replace(/,/g,'')

    // original value of component
    var uq = fb [ttb].value
    uq = uq.replace(/,/g,'')

    var uu = new Number(uq)

    // Now put it all together
    var zz = new Number(zq)
    var totot = yy + zz - uu

    //Now ensures 2 decimal places always displayed
    totot1 = Math.round(  ( (Math.round(totot * 100) / 100) + 0.001 ) * 1000 ) / 1000
    var totot1str = '' + totot1
    var xpo = totot1str.length
    var totot2 = CommaFormatted(totot1str.substr(0,xpo - 1))

    tototv1 = Math.round(  ( (Math.round(totot1 * (1 + vatrate1) * 100) / 100) + 0.001 ) * 1000 ) / 1000
    var tototv1str = '' + tototv1
    var xpov = tototv1str.length
    var tototv2 = CommaFormatted(tototv1str.substr(0,xpov - 1))

    if (fb ["all"].pricetag)
        fb ["all"].pricetag.innerText = totot2

    if (fb ["all"].pricetag2)
        fb ["all"].pricetag2.innerText = totot2

    if (fb ["all"].pricetagv)
        fb ["all"].pricetagv.innerText = tototv2

    if (fb ["all"].pricetagv2)
        fb ["all"].pricetagv2.innerText = tototv2

    // update spsp... with current selected value for next time
    fb [ttb].value = zz
}


function updateprice3(fb,tb)
{
    // current base unit price
    var yq = fb ["all"].pricetag.innerText
    yq = yq.replace(/,/g,'')

    var yy = new Number(yq)

    // new part number of component  selected
    var zpp = tb.name

    var zi2 = 'mpmp' + zpp

    var zq = fb [zi2].value
    zq = zq.replace(/,/g,'')

    // Now put it all together
    var zz = new Number(zq)

    if (tb.checked)
        var totot = yy + zz
    else
        var totot = yy - zz

    //Now ensures 2 decimal places always displayed
    totot1 = Math.round(  ( (Math.round(totot * 100) / 100) + 0.001 ) * 1000 ) / 1000
    var totot1str = '' + totot1
    var xpo = totot1str.length
    totot2 = CommaFormatted(totot1str.substr(0,xpo - 1))

    tototv1 = Math.round(  ( (Math.round(totot1 * (1 + vatrate1) * 100) / 100) + 0.001 ) * 1000 ) / 1000
    var tototv1str = '' + tototv1
    var xpov = tototv1str.length
    var tototv2 = CommaFormatted(tototv1str.substr(0,xpov - 1))

    if (fb ["all"].pricetag)
        fb ["all"].pricetag.innerText = totot2

    if (fb ["all"].pricetag2)
        fb ["all"].pricetag2.innerText = totot2

    if (fb ["all"].pricetagv)
        fb ["all"].pricetagv.innerText = tototv2

    if (fb ["all"].pricetagv2)
        fb ["all"].pricetagv2.innerText = tototv2
}


function updateprice4(fb,tb)
{
    ttb = "spsp" + tb.name

    // current base unit price
    var yq = fb ["all"].pricetag.innerText
    yq = yq.replace(/,/g,'')

    var yy = new Number(yq)

    // new part number of component  selected
    zpp = tb.value
    //extract price of this choice and put it into zz
    var zi1 = zpp.lastIndexOf('-x-') + 3
    var zq = zpp.slice(zi1)
    zq = zq.replace(/,/g,'')

    // original value of component
    var uq = fb [ttb].value
    uq = uq.replace(/,/g,'')

    var uu = new Number(uq)

    // Now put it all together
    var zz = new Number(zq)
    var totot = yy + zz - uu

    //Now ensures 2 decimal places always displayed
    totot1 = Math.round(  ( (Math.round(totot * 100) / 100) + 0.001 ) * 1000 ) / 1000
    var totot1str = '' + totot1
    var xpo = totot1str.length
    var totot2 = CommaFormatted(totot1str.substr(0,xpo - 1))

    tototv1 = Math.round(  ( (Math.round(totot1 * (1 + vatrate1) * 100) / 100) + 0.001 ) * 1000 ) / 1000
    var tototv1str = '' + tototv1
    var xpov = tototv1str.length
    var tototv2 = CommaFormatted(tototv1str.substr(0,xpov - 1))

    if (fb ["all"].pricetag)
        fb ["all"].pricetag.innerText = totot2

    if (fb ["all"].pricetag2)
        fb ["all"].pricetag2.innerText = totot2

    if (fb ["all"].pricetagv)
        fb ["all"].pricetagv.innerText = tototv2

    if (fb ["all"].pricetagv2)
        fb ["all"].pricetagv2.innerText = tototv2

    // update spsp... with current selected value for next time
    fb [ttb].value = zz
}


function CommaFormatted(amount)
{
    var delimiter = ","; // replace comma if desired
    var a = amount.split('.',2)
    var d = a[1];
    var i = parseInt(a[0]);
    if(isNaN(i)) { return ''; }
    var minus = '';
    if(i < 0) { minus = '-'; }
    i = Math.abs(i);
    var n = new String(i);
    var a = [];
    while(n.length > 3)
    {
        var nn = n.substr(n.length-3);
        a.unshift(nn);
        n = n.substr(0,n.length-3);
    }
    if(n.length > 0) { a.unshift(n); }
    n = a.join(delimiter);
    if(d.length < 1) { amount = n; }
    else { amount = n + '.' + d; }
    amount = minus + amount;
    return amount;
}


function updateprice(fb) 
{
    fb.action = 'products.asp?isbaseunit=1';
    fb.submit()
}

  
function addtopart(y,z)
{ 
    document ["addtoform"].partno.value = y

    if (document ["compare"] ["quant"+y+z])
        document ["addtoform"].quantity.value = document ["compare"] ["quant"+y+z].value
    document ["addtoform"].submit()
}


function dosubmit4()
{  
    document ["compare"].action = 'code/addtoordermultiple.asp?fromprodsumlistmultiform=yes'
    document ["compare"].submit()
}


function sortsubmit(xpx,sn1,sn1d, querystring)
{
    document ['DoMoveNext'].action = xpx + '?' + querystring;
    document ['DoMoveNext'].CurrentPage.value = 1
    document ['DoMoveNext'].sortname1.value = sn1
    document ['DoMoveNext'].sortdirection1.value = sn1d
    document ['DoMoveNext'].sortname2.value = ''
    document ['DoMoveNext'].submit()
}


function sboxscreload(rlscid,box)
{  
    frmname = "ParamSearch" + rlscid
    document [frmname].action='products.asp?reload=YES&reloadbox='+box+'&subcatid='+rlscid
    document [frmname].submit()
}


function sboxcreload(rlcid,box)
{
    frmname = "ParamSearch" + rlcid
    document [frmname].action='products.asp?reload=YES&reloadbox='+box+'&catid='+rlcid
    document [frmname].submit()
}


function sboxhfreload(box, s_action)
{
    frmname = "ParamSearch" 
    document [frmname].action='main.asp?reload=YES&reloadbox='+box
    if (s_action.length > 0) 
    {
        document [frmname].action = s_action
    }
    document [frmname].submit()
}


function gosearch(xxform)
{
    for (ipq = 1; ipq <=15; ipq++)
    {  
        if (xxform["searchbox" + ipq])
        {
            zzzbox = xxform["searchbox" + ipq].value
            if (zzzbox == "xx00xx")
            {
                alert("Please select a value")
                return
            }

        }
    }
    xxform.submit()
}


// copied existing naming convention even though it isnt great
function dosubmit5()
{  
    document ["compare"].action = '/Compare.asp'
    document ["compare"].submit()
}


// updates page url when searching prices with url-rewriting on (with searchboxallaslist)
function updatepricesearch(isSearchPage)
{  
    var priceLoc, priceminIsValid, pricemaxIsValid, querystr, newurl;
    priceminIsValid = 0;
    pricemaxIsValid = 0;
    querystr = "";
    newurl = document.location.href;
    if (isSearchPage == 0)
    {
        var newurlArr = newurl.split("/");
        for (i=2;i<newurlArr.length;i++)
        {
            if (newurlArr[i].substring(0,3).toLowerCase() == "scp")
            {
                newurlArr[i] = "sp/category";
                newurlArr[i+1] += "/subcategory";
                if (document ["DoMoveNext"])
                {
                    if (document ["DoMoveNext"].elements["subcatid"])
                    {
                        newurlArr[i+2] += "/subcatID/" + document ["DoMoveNext"].elements["subcatid"].value;
                    }
                }
                break;
            }
            if ((newurlArr[i].substring(0,3).toLowerCase() == "mcp") || (newurlArr[i].substring(0,3).toLowerCase() == "pcp"))
            {
                newurlArr[i] = "sp/category";
                break;
            }
        }
        newurl = newurlArr.join("/");
    }
    //Check pricemin is a number
    if (document ["searchboxAllPrices"].searchboxpricemin.value.length > 0)
    {
        if (!isNaN(parseInt(document ["searchboxAllPrices"].searchboxpricemin.value)))
        {
            priceminIsValid = 1;
        }
        else
        {
            document ["searchboxAllPrices"].searchboxpricemin.focus();
            alert("Please enter a number for Minimum price.")
            return false;
        }
    }
    //Check pricemax is a number
    if (document ["searchboxAllPrices"].searchboxpricemax.value.length > 0)
    {
        if (!isNaN(parseInt(document ["searchboxAllPrices"].searchboxpricemax.value)))
        {
            pricemaxIsValid = 1;
        }
        else
        {
            document ["searchboxAllPrices"].searchboxpricemax.focus();
            alert("Please enter a number for Maximum price.")
            return false;
        }
    }
    //Check pricemin and/or pricemax was entered
    if (priceminIsValid + pricemaxIsValid == 0)
    {
        document ["searchboxAllPrices"].searchboxpricemin.focus();
        alert("Please enter a Minimum and Maximum price.")
    }
    
    
    if (newurl.indexOf("?") > -1)
    {
        querystr = newurl.substring(newurl.indexOf("?"),newurl.length)
        newurl = newurl.substring(0,newurl.indexOf("?"));
    }
    if (newurl.indexOf("#") > -1)
    {
        querystr = querystr + newurl.substring(newurl.indexOf("#"),newurl.length)
        newurl = newurl.substring(0,newurl.indexOf("#"));
    }
    //Remove old .html and pricemin and pricemax
    if (newurl.substring(newurl.length-5, newurl.length) == ".html")
    {
        newurl = newurl.substring(0,newurl.length-5);
    }
    priceLoc = newurl.indexOf("/pricemin/")
    if (priceLoc > -1)
    {
        if (newurl.indexOf("/", priceLoc+10) > -1)
        {
            newurl = newurl.substring(0,priceLoc) + newurl.substring(newurl.indexOf("/", priceLoc+10), newurl.length);
        }
        else
        {
            newurl = newurl.substring(0,priceLoc);
        }
    }
    priceLoc = newurl.indexOf("/pricemax/")
    if (priceLoc > -1)
    {
        if (newurl.indexOf("/", priceLoc+10) > -1)
        {
            newurl = newurl.substring(0,priceLoc) + newurl.substring(newurl.indexOf("/", priceLoc+10), newurl.length);
        }
        else
        {
            newurl = newurl.substring(0,priceLoc);
        }
    }
    if (priceminIsValid == 1)
    {
        newurl = newurl + "/pricemin/" + document ["searchboxAllPrices"].searchboxpricemin.value;
    }
    if (pricemaxIsValid == 1)
    {
        newurl = newurl + "/pricemax/" + document ["searchboxAllPrices"].searchboxpricemax.value;
    }
    document.location.href = newurl + ".html" + querystr;
}
vatrate1 = 0.2
store_image = new Array()
store_image[0] = new Array('','','View Order')
store_image[1] = new Array('','','Cancel Order')
store_image[2] = new Array('bu-remove.jpg','bu-remove.jpg','Remove Item')
store_image[3] = new Array('bu-proceedtocheckout.jpg','bu-proceedtocheckout.jpg','Order Now')
store_image[4] = new Array('b_cancelorder_2.gif','b_cancelorder.gif','Cancel Cart Order')
store_image[5] = new Array('bu-shopformore.jpg','bu-shopformore.jpg','Shop For More')
store_image[6] = new Array('','','Swap Item')
store_image[7] = new Array('bu-addtobasket.jpg','bu-addtobasket.jpg','Add To Order')
store_image[8] = new Array('bu-go.jpg','bu-go.jpg','Go Search')
store_image[9] = new Array('go.gif','go.gif','Go Logon')
store_image[11] = new Array('b_savequote_2.gif','b_savequote.gif','Save Quote')
store_image[12] = new Array('b_recoverquote_2.gif','b_recoverquote.gif','Recover Quote')
store_image[13] = new Array('','','Fast checkout through Google')

function Cat1_Over (varObj, strImagename, strclass, strtagname ) {
varObj.className =  strclass
top.status='' }
function Cat2_Over (varObj, strImagename, strclass, strtagname ) {
varObj.className =  strclass
top.status='' }

