// Copyright 1998-2005 Quickboards.  All rights reserved.
var blk1  = "http://www.bitart.com.au";
var blk1a = "add=1";
var blk1d = "display=1";
var blk2  = "&business=bitart.com.au";
var blk3  = "&item_name=Item description";
var blk3n = "Test";
var blk4  = "&amount=";
var blk4a = "1.08";

var blk5  = "" + "";

var blk6 = "4";
	

function AddBoth (strn1, strn2, arg) {  // add to both fields
  AddStyle (strn1, "0");  // add to description
  AddPrice (strn2, arg);  // add to price
}

function AddPrice (strn, arg) {  // add to current price
var r1,r2,pos;

 r1 = blk4a * 1.0 + 0.005; // float 'em

 r2 = strn * 1.0;
  strn = escape (r1 + r2);  // add and put back to string
  pos = strn.indexOf ("."); // find decimal point
  blk4a = strn.substring (0, pos + 3);  // lop off extra

  if (arg != "0") CallPay ();
}

function AddNegative (strn, arg) {  // add to current price
var r1,r2,pos,neg;

 r1 = blk4a * 1.0 + 0.005; // float 'em

 r2 = strn * 1.0;
  strn = escape (r1 - r2);  // subtract and put back to string
  pos = strn.indexOf ("."); // find decimal point
  blk4a = strn.substring (0, pos + 3);  // lop off extra

  if (arg != "0") CallPay ();
}

function AddMultip (strn, arg) {  // multiply to current price
var r1,r2,pos,mult;

 r1 = blk4a * 1.0 + 0.005; // float 'em

 r2 = strn * 1.0;
  strn = escape (r1 * r2);  // sub and put back to string
  pos = strn.indexOf ("."); // find decimal point
  blk4a = strn.substring (0, pos + 3);  // lop off extra

  if (arg != "0") CallPay ();
}

function AddStyle (strn, arg) {  // add to current description
  blk3n = blk3n + "%2C%20" + escape (strn);
  if (arg != "0") CallPay ();
}

function CallPay () { // call the PayPal shopping cart
  window.open (blk1 + blk1a + // open the cart window
               blk2 + blk3 + blk3n + blk4 + blk4a + blk5,
               "cartwin",
               winpar);
}

function CallView () { // call the PayPal shopping cart view
  window.open (blk1 + blk1d +  // open the PayPal cart window
               blk2,
               "cartwin",
               winpar);
}

function MakeBuy (obj1) {  //get form data for PayPal
var i,j,obj,temp,pick,pos,neg,mult;
var stax, tax, dec_pos, with_tax ; 
var r1, r2;

var aray = new Array ();
  SetBoth("0", "0", "0"); // base description
  j = 0;
  tax = 0.0
 ; // default tax value
  for (i=1; i<blk6; i++) {    // get the dropdown stuff...
    obj = obj1.elements[i];     // The form element object
    pick = obj.selectedIndex;   // which option selected
    aray[j] = obj.options[pick].value;  // isolate it

    temp = aray[j];  // get any price values from data
    j = j + 1;       // bump array index

    pos  = temp.indexOf ("+$"); // is there an adjustment?  
    stax = temp.indexOf("%")  ; // need to add sales tax ?
	neg = temp.indexOf("-$")  ; // is there an adjustment?  
	mult = temp.indexOf("*$")  ; // is there an adjustment? 
    
   if (stax > 0) {
	   tax = temp.substring(stax-3, stax) ;
  
  }
   else {
	if (pos > 0) {AddPrice (temp.substring (pos + 2), "0");}
	if (mult > 0) {AddMultip (temp.substring (mult + 2), "0");}
    if (neg > 0) {AddNegative (temp.substring (neg + 2), "0");}

	}
  }

  // plug in the price...
  with_tax = blk4a * (1.0 + tax) ; // include sales tax if applicable
  r1 = with_tax * 1.0 + 0.005; // to get cents (with two decimal places always)

temp_withtax = escape (r1 ); // converts to string
dec_pos = temp_withtax.indexOf ("."); // find decimal point

blk4a = temp_withtax.substring(0, dec_pos + 3) ;
  obj1.elements[0].value = "$" + blk4a ;

  AddStyle (aray.join (", "), "0");  // build desc
}

function SetBoth (strn1, strn2, arg) {  // set desc and value
  SetDesc  (strn1);
  SetPrice (strn2);
  if (arg != "0") CallPay ();
}

function SetDesc (strn) {  // set the desc field
  blk3n = escape (strn);
}

function SetPrice (strn) {  // set the current price
  blk4a = "0.00";
  AddPrice (strn, "0");
}

function MakePrice (strn) {  // set the current price on form
obj1.elements[0].value = "$" + blk4a;
}


function dollarFormat(valuein) {
var tDollars
var formatStr = ""
var decipos = valuein.indexOf(".")
if (decipos == -1)
	decipos = valuein.length
var dollars = valuein.substring(0,decipos)
var Outdollars = ""
var dollen = dollars.length
tDollars = dollars.substring(dollen-3, dollen)
if (dollen >3 ) {
	   while (dollen > 0 ) {
		if (tDollars.length == 3) {
		   Outdollars = ","+tDollars+Outdollars
		   dollen = dollen-3
		}
		else {
		     Outdollars = tdollars+Outdollars
		     dollen = 0
		}
          }	
	 if (Outdollars.substring(0,1) == ",")
		dollars = Outdollars.substring(1, Outdollars.length)
	  else
		dollars=Outdollars
      }
var cents = valuein.substring(decipos+1,decipos+3)
if (cents == "")
  cents ="00"
if (cents.length == 1)
   cents = cents+"0"
var formatStr = "$"+dollars+"."+cents
return formatStr
}