<!--//



// Script copyrighted by Kim Hjortholm, Denmark, 1997, 1998
//
//   
//   What a surprice ..... I got several inqueries for this script (thanks to those that
//   payed as well !)
//   Anyway, after answering several email I finally came around to translate the variablenames
//   to english, added more comments, and more ..... se version history
//
// Currently this script support following functions
//
//   Version 1.0 (June 1, 1997)
//   - shoppingbasket based on Javascript for an unlimited number of items
//     (well limited by storage - but if your customers order that much you need something
//      else than this script)
//   - Calculation of total cost of items in shoppingbasket
//   - Removal of specific item from shoppingbasket with recalculation of total cost 
//   - Ability to define fixed discount for items belonging to specific groups
//     (e.g. 1 item 10$ - 3 items 24$) 
//   - Order from shoppingbasket forwarded via formmail (integration with database to come)
//     
//   Version 1.1 (november 25, 1997)
//   - variablenames translated from Danish to English
//   - Logic code cleaned for "leftover" from testing (no bugs - but some noise were present)
//   - Added more comments to clarify logic
//   - sum of total order are now showed in toc-frame 
//     and dynamicly updated when order are changed ! (simple - when you think about it !)
//   - Order links in toc-frame are now only active when there is an order (well potentiel order) in the basket
//   - Added validation routines to order-form
//   - Added switch to customize alert-box (when ordering) on/off
//   - Codebase for handling quantity with order (ordering more than 1 copy of then same item)
//     added .......(the only thing missign right now are the calculations)
//
//    Version 1.11 (march 4, 1998)
//   new customizationparameter:
//   - added optional free delivery when order > x
//   - added colorcoding to orderline
//
//   Version 1.2 (july 20, 1998)
//   - added ability to order more than 1 item at a time
//   -
//
////   Version 1.21 (october 5, 1998)
//   - added function round_amount to handle descimal places
//   -
//
// Hopefully this brief documentation will get you going ! 
//
// If you are going to copy the shoppingbasket you need scripts from following pages
//    index.html    : This page - contains all major logic and are called from other pages
//    basket.html   : Shopping basket display
//    order01.html  : Mail-integration (dynamic generations of hidden fields)
//    catalog.html  : Call to order-routine via form-buttons
//    base.html   : Menubar 
//    confirm1.html : Order-confirmation page
//    
// To see the script in action try visit one of the link listed under 'Musik-katalog'
//    it's safe to place order in the shoppingbasket (push the buttons)
//    to see your order : follow link titled 'Indkøbsvogn'
//    to see submitform : follow link titled 'Bestilling'
//    (please DO NOT SUBMIT - unless you actually will order something)
//                                                         
// 
// If copied please keep this copyright notice 
// 
// For commercial use following terms apply :
//    
//   You may use this script for a period of 30 days, after which, if you decide to continue
//   using the product, you are obligated to register by paying the sum of
//   US$40  to the author.
//
//	Payment options 
//
//	Payment via credicart at secure website
//	available within a month (october 1998) 
//
//	Payment by sending a cheque in Danish funds, made payable to 
//	New Beginnings
//	Kim Hjortholm
//	Fasanvej 23, st tv
//	DK-4600 Koege
//	Denmark
//	Include the following information together with the payment: 
//
//	name 
//	address 
//	e-mail account 
//
//     Special tailoring of script can be ordered on consultant-basis
//
//     Copyright © 1997, 1998 Kim Hjortholm, all rights reserved
//     Email : newbeginnings@post1.com   http://www.spiritnet.dk/newbeginnings/www
//
//----------------------------------------------------------------------
// Customization parameters
//----------------------------------------------------------------------
// change value to nomsg if you don't want confirmbox when adding item to basket
var msg='msg';
// normal deliverycost added to total orderprice
var deliverycost=5; 
// Set this variable to 999999 if you don't want to offer free delivery when order
// exceeds a specific amount or set reduced_deliverycost=deliverycost
var free_delivery=100; 
// reduced deliverycost if order > free-delivery, default value 0 (free delivery)
var reduced_deliverycost=0; // 
// colorvariable used when displaying order
var headercolor='660000';
var headertext='ffffff';
var ordercolor1='66cc66'; // alternate colors used in orderdetail
var ordercolor2='ffcc66'; // alternate colors used in orderdetail
var totalcolor='F9E7C1';
//----------------------------------------------------------------------

var actual_deliverycost=deliverycost;  // This variable holds the acutal deliverycost (allow for free delivery if order > freedelivery)
var itemn=0;                    // ix til item_arr og price_arr

var total_price=0;              // total price eg sum of items ordered
var item_arr = new Array();     // array to hold items ordered
var price_arr = new Array();    // Array to hold each item price
var quantity_arr = new Array(); // Array to hold item quantity
var group_arr = new Array();    // Array to hold discountgroup 
var discountgroup = new Array("G1","G2","G3","G4"); 
// G0 : no discount, this group or anything else not specified above can be used as
//      dummy-parameter in each order-buton
// G1 : 1 item 20 - 3 item 50
// 62 : 1 item 80  - 4 item 260
// G3 : 1 item 108 - 3 item 300
// G4 : 1 item 118 - 3 item 330
var discountgroupmin = new Array(3,4,3,3); // minimum quantum required for discount
var discountgroupval = new Array(10,60,24,24); // discountvalue in local currency
var discountgroupant  = new Array(0,0,0,0); // array holding # of item qualifying for discount
var discountgrouptxt  = new Array("Discount text1","Discount text2","Discount text3","Discount text4");
var temp_item_arr = new Array(); // used when deleting an item
var temp_price_arr = new Array(); // used when deleting an item
var temp_group_arr = new Array(); // used when deleting an item
var temp_quantity_arr = new Array(); // used when deleting an item
var bill_arr1 = new Array(); // bill part1 with item# or discounttext
var bill_arr2 = new Array(); // bill part2 with price / discount 
var bill_arr3 = new Array(); // bill part3 Quantity 
var bill_item_ix = new Array(); // bonpart3 with ix for item_arr ... used when deleting an item
var bill_ix = 0; // ix for bill_arr1 og bill_arr2
var sw_delete = false; // switch used when deleting an order
var first_order = true; 
//----------------------------------------------------------------------
//funtion to delete all item in shoppingvbasket
//----------------------------------------------------------------------
function delete_all(showbasket)
{
itemn=0; total_price=0; bill_ix = 0;
 
// remove basketvalue in toc-frame
first_order = true; 
base.location.href='base.html';

// reset discountcounter
for(var i=0; i<discountgroupant.length; i++) 
   {discountgroupant[i]=0;
    }
// Show empty basket - unless this is a submit of order
if (showbasket != 'nobasket')
  {
  corpo.location.href='basket.html';
  }	
}
//----------------------------------------------------------------------
//this function handles volume-discount
//----------------------------------------------------------------------
//For each discount group 
//  check if # item ordered equal discount-volume 
//  if so - subtract discount 
function discountcheck(item2,group2,quan2)
{
    for(var i=0; i<discountgroup.length; i++) 
   {
   //if item order belong to discount group then increment # of item ordered for this group
       if (discountgroup[i] == group2)
		{
         	discountgroupant[i]= discountgroupant[i]+eval(quan2);

			// if #item order for this group > discountlimit then calculate numer of times to give discount
			if (discountgroupant[i] >= discountgroupmin[i])
			     {
	 	          temp2 = discountgroupant[i] % discountgroupmin[i];
				  temp1 = (discountgroupant[i] -temp2)/discountgroupmin[i];
    		 	  discountgroupant[i]=temp2;
				  discount(discountgrouptxt[i],discountgroupval[i],temp1);
         		 }    
   		}
	 }  
}
//----------------------------------------------------------------------
//this function handle discount
//----------------------------------------------------------------------
// add the discount info to the bill_array's
function discount(discounttekst,reduction,quantity)
{
bill_arr1[bill_ix] = discounttekst;
bill_arr2[bill_ix] = reduction;
bill_arr3[bill_ix] = quantity;
bill_item_ix[bill_ix] = null;
bill_ix++;
total_price=total_price-reduction*quantity;
if (sw_delete == false)
alert(discounttekst+" "+reduction*quantity+" deducted\nTotal price: "+total_price);
}
//----------------------------------------------------------------------
//this function delete a specific order
//----------------------------------------------------------------------
function delete_order(itemix)
// copy basket to temp basket
{
 for(var i = 0; i < itemn; i++)
{ temp_item_arr[i] = item_arr[i];
  temp_price_arr[i] = price_arr[i];
  temp_quantity_arr[i]  = quantity_arr[i];
  temp_group_arr[i]  = group_arr[i];
}
//
// reset discountcounter
//
for(var i=0; i<discountgroupant.length; i++) 
   {discountgroupant[i]=0;
    }
//
// fill basket again except for cancelled order
//
j=itemn; 
 itemn=0; total_price=0; bill_ix = 0;
sw_delete = true; // no order-alert when recalculating
 for(var i=0; i < j; i++)
{
if (i != itemix) 
order(temp_item_arr[i],temp_price_arr[i],temp_quantity_arr[i],temp_group_arr[i]); 
 }
sw_delete = false;
//
// Update basketvalue in toc-frame
//
base.document.frm.basket.value='      '+total_price;
//
// remove basketvalue in toc-frame if this were last item
//
if (total_price == 0)
 {
 first_order = true; 
 base.location.href='base.html';
 }
//
// update basket-view
//
 corpo.location.href='basket.html';
}
function order_ok(item,price,quantity)
{
//Check that the user really want to order this item
// - skip this if we are deleting and item (otherwise we would notify the user for each
//   remaining item in basket
//
if (sw_delete == true) 
  return true;
  else
  {
// Confirm order unless the nomsg option are turned on  
  if (msg == 'nomsg')
   return true;
   else
    {
	temp = total_price+price*quantity;






	return (confirm("Please confirm ordering  "+quantity+" '"+item+"', price "+round_amount(price)+"\nTotal in basket: "+round_amount(temp)));
	}
  }
}
//----------------------------------------------------------------------
//this function handle each order by adding orderinfo to relevant arrays
//----------------------------------------------------------------------
function order(item,price,quantity,group)

{
if (order_ok(item,price,quantity))
{
//this section store the orderinfo
item_arr[itemn] = item;
price_arr[itemn] = price;
quantity_arr[itemn] = quantity;
group_arr[itemn]  = group;
bill_item_ix[bill_ix] = itemn;
itemn++;

//this section store the bill-info which might include discount-info
bill_arr1[bill_ix] = item;
bill_arr2[bill_ix] = price;
bill_arr3[bill_ix] = quantity;
bill_ix++;
total_price=total_price+price*quantity;
// check for reduced deliverycost
actual_deliverycost=deliverycost; 
if (total_price > free_delivery) 
   actual_deliverycost=reduced_deliverycost;
// check for discount
discountcheck(item,group,quantity);
// if this is first order then update toc-frame with basket-cell
if (first_order==true && sw_delete == false)
   {first_order=false;
   base.location.href='base.html';
   }
// else update basketvalue in toc-frame
 else base.document.frm.basket.value='   '+round_amount(total_price);

}
}

function send_order()
{
  parent.corpo.location.href='ordform.asp';
}



function round_amount(amount)
{  
var string_amount = "";  
var decimal_sign;
amount = parseFloat(amount);  
if (!(isNaN(amount))) 
{// round to nearest cent    
amount = Math.round(amount * 100);
amount = amount / 100;    
// format output    
string_amount = new String(amount);
decimal_sign = string_amount.indexOf(".");    
if (decimal_sign == -1) 
{      
// whole number
 string_amount =string_amount+".00";    
 } 
 else
 { if (decimal_sign == (string_amount.length - 2)) {
   // needs trailing zero        
   string_amount=string_amount+"0";      }    
 }  
} 
else {
    // not a number  return zero    
	string_amount = "0.00";  }  
return string_amount;}

//-->