
function handleResize(){
  if (window.innerWidth != origWidth || window.innerHeight != origHeight) {
    location.href = location.href;
    return false;
  }
}

if (document.layers){
  origWidth = window.innerWidth;
  origHeight = window.innerHeight;
  window.captureEvents(Event.RESIZE);
  window.onresize = handleResize;
}

// Window Opening / Closing Funcitons 
function openChildWindow( appurl, windowname ) {
  var appwindow = window.open( appurl , windowname, "toolbar=yes,status=yes,top=25,left=0,outerWidth=798,outerHeight=547,width=798,height=547,scrollbars=yes,resizable=yes,menubar=yes,locationbar=no,");
  if (appwindow) appwindow.focus();
}

function global_openCdcPopup ( url, width, height ) {
  if ( isNaN(parseInt(width)) ) { width=550; } 
  else { width=parseInt(width); }
  if ( isNaN(parseInt(height)) ) {height=550; }
  else { height=parseInt(height); }
  var windowparms = "status=yes,scrollbars=yes,resizable=yes,width="+width+",height="+height;
  var popup = window.open ( url, "globalCDCpopup", windowparms);
  if (popup) popup.focus();
}

// Drop-down location.href redirection
function dropdown_redirect(select_name,reset) {
	if (reset == null) { reset = true };
	var theselect=eval(select_name);
	var tmp=theselect.selectedIndex;
	if (reset) { theselect.options[0].selected=true; }
	if(theselect.options[tmp].value != "") {
		location.href=get_baseTag()+theselect.options[tmp].value;
	}
}

// Area drop-down redirection
var areanav_current = 0;
function set_areanav_current( index ) {
	// xsl position starts at 1, array index starts at 0
	areanav_current = index-1;
}

function areanav_redirect(select_name) {	
  var theselect=eval(select_name);
  var tmp=theselect.selectedIndex;
  if(theselect.options[tmp].value != "") {
	 theselect.options[areanav_current].selected=true;
	 location.href=get_baseTag()+theselect.options[tmp].value;
  }
}

// functions used to register functions that execute on the global onClick event
var globalBodyOnClickList = new Array();

//function called to add a handler to the event
function addToBodyOnClick(funct){
    //assign the wrapper function to the event this blows away any traditionally assigned handlers
    document.onclick = bodyOnClick;
    //add the function to the array
    globalBodyOnClickList[globalBodyOnClickList.length] = funct;
}

//function that gets called by the body's onClick event
function bodyOnClick(){	
    for (var i=0;i<globalBodyOnClickList.length;i++){
        //do each of the functions in the array
        globalBodyOnClickList[i]();
    }
}


function addToWindowOnLoad(funct){
    var oldOnload = window.onload;
    //alert(oldOnload);
    if (typeof window.onload != 'function') {
    window.onload = funct;
    } else {
    window.onload = function() {
    oldOnload();
    funct();
    }
  }
}


function global_daysFutureToTimeMS (days) {
  var mydate = new Date();
  var ms;
  mydate.setTime(mydate.getTime()+((days)*24*60*60*1000));
  ms = Date.parse(mydate);
  return ms;
}

function global_setCookie(name, value, days) {
  if (days) {
    var dateobj = new Date(global_daysFutureToTimeMS (days));
    var expdate = dateobj.toGMTString();
    var expires = "; expires="+expdate;
  } else {
    var expires = "";
  }
  //alert("expires="+expires);
  document.cookie = name+"="+value+expires+"; path=/; domain=cisco.com";
}

function global_getCookie(name) {
 var CValue = new String();
  CValue = document.cookie;
  var exp = new RegExp("^.*" + name + "=" );
  if (CValue.match(exp)){
    CValue = CValue.replace(exp,'');
    CValue = CValue.replace(/;.*/,'');
    //alert(name +" is currently set to "+CValue);
    return CValue;
  }
  //alert(name+" has no value yet");
  return ""; 
}
 
function global_extractCookieChip(cookiename,parmname) {
  //alert("extracting "+parmname+" from "+cookiename);
  var CValue = unescape(global_getCookie(cookiename));
  var PValue = new String();
  var namestr = "&"+parmname+"=";
  var start = CValue.indexOf(namestr);
  if (start > -1) {
    start += namestr.length;
    PValue = CValue.substring(start,CValue.length);
    //alert(PValue+"=PValue");
    if (PValue.indexOf("&") > -1) {
      PValue = PValue.substring(0,PValue.indexOf("&"));
    }
    return PValue;
  }
  return "";
}

function global_crumbleCookieChip(cookiename, parmname) {
  /* get cookie values in array */
  var CValue = unescape(global_getCookie(cookiename));
  if ( CValue.indexOf ("&", CValue) > -1) {
    var chips = CValue.split("&");
    var newchips = new String();

    /* reassemble without parm and rewrite */
    for ( var i=0; i < chips.length; i++) {
      if ( chips[i].indexOf(parmname) != 0 ) {
        if ( newchips == "") { chips[i] = "&"+chips[i]; }
        newchips += chips[i];
      }
    } /* end stepping through array */
    global_setCookie(cookiename, newchips, 366);
  } /* if there was no '&' we did nothing */
}

function global_addCookieChip(cookiename, newname, newvalue ) {
  var CValue = global_getCookie(cookiename);
  CValue += escape("&"+newname+"="+ newvalue);
  global_setCookie (cookiename, CValue, 366);
}







function doRedirect(Burl,chance,cookieName) {
    if(!Burl) {
        return;
    }
    if (!chance) {
        chance = 2;
    }
    if (cookieName) {
        var cookie = global_getCookie(cookieName);
        if (cookie == 'b') {
            window.location.replace(Burl);
            return;
        }
        if (cookie == 'a') {
            return;
        }
    }
    var chooser = Math.ceil(Math.random()*chance);
    if (chooser == 1) {
        if (cookieName) {
             global_setCookie(cookieName, 'b');
        }
        window.location.replace(Burl);
    }
    else {
        if (cookieName){
             global_setCookie(cookieName, 'a');
        }
    }

	var chooser = Math.ceil(Math.random()*chance);
	if (chooser == 1) {
		window.location.replace(Burl)
	}
}


function debug(debugStr, str) {
	debugStr = debugStr + str + '\n';
	return debugStr;
}
function sniffDebugClear(debugStr) {
	debugStr = '';
}
function sniffDebugAlert(str, bDebug) {
	if (bDebug) {
		alert(str);
	}
} 
var sniffDebugFlag = false;
var sniffDebugStr = '';

	
// Set up some definitions.
// The following are the arrays that are compared against the appName.
var Wins = 	new Array("Win32");
var Unixes = new Array("SunOS", "HP", "Linux"); 
var Macs = 	new Array("MacPPC","Intel");
var Geckos = new Array("Netscape");


var MozillaBaseGecko = 20030329;
var MozillaBaseSafari = 85;
var Mozillas = new Array(	"Gecko/20031007",  	// Mozilla 1.5
							"Gecko/20040113",  	// Mozilla 1.6
							"Gecko/20030329", 	// Mozilla 1.3 (Sun)
							"Gecko/20030624"); 	// Netscape 7.1
var NS70s = new Array(	"Gecko/20020823", 	// Netscape 7.0		
						"Gecko/20030208", 	// Netscape 7.0.2 
						"Gecko/20020921",	// Netscape 7.0 (Sun)
						"Gecko/20020920");	// Netscape 7.0 (Sun)
var NS6s = new Array(	"Gecko/20020508", 	// Netscape 6.2.3
						"Gecko/20020314",	// Netscpae 6.2.2
						"Gecko/20011128", 	// Netscape 6.2.1
						"Gecko/20010726" );	// Netscape 6.1
var Safaris = new Array("Safari/85",
						"Safari/100");		// Safari 1.0
var IEs = new Array("Microsoft Internet Explorer");

var Browser = new Object;
// Set up some fundamentals.
Browser.name = navigator.appName;
Browser.version = navigator.appVersion;
Browser.os = navigator.platform;
Browser.useragent = navigator.userAgent;
// platform browser bools
Browser.isIE = false;
Browser.isNS70 = false;
Browser.isMozilla = false;
Browser.isNS6 = false;
Browser.isNSOld = false;
Browser.isSafari = false;

// platform bools
Browser.isUnix = false;
Browser.isWin = false;
Browser.isMac = false;
	


function sniffIsIE() { return Browser.isIE; }
function sniffIsNS6() { return Browser.isNS6; }
function sniffIsNS70() { return Browser.isNS70; }
function sniffIsMozilla() { return Browser.isMozilla; }
function sniffIsUnix() { return Browser.isUnix; }

function sniffIsUnixMozilla() {
	return (sniffIsMozilla() && sniffIsUnix());
}

function sniffIsUnix70() {
	return (sniffIsNS70() && sniffIsUnix());
}
function sniffIsWin() {	return Browser.isWin; }
function sniffIsMac() { return Browser.isMac; }
function sniffIsSafari() { return Browser.isSafari; }


function sniffIsFunctFull() {
  if (!sniffIsMac()) {
    return ( sniffIsIE() || sniffIsMozilla() );
  }
} 



var currDropdowns = new Array();
var currId =0;
var autoOpenDropTimer=0;
var closeDropTimer=0; 		//currently not using any timed auto-closing

var dropdownDontClose = false; 	//use for handling events from the document.onclick
addToBodyOnClick(dropdownDocOnClick);
//addToFlyoutToggle(dropdownCloseAll);

/* Debugging functions, setting bDebug to true will spawn an alert
 * with debugging info. */
var dropdownDebugStr = '';
/* Debugging functions, setting bDebug to true will spawn an alert
 * with debugging info. */
function debug(debugStr, str) {
	debugStr = debugStr + str + '\n';
	return debugStr;
}
function debugClear(debugStr) {
	debugStr = '';
}
function debugAlert(str, bDebug) {
	if (bDebug) {
		alert(str);
	}
} 
function EventDebug(e) {
	dropdownDebugStr = debug (dropdownDebugStr, 'Event Info:');
	dropdownDebugStr = debug (dropdownDebugStr, 'clientX: ' + e.clientX);
	dropdownDebugStr = debug (dropdownDebugStr, 'clientY: ' + e.clientY);
	dropdownDebugStr = debug (dropdownDebugStr, 'layerX: ' + e.layerX);
	dropdownDebugStr = debug (dropdownDebugStr, 'layerY: ' + e.layerY);
	dropdownDebugStr = debug (dropdownDebugStr, 'pageX: ' + e.pageX);
	dropdownDebugStr = debug (dropdownDebugStr, 'pageY: ' + e.pageY);
	dropdownDebugStr = debug (dropdownDebugStr, 'screenX: ' + e.screenX);
	dropdownDebugStr = debug (dropdownDebugStr, 'screenY: ' + e.screenY);
	dropdownDebugStr = debug (dropdownDebugStr, 'offsetX: ' + e.offsetX);
	dropdownDebugStr = debug (dropdownDebugStr, 'offsetY: ' + e.offsetY);
	dropdownDebugStr = debug (dropdownDebugStr, 'x: ' + e.x);
	dropdownDebugStr = debug (dropdownDebugStr, 'y: ' + e.y);
}

/* switches between showing & hiding */
function dropdownToggle(dropdown,id,event){
	//alert('ddtoggle' + dropdownDontClose);
	clearTimeout(autoOpenDropTimer);
	dropdownCloseAllOther(id);
	
	//prompEle = the <a> tag
	promptEle = dropdown;
	//
	dropdown = dropdown.parentNode;
	
	// Get IDs
	parentID = dropdown.id;
	childID = dropdown.id + '-list';
	arrowID = dropdown.id + '-arrow';
	dropdownDebugStr = debug(dropdownDebugStr, 'parentID: ' + parentID + ', childID:' + childID);
		
	// set up pointers.
	if (document.all) {
		ele = document.all[parentID];
		pd = document.all[childID];
		arrow = document.all[arrowID];
		// Get the window height
		winWidth = document.documentElement.clientWidth;
		winHeight = document.documentElement.clientHeight;
		// must reconstruct aboslute page location based 
		// on mouse click abs position, and relative to layer
		eleTop = event.clientY - event.offsetY;
		
	} else if (document.getElementById) {
		ele = document.getElementById(parentID);
		pd = document.getElementById(childID);
		arrow = document.getElementById(arrowID);
		// Get the window height
		winWidth = window.innerWidth;
		winHeight = window.innerHeight; 
		// must reconstruct aboslute page location based 
		// on mouse click abs position, and relative to layer
		eleTop = event.pageY - event.layerY;
		//alert(winHeight);
	}
	
	dropdownDebugStr = debug(dropdownDebugStr, 'Window Width: ' + winWidth + ',' + 'Window Height: ' + winHeight);
	dropdownDebugStr = debug(dropdownDebugStr, 'Element Top: ' + eleTop);
	
	// change the visibility of the layer.
	if (ele.className == 'collapsed'){
		ele.className = 'shown';
		currDropdowns[id] = ele;
		promptEle.className = 'dropdownInstructionOpen';
		/* HAAAACK to Fix NS 7.0 first time click bug. */
		pd.style.display = 'block';
		// hide the arrow.
		arrow.className = 'dropdownArrowHidden';
		dropdownDontClose = true;
	} else {
		//alert(pd.offsetTop);
		ele.className = 'collapsed';
		pd.style.top = '0px';
		/* HAAAACK to Fix NS 7.0 first time click bug. */
		pd.style.display = 'none';
		currDropdowns[id] = null;
		promptEle.className = 'dropdownInstruction';
		// show the arrow.
		arrow.className = 'dropdownArrow';
		dropdownDontClose = false;
	}

	// determine if we have enough space to render down.
	needHeight = (eleTop + pd.offsetHeight + ele.offsetHeight);	
	//alert(pd.offsetTop);
	dropdownDebugStr = debug(dropdownDebugStr, 'Height Req: ' + needHeight);
	//alert(eleTop);
	if (needHeight > winHeight) {
		dropdownDebugStr = debug(dropdownDebugStr, '***Render UP***');

		if(pd.offsetTop == -17)
		    newPosX = 0 - (pd.offsetHeight + ele.offsetHeight);
		else
		    newPosX = pd.offsetTop - (pd.offsetHeight + ele.offsetHeight);
		/////////////////////////////////////////////////////////
		
		pd.style.top = newPosX + 'px';
	} else {
		dropdownDebugStr = debug(dropdownDebugStr, '***Render DOWN***');
	}
	
    dropdownDebugStr = debug(dropdownDebugStr, 'parent width = ' + ele.offsetWidth + ' height = ' +  ele.offsetHeight);
    dropdownDebugStr = debug(dropdownDebugStr, 'parent pos: ' + ele.offsetLeft + ':' + ele.offsetTop);
    dropdownDebugStr = debug(dropdownDebugStr, 'parent-parent top: ' + ele.offsetParent.offsetTop);
	dropdownDebugStr = debug(dropdownDebugStr, 'flyout dim: ' + pd.offsetWidth + ':' + pd.offsetHeight);
	dropdownDebugStr = debug(dropdownDebugStr, 'flyout pos: ' + pd.offsetLeft + ":" + pd.offsetTop);
	dropdownDebugStr = debug(dropdownDebugStr, '---');
	EventDebug(event);
	debugAlert(dropdownDebugStr, false);
}



function autoCloseDropdown() {
	clearTimeout(autoOpenDropTimer);
	closeDropTimer = setTimeout("dropdownTimesOut()",1000);
	currDropdown = null;
}

function dropdownTimesOut() {
	if (currDropdown != null) {	
		currDropdown.className = 'collapsed';
	}
	else {
		//close all dhtml dropdowns
	}
}

function dropdownCloseAllOther(id) {
	for (var i=1;i<currDropdowns.length;i++) {
		if (i!=id) {
			dropdownClose(currDropdowns[i]);
			currDropdowns[i]=null;
		}	
	}
}

function dropdownClose(drop) {
	if (drop != null) {
		// change the visibility
		drop.className = 'collapsed';
		dropdownDontClose = false;

		// Get IDs
		childID = drop.id + '-list';
		arrowID = drop.id + '-arrow';
		promptID = drop.id + '-prompt';
	
		// set up pointers.
		if (document.all) {
			pd = document.all[childID];
			drop.firstChild.className = 'dropdownInstruction'; 
		} else if (document.getElementById) {
			pd = document.getElementById(childID);
			prompt = document.getElementById(promptID);
			prompt.className = 'dropdownInstruction';
		}
		// reset the layer position to relative zero.
		dropdownDebugStr = debug(dropdownDebugStr, 'AutocloseID: ' + drop.id + ', childID:' + childID);
		pd.style.top = '0px';
		/* HAAAACK to Fix NS 7.0 first time click bug. */
		pd.style.display = 'none';
		arrow.className = 'dropdownArrow';
	}
	debugAlert(dropdownDebugStr, false);
}

function dropdownCancelBubble() {
	// 	This function essentially replicates the cancel bubble functionality by preventing parent element onClicks from closing the pulldown.
	dropdownDontClose = true;
}

function dropdownDocOnClick() {
	//If someone has set the don't close me flag, just clear the flag, otherwise close the whole shibang.
	//alert('dropdownDocOnClick ' + dropdownDontClose);
	if (dropdownDontClose) {
		dropdownDontClose = false;
	} else {
		dropdownCloseAll();
	}
}

function dropdownCloseAll() {
	for (var i=1;i<currDropdowns.length;i++) {
		dropdownClose(currDropdowns[i]);
		currDropdowns[i]=null;	
	}
	dropdownDontClose = false;
}



/***************************************
controlFocus.js
****************************************/



var setLoadFocus = function() {

	try {
 		document.sitewidesearch.searchPhrase.focus();
		if (document.sitewidesearch.searchPhrase.value == '') {
			document.sidewidesearch.searchPhrase.value = 'Search';
		}
	}
 	catch(err) {
		//ignore errors here
	}
}

function setAfterFlydownFocus() { document.sitewidesearch.tabIndexControler.focus(); }
function setReverseFlydownFocus() { _popi(47); }
addToWindowOnLoad(setLoadFocus);


