var BrontoAccountID = "arsbmqtbqaehbexwpnggmfvudswnbkc";

function BrontoConversionTracker(type, description, money) {
	this.baseUrl = "https://app.bronto.com/public/?q=stream_conversion&fn=Mail_Conversion&id=" + BrontoAccountID;
	this.type = type;
	this.description = description;
	this.money = money;
	this.getImgSrc = function() {
		var myImg = this.baseUrl 
			+ "&type=" + this.type 
			+ "&description=" + this.description 
			+ "&money=" + this.money
			+ "&_forteRandom=" + Math.floor(Math.random()*100000);
		return myImg;		
	}
	this.track = function() {
		var newImg = document.createElement('img');
		newImg.src = this.getImgSrc();
		newImg.style.width = 0;
		newImg.style.height = 0;
		document.getElementById('Body').appendChild(newImg);
	}
}

function BrontoDirectUpdate(numberorders, totaldollars, lastorderdate) {
	this.baseUrl = "https://app.bronto.com/public/?q=direct_update&fn=Public_DirectUpdateForm&id=" + BrontoAccountID;
	this.numberOrders = numberorders;
	this.totalDollars = totaldollars;
	this.lastOrderDate = lastorderdate;
	this.getImgSrc = function() {
		var myImg = this.baseUrl 
			+ "&field1=numberorders,add," + this.numberOrders
			+ "&field2=totaldollars,add," + this.totalDollars 
			+ "&field3=lastorderdate,set," + this.lastOrderDate
			+ "&_forteRandom=" + Math.floor(Math.random()*100000);
		return myImg;
	}
	this.track = function() {
		var newImg = document.createElement('img');
		newImg.src = this.getImgSrc();
		newImg.style.width = 0;
		newImg.style.height = 0;
		document.getElementById('Body').appendChild(newImg);
	}
}

function BrontoDirectAdd(formName, contactObj) {
	var brontoFormObj = {
		orderConfirmation: {
			formId:'abmkpvs4hxcxtcje0m7a2js4scdf3',
			formFields:['lastOrderDate','numberOrders','totalDollars','firstOrderDate']
		},
		checkoutProcessShippingForm: {
			formId:'e93ninu22w23oj3fazwf7pbrweqjc',
			formFields:['firstName','lastName','zip','country','referralSource','purchasePurpose']
		},
		catalogRequestForm: {
			formId:'irn9n4t2met2v3m2vellaoz0puqqh',
			formFields:['firstName','lastName','zip','country','referralSource']
		},
		emailSignupForm: {
			formId:'jxw90q27z9wkbd1fq7ui1m0v0x6l5',
			formFields:[]
		}
	}
	
	this.brontoFormId = brontoFormObj[formName].formId;
	this.brontoFieldsToUpdate = brontoFormObj[formName].formFields;
	
	this.contactObj = contactObj;
	
	this.baseUrl = "https://app.bronto.com/public/?q=landingpage&id=" + this.brontoFormId + "&a=DirectAdd&fn=Mail_LandingPage_Subadd&type=p&page=subadd&ssid=10173";

	this.getBrontoFieldId = function(fieldname) {
		var obj = {
			firstName:49903,
			lastName:49904,
			zip:49906,
			country:49907,
			referralSource:49912,
			purchasePurpose:49913,
			lastOrderDate:49911,
			numberOrders:50333,
			totalDollars:50334,
			firstOrderDate:50380
		}
		return obj[fieldname];
	}
	
	this.getImgSrc = function() {
		var imgSrc = this.baseUrl + "&email=" + this.contactObj.email;
		for(var i=0; i < this.brontoFieldsToUpdate.length; i++) {
			imgSrc += "&fieldcontents[" + this.getBrontoFieldId(this.brontoFieldsToUpdate[i]) + "]=" + this.contactObj[this.brontoFieldsToUpdate[i]];
		}
		imgSrc += "&_forteRandom=" + Math.floor(Math.random()*100000);
		return imgSrc;
	}
	
	this.track = function() {
		var imgSrc = this.getImgSrc();
		var newImg = document.createElement('img');
		newImg.src = imgSrc;
		newImg.style.width = 0;
		newImg.style.height = 0;
		document.getElementById('Body').appendChild(newImg);
		//var imgObj = new Image();
		//imgObj.src = imgSrc;
	}
}


