/**
 * necessary javascript code to send page infos to instadia server
 */
var instadiaSTLPageIdSuffix="";
var instadiaSTLPageId2Suffix="";

var overriddenPageId="";

// declare empty instadia methods, in case when the instadia script can't be included (e.g. server is down)
function Instadia_sendInfo() {
}

function Instadia_sendEvent(a,b,c) {
	// for debugging purposes
	//alert("1: " + a + "\n2: " + b + "\n3: " + c);
}

function getInstadiaId() {
	return instadiaId;
}

function overridePageId(pageId) {
	overriddenPageId = pageId;
}
		
function getInstadiaPageId() {
	if (overriddenPageId != ""){
		return overriddenPageId;
	} else {
		return instadiaPageId + instadiaSTLPageIdSuffix;
	}
}
		
function getInstadiaPageId2() {
	if (overriddenPageId != "") {
		return overriddenPageId;
	} else {
		return instadiaPageId2 + instadiaSTLPageId2Suffix;
	}
}

// description is determined by comparing both pageIds. The common prefix is just stripped.
function getInstadiaLinkDescription(s2) {
	//alert("s1: "+s1+", s2: "+s2);
	var s1 = getInstadiaPageId();
	var len = Math.min(getInstadiaPageId().length, s2.length - 1);
	var prefix = 0;

	for(var i=0; i<len; i++) {
		if(s1.charAt(i) != s2.charAt(i)) {
			break;
		} else if(s1.charAt(i) == '/') {
			prefix = i + 1;
		}
	}
	
	// should we really remove the last character
	return s2.substring(prefix, s2.length - 1);
}

// see CR173, called from flash
function Instadia_sendFlashEvent(flashtag) {
// CR479: do not send Instadia tracking anymore
//	Instadia_sendEvent(getInstadiaId(), getInstadiaPageId(), getInstadiaPageId2()+flashtag);
}

// method to replace the instadia id in link parameters
function replaceCSBridge(link) {
	var _instadiaId = getInstadiaId();

	if (_instadiaId != null && _instadiaId.length > 0 && _instadiaId != "null") {
		var keyValue = "inretid";
		link = link.replace(/instadiaid/, encodeURI( keyValue ));

		if(CSbridge != null) {
			link = link.replace(/CSbridge/, CSbridge);
		} else {
			link = link.replace(/&CSbridge/, '');
			link = link.replace(/\?CSbridge&/, '\?');
		}
	} else {
		link = link.replace(/&inretid/, '');
		link = link.replace(/\?inretid&/, '\?');

		link = link.replace(/&CSbridge/, '');
		link = link.replace(/\?CSbridge&/, '\?');
	}

	return link;
}