//------------------------------------------------
// action (sale / lead / custom action) object
//------------------------------------------------

var PostAffAction = function(actionCode) {
	this._actionCode = actionCode;
	this._totalCost = '';
	this._fixedCost = '';
	this._orderID = '';
	this._productID = '';
	this._data1 = '';
	this._data2 = '';
	this._data3 = '';
	this._data4 = '';
	this._data5 = '';
	this._affiliateID = '';
	this._campaignID = '';
	this._channelID = '';
	this._customCommission = '';
	this._status = '';
	this._currency = '';
	this._couponCode = '';
}

PostAffAction.prototype.correctSumChars = function(value) {
	var strValue = new String(value);
	strValue = strValue.replace(/,/g, ".");
	strValue = strValue.replace(/[^0-9\.]/gi, "");
	return strValue;
}

PostAffAction.prototype.correctCustomParameterChars = function(value) {
	var strValue = new String(value);
	strValue = strValue.replace(/,/g, ".");
	strValue = strValue.replace(/[^0-9\.\%]/gi, "");
	strValue = strValue.replace(/%/gi, "%25");
	return strValue;
}

PostAffAction.prototype.correctTextChars = function(value) {
	var strValue = new String(value);
	strValue = strValue.replace(/ /gi, "+");
	strValue = strValue.replace(/:/gi, "");
	return strValue;
}

PostAffAction.prototype.setTotalCost = function(value) {
	try {
		if (typeof (value) != 'undefined') {
			this._totalCost = this.correctSumChars(value);
		}
	} catch (err) {
	}
}

PostAffAction.prototype.setCoupon = function(value) {
	try {
		if (typeof (value) != 'undefined') {
			this._couponCode = this.correctTextChars(value);
		}
	} catch (err) {
	}
}

PostAffAction.prototype.setFixedCost = function(value) {
	try {
		if (typeof (value) != 'undefined') {
			this._fixedCost = this.correctCustomParameterChars(value);
		}
	} catch (err) {
	}
}

PostAffAction.prototype.setOrderID = function(value) {
	try {
		if (typeof (value) != 'undefined') {
			this._orderID = this.correctTextChars(value);
		}
	} catch (err) {
	}
}

PostAffAction.prototype.setProductID = function(value) {
	try {
		if (typeof (value) != 'undefined') {
			this._productID = this.correctTextChars(value);
		}
	} catch (err) {
	}
}

PostAffAction.prototype.setAffiliateID = function(value) {
	try {
		if (typeof (value) != 'undefined') {
			this._affiliateID = this.correctTextChars(value);
		}
	} catch (err) {
	}
}

PostAffAction.prototype.setCampaignID = function(value) {
	try {
		if (typeof (value) != 'undefined') {
			this._campaignID = this.correctTextChars(value);
		}
	} catch (err) {
	}
}

PostAffAction.prototype.setChannelID = function(value) {
	try {
		if (typeof (value) != 'undefined') {
			this._channelID = this.correctTextChars(value);
		}
	} catch (err) {
	}
}

PostAffAction.prototype.setCurrency = function(value) {
	try {
		if (typeof (value) != 'undefined') {
			this._currency = this.correctTextChars(value);
		}
	} catch (err) {
	}
}

PostAffAction.prototype.setCustomCommission = function(value) {
	try {
		if (typeof (value) != 'undefined') {
			this._customCommission = this.correctCustomParameterChars(value);
		}
	} catch (err) {
	}
}

PostAffAction.prototype.setStatus = function(value) {
	try {
		if (typeof (value) != 'undefined') {
			this._status = value;
		}
	} catch (err) {
	}
}

PostAffAction.prototype.setData1 = function(value) {
	try {
		if (typeof (value) != 'undefined') {
			this._data1 = this.correctTextChars(value);
		}
	} catch (err) {
		this._data1 = 0;
	}
}

PostAffAction.prototype.setData2 = function(value) {
	try {
		if (typeof (value) != 'undefined') {
			this._data2 = this.correctTextChars(value);
		}
	} catch (err) {
		this._data2 = 0;
	}
}

PostAffAction.prototype.setData3 = function(value) {
	try {
		if (typeof (value) != 'undefined') {
			this._data3 = this.correctTextChars(value);
		}
	} catch (err) {
		this._data3 = 0;
	}
}

PostAffAction.prototype.setData4 = function(value) {
	try {
		if (typeof (value) != 'undefined') {
			this._data4 = this.correctTextChars(value);
		}
	} catch (err) {
		this._data4 = 0;
	}
}

PostAffAction.prototype.setData5 = function(value) {
	try {
		if (typeof (value) != 'undefined') {
			this._data5 = this.correctTextChars(value);
		}
	} catch (err) {
		this._data5 = 0;
	}
}

// ------------------------------------------------
// real tracker object
// ------------------------------------------------

var PostAffTrackerObject = function() {
	this._lid = '';

	var trackingUrl = new String(document.getElementById('pap_x2s6df8d').src);
	this._trackingUrl = trackingUrl.substr(0, Math.max(trackingUrl
			.lastIndexOf('\\'), trackingUrl.lastIndexOf('/')) + 1);

	this._trackingMethod = '1';
	this._cookieVal = '';

	this._flashStarted = false;
	this._actionObjects = new Array();
	this._cookies = new Array();

	var cookie = new Object;
	cookie.name = 'PAPCookie_Sale';
	cookie.postname = 'fsc';
	cookie.value = '';
	cookie.del = false;
	this._cookies[0] = cookie;

	var cookie = new Object;
	cookie.name = 'PAPCookie_FirstClick';
	cookie.postname = 'ffcc';
	cookie.value = '';
	cookie.del = false;
	this._cookies[1] = cookie;

	var cookie = new Object;
	cookie.name = 'PAPCookie_LastClick';
	cookie.postname = 'flcc';
	cookie.value = '';
	cookie.del = false;
	this._cookies[2] = cookie;

	this._loadFirstPartyCookies();
}

PostAffTrackerObject.prototype.createAction = function(actionCode) {
	var obj = new PostAffAction(actionCode);
	var index = this._actionObjects.length;
	this._actionObjects[index] = obj;

	return obj;
}

PostAffTrackerObject.prototype.waitForClickTracker = function(command) {
	try {
		tracker = _tracker;
	} catch (err) {
		tracker = null;
	}
	if (tracker != null && tracker.isRunning()) {
		setTimeout(command, 500);
		return true;
	}
	return false;
}

PostAffTrackerObject.prototype.register = function() {
	if (this.waitForClickTracker('PostAffTracker.register();'))
		return;

	if (this._isFlashActive()) {
		this._insertFlashObject();
		setTimeout('trackNext()', 1000);
	} else {
		this._trackNext();
	}
	this._deleteFirstPatyCookies();
}

PostAffTrackerObject.prototype.notifySale = function() {
	if (this.waitForClickTracker('PostAffTracker.notifySale();'))
		return;

	this.writeValueToAttribute('pap_dx8vc2s5', 'value', 'cookie');
}

PostAffTrackerObject.prototype._checkIfToRunFlash = function(value) {
	if (this._isFlashActive() && this._flashStarted == false) {
		return true;
	}
	return false;
}

PostAffTrackerObject.prototype.setLid = function(value) {
	try {
		if (typeof (value) != 'undefined') {
			this._lid = value;
		}
	} catch (err) {
	}
}

PostAffTrackerObject.prototype.setCookieValue = function(value) {
	try {
		if (typeof (value) != 'undefined') {
			this._cookieVal = value;
		}
	} catch (err) {
	}
}

PostAffTrackerObject.prototype._getFlashVersion = function() {
	var version = "", n = navigator;
	if (n.plugins && n.plugins.length) {
		for ( var i = 0; i < n.plugins.length; i++) {
			if (n.plugins[i].name.indexOf('Shockwave Flash') != -1) {
				version = n.plugins[i].description.split('Shockwave Flash ')[1];
				break;
			}
		}
	} else if (window.ActiveXObject) {
		for ( var i = 10; i >= 4; i--) {
			try {
				var result = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash."
						+ i + "');");
				if (result) {
					version = i + '.0';
					break;
				}
			} catch (e) {
			}
		}
	}
	return version;
}

PostAffTrackerObject.prototype._isFlashActive = function() {
	var version = this._getFlashVersion();
	var ns4 = document.layers;
	var ns6 = document.getElementById && !document.all
			|| (navigator.userAgent.indexOf('Opera') >= 0);
	var ie4 = document.all;
	if (!ns4 && !ns6 && ie4) {
		return false;
	}
	return !(version == "" || version < 5);
}

PostAffTrackerObject.prototype._getFlashParams = function() {
	var params = "";
	for ( var i = 0; i < this._cookies.length; i++) {
		params += "&amp;n" + i + "=" + this._cookies[i].name;
		if (this._cookies[i].del == true) {
			params += "&amp;d" + i + "=1";
		}
	}
	return "?a=r" + params;
}

PostAffTrackerObject.prototype._insertFlashObject = function() {
	if (this._checkIfToRunFlash()) {
		this._flashStarted = true;

		document
				.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" "
						+ "codebase=\""
						+ ((this._trackingUrl.substr(0, 5) == "https") ? "https"
								: "http")
						+ "://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" "
						+ "width=\"1px\" height=\"1px\"> "
						+ "<param name=\"allowScriptAccess\" value=\"always\" />"
						+ "<param name=\"movie\" value=\""
						+ this._trackingUrl
						+ "pap.swf"
						+ this._getFlashParams()
						+ "\" /> "
						+ "<embed src=\""
						+ this._trackingUrl
						+ "pap.swf"
						+ this._getFlashParams()
						+ "\" width=\"1px\" height=\"1px\" allowScriptAccess=\"always\"/> "
						+ "</object>");
	}
}

PostAffTrackerObject.prototype._processFlashCookies = function(cookies) {
	var flashCookies = cookies.split('_,_');
	for ( var i = 0; i < flashCookies.length; i++) {
		var splitIndex = flashCookies[i].indexOf('=');
		if (splitIndex < 0)
			continue;
		if ((flashCookies[i].substr(splitIndex + 1) == null)
				|| (flashCookies[i].substr(splitIndex + 1) == ''))
			continue;
		this._setCookie(flashCookies[i].substr(0, splitIndex), flashCookies[i]
				.substr(splitIndex + 1), 'F');
	}
}

PostAffTrackerObject.prototype._setCookie = function(name, value, type) {
	for ( var i = 0; i < this._cookies.length; i++) {
		if (this._cookies[i].name == name) {
			this._cookies[i].value = value;
			this._trackingMethod = type;
		}
	}
}

PostAffTrackerObject.prototype._setCookieToBeDeleted = function(name) {
	for ( var i = 0; i < this._cookies.length; i++) {
		if (this._cookies[i].name == name) {
			this._cookies[i].del = true;
		}
	}
}

PostAffTrackerObject.prototype._loadFirstPartyCookies = function() {
	for ( var i = 0; i < this._cookies.length; i++) {
		var cookieValue = this._getNormalCookie(this._cookies[i].name);
		if (cookieValue != null) {
			this._cookies[i].value = cookieValue;
			this._trackingMethod = '1';
		}
	}
}

PostAffTrackerObject.prototype._deleteFirstPatyCookies = function() {
	for ( var i = 0; i < this._cookies.length; i++) {
		if (this._cookies[i].del) {
			document.cookie = this._cookies[i].name + '=;expires=Thu, 01-Jan-1970 00:00:01 GMT;path=/';
		}
	}
}

PostAffTrackerObject.prototype._getNormalCookie = function(name) {
	var nameequals = name + "=";
	var beginpos = 0;
	var beginpos2 = 0;
	while (beginpos < document.cookie.length) {
		beginpos2 = beginpos + name.length + 1;
		if (document.cookie.substring(beginpos, beginpos2) == nameequals) {
			var endpos = document.cookie.indexOf(";", beginpos2);
			if (endpos == -1)
				endpos = document.cookie.length;
			return this._decodeString(document.cookie.substring(beginpos2, endpos));
		}
		beginpos = document.cookie.indexOf(" ", beginpos) + 1;
		if (beginpos == 0)
			break;
	}

	return null;
}

PostAffTrackerObject.prototype._trackNext = function() {
	var trackNextScript = document.createElement('script');
	trackNextScript.id = 'pap_x2c8rf47';
	trackNextScript.type = 'text/javascript';
	trackNextScript.src = this._trackingUrl + "sale.php" + this._getParameters();
	
    scriptElement = document.getElementById('pap_x2s6df8d');
    scriptElement.parentNode.insertBefore(trackNextScript, scriptElement.nextSibling);
}

PostAffTrackerObject.prototype._encodeString = function(item) {
	return encodeURIComponent(item);
}

PostAffTrackerObject.prototype._decodeString = function(item) {
	return decodeURIComponent(item);
}


PostAffTrackerObject.prototype._getParameters = function() {
	var params = "?lid=" + this._lid;
	params += "&ptm=" + this._trackingMethod;

	if (this._cookieVal != '') {
		params += "&CookieValue=" + this._cookieVal;
	}

	var length = this._actionObjects.length;
	if (length > 0) {
		var actionCode = '';
		var totalCost = '';
		var fixedCost = '';
		var couponCode = '';
		var orderID = '';
		var productID = '';
		var data1 = '';
		var data2 = '';
		var data3 = '';
		var data4 = '';
		var data5 = '';
		var affiliateID = '';
		var campaignID = '';
		var channelID = '';
		var customCommission = '';
		var customStatus = '';
		var currencyCode = '';

		for (i = 0; i < length; i++) {
			obj = this._actionObjects[i];

			actionCode = this._addToInnerParameter(i, actionCode,
					obj._actionCode);
			totalCost = this._addToInnerParameter(i, totalCost, obj._totalCost);
			couponCode = this._addToInnerParameter(i, couponCode, obj._couponCode);
			fixedCost = this._addToInnerParameter(i, fixedCost, obj._fixedCost);
			orderID = this._addToInnerParameter(i, orderID, obj._orderID);
			productID = this._addToInnerParameter(i, productID, obj._productID);
			data1 = this._addToInnerParameter(i, data1, obj._data1);
			data2 = this._addToInnerParameter(i, data2, obj._data2);
			data3 = this._addToInnerParameter(i, data3, obj._data3);
			data4 = this._addToInnerParameter(i, data4, obj._data4);
			data5 = this._addToInnerParameter(i, data5, obj._data5);
			affiliateID = this._addToInnerParameter(i, affiliateID,
					obj._affiliateID);
			campaignID = this._addToInnerParameter(i, campaignID,
					obj._campaignID);
			channelID = this._addToInnerParameter(i, channelID, obj._channelID);
			customCommission = this._addToInnerParameter(i, customCommission,
					obj._customCommission);
			customStatus = this._addToInnerParameter(i, customStatus,
					obj._status);
			currencyCode = this._addToInnerParameter(i, currencyCode,
					obj._currency);
		}

		var somethingExists = false;
		if (actionCode != '') {
			params += "&ActionCode=" + this._encodeString(actionCode);
			somethingExists = true;
		}
		if (totalCost != '') {
			params += "&TotalCost=" + this._encodeString(totalCost);
			somethingExists = true;
		}
		if (couponCode != '') {
			params += "&Coupon=" + this._encodeString(couponCode);
			somethingExists = true;
		}
		if (fixedCost != '') {
			params += "&FixedCost=" + this._encodeString(fixedCost);
			somethingExists = true;
		}
		if (orderID != '') {
			params += "&OrderID=" + this._encodeString(orderID);
			somethingExists = true;
		}
		if (productID != '') {
			params += "&ProductID=" + this._encodeString(productID);
			somethingExists = true;
		}
		if (data1 != '') {
			params += "&data1=" + this._encodeString(data1);
			somethingExists = true;
		}
		if (data2 != '') {
			params += "&data2=" + this._encodeString(data2);
			somethingExists = true;
		}
		if (data3 != '') {
			params += "&data3=" + this._encodeString(data3);
			somethingExists = true;
		}
		if (data4 != '') {
			params += "&data4=" + this._encodeString(data4);
			somethingExists = true;
		}
		if (data5 != '') {
			params += "&data5=" + this._encodeString(data5);
			somethingExists = true;
		}
		if (affiliateID != '') {
			params += "&AffiliateID=" + this._encodeString(affiliateID);
			somethingExists = true;
		}
		if (campaignID != '') {
			params += "&CampaignID=" + this._encodeString(campaignID);
			somethingExists = true;
		}
		if (channelID != '') {
			params += "&ChannelID=" + this._encodeString(channelID);
			somethingExists = true;
		}
		if (customCommission != '') {
			params += "&Commission=" + this._encodeString(customCommission);
			somethingExists = true;
		}
		if (customStatus != '') {
			params += "&PStatus=" + this._encodeString(customStatus);
			somethingExists = true;
		}
		if (currencyCode != '') {
			params += "&Currency=" + this._encodeString(currencyCode);
			somethingExists = true;
		}

		if (somethingExists == false) {
			params += "&OrderID=";
			for (i = 0; i < length - 1; i++) {
				params += ":";
			}
		}
	}

	params += this._getCookieParams();
	return params;
}

PostAffTrackerObject.prototype._addToInnerParameter = function(index, param,
		value) {
	if (param != '') {
		param += ':';
	}
	if (value != '') {
		if (param == '') {
			for (i = 0; i < index; i++) {
				param += ":";
			}
		}

		param += value.replace(/:/g, '');
	}
	return param;
}

PostAffTrackerObject.prototype._getParamFromLink = function(link, name) {
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regexS = "[\\?&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(link);
	if (results == null)
		return null;
	else
		return results[1];
}

PostAffTrackerObject.prototype._encodeRegExp = function(re) {
	if (re == null) {
		return '';
	}
	return re.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
}

PostAffTrackerObject.prototype._getLinkWithValue = function(link,
		parameterName, value, separator, storedBefore) {
	value = this._encodeString(value);
	
	if (link == null || link == '') {
		return '?'+value; 
	}
	
	if (separator == null) {
		separator = '||';
	}

	var oldParam = this._getParamFromLink(link, parameterName);

	if (storedBefore) {
		if (link.indexOf(separator) == -1) {
			link = link.replace(this._encodeRegExp(oldParam), '');
		} else {
			link = link.replace(this._encodeRegExp(separator) + '*', '');
		}
		oldParam = this._getParamFromLink(link, parameterName);
	}

	if (oldParam != null) {
		if (oldParam == '') {
			return link.replace(this._encodeRegExp(parameterName + '='),
					parameterName + '=' + value);
		} else {
			return link.replace(this._encodeRegExp(parameterName + '='
					+ oldParam), parameterName + '=' + oldParam + separator
					+ value);
		}
	} else {
		var joinChar;
		if (link.indexOf('?') == -1) {
			joinChar = '?';
		} else {
			joinChar = '&';
		}
		return link + joinChar + parameterName + '=' + value;
	}
}

PostAffTrackerObject.prototype.getElementsById = function(id) {
	var nodes = new Array();
	var tmpNode = document.getElementById(id);
	while (tmpNode) {
		nodes.push(tmpNode);
		tmpNode.id = "";
		tmpNode = document.getElementById(id);
		for ( var x = 0; x < nodes.length; x++) {
			if (nodes[x] == tmpNode) {
				tmpNode = false;
			}
		}

	}
	for ( var x = 0; x < nodes.length; x++) {
		nodes[x].id = id;
	}

	return nodes;
}

PostAffTrackerObject.prototype._replaceHttpInText = function(text) {
	text = text.replace("http://", "H_");
	text = text.replace("https://", "S_");
	return text;
}

PostAffTrackerObject.prototype._getCookieParams = function() {
	var params = "";
	for ( var i = 0; i < this._cookies.length; i++) {
		params += "&" + this._cookies[i].postname + "="
				+ this._encodeString(this._replaceHttpInText(this._cookies[i].value));
	}
	return params;
}

/** 
 * add value to html element
 * @params id(element id); attributeName(href, value, action); value(cookie, affiliate, campaign),
 * 		   urlParamName - name for url parameter(e.g: papCookie), null if it is not link
 * 		   separator - separation for adding pap value, default null = old value is overwritten
 * 		     
 */
PostAffTrackerObject.prototype.writeValueToAttribute = function(id,
		attributeName, value, urlParamName, separator) {
	if (this._isFlashActive()) {
		// write 1st party cookies immediately
		var storedBefore = this._writeValueToAttribute(id, attributeName,
				value, urlParamName, separator, false);
		// get flash cookies on delay
		this._insertFlashObject();

		var self = this;
		setTimeout( function(ms) {
			self._writeValueToAttribute(id, attributeName, value, urlParamName,
					separator, storedBefore)
		}, 1000);
	} else {
		this._writeValueToAttribute(id, attributeName, value, urlParamName, separator,
				false);
		;
	}
}

PostAffTrackerObject.prototype._writeValueToAttribute = function(id,
		attributeName, value, urlParamName, separator, storedBefore) {
	var cookieVal = this._cookies[0].value;
	if (cookieVal == null || cookieVal == '') {
		return false;
	}

	try {
		if (value == 'affiliate') {
			cookieVal = eval('(' + cookieVal + ')').a;
		} else if (value == 'campaign') {
			cookieVal = eval('(' + cookieVal + ')').c;
		}
	} catch (exception) {
		return;
	}
	return this._writeValue(id, attributeName, cookieVal, urlParamName, separator,
			storedBefore);
}

PostAffTrackerObject.prototype._getValue = function(oldValue, newValue,
		urlParamName, separator, storedBefore) {
	if (urlParamName == null) {	
		if (separator == null) {
			return newValue;
		}
		
		if (storedBefore) {		
			indexOfSeparator = oldValue.indexOf(separator);
			oldValue = oldValue.substring(0, indexOfSeparator);
		} 
		
		return oldValue + separator + newValue;
	}
	return this._getLinkWithValue(oldValue, urlParamName, newValue, separator,
			storedBefore);
}

PostAffTrackerObject.prototype._writeValue = function(id, attributeName, value,
		urlParamName, separator, storedBefore) {
	if (value == null || value == '') {
		return false;
	}

	var elements = this.getElementsById(id);
	for (i = 0; i < elements.length; i++) {
		if (elements[i].id == id) {
			// SWITCH CASES are used because of Internet Explorer 6 doesn't
			// support setAttribute in correct way
			switch (attributeName) {
			case 'href':
				elements[i].href = this._getValue(elements[i].href, value,
						urlParamName, separator, storedBefore);
				break;
			case 'value':
				elements[i].value = this._getValue(elements[i].value, value,
						urlParamName, separator, storedBefore);
				break;
			case 'action':
				elements[i].action = this._getValue(elements[i].action, value,
						urlParamName, separator, storedBefore);
				break;
			default:
				elements[i].setAttribute(attributeName, this._getValue(
						elements[i].getAttribute(attributeName), value,
						urlParamName, separator, storedBefore));
				break;
			}
		}
	}
	return true;
}

// ------------------------------------------------
// singleton tracker object
// ------------------------------------------------

var PostAffTracker = new function(lid) {
	this._instance = new PostAffTrackerObject();
	this._separator;

	this.createSale = function() {
		return this._instance.createAction('');
	}

	this.createAction = function(actionCode) {
		return this._instance.createAction(actionCode);
	}

	this.register = function() {
		return this._instance.register();
	}

	this.notifySale = function() {
		return this._instance.notifySale();
	}

	this.setLid = function(value) {
		return this._instance.setLid(value);
	}

	this.setChannel = function(value) {
		return this._instance.setChannel(value);
	}

	this.setCookieValue = function(value) {
		return this._instance.setCookieValue(value);
	}

	this._processFlashCookies = function(cookies) {
		return this._instance._processFlashCookies(cookies);
	}

	this._setCookieToBeDeleted = function(name) {
		return this._instance._setCookieToBeDeleted(name);
	}

	this.setAppendValuesToField = function(separator) {
		return this._separator = separator;
	}

	this._trackNext = function() {
		return this._instance._trackNext();
	}

	this.writeCookieToCustomField = function(id) {
		return this._instance.writeValueToAttribute(id, 'value', 'cookie', null, this._separator);
	}

	this.writeAffiliateToCustomField = function(id) {
		return this._instance.writeValueToAttribute(id, 'value', 'affiliate', null, this._separator);
	}

	this.writeCampaignToCustomField = function(id) {
		return this._instance.writeValueToAttribute(id, 'value', 'campaign', null, this._separator);
	}

	this.writeCookieToLink = function(id, urlParamName, separator) {
		return this._instance.writeValueToAttribute(id, 'href', 'cookie',
				urlParamName, separator == null ? this._separator : separator);
	}

	this.writeAffiliateToLink = function(id, urlParamName, separator) {
		return this._instance.writeValueToAttribute(id, 'href', 'affiliate',
				urlParamName, separator == null ? this._separator : separator);
	}

	this.writeValueToAttribute = function(id, attributeName, value, type,
			separator) {
		return this._instance.writeValueToAttribute(id, attributeName, value,
				type, separator == null ? this._separator : separator);
	}

}

// ------------------------------------------------
// global functions
// ------------------------------------------------

function rpap(cookies) {
	PostAffTracker._processFlashCookies(cookies);
}

function trackNext() {
	PostAffTracker._trackNext();
}
