if (window.order)  // IF order ALREADY EXISTS, DELETE IT.
  delete(order);
  
var root     = new Object();  // selection criteria
var order    = new Array();  // object to store order items in
var orderErr = new Array();   // stores error calls
var isaPledge = false;
var isaGift = false;
//********************
// place for user-specific options
root.xx_can  = "";   // place for PayPal cancel return path
root.xx_cur  = "USD";// enter default currency code (or null)
root.xx_id   = "paypal@la-bike.org" //"DVRGJPGRH8J4E";  //paypal_1229203903_biz@la-bike.org";

root.xx_img  = ""; // image URL
root.xx_lc   = "US"; // enter default country code (or null)
root.xx_ret  = ""; // place for PayPal return path
root.xx_sty  = ""; // place for PayPal page style
root.xx_xtra = "&rm=2"; // place for other PayPal commands
//***************************************************************


function ProcessForm () {
 	if(document.orderf.first_name.value == "" || document.orderf.last_name.value == ""){
		alert("Please provide your first and last names.")
	}else{
  		GetOrder();
  		if ( !ThrowError() ){
    		SendCart();
    	}
   	}
}

function GetOrder (id, des) {  // get all ordered items
	
	var stra, str, i = 0;
	var opt          = -1;

	
	// get number of tickets
	var adNum = parseFloat(document.getElementById("anum").value);
	if(adNum>0){
		
		order[i]     =  new Object();		
		order[i].des = "LACBC 1st Annual City of Lights Awards Dinner Ticket";
		order[i].amt = 35;
		order[i].qty = adNum;		
	}

	stra         = document.orderf.item_2.value;
	if(stra != ""){
		i++;
		  order[i]     = new Object();
		  order[i].des = "Extra Contribution"
		 
		 
		  
			str = document.getElementsByName("item_2")[0].value.replace(/^\s*([\S\s]*?)\s*$/, '$1'); // trim whitespace
			if (str == "" || isNaN(str) || parseFloat(str) < .01) {
			  //orderErr[i] = "Please enter a valid donation amount";
			  str = ""
			} else {
			  str = Math.round((parseFloat(str)*100))/100;
			}
			
		  order[i].amt = parseFloat (str);
		  order[i].qty = 1; 
		
	}

	
	// get how heard about the Awards
	var howSel = document.getElementById("how")
	if(howSel.selectedIndex > 0){
		var howHeard = howSel.options[howSel.selectedIndex].value;
		i++;
		order[i]     =  new Object();
		
		order[i].des = "I heard about the Awards Dinner through: "+howHeard;
		
		order[i].amt = 0;
		order[i].qty = 1;
		
	}


}


function calcTot(){
 	var testStr="123456789";
 	var adNum = document.getElementById("anum").value;
 	if(testStr.indexOf(adNum) >= 1){
 		
 		 	document.getElementById("atot").value=adNum*35
 		
 	}else{
 		document.getElementById("anum").value="1";
 		document.getElementById("atot").value="35";
 	}
 	//alert(document.getElementsByName("item_4")[0].value)
 }
 
 function checkDon(){
 	str = document.getElementsByName("item_2")[0].value.replace(/^\s*([\S\s]*?)\s*$/, '$1'); // trim whitespace
			if (isNaN(str) || parseFloat(str) < 1.00) {
			 
			  document.getElementsByName("item_2")[0].value = ""
			  }
 }

function handleNams(t,id){
	if(parseInt(t.value) > 0){
		document.getElementById(id).disabled = false;
		//document.getElementById(id).focus();
	}else{
		document.getElementById(id).value = "";
		document.getElementById(id).disabled = true;
	}

}

function ThrowError () {
  if (typeof(orderErr[0]) != "undefined") {
    var stra = new Array();
    var str  = "";
    
    str = orderErr[0];
    
    if (orderErr.length > 1) { 
      for (var i=1; i < orderErr.length; i++) {
        stra = orderErr[i].split("Please ")
        str += " and " + stra[1];
      } 
    } 

    order    = new Array();
    orderErr = new Array();
    alert(str+".");
    return true;
  
  } else {
    return false;
  }
}
var tempStrn = "";
function SendCart () {  // send the cart to PayPal
  //var strn = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_cart" + "&upload=1" + "&shipping=0&tax=0" + "&business=" + root.xx_id + root.xx_xtra;               
              
  	var strn   = "https://www.paypal.com/cgi-bin/webscr?cmd=_cart" + "&upload=1" + "&shipping=0&tax=0" + "&business=" + root.xx_id + root.xx_xtra; 

  var i=1,j=0,des;

  if (root.xx_cur.length > 0)
    strn = strn + "&currency_code=" + root.xx_cur;
  if (root.xx_lc.length > 0)
    strn = strn + "&lc=" + root.xx_lc;
  if (root.xx_can.length > 0)
    strn = strn + "&cancel_return=" + root.xx_can;
  if (root.xx_ret.length > 0)
    strn = strn + "&return=" + root.xx_ret;
  if (root.xx_sty.length > 0)
    strn = strn + "&page_style=" + root.xx_sty;
  if (root.xx_img.length > 0)
    strn = strn + "&image_url=" + root.xx_img;
    
  if (document.getElementsByName("first_name")[0].value.length > 0)
    strn = strn + "&first_name=" + escape (document.getElementsByName("first_name")[0].value);
  if (document.getElementsByName("last_name")[0].value.length > 0)
    strn = strn + "&last_name=" + escape (document.getElementsByName("last_name")[0].value);
  

  for (i in order) {  // send all valid data
    j = j + 1;
     
		strn = strn + "&item_name_"   + j + "=" + escape (order[i].des) +
					//"&item_number_" + j + "=" + i +
					  "&quantity_"    + j + "=" + order[i].qty +
					  "&amount_"      + j + "=" + order[i].amt; // + order[i].amt;
		if (typeof order[i].os0 !== 'undefined')
      		strn = strn + "&on0_"       + j + "=" + escape (order[i].on0) +
                   		  "&os0_"       + j + "=" + escape (order[i].os0);
        if (typeof order[i].os1 !== 'undefined')
      		strn = strn + "&on1_"       + j + "=" + escape (order[i].on1) +
                    	  "&os1_"       + j + "=" + escape (order[i].os1);
    	if (typeof order[i].os2 !== 'undefined')
			strn = strn + "&on2_"       + j + "=" + escape (order[i].on2) +
						  "&os2_"       + j + "=" + escape (order[i].os2);
    	if (typeof order[i].os3 !== 'undefined')
      		strn = strn + "&on3_"       + j + "=" + escape (order[i].on3);
   
    
  }
  
  //alert(strn)
	if (j > 0) window.location.href = strn;
}



