/*===========================================================
Reporting JS

Contains all functions neccessary for reporting
************************************************************
Created by Ming Chan(ming_chan@designreactor.com)
copyright © 2005 Design Reactor Inc.
************************************************************
Last Modified: 03/10/05
Version: 1.0
===========================================================*/
/*===========================
Define locations of the image
============================*/

//var imgOrgSrc= "http://marketplace.onbusinessnetwork.com/testingLog.img"
var imgOrgSrc= "http://demo.ciscovideo.com:8080/NatC_Metrics/clickImage.jsp";
var s_clickLocation="";
var s_action="";
var s_contentType="";
var s_contentID="";
var s_userID="";
var QA_log="";
var winURL="";
var myWindow=""
var reportingImage;
/*===========================
Write Image Functions
============================*/

function initReporting(){
	reportingImage= new Image(1,1);
	//document.write('<img src="' + imgOrgSrc + '" name="reportingImage" WIDTH=1 HEIGHT=1>');
}

/*===========================
Send Tracking Functions
============================*/

// variables being sent: clickLocation, action, contentType, contentID, userID
function sendReporting(arg){
	if (!document.getElementById) return
	var today= new Date();
	//parse arg
	
	var temp= new Array();
	var begin=0;
	var end=0;
	var firstSpace=arg.indexOf(",");
	var lastSpace=arg.lastIndexOf(",");
	for(var i=0;i<arg.length;i++){
		if(end!=lastSpace){
			end=arg.indexOf(",",begin+1)
			temp[i]=arg.substring(begin,end,end-begin);
			begin=arg.indexOf(",",end)+1;
		}
	}
	temp.push(arg.substring(lastSpace+1,arg.length));
	var s_clickLocation= temp[0];
	var s_action= temp[1];
	var s_contentType= temp[2];
	var s_contentID= temp[3];
	var s_userID= temp[4];
	
	var imgSrc= imgOrgSrc + "?clickLocation=" + s_clickLocation + "&action=" + s_action + "&contentType=" + s_contentType + "&contentID=" + s_contentID + "&userID=" + s_userID + "&random=" + today.getTime();
	//document.reportingImage.setAttribute('src',imgSrc);
	reportingImage.src=imgSrc;
	
	/****** Popup file For QA **********/
	/*QA_log+= imgSrc +"<br><br>";
	QA_log= replace(QA_log,"&", " + ");
	winURL= "QAPopup.html?log=" + QA_log;
	
	myWindow = window.open(winURL,'QA','width=300,height=150,resizable=1,scrollbars=1, menubar=1');*/
} 

/*===========================
FOR QA
============================*/

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);
    return newstr;
}

