// Globals
var offTimer = 0;
var activeMenu = false;
var currentSection = 'off';

var navImages = new Array(); // Image cache for navigation bar image states. 
if (document.images) {
    var navSrc = document.location.protocol + '//www.vitesse.com/images/';
    navImages["products"] = new Image();
    navImages["products"].src = navSrc  + 'nav_products.png';
    navImages["tech"] = new Image();
    navImages["tech"].src = navSrc + 'nav_tech.png';
    navImages["sales"] = new Image();
    navImages["sales"].src = navSrc + 'nav_sales.png';
    navImages["about"] = new Image();
    navImages["about"].src = navSrc + 'nav_about.png';
    navImages["investors"] = new Image();
    navImages["investors"].src = navSrc + 'nav_investors.png';
    navImages["news"] = new Image();
    navImages["news"].src = navSrc + 'nav_news.png';
    navImages["press"] = new Image();
    navImages["press"].src = navSrc + 'nav_press.png';
    navImages["careers"] = new Image();
    navImages["careers"].src = navSrc + 'nav_careers.png';
    navImages["home"] = new Image();
    navImages["home"].src = navSrc + 'nav_home.png';
    navImages["off"] = new Image();
    navImages["off"].src = navSrc + 'nav_off.png';
    navImages["current"] = new Image();
    navImages["current"].src = navSrc + 'nav_off.png';
}


// Called from the window onload event handler of every page.
function setclname() {
	dd = document.getElementById("nav");
	var elms = dd.getElementsByTagName("li");
	elms[0].className="home";
	elms[1].className="products";
	elms[2].className="sales";
	elms[3].className="about";
	elms[4].className="newsnav";
	elms[5].className="investors";
	elms[6].className="careers last";

	
	// alert(elms[0].className+" "+elms[1].className+" "+elms[2].className+" "+elms[3].className  + " "+elms[4].className + " "+elms[5].className + " "+elms[6].className);

}

function setCurrentSection() {     
   // Save the hilighted version of the navigation image on page load for this section.
   if (navImages["current"] && document.images["navimg"]) {
       navImages["current"].src = document.images["navimg"].src;
   }

   // Set a global variable to denote the current section based on
   // what page was just loaded; DOM first, hack based on URL next.
   var section = 'off';
   if (document.getElementsByTagName) {
       var elems = document.getElementsByTagName("body");
       if (elems && (elems[0].id != "")) {
           section = elems[0].id;
       }
   } 

/*
	newdesign = section + 's';
 	setclname();
	dd = document.getElementById("nav");
	var elms = dd.getElementsByTagName("li");
         for(var i = 0, maxI = elms.length; i < maxI; ++i) {
            var elm = elms[i];
	     if( elm.className == section )
		{
   		 elm.className = newdesign;
		}		
         }
*/
	
   if (section == 'off') {
       /*
        * Try and find the directory name 
        *                     0123456...
        * http://www.vitesse.com/products/index.php
        */
       var slash_index = document.location.pathname.indexOf('/', 1);
       if (slash_index != -1) {
           section = document.location.pathname.substring(1, slash_index);
       } else {
           section = document.location.hostname;
       }
   }
   currentSection = section;

   // Reset the selected search scope dropdown based on the current section.
   if (document.forms['search'] && document.forms['search'].elements['restrict']) {
       var elem = document.forms['search'].elements['restrict'];
       for (var i = 0; i < elem.length; i++) {
            if (elem[i].value == "/" + currentSection + "/") {
                elem.selectedIndex = i;
            }
       }
   }

   return true;
}

function hiliteButton(id) {
   if (document.images['navimg'] && navImages[id]) {
       document.images['navimg'].src = navImages[id].src;
   }
   return true;
}

function cancelHideMenu() {
   clearTimeout(offTimer);
   return true;
}

function initiateHideMenu() {
    offTimer = setTimeout("hideMenu()", 350);  
} 

function hideMenu() {
   hiliteButton("current");
   if (activeMenu) {
       xHide(activeMenu);
   }
   activeMenu = false;
   return true;
}

function getAreaMinX(area) {
   if (area.coords) {
       var xys = area.coords.split(",");
       var left = xys[0];
       for (var i = 0; i < xys.length; i += 2) {
            var x = parseInt(xys[i]);
            if (x < left) {
                left = x;
            } 
       }
   }
   return left;
}

function getImgMaxY(id) {
   var img;
   if (document.getElementById) {
       img = document.getElementById(id);
       if (img && img.style) {
           var offsetTrail = img;
           var offsetTop = 0;
           while (offsetTrail) {
                  offsetTop += offsetTrail.offsetTop;
                  offsetTrail = offsetTrail.offsetParent;
           } 
           return offsetTop + img.height;
       }
   }
   if (document.images) {
       img = document.images[id];
       if (img && img.y) {
           return img.y + img.height;
       }
   }
   return false;
}

function showMenu(id) {
   var menuId = id + "menu";
   cancelHideMenu();
   hideMenu();
   hiliteButton(id);
   // bigtime hack to ignore IE's that do not hide my menus.
   var ua = navigator.userAgent.toLowerCase();
   var ua_index = ua.indexOf('msie');
   if (ua_index != -1) {
       var msie = ua.substring(ua_index); 
       var ver = msie.substring(5, msie.indexOf(";"));
       if (ver < 5.1) {
           return true;
       }
   }
   // Adjust in case the horizontal position is not what we expected.
   var y = getImgMaxY('navimg');
   if (y) {
       xTop(menuId, y);
   }
   activeMenu = xShow(menuId);

   return true;
}

function parentWin(parentA) {
   if (window.opener && window.opener.focus) {
      window.opener.location.href = parentA.href;
      window.opener.focus();
      return false;
   }
   return true;
}

function makeChildWindow(url, targ) {
   var childWindow = window.open(url, targ, "status,height=600,width=550,location=yes,menubar=yes,toolbar=yes,resizable=yes,status=yes,scrollbars=yes,");
   if (childWindow) {
       childWindow.focus();
//       childWindow.opener.history.go(0); // So anchor in parent showes visited.
       return false; // fail the onclick so the anchor does not overwrite the current window.
   }

   return true; // let anchor do it's job and write to the window target.
}

function newWindow(selfLink, visitedClassName) {
   var childWindow = window.open(selfLink.href, selfLink.target, "status,height=600,width=550,location=yes,menubar=yes,toolbar=yes,resizable=yes,status=yes,scrollbars=yes,");
   if (childWindow) {
       childWindow.focus();
       var links = document.getElementsByTagName("a");
       for (var i = 0; i < links.length; i++) {
          if (links[i].href == selfLink.href) {
//             links[i].className = "partlnkvisited";
             links[i].className = visitedClassName;
          }
       }
       return false; // fail the onclick so the anchor does not overwrite the current window.
   }

   return true; // let anchor do it's job and write to the window target.
}

function check_form_fields(form) {
   for (var i = 1; i < check_form_fields.arguments.length; i++) {
        var e = check_form_fields.arguments[i];
        if (form.elements[e] && form.elements[e].value == "") {
            alert("The '" + e + "' is a required field.");
            form.elements[e].focus();
            return false;
        }
   }
   return true;
}

// For the products pages, show the list of products in a subgroup.
function subGroupCB(id) {
      var imgurl;
      if (document.getElementById) {
          var ul = document.getElementById(id);
          if (ul && ul.className == "parts") {
              var display = ul.style.display;
              if (display == "block") {
                  ul.style.display = "none";
                  ul.parentNode.style.listStyleImage = "url(/images/east_blue_triangle_bullet.png)"; 
              } else {
                  ul.style.display = "block";
                  ul.parentNode.style.listStyleImage = "url(/images/south_blue_triangle_bullet.png)"; 
              }
          }
      }
      return false;
}

function viewAll() {
   if (document.getElementsByTagName) {
       var uls = document.getElementsByTagName("ul");
       if (uls) {
           for (var i = 0; i < uls.length; i++) {
                if (uls[i] && uls[i].className == "parts") {
                   uls[i].style.display = "block";
                   uls[i].parentNode.style.listStyleImage = "url(/images/south_blue_triangle_bullet.png)";
                }
           }

           var viewanchor = document.getElementById("view");
           if (viewanchor) {
              viewanchor.style.display = "none";
           }

           var hideanchor = document.getElementById("hide");
           if (hideanchor) {
              hideanchor.style.display = "inline";
           }
       }
   }
   return true;
}

function hideAll() {
   if (document.getElementsByTagName) {
       var uls = document.getElementsByTagName("ul");
       if (uls) {
           for (var i = 0; i < uls.length; i++) {
                if (uls[i] && uls[i].className == "parts") {
                   uls[i].style.display = "none";
                   uls[i].parentNode.style.listStyleImage = "url(/images/east_blue_triangle_bullet.png)";
                }
           }

           var viewanchor = document.getElementById("view");
           if (viewanchor) {
              viewanchor.style.display = "inline";
           }

           var hideanchor = document.getElementById("hide");
           if (hideanchor) {
              hideanchor.style.display = "none";
           }
       }
   }
   return true;
}

function showHideCB(id) {
      if (document.getElementById) {
          var ul = document.getElementById(id);
          if (ul && ul.className == "hide") {
              var display = ul.style.display;
              if (display == "block") {
                  ul.style.display = "none";
              } else {
                  ul.style.display = "block";
              }
          }
      }
      return false;
}

function buttonCB(evt) {
   evt = (evt) ? evt : ((window.event) ? window.event : ((arguments.callee.caller.arguments[0]) ? arguments.callee.caller.arguments[0] : null));
   if (evt) {
       var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
       if (elem) {
           switch (evt.type) {
                   case "mouseover":
                      break;
                   case "mouseout":
                      break;
                   default:
                      break;
           }
           evt.cancelBubble = true;
       }
   }
}


/*
function assignButtonEvents() {
   var navmap = xGetElementById('navmap');
   if (navmap) {
       for (var i = 0; i < navmap.areas.length; i++) {
            navmap.areas[i].onmouseover = buttonCB;
            navmap.areas[i].onmouseout = buttonCB;
       }
   }
}
 */

function dump(obj) {
   var str = "";
   for (i in obj) {
        str += i + ": " + obj[i] + " | ";
   }
   return str;
}



// x.js
// X v3.4, Cross-Browser DHTML Library from Cross-Browser.com
// Copyright (c) 2002,2003 Michael Foster (mike@cross-browser.com)
// This library is distributed under the terms of the LGPL (gnu.org)
// $Revision: 1.32 $

// Variables:
var xVersion='3.4',xOp5or6=false,xIE4Up=false,xNN4=false,xUA=navigator.userAgent.toLowerCase();
if(window.opera){xOp5or6=(xUA.indexOf('opera 5')!=-1 || xUA.indexOf('opera/5')!=-1 || xUA.indexOf('opera 6')!=-1 || xUA.indexOf('opera/6')!=-1);}
else if(document.layers) xNN4=true;
else {xIE4Up=document.all && xUA.indexOf('msie')!=-1 && parseInt(navigator.appVersion)>=4;}

// Appearance:
function xShow(e) {
  if(!(e=xGetElementById(e))) return e;
  if(e.style && xDef(e.style.visibility)) e.style.visibility='inherit';
  else if(xDef(e.visibility)) e.visibility='show';
  return e;
}
function xHide(e) {
  if (!(e=xGetElementById(e))) { 
      return;
  }
  if (e.style && xDef(e.style.visibility)) {
      e.style.visibility='hidden';
  } else if (xDef(e.visibility)) {
      e.visibility='hide';
  }
}
function xZIndex(e,uZ) {
  if(!(e=xGetElementById(e))) return null;
  if(e.style && xDef(e.style.zIndex)) {
    if(arguments.length>1) e.style.zIndex=uZ;
    else uZ=e.style.zIndex;
  }
  else if(xDef(e.zIndex)) {
    if(arguments.length>1) e.zIndex=uZ;
    else uZ=e.zIndex;
  }
  return uZ;
}
function xColor(e,sColor) {
  if(!(e=xGetElementById(e))) return null;
  var c="";
  if(e.style && xDef(e.style.color)) {
    if(arguments.length>1) e.style.color=sColor;
    c=e.style.color;
  }
  return c;
}
function xBackground(e,sColor,sImage) {
  if(!(e=xGetElementById(e))) return null;
  var bg="";
  if(e.style) {
    if(arguments.length>1) e.style.backgroundColor=sColor;
    if(arguments.length==3) e.style.backgroundImage=(sImage && sImage!="")? "url("+sImage+")" : null;
    bg=e.style.backgroundColor;
  }
  else if(xDef(e.bgColor)) {
    if(arguments.length>1) e.bgColor=sColor;
    bg=e.bgColor;
    if(arguments.length==3) e.background.src=sImage;
  }
  return bg;
}

// Position:
function xMoveTo(e,iX,iY) {
  xLeft(e,iX);
  xTop(e,iY);
}
function xLeft(e,iX) {
  if(!(e=xGetElementById(e))) return null;
  var css=xDef(e.style);
  if (css && xDef(e.style.left) && typeof(e.style.left)=="string") {
    if(arguments.length>1) e.style.left=iX+"px";
    else {
      iX=parseInt(e.style.left);
      if(isNaN(iX)) iX=0;
    }
  }
  else if(css && xDef(e.style.pixelLeft)) {
    if(arguments.length>1) e.style.pixelLeft=iX;
    else iX=e.style.pixelLeft;
  }
  else if(xDef(e.left)) {
    if(arguments.length>1) e.left=iX;
    else iX=e.left;
  }
  return iX;
}
function xTop(e,iY) {
  if(!(e=xGetElementById(e))) return null;
  var css=xDef(e.style);
  if(css && xDef(e.style.top) && typeof(e.style.top)=="string") {
    if(arguments.length>1) e.style.top=iY+"px";
    else {
      iY=parseInt(e.style.top);
      if(isNaN(iY)) iY=0;
    }
  }
  else if(css && xDef(e.style.pixelTop)) {
    if(arguments.length>1) e.style.pixelTop=iY;
    else iY=e.style.pixelTop;
  }
  else if(xDef(e.top)) {
    if(arguments.length>1) e.top=iY;
    else iY=e.top;
  }
  return iY;
}
function xPageX(e) {
  if (!(e=xGetElementById(e))) return null;
  if (xDef(e.pageX)) return e.pageX;
  var x = 0;
  while (e) {
    if (xDef(e.offsetLeft)) x += e.offsetLeft;
    e = xParent(e);
  }
  return x;
}
function xPageY(e) {
  if (!(e=xGetElementById(e))) return null;
  if (xDef(e.pageY)) return e.pageY;
  var y = 0;
  while (e) {
    if (xDef(e.offsetTop)) y += e.offsetTop;
    e = xParent(e);
  }
  return y;
}
function xSlideTo(e,x,y,uTime) {
  if (!(e=xGetElementById(e))) return;
  if (!e.timeout) e.timeout = 25;
  e.xTarget = x; e.yTarget = y; e.slideTime = uTime; e.stop = false;
  e.yA = e.yTarget - xTop(e); e.xA = e.xTarget - xLeft(e); // A = distance
  e.B = Math.PI / (2 * e.slideTime); // B = period
  e.yD = xTop(e); e.xD = xLeft(e); // D = initial position
  var d = new Date(); e.C = d.getTime();
  if (!e.moving) xSlide(e);
}
function xSlide(e) {
  if (!(e=xGetElementById(e))) return;
  var now, s, t, newY, newX;
  now = new Date();
  t = now.getTime() - e.C;
  if (e.stop) { e.moving = false; }
  else if (t < e.slideTime) {
    setTimeout("xSlide('"+e.id+"')", e.timeout);
    s = Math.sin(e.B * t);
    newX = Math.round(e.xA * s + e.xD);
    newY = Math.round(e.yA * s + e.yD);
    xMoveTo(e, newX, newY);
    e.moving = true;
  }  
  else {
    xMoveTo(e, e.xTarget, e.yTarget);
    e.moving = false;
  }  
}

// Size:
function xResizeTo(e,uW,uH) {
  xWidth(e,uW);
  xHeight(e,uH);
}
function xWidth(e,uW) {
  if(!(e=xGetElementById(e)) || (uW && uW<0)) return null;
  uW=Math.round(uW);
  var css=xDef(e.style);
  if(css && xDef(e.style.width,e.offsetWidth) && typeof(e.style.width)=="string") {
    if(arguments.length>1) {
      e.style.width = uW + "px";
      var cssW = uW - (e.offsetWidth - uW);
      if(!isNaN(cssW) && cssW >= 0 && cssW != uW) e.style.width = cssW + "px";
    }  
    uW=e.offsetWidth;
  }
  else if(css && xDef(e.style.pixelWidth)) {
    if(arguments.length>1) e.style.pixelWidth=uW;
    uW=e.style.pixelWidth;
  }
  else if(xDef(e.clip) && xDef(e.clip.right)) {
    if(arguments.length>1) e.clip.right=uW;
    uW=e.clip.right;
  }
  return uW;
}
function xHeight(e,uH) {
  if(!(e=xGetElementById(e)) || (uH && uH<0)) return null;
  uH=Math.round(uH);
  var css=xDef(e.style);
  if(css && xDef(e.style.height,e.offsetHeight) && typeof(e.style.height)=="string") {
    if(arguments.length>1) {
      e.style.height = uH + "px";
      var cssH = uH - (e.offsetHeight - uH);
      if(!isNaN(cssH) && cssH >= 0 && cssH != uH) e.style.height = cssH + "px";
    }  
    uH=e.offsetHeight;
  }
  else if(css && xDef(e.style.pixelHeight)) {
    if(arguments.length>1) e.style.pixelHeight=uH;
    uH=e.style.pixelHeight;
  }
  else if(xDef(e.clip) && xDef(e.clip.bottom)) {
    if(arguments.length>1) e.clip.bottom=uH;
    uH=e.clip.bottom;
  }
  return uH;
}
function xClip(e,iTop,iRight,iBottom,iLeft) {
  if(!(e=xGetElementById(e))) return;
  if(e.style) {
    if (arguments.length == 5) e.style.clip="rect("+iTop+"px "+iRight+"px "+iBottom+"px "+iLeft+"px)";
    else e.style.clip="rect(0 "+parseInt(e.style.width)+"px "+parseInt(e.style.height)+"px 0)";
  }
  else if(e.clip) {
    if (arguments.length == 5) { e.clip.top=iTop; e.clip.right=iRight; e.clip.bottom=iBottom; e.clip.left=iLeft; }
    else { e.clip.top=0; e.clip.right=xWidth(e); e.clip.bottom=xHeight(e); e.clip.left=0; }
  }
}

// Event:
function xAddEventListener(e,eventType,eventListener,useCapture) {
  if(!(e=xGetElementById(e))) return;
  eventType=eventType.toLowerCase();
  if((xOp5or6 || xNN4) && e==window) {
    if(eventType=='resize') { window.xPCW=xClientWidth(); window.xPCH=xClientHeight(); window.xREL=eventListener; xResizeEvent(); return; }
    if(eventType=='scroll') { window.xPSL=xScrollLeft(); window.xPST=xScrollTop(); window.xSEL=eventListener; xScrollEvent(); return; }
  }
  var eh="e.on"+eventType+"=eventListener";
  if(e.addEventListener) e.addEventListener(eventType,eventListener,useCapture);
  else if(e.attachEvent) e.attachEvent("on"+eventType,eventListener);
  else if(e.captureEvents) {
    if(useCapture||(eventType.indexOf('mousemove')!=-1)) { e.captureEvents(eval("Event."+eventType.toUpperCase())); }
    eval(eh);
  }
  else eval(eh);
}
function xRemoveEventListener(e,eventType,eventListener,useCapture) {
  if(!(e=xGetElementById(e))) return;
  eventType=eventType.toLowerCase();
  if((xOp5or6 || xNN4) && e==window) {
    if(eventType=='resize') { window.xREL=null; return; }
    if(eventType=='scroll') { window.xSEL=null; return; }
  }
  var eh="e.on"+eventType+"=null";
  if(e.removeEventListener) e.removeEventListener(eventType,eventListener,useCapture);
  else if(e.detachEvent) e.detachEvent("on"+eventType,eventListener);
  else if(e.releaseEvents) {
    if(useCapture||(eventType.indexOf('mousemove')!=-1)) { e.releaseEvents(eval("Event."+eventType.toUpperCase())); }
    eval(eh);
  }
  else eval(eh);
}
function xEvent(evt) { // cross-browser event object prototype
  this.target = null;
  var e = evt ? evt : window.event;
  if(e) {
    if(xNN4) this.target = xLayerFromPoint(e.pageX, e.pageY);
    else if(e.target) this.target = e.target;
    else this.target = e.srcElement;
  }
}
function xResizeEvent() { // simulation for op5or6 and nn4
  setTimeout("xResizeEvent()", 250);
  var cw = xClientWidth(), ch = xClientHeight();
  if (window.xPCW != cw || window.xPCH != ch) { window.xPCW = cw; window.xPCH = ch; window.xREL(); }
}
function xScrollEvent() { // simulation for op5or6 and nn4
  setTimeout("xScrollEvent()", 250);
  var sl = xScrollLeft(), st = xScrollTop();
  if (window.xPSL != sl || window.xPST != st) { window.xPSL = sl; window.xPST = st; window.xSEL(); }
}

// Object:
function xGetElementById(e) {
  if(typeof(e)!="string") return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else if(document.layers) e=xLayer(e);
  else e=null;
  return e;
}
function xLayer(id,root) { // only for nn4
  var i,layer,found=null;
  if (!root) root=window;
  for(i=0; i<root.document.layers.length; i++) {
    layer=root.document.layers[i];
    if(layer.id==id) return layer;
    if(layer.document.layers.length) found=xLayer(id,layer);
    if(found) return found;
  }
  return null;
}
function xLayerFromPoint(x,y,root) { // only for nn4
  var i, hn=null, hz=-1, cn;
  if (!root) root = window;
  for (i=0; i < root.document.layers.length; ++i) {
    cn = root.document.layers[i];
    if (cn.visibility != "hide" && x >= cn.pageX && x <= cn.pageX + cn.clip.right && y >= cn.pageY && y <= cn.pageY + cn.clip.bottom ) {
      if (cn.zIndex > hz) { hz = cn.zIndex; hn = cn; }
    }
  }
  if (hn) {
    cn = xLayerFromPoint(x,y,hn);
    if (cn) hn = cn;
  }
  return hn;
}
function xParent(e){
  if (!(e=xGetElementById(e))) return null;
  var p=null;
  if (e.parentLayer){if (e.parentLayer!=window) p=e.parentLayer;}
  else{
    if (e.offsetParent) p=e.offsetParent;
    else if (e.parentNode) p=e.parentNode;
    else if (e.parentElement) p=e.parentElement;
  }
  return p;
}
function xDef() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=="" || typeof(arguments[i])=="undefined") return false;}
  return true;
}

// Window:
function xScrollLeft() {
  var offset=0;
  if(xDef(window.pageXOffset)) offset=window.pageXOffset;
  else if(document.documentElement && document.documentElement.scrollLeft) offset=document.documentElement.scrollLeft;
  else if(document.body && xDef(document.body.scrollLeft)) offset=document.body.scrollLeft;
  return offset;
}
function xScrollTop() {
  var offset=0;
  if(xDef(window.pageYOffset)) offset=window.pageYOffset;
  else if(document.documentElement && document.documentElement.scrollTop) offset=document.documentElement.scrollTop;
  else if(document.body && xDef(document.body.scrollTop)) offset=document.body.scrollTop;
  return offset;
}
function xClientWidth() {
  var w=0;
  if(xOp5or6) w=window.innerWidth;
  else if(xIE4Up && document.documentElement && document.documentElement.clientWidth)
    w=document.documentElement.clientWidth;
  else if(document.body && document.body.clientWidth)
    w=document.body.clientWidth;
  else if(xDef(window.innerWidth,window.innerHeight,document.height)) {
    w=window.innerWidth;
    if(document.height>window.innerHeight) { w-=16; }
  }
  return w;
}
function xClientHeight() {
  var h=0;
  if(xOp5or6) h=window.innerHeight;
  else if(xIE4Up && document.documentElement && document.documentElement.clientHeight)
    h=document.documentElement.clientHeight;
  else if(document.body && document.body.clientHeight)
    h=document.body.clientHeight;
  else if(xDef(window.innerWidth,window.innerHeight,document.width)) {
    h=window.innerHeight;
    if(document.width>window.innerWidth) h-=16;
  }
  return h;
}

// end x.js


function myLeftTrim ( strInput )
{
   var strOutput = "";
   var strSpace = " " + "\t" + "\n" + "\r" + "\0" + "\x0B";

   if (strInput.length > 0 )
   {
      count = 0
      while ( strSpace.indexOf(strInput.charAt(count)) != -1 && (count < strInput.length ))
      {
         count ++;
      }

      if (count < strInput.length )
      {
         strOutput = strInput.substr ( count, strInput.length - count )
      }
   }
   return strOutput;
}

function myRightTrim ( strInput )
{
   var strOutput = "";
   var strSpace = " " + "\t" + "\n" + "\r" + "\0" + "\x0B";

   if (strInput.length > 0 )
   {
      count = strInput.length -1
      while ( strSpace.indexOf(strInput.charAt(count)) != -1 && (count >= 0 ))
      {
         count --;
      }

      if (count >= 0 )
      {
         strOutput = strInput.substr ( 0, count+1 )
      }
   }
   return strOutput;
}


function myTrim ( strInput )
{
   var strOutput = "";
   var strLeftOut = "";

   strLeftOut = myLeftTrim ( strInput );
   strOutput = myRightTrim ( strLeftOut );

   return strOutput;
}


function checkEmpty ( fieldName, strDscip) {
   if (fieldName) {
      var isempty = false;
      var evalue;

      // For text-related form elements, trim the white spaces,
      // then check if the value of this element is empty.
      var etagName = fieldName.tagName.toUpperCase();

      switch (etagName) {
         case 'TEXTAREA':
            evalue = myTrim (fieldName.value);

            if (evalue == '') {
               isempty = true;
            }
            break;
         case 'SELECT':
            evalue = fieldName.value;

            if (evalue == '') {
               isempty = true;
            }
            break;
         case 'INPUT':
            var inputtype = fieldName.type.toUpperCase();

            if ((inputtype == 'TEXT') || (inputtype == 'PASSWORD')) {
               evalue = myTrim (fieldName.value);

               if (evalue == '') {
                  isempty = true;
               }
            }

            if ((inputtype == 'CHECKBOX') || (inputtype == 'RADIO')) {
               if (!fieldName.checked) {
                  isempty = true;
               }
            }

            break;
         default:
      }

      if (isempty) {
         alert("The required field '" + strDscip + "' is empty.");
         fieldName.focus();

         return false;
      }
   }

   return true;
}


function checkEmail ( fieldName )
{
   strEmail = myTrim (fieldName.value);
   at=strEmail.indexOf("@");
   dot=strEmail.indexOf(".");
   if (at == -1 || dot == -1)
   {
      alert("This is not a valid e-mail address.");
      fieldName.select();
      fieldName.focus();
      return false;
   }
   return true;
}


function checkPwdLength ( passwdFld, strDscip, minlength)
{
   var maxlength = null;

   if (arguments.length > 3) {
      maxlength = arguments[3];
   }

   var strPwd = passwdFld.value;

   if ((strPwd.length < minlength ) || (maxlength && (strPwd.length > maxlength)))
   {
      if (maxlength) {
         alert("The " + strDscip + " field must have " + minlength + "-" + maxlength + " characters.");
      } else {
         alert("The " + strDscip + " field must have at lease " + minlength + " characters.");
      }
      passwdFld.select();
      passwdFld.focus();
      return false;
   }
   else
      return true;
}

function checkPasswd ( passwdFld, confirmFld, strDscip )
{
   strPwd = passwdFld.value;
   strCfmPwd = confirmFld.value;

   if ((strPwd.length == strCfmPwd.length) && (strPwd.indexOf(strCfmPwd) != -1))
      return true;
   else
   {
      alert("The " + strDscip + " field are not exactly the same as the Confirm " + strDscip + " field!");
      passwdFld.select();
      passwdFld.focus();
      return false;
   }
}

function checkStrEqual ( toCheckFld, confirmFld, strDscip )
{
   strToCheck = toCheckFld.value;
   strCfmFld = confirmFld.value;

   if ((strToCheck.length == strCfmFld.length) && (strToCheck.indexOf(strCfmFld) != -1))
      return true;
   else
   {
      alert("The '" + strDscip + "' field does not match the 'Confirm " + strDscip + "' field.");
      toCheckFld.select();
      toCheckFld.focus();
      return false;
   }
}

function verify_contact()
{
   var x=document.requestF;
   strAllowedChar = "()-.+ ";

   if (myLeftTrim (x.FirstName.value) == "")
   {
      alert("Not a valid first name!");
      x.FirstName.select();
      x.FirstName.focus();
      return false;
   }

   if (myLeftTrim (x.LastName.value) == "")
   {
      alert("Not a valid last name!");
      x.LastName.select();
      x.LastName.focus();
      return false;
   }

   if (myLeftTrim (x.Company.value) == "")
   {
      alert("Not a valid company name!");
      x.Company.select();
      x.Company.focus();
      return false;
   }

   if (myLeftTrim (x.Address.value) == "")
   {
      alert("Not a valid address!");
      x.Address.select();
      x.Address.focus();
      return false;
   }

   if (myLeftTrim (x.City.value) == "")
   {
      alert("Not a valid city name!");
      x.City.select();
      x.City.focus();
      return false;
   }

   if (myLeftTrim (x.State.value) == "")
   {
      alert("Not a valid state name!");
      return false;
   }

   if (myLeftTrim (x.Zip.value) == "")
   {
      alert("Not a valid zip!");
      x.Zip.select();
      x.Zip.focus();
      return false;
   }

   if (myLeftTrim (x.Country.value) == "")
   {
      alert("Not a valid country name!");
      return false;
   }

   var strPhone = x.Phone.value;
   if (myLeftTrim (strPhone) == "")
   {
      alert("Not a valid phone number!");
      x.Phone.select();
      x.Phone.focus();
      return false;
   }

   for (i = 0; i < strPhone.length; i++)
   {
      var currentChar = strPhone.charAt (i);
      if (!(currentChar >= "0" && currentChar <= "9") && strAllowedChar.indexOf( currentChar ) == -1)
      {
         alert("Not a valid phone number!");
         x.Phone.select()
         x.Phone.focus();
         return false;
      }
   }

   if (myLeftTrim (x.Email.value) == "")
   {
      alert("Not a valid e-mail!");
      x.Email.select();
      x.Email.focus();
      return false;
   }

   at=x.Email.value.indexOf("@");
   dot=x.Email.value.indexOf(".");
   if (at == -1 || dot == -1)
   {
      alert("Not a valid e-mail!");
      x.Email.select()
      x.Email.focus();
      return false;
   }

   return true;
}


function verify_apply()
{

   var x=document.apply;
   strAllowedChar = "()-.+ ";
   var currentChar = "";

   if(x.job_code.value == "---")
    {
	alert("You haven't selected any job, Choose a job from 'Career Opportunities' ");
	return false;
   }

/*   if (x.Prefix.value == "")
   {
      alert("Choose a title!");
      x.Prefix.focus();
      return false;
   }
*/
	
   if (myTrim (x.FirstName.value) == "")
   {
      alert("Not a valid first name!");
      x.FirstName.select();
      x.FirstName.focus();
      return false;
   }

   if (myTrim (x.LastName.value) == "")
   {
      alert("Not a valid last name!");
      x.LastName.select();
      x.LastName.focus();
      return false;
   }

   var strPhone = x.phone_day.value;
   if (myTrim (strPhone) != "")
   {
      for (i = 0; i < strPhone.length; i++)
      {
         currentChar = strPhone.charAt (i);
         if (!(currentChar >= "0" && currentChar <= "9") && strAllowedChar.indexOf( currentChar ) == -1)
         {
            alert("Not a valid daytime phone number!");
            x.phone_day.select()
            x.phone_day.focus();
            return false;
         }
      }
   }

   strPhone = x.phone_nite.value;
   if (myTrim (strPhone) != "")
   {
      for (i = 0; i < strPhone.length; i++)
      {
         currentChar = strPhone.charAt (i);
         if (!(currentChar >= "0" && currentChar <= "9") && strAllowedChar.indexOf( currentChar ) == -1)
         {
            alert("Not a valid evening phone number!");
            x.phone_nite.select()
            x.phone_nite.focus();
            return false;
         }
      }
   }

   if (myTrim (x.Email.value) == "")
   {
      alert("Not a valid e-mail!");
      x.Email.select();
      x.Email.focus();
      return false;
   }
   else
   {
      at=x.Email.value.indexOf("@");
      dot=x.Email.value.indexOf(".");
      if (at == -1 || dot == -1)
      {
         alert("Not a valid e-mail!");
         x.Email.select()
         x.Email.focus();
         return false;
      }
   }

   if (myTrim (x.Address.value) == "")
   {
      alert("Not a valid address!");
      x.Address.select();
      x.Address.focus();
      return false;
   }

   if (myTrim (x.City.value) == "")
   {
      alert("Not a valid city name!");
      x.City.select();
      x.City.focus();
      return false;
   }

   if (x.State.value == "")
   {
      alert("Choose a state!");
      x.State.focus();
      return false;
   }

   if (myTrim (x.Zip.value) == "")
   {
      alert("Not a valid zip!");
      x.Zip.select();
      x.Zip.focus();
      return false;
   }

   if (x.Country.value == "")
   {
      alert("Choose a country!");
      x.Country.focus();
      return false;
   }

   if (x.Source.value == "")
   {
     
      alert("How did you hear about Vitesse ?");
      x.Source.focus();
      return false;
   }
   if ( (x.Source.value == 8 || x.Source.value == 7) && myTrim(x.OtherSource.value) == "") {
      alert("Please Specify How did you hear about Vitesse ?");
      x.OtherSource.focus();
      return false;
   }
   
   if (myTrim (x.Resume.value) == "")
   {
      alert("Not a valid resume!");
      x.Resume.select();
      x.Resume.focus();
      return false;
   }

   return true;
}

function frameBuster() {
   if (parent.frames.length > 0) {
       parent.location.href = self.document.location
   }
}

function disp_other(va) {

	if ( (va == 8) || (va == 7) ) {
	  document.getElementById('other_src').style.display="block";
	}
	else {
	  document.getElementById('other_src').style.display="none";
	}	
}

// New project

function isEmptyfield ( form, fieldname, strDscip)
{
   var isempty = false;
   var formElement = form.elements[fieldname];

   if (formElement) {
      var evalue; 

      // For text-related form elements, trim the white spaces,
      // then check if the value of this element is empty.
      var etagName = formElement.tagName.toUpperCase();

      switch (etagName) {
         case 'TEXTAREA':
            evalue = myTrim (formElement.value);

            if (evalue == '') {
               isempty = true;
            }
            break;
         case 'SELECT':
            evalue = formElement.value;

            if (evalue == '') {
               isempty = true;
            }
            break;
         case 'INPUT':
            var inputtype = formElement.type.toUpperCase();

            if ((inputtype == 'TEXT') || (inputtype == 'PASSWORD')) {
               evalue = myTrim (formElement.value);

               if (evalue == '') {
                  isempty = true;
               }
            }

            if ((inputtype == 'CHECKBOX') || (inputtype == 'RADIO')) {
               if (!formElement.checked) {
                  isempty = true;
               }
            }

            break;
         default:
      }
   }

   if (isempty) {
      alert("The required field '" + strDscip + "' is empty.");
      formElement.focus();
   }
   
   return isempty;
}

function check_mul_fields_empty (form) {
   for (var i = 1; i < arguments.length; i += 2) {
      var fieldname = arguments[i];
      var description = arguments[i+1];
      if (isEmptyfield (form, fieldname, description)) {
         return false;
      }
   }
   
   return true;
}

function verify_register(form) {
   var state_elementID;

   var state_elements = document.getElementsByName('State');

   for (var i = 0; i < state_elements.length; i++) {
      if (state_elements[i].style.display == 'block') {
         state_elementID = state_elements[i].id;
      }
   }

   if (!check_mul_fields_empty(form,
                               'FirstName', 'First Name',
                               'LastName', 'Last Name',
                               'Title', 'Title',
                               'Company', 'Company',
                               'Country', 'Country',
                               'Address', 'Address',
                               'City', 'City',
                                state_elementID, 'State',
                               'Zip', 'Zip/Postal Code',
                               'Phone', 'Phone',
                               'Email', 'Email',
                               'Password', 'Password',
                               'Accept', 'Accept Vitesse User Agreement and Privacy Policy')) {
      return false;
   }

   if (!checkEmail (form.Email))
      return false;
   if (!checkStrEqual (form.Email, form.ConfirmEmail, 'Email'))
      return false;

   if (!checkPwdLength (form.Password, 'Password', 6))
      return false;
   if (!checkStrEqual (form.Password, form.ConfirmPassword, 'Password'))
      return false;

   return true;
}

function verify_update(form) {
   var state_elementID;

   var state_elements = document.getElementsByName('State');

   for (var i = 0; i < state_elements.length; i++) {
      if (state_elements[i].style.display == 'block') {
         state_elementID = state_elements[i].id;
      }
   }

   if (!check_mul_fields_empty(form,
                               'FirstName', 'First Name',
                               'LastName', 'Last Name',
                               'Title', 'Title',
                               'Country', 'Country',
                               'Address', 'Address',
                               'City', 'City',
                                state_elementID, 'State',
                               'Zip', 'Zip/Postal Code',
                               'Phone', 'Phone')) {
      return false;
   }

   if (form.NewPwd.value !== '') {
      if (!checkPwdLength (form.NewPwd, 'New Password', 6))
         return false;
      if (!checkStrEqual (form.NewPwd, form.ConfirmNewPwd, 'New Password'))
         return false;
   }

   return true;
}

// Since I put the state text field after the dropdown list,
// the action page always get state value from text field.
function changeState(textfldname, selectfldname) {
   document.getElementById(textfldname).value = document.getElementById(selectfldname).value;
   return true;
}

// This function is used to select all items in the member group
// then submit the form. The first parameter is the name of the form.
// Other parameters are the names of the member groups.
function selectAll(f) {
   if (arguments.length >=2) {
      for (j = 1; j < arguments.length; j++) {
         sobject = f.elements[arguments[j]];
         optionsNo = sobject.length;

         for (i = 0; i < optionsNo; i++) {
            sobject.options[i].selected = true;
         }
      }

      f.submit();
   }
}

// This function is used to check all checkboxes.
function check_uncheck(f, fieldname, btnname) {
   var field = f.elements[fieldname];
   if (field) {
      if (btnname == 'CheckBtn') {
         for (i = 0; i < field.length; i++) {
            field[i].checked = true;
         }
      } else {
         for (i = 0; i < field.length; i++) {
            field[i].checked = false; 
         }
      }
   }

   return true;
}
function cart_add(chk_name){

     group = document.getElementsByName(chk_name);


         for (i = 0; i < group.length; i++) {
			if (group[i].checked) {
					alert(group[i].value);
			}

		}
}
function iwebTrack() {
 var iwt_visible = "false";
 var iwt_ototal = 0;
 var iwt_invnum = 0;
 var iwt_udef01 = 0;

 if (iwt_visible == "false")
   var iwt_tm ="border='0' width='0' height='0'";
 else
   var iwt_tm ="width='11' height='11'";

 if (document.URL.indexOf('https:') == 0)
   var iwt_statsserver = "https://stats.iwebtrack.com";
 else
   var iwt_statsserver = "http://stats.iwebtrack.com";

 document.write("<img alt='IWEBTrack' "+iwt_tm+" src='" + iwt_statsserver + "/nTrack.asp?id=26089&ototal="+iwt_ototal+"&invnum="+iwt_invnum+"&udef01="+iwt_udef01+"&referer="+document.referrer.replace
 (/&/g,'!~!')+"&title="+document.title+"&sw="+screen.width+"&sh="+screen.height+"&cd="+screen.colorDepth+"'>");

}
