//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)
{
   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)
{
    document ['DoMoveNext'].action = xpx
    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()
 
}vatrate1 = 0
store_image = new Array()
store_image[0] = new Array('','','View Order')
store_image[1] = new Array('','','Cancel Order')
store_image[2] = new Array('b_remove_2.gif','b_remove.gif','Remove Item')
store_image[3] = new Array('b_ordernow_2.gif','b_ordernow.gif','Order Now')
store_image[4] = new Array('b_cancelorder_2.gif','b_cancelorder.gif','Cancel Cart Order')
store_image[5] = new Array('b_shopformore_2.gif','b_shopformore.gif','Shop For More')
store_image[6] = new Array('','','Swap Item')
store_image[7] = new Array('b_addtocart_2.gif','b_addtocart.gif','Add To Order')
store_image[8] = new Array('button_go.gif','button_go.gif','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')

function Cat1_Over (varObj, strImagename, strclass, strtagname ) {
varObj.className =  strclass
top.status='' }
function Cat2_Over (varObj, strImagename, strclass, strtagname ) {
varObj.className =  strclass
top.status='' }
