// Here are the arrays that we need for the displaying the correct text and/or images.
var text = new Array();			// This is the basic show/hide text for each item
var SHtext = new Array();		// This is the show/hide text for the ShowAll link
var imgs = new Array();			// This is the images to use in show/hide if used
var UseCookies = false;         // Use a cookie to keep track of which show/hide  
                                //    blocks have been shown....

// Here are the text arrays for the basic show/hide
text["Default"] = new ShowHideText("Show","Hide");
text["PlusMinus"] = new ShowHideImages("<img src=\"Images/Plus.gif\" border=\"0\" align=\"absmiddle\" />","<img src=\"Images/Minus.gif\" border=\"0\" align=\"absmiddle\" />");

// Here are the text arrays for use with the ShowAll links
SHtext["Default"] = new ShowHideSHText("Expand All Sections","Collapse All Sections");

// Here are the image arrays for use in the basic show/hide if used
imgs["Default"] = new ShowHideImages("Images/Show_Hide_Closed_Arrow.gif","Images/Show_Hide_Open_Arrow.gif");
imgs["Arrows"] = new ShowHideImages("Images/Show_Hide_Closed_Arrow.gif","Images/Show_Hide_Open_Arrow.gif");
imgs["PlusMinus"] = new ShowHideImages("Images/Plus.gif","Images/Minus.gif");

// This is the initialization function that is run onLoad();
// Note that if an InitBlock is sent this will be block will be open regardless of the cookie settings.
function ShowHideInit(InitBlock) {
	
	if (arguments.length == 0) {
		InitBlock = '';
	}

	if ( !document.getElementById ) {
		alert("This page requires a browser that is compliant with the latest DOM in order to operate correctly.  This generally means IE 5.5+ or NS 6+");
		return;
	}
		
	var oDivs = document.body.getElementsByTagName("DIV");
	var div;
	var Link;
	var Img;
	var BlockID;
	var DefDisplay = '0';
	var onText;
	var offText;
	var onImg;
	var offImg;
	
	// First make sure everything is hidden
	for (i=0; i < oDivs.length; i++ ) {
		div = oDivs.item(i);
		
		if (div.id.indexOf("Block_") != -1) {
			// Snag the ID from div.id
			BlockID = (div.id).substring(6,(div.id).length);
			
			// Try to get the associated link and image.
			Link = document.getElementById("Link_"+BlockID);
			Img = document.getElementById("Img_"+BlockID);
			
			// Find the previous display option and set the cookie if needed.
			if (!UseCookies) {
				DefDisplay = '0';
			} else if ( Get_Cookie(div.id) ) {
				DefDisplay = Get_Cookie(div.id);
			} else {
				Set_Cookie(div.id,'0','','/','','');
				DefDisplay = '0';
			}
			
			// Now set current display to old display
			div.style.display = (DefDisplay == '0' && InitBlock != BlockID) ? "none" : "block";
			
			// Determine the correct text and image
			var DisText = GetText(BlockID);
			onText = DisText.on;
			offText = DisText.off;
			
			var DisImages = GetImages(BlockID);
			onImg = DisImages.on;
			offImg = DisImages.off;
			
			// If the link exists set the text
			if (Link != null) {
				Link.innerHTML = (DefDisplay == '0' && InitBlock != BlockID) ? onText : offText;
			}
			
			// If the image exists set the source.
			if (Img != null) {
				Img.src = (DefDisplay == '0' && InitBlock != BlockID) ? onImg : offImg;
			}
		}				
	}
	
	// In case I need to do anything with this...
	// Don't do this anymore....
	// initDHTMLAPI();
	
}

// For the basic show/hide text
function ShowHideText(on,off) {
	this.on = on;
	this.off = off;
}

// For the ShowAll link text
function ShowHideSHText(exp,col) {
	this.expand = exp;
	this.collapse = col;
}

// For the images to use with the basic show/hide if used
function ShowHideImages(on,off) {
	this.on = on;
	this.off = off;
}

// Here's the function that does the basic show/hide for a div...
//
// In order for this to work the portion that is to be shown/hidden needs to
// be enclosed in a div with an id in the form Block_XXXX
// 
// The link that is used to trigger ShowHide needs to have an id in the form
// Link_XXXX.  If there is an image to change as the show/hide state is changed
// it needs to have an id in the form Img_XXXX
//
// In all of these the XXXX needs to match for each set.
//
// In the function call id = XXXX from above and type is used to determine the
// text/image that is pulled from the initialization arrays at the top of the file.
// If type is not found in the arrays then the default text/image is used.  If you
// want to default the image to some default/common image then send this as imgtype.
//
// If only one arguement is sent then it is assumed that id = type.
//
function ShowHide(type,id, imgtype) {
	
	if (arguments.length == 1) {
		type = arguments[0];
		id = arguments[0];
		imgtype = arguments[0];
	} else if (arguments.length == 2) {
		imgtype = type;
	}
	
	if ( !document.getElementById("Block_"+id) ) {
		return;
	}
	
	// Get the Div, link and image as well as the current display state
	var objDiv = document.getElementById("Block_"+id);
	var objLink = document.getElementById("Link_"+id);
	var objImg = document.getElementById("Img_"+id);
	var currentState = objDiv.style.display;
	
	// Sometimes these don't properly intialize so...
	if (currentState == "" || currentState == null) {
		currentState = "none";	
	}
	
	var onText;
	var offText;
	var onImg;
	var offImg;
	var DefDisplay;
	
	// Set the correct link text and image source
	if (text[type]) {
		onText = text[type].on;
		offText = text[type].off;
	} else {
		onText = text["Default"].on;
		offText = text["Default"].off;
	}
	
	if (imgs[imgtype]) {
		onImg = imgs[imgtype].on;
		offImg = imgs[imgtype].off;
	} else {
		onImg = imgs["Default"].on;
		offImg = imgs["Default"].off;
	}
		
	// Change the display state and set the cookie.
	DefDisplay = (currentState == "none") ? "1" : "0";
	if (UseCookies) {
		Set_Cookie(objDiv.id,DefDisplay,'','/','','');	
	}
	objDiv.style.display = (currentState == "none") ? "block" : "none";
	
	// Set the link text
	objLink.innerHTML = (currentState == "none") ? offText : onText;
	
	// If the image exists set the source.
	if (objImg != null) {
		objImg.src = (currentState == "none") ? offImg : onImg;
	}
	
	// Are we in a solution iframe and need to force a resize?
	var CurLoc = document.location.href;
	if (CurLoc.indexOf("/Solutions/") != -1 && parent.location.href != CurLoc) {
	    //alert(parent.location.href);
	    parent.ResizeSolnFrame();
	}

}

// Here is the function for use in the ShowAll link....
//
// In the function call type is used to identify only certain show/hide blocks.
// To use this simply make sure each div/link/img following the naming convention 
// in the ShowHide() documentation all contain the string given by type.  If given,
// only those with type in their id will be switched.  
//
// Sending only one argument or a zero length string for type will ShowHide() all 
// blocks on the page.
//
// To show all blocks send action == 1.  To hide all blocks send action == 0
//
// Sending no arguments assumes that all blocks are to be shown.
//
function ShowHideAll(type, action) {
	
	if (arguments.length == 1) {
		// in this case we want everything to apply the action sent....
		action = type;
		type = "";
	} else if (arguments.length == 0) {
		type = "";
		action = 1;
	}
	
	var oDivs = document.body.getElementsByTagName("DIV");
	var div;
	var Link;
	var Img;
	var BlockID;
	var onText;
	var offText;
	var onImg;
	var offImg;
	var ExpText;
	var ColText;
	
	for (i=0; i < oDivs.length; i++ ) {
		div = oDivs.item(i);
		
		if (div.id.indexOf("Block_") != -1) {
			
			// if we're after a specific type here make sure we've got that
			if (type != "" && div.id.indexOf(type) == -1) {
				continue;	
			}
			
			// Snag the ID from div.id
			BlockID = (div.id).substring(6,(div.id).length);
			
			// Try to get the associated link and image.
			Link = document.getElementById("Link_"+BlockID);
			Img = document.getElementById("Img_"+BlockID);
			
			// Find the previous display option and set the cookie if needed.
			Set_Cookie(div.id,action,'','/','','');
			
			// Now set current display to old display
			div.style.display = (action == 0) ? "none" : "block";
			
			// Determine the correct text and image
			var DisText = GetText(BlockID);
			onText = DisText.on;
			offText = DisText.off;
			
			var DisImages = GetImages(BlockID);
			onImg = DisImages.on;
			offImg = DisImages.off;
			
			var DisSHText = GetSHText(BlockID);
			ExpText = DisSHText.expand;
			ColText = DisSHText.collapse;
				
			
			// If the link exists set the text
			if (Link != null) {
				Link.innerHTML = (action == 0) ? onText : offText;
			}
			
			// If the image exists set the source.
			if (Img != null) {
				Img.src = (action == 0) ? onImg : offImg;
			}
		}				
	}
	
	// Now take care of the the ShowHideAll link text and action....
	Link = document.getElementById("SH"+type);
	if (Link != null) {
		Link.innerHTML = (action == 0) ? ExpText : ColText;
		Link.href = "javascript:ShowHideAll('" + type + "', " + (action == 0 ? 1 : 0) + ")";
	}
	
	// Are we in a solution iframe and need to force a resize?
	var CurLoc = document.location.href;
	if (CurLoc.indexOf("/Solutions/") != -1 && parent.location.href != CurLoc) {
	    //alert(parent.location.href);
	    parent.ResizeSolnFrame();
	}

}

// This is the function that will get the text for each basic show/hide block.
function GetText(BlockID) {
	var onText;
	var offText;
	
	if (text[BlockID]) {
		onText = text[BlockID].on;
		offText = text[BlockID].off;
	} else {
		// For this case, since we only have one details "text" and many links we'll
		// need an explicit check here
		if (BlockID.indexOf("WoW") != -1) {
			onText = text["PlusMinus"].on;
			offText = text["PlusMinus"].off;
		}  else {
			onText = text["Default"].on;
			offText = text["Default"].off;
		}
	}
	
	return new ShowHideText(onText,offText);
}

// This is the function that will get the images for each basic show/hide block if used
function GetImages(BlockID) {
	var onImg;
	var offImg;
	
	if (imgs[BlockID]) {
		onImg = imgs[BlockID].on;
		offImg = imgs[BlockID].off;
	} else {
		if (BlockID.indexOf("Soln") != -1) {
			onImg = imgs["Arrows"].on;
			offImg = imgs["Arrows"].off;
		} else {
			onImg = imgs["Default"].on;
			offImg = imgs["Default"].off;
		}
	}
	
	return new ShowHideImages(onImg,offImg);
}

// This is the function that will get the text for each ShowAll link.
function GetSHText(BlockID) {
	var ExpText;
	var ColText;
	
	if (SHtext[BlockID]) {
		ExpText = SHtext[BlockID].expand;
		ColText = SHtext[BlockID].collapse;
	} else {
		if (BlockID.indexOf("Soln") != -1) {
			ExpText = SHtext["Solution"].expand;
			ColText = SHtext["Solution"].collapse
		} else if (BlockID.indexOf("Step") != -1) {
			ExpText = SHtext["Step"].expand;
			ColText = SHtext["Step"].collapse;
		} else {
			ExpText = SHtext["Default"].expand;
			ColText = SHtext["Default"].collapse;
		}
	}
	
	return new ShowHideSHText(ExpText,ColText);
}

// Here is the function that will display a basic popup.  The material to be 
// displayed in the popup should be in a div with id in the form PopUp_XXXX.  The
// area that is mousedover or clicked should be in a span/img/etc with id whose id 
// can be either S_XXXX (to have the function assume this) or some other id.  Note
// that in order for the placement of the popup to be correct this really does need
// to be found by the routine and so the id must be known.
//
// If the popup is a balloon and you want to adjust the top/side to account for
// viewing issues then you'll need to make sure there are two div's for top/bottom
// image containing the balloon tip named BalTop_XXXX and BalBot_XXXX.
//
// In the function call id == XXXX.  If the span id is not S_XXXX then the final 
// argument needs to be this id, if not there is no need to send the final arguement
// as the function will then assume S_XXXX.  Offset_Above and Offset_Below is how 
// much to offiset if displaying above/below the link.
//
// Offset_##### - These tell the function how much to offset the popup in the 
//                various directions depending upon where the popup is occuring.
//                Offset_Left is used when aligning with the left edge of calling
//                element or if we're aligning to the mouse click then it will
//                shift if aligning left edge of popup to mouse click, etc... 
//                The defaults are all zero.
// adjtop - boolean to tell the function to determine if the popup will occur 
//          outside of the viewing range and adjust accordingly.  The function
//          assumes the popup will occur above link and then will adjust to below
//          link if needed.  The default is set to true and so will adjust.
// adjside - Same thing as adjtop but for right/left.  The default is to assume
//           the popup will occur to the right and then set to left if will appear
//           out of viewing range.
// pctdel - The popup will slowly appear if that is what you want.  This determines
//          the amount that will show up each timedel.  The default is 5% of the
//          popup will show each time.  Set to 100 to have it appear completely.
// timedel - This is the time differential to use when showing the popup.
// isBalloon - A boolean variable telling the function if the popup is a balloon
//             or not as it will need to adjust accordingly if adjtop and/or
//             adjside are true.  If both of these are false then it won't matter.
//
// popW - This will set the width of the element PopUp_XXXX and if isBalloon is
//        set to true it will also set with width for BalTop_XXXX, BalHead_XXXX,
//        BalText_XXXX, and BalBot_XXXX.  Set to negative to not set width.
//
// popH - This will set the height of the element PopUp_XXXX.  Set to negative to
//        not set a width.
//
// align - Where should the popup align be default.
//         L = align to left sides of popup and calling element
//         R = align to right sides of popup and calling element
//         C = center popup over calling element
//         LR = align left edge of popup to right edge of calling element
//         RL = align right edge of popup to left edge of calling element
//         ML = align left edge of popup at mouse click
//         MR = align right edge of popup at mouse click
//         MC = aligh center of popup at mouse click
//
// horiz - Align along the top (T) or bottom (B) of the calling element.
//
// the evt argument should just be entered as event to get the mouseover/click
// event send down to this.
//
function ShowPopUp(id, evt, Offset_Above, Offset_Below, Offset_Right, Offset_Left, adjtop, adjside, pctdel, timdel, isBalloon, popW, popH, align, horiz, SpanID) {
	var initPercent;
	var leftpos;
	var rightpos;
	var toppos;
	var botpos;
	
	if ( !document.getElementById("PopUp_"+id) || arguments.length < 2 ) {
		return;
	}
	
	if (arguments.length == 2) {
	    Offset_Above = 0;
	    Offset_Below = 0;
	    Offset_Right = 0;
	    Offset_Left = 0;
	    adjtop = true;
	    adjside = true;
	    pctdel = 100;
	    timdel = 1;
	    isBalloon = false;
	    popW = -1;
	    popH = -1;
	    align = "L";
	    horiz = "T";
		SpanID = "S_"+id;
	} else if (arguments.length == 3) {
	    Offset_Below = 0;
	    Offset_Right = 0;
	    Offset_Left = 0;
	    adjtop = true;
	    adjside = true;
	    pctdel = 100;
	    timdel = 1;
	    isBalloon = false;
	    popW = -1;
	    popH = -1;
	    align = "L";
	    horiz = "T";
		SpanID = "S_"+id;
	} else if (arguments.length == 4) {
	    Offset_Right = 0;
	    Offset_Left = 0;
	    adjtop = true;
	    adjside = true;
	    pctdel = 100;
	    timdel = 1;
	    isBalloon = false;
	    popW = -1;
	    popH = -1;
	    align = "L";
	    horiz = "T";
		SpanID = "S_"+id;
	} else if (arguments.length == 5) {
	    Offset_Left = 0;
	    adjtop = true;
	    adjside = true;
	    pctdel = 100;
	    timdel = 1;
	    isBalloon = false;
	    popW = -1;
	    popH = -1;
	    align = "L";
	    horiz = "T";
		SpanID = "S_"+id;
	} else if (arguments.length == 6) {
	    adjtop = true;
	    adjside = true;
	    pctdel = 100;
	    timdel = 1;
	    isBalloon = false;
	    popW = -1;
	    popH = -1;
	    align = "L";
	    horiz = "T";
		SpanID = "S_"+id;
	} else if (arguments.length == 7) {
	    adjside = true;
	    pctdel = 100;
	    timdel = 1;
	    isBalloon = false;
	    popW = -1;
	    popH = -1;
	    align = "L";
	    horiz = "T";
		SpanID = "S_"+id;
	} else if (arguments.length == 8) {
	    pctdel = 100;
	    timdel = 1;
	    isBalloon = false;
	    popW = -1;
	    popH = -1;
	    align = "L";
	    horiz = "T";
		SpanID = "S_"+id;
	} else if (arguments.length == 9) {
	    timdel = 1;
	    isBalloon = false;
	    popW = -1;
	    popH = -1;
	    align = "L";
	    horiz = "T";
		SpanID = "S_"+id;
	} else if (arguments.length == 10) {
	    isBalloon = false;
	    popW = -1;
	    popH = -1;
	    align = "L";
	    horiz = "T";
		SpanID = "S_"+id;
	} else if (arguments.length == 11) {
		popW = -1;
	    popH = -1;
	    align = "L";
	    horiz = "T";
		SpanID = "S_"+id;
	} else if (arguments.length == 12) {
	    popH = -1;
	    align = "L";
	    horiz = "T";
		SpanID = "S_"+id;
	} else if (arguments.length == 13) {
	    align = "L";
	    horiz = "T";
		SpanID = "S_"+id;
	} else if (arguments.length == 14) {
	    horiz = "T";
		SpanID = "S_"+id;
	} else if (arguments.length == 15) {
		SpanID = "S_"+id;
	}  
	
	var objDiv = document.getElementById("PopUp_"+id);
	var currentState = objDiv.style.display;
	
	// Make sure the align arguement is upper case...
	align = align.toUpperCase();
	
	if (currentState == "none" || currentState == "") {
		
		evt = (evt) ? evt : ((window.event) ? event : null);
		
		// We need this set to "block" now to determine the correct height.
		objDiv.style.display = "block";
		
		if (popW > -1) {
		    DHTMLAPI.setWidth("PopUp_"+id, popW);
		    if (isBalloon) {
		        DHTMLAPI.setWidth("BalTop_"+id, popW);
		        DHTMLAPI.setWidth("BalHead_"+id, popW);
		        DHTMLAPI.setWidth("BalBot_"+id, popW);
		        DHTMLAPI.setWidth("BalText_"+id, popW);
		    }
		}
		
		if (popH > -1) {
		    DHTMLAPI.setHeight("PopUp_"+id, popH);
		    DHTMLAPI.setHeight("BalText_"+id, popH);
		}
		// PageC gives the location of the click in the page.
		// DivC gives the location of the click relative to the lower left 
		//      corner of the element containing the click.  I.e. it gives
		//      the location of the click inside the containing element.
		// DivW, DivH gives the width and height of the popup.
		// SpanW, SpanH gives the width and height of the element clicked
		//              to get the popup....
		var PageC = DHTMLAPI.getPageEventCoords(evt);
		var DivC = DHTMLAPI.getPositionedEventCoords(evt);
		var DivW = DHTMLAPI.getElementWidth("PopUp_"+id);
		var DivH = DHTMLAPI.getElementHeight("PopUp_"+id);
		var SpanH = DHTMLAPI.getElementHeight(SpanID);
		var SpanW = DHTMLAPI.getElementWidth(SpanID);
		var SpanC = DHTMLAPI.getElementPosition(SpanID);
		var WinW = DHTMLAPI.getInsideWindowWidth();
		var WinH = DHTMLAPI.getInsideWindowHeight();
		
		var coords = {left:0, top:0};
		
		var didAdjSide = false;
		var didAdjTop = false;
		
		// First we need to figure out where the left edge of the popup should be
		switch(align) {
		    // Right edges of popup and calling element are aligned
		    case "R":
		        // Figure out if we need to adjust the side location or not
		        // Here is the location of the left edge of popup....
		        leftpos = PageC.left - (DivW - SpanW + DivC.left) + Offset_Right;
		        //leftpos = SpanC.left + SpanW - DivW + Offset_Right;
		        if ( leftpos > 0  || !adjside ) {
        		    coords.left = leftpos;
		        } else {
					// This will match up left edges instead...
		            didAdjSide = true;
		            coords.left = PageC.left - DivC.left + Offset_Left;
		            //coords.leftpos = SpanC.left + Offset_Left;
		        }
		        break;
		    // Center popup over calling element
		    case "C":
		        // Figure out if we need to adjust the side location or not
		        // Here is the location of the left edge of popup....
		        leftpos = PageC.left - DivC.left + parseInt(SpanW/2) - parseInt(DivW/2);
		        rightpos = PageC.left - DivC.left + parseInt(SpanW/2) + parseInt(DivW/2);
		        //leftpos = SpanC.left + parseInt(SpanW/2) - parseInt(DivW/2);
		        //rightpos =  SpanC.left + parseInt(SpanW/2) + parseInt(DivW/2);
		        // Note that if both edges are outside the window then it's probably
		        // best that we don't adjust the position.....
		        if ( (leftpos > 0  && rightpos < WinW)  ||
		             (leftpos < 0 && rightpos > WinW) || !adjside ) {
        		    coords.left = leftpos;
		        } else if (leftpos > 0  && rightpos > WinW) {
					// We're past the right edge so line up right edges...
		            didAdjSide = true;
		            coords.left = PageC.left - (DivW - SpanW + DivC.left);
		            //coords.left = SpanC.left + SpanW - DivW;
		        } else if (leftpos < 0  && rightpos < WinW) {
					// We're past the left edge so line up left edges..
		            didAdjSide = true;
		            coords.left = PageC.left - DivC.left + Offset_Left;
		            //coords.left = SpanC.left;
		        }
		        break;
		    // Left edge of popup aligns with right edge of calling element
		    case "LR":
		        // Figure out if we need to adjust the side location or not
		        // Here is the location of the right edge of popup....
		        rightpos = PageC.left + SpanW - DivC.left + DivW + Offset_Right;
		        //rightpos = SpanC.left + SpanW + DivW + Offset_Right;
		        if ( rightpos  < WinW || !adjside ) {
					//coords.left = PageC.left + SpanW - DivC.left + Offset_Right;
        		    coords.left = PageC.left + SpanW - DivC.left + Offset_Right;
		        } else {
					// we're past the right edge so align the right edges...
					coords.left = PageC.left - 
		                            (DivW - SpanW + DivC.left) + Offset_Right;
		            //coords.left = SpanC.left + SpanW - DivW + Offset_Right;
		            didAdjSide = true;
		        }
		        break;
		    // Right edge of popup aligns with left edge of calling element
		    case "RL":
		        // Figure out if we need to adjust the side location or not
		        // Here is the location of the left edge of popup....
		        leftpos = PageC.left - (DivW + DivC.left) + Offset_Left;
		        //leftpos = SpanC.left - DivW + Offset_Left;
		        if ( leftpos > 0  || !adjside ) {
        		    coords.left = leftpos;
		        } else {
					// we're past the left edge so line up left edges.
		            didAdjSide = true;
		            coords.left = PageC.left - DivC.left + Offset_Left;
		            //coords.left = SpanC.left + Offset_Left;
		        }
		        break;
		    // Align left edge of popup to mouse click....
		    case "ML":
		        // Figure out if we need to adjust the side location or not
		        // Here is the location of the right edge of popup....
		        rightpos = PageC.left + DivW + Offset_Left;
		        if ( rightpos < WinW || !adjside ) {
        		    coords.left = PageC.left + Offset_Left;
		        } else {
					// We're past the right edge so line up right edge with mouse.
		            didAdjSide = true;
		            coords.left = PageC.left - DivW + Offset_Right;
		            //coords.left = SpanC.left + SpanW - DivW + Offset_Right;
		        }
		        break;
		    // Align right edge of popup to mouse click....
		    case "MR":
		        // Figure out if we need to adjust the side location or not
		        // Here is the location of the left edge of popup....
		        leftpos = PageC.left - DivW + Offset_Left;
		        if ( leftpos > 0  || !adjside ) {
        		    coords.left = leftpos;
		        } else {
					// We're past the left edge so line up left edge with mouse.
		            didAdjSide = true;
		            coords.left = PageC.left + Offset_Left;
		            //coords.left = SpanC.left + Offset_Left;
		        }
		        break;
		    // Center popup over mouse click
		    case "MC":
		        // Figure out if we need to adjust the side location or not
		        // Here is the location of the left edge of popup....
		        leftpos = PageC.left - parseInt(DivW/2);
		        rightpos = PageC.left + parseInt(DivW/2);
		        // Note that if both edges are outside the window then it's probably
		        // best that we don't adjust the position.....
		        if ( (leftpos > 0  && rightpos < WinW)  ||
		             (leftpos < 0 && rightpos > WinW) || !adjside ) {
        		    coords.left = leftpos;
		        } else if (leftpos > 0  && rightpos > WinW) {
					// We're past the right edge line so line up the right edges.
		            didAdjSide = true;
		            coords.left = PageC.left - (DivW - SpanW + DivC.left);
		            //coords.left = SpanC.left + SpanW - DivW + Offset_Right;
		        } else if (leftpos < 0  && rightpos < WinW) {
					// We're past the left edge so line up the left edges.
		            didAdjSide = true;
		            coords.left = PageC.left - DivC.left + Offset_Left;
		            //coords.left = SpanC.left + Offset_Left;
		        }
		        break;
		    // Left edges of popup and calling element are aligned
		    case "L": default:
		        // Figure out if we need to adjust the side location or not.
		        // Here is the location of the right edge of popup....
		        rightpos = DivW - DivC.left + PageC.left + Offset_Left;
		        //rightpos = SpanC.left + DivW + Offset_Left;
		        if (rightpos  < WinW || !adjside ) {
					coords.left = PageC.left - DivC.left + Offset_Left;
        		    //coords.left = SpanC.left + Offset_Left;
		        } else {
		            didAdjSide = true;
		            coords.left = PageC.left - 
		                            (DivW - SpanW + DivC.left) + Offset_Right;
		            //coords.left = SpanC.left + SpanW - DivW + Offset_Right;
		        }
		        break;
		}
		
		// Next figure out where the top should be.....
		switch(horiz) {
		    // Right edges of popup and calling element are aligned
		    case "B":
		        // Figure out if we need to adjust the side location or not
		        // Here is the location of the left edge of popup....
		        botpos = evt.clientY + DivC.top + DivH + Offset_Below;
		        if ( botpos < WinH  || !adjtop ) {
        		    coords.top = PageC.top + (SpanH - DivC.top) + Offset_Below;
		        } else {
		            didAdjSide = true;
		            coords.top = SpanC.top - DivH + Offset_Above;
		        }
		        break;
		     // Left edges of popup and calling element are aligned
		    case "T": default:
		        // Figure out if we need to adjust the side location or not.
		        // Here is the location of the top edge of popup....
		        toppos = evt.clientY - (DivC.top + DivH) + Offset_Above;
		        if (toppos > 0 || !adjtop) {			
			        coords.top = PageC.top - (DivC.top + DivH) + Offset_Above;
		        } else {
		            didAdjTop = true;
			        coords.top = PageC.top + (SpanH - DivC.top) + Offset_Below;
		        }
		        break;
		}
		
		// Now get the popup into the correct place...
		DHTMLAPI.moveTo(objDiv.id, coords.left, coords.top);
		
		// If it was a balloon get the tip set up correctly....
		if (isBalloon) {
		    if (didAdjTop) {
		        DHTMLAPI.setDisplay("BalBot_"+id, "none");   
		        DHTMLAPI.setDisplay("BalTop_"+id, "block");
		        DHTMLAPI.setBorderWidth("BalText_"+id, "", "1px", "", "");
		        DHTMLAPI.setBorderWidth("BalHead_"+id, "0px", "", "", ""); 
		        
		        if (didAdjSide) {
		            DHTMLAPI.setBGImage("BalTop_"+id, "/Images/Balloon_Top_Right.gif", "", "right bottom");
		        } else {
		            DHTMLAPI.setBGImage("BalTop_"+id, "/Images/Balloon_Top_Left.gif", "", "left bottom");
		        }
		          
		    } else if (!didAdjTop) {
		        DHTMLAPI.setDisplay("BalBot_"+id, "block");   
		        DHTMLAPI.setDisplay("BalTop_"+id, "none"); 
		        DHTMLAPI.setBorderWidth("BalText_"+id, "", "0px", "", "");
		        DHTMLAPI.setBorderWidth("BalHead_"+id, "1px", "", "", "");
		        
		        if (didAdjSide) {
		            DHTMLAPI.setBGImage("BalBot_"+id, "/Images/Balloon_Bottom_Right.gif", "", "right top");
		        } else {
		            DHTMLAPI.setBGImage("BalBot_"+id, "/Images/Balloon_Bottom_Left.gif", "", "left top");
		        } 
		    }
		}
		
		// Show the object.....
		initPercent = (didAdjTop) ? 0 : 100;
		AddClip("PopUp_"+id, didAdjTop, initPercent, pctdel, timdel);
	} else {
	    // Remove the object...
	    // currently the didAdjTop isn't set for this and so
	    // doesn't do anything.....  I'll probably need to set a cookie
	    // in the previous bit to get this to work properly.
		initPercent = (!didAdjTop) ? 0 : 100;
		RemoveClip("PopUp_"+id, !didAdjTop, initPercent, pctdel, timdel);
	}
}

function AddClip(elemRef, FromTop, percent, pctdel, timedel) {
    var elem = DHTMLAPI.getStyleObject(elemRef);
    var clipheight;
    var height;
    var width;
    
    if (elem == null) {
        return;
    }
    //alert(elem.clip);
    // if pctdel == 100 then there's no reason to do any clipping....
    if (pctdel == 100) {
        elem.display = "block";
        return;
    }
    
    // Firefox needs the +4.  This is probably from the borders
    // and I'll need to fix this up....
	width = DHTMLAPI.getElementWidth(elemRef)+4;
	height = DHTMLAPI.getElementHeight(elemRef);
	clipheight = parseInt(percent*height/100);
	
	if (FromTop) {
		elem.clip = "rect(0px " + width + "px " + clipheight + "px 0px)";
		percent += pctdel;
		
		if (percent <= 100 ) {
			setTimeout("AddClip('" + elemRef + "', true, " + percent + ", " + pctdel + ", " + timedel + ")", timedel);	
		}
	} else {
		elem.clip = "rect(" + clipheight + "px " + width + "px " + height + "px 0px)";
		percent -= pctdel;
		
		if (percent >= 0 ) {
			setTimeout("AddClip('" + elemRef + "', false, " + percent + ", " + pctdel + ", " + timedel + ")", timedel);	
		}
		
	}
}

function RemoveClip(elemRef, FromTop, percent, pctdel, timedel) {
    var elem = DHTMLAPI.getStyleObject(elemRef);
    var clipheight;
    var height;
    var width;
    
    if (elem == null) {
        return;
    }
    
    // if pctdel == 100 then there's no reason to do any clipping....
    if (pctdel == 100) {
        elem.display = "none";
        return;
    }
    
    // Firefox needs the +4.  This is probably from the borders
    // and I'll need to fix this up....
	width = DHTMLAPI.getElementWidth(elemRef)+4;
	height = DHTMLAPI.getElementHeight(elemRef);
	clipheight = parseInt(percent*height/100);
    
	if (FromTop) {	
		elem.clip = "rect(" + clipheight + "px " + width + "px " + height + "px 0px)";
		percent += pctdel;
		
		if (percent <= 100) {
			setTimeout("RemoveClip('" + elemRef + "', true, " + percent + ", " + pctdel + ", " + timedel + ")", timedel);	
		} else {
		    // Once done with the clipping this completely removes
		    // the element from the dispaly...
			elem.display = "none";	
		}
	} else  {
		elem.clip = "rect(0px " + width + "px " + clipheight + "px 0px)";
		percent -= pctdel;
		
		if (percent >= 0) {
			setTimeout("RemoveClip('" + elemRef + "', false, " + percent + ", " + pctdel + ", " + timedel + ")", timedel);	
		} else {
		    // Once done with the clipping this completely removes
		    // the element from the dispaly...
			elem.display = "none";	
		}
	}
}


// I snagged the following from 
// http://techpatterns.com/downloads/javascript_cookies.php
//
function Set_Cookie( name, value, expires, path, domain, secure ) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
		
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}

// this function gets the cookie, if it exists
function Get_Cookie_New( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}