/**
 * home.metrics.js
 * $Revision: 1.4 $
 *
 * visual sciences for Global homepage only
 *
 * depends upon: jQuery
 *
 * (c) 1992-2008 Cisco Systems, Inc. All rights reserved.
 */

/* - param set for lc.js - */
var vs_pt = true;

/**
 *  lc.js
   *     uses image request not http_request
   *
   *  Revision: 1.5
 */

/*---------------------------------------------------------------------------------------------------*/
var vs_imgArr=new Array(),vs_hif=-1;
for(var i=0;i<10;i++){
	vs_imgArr[i]=new Image();
}
function vs_Q(a){
	vs_hif++;
	if(vs_hif>10){
		vs_hif=0;
	}
	vs_imgArr[vs_hif]="";
	vs_imgArr[vs_hif]=new Image();
	vs_imgArr[vs_hif].src=a;
}
/*---------------------------------------------------------------------------------------------------*/

//var vs_getdomain = ""; //for root-relative url
var vs_getdomain="http://www.cisco.com"; // example for absolute url
var vs_filename = vs_getdomain + "/swa/j/zag2_vs_log1.asc?Log=1";


function vs_makeImg(link) {
  //var method = "POST";
  var method = "GET";

  var lsrc = "&link=" + escape(link.src);
  var lname = unescape(link.name);
  var ltext = "&linktext=" + escape(link.alt);
  var dref = "&title=" + document.title;
  var dlink = "&basepage=" + window.location.href;
  var etype = "&eventtype=" + "impression";
  var cb = "&cb=" + (new Date()).getTime();
  var reqUrl = vs_filename + lsrc + lname + ltext + dref + dlink + etype + cb;
  vs_Q(reqUrl);

  return true;
}

function vs_makeExit(link) {
  return function() {
    //var method = "POST";
    var method = "GET";

    var lhref = "&link=" + escape(link.href);
    var lname = unescape(link.name);
    var theText = jQuery(link).text() || jQuery(link).children('img').attr('alt');
    var ltext = "&linktext=" + theText;
    var dref = "&title=" + document.title;
    var dlink = "&basepage=" + window.location.href;
    var etype = "&eventtype=" + "click";
    var cb = "&cb=" + (new Date()).getTime();
    var reqUrl = vs_filename + lhref + lname + ltext + dref + dlink + etype + cb;
    vs_Q(reqUrl);

    return true;
  }
}

function vs_makeSubmit(link) {
  //var method = "POST";
  var method = "GET";

  var lname = "&link=" + escape(link.action);
  var lname = "&linktext=" + escape(link.name);
  var dref = "&title=" + document.title;
  var dlink = "&basepage=" + window.location.href;
  var etype = "&eventtype=" + "click";
  var cb = "&cb=" + (new Date()).getTime();
  var reqUrl = vs_filename + lname + dref + dlink + etype + cb;
  vs_Q(reqUrl);

  return true;
}
function vs_pageTag() {
  //var method = "POST";
  var method = "GET";

  var dref = "&title=" + document.title;
  var dlink = "&basepage=" + window.location.href;
  var etype = "&eventtype=" + "pageview";
  var cb = "&cb=" + (new Date()).getTime();
  var local_vars = "";
  if (typeof vs_vars != "undefined") {
    if (vs_vars) {
      local_vars = "&" + vs_vars;
    }
  }
  var reqUrl = vs_filename + dref + dlink + local_vars + etype + cb;
  vs_Q(reqUrl);

  return true;
}

jQuery(document).ready(function() {
  if (typeof vs_pt != "undefined") {
    if (vs_pt) {
      vs_pageTag();
    }
  }
  // Get all of the a tags
  var o = document.getElementsByTagName("a");
  // Loop through all of the links
  for (i = 0; i < o.length; i++) {
    // Grab the rel attribute values
    if (anchs = o[i].getAttribute("rel")) {
      // If there is more than one value of rel, we need to split it
      var rels = anchs.split(" ");
      // Loop through all of the values of the rel attribute
      for (j = 0; j < rels.length; j++) {
        // If we found an exit link
        if (rels[j] == "exit") {
          // Make a new function to attach to the link
          exitLinkFunction = vs_makeExit(o[i]);
          // Attach the function to the onclick event of the link we found.
          o[i].onmousedown = exitLinkFunction;
        }
      }
    }
  }

  // Get all of the area tags
  var p = document.getElementsByTagName("area");
  // Loop through all of the links
  for (i = 0; i < p.length; i++) {
    // Grab the rel attribute values
    if (anchs = p[i].getAttribute("rel")) {
      // If there is more than one value of rel, we need to split it
      var arearels = anchs.split(" ");
      // Loop through all of the values of the rel attribute
      for (j = 0; j < arearels.length; j++) {
        // If we found an exit link
        if (arearels[j] == "exit") {
          // Make a new function to attach to the link
          exitLinkFunction = vs_makeExit(p[i]);
          // Attach the function to the onclick event of the link we found.
          p[i].onclick = exitLinkFunction;
        }
      }
    }
  }
});

