﻿execOnLoad = function() {
// updateContentForNav();
 an_StartList();
// an_SetNavAndCrumbs();
// preloadImages();
// initPopups();
// Back/Forward remedy for javascript-controlled tabs. Only works for VI3 pages for now.
// if(window.location.href.match('/products/vi')) return pollHash();
}

//execNow = function() {
// updateContentForNav();
//}

window.onload=execOnLoad;

// ------------------------------------------------------------------------- \\

function updateContentForNav() {
  if (document.getElementById("secondary_navigation")) {
    var cw = document.getElementById("content-wrapper");
    if(cw && cw.style) {
        cw.style.marginRight = "200px";
        if (!cw.attributes["id"].value) { cw.style.width = "100%"; } /* IE 5.5 needs this also */
    };
  }
}

function an_StartList() {
  if (document.all&&document.getElementById && !window.opera) {
    navRoot = document.getElementById("primary-navigation");
    if (navRoot) {
      for (i=0; i<navRoot.childNodes.length; i++) {
           node1 = navRoot.childNodes[i];
           if (node1.nodeName=="UL") {
          for (j=0; j<node1.childNodes.length; j++) {
            node2 = node1.childNodes[j];
            if (node2.nodeName=="LI") {
              node2.onmouseover=function() {
                this.className+=" over";
              }
              node2.onmouseout=function() {
                this.className=this.className.replace(" over", "");
              }
    } } } } }
    navRoot = document.getElementById("sites");
    if (navRoot) {
      for (i=0; i<navRoot.childNodes.length; i++) {
        node = navRoot.childNodes[i];
        if (node.attributes["class"].value) { cls = node.attributes["class"].value; } /* IE 6 */
        else { cls = node.attributes["class"]+""; /* IE 5.5 */ }
        if (cls.indexOf("expand") >= 0) {
          if (node.nodeName=="LI") {
            node.onmouseover=function() {
              this.className+=" over";
            }
            node.onmouseout=function() {
              this.className=this.className.replace(" over", "");
            }
    } } } }
    cls = "";
    navRoot = document.getElementById("site-tools");
    if (navRoot) {
      for (i=0; i<navRoot.childNodes.length; i++) {
           node1 = navRoot.childNodes[i];
           if (node1.nodeName=="UL") {
          for (j=0; j<node1.childNodes.length; j++) {
            node2 = node1.childNodes[j];
            if (node2.attributes["class"].value) { cls = node2.attributes["class"].value; /* IE 6 */ }
            else { cls = node2.attributes["class"]+""; /* IE 5.5 */ }
            if (cls.indexOf("expand") >= 0) {
            if (node2.nodeName=="LI") {
              node2.onmouseover=function() {
                this.className+=" over";
              }
              node2.onmouseout=function() {
                this.className=this.className.replace(" over", "");
              }
    } } } } } }
} }


function an_IE_GetAttribute(tag,attribute,removeOnlyIfTwo) {
  attribute = attribute.toLowerCase();
  // Find the first instance of the attribute.
  var startOfClass = tag.toLowerCase().indexOf(attribute);
  if (startOfClass == -1) { return tag; /* probably need some kind of timeout event or something because IE sucks */ }
  // Make sure there is another class assigned
  if (startOfClass != tag.toLowerCase().lastIndexOf(attribute) || !removeOnlyIfTwo) {
    // Find the first space after the first class
    var lengthOfClass = tag.substring(startOfClass).indexOf(" ");
    // The string to remove is from 'class' up to the next space
    var classString = tag.substr(startOfClass,lengthOfClass)+" ";
    tag = an_StringReplace(tag,classString,"");
  }
  return tag;
}

var promotion_index = 0;
function an_Promotions(step) {
 var promotions = document.getElementById("promotions-content");
 if (promotions && promotions.childNodes) {

  var len = 0; // number of LI child nodes -- Opera, Mozilla consider blank space as a text node
  for (var i = 0; i < promotions.childNodes.length; i++) { if (promotions.childNodes[i].nodeName == "LI") len++; }
  if (len == 1) return;

  var new_index = promotion_index + step;
  if (new_index < 0) new_index = len-1;
  if (new_index >= len) new_index = 0;

  var c = 0;
  for (i = 0; i < promotions.childNodes.length; i++) {
   if(promotions.childNodes[i].nodeName == "LI") {
    if (promotion_index == c) { promotions.childNodes[i].style.display = "none"; }
    if (new_index == c) { promotions.childNodes[i].style.display = "block"; }
    c++;
   }
  }
  promotion_index = new_index;
 }
}

function an_StringReplace(str, match, replace) {
  // This function takes a three string arguments.
  //  str - the string to work on
  //  match - a sub string of str to replace with:
  //  replace - text to replace 'match' with
  str=str+""; // This was needed to make sure str is considered a string.
  var a=str.indexOf(match);
  if (a >= 0) { str = str.substring(0,a) + replace + str.substring(a+match.length); }
  return str;
}

// -----------------------------------------------------------------------------
// The following function cycles through the main nav HTML and highlights the
// appropriate top-level section.
// It also assembles and generates the page breadcrumbs based on values in the
// main nav.
function an_SetNavAndCrumbs() {
  var crumb = document.getElementById("breadcrumbs");
  if (crumb) {
    // If there are no list-item descendants, continue...
    if (crumb.getElementsByTagName('li').length == 0) {

        var breadcrumbs = ["Home", "/"];

        var loc = document.location+"";

        loc = loc.replace("://", "");
        loc = loc.substring(loc.indexOf("/"));

        var navroot = document.getElementById("primary-navigation");
        if (navroot) var c = an_GetChildrenOfType(navroot, "ul");

        if(c.defined) {
          c = an_GetChildrenOfType(c[0],"li");
            for (var i = 0; i < c.length; i++) {
            // For every <li> child, we must test it's the href value of it's <a> child:
            var li = c[i];
            var a = an_GetChildrenOfType(li,"a")[0]; // first anchor child of current LI

            // NOTE: 'href' Refers to the href values taken from the primary nav, while 'loc' refers to the document location.
            var href = (a+"").replace("//","");
            href = href.substring(href.indexOf("/"));

            if (loc.indexOf(href) == 0) {
                // At this point, we've found the top-level section this page belongs to
                // Store the breadcrumb information:
                breadcrumbs[breadcrumbs.length] = a.firstChild.data;
                breadcrumbs[breadcrumbs.length] = href;

                // Set the proper section active:
                an_SetAttribute(li, "class", "active");

                // Now, we prepare to visit the second-level elements:
                var d = an_GetChildrenOfType(li, "div")[0];
                var ul = an_GetChildrenOfType(d, "ul")[0];
                c = an_GetChildrenOfType(ul,"li");


                for (var j = 0; j < c.length; j++) {
                    var li = c[j];
                    var a = an_GetChildrenOfType(li,"a")[0];
                    var href = (a+"").replace("///","").replace("//","");

                    href = href.substring(href.indexOf("/"));

                    if (
                      (loc.indexOf(href) >= 0) &&                                // If href (URL from nav) matches document location
                      (href != breadcrumbs[breadcrumbs.length-1]) &&             // and href does not match previously breadcrumb URL 
                      !(                                                         // BUT NOT
                       (loc == href) ||                                          // if href and document location match
                       (loc.indexOf(href+'index.') >= 0) ||                      // or location refers to and href+index file
                       ((loc.lastIndexOf("/") == loc.length-1) && (loc == href)) // or href refers to a directory and loc == href (excludes subdirectories)
                      )
                    ) {
                        // At this point, we've found the next level element
                        // Store the breadcrumb information:
                        breadcrumbs[breadcrumbs.length] = a.firstChild.data;
                        breadcrumbs[breadcrumbs.length] = href;
                        break;
                    }
                }
                break;
            }
          }
        }

//      Remove any default breadcrumbs
//      crumb.innerHTML = "";

      // Loop through our breadcrumbs array
        for (var i = 0; i < breadcrumbs.length; i+=2) {
        // Create our text node
        var text = document.createTextNode(breadcrumbs[i]);

        // Create the anchor tag
        var a = document.createElement('a');
        an_SetAttribute(a, "href", breadcrumbs[i+1]);

        // Create the LI tag
        var li = document.createElement('li');

        // Finally, assemble everything and add it to the page.
        a.appendChild(text);
        li.appendChild(a);
        crumb.appendChild(li);
      }

      // If loc does not match the previously stored breadcrumb URL
      if (loc != breadcrumbs[breadcrumbs.length-1]) {
        // Set breadcrumb overrides for specific sections, and any exceptions
        // The format is an array of overides.
        // The overides consist of either:
        //  - a single directory sting, or
        //  - an array consisting a directory string and any exceptions within that directory.
        // Exceptions consist of either:
        //  - a string or regular expression pattern
        //  - an array of strings or regular expressions.

        // var breadcrumbOverride = new Array(
        //    new Array("/news/press/", "/index.html"),
        //    new Array("/news/releases/", new Array("/index.html", /\/\d\d\d\d\.html/i))
        // );
        // This will override using the <title> tag breadcrumb for files in /news/press/ with the exception of the index.html
        // It will also override using the <title> tag breadcrumb for files in /news/releases/ except index.html and files matching ####.html (for example: 2004.html, 2005.html)
        var breadcrumbOverride = new Array(
            new Array("/news/press/", new Array("/index.html", /\/\d\d\d\d\.html/i)),
            new Array("/news/releases/", new Array("/index.html", /\/\d\d\d\d\.html/i))
        );

        // Assign 'Type' properties to Array and String objects
        Array.prototype.Type="Array";
        String.prototype.Type="String";


        var proceed = true;
        for (var i = 0; i < breadcrumbOverride.length; i++) {
            // In case of a non-array element, we convert it to a 1-dimensional array
            if (breadcrumbOverride[i].Type != "Array") { breadcrumbOverride[i] = new Array(breadcrumbOverride[i]); }

            if (loc.match(breadcrumbOverride[i][0])) {
                // We're in an override section, so we set 'proceed' to false.
                proceed = false;

                // However, it is now necessary to check for exceptions to the override
                if (breadcrumbOverride[i][1]) {
                    for (var j = 0; j < breadcrumbOverride[i][1].length; j++) {
                        // In case of a non-array element, we convert it to a 1-dimensional array
                        if (breadcrumbOverride[i][1].Type != "Array") { breadcrumbOverride[i][1] = new Array(breadcrumbOverride[i][1]); }

                        // In the case of an index file, we also add a condition to match on an ending slash, not just 'index.html'
                        if ((breadcrumbOverride[i][1][j]+"").match(/index\./)) { breadcrumbOverride[i][1][breadcrumbOverride[i][1].length] = /\/$/; }

                        // Check for an exception case and update 'proceed' if found
                        if (loc.match(breadcrumbOverride[i][1][j])) { proceed = true; break; }
                    }
                }
            }
        }


          if (proceed) {
            // For the final crumb, we get the value from the <title> tag.
            var text_content = document.getElementsByTagName('title')[0].innerHTML;
            // Create the final LI node, and add it to the document.
            var text = document.createTextNode(text_content);
            var li = document.createElement('li');
            li.appendChild(text);
            crumb.appendChild(li);
        }
      }
    }
  }
}

function an_GetChildrenOfType(n,t) {
    // This function returns an array of child nodes of type 't'
    var a = [];
    var c = 0;
    // Cycle through all child nodes:
    for (var i = 0; i < n.childNodes.length; i++) {
        if (n.childNodes[i].nodeName.toLowerCase() == t.toLowerCase()) {
            a[c] = n.childNodes[i];
            c++;
        }
    }
    a.length=c;
    a.defined=true;
    return a;
}

function an_SetAttribute(node,att,val) {
    var current = "";
    if (node.attributes[att]) {
        current = node.attributes[att].nodeValue;
        val = current ? current + " " + val : val;
        node.attributes[att].nodeValue = val;
    } else {
        node.setAttribute(att,val);
    }
        
}

//-----------------------------------------------------------------------------
// toggleRegion
//  This function cycles through a series of HTML tags (img, div, etc) and sets
//  all the visibility of all but one to hidden. The other is made visible.
//  It takes two or more arguments:
//   1  - The tag number to make visible.
//   2+ - The tag ID, minus it's sequence number: 'image' in the case of
//       'image0', 'image1', 'image2', etc...
//  By convention, 0 is the default ID. Initial states of the tags must
//   be defined elsewhere.
function toggleRegion(which, region) {
    // Cycle through arguments, and apply the appropriate rollover status
    for (var a = 1; a < arguments.length; a++) {
        var i = 1;
        var x = document.getElementById(arguments[a]+i);

        // Cycle through all rollover tag (starting at 1, ending at the first sequentially non-existant element)
        while (x) {
            // Set all images hidden, except 'which'
            if (which != i) { x.style.visibility="hidden"; }
            x = document.getElementById(arguments[a]+(++i));
        }

        // Make the selected tag visible
        x = document.getElementById(arguments[a]+which);
        if (x) {
            x.style.visibility="visible";
        } else {
            x = document.getElementById(arguments[a]+0);
            if (x) x.style.visibility="visible";
        }
    }
}
//------------------------------------------------------------------------------


function newImage(arg) {
    if (document.images) {
        rslt = new Image();
        rslt.src = arg;
        return rslt;
    }
}

function changeImages() {
    if (document.images && (preloadFlag == true)) {
        for (var i=0; i<changeImages.arguments.length; i+=2) {
            document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
        }
    }
}

var preloadFlag = false;
function preloadImages() {
    if (document.images) {
        button1_over = newImage("../img/home_solutions_button1-over.gif");
        button2_over = newImage("../img/home_solutions_button2-over.gif");
        button3_over = newImage("../img/home_solutions_button3-over.gif");
        preloadFlag = true;
    }
}

var productTarget = "_top";
function productThere(){
if(!document.productForm.productMenu.selectedIndex==""){
window.open(document.productForm.productMenu.options[document.productForm.productMenu.selectedIndex].value,productTarget,"");
    }
}

var demoTarget = "_blank";
function demoThere(){
if(!document.demoForm.demoMenu.selectedIndex==""){
window.open(document.demoForm.demoMenu.options[document.demoForm.demoMenu.selectedIndex].value,demoTarget,"");
    }
}

// ----------------------------------------------------------------------------
// Sets onclick events for anchors having the class 'popupLink'
//  Assigns a ?referer to popupLinks with a target value of "wForm"
initPopups = function() {
  var x = new Array()
  x[0] = document.getElementById('toolbox');

  var list = new Array();
  var c = 0;
  // Collect all <a/> tags within the areas defined in 'x'
  for (var i = 0; i < x.length; i++) {
   if (x[i]) {
    var y = x[i].getElementsByTagName('a');
 for (var j = 0; j < y.length; j++) {
  list[c] = y[j];
  c++;
 }
   } 
  }

  // Set default values
  var width = 800; var height = 600; var scroll = 1; var resize = 1; var status = 1;
  if (list.length > 0) {
    for (var i=0; i < list.length; i++) {
    if (list[i].className == "popupLink") {
    if (!list[i].onclick) { // Make sure not to overwrite an existing onclick event
       list[i].onclick = function() {
      var wHref = this.href;
      var wName = this.target;
      if (wName=="_blank" || wName=="") { wName = "default"; }
      if (wName=="wForm") { wHref += "?referer=" + window.location; width = 640; height = 480; scroll = 0; status = 0; }
      popup(wHref, wName, width, height, scroll, resize, status);
      return false;
} } }   }  }   }

// General popup window function
function popup(URL,name,w,h,scroll, resize, status, buttons) {
  var featureStr = "";
  if (scroll) { scroll = 'yes'; } else { scroll = 'no'; }
  if (resize) { resize = 'yes'; } else { resize = 'no'; }
  if (status) { status = 'yes'; } else { status = 'no'; }
  if (!buttons) { buttons = 'no'; } else { buttons = 'yes'; } // This includes location bar, menubar and toolbar
  featureStr = "width=" + w + ",height=" + h + ",directories=no,location=" + buttons + ",menubar=" + buttons + ",resizable=" + resize + ",scrollbars=" + scroll + ",status=" + status + ",toolbar=" + buttons
  var newWin = window.open(URL,name,featureStr);
  newWin.focus(); // Bring window to focus (in case of updating an existing window)
}

// hompage product flip
var delay = 10; //delay in seconds
var promotion_index = 0;
var timerID = setTimeout("flipPromotions()",delay*1000);

function flipPromotions()
{
   an_Promotions(1);
   clearTimeout(timerID);
   timerID = setTimeout("flipPromotions()",delay*1000);
}
 
function flipPromotionsBack() 
{
   an_Promotions(-1);
   clearTimeout(timerID);
   timerID = setTimeout("flipPromotions()",delay*1000); 
   //after going back one, resume flipping 
   //forward after next timeout
}

// Year Script
function printYear() {
  var time=new Date();
  var year=time.getYear();
  if (year < 2000)
    year = year + 1900; 
    document.write(year);
}

// Spam-proof email by deanq.com
function vmemail(who,subject,domain,body) {
  if (!domain) var domain = "vmware.com";
  if (!subject) var subject = " ";
  if (!body) var body = " ";
  eval("location.href='mailto:" + who + "@" + domain + "?subject=" + subject + "&body=" + body + "'");
}

/////////////////////////////////////////////
// Dynamic Tabs controller used in VI3 pages
//

function showLayer(lyr) {
//   makeHistory(lyr);
   document.getElementById(currentLayer).className = 'hide';
   document.getElementById(lyr).className = 'show';
   currentLayer = lyr;
//   showTab(lyr.replace("tab","t_"));
}

function showTab(lyr) {
   document.getElementById(currentTab).className = 'taboff';
   document.getElementById(lyr).className = 'tabon';
   currentTab = lyr;
}

//function makeHistory(newHash) {
//  window.location.hash = "_" + newHash;
//  expectedHash = window.location.hash;
//  return true;
//}

//function handleHistory() {
//  if ( window.location.hash != expectedHash ) {
//    expectedHash = window.location.hash;
//    if (expectedHash.match('tab')) showLayer(expectedHash.substring(2));
//  }
//  return true;
//}

//function pollHash() {
//  handleHistory();
//  window.setInterval("handleHistory()", 200);
//  return true;
//}
////////// END Dynamic Tabs /////////

// HBX tracking
var _hbEC=0,_hbE=new Array;function _hbEvent(a,b){b=_hbE[_hbEC++]=new Object();b._N=a;b._C=0;return b;}
var hbx=_hbEvent("pv");hbx.vpc="HBX0100u";hbx.gn="ehg-vmware.hitbox.com";
hbx.acct="DM5610044DEF96EN3;DM550929D5BC96EN3";//VMware;Rollup
hbx.pn="PUT+PAGE+NAME+HERE";
hbx.mlc="CONTENT+CATEGORY";
hbx.pndef="index.html";
hbx.ctdef="full";
hbx.fv="";
hbx.lt="auto";
hbx.dlf=".exe,.zip,.rpm,.gz,.iso,.tgz,.xls";
hbx.dft="n";
hbx.elf="n";
hbx.seg="";
hbx.fnl="";
