/**=========================================================================
 File    : OwcGoogleReporter.js
 Author  : E.W.Z.
 Created : 05-Sep-2007
 Summary : Core classes for Olive Analytics
*=========================================================================*/
if (typeof(JScript) == "undefined")
	throw DHTML.newError(0, "JavaScript OOP API is not included.  Add JScriptCore.js to your file");

/******************************************************************************
 * Class    : Olive.ContentGoogleReporter
 * Overview : Class describing type of custom JScript event
******************************************************************************/

if (!Olive.ContentGoogleReporter)
{
	Olive.ContentGoogleReporter = function OwcContentGoogleReporter()
	{
		this.getReporterSettings();
	} // Olive.ContentGoogleReporter()

	Olive.ContentGoogleReporter.DeclareType = function OwcContentGoogleReporter_DeclareType()
	{
		this.DeclareField("OwcTrackingCode", "UA-2527727-1");
		this.DeclareField("OwcReportStr", "");
		
		this.ReplaceMethod("reportActivityData", OwcContentGoogleReporter_reportActivityData);
		this.DeclareMethod("prepareGoogleData", OwcContentGoogleReporter_prepareGoogleData);
		this.DeclareMethod("getReporterSettings", OwcContentGoogleReporter_getReporterSettings);
	}
	
	Olive.ContentGoogleReporter.ApplyPrototype = function OwcContentGoogleReporter_ApplyPrototype(rObject, bDynamic)
	{
	} // Olive.ContentGoogleReporter.ApplyPrototype()
	
	function OwcContentGoogleReporter_getReporterSettings()
	{
		var tmpTrkngCode = OwcGetApplication.Application.getPreference("OwcTrackingCode");
		if (tmpTrkngCode)
			this.OwcTrackingCode = tmpTrkngCode;
	}
	
	function OwcContentGoogleReporter_prepareGoogleData()
	{
		this.OwcReportStr = "";
		switch(this.OwcActivityInfo.m_sActivityType)
        {
            case Olive.Activity.Data.ActivityType.pageViewed:
            case Olive.Activity.Data.ActivityType.zoom:
            {
			    this.OwcReportStr = "/" + this.OwcPublication + "_" + this.OwcIssueDate.replace(/\//gi,"-");
			    this.OwcReportStr += "/page";
			    this.OwcReportStr += "/" + this.OwcSection + "_" + this.OwcPageLabel;
			    if (this.OwcEntName)
				     this.OwcReportStr += "_" + this.OwcEntName;
            }
            break;
            case Olive.Activity.Data.ActivityType.componentOpened:
            {
				this.OwcReportStr = "/" + this.OwcPublication + "_" + this.OwcIssueDate.replace(/\//gi,"-");
				this.OwcReportStr += "/" + this.OwcEntType + "/" + this.OwcSection + "_" + this.OwcPageLabel;
				if (this.OwcEntName)
					 this.OwcReportStr += "_" + this.OwcEntName;
            }
            break;
            case Olive.Activity.Data.ActivityType.searchRequestSubmited:
            {
                this.OwcReportStr = "/" + this.OwcPublication;
                if (this.OwcIssueDate)
                    this.OwcReportStr += "_" + this.OwcIssueDate.replace(/\//gi,"-");
                this.OwcReportStr += "/action/" + Olive.ContentGoogleReporter.ActionName[this.OwcActivityInfo.m_sActivityType];
                this.OwcReportStr += "/";
                if (this.OwcSearchInCurrentIssue)
                    this.OwcReportStr += Olive.ContentActivityReporter.SearchRange.currentIssue;
                else
                    this.OwcReportStr += Olive.ContentActivityReporter.SearchRange.archive;
                    
                if (this.OwcSearchQuery && typeof(this.OwcSearchQuery) != "undefined") 
                    this.OwcReportStr += "_" + this.OwcSearchQuery;
            }
            break;
            case Olive.Activity.Data.ActivityType.mailSent:
            case Olive.Activity.Data.ActivityType.printEntity:
            {
                this.OwcReportStr = "/" + this.OwcPublication + "_" + this.OwcIssueDate.replace(/\//gi,"-");
				this.OwcReportStr += "/action/" + Olive.ContentGoogleReporter.ActionName[this.OwcActivityInfo.m_sActivityType];
				this.OwcReportStr += "/";
				if (this.OwcSection && typeof(this.OwcSection) != "undefined")
				    this.OwcReportStr += this.OwcSection;
				if (this.OwcPageLabel && typeof(this.OwcPageLabel) != "undefined")
				    this.OwcReportStr += "_" + this.OwcPageLabel;
				if (this.OwcEntName)
					this.OwcReportStr += "_" + this.OwcEntName;
            }
            break;
            case Olive.Activity.Data.ActivityType.printDocument:
            {
				this.OwcReportStr = "/" + this.OwcPublication + "_" + this.OwcIssueDate.replace(/\//gi,"-");
				this.OwcReportStr += "/action/" + Olive.ContentGoogleReporter.ActionName[this.OwcActivityInfo.m_sActivityType];
				this.OwcReportStr += "/";
				if (this.OwcSection && typeof(this.OwcSection) != "undefined")
				    this.OwcReportStr += this.OwcSection;
				
				if (   this.OwcListOfPageSectionsForPrint && typeof (this.OwcListOfPageSectionsForPrint) != "undefined")
				    this.OwcReportStr += "_" + this.OwcListOfPageSectionsForPrint;
				else if (this.OwcPageNo && typeof(this.OwcPageNo) != "undefined")
				    this.OwcReportStr += "_" + this.OwcPageNo;
		    }
            break;
            case Olive.Activity.Data.ActivityType.bookmarkAdded:
            {
                this.OwcReportStr = "/" + this.OwcPublication + "_" + this.OwcIssueDate.replace(/\//gi,"-");
				this.OwcReportStr += "/action/" + Olive.ContentGoogleReporter.ActionName[this.OwcActivityInfo.m_sActivityType];
				if (this.OwcSection)
				    this.OwcReportStr += "/" + this.OwcSection;
				    
				if (this.OwcPageLabel && typeof(this.OwcPageLabel) != "undefined")
				    this.OwcReportStr += "_" + this.OwcPageLabel;
				    
				if (this.OwcEntName)
					this.OwcReportStr += "_" + this.OwcEntName;
            }
            break;
            case Olive.Activity.Data.ActivityType.bookmarkServiceItemSaved:
            {
                this.OwcReportStr = "/" + this.OwcPublication + "_" + this.OwcIssueDate.replace(/\//gi,"-");
				this.OwcReportStr += "/action/" + Olive.ContentGoogleReporter.ActionName[this.OwcActivityInfo.m_sActivityType];
				if (this.OwcSection)
				    this.OwcReportStr += "/" + this.OwcSection;
				    
				if (this.OwcPageLabel && typeof(this.OwcPageLabel) != "undefined")
				    this.OwcReportStr += "_" + this.OwcPageLabel;
				    
				if (this.OwcEntName)
					this.OwcReportStr += "_" + this.OwcEntName;
			    if (this.OwcAdapterName)
			        this.OwcReportStr += "_" + this.OwcAdapterName;
            }
            break;
            case Olive.Activity.Data.ActivityType.linkClicked:
            {
				 this.OwcReportStr = "/" + this.OwcPublication + "_" + this.OwcIssueDate.replace(/\//gi,"-") + "/" + Olive.ContentGoogleReporter.ActionName[this.OwcActivityInfo.m_sActivityType] + "/";
				 if (this.OwcPageLabel && typeof(this.OwcPageLabel) != "undefined")
				    this.OwcReportStr += this.OwcPageLabel;
				 if (this.OwcURL && typeof (this.OwcURL) != "undefined")
				    this.OwcReportStr += "_" + this.OwcURL;
            }
            break;
            case Olive.Activity.Data.ActivityType.richMediaPlayed:
            {
                this.OwcReportStr = "/" + this.OwcPublication + "_" + this.OwcIssueDate.replace(/\//gi,"-");
				this.OwcReportStr += "/action/" + Olive.ContentGoogleReporter.ActionName[this.OwcActivityInfo.m_sActivityType];
				if (this.OwcSection)
				    this.OwcReportStr += "/" + this.OwcSection;
				if (this.OwcPageLabel)
				    this.OwcReportStr += "_" + this.OwcPageLabel;
				if (this.OwcURL)
					this.OwcReportStr += "_" + this.OwcURL;
			    if (this.OwcDuration)
					this.OwcReportStr += "_" + this.OwcDuration;
            } 
            break;
            default:
            {
				return false;
            }
        }
        return true;
	}
	function OwcContentGoogleReporter_reportActivityData()
	{
		try
		{
			if (this.prepareGoogleData())
			{
				_uacct = this.OwcTrackingCode;
				if (this.OwcReportStr)
					urchinTracker(this.OwcReportStr);
			}
		}
		catch(e)
		{
			// Thou shall not interrupt application
		}
	}
	JScript.Type.RegisterClass("Olive.ContentGoogleReporter", Olive.ContentGoogleReporter, Olive.ContentActivityReporter);
} // Define Olive.ContentGoogleReporter class

if (!Olive.ContentGoogleReporter.ActionName)
{
	Olive.ContentGoogleReporter.ActionName = 
	{
		pageViewed			    : "view",
		zoom				    : "zoom",
		printDocument           : "print",
		printEntity             : "print",
		searchRequestSubmited	: "search",
		mailSent			    : "email",
		bookmarkAdded		    : "bookmark",
		bookmarkSaved		    : "bookmark",
        linkClicked			    : "link",
        componentOpened		    : "clickedtotext",
        richMediaPlayed         : "play"
        
	}
	JScript.Type.RegisterClass("Olive.ContentGoogleReporter.ActionName", Olive.ContentGoogleReporter.ActionName);
}
