/*
    This script do the following
    1.staff onclick event and event handler to all anchors in the page.
    2.iterates on the images and object in the page and hit on webtrends server that objects.
*/

var gDomain = "statse.webtrendslive.com";
var gDcsId = "dcsoot4nx000008yn7vvnn0pg_1k6p";
var gFpc = "WT_FPC";
var gConvert = true;

function hitlOnlyLoadedViewableResources()
{
   // get all document images
   var imagesArray = document.getElementsByTagName("img");
   for (var i = 0 ; i < imagesArray.length ; i ++ )
   {
    /*
    * hits all images in the page that satisfy the follwing conditions
    * 1.The image completely loaded this known from the complete property.
    * 2.The image have the attribute assetId which means that this image is an asset. (assetId is not standard property in HTML but it is used in 
    * UTCFS websites).
    * 3.The image that satisfy the above two conditions is not inside anchor whaich known in HTML as anchor image.
    */
      if (imagesArray[i].complete && imagesArray[i].assetId != undefined)
      {
         // hit webtrends server with image source.
         dcsMultiTrack('DCSext.image', imagesArray[i].src);
      }
   }

   // get all document objects 
   var objectsArray = document.getElementsByTagName("object");
   for (var j = 0 ; j < objectsArray.length ;
   j ++ )
   {
      // filter objects that have the property assetId to hit them on webtrends server.
      if (objectsArray[j].readyState == 4 && objectsArray[j].assetId != undefined )
      {
         dcsMultiTrack('DCSext.image', objectsArray[j].data);
      }
   }
}

function addEventToClickableResources()
{
    // get all anchors in the document
   var anchorsArray = document.getElementsByTagName('a');

    // staff onclick event and event handler in document anchors.
   for (var i = 0 ; i < anchorsArray.length ; i ++ )
   {
      /* filter anchors with linkType attribute. linkType attribute is not standard HTML but it is used to 
      *  mark anchors that points to assets on vignette.
      */
      if(anchorsArray[i].linkType == "1" || anchorsArray[i].href.lastIndexOf("Assets") != -1 )
      {
         anchorsArray[i].onclick = clickableResources;
      }
   }
}

function clickableResources()
{
   dcsMultiTrack();
}

function preparePageToAnalysis()
{
   try
   {    
      hitlOnlyLoadedViewableResources();
      addEventToClickableResources();
   }
   catch(e){
     // nothing to do in the catch block 
   }
}

function hitsIfOptionLinktoAsset(optionLink)
{
    if (optionLink.value.lastIndexOf("Assets") != -1)
        dcsMultiTrack();
  
}

onload = preparePageToAnalysis;

