var traceCount = 0;

function getQueryVariable(variable)
{
	var src = window.location.href;
	var params = src.split("?");
	if (params.length == 2)
	{
    	var vars = params[1].split("&");
    	for (var i=0;i<vars.length;i++) {
	       var pair = vars[i].split("=");
	       if(pair[0] == variable){
	       		return pair[1];
	       }
    	}
	}
    return "";
}

function sendTraceMessageFunction(message)
{ 
	// This variable is used in the API's data structure. 
	var componentId = getQueryVariable('frameComponentId');	
	try
	{
		// The 'componentId' is a mandatory field and must be filled as given here.
		// The 'traceMessage' is written into the trace log of the CBA item. 
		var pass_data = {
 		'componentId': componentId,
 		'traceMessage': message,
 		'traceCount' : traceCount
		};
		
		traceCount++;
		window.parent.postMessage(JSON.stringify(pass_data), '*');

	} catch(e) {console.debug(e); }
}


