﻿// JScript File

//*****************************************************************************
//*
//*	PROGRAM DATA EXPLORER
//*	 (C) 2008 Educational Testing Service
//*
//*		popup.JS
//*
//*		Javascript functions to support PDEClient web application
//*
//*		
//*
//*		Created:  03-05-2008 by sravipati@ets.org
//*
//*
//*****************************************************************************


var pdePopId="";  //global popup identifier - change this to array if more than one popup is visible
var pdeSelId="";  //kludge fix for IE - if popup is over a select element, need to clip this element
var selCtrlIDs=new Array();  //more IE kludge - controls to hide if popup covers them
var clipWidth=0;
var clipHeight=0;
var xClip=0;
var yClip=0;
var pdeLoaded=false;
var pdePopOn=false;
var pdePopX;
var pdePopY;
var pdePopXStart;
var pdePopYStart;
var pdePopXOffset;
var pdePopYOffset;

//*****************************************************************
//* Hashtable definitions
	Hashtable.prototype.hash = null;
	Hashtable.prototype.keys = null;
	Hashtable.prototype.location = null;

	function Hashtable()
	{
		this.hash = new Array();
		this.keys = new Array();

		this.location = 0;
	}

	Hashtable.prototype.get = function (key) {
		return this.hash[key];
	}

	Hashtable.prototype.put = function (key, value)
	{
		if (value == null)
			return null;

		if (this.hash[key] == null)
			this.keys[this.keys.length] = key;

		this.hash[key] = value;
	}
//*
//*****************************************************************
function openWin(theURL,theWidth,theHeight)
{
aWindow=window.open(theURL,"popupwin","width="+((theWidth!=null)?theWidth:455)+",height="+((theHeight!=null)?theHeight:300)+",scrollbars=no,resizable=yes,screenX=0,screenY=0,top=0,left=0,top=0,left=0, toolbar=yes");
aWindow.focus();
}
//*****************************************************************
		//*
		//*  Collapse Functions
		//*
		//*****************************************************************
		
		//*****************************************************************
		//* Global variables
		var collapsePops = new Hashtable();
		var collapseArea = new Hashtable();
		//var collapseDups = new Hashtable();
		var collapseCnts = new Hashtable();
		var btnStrtImage = "";
		//var btnDupsImage = "";
		var btnRemvImage = "";
		var btnDoneImage = "";
		var btnStrtImageDis = "";
		//var btnDupsImageDis = "";
		var btnRemvImageDis = "";
		var btnDoneImageDis = "";
		var btnStrtImageHvr = "";
		//var btnDupsImageHvr = "";
		var btnRemvImageHvr = "";
		var btnDoneImageHvr = "";
		
		var btnImgRmvHvr = "";
		var btnImgRmvDis = "";
		
		var GroupNames = new Hashtable();
		var NewGroupNames = new Hashtable();
//*****************************************************************
		//* function loadCollapsePop
		//*
		//*		string colPopID : identifies this collapse popup
		//*		array  colPopItemIDs : items displayed in check list
		//*		bool   colDups : sets condition of Dups button enabled
		//*		array  btnImages : button images for collapse popup
		//*		array  gNames : previously existing group names
		//*		string colGroupListID : identifies the group name list area
		//*		array  gRItems : items in groups to remove from list 
		//*
		//*		-- Sets initial information for the collapse popup.  Item
		//*		ID's are added to hashtable, button images are assigned,
		//*		group names are initialized, and display state is saved
		//*		for Start Over.
		//*colDups, 
		function loadCollapsePop(colPopID, colPopItemIDs, btnImages, gNames, colGroupListID, gRItems)
		{
			collapsePops.put(colPopID, colPopItemIDs);
			
			btnStrtImage = btnImages[0];
			//btnDupsImage = btnImages[1];
			btnRemvImage = btnImages[1];
			btnDoneImage = btnImages[2];
			btnStrtImageHvr = btnImages[3];
			//btnDupsImageHvr = btnImages[5];
			btnRemvImageHvr = btnImages[4];
			btnDoneImageHvr = btnImages[5];
			btnStrtImageDis = btnImages[6];
			//btnDupsImageDis = btnImages[9];
			btnRemvImageDis = btnImages[7];
			btnDoneImageDis = btnImages[8];
			
			btnImgRmvHvr = btnImages[10];
		    btnImgRmvDis = btnImages[9];

			var objColGroupList = getObject(colGroupListID);
			var gn = new Array();			
			if (gNames != null)
			{
				for (i=0; i<gNames.length; i++)
				{
					gn[i] = gNames[i];
					objColGroupList.innerHTML += "<p><b>&nbsp;&nbsp;" + gNames[i].toString().substring(1) + "</b><br></p>";
				}
			}
			GroupNames.put(colPopID, gn);
						
			NewGroupNames.put(colPopID, new Array());
			
			var objColItems = getObject(colPopID);
			if (objColItems)
			{
				collapseArea.put(colPopID, objColItems.parentNode.innerHTML);
			}
			
			//collapseDups.put(colPopID, colDups);
			collapseCnts.put(colPopID, 0);
			
			if (gRItems != null)
			{
				for (i=0; i<gRItems.length; i++)
				{
					var objColItem = getObject(gRItems[i]);
					if (objColItem)
					{
						objColItem.checked = false;
						// parent1=<span>, parent2=<td>, parent3=<tr>
						var objParent = objColItem.parentNode.parentNode.parentNode;
						objParent.parentNode.removeChild(objParent);
					}
				}
			}
		}
				
//*****************************************************************
		//* function hideAllPopups
		//*
//*****************************************************************
function hideAllPopups(eventObj) 
{
	if ((pdePopId == '') || (pdeLoaded == false))
		return;

	if (pdePopOn)
		endPopMove(eventObj);
	
	if (!ie)
	{
		// Fix for bug in Mozilla browers.  Description of bug:
		// http://www.howtocreate.co.uk/mozBugs/testcapture.html
		// Workaround is to see if mouse was clicked inside of
		// popup window.  If so, ignore the click and return.
		
		if (!eventObj) eventObj = window.event;
		
		if (eventObj)
		{
			var mouseX=(nav)?eventObj.pageX:event.clientX+document.body.scrollLeft;
			var mouseY=(nav)?eventObj.pageY:event.clientY+document.body.scrollTop;
			var menuPos = getElementPosition(pdePopId);
			
			
			objMenu = getObject(pdePopId);
			if (objMenu)
			{
				if ((mouseX > menuPos.left) && (mouseX < (menuPos.left + objMenu.clientWidth)) &&
					(mouseY > menuPos.top)  && (mouseY < (menuPos.top  + objMenu.clientHeight)))
				{
					return;
				}
			}
		}
	}
	
	pdeLoaded = false;
	
	changeObjectVisibility(pdePopId, 'hidden');
	pdePopId = '';
	if (ie && (pdeSelId != '')){
		selcIdStyle = getStyleObject(pdeSelId);
		if (selcIdStyle)
		{
			selcIdStyle.position = '';
			selcIdStyle.clip = 'rect(auto auto auto auto)';
		}
		
		//changeObjectVisibility(pdeSelId, 'visible');
	}
	if (ie && (selCtrlIDs.length > 0))
		showSelectObjects();
		
	if(nav){
   		document.releaseEvents(Event.MOUSEMOVE);
		document.releaseEvents(Event.MOUSEOVER);
	}
}

function setmsg(msg) {
  window.status=msg
  return true
}
/////////////////////////////////////////////////////////////////////
 function getObject(objectId)
{
    if(document.getElementById && document.getElementById(objectId)) {
    return document.getElementById(objectId);
    } else if (document.all && document.all(objectId)) {
    return document.all(objectId);
    } else if (document.layers) {
    return eval('document.'+objectId);
    } else {
    return false;
    }
}
/////////////////////////////////////////////////////////////////////

function getObjectByTagName(objectTagName)
{
    if(document.getElementsByTagName && document.getElementsByTagName(objectTagName)) {
    return document.getElementsByTagName(objectTagName);
    } else if (document.all && document.all(objectTagName)) {
    return document.all(objectTagName);
    } else if (document.layers) {
    return eval('document.'+objectTagName);
    } else {
    return false;
    }
}

/////////////////////////////////////////////////////////////////////
        
function getStyleObject(objectId) 
{
    if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	return document.layers[objectId];
    } else {
	return false;
    }
}         
//*****************************************************************************

var nav = (navigator.appName=="Netscape") ? true : false;
var mac = (navigator.appVersion.indexOf("Mac") != -1);
var ie = (document.all) ? true : false;

//*****************************************************************
/////////////////////////////////////////////////////////////////////
// This allows the popup(s) to be hidden by clicking off the popup
// on the document.  Comment this out to make popup(s) strictly
// modal.  See also information about Mozilla bug in hideAllPopups.
//document.onclick = hideAllPopups;
var pdePopId="";
/////////////////////////////////////////////////////////////////////

function showPop(popID, selID, eventObj, bTimer, offX, offY, bVAlign, bAnimate) 
{
	/////////////////////////////////////////////////////////////////
	// First make sure no other popup is active.  If multi-popups are
	// allowed by changing pdePopId to array, this can be removed.
	if (pdePopId != "")
	{
		hideAllPopups();
	}

	//////////////////////////////////////	
	// These are global vars
	pdePopId = popID;
	pdeSelId = selID;

	//if (ctrlIDs != null)
	//	registerIEWindowCtrls(ctrlIDs);
	//////////////////////////////////////

	var obj = getObject(pdePopId);
	if (!obj)
	{
		alert('No popup found: ' + popID);
		return;
	}

	var styobj = getStyleObject(pdePopId);
	if (!styobj)
	{
		alert('No popup style:' + popID);
		return;
	}	

	if (nav)
	{
		document.captureEvents(Event.MOUSEMOVE);
		document.captureEvents(Event.MOUSEOVER);
	}

	/////////////////////////////////////////////////////////////////
	// Popups can be auto closed after a specific time.  Timer
	// count starts when mouse leaves the popup area.
	if (bTimer)
	{
		obj.onmouseout = timeKill;
 		obj.onmouseover = resetTimer;
	}

	var viewWidth  = (ie)?document.body.clientWidth:window.innerWidth;
	var viewHeight = (ie)?document.body.clientHeight:window.innerHeight;

	/////////////////////////////////////////////////////////////////
	// Popup positioning - the popup is initially positioned as 
	// close to the point of the event as possible.  The caller
	// can offset this position by passing in values.  If no event
	// object is defined, the position defaults to screen center.
	var x=0;
	var y=0;
	if ((eventObj != null))
	{
		x = (nav)?eventObj.pageX:event.clientX+document.body.scrollLeft;
		y = (nav)?eventObj.pageY:event.clientY+document.body.scrollTop;
		x += offX;
		y += offY;
	}
	else
	{
		x = viewWidth/2;
		x += (ie)?document.body.scrollLeft:window.pageXOffset;
		x -= obj.offsetWidth/2;
		if (x<0) x=0;
		y = viewHeight/2;
		y += (ie)?document.body.scrollTop:window.pageYOffset;
		y -= obj.offsetHeight/2;
		if (y<0) y=0;
		x += offX;
		y += offY;
	}

	if(mac&&ie){//mac ie bug fix
		winWidth = document.body.clientWidth;
		if(winWidth > 612) x -= (winWidth - 612)/2;
	}

	/////////////////////////////////////////////////////////////////
	// If the x-position will cause the popup to disappear off the
	// right side of the window, try to move the popup to the left
	// so that the maximum amount of popup will be visible.
	if ((x+obj.offsetWidth) > viewWidth)
	{
		x -= ((x+obj.offsetWidth) - viewWidth);
		x -= 40;
		if (x < 0) x=5;
	}

	/////////////////////////////////////////////////////////////////
	// Caller can specify that the popup is vertically aligned in
	// the visible browser window.
	if (bVAlign)
	{	
		y = viewHeight/2;
		y += (ie)?document.body.scrollTop:window.pageYOffset;
		y -= obj.offsetHeight/2;
		if (y<0) y=0;
	}

	/////////////////////////////////////////////////////////////////
	// Move the popup to final x,y position
	moveObject(pdePopId, x, y);
	pdePopX = x;
	pdePopY = y;

	/////////////////////////////////////////////////////////////////
	// IE bug fix.  Selection controls (listboxes, droplists) do not
	// have valid z-orders in IE.  These controls will always display
	// on top of other controls.  Therefore, these type of controls
	// need to be hidden if the popup overlaps them.  
	//
	// There are two types of selection items that can be referenced
	// from this function.  The first type is a known selection control
	// position that the popup will overlap.  This control is much
	// larger than the popup, and is clipped rather than fully hidden.
	if ((pdeSelId != '') && ie)
	{
		// The selection control is referenced in global pdeSelId
		var selDim = getStyleObject(pdeSelId);
		if (selDim)
		{
			selDim.position = 'absolute';
			nObjHeight = obj.offsetHeight - 20;
			selDim.clip = 'rect(' + nObjHeight + ' auto auto auto)';
		}
	}
	//
	// The second type of selection control(s) are controls that
	// are known to be somewhere on the display, and may or may
	// not interfere with the popup.  These controls are checked
	// one at a time for location and overlap with the popup.  If
	// the controls overlap, only then are they hidden.
	//if (ie && (selCtrlIDs.length > 0))
	//	hideSelectObjects(x, y, obj.offsetWidth, obj.offsetHeight);		 
	//
	/////////////////////////////////////////////////////////////////

	if (styobj.display == 'none')
		styobj.display='inline';
		
	if (!bAnimate)
	{
		//Commented out by Sirisha Ravipati on March 1st 2007
		//obj.onmousedown = startPopMove;

		/////////////////////////////////////////////////////////////////
		// Make the popup visible
		if(changeObjectVisibility(pdePopId, 'visible')) 
		{
			if (eventObj != null)
				eventObj.cancelBubble = true;
			pdeLoaded = true;
			return true;
		} 
		else 
		{
			return false;
		}
	}
	else
	{
		clipWidth  = obj.offsetWidth;
		clipHeight = obj.offsetHeight;	
		xClip = 0;
		yClip = 0;
		setTimeout('showClip()', 2);
		return true;
	}
}

function showClip()
{
	var styobj = getStyleObject(pdePopId);
	if (!styobj)
		return;

	styobj.visibility = 'visible';
	
	var ratio = (clipWidth >= clipHeight) ? clipWidth / clipHeight : clipHeight / clipWidth;
	var xMod = (clipWidth <= clipHeight) ? 1 : ratio;
	var yMod = (clipHeight <= clipWidth) ? 1 : ratio;
	
	styobj.clip = 'rect(auto ' + xClip + ' ' + yClip + ' auto)';
	if (xClip < clipWidth)
		xClip += xMod * 6;
	else
		xClip = clipWidth;
	if (yClip < clipHeight)
		yClip += yMod * 6;
	else
		yClip = clipHeight;
	if ((yClip < clipHeight) || (xClip < clipWidth))
	{
		setTimeout('showClip()', 1);
		return;
	}
	
	styobj.clip = 'rect(auto auto auto auto)';
	pdeLoaded = true;
}

//*****************************************************************
		//* function EnableButton
		//*
		//*		object objBtn : the button to enable
		//*		string btnImg : image to set for enabled button
		//*		string btnImgHvr : image to set for mouseover
		//*
		function EnableButton(objBtn, btnImg, btnImgHvr)
		{
			objBtn.disabled = false;
			objBtn.src = btnImg;
			objBtn.onmouseover = function() { objBtn.src = btnImgHvr; objBtn.style.cursor = 'pointer';};
			objBtn.onmouseout = function () { objBtn.src = btnImg; objBtn.style.cursor = 'default';};
		}
		
		//*****************************************************************
		//* function DisableButton
		//*
		//*		object objBtn : the button to disable
		//*		string btnImgDis : image to set for disabled button
		//*
		function DisableButton(objBtn, btnImgDis)
		{
			objBtn.disabled = true;
			objBtn.src = btnImgDis;
			objBtn.onmouseover = null;
			objBtn.onmouseout = null;
		}
		

//*****************************************************************
		//* function onCollapseItemChecked
		//*
		//*		event  eventObj : event object that fired this call
		//*		string colPopID : identifies the collapse list
		//*		string colItemID : identifies the collapse list check item
		//*		string colPopTxtBoxID : identifies the group name text box
		//*		string colBtn1ID : identifies the collapse dups button
		//*		string colBtn2ID : identifies the collapse remove button
		//*
		//*		-- called when item in collapse list is selected or de-
		//*		selected.  If one or more items are selected, the text
		//*		box to enter group name is enabled, and collapse buttons
		//*		are enabled if allowed.
		//* Sirisha Ravipati SR April 5th 2007, edited this function to implement "Check All Items" functionality
		function onCollapseItemChecked(eventObj, colPopID, colItemID, colPopTxtBoxID, colBtn2ID)
		{
		    try
		    {
			    var checkCount = collapseCnts.get(colPopID);
			    var colPopItems = collapsePops.get(colPopID);
			    var objColTxtBox = getObject(colPopTxtBoxID);
			    //var objColBtn1 = getObject(colBtn1ID);
			    var objColBtn2 = getObject(colBtn2ID);
			    //var objColBtn3 = getObject(colBtn3ID);
			    //var bCollapseDups = collapseDups.get(colPopID);
    			
			    if (!objColTxtBox)
			    {
				    alert('No GroupName text box!');
				    return;
			    }

			    var objColItem = getObject(colItemID);
			    if (objColItem)
			    {
				    if (objColItem.checked)
				    {
					    checkCount++;
					    //if(checkCount == parentID.length)
					    //	chkAllID.checked = true;
				    }
				    else
				    {
					    checkCount--;
					    //if(chkAllID.checked == true)
					    //	chkAllID.checked = false;
				    }
			    }
    			
			    collapseCnts.put(colPopID, checkCount);
    			
			    if (checkCount < 0)
				    alert('Invalid checkCount: Please alert development staff!');
    			
			    if (checkCount > 0)
			    {
				    objColTxtBox.disabled = false;
    //				if (bCollapseDups)
    //					EnableButton(objColBtn1, btnDupsImage, btnDupsImageHvr);
    //				else
    //					DisableButton(objColBtn1, btnDupsImageDis);
				    EnableButton(objColBtn2, btnRemvImage, btnRemvImageHvr);
				    //EnableButton(objColBtn3, btnImgRmvHvr, btnImgRmvHvr);
			    }
			    else
			    {
				    objColTxtBox.disabled = true;
				    //DisableButton(objColBtn1, btnDupsImageDis);
				    DisableButton(objColBtn2, btnRemvImageDis);
				    //DisableButton(objColBtn3, btnImgRmvDis);
			    }
			}
			catch(err)
			{
			    alert(err.description );
			}
		}
		
		
		//*****************************************************************
		//* function onCollapseListChecked
		//*
		//*		event  eventObj : event object that fired this call
		//*		string colPopID : identifies the collapse list
		//*		string colPopTxtBoxID : identifies the group name text box
		//*		string colBtn1ID : identifies the collapse dups button
		//*		string colBtn2ID : identifies the collapse remove button
		//*
		//*		-- This function was added as a workaround due to a bug in
		//*		Mozilla browsers (i.e. Firefox).  The bug is a failure 
		//*		to fire an event on the checkbox when the label of the
		//*		checkbox is clicked on.  The label click event will turn
		//*		the checkbox selection on or off, so the event needs to
		//*		be captured within the entire list.  The only difference
		//*		with the entire list event is that the checkbox is not
		//*		actually selected (or de-selected) yet.
		//*
		function onCollapseListChecked(eventObj, colPopID, colPopTxtBoxID, colBtn2ID)
		{
			if ((ie) || (eventObj.target.attributes["for"] == null))
				return;
			
			var colItemID = eventObj.target.attributes["for"].value;
			var checkCount = collapseCnts.get(colPopID);
			var colPopItems = collapsePops.get(colPopID);
			var objColTxtBox = getObject(colPopTxtBoxID);
			//var objColBtn1 = getObject(colBtn1ID);
			var objColBtn2 = getObject(colBtn2ID);
			//var objColBtn3 = getObject(colBtn3ID);
			//var bCollapseDups = collapseDups.get(colPopID);
			
			if (!objColTxtBox)
			{
				alert('No GroupName text box!');
				return;
			}

			var objColItem = getObject(colItemID);
			if (objColItem)
			{
				if (objColItem.checked)
					checkCount--;
				else
					checkCount++;
			}
			
			collapseCnts.put(colPopID, checkCount);
			
			if (checkCount < 0)
				alert('Invalid checkCount: Please alert development staff!');
			
			if (checkCount > 0)
			{
				objColTxtBox.disabled = false;
//				if (bCollapseDups)
//					EnableButton(objColBtn1, btnDupsImage, btnDupsImageHvr);
//				else
//					DisableButton(objColBtn1, btnDupsImageDis);
				EnableButton(objColBtn2, btnRemvImage, btnRemvImageHvr);
				//EnableButton(objColBtn3, btnImgRmvHvr, btnImgRmvHvr);
			}
			else
			{
				objColTxtBox.disabled = true;
				//DisableButton(objColBtn1, btnDupsImageDis);
				DisableButton(objColBtn2, btnRemvImageDis);
				//DisableButton(objColBtn3, btnImgRmvDis);
			}
		}
		
		//*****************************************************************
		//* function onCollapseVarItemChecked
		//*
		//*		event  eventObj : event object that fired this call
		//*		string colPopID : identifies the collapse list
		//*		string colItemID : identifies the collapse list check item
		//*		string colPopTxtBoxID : identifies the group name text box
		//*		string colBtn1ID : identifies the collapse dups button
		//*		string colBtn2ID : identifies the collapse remove button
		//*
		//*		-- called when item in collapse list is selected or de-
		//*		selected.  If one or more items are selected, the text
		//*		box to enter group name is enabled, and collapse buttons
		//*		are enabled if allowed.
		function onCollapseVarItemChecked(eventObj, colPopID, colItemID, colPopTxtBoxID, colBtn2ID)
		{
		    try
		    {
			    var checkCount = collapseCnts.get(colPopID);
			    var colPopItems = collapsePops.get(colPopID);
			    var objColTxtBox = getObject(colPopTxtBoxID);
			    //var objColBtn1 = getObject(colBtn1ID);
			    var objColBtn2 = getObject(colBtn2ID);
			    //var objColBtn3 = getObject(colBtn3ID);
			    //var bCollapseDups = collapseDups.get(colPopID);
    			
			    if (!objColTxtBox)
			    {
				    alert('No GroupName text box!');
				    return;
			    }

			    var objColItem = getObject(colItemID);
			    if (objColItem)
			    {
				    if (objColItem.checked)
				    {
					    checkCount++;
					    //if(checkCount == parentID.length)
					    //	chkAllID.checked = true;
				    }
				    else
				    {
					    checkCount--;
					    //if(chkAllID.checked == true)
					    //	chkAllID.checked = false;
				    }
			    }
    			
			    collapseCnts.put(colPopID, checkCount);
    			
			    if (checkCount < 0)
				    alert('Invalid checkCount: Please alert development staff!');
    			
			    if (checkCount > 0)
			    {
				    objColTxtBox.disabled = false;
    //				if (bCollapseDups)
    //					EnableButton(objColBtn1, btnDupsImage, btnDupsImageHvr);
    //				else
    //					DisableButton(objColBtn1, btnDupsImageDis);
				    EnableButton(objColBtn2, btnRemvImage, btnRemvImageHvr);
				    //EnableButton(objColBtn3, btnImgRmvHvr, btnImgRmvHvr);
			    }
			    else
			    {
				    objColTxtBox.disabled = true;
				    //DisableButton(objColBtn1, btnDupsImageDis);
				    DisableButton(objColBtn2, btnRemvImageDis);
				    //DisableButton(objColBtn3, btnImgRmvDis);
			    }
			}
			catch(err)
			{
			    alert(err.description );
			}
		}
		
		
		//*****************************************************************
		//* function onCollapseVarListChecked
		//*
		//*		event  eventObj : event object that fired this call
		//*		string colPopID : identifies the collapse list
		//*		string colPopTxtBoxID : identifies the group name text box
		//*		string colBtn1ID : identifies the collapse dups button
		//*		string colBtn2ID : identifies the collapse remove button
		//*
		//*		-- This function was added as a workaround due to a bug in
		//*		Mozilla browsers (i.e. Firefox).  The bug is a failure 
		//*		to fire an event on the checkbox when the label of the
		//*		checkbox is clicked on.  The label click event will turn
		//*		the checkbox selection on or off, so the event needs to
		//*		be captured within the entire list.  The only difference
		//*		with the entire list event is that the checkbox is not
		//*		actually selected (or de-selected) yet.
		//*
		function onCollapseVarListChecked(eventObj, colPopID, colPopTxtBoxID, colBtn2ID)
		{
			if ((ie) || (eventObj.target.attributes["for"] == null))
				return;
			
			var colItemID = eventObj.target.attributes["for"].value;
			var checkCount = collapseCnts.get(colPopID);
			var colPopItems = collapsePops.get(colPopID);
			var objColTxtBox = getObject(colPopTxtBoxID);
			//var objColBtn1 = getObject(colBtn1ID);
			var objColBtn2 = getObject(colBtn2ID);
			//var objColBtn3 = getObject(colBtn3ID);
			//var bCollapseDups = collapseDups.get(colPopID);
			
			if (!objColTxtBox)
			{
				alert('No GroupName text box!');
				return;
			}

			var objColItem = getObject(colItemID);
			if (objColItem)
			{
				if (objColItem.checked)
					checkCount--;
				else
					checkCount++;
			}
			
			collapseCnts.put(colPopID, checkCount);
			
			if (checkCount < 0)
				alert('Invalid checkCount: Please alert development staff!');
			
			if (checkCount > 0)
			{
				objColTxtBox.disabled = false;
//				if (bCollapseDups)
//					EnableButton(objColBtn1, btnDupsImage, btnDupsImageHvr);
//				else
//					DisableButton(objColBtn1, btnDupsImageDis);
				EnableButton(objColBtn2, btnRemvImage, btnRemvImageHvr);
				//EnableButton(objColBtn3, btnImgRmvHvr, btnImgRmvHvr);
			}
			else
			{
				objColTxtBox.disabled = true;
				//DisableButton(objColBtn1, btnDupsImageDis);
				DisableButton(objColBtn2, btnRemvImageDis);
				//DisableButton(objColBtn3, btnImgRmvDis);
			}
		}
		
		//*****************************************************************
		//* function onCollapseStartOver
		//*
		//*		string colPopID : identifies the collapse list
		//*		string colPopTxtBoxID : identifies the group name text box
		//*		string colBtnStartID : identifies the start over button
		//*		string colBtn1ID : identifies the collapse dups button
		//*		string colBtn2ID : identifies the collapse remove button
		//*		string colGroupListID : identifies the group name list area
		//*		string colHiddenListID : identifies the hidden area of group names
		//*
		//*		-- called when Start Over button is pressed.  Resets all
		//*		values to initial settings, and restores the check box area.
		//*
		function onCollapseStartOver(colPopID, colPopTxtBoxID, colBtnStartID, colBtn2ID, colGroupListID, colHiddenListID, colBtn3ID, ddlVarID)
		{
			var objColTxtBox = getObject(colPopTxtBoxID);
			var objColStartBtn = getObject(colBtnStartID);
			//var objColBtn1 = getObject(colBtn1ID);
			var objColBtn2 = getObject(colBtn2ID);
			var objColBtn3 = getObject(colBtn3ID);
			var objColGroupList = getObject(colGroupListID);
			var objColHiddenList = getObject(colHiddenListID);

			collapseCnts.put(colPopID, 0);
			
			GroupNames.put(colPopID, new Array());
			NewGroupNames.put(colPopID, new Array());
			objColGroupList.innerHTML = "";
			objColHiddenList.defaultValue = "";
			//objColHiddenList.value = "!!";
			objColHiddenList.disabled = false;
			
			if(ddlVarID != "")
			{
			    var objVarddl = getObject(ddlVarID);
			    objVarddl.disabled = false;
			}
			
			if (!objColTxtBox)
			{
				//alert('No GroupName text box!');
				return;
			}

			var objColItems = getObject(colPopID);
			if (objColItems)
			{
				var objDiv = objColItems.parentNode;
				if (objDiv)
					objDiv.innerHTML = collapseArea.get(colPopID);
			}
			
						
			var colPopItems = collapsePops.get(colPopID);
			if (colPopItems != null)
			{
				for (i=0; i<colPopItems.length; i++)
				{
					var objColItem = getObject(colPopItems[i]);
					if (objColItem)
					{
						objColItem.checked = false;
					}
				}
			}	
			//if(chkAllID.checked == true)
			//	chkAllID.checked = false;
						
			objColTxtBox.disabled = true;
			//objColTxtBox.text = "New Group Name";
			EnableButton(objColStartBtn, btnStrtImage, btnStrtImageHvr);
			//DisableButton(objColBtn1, btnDupsImageDis);
			DisableButton(objColBtn2, btnRemvImageDis);
			DisableButton(objColBtn3, btnImgRmvDis);
			objColTxtBox.value = "New Group Name";
		}
		//*****************************************************************
		//* function isGroupNameValid
		//*
		//*		string GroupName : group name to validate
		//*
		//*		returns: true if GroupName is valid, otherwise false.
		//*
		//*		-- checks for illegal characters in group name, and
		//*		determines whether or not group name was already used.
		//*
		function isGroupNameValid(colPopID, GroupName)
		{
			if ((GroupName.indexOf("$") != -1) ||
				(GroupName.indexOf("<") != -1) ||
				(GroupName.indexOf(">") != -1) ||
				(GroupName.indexOf("?") != -1) ||
				(GroupName.indexOf("\\") != -1) ||
				(GroupName.indexOf("[") != -1) ||
				(GroupName.indexOf("]") != -1) ||
				(GroupName.indexOf(",") != -1) ||
				(GroupName.indexOf(".") != -1) ||
				(GroupName.indexOf(";") != -1) ||
				(GroupName.indexOf("{") != -1) ||
				(GroupName.indexOf("}") != -1) ||
				(GroupName.indexOf("|") != -1) ||
				(GroupName.indexOf("%") != -1) ||
				(GroupName.indexOf("&") != -1) ||
				(GroupName.indexOf("#") != -1) ||
				(GroupName.indexOf("!") != -1) ||
				(GroupName.indexOf("~") != -1) ||
				(GroupName.indexOf("’") != -1) ||
				(GroupName.indexOf("‘") != -1) ||
				(GroupName.indexOf("^") != -1) ||
				(GroupName.indexOf("`") != -1) ||
				(GroupName.indexOf("*") != -1) ||
				(GroupName.indexOf('"') != -1) ||
				(GroupName.indexOf("'") != -1) )
			{
				var errString = "Group Name can have letters and numbers only ";
				alert(errString);
				return false;
			}

			var gn = GroupNames.get(colPopID);			
			for (i=0; i<gn.length; i++)
			{
				if (GroupName == gn[i].toString().substring(1))
				{
					alert('Group Name already exists.  Please enter a different name.');
					return false;
				}
			}
			
			var ngn = NewGroupNames.get(colPopID);
			for (i=0; i<ngn.length; i++)
			{
				if (GroupName == ngn[i])
				{
					alert('Group Name already exists.  Please enter a different name.');
					return false;
				}
			}
			
			return true;
		}
		
//*****************************************************************
//*****************function trimString
//*****************************************************************

    function trimString(str) 
    {
	    while (str.charAt(0) == ' ')
		    str = str.substring(1);
	    while (str.charAt(str.length - 1) == ' ')
		    str = str.substring(0, str.length - 1);
	    return str;
    }
		
		//*****************************************************************
		//* function onCollapseKeep
		//*
		//*		string colPopID : identifies the collapse list
		//*		string colPopTxtBoxID : identifies the group name text box
		//*		string colBtn1ID : identifies the collapse dups button
		//*		string colBtn2ID : identifies the collapse remove button
		//*		string colGroupListID : identifies the group name list area
		//*		string colHiddenListID : identifies the hidden area of group names
		//*
		//*		-- called when Collapse Remove button is pressed.  Gets all
		//*		selected items and assigns them to the group name entered.
		//*		The items are added as an array in the hidden group name
		//*		area.  The group name is prefixed with $R to indicate that
		//*		these items should be removed.  The new group name is also
		//*		added to the visible group list.
		//*
		function onCollapseKeep(colPopID, colPopTxtBoxID, colBtn2ID, colGroupListID, colHiddenListID, colBtn3ID)
		{
			var objColTxtBox = getObject(colPopTxtBoxID);
			//var objColBtn1 = getObject(colBtn1ID);
			var objColBtn2 = getObject(colBtn2ID);
			//new add
			var objColBtn3 = getObject(colBtn3ID);
			//
			var objColPopID = getObject(colPopID);
			var objColGroupList = getObject(colGroupListID);
			var objColHiddenList = getObject(colHiddenListID);
			
			var txtGroupName = objColTxtBox.value;
			txtGroupName = trimString(txtGroupName);
			
			if (txtGroupName == "")
			{
				alert('Please enter a Group Name');
				return;
			}
			
			if (!isGroupNameValid(colPopID, txtGroupName))
				return;

			var ngLength = NewGroupNames.get(colPopID).length;
			NewGroupNames.get(colPopID)[ngLength] = txtGroupName;
			
			var newChkItem = document.createElement('input');
			newChkItem.type = "checkbox";
			newChkItem.id = txtGroupName;
			newChkItem.name = txtGroupName;
			//newChkItem.onclick = "onGroupItemChecked('" + txtGroupName + "')" ;
			objColGroupList.appendChild(newChkItem);
			
			objColGroupList.innerHTML += "<b>&nbsp;&nbsp;" + txtGroupName + " [</b>";
			
			objColHiddenList.value += "$" + txtGroupName + "[";
			var colPopItems = collapsePops.get(colPopID);
			
			if (colPopItems != null)
			{
				for (i=0; i<colPopItems.length; i++)
				{
					var objColItem = getObject(colPopItems[i]);
					var chkText = "";
					//var newChkItem = document.createElement('input');
					//newChkItem.type = "checkbox";
					//newChkItem.id = objColItem.parentNode.defaultValue;
					//newChkItem.name = txtGroupName + " (";
					//var objNewChkItem = getObject(newChkItem);
					//newChkItem.outerHTML = "someText"
					//newChkItem.innerText = "someText"
					//objColPopID.appendChild(newChkItem)
					//objColGroupList.appendChild(newChkItem);
					
					if (objColItem)
					{
						if (objColItem.checked)
						{
							var lbl = objColItem.parentNode.getElementsByTagName('label');
							if (objColItem.parentNode.attributes[objColItem.parentNode.attributes.length-1].name.toUpperCase() == "DEFAULTVALUE")
							{	
							    objColHiddenList.value += objColItem.parentNode.attributes[objColItem.parentNode.attributes.length-1].value;
							    objColHiddenList.value += "|" + lbl[0].innerHTML ;//objColItem.nextSibling.innerHTML;
							    chkText += objColItem.parentNode.attributes[objColItem.parentNode.attributes.length-1].value;
								//newChkItem.id += objColItem.parentNode.attributes[objColItem.parentNode.attributes.length-1].value;
								//newChkItem.name += objColItem.parentNode.attributes[objColItem.parentNode.attributes.length-1].value;
								//newChkItem.outerText += objColItem.parentNode.attributes[objColItem.parentNode.attributes.length-1].value;
							}
							else 
							{
								objColHiddenList.value += objColItem.parentNode.defaultValue;
								objColHiddenList.value += "|" + lbl[0].innerHTML ;//objColItem.parentNode.innerText;
								 chkText += objColItem.parentNode.defaultValue;
								//newChkItem.id += objColItem.parentNode.defaultValue + ",";
								//newChkItem.name += objColItem.parentNode.defaultValue + ",";
								//newChkItem.outerText += objColItem.parentNode.defaultValue + ",";
							}
							objColHiddenList.value += ",";
							chkText += ",";
							objColGroupList.innerHTML += chkText; 
							objColItem.checked = false;
							// parent1=<span>, parent2=<td>, parent3=<tr>
							var objParent = objColItem.parentNode.parentNode.parentNode;
							//objParent.parentNode.removeChild(objParent);
						}
					}
				}
			}
			objColHiddenList.value = objColHiddenList.value.substring(0, (objColHiddenList.value.length-1)) + "]";
			//objColHiddenList.value += "]\r\n";
			objColGroupList.innerHTML = objColGroupList.innerHTML.substring(0, (objColGroupList.innerHTML.length-1));
			
			objColGroupList.innerHTML += "<b>]</b> ";
			//objColGroupList.appendChild(newChkItem);
			objColGroupList.innerHTML += "<br> ";
			objColHiddenList.disabled = false;
			
			//objColPopID.appendChild(newChkItem)
			//objColGroupList.appendChild(newChkItem);		
						
			objColTxtBox.value = "";
			objColTxtBox.disabled = true;
			
			//if(chkAllID.checked == true)
			//	chkAllID.checked = false;
				
			//DisableButton(objColBtn1, btnDupsImageDis);
			DisableButton(objColBtn2, btnRemvImageDis);
			EnableButton(objColBtn3, btnImgRmvHvr, btnImgRmvHvr);

			collapseCnts.put(colPopID, 0);
		}
		
//*****************************************************************
		//* function onRemoveClick
		//*
		
		//*
		function onRemoveClick(colPopID, colBtn3ID, colGroupListID, colHiddenListID)
		{
			//var objColTxtBox = getObject(colPopTxtBoxID);
			//var objColBtn1 = getObject(colBtn1ID);
			var objColBtn3 = getObject(colBtn3ID);
			var objColPopID = getObject(colPopID);
			var objColGroupList = getObject(colGroupListID);
			var objColHiddenList = getObject(colHiddenListID);
			var d = objColGroupList.getElementsByTagName("input");
            //var t = d.length;
            var objColGroupListText = "";
            var objColHiddenListText = "$";
            
            var arrayGroupList = new Array();
            arrayGroupList = objColGroupList.innerHTML.split("<BR>");
            
            var arrayHiddenList = new Array();
            arrayHiddenList = objColHiddenList.value.split("$");
            
            var checkedCount=0;
            for (var i=0; i<d.length; i++)
            {
                var objChkBoxChecked = getObject(d[i].id);
                if(objChkBoxChecked.checked)
                    checkedCount++;                    
            }
            if(checkedCount == 0)
            {
		        alert('Please check at least one item from My Jurisdictions to remove');
		        return;
	        }    
            for (var x=0; x<d.length; x++)
            {
                var objChkBox = getObject(d[x].id);                               
                if(objChkBox.checked)
                {
                    //alert("IT IS CHECKED");
                   //objColGroupList.removeChild(objChkBox)
                   arrayGroupList[x] = "";
                   arrayHiddenList[x + 1] = "";
                   //x--;
                }
                else
                {
                    objColGroupListText += arrayGroupList[x] + "<br>";
                    objColHiddenListText += arrayHiddenList[x + 1] + "$";
                }
            }
            
            objColGroupList.innerHTML = objColGroupListText;
            objColHiddenList.value = objColHiddenListText;
		}
		
//*****************************************************************		

//*****************************************************************
		//* function onVarRemoveClick
		//*
		
		//*
		function onVarRemoveClick(colPopID, colBtn3ID, colGroupListID, colHiddenListID, hiddenID)
		{
			//var objColTxtBox = getObject(colPopTxtBoxID);
			//var objColBtn1 = getObject(colBtn1ID);
			var objColBtn3 = getObject(colBtn3ID);
			var objColPopID = getObject(colPopID);
			var objColGroupList = getObject(colGroupListID);
			var objColHiddenList = getObject(colHiddenListID);
			var d = objColGroupList.getElementsByTagName("input");
            //var t = d.length;
            var objColGroupListText = "";
            var objColHiddenListText = "$";
            
            var arrayGroupList = new Array();
            arrayGroupList = objColGroupList.innerHTML.split("<BR>");
            
            var arrayHiddenList = new Array();
            arrayHiddenList = objColHiddenList.value.split("$");
            
            var checkedCount=0;
            for (var i=0; i<d.length; i++)
            {
                var objChkBoxChecked = getObject(d[i].id);
                if(objChkBoxChecked.checked)
                    checkedCount++;                    
            }
            if(checkedCount == 0)
            {
		        alert('Please check at least one item from My Jurisdictions to remove');
		        return;
	        }    
            for (var x=0; x<d.length; x++)
            {
                var objChkBox = getObject(d[x].id);                               
                if(objChkBox.checked)
                {
                    //alert("IT IS CHECKED");
                   //objColGroupList.removeChild(objChkBox)
                   arrayGroupList[x] = "";
                   arrayHiddenList[x + 1] = "";
                   //x--;
                }
                else
                {
                    objColGroupListText += arrayGroupList[x] + "<br>";
                    objColHiddenListText += arrayHiddenList[x + 1] + "$";
                }
            }
            
            objColGroupList.innerHTML = objColGroupListText;
            objColHiddenList.value = objColHiddenListText;
		}
		
//*****************************************************************		
		
//*****************************************************************
		//* function moveObject		
//*****************************************************************
function moveObject(objectId, newXCoordinate, newYCoordinate) 
{
    var styleObject = getStyleObject(objectId);
    if(styleObject) 
    {
	 styleObject.position = 'absolute';
	 styleObject.left = newXCoordinate;
	 styleObject.top = newYCoordinate;
	 return true;
    } else {
	return false;
    }
} 

//*****************************************************************
		//* function moveObject	
//*****************************************************************
function changeObjectVisibility(objectId, newVisibility) 
{
    var styleObject = getStyleObject(objectId);
    if(styleObject) 
    {
		styleObject.visibility = newVisibility;
		return true;
    } 
    else 
    {
		//alert('no style: ' + objectId);
		return false;
    }
}
//*****************************************************************
		//* function hidePop	
//*****************************************************************
function hidePop(popID)
{
	changeObjectVisibility(popID, 'hidden');
	
	if (pdePopOn)
		endPopMove(event);
	
	if (popID == pdePopId)
	{
		pdePopId = '';
		pdeLoaded = false;
		
		if (ie && (pdeSelId != '')){
			selcIdStyle = getStyleObject(pdeSelId);
			if (selcIdStyle)
			{
				selcIdStyle.position = '';
				selcIdStyle.clip = 'rect(auto auto auto auto)';
			}
			
			//changeObjectVisibility(pdeSelId, 'visible');
		}
		if (ie && (selCtrlIDs.length > 0))
			showSelectObjects();
			
	}
}
//*****************************************************************
		//* function hidePop	
//*****************************************************************
function hidePop(popID)
{
	changeObjectVisibility(popID, 'hidden');
	
	if (pdePopOn)
		endPopMove(event);
	
	if (popID == pdePopId)
	{
		pdePopId = '';
		pdeLoaded = false;
		
		if (ie && (pdeSelId != '')){
			selcIdStyle = getStyleObject(pdeSelId);
			if (selcIdStyle)
			{
				selcIdStyle.position = '';
				selcIdStyle.clip = 'rect(auto auto auto auto)';
			}
			
			//changeObjectVisibility(pdeSelId, 'visible');
		}
		if (ie && (selCtrlIDs.length > 0))
			showSelectObjects();
			
	}
}
//*****************************************************************
		//* function movePop	
//*****************************************************************
function movePop(eventObj)
{
	if (!event && !eventObj)
		return;
		
	x = (nav)?eventObj.pageX:event.clientX+document.body.scrollLeft;
	y = (nav)?eventObj.pageY:event.clientY+document.body.scrollTop;
	
	moveObject(pdePopId, x-pdePopXOffset, y-pdePopYOffset);

	var obj = getObject(pdePopId);
	if (ie && (selCtrlIDs.length > 0))
		hideSelectObjects(x, y, obj.offsetWidth, obj.offsetHeight);		 
}

//*****************************************************************
		//* function endPopMove	
//*****************************************************************

function endPopMove(eventObj)
{
	if (!event && !eventObj)
		return;
		
	var obj = getObject(pdePopId);
	if (obj && pdeLoaded)
	{
		var styobj = getStyleObject(pdePopId);
		if (styobj)
			styobj.cursor = 'default';

		x = (nav)?eventObj.pageX:event.clientX+document.body.scrollLeft;
		y = (nav)?eventObj.pageY:event.clientY+document.body.scrollTop;

		pdePopX = x-pdePopXOffset;
		pdePopY = y-pdePopYOffset;
		moveObject(pdePopId, pdePopX, pdePopY);

		obj.onmouseup = null;
		obj.onmousemove = null;

		if (ie && (selCtrlIDs.length > 0))
		{
			showSelectObjects();
			hideSelectObjects(x, y, obj.offsetWidth, obj.offsetHeight);		 
		}
	}
	
	pdePopXStart=0;
	pdePopYStart=0;
	pdePopXOffset=0;
	pdePopYOffset=0;
	
	pdePopOn=false;
	
	document.onmouseup = null;
	document.onmousemove = null;
}
//******************************** onClientDoneClick  ***************************************
function onClientDoneClick(colPopTxtBoxID, colHiddenListID, colPopID, strVarCode)
{
    var objColTxtBox = getObject(colPopTxtBoxID);
    var txtGroupName = objColTxtBox.value;
    var objChkBoxList = getObject(colPopID);
    var colPopItems = collapsePops.get(colPopID);
    var colPopCnt = colPopItems.length;
    var objColHiddenList = getObject(colHiddenListID);
    
    if(objColHiddenList.value != "")
    {
//        for (i=0; i<colPopItems.length; i++)
//	    {
//		    var objColItem = getObject(colPopItems[i]);
//    		
//		    if (objColItem)
//		    {
//		        var lbl = objColItem.parentNode.getElementsByTagName('label');
//		        objColHiddenList.value += "$" + lbl[0].innerHTML  + "[" + objColItem.parentNode.attributes[objColItem.parentNode.attributes.length-1].value; 
//		        objColHiddenList.value += "|" + lbl[0].innerHTML  + "]";
//		        objColHiddenList.value += "^" + strVarCode;
//		    }
//	    }
	    //objColHiddenList.value += "~" + txtGroupName;
	    
	    var aryNewVarVals = new Array();
	    
	    var strNewVarVals = txtGroupName + "~";
	    
	    for (i=0; i<colPopItems.length; i++)
        {
	        var objColItem = getObject(colPopItems[i]);
    		
	        if (objColItem)
	        {
	            var lbl = objColItem.parentNode.getElementsByTagName('label');
	            strNewVarVals += lbl[0].innerHTML  + "[" + objColItem.parentNode.attributes[objColItem.parentNode.attributes.length-1].value; 
	            strNewVarVals += "|" + lbl[0].innerHTML  + "]";
	            strNewVarVals += "^" + strVarCode + "$" ;
	        }
        }
        //strNewVarVals = strNewVarVals.substring(0, strNewVarVals.length-1);
        objColHiddenList.value = objColHiddenList.value.substring(1, objColHiddenList.value.length);
	    strNewVarVals += objColHiddenList.value;
	    aryNewVarVals = strNewVarVals.split("$");
	    strNewVarVals="";
	    for(var i=0; i<aryNewVarVals.length; i++)
	    {
	        if(aryNewVarVals[i] != "")
	            strNewVarVals += aryNewVarVals[i] + "*" + (i+1) + "$";
	        
	    }
	    strNewVarVals = strNewVarVals.substring(0, strNewVarVals.length-1);
	    objColHiddenList.value = strNewVarVals;
	    	
	}	
    
    
        
}

//*********************************************************************************************
		//* function onCollapseRemoveItems
		//*
		//*		string colPopID : identifies the collapse list
		//*		string colPopTxtBoxID : identifies the group name text box
		//*		string colBtn1ID : identifies the collapse dups button
		//*		string colBtn2ID : identifies the collapse remove button
		//*		string colGroupListID : identifies the group name list area
		//*		string colHiddenListID : identifies the hidden area of group names
		//*
		//*		-- called when Collapse Remove button is pressed.  Gets all
		//*		selected items and assigns them to the group name entered.
		//*		The items are added as an array in the hidden group name
		//*		area.  The group name is prefixed with $R to indicate that
		//*		these items should be removed.  The new group name is also
		//*		added to the visible group list.
		//*
		function onCollapseRemoveItems(colPopID, colPopTxtBoxID, colBtn2ID, colGroupListID, colHiddenListID, colBtn3ID, hiddenID, strVarCode, newVarValTxtBoxID, ddlVarID)
		{
			var objColTxtBox = getObject(colPopTxtBoxID);
			//var objColBtn1 = getObject(colBtn1ID);
			var objColBtn2 = getObject(colBtn2ID);
			//new add
			var objColBtn3 = getObject(colBtn3ID);
			var objHiddenID = getObject(hiddenID);
			//
			var objColPopID = getObject(colPopID);
			var objColGroupList = getObject(colGroupListID);
			var objColHiddenList = getObject(colHiddenListID);
			
			var objVarValTxtBoxID = getObject(newVarValTxtBoxID);
			
			var objDdlVarID = getObject(ddlVarID);
			
			var txtGroupName = objColTxtBox.value;
			txtGroupName = trimString(txtGroupName);
			if(txtGroupName == "")
			{
			    alert('Please enter a name for new variable value');
			    objColTxtBox.focus();
			    return;
			}
					
			var txtVarValName = objVarValTxtBoxID.value;
			txtVarValName = trimString(txtVarValName);
			
			for(var i=0; i<objDdlVarID.options.length; i++)
			{
			    if(txtVarValName == objDdlVarID.options[i].text)
			    {
			        alert('This variable name already exists.  Please type a different name');
			        objVarValTxtBoxID.focus();
			        return;
			    }
			}
			
//			if (txtGroupName == "")
//			{
//				alert('Please enter a Group Name');
//				return;
//			}
			
			if (!isGroupNameValid(colPopID, txtGroupName))
				return;
	
			var ngLength = NewGroupNames.get(colPopID).length;
			NewGroupNames.get(colPopID)[ngLength] = txtGroupName;
			
			var newChkItem = document.createElement('input');
			newChkItem.type = "checkbox";
			newChkItem.id = txtGroupName;
			newChkItem.name = txtGroupName;
			//newChkItem.onclick = "onGroupItemChecked('" + txtGroupName + "')" ;
			objColGroupList.appendChild(newChkItem);
			
			objColGroupList.innerHTML += "<b>&nbsp;&nbsp;" + txtGroupName + " [</b>";			
			//objColGroupList.innerHTML += "<b>&nbsp;&nbsp;" + txtVarValName + " [</b>";
			
			objColHiddenList.value += "$" + txtGroupName + "[";			
			//objColHiddenList.value += "[";
			
			var colPopItems = collapsePops.get(colPopID);
			
			if (colPopItems != null)
			{
				for (i=0; i<colPopItems.length; i++)
				{
					var objColItem = getObject(colPopItems[i]);
					var chkText = "";
					//var newChkItem = document.createElement('input');
					//newChkItem.type = "checkbox";
					//newChkItem.id = objColItem.parentNode.defaultValue;
					//newChkItem.name = txtGroupName + " (";
					//var objNewChkItem = getObject(newChkItem);
					//newChkItem.outerHTML = "someText"
					//newChkItem.innerText = "someText"
					//objColPopID.appendChild(newChkItem)
					//objColGroupList.appendChild(newChkItem);
					
					if (objColItem)
					{
						if (objColItem.checked)
						{
						    var lbl = objColItem.parentNode.getElementsByTagName('label');
							if (objColItem.parentNode.attributes[objColItem.parentNode.attributes.length-1].name.toUpperCase() == "DEFAULTVALUE")
							{	
							    objColHiddenList.value += objColItem.parentNode.attributes[objColItem.parentNode.attributes.length-1].value;
							    objColHiddenList.value += "|" + lbl[0].innerHTML ;
							    chkText += lbl[0].innerHTML; //objColItem.parentNode.attributes[objColItem.parentNode.attributes.length-1].value;
							    //objHiddenID += objColItem.parentNode.attributes[objColItem.parentNode.attributes.length-1].value + "|" + lbl[0].innerHTML;
								//newChkItem.id += objColItem.parentNode.attributes[objColItem.parentNode.attributes.length-1].value;
								//newChkItem.name += objColItem.parentNode.attributes[objColItem.parentNode.attributes.length-1].value;
								//newChkItem.outerText += objColItem.parentNode.attributes[objColItem.parentNode.attributes.length-1].value;
							}
							else 
							{
								objColHiddenList.value += objColItem.parentNode.defaultValue;
								objColHiddenList.value += "|" + lbl[0].innerHTML ;
								 chkText += objColItem.parentNode.defaultValue;
								//newChkItem.id += objColItem.parentNode.defaultValue + ",";
								//newChkItem.name += objColItem.parentNode.defaultValue + ",";
								//newChkItem.outerText += objColItem.parentNode.defaultValue + ",";
							}
							objColHiddenList.value += ",";
							chkText += ",";
							objColGroupList.innerHTML += chkText; 
							objColItem.checked = false;
							// parent1=<span>, parent2=<td>, parent3=<tr>
							var objParent = objColItem.parentNode.parentNode.parentNode;
							objParent.parentNode.removeChild(objParent);
						}
					}
				}
			}
			objColHiddenList.value = objColHiddenList.value.substring(0, (objColHiddenList.value.length-1)) + "]";
			objColHiddenList.value += "^" + strVarCode;
			//objColHiddenList.value += "]\r\n";
			objColGroupList.innerHTML = objColGroupList.innerHTML.substring(0, (objColGroupList.innerHTML.length-1));
			
			objColGroupList.innerHTML += "<b>]</b> ";
			//objColGroupList.appendChild(newChkItem);
			objColGroupList.innerHTML += "<br> ";
			objColHiddenList.disabled = false;
			
			document.getElementById(hiddenID).value = encode64(objColGroupList.innerHTML);  //encodeGrpText(objColGroupList.innerHTML); //objColHiddenList.value;
			//objColPopID.appendChild(newChkItem)
			//objColGroupList.appendChild(newChkItem);		
						
			objColTxtBox.value = "";
			//objVarValTxtBoxID.value = "";
			objColTxtBox.disabled = true;
			
			//if(chkAllID.checked == true)
			//	chkAllID.checked = false;
				
			//DisableButton(objColBtn1, btnDupsImageDis);
			DisableButton(objColBtn2, btnRemvImageDis);
			EnableButton(objColBtn3, btnImgRmvHvr, btnImgRmvHvr);

			collapseCnts.put(colPopID, 0);
		}
		
//*****************************************************************

function encodeGrpText(encodedHtml) {
     encodedHtml = escape(encodedHtml);
     encodedHtml = encodedHtml.replace(/\//g,"%2F");
     encodedHtml = encodedHtml.replace(/\?/g,"%3F");
     encodedHtml = encodedHtml.replace(/=/g,"%3D");
     encodedHtml = encodedHtml.replace(/&/g,"%26");
     encodedHtml = encodedHtml.replace(/@/g,"%40");
     return encodedHtml;
   } 

//*****************************************************************
		//* function 
//*****************************************************************


// Browser Detect  v2.1.6
// documentation: http://www.dithered.com/javascript/browser_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)


function BrowserDetect() {
   var ua = navigator.userAgent.toLowerCase(); 

   // browser engine name
   this.name		  = ua;
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

   // browser name
   this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
   this.isSafari      = (ua.indexOf('safari') != - 1);
   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
   this.isOpera       = (ua.indexOf('opera') != -1); 
   this.isIcab        = (ua.indexOf('icab') != -1); 
   this.isAol         = (ua.indexOf('aol') != -1); 
   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirebird    = (ua.indexOf('firebird/') != -1);
   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac    = (ua.indexOf('mac') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetect();

// if IE5.5+ on Win32, then display PNGs with AlphaImageLoader
if ((browser.isIE55 || browser.isIE6up) && browser.isWin32) 
{
	var pngAlpha = true;
// else, if the browser can display PNGs normally, then do that
} else if ((browser.isGecko) || (browser.isIE5up && browser.isMac) || 
	(browser.isOpera && browser.isWin && browser.versionMajor >= 6) || 
	(browser.isOpera && browser.isUnix && browser.versionMajor >= 6) || 
	(browser.isOpera && browser.isMac && browser.versionMajor >= 5) || 
	(browser.isOmniweb && browser.versionMinor >= 3.1) || 
	(browser.isIcab && browser.versionMinor >= 1.9) || 
	(browser.isWebtv) || (browser.isDreamcast)) 
{
	var pngNormal = true;
}


/////////////////////////////////////////////////////////////////////////////
    //Modal dialog (popup) window functions

    var ModalDialogWindow;
    var ModalDialog = new Object();

    ModalDialog.eventhandler = '';


    // OpenModalWindow - function to open a modal window.
    // Note: Call this function from the PARENT (opener) window. 
    function OpenModalWindow (URL, URLParms, Width, Height, ReturnEventHandler)
    {
        // uid uses current time to make a unique id for this request so that the modal window will always
        // be reloaded (and the Page_Load event in the modal window will be fired) when it is opened.  
        var parms = "uid=" + (new Date()).getTime() + "&" + URLParms;
        

        if (ReturnEventHandler)
            ModalDialog.eventhandler = ReturnEventHandler;

        // showModalDialog is supported only by IE
        if (window.showModalDialog)
        {
            var args = 'dialogWidth:' + Width + 'px;dialogHeight:' + Height + 'px;';
            
    //        window.showModalDialog ("DialogWindow_IFrame.htm", URL + '?' + parms, args);
            ModalDialog.value = window.showModalDialog (URL + '?' + parms, '', args);
            
            if (ModalDialog.value && ModalDialog.eventhandler)
                eval(ModalDialog.eventhandler);       
        }
        else
        {
            var args = 'width=' + Width + ',height=' + Height + ',';
            args += 'toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,modal=yes' ;
            ModalDialogWindow = window.open (URL + '?' + parms, '', args);
            ModalDialogInterval = window.setInterval("ModalDialogMaintainFocus()", 3);
        }
    }


    function ModalDialogMaintainFocus()
    {
        try
        {
            if (ModalDialogWindow.closed)
            {
                window.clearInterval(ModalDialogInterval);
                
                if (ModalDialog.value && ModalDialog.eventhandler)
                    eval(ModalDialog.eventhandler);       
                    
                return;
            }
            ModalDialogWindow.focus(); 
        }
        catch (everything) {   }
    } 


    // CloseModalWindow - function to close the modal window.
    // Note: Call this function from the CHILD (modal) window.
    function CloseModalWindow (ReturnObject)
    {
        if (window.showModalDialog)
            window.returnValue = ReturnObject;
        else
            window.opener.ModalDialog.value = ReturnObject;

        
        window.close();
    }
    
    ///////////////////////////////////////////////////////////////////////////////////
    
    var keyStr = "ABCDEFGHIJKLMNOP" +
                "QRSTUVWXYZabcdef" +
                "ghijklmnopqrstuv" +
                "wxyz0123456789+/" +
                "=<>\\`~^%$#@!|)(*&-_+'\";:?,.[]";

   function encode64(input) {
      var output = "";
      var chr1, chr2, chr3 = "";
      var enc1, enc2, enc3, enc4 = "";
      var i = 0;

      do {
         chr1 = input.charCodeAt(i++);
         chr2 = input.charCodeAt(i++);
         chr3 = input.charCodeAt(i++);

         enc1 = chr1 >> 2;
         enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
         enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
         enc4 = chr3 & 63;

         if (isNaN(chr2)) {
            enc3 = enc4 = 64;
         } else if (isNaN(chr3)) {
            enc4 = 64;
         }

         output = output +
            keyStr.charAt(enc1) +
            keyStr.charAt(enc2) +
            keyStr.charAt(enc3) +
            keyStr.charAt(enc4);
         chr1 = chr2 = chr3 = "";
         enc1 = enc2 = enc3 = enc4 = "";
      } while (i < input.length);

      return output;
  }
   
   
   function decode64(input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
		while (i < input.length) {
 
			enc1 = keyStr.indexOf(input.charAt(i++));
			enc2 = keyStr.indexOf(input.charAt(i++));
			enc3 = keyStr.indexOf(input.charAt(i++));
			enc4 = keyStr.indexOf(input.charAt(i++));
 
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
 
			output = output + String.fromCharCode(chr1);
 
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
 
		}

		output = utf8_decode64(output);
 
		return output;
 
	}

	function utf8_decode64(utftext)
	{
	    var string = "";
	    var i = 0;
	    var c = c1 = c2 = 0;

	    while (i < utftext.length)
	    {

	        c = utftext.charCodeAt(i);

	        if (c < 128)
	        {
	            string += String.fromCharCode(c);
	            i++;
	        }
	        else if ((c > 191) && (c < 224))
	        {
	            c2 = utftext.charCodeAt(i + 1);
	            string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
	            i += 2;
	        }
	        else
	        {
	            c2 = utftext.charCodeAt(i + 1);
	            c3 = utftext.charCodeAt(i + 2);
	            string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
	            i += 3;
	        }

	    }

	    return string;
	}



