//Toggles the visibility of an object
function toggleVisibility(mode, objID, parentID){
	//mode 0 - hide
	//mode 1 - display

	if(mode==0){
		if(client.ie || client.ns6){
			if(client.ie4){
				var element = eval("document.all." + objID);
				element.style.visibility='hidden';
			} else {
				document.getElementById(objID).style.visibility='hidden';
			}
		} else if(client.ns4){
			document[parentID].document[objID].visibility='hidden';
		}
	} else if(mode==1){
		if(client.ie || client.ns6){
			if(client.ie4){
				var element = eval("document.all." + objID);
				element.style.visibility='visible';
			} else {
				document.getElementById(objID).style.visibility='visible';
			}			
		} else if(client.ns4){
			document[parentID].document[objID].visibility='show';
		}	
	}
}

function _imgSwap(nav, mode){
	imgSrc = imgRoot + nav + '_' + mode + '.gif';
	imgSwap(nav, imgSrc);
}

//Swaps out an image for an img element
function imgSwap(objID, src, parentID){
	if((client.ns4) && (parentID!=null)){
		document[parentID].document.images[objID].src = src;	
	} else {
		document.images[objID].src = src;		
	}
}

//Swaps out the inner HTML for a DIV Layer
function swapHTML(element, html){
	if(!client.ns4){
		if(client.ns6){document.getElementById(element).innerHTML = "<div></div>";}
		document.getElementById(element).innerHTML = html;
	} else {
		document[element].document.open();
		document[element].document.write(html);
		document[element].document.close();
	}
}

//Generic comparison
function compare(a, b){
	value=null;
	
	if(a==b){
		value = 0;
	} else if(a < b){
		value = -1;
	} else if(a > b){
		value = 1;
	}
	return value;
}	

//Preloads the Images
function preloadImages(images_array) {
	for(i=0; i < images_array.length; i++){
   		var an_image = new Image();
		an_image.src = images_array[i];
	}
}


function researchPop(theURL){
	gPop(theURL, 798, 569);
}

function gPopUp(url, w, h, title, features, target) {
	
	var newWin=null;
	target = target ? target : "_blank";
	//calculate the x, and y position of the popup to center it
	var left = (screen.width - w)/2;
	var top = (screen.height - h)/2;
	var settings = 'width=' + w + ',height=' + h + ',top=' + top + ',left=' + left + ', ' + features;	
	newWin = window.open(url, target, settings);
	newWin.focus();
	
}

function gPop(url, w, h){
	target = "_blank";
	features = 'resizable=yes,scrollbars=yes,toolbar=yes';
	gPopUp(url, w, h, "", features);
}
//


//loadtheCookies clarsen 2/5/2002 
//the fuction returns an associative array indexed on the name of the cookie.
//currently Cookies is the name of this associative array 

function loadtheCookies(){
	theCookies=0;
	if(!theCookies) theCookies = new Array();	
	var cookieArray = document.cookie.split(';');
	for(i=0;i<cookieArray.length;i++){
		var nameValue = cookieArray[i].split('=');
		if(nameValue[0].substring(0,1)==" ") nameValue[0] = nameValue[0].substring(1);
		theCookies[nameValue[0]]=nameValue[1];
	}
	return theCookies;		
}
Cookies = loadtheCookies();

//user clarsen 2/7/2002
//user return an object that provides info about the users login and access state  
function user(){
	this.fullAccess=Cookies['WCW_Authentication']||(Cookies['WCW_Security'] && Cookies['SecurityId'])?true:false;
	this.recognized=Cookies['wcw.recognized.user']?true:false;
	this.hasBeenToGartner=Cookies['outage113001']?true:false;
}
theUser=new user();

//gets the original domain
function redirectDomain() {
	if (document.cookie.indexOf("trackDomain") != -1) {
		// the cookie contains trackDomain...
		
		// get domain from cookie...
		start = document.cookie.indexOf("trackDomain") + 12;
		trackDomain = document.cookie.substring(start,document.cookie.length);
		stop = trackDomain.indexOf("com") + 3;
		targetDomain = trackDomain.substring(0,stop);
		
		// check to see if cookie domain is same as current domain...
		if (targetDomain != location.hostname) {
			// redirect to cookie domain if current domain is not same...
			gotoURL = "http://" + targetDomain + location.pathname;
			self.location = gotoURL;
			return;
		}
	}
}

//used for drop down menu navigation
function g_go(selectObj){
	var listValue = selectObj.options[selectObj.selectedIndex].value; 
	if(listValue != "none"){
		window.location=listValue;
	}
}


/*
	EMAIL A FRIEND Directions
	
	Parameters:
	1) 	FORM url - optional
	2) 	WIDTH - of the form - optional
	3) 	HEIGHT - of the form - optional
	4) 	TITLE - to be displayed in the email - optional
	5) 	URL - to be displayed in the email - optional
	6) 	HEADER IMAGE - absolute path to the header image width: 187px - optional
	7) 	BUTTON IMAGE - absolute path to the button image width: 187px - optional
	8) 	TEXT BLURB - absolute path to the text blurb .js file  - optional
		- see \\enablizer.gartner.com\docs\common\emailafriend\default_blurb.js for an example
	9)  EMAIL SUFFIX - absolute path to the email suffix text blurb .js file - optional	
*/

//Calls the email a friend form
function emailAFriend(formURL, w, h, title, refer, hdrImage, btnImage, txtBlurb, txtPrefixBlurb, txtSuffixBlurb){

	var baseURL = "http://security.gartner.com";
	var formURL = formURL ? baseURL + "/docs/jspdocs/" + formURL : baseURL + "/docs/jspdocs/emailafriend/emailLinkerForm.jsp";
	var w = w ? w : 192;
	var h = h ? h : 380;
	var title = title ? title : escape(document.title);
	var refer = refer ? refer : escape(document.location);
	var hdrImage = hdrImage ? hdrImage : "http://symposium.gartner.com/docs/symposium/2003/subhead_emailafriend_blue.gif";
	var btnImage = btnImage ? btnImage : "http://symposium.gartner.com/docs/symposium/2003/button_sendemail.gif";
	var txtBlurb = txtBlurb ? txtBlurb : baseURL + "/docs/common/emailafriend/default_blurb.js"; 
	var txtPrefixBlurb = txtPrefixBlurb ? txtPrefixBlurb : baseURL + "/docs/common/emailafriend/default/txtPrefixBlurb.inc";
	var txtSuffixBlurb = txtSuffixBlurb ? txtSuffixBlurb : "";
	
	var url = formURL;
	url += "?title=" + title;
	url += "&refer=" + refer;
	url += "&hdrImage=" + hdrImage;
	url += "&btnImage=" + btnImage;
	url += "&txtBlurb=" + txtBlurb;
	url += "&txtPrefixBlurb=" + txtPrefixBlurb;
		
	if(txtSuffixBlurb != ""){
		url += "&txtSuffixBlurb=" + txtSuffixBlurb;
	}
	
	
	var features = 'resizable=yes,scrollbars=no,toolbar=no';	
	gPopUp(url, w, h, "", features);
}

//Generic Random number generation
//r1 = min number, r2 = max number
function randomNumber(r1, r2) {
  if (r2 > r1) return (Math.round(Math.random()*(r2-r1))+r1);
  else return (Math.round(Math.random()*(r1-r2))+r2);
}	

function openBio(href) {
   	//gPopUp(href, 565, 450, '', 'scrollbars=yes,resizable=no', '_blank')

	analystBaseURL = '/AnalystBiography?authorId=';
   	//convert the href to a string if its not already
	href += "";
	//check if the analsytBaseURL exists in the href - if not prefix the href with it - otherwise leave it alone
	url = (href.indexOf(analystBaseURL) == -1) ? analystBaseURL+href : href;
  	
	gPopUp(url, 565, 450, '', 'scrollbars=yes,resizable=no', '_blank');
}

function alertIsDemo() {
	alert("This is a demo. To learn more about Gartner Membership Programs, email us at apmember@gartner.com");
}


// The next three functions, randomImage(), linkToDocumentation() and countDown(), are from docs/symposium/utils.js -- greg.smalley@gartner.com, 20020716
//Random image generator for background image on story pages.
function randomImage(){
	var mycontent=new Array()
	mycontent[1]='<td valign=top nowrap background=docs/symposium/bg_woman.jpg>'
	mycontent[2]='<td valign=top nowrap background=docs/symposium/bg_woman_glasses.jpg>'
	mycontent[3]='<td valign=top nowrap background=docs/symposium/bg_man.jpg>'
	
	var ry=Math.floor(Math.random()*mycontent.length)
	if (ry==0)
	ry=1
	document.write(mycontent[ry])
}

function popUp( url, width, height, target, otherFeatures, replace ) {
// url is REQUIRED; target defaults to "_blank"; otherFeatures defaults to the string below.
	
	if( url ) {
		target = target ? target : "_blank";
		var features = "";
		if( width )  features += "width=" + width + ",";
		if( height ) features += "height=" + height + ",";
		features += otherFeatures ? otherFeatures : "location=no,scrollbars=yes,status=no,toolbar=no,resizable=no";
		var newWin = window.open( url, target, features, replace );
		newWin.focus();
		return newWin;
	} else {
		return false;
	}
}
function securityTeamPopUp(theURL){
	gPop(theURL, 800, 600);
}
//researchPopUp clarsen 2/7/2002
function researchPopUp(theURL){
	//popUp(theURL, 800, 600, 'gcom', 'resizable=yes,scrollbars=yes');
	gPop(theURL, 798, 569);
}

//Calls gReplace and doc writes the output
function gReplaceStringDocWrite(origStr, searchStr, replaceStr){
	document.write(gReplace(origStr, searchStr, replaceStr));
}


//Generic Search and Replace
function gReplace(origStr, searchStr, replaceStr){
	var tempStr = "";
	var startIndex = 0;
	if(searchStr == ""){
		return origStr;
	}

	if(origStr.indexOf(searchStr) != -1){
		while((searchIndex = origStr.indexOf(searchStr, startIndex)) != -1){
			tempStr += origStr.substring(startIndex, searchIndex);
			tempStr += replaceStr;
			startIndex = searchIndex + searchStr.length;
		}
		return tempStr + origStr.substring(startIndex);
	} else {
		return origStr;
	}
}

/*
WM_setCookie(), WM_readCookie(), WM_killCookie()
A set of functions that eases the pain of using cookies.
*/

// This next little bit of code tests whether the user accepts cookies.
var WM_acceptsCookies = false;
if(document.cookie == '') {
    document.cookie = 'WM_acceptsCookies=yes'; // Try to set a cookie.
    if(document.cookie.indexOf('WM_acceptsCookies=yes') != -1) {
	WM_acceptsCookies = true; 
    }// If it succeeds, set variable
} else { // there was already a cookie
  WM_acceptsCookies = true;
}


function WM_setCookie (name, value, hours, path, domain, secure) {
    if (WM_acceptsCookies) { // Don't waste your time if the browser doesn't accept cookies.
	var not_NN2 = (navigator && navigator.appName 
		       && (navigator.appName == 'Netscape') 
		       && navigator.appVersion 
		       && (parseInt(navigator.appVersion) == 2))?false:true;

	if(hours && not_NN2) { // NN2 cannot handle Dates, so skip this part
	    if ( (typeof(hours) == 'string') && Date.parse(hours) ) { // already a Date string
		var numHours = hours;
	    } else if (typeof(hours) == 'number') { // calculate Date from number of hours
		var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
	    }
	}
	document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified.
    }
} // WM_setCookie


function WM_readCookie(name) {
    if(document.cookie == '') { // there's no cookie, so go no further
	return false; 
    } else { // there is a cookie
	var firstChar, lastChar;
	var theBigCookie = document.cookie;
	firstChar = theBigCookie.indexOf(name);	// find the start of 'name'
	var NN2Hack = firstChar + name.length;
	if((firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=')) { // if you found the cookie
	    firstChar += name.length + 1; // skip 'name' and '='
	    lastChar = theBigCookie.indexOf(';', firstChar); // Find the end of the value string (i.e. the next ';').
	    if(lastChar == -1) lastChar = theBigCookie.length;
	    return unescape(theBigCookie.substring(firstChar, lastChar));
	} else { // If there was no cookie of that name, return false.
	    return false;
	}
    }	
} // WM_readCookie

function WM_killCookie(name, path, domain) {
  var theValue = WM_readCookie(name); // We need the value to kill the cookie
  if(theValue) {
      document.cookie = name + '=' + theValue + '; expires=Fri, 13-Apr-1970 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:''); // set an already-expired cookie
  }
} // WM_killCookie