/*---------------------------------------------------------------
	Function Portion BELOW
---------------------------------------------------------------*/
  /********************Initialize Google Analytics**********************/
  var ga = document.createElement('script');     
  ga.type = 'text/javascript'; 
  ga.setAttribute('async', 'true');
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; 
  s.parentNode.insertBefore(ga, s);
   
  var _gaq = _gaq || [];  
  var gaAcctNum = 'UA-4142018-1';
  _gaq.push(['_setAccount', gaAcctNum]);
  _gaq.push(['_setDomainName', window.location.hostname]);
  _gaq.push(['_setAllowLinker', true]);
  _gaq.push(['_setAllowHash', false]);
  _gaq.push(['_setAllowAnchor', true]);
  _gaq.push(['_trackPageview']);
  /********************Initialize Google Analytics**********************/ 
  
  function evenueLinkTracker(link)
  {
    var tracker = _gaq._getAsyncTracker();
    var gaLinkString = tracker._getLinkerUrl(link,true);
    window.open(gaLinkString, '_blank');
    return false;
  }
/*---------------------------------------------------------------
	END CUSTOM CODE - Google Analytics Functions
---------------------------------------------------------------*/

/*---------------------------------------------------------------
	Ecommerce Portion BELOW
---------------------------------------------------------------*/
if(typeof(order)!="undefined" && typeof(order.number)!="undefined" && typeof(cartCharges)!="undefined") {

	// ---------- TRANSACTION OBJECT ----------:
	_gaq.push(['_addTrans',
		order.number,           // order number
		linkID,												// Affiliation
		amountFormat(Number(cartCharges.total)),			// Total
		"blank_text",													// Tax
		amountFormat(Number(cartCharges.delivery)+Number(cartCharges.order)), // Shipping (delivery and order charge)
		tktBillAddr.city,									// City
		tktBillAddr.state,									// State
			tktBillAddr.country									// Country
	  ]);

	// ---------- Ticket Purchases ----------:
	for(var icount=0; icount<itemList_.length; icount++){
		  // ---------- Single Items ----------:						
		  if(itemList_[icount].type=="SE") {			
			  for(var j=0; j < itemList_[icount].reservationList.length; j++) {
				for(var k=0; k < itemList_[icount].reservationList[j].lineItemList.length; k++) {
					var temp_item = itemList_[icount].reservationList[j].lineItemList[k];
					_gaq.push(['_addItem',
            order.number,           // order number
            itemList_[icount].eventInfo.eventCode,           // event code
            itemList_[icount].eventInfo.description,        // event desc
            temp_item.description,   // price level
            amountFormat(temp_item.price),          // amount
            temp_item.qty	               // quantity 
          ]);
			}
		}
		  // ---------- Combo Items ----------:							  
		  } else if(itemList_[icount].type=="ST" || itemList_[icount].type=="DS") {					  	
				for(var j=0; j<itemList_[icount].priceTypeQtyList.length; j++) {
					var temp_item = itemList_[icount].priceTypeQtyList[j];
					_gaq.push(['_addItem',
            order.number,           // order number
            itemList_[icount].ticketInfo.eventCode,           // event code
            itemList_[icount].ticketInfo.description,        // event desc
            temp_item.description,   // price level
            amountFormat(temp_item.price),          // amount
            temp_item.qty	               // quantity 
          ]);
		}
	// ---------- Misc Items ----------:
		 } else if(itemList_[icount].type=="MI") {					  	
			for(var j=0; j < itemList_[icount].reservationList.length; j++) {
				var temp_item = itemList_[icount].reservationList[j].lineItem;
				_gaq.push(['_addItem',
          order.number,           // order number
          itemList_[icount].itemInfo.eventCode,           // event code
          itemList_[icount].itemInfo.description,        // event desc
          'Miscellaneous Item Purchases',   // price level
          amountFormat(Number(temp_item.price)+Number(temp_item.perItemFee)),          // amount
          temp_item.qty	               // quantity 
        ]);
		}
	// ---------- GC Items ----------:
		} else if(itemList_[icount].type=="GC") {	
			for(var j=0; j < itemList_[icount].reservationList.length; j++) {
				var temp_item = itemList_[icount].reservationList[j].lineItem;
				_gaq.push(['_addItem',
          order.number,           // order number
          itemList_[icount].itemInfo.eventCode,           // event code
          itemList_[icount].itemInfo.description,        // event desc
          'Gift Certificate Purchases',   // price level
          amountFormat(Number(temp_item.price)+Number(temp_item.perItemFee)),          // amount
          temp_item.qty	               // quantity 
        ]);
		}
	}
	}
	// ---------- Donations ----------:
	for(var i=0; i < cartPledgeList_.length; i++) {
	  _gaq.push(['_addItem',
      order.number,           // order number
      cartPledgeList_[i].code,           // event code
      cartPledgeList_[i].fundDrive,        // event desc
      'Donations',   // price level
      amountFormat(cartPledgeList_[i].paymentAmount),          // amount
      cartPledgeList_[i].paymentPlan	               // quantity (payment plan)
    ]);
	}
	for(var i=0; i < cartPledgePayList_.length; i++) {
	  _gaq.push(['_addItem',
      order.number,           // order number
      cartPledgePayList_[i].pledgePayCode,           // event code
      cartPledgePayList_[i].fundDrive,        // event desc
      'Donation/Pledge Payments',   // price level
      amountFormat(cartPledgePayList_[i].amount),          // amount
      '1'	               // quantity 
    ]);
	}
	// ---------- Transfers ----------:
	for(var i=0; i < cartAcceptTTList_.length; i++) {
		var transQty = cartAcceptTTList_[i].itemQty;
		if(cartAcceptTTList_[i].itemType=="TI") {
			for(var j=0; j<cartAcceptTTList_[i].seatList.length; j++) {
				transQty = Number(transQty) + Number(cartAcceptTTList_[i].seatList[j].qty);
			}
		}
		_gaq.push(['_addItem',
      order.number,           // order number
      cartAcceptTTList_[i].transferCode,           // event code
      cartAcceptTTList_[i].itemDesc,        // event desc
      'Transfers',   // price level
      amountFormat(cartAcceptTTList_[i].transferFee),          // amount
      transQty	               // quantity 
    ]);
	}
	// ---------- Renewals ----------:
	for(var i=0; i < cartRenewalList_.length; i++) {
	  _gaq.push(['_addItem',
      order.number,           // order number
      cartRenewalList_[i].appId,           // event code
      cartRenewalList_[i].name,        // event desc
      'Renewal Applications',   // price level
      amountFormat(cartRenewalList_[i].amount),          // amount
      '1'	               // quantity 
    ]);
	}
	// ---------- Item Packages ----------:
	for(var i=0; i < cartPKList_.length; i++) {
	  _gaq.push(['_addItem',
      order.number,           // order number
      cartPKList_[i].pkListInfo.cartPKNum,           // event code
      cartPKList_[i].pkItemList[0].itemInfo.pkDesc,        // event desc
      'Item Packages',   // price level
      cartPKList_[i].pkItemList[0].itemInfo.pkTotal,          // amount
      '1'	               // quantity 
    ]);
	}
	
	_gaq.push(['_trackTrans']); //submits transaction to the Analytics servers
}
/*---------------------------------------------------------------
	END CUSTOM CODE - Google Analytics with Ecommerce
---------------------------------------------------------------*/
