// EdiCart ver. 1.1
// Copyright (C) Hood Associates 2000
// This source code is the property of Hood Associates


function EdiCart_addItem(inCode,inProduct,inPrice,inTax,inQty,inDel, inChoice1, inChoice2, inDiscount){
//  This function is deprecated
  var cookieList = document.cookie;
  var ediStart = cookieList.indexOf(this.cookieName) + this.cookieName.length + 1;
  var ediEnd = cookieList.indexOf(";",ediStart);
  if(ediEnd == -1) ediEnd = cookieList.length;
  var cookieStr = unescape(cookieList.substring(ediStart,ediEnd));
  var cookieStr = cookieList.substring(ediStart,ediEnd);
  if(cookieStr.length > 4000){
    alert("Maximum No. of Titles reached - Please send order and add this item to a new order");
        return;
  }
  var itemLoc = this.checkItemCode(inCode);
  if(itemLoc != -1 && inChoice1.substr(0,4)!= "/C00"){
    var itemQty = parseInt(this.getItemQty(itemLoc)) + parseInt(inQty);
        this.changeItemQty(itemQty,itemLoc);
    this.tmpCart[this.tmpCart.length] = this.cart[itemLoc];
    if(this.isCookie == 1){this.saveToCookie()}
    return;
  }
//  if(inProduct.length > 25){inProduct = inProduct.substr(0,22) + "...";}
//  var itemLine =  new Array(inCode, escape(inProduct), inPrice, inTax, inQty, "0", escape(inChoice1), escape(inChoice2), inDiscount)
  var itemLine =  new Array(inCode, inProduct, inPrice, inTax, inQty, inDel, inChoice1, inChoice2, inDiscount)
  this.addItemArray(itemLine);

}

function EdiCart_addStdItem(inCode,inProduct,inPrice,inTax,inQty,inDel, inChoice1, inChoice2, inDiscount){
//  The item array is joined to overcome multi dimensional array problems
//  when IE5 uses the opener property of a window
  var itemLine =  new Array(inCode, inProduct, inPrice, inTax, inQty, inDel, inChoice1, inChoice2, inDiscount)
  this.addItemArray(itemLine);
}

function EdiCart_addItemArray(inItem){
  this.addDeliveryValue(inItem[5],1);
  if(this.taxRate != -1){inItem[3] = this.taxRate}
  this.cart[this.cart.length] = inItem.join(this.itemMarker);
  this.tmpCart[this.tmpCart.length] = inItem.join(this.itemMarker);
  this.itemLines = this.cart.length;
  if(this.isCookie == 1){this.saveToCookie()}
}

function EdiCart_incrementItem(inCode,inPrice,inTax,inQty, inProduct, inChoice1, inChoice2,inDiscount){
//  The item array is joined to overcome multi dimensional array problems
//  when IE5 uses the opener property of a window

  var itemLine =  new Array(inCode, inPrice, inProduct, inTax, inWeight, inChoice1, inChoice2, inDiscount)
  this.incrementItemArray(itemLine);
}

function EdiCart_incrementItemArray(inItem){
  var itemNo = this.getItemIndex(inItem[0]);
  if(itemNo == -1){
    inItem[3] = 1;
    this.cart[this.cart.length] = inItem.join(this.itemMarker);
    this.tmpCart[this.tmpCart.length] = inItem.join(this.itemMarker);
    if(this.isCookie == 1){this.saveToCookie()}
  }
  else{
    var newQty = this.getItemQty(itemNo);
    ++newQty;
    this.changeItemQty(newQty,itemNo);
    this.cart[this.cart.length] = this.cart[itemNo];
   if(this.isCookie == 1){this.saveToCookie()}
  }
  this.itemLines = this.cart.length;
}

function EdiCart_getItemArray(itemNo){
  var retItem = new Array();
  retItem = this.cart[itemNo].split(this.itemMarker);
  return retItem;
}

function EdiCart_getItemIndex(inCode){
  for(var i=0; i< this.cart.length; ++i){
    var thisItem = this.getItemArray(i);
    if(thisItem[0] == inCode){return i}
  }
  return -1;
}
function EdiCart_getItemOnOrder(inCode){
  var itemNo = this.getItemIndex(inCode);
  if(itemNo == -1){
    return 0;
  }
  return this.getItemQty(itemNo);
}
function EdiCart_changeItemArray(itemArray, itemNo){
// ** Note - This does not save to the Cookie

  this.cart[itemNo] = itemArray.join(this.itemMarker);
}

function EdiCart_fixedMult(inOne, inTwo){
  return Math.round(inOne * inTwo * 100)/100;
}

function EdiCart_discMult(inOne, inTwo){
  return Math.round(inOne * inTwo * 10000)/10000;
}

function EdiCart_fixedAdd(inOne, inTwo){
//  return  parseInt(parseInt(Math.round(inOne * 100)) + parseInt(Math.round(inTwo * 100)))/100;
  return  parseInt(Math.round(inOne * 100) + Math.round(inTwo * 100))/100;
}

function EdiCart_setDeliveryValue(inValue){
  this.deliveryValue = inValue;
  this.cartValue = this.fixedAdd(this.cartValue, this.deliveryValue);

  this.deliveryValue = this.formatOp(this.deliveryValue,2);
  this.cartValue = this.formatOp(this.cartValue,2);
  if(this.isCookie == 1){this.saveToCookie()};
}
function EdiCart_setDiscountValue(inValue){
  this.discountValue = inValue;
  this.cartValue = this.fixedAdd(this.cartValue, 0-this.discountValue);

  this.discountValue = this.formatOp(this.discountValue,2);
  this.cartValue = this.formatOp(this.cartValue,2);
  if(this.isCookie == 1){this.saveToCookie()};
}

function EdiCart_addDeliveryValue(inValue,inQty){
  var tmpValue = this.fixedMult(inValue,inQty);
  this.deliveryValue = this.fixedAdd(this.deliveryValue,tmpValue);
  this.cartValue = this.fixedAdd(this.cartValue,tmpValue);

//  this.deliveryValue = this.formatOp(this.deliveryValue,2);
//  this.cartValue = this.formatOp(this.cartValue,2);
  if(this.isCookie == 1){this.saveToCookie()};

}
function EdiCart_getDeliveryValue(){
  return this.deliveryValue;
}

function EdiCart_getDiscountValue(){
  return this.discountValue;
}
function EdiCart_getDeliveryMethod(){
  return this.deliveryMethod;
}

function EdiCart_setDeliveryMethod(inStr){
  this.deliveryMethod = inStr;
  if(this.isCookie == 1){this.saveToCookie()};
}

function EdiCart_checkItemCode(inCode){
  var noLines = eCart.getLines();
  for(tCount =0; tCount < noLines; tCount++){
    if(inCode == this.getItemCode(tCount)){
          return tCount;
        }
  }
   return -1;
}
function EdiCart_getItemCode(inItem){
  var thisItem = this.cart[inItem].split(this.itemMarker)
  return thisItem[0];
}
function EdiCart_getItemLineRef(inItem){
  var thisItem = this.cart[inItem].split(this.itemMarker)
  return thisItem[6];
}
function EdiCart_getItemBranchCode(inItem){
  var thisItem = this.cart[inItem].split(this.itemMarker)
  return thisItem[7];
}
function EdiCart_getItemPrice(inItem){
  var thisItem = this.cart[inItem].split(this.itemMarker)
  return this.formatOp(thisItem[2],2);
}

function EdiCart_getItemDiscountRate(inItem){
  var thisItem = this.cart[inItem].split(this.itemMarker)
  return this.formatOp(thisItem[8],2);
}
function EdiCart_getItemPriceDiscount(inItem){
  var thisItem = this.cart[inItem].split(this.itemMarker)
  var thisDiscount = this.discMult(thisItem[8], 0.01);
  return this.fixedMult(thisItem[2], thisDiscount);
}
function EdiCart_getItemValueDiscount(inItem){
  var thisItem = this.cart[inItem].split(this.itemMarker)
  var thisDiscount = this.getItemPriceDiscount(inItem);
  return this.formatOp(this.fixedMult(thisItem[4],thisDiscount),2);
}
function EdiCart_getItemTaxRate(inItem){
  var thisItem = this.cart[inItem].split(this.itemMarker)
  return this.formatOp(thisItem[3],2);
}
function EdiCart_getItemQty(inItem){
  var thisItem = this.cart[inItem].split(this.itemMarker)
  return thisItem[4];
}
function EdiCart_getItemProduct(inItem){
  var thisItem = this.cart[inItem].split(this.itemMarker)
  return thisItem[1];
}
function EdiCart_getItemTitle(inItem){
  var thisItem = this.cart[inItem].split(this.itemMarker)
  if(thisItem[1].indexOf(this.titleMarker) != -1){
   thisItem = thisItem[1].split(this.titleMarker);
  } 
  return thisItem[1];
}
function EdiCart_getItemAuthor(inItem){
  var thisItem = this.cart[inItem].split(this.itemMarker)
  if(thisItem[1].indexOf(this.titleMarker) != -1){
   thisItem = thisItem[1].split(this.titleMarker);
   return thisItem[0]; 
  } 
  return "";
}
function EdiCart_getItemValue(inItem){
  var thisItem = this.cart[inItem].split(this.itemMarker)
  var thisNett = this.fixedMult(thisItem[2],thisItem[4]);
 
  return this.formatOp(this.fixedAdd(thisNett,0-this.getItemValueDiscount(inItem)),2);
}

function EdiCart_getItemTax(inItem){
   var thisItem = this.cart[inItem].split(this.itemMarker)
   var lineTax = this.fixedMult(thisItem[3],this.getItemValue(inItem));
   if(this.getItemTaxRate(inItem) < 0){
     lineTax = 0;
   }
   return this.formatOp(this.fixedMult(lineTax,.01),2);
}

function EdiCart_getItemDelivery(inItem){
  var thisItem = this.cart[inItem].split(this.itemMarker)
  return this.formatOp(thisItem[5],2);
}
function EdiCart_getItemCompany(inItem){
// uses delivery field
  var thisItem = this.cart[inItem].split(this.itemMarker)
  return thisItem[5];
}

function EdiCart_clear(){
  this.cart = new Array();
  this.cart.length = 0;
  this.itemLines = 0;
  this.deliveryValue = 0;
  this.taxRate = -1; 
  this.deliveryMethod = "";
  this.discountValue = 0;
  this.cookieData = "0000000000000"
  this.tmpCart[this.tmpCart.length] = this.cookieData;
  if(this.isCookie == 1){this.saveToCookie()}
}
function EdiCart_clearCookieTitles(){
  this.tmpCart = new Array();
  if(this.isCookie == 1){this.saveToCookie()}
}
function EdiCart_changeItemQty(inValue, inItem){
  if(isNaN(inValue)){inValue = 0}

  var thisItem = this.cart[inItem].split(this.itemMarker)
  thisItem[4] = inValue;
  this.cart[inItem] = thisItem.join(this.itemMarker);
  this.tmpCart[this.tmpCart.length] = thisItem.join(this.itemMarker);
 if(this.isCookie == 1){this.saveToCookie()}
}
function EdiCart_changeItemDiscountRate(inValue, inItem){
  if(isNaN(inValue)){inValue = 0}

  var thisItem = this.cart[inItem].split(this.itemMarker)
  thisItem[8] = inValue;
  this.cart[inItem] = thisItem.join(this.itemMarker);
  this.tmpCart[this.tmpCart.length] = thisItem.join(this.itemMarker);
 if(this.isCookie == 1){this.saveToCookie()}
}

function EdiCart_changeLineRef(inLineRef, inItem){
  var thisItem = this.cart[inItem].split(this.itemMarker)
  thisItem[6] = inLineRef;
  this.cart[inItem] = thisItem.join(this.itemMarker);
  this.tmpCart[this.tmpCart.length] = thisItem.join(this.itemMarker);
  if(this.isCookie == 1){this.saveToCookie()}
}
function EdiCart_changeBranchCode(inBranchCode, inItem){
  var thisItem = this.cart[inItem].split(this.itemMarker)
  thisItem[7] = inBranchCode;
  this.cart[inItem] = thisItem.join(this.itemMarker);
  this.tmpCart[this.tmpCart.length] = thisItem.join(this.itemMarker);
  if(this.isCookie == 1){this.saveToCookie()}

}

function EdiCart_removeZeroedItems(){
  var tmpItem
  var tmpItems = this.cart;
  this.cart = new Array();
  this.itemLines = 0;
  this.isCookie = -1;
  for(var i = 0; i < tmpItems.length; i++){
    tmpItem = tmpItems[i].split(this.itemMarker);
    if(tmpItem[4] != 0){
      this.addItemArray(tmpItem);
    }else{
      this.tmpCart[this.tmpCart.length] = tmpItem;
        }
    
  }
  this.isCookie = 1; 
  if(this.isCookie == 1){this.saveToCookie()}
}

function EdiCart_formatOp(inNum, inDec){
  var tNum = inNum.toString();
  if (tNum.indexOf(".") == -1){
    tNum = tNum + ".0";
  }
  for( var i=tNum.length - tNum.indexOf("."); i <= inDec; i++){
    tNum = tNum + "0";
  }
  return tNum;
}

function EdiCart_restoreFromCookie(){
  var cookieTest = document.cookie;
  if(cookieTest.indexOf(this.cookieName) == -1){return;};
//   alert("aaa" +  this.titleData + "---");

  var saveCookieStatus = this.isCookie;
  var cookieList = document.cookie;
  this.isCookie = 0;
//  this.clear();
  this.isCookie = saveCookieStatus;
  var ediStart = cookieList.indexOf(this.cookieName) + this.cookieName.length + 1;
  var ediEnd = cookieList.indexOf(";",ediStart);
  if(ediEnd == -1) ediEnd = cookieList.length;
//  var cookieStr = unescape(cookieList.substring(ediStart,ediEnd));
  var cookieStr = unescape(cookieList.substring(ediStart,ediEnd));
//alert(cookieStr.length);
  var endHeader = cookieStr.indexOf(this.headerMarker);
  var cookieHeadStr = cookieStr.substring(0,endHeader);
  var cookieHeader = cookieHeadStr.split(",");
  var cookieFlag = cookieHeader[0];
  if( cookieFlag == "1"){this.isCookie = 1}
  this.taxRate = cookieHeader[1];
  this.deliveryValue = cookieHeader[2];
  this.deliveryValue = this.formatOp(this.deliveryValue,2);
  this.deliveryMethod = cookieHeader[3];
  this.discountValue = cookieHeader[4];
  this.discountValue = this.formatOp(this.discountValue,2);
// var cookieInfo = cookieStr.substring(endHeader + 1);
//  this.cookieData = cookieInfo;

 var cookieInfo = this.titleData;
  this.cookieData = cookieInfo;
//  alert("ccc" + cookieInfo + "---");
  if(cookieInfo.length > 0){
  var ediItems = cookieInfo.split(this.lineMarker);
  var noItems = ediItems.length;
  if (ediEnd - ediStart > 1){
    for(var i=0; i<noItems; ++i){
      this.cart[i] = ediItems[i];
      this.itemLines = i + 1;
    }
  }
  }
  document.cookie= this.cookieName + '=' + escape(this.isCookie.toString()+','+this.taxRate.toString()+','+this.deliveryValue.toString()+','+this.deliveryMethod+','+this.discountValue.toString()+this.headerMarker) + ';path=/;domain=ulverscroft.com;'
}

function EdiCart_saveToCookie(){
//alert("save");
//  var cData = " ";
//  if(this.tmpCart.join(this.lineMarker).length == 0){
//     alert(this.isCookie.toString()+','+this.taxRate.toString()+','+this.deliveryValue.toString()+','+this.deliveryMethod+','+this.discountValue.toString()+this.headerMarker);
//     alert(this.isCookie.toString() + ',' + this.taxRate.toString() + ',' + this.deliveryValue.toString());
//alert(this.taxRate);
//     alert(this.isCookie.toString() + ',' + this.taxRate.toString());
//   cData = escape(this.isCookie.toString()+','+this.taxRate.toString()+','+this.deliveryValue.toString()+','+this.deliveryMethod+','+this.discountValue.toString()+this.headerMarker);
//alert(this.tmpCart.join(this.lineMarker).length);
//   }else{
//    cData = escape(this.isCookie.toString()+','+this.taxRate.toString()+','+this.deliveryValue.toString()+','+this.deliveryMethod+','+this.discountValue.toString()+this.headerMarker+this.tmpCart.join(this.lineMarker));
//   }
//alert(this.tmpCart.join(this.lineMarker).length);
//alert(escape(this.isCookie.toString()+','+this.taxRate.toString()+','+this.deliveryValue.toString()+','+this.deliveryMethod+','+this.discountValue.toString()+this.headerMarker+this.tmpCart.join(this.lineMarker)));
//  document.cookie= this.cookieName + '=' + cData + ';path=/;domain=ulverscroft.com;';
  document.cookie= this.cookieName + '=' + escape(this.isCookie.toString()+','+this.taxRate.toString()+','+this.deliveryValue.toString()+','+this.deliveryMethod+','+this.discountValue.toString()+this.headerMarker+this.tmpCart.join(this.lineMarker)) + ';path=/;domain=ulverscroft.com;';
 // document.cookie= this.cookieName + '=' + escape(this.isCookie.toString()+','+this.taxRate.toString()+','+this.deliveryValue.toString()+','+this.deliveryMethod+','+this.discountValue.toString()+this.headerMarker+this.tmpCart.join(this.lineMarker)) + ';path=/;domain=ulverscroft.com;'
// alert(document.cookie);
//  document.cookie= this.cookieName + '=' + escape(this.isCookie.toString()+','+this.taxRate.toString()+','+this.deliveryValue.toString()+','+this.deliveryMethod+','+this.discountValue.toString()+this.headerMarker+this.cart.join(this.lineMarker)) + ';path=/;domain=ulverscroft.com;'
//  document.cookie= this.cookieName + '=' + this.isCookie.toString()+','+this.taxRate.toString()+','+this.deliveryValue.toString()+','+this.deliveryMethod+','+this.discountValue.toString()+this.headerMarker+this.cart.join(this.lineMarker) + ';path=/;domain=ulverscroft.com;'
//  var cookieTest = unescape(document.cookie);
//  if(cookieTest.indexOf(this.cookieName) == -1){
//    return false;
//  }
//alert(document.cookie);
  return true;
}

function EdiCart_setCookieOn(){
  this.isCookie = 1;
}

function EdiCart_getGoodsValue(){
  var retValue = 0;
  for(var i=0; i<this.itemLines; ++i){
    retValue = this.fixedAdd(retValue,this.getItemValue(i));
  }
  return this.formatOp(retValue,2);
}

function EdiCart_getTaxValue(){
  var retValue = 0;
  for(var i=0; i<this.itemLines; ++i){
    retValue = this.fixedAdd(retValue,this.getItemTax(i));
  }
  return this.formatOp(retValue,2);
}

function EdiCart_getCartValue(){
  var retValue = 0;
  for(var i=0; i<this.itemLines; ++i){
    retValue = this.fixedAdd(retValue,this.getItemValue(i));
    retValue = this.fixedAdd(retValue,this.getItemTax(i));
  }
//  retValue = this.fixedAdd(retValue,this.deliveryValue);
  retValue = this.fixedAdd(retValue,0-this.discountValue);
  return this.formatOp(retValue,2);
}

function EdiCart_getQty(){
  var retValue = 0;
  for(var i=0; i<this.itemLines; ++i){
    retValue = this.fixedAdd(retValue,this.getItemQty(i));
  }
  return retValue;
}

function EdiCart_getWeight(){
  var retValue = 0;
  for(var i=0; i<this.itemLines; ++i){
    retValue = this.fixedAdd(retValue,this.getItemWeight(i));
  }
  return this.formatOp(retValue,2);
}


function EdiCart_getLines(){
  return this.itemLines;
}

function EdiCart_setTaxRate(inRate){
  this.taxRate = inRate;
  if(this.isCookie == 1){this.saveToCookie()}
}

function EdiCart_refreshItemTaxRates(){
  var thisItem;
  if(this.taxRate != -1){
    for(var i=0; i<this.itemLines; ++i){
      thisItem = this.getItemArray(i);
      thisItem[3] = this.taxRate;
      this.changeItemArray(thisItem,i);
    }
  if(this.isCookie == 1){this.saveToCookie()}
  }

}
function EdiCart(){
  // Constructor for the cart object

  this.itemLines = 0;
  this.deliveryValue = 0;
  this.deliveryMethod = " ";
  this.cookieData = " ";
  this.titleData = " ";
  this.cart = new Array();
  this.tmpCart = new Array();
  this.cookieName = "ediCartObject";
  this.itemMarker = "||";
  this.lineMarker = "<||>";
  this.headerMarker = "$"
  this.titleMarker = "!*!"; 
  this.isCookie = 1;
  this.taxRate = -1;
  this.discountValue = 0;

  // Public Methods
  this.addItem = EdiCart_addItem;
  this.addStdItem = EdiCart_addStdItem;
  this.addItemArray = EdiCart_addItemArray;
  this.incrementItem = EdiCart_incrementItem;
  this.incrementItemArray = EdiCart_incrementItemArray;

  this.getItemArray = EdiCart_getItemArray;
  this.changeItemArray = EdiCart_changeItemArray;

  this.getGoodsValue = EdiCart_getGoodsValue;
  this.getTaxValue = EdiCart_getTaxValue;
  this.getCartValue = EdiCart_getCartValue;
  this.getQty = EdiCart_getQty;
  this.getWeight = EdiCart_getWeight;
  this.getLines = EdiCart_getLines;

  this.getItemValue = EdiCart_getItemValue;
  this.getItemTax = EdiCart_getItemTax;
  this.getItemTaxRate = EdiCart_getItemTaxRate;
  this.getItemCode = EdiCart_getItemCode;
  this.getItemPrice = EdiCart_getItemPrice;
  this.getItemDiscountRate = EdiCart_getItemDiscountRate;
  this.getItemValueDiscount = EdiCart_getItemValueDiscount;
  this.getItemPriceDiscount = EdiCart_getItemPriceDiscount;
  this.getItemQty = EdiCart_getItemQty;
  this.getItemProduct = EdiCart_getItemProduct;
  this.getItemTitle = EdiCart_getItemTitle;
  this.getItemAuthor = EdiCart_getItemAuthor;
  this.getItemLineRef = EdiCart_getItemLineRef;
  this.getItemBranchCode = EdiCart_getItemBranchCode;
  this.getItemDelivery = EdiCart_getItemDelivery;
  this.getItemCompany = EdiCart_getItemCompany;
  this.getItemIndex = EdiCart_getItemIndex;
  this.getDiscountValue = EdiCart_getDiscountValue;
  this.setDiscountValue = EdiCart_setDiscountValue;
  this.getItemOnOrder = EdiCart_getItemOnOrder;
  
  this.checkItemCode = EdiCart_checkItemCode;
 
  this.changeLineRef = EdiCart_changeLineRef;
  this.changeBranchCode = EdiCart_changeBranchCode;
  this.changeItemQty = EdiCart_changeItemQty;
  this.changeItemDiscountRate = EdiCart_changeItemDiscountRate;

  this.clear = EdiCart_clear;
  this.clearTitleData = EdiCart_clearCookieTitles;
  this.removeZeroedItems = EdiCart_removeZeroedItems;

  this.fixedAdd = EdiCart_fixedAdd;
  this.fixedMult = EdiCart_fixedMult;
  this.discMult = EdiCart_discMult;
  this.formatOp = EdiCart_formatOp;

  this.saveToCookie = EdiCart_saveToCookie;
  this.setCookieOn = EdiCart_setCookieOn;

  this.setDeliveryValue = EdiCart_setDeliveryValue;
  this.addDeliveryValue = EdiCart_addDeliveryValue;
  this.getDeliveryValue = EdiCart_getDeliveryValue;
  this.setDeliveryMethod = EdiCart_setDeliveryMethod;
  this.getDeliveryMethod = EdiCart_getDeliveryMethod;

  this.setTaxRate = EdiCart_setTaxRate;
  this.refreshItemTaxRates = EdiCart_refreshItemTaxRates; 
  // Private Methods
  this.restoreFromCookie = EdiCart_restoreFromCookie;

  var cookieTest = unescape(document.cookie);
//  if(cookieTest.indexOf(this.cookieName) != -1){this.restoreFromCookie()};
}
// *********** End of Cart Object *********************

var eCart = new EdiCart()

// common javascript functions

function orderWarning(actionType, targetUrl){
 if(actionType == "R" && eCart.getQty() < 1){
  window.location = targetUrl;
  return;
  }
   var alertMessage = "This will clear any titles that currently you have in your basket";
   if(actionType == "S") alertMessage = "This will overwrite any previously saved order"
   if(confirm(alertMessage)) window.location = targetUrl;
   return;
}

function checkOffer(offerCode,offerDisc,offerMin){

    if(!validOffer(offerCode)){return;}
    var nextLoc = "titlelist.php?offercode="+offerCode+"&offerdisc="+offerDisc;
    if(offerMin != 0){nextLoc = nextLoc + "&offermin="+offerMin;} 
        window.location = nextLoc;
}
function checkPriceOffer(offerCode,offerDisc,offerMin){

    if(!validOffer(offerCode)){return;}
    var nextLoc = "titlelist.php?offercode="+offerCode+"&offerprice="+offerDisc;
    if(offerMin != 0){nextLoc = nextLoc + "&offermin="+offerMin;} 
    window.location = nextLoc;
}

function orderOffer(offerCode, offerDisc, offerQty){
    if(!validOffer(offerCode)){return;}
    if(offerQty == undefined) offerQty = 1;
    window.location = "basket.php?offercode="+offerCode+"&offerdisc="+offerDisc+"&offerOrder="+offerQty;
}

function orderPriceOffer(offerCode, offerDisc, offerQty){
    if(!validOffer(offerCode)){return;}
    if(offerQty == undefined) offerQty = 1;
    window.location = "basket.php?offercode="+offerCode+"&offerprice="+offerDisc+"&offerOrder="+offerQty;
}

// Hover class for IE6

sfHover = function() {
        var sfEls = document.getElementById("nav").getElementsByTagName("LI");
        for (var i=0; i<sfEls.length; i++) {
                sfEls[i].onmouseover=function() {
                        this.className+=" sfhover";
                }
                sfEls[i].onmouseout=function() {
                        this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
                }
        }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

///////////////////////////////////////////////////////////
// Usage IEprompt("dialog descriptive text", "default starting value");
//
// IEprompt will call promptCallback(val)
// Where val is the user's input or null if the dialog was canceled.
///////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////
// This source code has been released into the public domain
// January 14th, 2007.
// You may use it and modify it freely without compensation
// and without the need to tell everyone where you got it.
///////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////
// You must create a promptCallback(val) function to handle
// the user input.  If you don't this script will fail and
// Bunnies will die.
///////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////
// These are global scope variables, they should remain global.
///////////////////////////////////////////////////////////
var _dialogPromptID=null;
var _blackoutPromptID=null;
///////////////////////////////////////////////////////////

function IEprompt(innertxt,def) {

   that=this;

   // Check to see if this is MSIE 7.   This isn't a great general purpose
   // detection system but it works well enough just to find MSIE 7.
   var _isIE7=(navigator.userAgent.indexOf('MSIE 7')>0);

   this.wrapupPrompt = function (cancled) {
      // wrapupPrompt is called when the user enters or cancels the box.
      // It's called only by the IE7 dialog box, not the non IE prompt box
      if (_isIE7) {
         // Make sure we're in IE7 mode and get the text box value
         val=document.getElementById('iepromptfield').value;
         // clear out the dialog box
         _dialogPromptID.style.display='none';
         // clear out the screen
         _blackoutPromptID.style.display='none';
         // clear out the text field
         document.getElementById('iepromptfield').value = '';
         // if the cancel button was pushed, force value to null.
         if (cancled) { val = '' }
         // call the user's function
         promptCallback(val);
      }
      return false;
   }

   //if def wasn't actually passed, initialize it to null
   if (def==undefined) { def=''; }

   if (_isIE7) {
      // If this is MSIE 7.0 then...
      if (_dialogPromptID==null) {
         // Check to see if we've created the dialog divisions.
         // This block sets up the divisons
         // Get the body tag in the dom
         var tbody = document.getElementsByTagName("body")[0];
         // create a new division
         tnode = document.createElement('div');
         // name it
         tnode.id='IEPromptBox';
         // attach the new division to the body tag
         tbody.appendChild(tnode);
         // and save the element reference in a global variable
         _dialogPromptID=document.getElementById('IEPromptBox');
         // Create a new division (blackout)
         tnode = document.createElement('div');
         // name it.
         tnode.id='promptBlackout';
         // attach it to body.
         tbody.appendChild(tnode);
         // And get the element reference
         _blackoutPromptID=document.getElementById('promptBlackout');
         // assign the styles to the blackout division.
         _blackoutPromptID.style.opacity='.9';
         _blackoutPromptID.style.position='absolute';
         _blackoutPromptID.style.top='0px';
         _blackoutPromptID.style.left='0px';
         _blackoutPromptID.style.backgroundColor='#555555';
         _blackoutPromptID.style.filter='alpha(opacity=90)';
         _blackoutPromptID.style.height=(document.body.offsetHeight<screen.height) ? screen.height+'px' : document.body.offsetHeight+20+'px';
         _blackoutPromptID.style.display='block';
         _blackoutPromptID.style.zIndex='50';
         // assign the styles to the dialog box
         _dialogPromptID.style.border='2px solid blue';
         _dialogPromptID.style.backgroundColor='#DDDDDD';
         _dialogPromptID.style.position='absolute';
         _dialogPromptID.style.width='330px';
         _dialogPromptID.style.zIndex='100';
      }
      // This is the HTML which makes up the dialog box, it will be inserted into
      // innerHTML later. We insert into a temporary variable because
      // it's very, very slow doing multiple innerHTML injections, it's much
      // more efficient to use a variable and then do one LARGE injection.
      var tmp = '<div style="width: 100%; background-color: blue; color: white; font-family: verdana; font-size: 10pt; font-weight: bold; height: 20px">Input Required</div>';
      tmp += '<div style="padding: 10px">'+innertxt + '<BR><BR>';
      tmp += '<form action="" onsubmit="return that.wrapupPrompt()">';
      tmp += '<input id="iepromptfield" name="iepromptdata" type=text size=46 value="'+def+'">';
      tmp += '<br><br><center>';
      tmp += '<input type="submit" value="&nbsp;&nbsp;&nbsp;OK&nbsp;&nbsp;&nbsp;">';
      tmp += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
      tmp += '<input type="button" onclick="that.wrapupPrompt(true)" value="&nbsp;Cancel&nbsp;">';
      tmp += '</form></div>';
      // Stretch the blackout division to fill the entire document
      // and make it visible.  Because it has a high z-index it should
      // make all other elements on the page unclickable.
      _blackoutPromptID.style.height=(document.body.offsetHeight<screen.height) ? screen.height+'px' : document.body.offsetHeight+20+'px';
      _blackoutPromptID.style.width='100%';
      _blackoutPromptID.style.display='block';
      // Insert the tmp HTML string into the dialog box.
      // Then position the dialog box on the screen and make it visible.
      _dialogPromptID.innerHTML=tmp;
      _dialogPromptID.style.top=parseInt(document.documentElement.scrollTop+(screen.height/3))+'px';
      _dialogPromptID.style.left=parseInt((document.body.offsetWidth-315)/2)+'px';
      _dialogPromptID.style.display='block';
      // Give the dialog box's input field the focus.
      document.getElementById('iepromptfield').focus();
   } else {
      // we are not using IE7 so do things "normally"
      promptCallback(prompt(innertxt,def));
   }
}
