var sasTrackingType = "sale";  //sale or lead, tho only sale is supported at the moment

// Bind a change handler to the window location.
$j( window.location ).bind(
      "change",
      function(objEvent, objData){
              hash = objData.currentHash.slice(6);  //trim the ecwid and the COLON leading.

  	      page.mode = getPageType(hash);
              //page.category = getCategory(hash);
	      //page.product = getProduct(hash);  Don't need here.
	      runMods(page);  //If the window's changed, run the mods.
      	}
);

function runMods(page) {
	   //Call anything you want on every page here.
 	   functionComplete = false;  //They all retrun true if successful. false if not.
           if (window.t1 !== undefined) { clearInterval(t1); }

	   t1 = setInterval (function() {
              switch(page.mode) {
		 /*case "category":
		      functionComplete = toggleCategoryTitle("hide");
		      break;
   		 case "product":
		      functionComplete = resizeProductImages() &&
		      		       	 toggleCategoryTitle("show");
		      break;    */
	        case "orderConfirmation":
		      //functionComplete = googleConversion();
		      functionComplete = shareASale();
		      break;
      		default:
		//Nothing to do!
		functionComplete = true;
	      }
	      
	      if (functionComplete) { clearInterval(t1); }
          }, 100);
}

function shareASale() {
      //Read required values
      /*
      <img 
      	   src="https://shareasale.com/sale.cfm?amount=AMOUNTOFSALE&tracking=TRACKINGNUMBER&transtype=TYPEOFTRANSACTION&merchantID=25351" 
	   width="1" 
	   height="1" >
      */
      
      if ( $j('.ecwid-Invoice-Header-OrderId span').length ) {
      	      orderID = $j('.ecwid-Invoice-Header-OrderId span').text().slice(1);
      }  else return false;
            if ( $j('.ecwid-Invoice-Summary-value-price').length ) {
      	     price = $j('.ecwid-Invoice-Summary-value-price').text().slice(1);
      } else return false;

      $j("<img src='http://4xtrader.net/pa/scripts/sale.php?AccountId=default1&TotalCost=" + price + "&OrderID=" + orderID + "' width='1' height='1'>").appendTo("body");

      return true;
}
