
/* Marts 2002 - Electric Flight Equipment - alle rettigheder forbeholdes */
/* Copyright 2002  Electric Flight Equipment, All Rights Reserved         */

//----------------------------------------------------------------------
// Betalingskort
//----------------------------------------------------------------------



// variabler til betalingskort
var svarmail = ' ';
var ordreid = 0;
var dispbelob = 0;

// husk betalingsdata
function set_bet_data(item1,item2,item3){
svarmail = item1;
ordreid = item2;
dispbelob = item3;
}

//betalingsform
function set_betaling(metode){
	Betalingsform = metode;
}

function set_navn(navn){
	bnavn = navn;
}

function set_email(mail){
	bemail = mail;
}

function set_belob(be1,be2){
	bbelob1 = be1;
	bbelob2 = be2;
	belob = be1 + "," + be2 + " kr." ;
	pbsbelob = eval(be1) * 100;
	pbsbelob = pbsbelob + eval(be2);
}

//----------------------------------------------------------------------
// Ask om en varer, tilbud
//----------------------------------------------------------------------
// info om tilbud
// -------------
var ting = 'Der er ikke valgt en varer';

function ask(item){
ting = item;
main.location.href='b-info-t.htm';
}
// ------slut

function openwin(nyURL) {
	var remote=window.open(nyURL,"remoteefe","width=600,height=480,resizable=1,location=0,menubar=0,status=1,scrollbars=1");
	if (remote.opener == null)      {
		remote.opener = window;
		}   
	else      { 
		remote.focus();      
		}
	return false      
}

 
// 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=0; 
// 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=999999; 
// reduced deliverycost if order > free-delivery, default value 0 (free delivery)
var reduced_deliverycost=0; // 
// colorvariable used when displaying order
var headercolor='#0000FF';
var headertext='ffffff';
var ordercolor1='66cc66'; // alternate colors used in orderdetail
var ordercolor2='ffcc66'; // alternate colors used in orderdetail
var totalcolor='#f8df00';
//----------------------------------------------------------------------

var Current_Country = new Array();
var Country='NC';

//----------------------------------------------------------------------

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 setitem_arr = new Array();  // Set pointer - special!  (JA)
//var temp_setitem_arr = new Array();  // Array to hold setitem nbr (JA
//var group_arr = new Array();    // Array to hold discountgroup
var shipping_arr = new Array(); // Array to hold shippinggroup
var shippinggroupDanmark = new Array(0,1,2,3,4,5,6,7,8,9);
var shippinggroupSverige = new Array(0,11,12,13,14,15,16,17,18,19);
var shippinggroupNorge = new Array(0,21,22,23,24,25,26,27,28,29);
//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_shipping_arr = new Array(); // used when deleting an item
var temp_quantity_arr = new Array(); // used when deleting an item
var temp_setitem_arr = new Array(); // temp Set pointer - special!  (JA)
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_arr4 = new Array(); // bill part4 price * Quantity
var bill_arr5 = new Array(); // bill part5 Shipping 
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;actual_deliverycost=0;
 
// remove basketvalue in topside-frame
first_order = true; 
topside.location.href='logo.htm';
Country='NC';
// 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')
  {
 main.location.href='basket.htm';
  }
}
//----------------------------------------------------------------------
//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
{
var startidx=itemix;  
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_shipping_arr[i]  = shipping_arr[i];
  //alert(setitem_arr[i]);
  temp_setitem_arr[i] = setitem_arr[i]; 
  //temp_group_arr[i]  = group_arr[i];
}
if (temp_setitem_arr[itemix]>0) {  
  startidx=itemix-temp_setitem_arr[itemix];
}
//
// 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;
actual_deliverycost=0
sw_delete = true; // no order-alert when recalculating
//alert(itemix);
//alert(startidx);
for(var i=0; i < j; i++)
{
if (!(i>=startidx && i<=itemix)) 
	{
	order(temp_item_arr[i],temp_price_arr[i],temp_quantity_arr[i],temp_shipping_arr[i],temp_setitem_arr[i]); 
	}
}
sw_delete = false;
//
// Update basketvalue in topside-frame
//
topside.document.frm.basket.value='      '+round_amount(total_price);
//
// remove basketvalue in topside-frame if this were last item
//
// if (total_price == 0)
 //alert(itemn);
 if (itemn == 0)
 {
 //alert(itemn);
 Country='NC'
 actual_deliverycost=0;
 first_order = true; 
 topside.location.href='logo.htm';
 }
//
// update basket-view
//
main.location.href='basket.htm';
}
//----------------------------------------------------------------------
//this function displays confirmation too user
//----------------------------------------------------------------------
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("Skal "+quantity+" stk."+item+" lægges i kurven\nPris pr. Stk. "+price+"\nIalt i kurv: "+temp));
	}
  }
}
function additem(item,price,quantity,shipping,setitem) {
//this section store the orderinfo
item_arr[itemn] = item;
price_arr[itemn] = price;
quantity_arr[itemn] = quantity;
shipping_arr[itemn]  = shipping;
bill_item_ix[bill_ix] = itemn;
setitem_arr[itemn] = setitem;
if (setitem==-1) {
  bill_item_ix[itemn]=null;
}

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_arr4[bill_ix] = round_amount(bill_arr2[bill_ix]*bill_arr3[bill_ix])
bill_arr5[bill_ix] = shipping;
bill_ix++;
total_price=total_price+price*quantity;
}

//-------------------------------------------------------------------
//this function adds sets to relevant arrays
//-------------------------------------------------------------------
function orderset(desc,items,price,linesonly) {
  price=String(price)
  price=price.replace(/,/gi,'.');
  var setitem=itemn;
  if (order_ok(desc,price,1,"")) {
    for (var i=0;i<(items.length);i+=3) {
	  
	  if (!linesonly) {
	    additem(items[(i)],items[(i+2)],items[(i)+1],"",-1)  
	  } else {
        additem(items[(i)],items[(i+2)],items[(i)+1],"")  
	  }
	}
	if (!linesonly) {
	  additem(desc,price,1,"",items.length/3);
	}
	shipment();
	if (first_order==true && sw_delete == false)
   {first_order=false;
		topside.location.href='logo.htm';
   }
// else update basketvalue in topside-frame
 else
	{
		topside.document.frm.basket.value='      '+round_amount(total_price);
	}
   }
}

//----------------------------------------------------------------------
//this function handle each order by adding orderinfo to relevant arrays
//----------------------------------------------------------------------
function order(item,price,quantity,shipping,setitem)
//,group
// fix quantity format
{
price=String(price)
price=price.replace(/,/gi,'.');
if (order_ok(item,price,quantity,shipping))
{
additem(item,price,quantity,shipping,setitem)
/*

//this section store the orderinfo
item_arr[itemn] = item;
price_arr[itemn] = price;
quantity_arr[itemn] = quantity;
shipping_arr[itemn]  = shipping;
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_arr4[bill_ix] = round_amount(bill_arr2[bill_ix]*bill_arr3[bill_ix])
bill_arr5[bill_ix] = shipping;
bill_ix++;
total_price=total_price+price*quantity;
*/
//check for shipping cost
shipment();

// 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 topside-frame with basket-cell
if (first_order==true && sw_delete == false)
   {first_order=false;
		topside.location.href='logo.htm';
   }
// else update basketvalue in topside-frame
 else
	{
		topside.document.frm.basket.value='      '+round_amount(total_price);
	}
}
}

//----------------------------------------------------------------------
//this function sends the order
//----------------------------------------------------------------------
function send_order()
{
parent.main.location.href='order.htm';
}

function send_order_ns()
{
parent.main.location.href='order-ns.htm';
}

function send_order_uk()
{
parent.main.location.href='order-uk.htm';
}

//----------------------------------------------------------------------
//this function makes the amount a ronund number
//----------------------------------------------------------------------
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);
string_amount=string_amount.replace(/,/gi,'.');
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;}


//----------------------------------------------------------------------
//this function steps forward or back
//----------------------------------------------------------------------
function Frem()
{
	history.forward();
}

function Tilbage()
{
	history.back();
}

//----------------------------------------------------------------------
//this function handle the shipment cost
//----------------------------------------------------------------------
function shipment()
{
if (Country!='NC')
{
	for(var y=0; y < bill_ix; y++)
	{
		for(var i=0; i < Current_Country.length; i++) 
		{
			if (i == bill_arr5[y])
			{
			if ( actual_deliverycost < Current_Country[i])
				{
				actual_deliverycost=Current_Country[i];
				}
			i=30;
			}
		}
	}
}	
else
	{
	actual_deliverycost=0;
	}
}


//----------------------------------------------------------------------
//this function changes the Country
//----------------------------------------------------------------------
function Select_Country(C)
{
Country=C;
if (Country=='Danmark')
	Current_Country=shippinggroupDanmark;
else if (Country=='Sverige')
	Current_Country=shippinggroupSverige;
else if (Country=='Norge')
	Current_Country=shippinggroupNorge;
//Update shipment	
shipment();
//Updates Basket and Menu
topside.location.href='logo.htm';
main.location.href='basket.htm';
}


