
/* tracking/mmh_omniture.js */

 /**
 * Custom functions related to omniture.  Include this javascript after omniture_s_code.js.
 * These functions are mainly used by Flex widgets.  Rails should use omniture_config() and mmh_omniture_tag().
 * JSP should use <mmh:omniture> tag.
 *
 */

// @todo change this to OOP

var OMNITURE_MMMOVE_CUSTOMIZE_TODO_LIST = "MMMove - Customize to-do list";

// private function section

function publishCustomizeToDoFormAnalysisOmnitureEvent(event) {
    s.events = event;
    void(s.t());
    s.events = "";
}

// public function section

function publishCustomizeToDoListPageOmnitureEvent() {
    s.eVar9 = OMNITURE_MMMOVE_CUSTOMIZE_TODO_LIST;
    void(s.t());
    s.eVar9 = "";
}

function publishCustomizeYourMovingToDoListPageOmnitureEvent() {
    s.eVar3 = OMNITURE_MMMOVE_CUSTOMIZE_TODO_LIST;
    void(s.t());
    s.eVar3 = "";
}

function publishCustomizeToDoListSuccessOmnitureEvent() {
    publishCustomizeToDoFormAnalysisOmnitureEvent("event6");
}

function publishCustomizeToDoListAbandonOmnitureEvent() {
    publishCustomizeToDoFormAnalysisOmnitureEvent("event7");
}

function publishCustomizeToDoListErrorOmnitureEvent() {
    publishCustomizeToDoFormAnalysisOmnitureEvent("event8");
}

function generate_handler_for_tab(section, tab, href, needDelay, need_tl) {
  return function() {
    s.prop47 = tab + " tab|" + section + " DCE";
    if(need_tl) {
      s.linkTrackVars="prop47,";
      s.tl(this,"o","DCE");
      s.linkTrackVars="";
    } else {
      void(s.t());
    }
    s.prop47=""
    if(needDelay) {
      setTimeout(function(){window.location = href}, 100);
      return false;
    }
  }
};

function append_url_parameter(url, name, value) {
  var ch = '?'
  if (url.indexOf(ch)!=-1) {
    ch='&';
  }
  var new_url = url + ch + name + "=" + escape(value);
  return new_url;
};

function observe_chatter_widgets(section) {
  $$("#chatter_items a").each(function(item) {
    item.observe("click", generate_handler_for_tab(section, "Chatter", item.href, false, true));
  });
  $$("#todo_items a").each(function(item) {
    item.onclick = generate_handler_for_tab(section, "To do", item.href, true, true);
  });
  $$("#tool_items a").each(function(item) {
    item.onclick = generate_handler_for_tab(section, "Tools", item.href, true, true);
  });
}

function observe_services_widgets(section, kewords) {
  $$("#products_items a").each(function(item) {
    item.href = append_url_parameter(item.href, "sid", "MMHX"+ section + "DCEX" + kewords)
    item.observe("click", generate_handler_for_tab(section, "Products", item.href, false, true));
  });
  $$("#services a").each(function(item) {
    item.href = append_url_parameter(item.href, "sid", "MMHX"+ section + "DCEX" + item.innerHTML)
    item.onclick = generate_handler_for_tab(section, "Services", item.href, false, true);
  });  
}

function observe_editors_pick(section, name) {
  $$("#editors_pick p.title a").each(function(item) {
    item.observe('click', function() {
        s.prop48 = "Editor's Pick: " + section + " DCE: [" + name + "]";
        void(s.t());
        s.prop48 = '';
        setTimeout(function(){window.location = href}, 100);
        return false;
      });
  });
}

function observe_question_box(section) {
  Event.observe(window, 'load', function() {
    $('ask').observe('click', function() {
      s.linkTrackVars='prop11,eVar4,';
      s.prop11 = section + " DCE: " + $('ask_a_question')['answers_qt'].getValue();
      void(s.tl(this, 'o', 'DCE'));
      s.prop11 = ''; s.linkTrackVars='';
    });
  });
}

function observe_speak_email(section) {
  Event.observe("click_to_call_phone", "click", function() {
    s.linkTrackVars='prop20,'; s.prop20= 'Speak|' + section + ' DCE' ; s.tl(this,'o','PHA');
    s.linkTrackVars=''; s.prop20='';
  });
  Event.observe("click_to_call_email", "click", function() {
    s.linkTrackVars='prop20,'; s.prop20= 'Email|' + section + ' DCE' ; s.tl(this,'o','PHA');
    s.linkTrackVars=''; s.prop20='';
  });
}

function track_article_sharing(ev) {  
  s.linktrackEvents='event21';
  s.events = 'event21';
  s.linkTrackVars='eVar7';
  s.eVar7=Event.element(ev).id + '|Article DCE';
  s.tl(this,'o','socMda');
  s.linktrackEvents='';s.events='';s.linkTrackVars='';s.eVar7='';
}
