/*
hide.js
(c) 1992-2005 Cisco Systems, Inc. All rights reserved. 
Terms and Conditions: http://cisco.com/en/US/swassets/sw293/sitewide_important_notices.html
*/	
document.writeln('<style>');
document.writeln('.hide-target-hidden{display:none;}');
document.writeln('.hide-noscript{display:none;}');
document.writeln('</style>');
if (typeof (cdc) == "undefined") cdc = new Object();
if (typeof (cdc.util) == "undefined") cdc.util = new Object();
cdc.util.setToHash = function(widget,val){
   var cur = cdc.util.getFromHash();
   var newHash='';
   if (widget&&val){
      cur[widget] = val;
   }
   for (widget in cur){
      newHash += widget+'~'+cur[widget]+',';
   }
   newHash = newHash.substr(0,newHash.length-1);
   newHash = '#~'+newHash;
   window.location.hash = newHash;
};
cdc.util.getFromHash = function(){
   var ret = new Object();
   var h = window.location.hash;
   if (h.indexOf("#~")<0){
      return ret;
   }
   h = h.substr(2);
   currHashArr = h.split(",");
   for (h=0; h<currHashArr.length; h++){
      var pair = new Array();
      pair = currHashArr[h].split('~');
      if (!(pair[1])){
         ret['tab']=pair[0];
      } else {
         ret[pair[0]] = pair[1];
      }
   }
   return ret;
};
function HidePair(tri, tar) {
	this.trigger = tri;
	this.target = tar;
	this.getTrigger = function() { return this.trigger; }
	this.setTriggerClass = function(newclass) { this.trigger.className = newclass; }
	this.getTarget = function() { return this.target; }
	this.setTargetClass = function(newclass) { this.target.className = newclass; }
}
function HideGroup(name) {
	this.GroupName = name;
	this.Pairs = new Array();
	this.Active = new String();
	this.getName = function() { return this.GroupName; }
	this.setName = function(str) { this.GroupName = str; }
	this.getActive = function() { return this.Active; }
	this.setActive = function(str) { this.Active = str; }
	this.addPair = function(trigger, target) { 
		newp = new HidePair(trigger, target)
		this.Pairs.push( newp ); 
	}
	this.hideAll = function() {
		for (var i=0; i < this.Pairs.length; i++) {
			this.Pairs[i].setTriggerClass(cssTriggerRoot + '-' + this.GroupName);
			if (this.Pairs[i].getTarget() && (this.Pairs[i].getTarget() != '') ) {
				this.Pairs[i].setTargetClass( cssTargetHidden );
			} else {
			}
		}
	}
}
function HideOptPair(token, value) {
	this.Token = token;
	this.Val = value;
	this.setValue = function(value) {
		this.Val = value;
	}
	this.getPair = function() {
		return this;	
	}
	this.getToken = function() { return this.Token }
	this.getValue = function() { return this.Val }
	this.toString = function() { 
		var s = new String( this.Token + ':' + this.Val );
		return s;	
	}
}
function HideGroupOptions(name) {
	// for each display group we have an array of options
	this.GroupName = name;
	this.GroupOpts = new Array();
	this.getName = function() { return this.GroupName; }
	this.getOptions = function() { return this.GroupOpts; }
	this.setOption = function(token, value) {
		found = -1;
		for (i = 0; i < this.GroupOpts.length; i++) {
			if ( this.GroupOpts[i].getToken() == token ) {
				found = i;
				this.GroupOpts[i].setValue(value);
				break;
			}
		}
		if ( found < 0 ) {
			this.GroupOpts.push( new HideOptPair(token, value) );
		}
	}
	this.getOption = function(token) {
		value = null;
		for (i = 0; i < this.GroupOpts.length; i++) {
			if ( this.GroupOpts[i].getToken() == token ) {
				value = this.GroupOpts[i].getValue();
				break;
			}
		}
		return value;
	}
	this.toString = function() {
		var s = new String();
		for (i = 0; i < this.GroupOpts.length; i++) {
			s = s.concat(this.GroupName + "=>" + this.GroupOpts[i].toString() + "\n");
		}
		return s;
	}
}
function hide_GetOptionsGroup(group) {
	// lookup the options group if it exists.
	// if it doesn't exist, create a new one, and add it to the array.
	var index = hide_LookupOptionsGroup(group);
	if (index < 0) {
		hide_Options.push( new HideGroupOptions(group) );
		outGroup = hide_Options[hide_Options.length-1];
	} else {
		outGroup = hide_Options[index];
	}
	return outGroup;
}
function hide_LookupOptionsGroup(group) {
	// find the correct group index, if it exists.
	// returns -1 on failure.
	var found = -1;
	for (var i = 0; i < hide_Options.length; i++) {
		if ( hide_Options[i].getName() == group) {
			found = i;
			break;
		}
	}
	return found;
}
function hide_GetOption(group, token) {
	// get the value for a given group, and token.
	var found = null;
	optindex = hide_LookupOptionsGroup(group);
	if (optindex >= 0) {
		found = hide_Options[optindex].getOption(token);
	}
	return found;
}
// Trigger IDs
var triggerKey = new String ('hide-id-trigger-');
var targetKey = new String ('hide-id-target-');
// CSS Strings
var cssTriggerRoot = new String ('hide-trigger');
var cssTargetShown = new String ('hide-target-shown');
var cssTargetHidden = new String ('hide-target-hidden');
// Script Variables
var hide_Groups = new Array();
var hide_Options = new Array();
function hide_DoClick(argTrigger, history, hide_active) {
	var trigger = argTrigger;
	// remove selection border from browser.
	trigger.blur();
	// determine the trigger's group and identifier (not html id.)
	var temp_sGroup = hide_ParseGroup(trigger.id, triggerKey);
	var temp_sPairID = hide_ParsePairID(trigger.id, triggerKey);
	// retrieve the group this trigger is in.
	thisGroup = hide_GetGroup(temp_sGroup);
	// hide all target's in the triggers's group (including its own target)
	thisGroup.hideAll();
	// show the clicked trigger's target.
	// if the trigger is active already, and toggle is true we 
	// do nothing, so it will revert to closed state.
	if ( (thisGroup.getActive() != trigger.id) || !hide_active ) {
		target = document.getElementById(targetKey + temp_sGroup + "-" + temp_sPairID);
		if (target) {
			target.className = cssTargetShown;
		} else {
		}
		trigger.className = cssTriggerRoot + '-' + thisGroup.getName() + '-active';
		thisGroup.setActive(trigger.id);
	} else if ( (thisGroup.getActive() == trigger.id) && hide_active) { 
		// leave the panel closed, but update the active, (and thus the history/init state.)
		thisGroup.setActive('');
	}
	if (history) {
		hide_setHash();
	}
	return false;
}
function hide_GetGroup(group) {
	var index = hide_LookupGroup(group);
	if (index < 0) {
		hide_Groups.push( new HideGroup(group) );
		outGroup = hide_Groups[hide_Groups.length-1];
	} else {
		outGroup = hide_Groups[index];
	}
	return outGroup;
}
function hide_LookupGroup(group) {
	var found;
	found = -1;
	for (var i = 0; i < hide_Groups.length; i++) {
		if ( hide_Groups[i].getName() == group) {
			found = i;
		}
	}
	return found;
}
function hide_InitActive() {
	var htriggers = cdc.util.getFromHash()['hide_v3'];
	htriggers = new String(htriggers);
	htriggers = htriggers.split("+");
	for (var i = 0; i < htriggers.length; i++) {
		if ( htriggers[i] != '' ) {
			if ( trigger = document.getElementById(htriggers[i]) ) {
				hide_DoClick(trigger, false, false);
			}	
		}
	}
}
function hide_setHash() {
	var newhash = new String();
	var active;
	for (var i = 0; i < hide_Groups.length; i++) {
		newhash = newhash.concat( "+" + hide_Groups[i].getActive() ); 
	}
	cdc.util.setToHash('hide_v3',newhash);
}
function hide_ParseGroup(id, key) {
	var info = id.substr(key.length, id.length);
	var out = info.split("-")[0];
	return out;
}
function hide_ParsePairID(id, key) {
	var info = id.substr(key.length, id.length);
	var out = info.split("-")[1];
	return out;
}
function hide_Init() {
	var nTriggers = 0;
	var nTriggerErrors = 0;
	var group;
	var index;
	// run through the anchors looking for id's like our keys
	var pageLinks = document.getElementsByTagName('a');
	var numlinks = pageLinks.length;
	for (var i = 0; i < numlinks; i++) {
		var trigger = pageLinks[i];
		var triggerID = trigger.id;
		if (triggerID.indexOf(triggerKey) != -1) {
			// found a trigger
			nTriggers++;
			// parse out it's group
			gname = hide_ParseGroup(triggerID, triggerKey);
			// get the options for the group
			var ghist = hide_GetOption(gname, 'history');
			var ghideall = hide_GetOption(gname, 'allow_hideall');
			if (ghist == null) {
				ghist = true;
			}
			if (ghideall == null) {
				ghideall = true;
			}
			// set its onclick
			trigger.onclick = new Function("{ return hide_DoClick(this, " + ghist + ", " + ghideall + "); }");
			// parse out the index/identifer of the trigger
			// hide-id-trigger-[group]-[index]
			// index can be a string.
			index = hide_ParsePairID(triggerID, triggerKey);
			// retrieve the group from the list of groups.
			Group = hide_GetGroup(gname);
			// build the corresponding target id string.
			targetID = targetKey + gname + '-' + index;
			// get the target out of the DOM
			target = document.getElementById( targetID );
			if (!target) {
				// oops
				nTriggerErrors++;
				Group.addPair(trigger, null);
			} else {
				// add the trigger/target pair to the group list.
				csstriggeractive = cssTriggerRoot + '-' + gname + '-active'
				if (trigger.className == csstriggeractive) {
					target.className = cssTargetShown;
				} else {
					trigger.className = cssTriggerRoot + '-' + gname;
					target.className = cssTargetHidden;
				}
				Group.addPair(trigger, target);
			}
		}
	}
	// build list of groups.
	s = '';
	for (i = 0; i < hide_Groups.length; i++) {
		s += "'" + hide_Groups[i].getName() + "', ";
	}
	hide_InitActive();
}
$(document).ready(hide_Init);

