/**=========================================================================
 File    : OwcLogReporter.js
 Author  : Miki Raviv 
 Created : 16-Sep-2009
 Summary : classes for Olive Analytics Log File
*=========================================================================*/
if (typeof(JScript) == "undefined")
	throw DHTML.newError(0, "JavaScript OOP API is not included.  Add JScriptCore.js to your file");

/******************************************************************************
 * Class    : Olive.ContentLogReporter
 * Overview : Class describing type of custom JScript event
******************************************************************************/

if (!Olive.ContentLogReporter)
{
	Olive.ContentLogReporter = function OwcContentLogReporter()
	{
	} // Olive.ContentLogReporter()

	Olive.ContentLogReporter.DeclareType = function OwcContentLogReporter_DeclareType()
	{
		this.DeclareField("xmlHttp", "");
		this.DeclareField("method", "POST");
		this.DeclareField("async", true);
		this.DeclareField("xmlHttp", null);
		this.DeclareField("url", "Server/TrackUsers.asp");
		this.DeclareField("sStatsInfo", "");
		
				
		this.ReplaceMethod("reportActivityData", OwcContentLogReporter_reportActivityData);
		this.DeclareMethod("prepareLogData", OwcContentLogReporter_prepareLogData);
		this.DeclareMethod("getReporterSettings", OwcContentLogReporter_getReporterSettings);		
	}
	
	Olive.ContentLogReporter.ApplyPrototype = function OwcContentLogReporter_ApplyPrototype(rObject, bDynamic)
	{
	} // Olive.ContentLogReporter.ApplyPrototype()
	
	function OwcContentLogReporter_getReporterSettings()
	{
	}
	
	function OwcContentLogReporter_prepareLogData()
	{
		;
		this.OwcReportStr = "";
		
		// Adding Statistics Info Into String Variables
		try
        {
            var sBaseHref = this.OwcPublication + "/" + this.OwcIssueDate;
            var sURL = sBaseHref + "&pageno=" + this.OwcPageNo;
                            
            var sEmailAddrr = "";
            // Get Email Address From URL
            sEmailAddrr = gup('EmailAddrr');
            ///                              
	        var oDate = new Date();
            var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
            var curr_min = oDate.getMinutes();
            curr_min = curr_min + "";
            if (curr_min.length == 1)
                curr_min = "0" + curr_min;
            var sClientTime = "";
            var sClientDate = "";                
            sClientDate = sClientDate.concat(m_names[oDate.getMonth()],"-",oDate.getDate(),"-",oDate.getFullYear());
            sClientTime = sClientTime.concat(oDate.getHours(),":",curr_min,":",oDate.getSeconds());
	        
	        this.sStatsInfo = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
   	        this.sStatsInfo = this.sStatsInfo.concat("<OliveVariables>","<ClientDate>",encodeURIComponent(sClientDate),"</ClientDate>","<ClientTime>",encodeURIComponent(sClientTime),"</ClientTime>","<EmailAddress>",encodeURIComponent(sEmailAddrr),"</EmailAddress>","<URL>",encodeURIComponent(sURL),"</URL>","<Issue>",encodeURIComponent(this.OwcIssueDate),"</Issue>","<Section>",encodeURIComponent(this.OwcSection),"</Section>","<Publication>",encodeURIComponent(this.OwcPublication),"</Publication>","<PageLabel>",encodeURIComponent(this.OwcPageLabel),"</PageLabel>","<ComponentType>",encodeURIComponent(this.OwcEntType),"</ComponentType>","<BaseHref>",encodeURIComponent(sBaseHref),"</BaseHref>","<Action>",encodeURIComponent(Olive.ContentLogReporter.ActionName[this.OwcActivityInfo.m_sActivityType]),"</Action>","<ComponentId>",encodeURIComponent(this.OwcEntId),"</ComponentId>","<ComponentName>",encodeURIComponent(this.OwcEntName),"</ComponentName>","<PageNumber>",encodeURIComponent(this.OwcPageNo),"</PageNumber>","<PageTitle>",encodeURIComponent(this.OwcDocTitle),"</PageTitle>","<URLClick>",encodeURIComponent(this.OwcURL),"</URLClick></OliveVariables>");
            this.xmlHttp.open(this.method,this.url);
            this.xmlHttp.send(this.sStatsInfo);
               
         }
         catch(e)
         {
         }
		
		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.ContentLogReporter.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.ContentLogReporter.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.ContentLogReporter.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.ContentLogReporter.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.ContentLogReporter.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.ContentLogReporter.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.ContentLogReporter.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 OwcContentLogReporter_reportActivityData()
	{
		if (this.prepareLogData())
		{

		try
		{
			try
            {
                  try
                    {    
                        // Firefox, Opera 8.0+, Safari    
                        this.xmlHttp = new XMLHttpRequest();    
                    }
                    catch (e)
                    {    
                      // Internet Explorer    
                      try
                      {      
                        this.xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
                      }
                      catch (e)
                      {      
                          try
                          {        
                            this.xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
                          }
                          catch (e)
                          {        
                            //The browser does not support AJAX!;       
                            this.xmlHttp = null;       
                          }      
                      }
                      
                   }               

                   if(this.xmlHttp)
                   {
                    this.xmlHttp.open(this.method,this.url);
                    this.xmlHttp.send(this.sStatsInfo);
                   }
             }
             catch(e)
             {
             }
             
		}
		catch(e)
		{
			// Thou shall not interrupt application
		}
		}
	}
	
    function gup(name)
    {  
        name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
        var regexS = "[\\?&]"+name+"=([^&#]*)";  
        var regex = new RegExp( regexS );  
        var results = regex.exec(window.location.href);  
        if( results == null )    
            return "";  
        else    
            return results[1];
    } 	
	
	JScript.Type.RegisterClass("Olive.ContentLogReporter", Olive.ContentLogReporter, Olive.ContentActivityReporter);
} // Define Olive.ContentLogReporter class

if (!Olive.ContentLogReporter.ActionName)
{
	Olive.ContentLogReporter.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.ContentLogReporter.ActionName", Olive.ContentLogReporter.ActionName);
}


