
function appendToHandler(sHandler,sFunctions) {

	if (isIE()) {

		eventDOMref = "document.body.";
	}
	if (isNetscape()) {

		eventDOMref = "parent.";
	}
	if (eval(eventDOMref + sHandler + " != null")) {
		tempString = eval(eventDOMref + sHandler + ".toString()");
		handlerString = tempString.substring(tempString.indexOf("{") + 1,tempString.length - 2);
	} else {
	 	handlerString = "";
	}
	handlerString = handlerString + sFunctions;
	eval(eventDOMref + sHandler + " = new Function(handlerString);");

}







function ListControl_object ( sID,iDefaultHeight, iMinWidth, iMaxWidth, iMinHeight, iMaxHeight )
{

	this.toolBar = new Toolbar_object();
	this.toolBar.listControlID = sID;
	this.toolBar.listViewRef = this;
	this.toolBar.parentObject = this;
	this.assetList = new AssetList_object();
	this.containerAsset = null;
	this.header = null;
	this.selectedAssetList = null;


	this.pathMenu = null;
	this.pathBar = null;
	this.listScroller = null;
	this.theTD = null;
	this.listView = null;
	this.gridTable = null;
	this.formObject = null;
	this.toolbarDIV = null;
	this.listScrollerTD = null;


	this.ID = sID;
	this.defaultHeight = iDefaultHeight;
	this.minWidth = iMinWidth;
	this.maxWidth = iMaxWidth;
	this.minHeight = iMinHeight;
	this.maxHeight = iMaxHeight;
	this.currentHeight = 0;
	this.origHeight = 0;
	this.origWidth = 0;
	this.lastWidth = 0;
	this.listViewOffsetHeight  = 0;
	this.listViewOffsetWidth  = 0;
	this.windowOffsetHeight = 0;
	this.bodyOffset = 0;
	this.objType="listControl";
	this.parentObject = null;


	this.firstPass = true;
	this.startScroll = false;
	this.embedded = false;
	this.checkBoxState = false;
	this.pathVisible = false;


	if (this.minHeight < 50) this.minHeight = 50;
	if (this.minWidth < 200) this.minWidth = 200;
	if ((iDefaultHeight < iMinHeight) && (iDefaultHeight != 0)) {
		alert('spf:listView: ListControl default height is smaller than minimum height.');
	}
	if ((iDefaultHeight > iMaxHeight) && (iMaxHeight != 0)){
		alert('spf:listView: ListControl default height is greater than maximum height.');
	}
	if (((iMinWidth > iMaxWidth) || (iMinHeight > iMaxHeight)) && (iMaxHeight != 0) && (iMaxWidth != 0)) {
		alert('spf:listView: Please check your minimum and maximum widths and heights.');
	}
	if (arguments.length < 6)
		alert ('spf:listView: ListControl_object - please use all constructor arguments')
}







ListControl_object.prototype.fixPage = function() {
	// event handler for onresize event - jiggles everything around

	//set some browser-constrained constants
	if (IE) {
		curWinHeight = document.body.clientHeight;
		curWinWidth = document.body.clientWidth;

		scrollMod = 0;

		listMod = !!document.getElementById("table_tabs") * 50 ;
		rightListMargin = 20;
	} else if (NN) {
		curWinHeight = window.innerHeight;
		curWinWidth = window.innerWidth;
		scrollMod = 35;
		listMod = !!document.getElementById("table_tabs") * 50 + 30;
		rightListMargin = 30;
		tableArr = document.getElementsByTagName("table");
		tableArr[0]=curWinWidth;
		
	}
		
	// Height Management
	switch (this.defaultHeight) {
	// positioning modifiers based on menuType
		case -1: {
			// portlet flag; no vertical scrolling
			if (IE) {
				parentObject = this.listView;
				sizeObject = this.listScroller;
				intervalID = setInterval('waitForDraw()',50);
			}
		} break;
		case 0: {
			// full page; browserHeight-based scrolling				
			// get positions of the listView and DIV
			listTop = getTop(this.listView);
			listLeft = getLeft(this.listView);
			scrollerTop = getTop(this.listScroller);
			
			//Width Management
			if (listLeft > 50) {
				// width not based on full-window width
				newWidth = curWinWidth - listLeft - rightListMargin;
				if (newWidth < this.minWidth) newWidth = this.minWidth;
				this.listScroller.style.width = newWidth - 2;
				this.listView.style.width = newWidth;
			} else {
				// width is full window
				theList=this.listScroller;
				newSize = curWinWidth - listLeft;
				if (newSize < this.minWidth) newSize = this.minWidth;
				if (NN) {
					this.listScrollerTD.style.width = newSize - 15;
					theList.style.width = this.listView.offsetWidth - 2;
					this.listScrollerTD.style.width = newSize - 15;
				}
				if (IE) {
						theList.style.width = newSize - rightListMargin;
						this.listView.style.width = newSize - rightListMargin -10;
				}
			}
					
			//Height Management
			this.listView.style.height = curWinHeight - listTop - scrollMod;
			this.listScroller.style.height =  curWinHeight - scrollerTop - scrollMod;
		} break;
		
		default: {
			// all other values for defaultHeight
			
			// Width Management
			listLeft = getLeft(this.listView);
			newWidth = curWinWidth - 20;
			theList=this.listScroller;
							
			if (theList.offsetWidth + listLeft + 30 > curWinWidth) {
				this.listScrollerTD.style.width = curWinWidth - listLeft - 6;
			}
			if (theList.offsetWidth + listLeft + 30 < curWinWidth) {
				this.listScrollerTD.style.width = curWinWidth - listLeft - 6;
			}
			theList.style.width = theList.parentNode.style.width;
			
			if (theList.clientWidth < curWinWidth - listLeft - 45) {
				if (IE) theList.style.width = this.listView.clientWidth;
				if (NN) theList.style.width = this.listView.offsetWidth - 2;
			}
			
			// Height Management
			listTop = getTop(this.listView);
			if (this.firstPass) {
				this.currentHeight = this.listView.offsetHeight;
				chromeHeight = this.listView.offsetHeight - this.listScroller.offsetHeight;
				this.bodyOffset = curWinHeight - listTop - this.currentHeight;
			}
			
			this.listScroller.style.height = this.defaultHeight;
			this.listView.style.height = this.defaultHeight + chromeHeight;
			
			newHeight = this.listView.parentNode.offsetHeight - chromeHeight -scrollMod;

			//uppper and lower bounds
			if (newHeight < this.minHeight) {
				newHeight = this.minHeight;
			}
			if (this.maxHeight != 0) {
				if ((newHeight) > this.maxHeight) {
					newHeight = this.maxHeight;
				}
			}
			
			this.listScroller.style.height = newHeight;
		}
	} // end switch statement

	

	if (this.pathMenu) {
		pathWidth = this.listScroller.offsetWidth - 200;
		if (pathWidth < 200) pathWidth = 200;
		this.pathBar.style.width = pathWidth;
 		this.pathMenu.fixPathWidth();
 	}
	
	this.firstPass = false;
}



ListControl_object.prototype.postOnLoad = function(sUniqueSuffix) {

	if (document.all) {
		this.origHeight = document.body.clientHeight;
	} else {
		this.origHeight = window.innerHeight;
	}
	
	if (this.embedded) {
		this.defaultHeight = -1;
	}
	
	if (true) {
		
		this.listViewOffsetHeight =  this.listScroller.offsetHeight;
		this.windowOffsetHeight = document.body.clientHeight - this.listView.offsetHeight;
		this.listViewOffsetWidth = document.body.clientWidth - this.listView.offsetWidth;
	}
	

	if (this.pathBar && document.getElementById("menuM0")) {
		tempStr = this.pathBar.value;
		tempStr = tempStr.substring(1,tempStr.length);
		if (tempStr.indexOf("/") > 0) {
			endStr = tempStr.indexOf("/")
		} else {
			endStr = tempStr.length;
		}
		rootProj = tempStr.substring(0,endStr);
		if (document.getElementById(rootProj)) {
			document.getElementById(rootProj).className = "vign-menuLinkMain1Roll";
		}
	}


	if (document.getElementById("actionFormatTable")  && document.getElementById("Home"))
		document.getElementById("Home").className = "vign-menuLinkMain1Roll";

	var refreshEl = document.getElementById(sUniqueSuffix + "_refreshFlag");
	if (refreshEl.value == "refreshMe") {
		window.location.reload(false);
	} else {

		refreshEl.value = refreshEl.defaultValue = "refreshMe";
	}

	this.doSelection(null);
	
}




ListControl_object.prototype.doSelection = function (oSelectorObject) {


	if (oSelectorObject != null) {

		selectorName = oSelectorObject.id;
		selectorState = oSelectorObject.checked;
		theAsset = this.assetList.assets[selectorName];
		theAsset.state = selectorState;
		if (selectorState) {

			this.selectedAssetList = addNode(theAsset,this.selectedAssetList);
		} else {

			if (this.selectedAssetList)
				this.selectedAssetList = removeNode(theAsset,this.selectedAssetList);
		}

		this.assetList.selectedCount += 1 - (2 * !selectorState);

		for (var i = 0; i < this.toolBar.actions.length; i++) {

			thisAction = this.toolBar.actions[i];
			theSelectedAsset = this.selectedAssetList;

			newURLState = true;
			newACLState = true;
			newMinMaxState = true;

			if (theSelectedAsset) {
				while (theSelectedAsset) {

					thisAssetActionMapNode = theSelectedAsset.objRef.actionMap[thisAction.ID];
					if (thisAssetActionMapNode) {

						newURLState =  newURLState && (this.doURLs(thisAssetActionMapNode.actionURL,thisAction));
					} else {

						thisAssetActionMapNode = this.containerAsset.actionMap[thisAction.ID];
					}
					if (thisAssetActionMapNode) {
						newACLState = newACLState && thisAssetActionMapNode.authzn;
					} else {

						newACLState = false;
					}

					theSelectedAsset = theSelectedAsset.next;
				}
			} else {
				if (this.containerAsset.actionMap[thisAction.ID]) {

					newACLState = this.containerAsset.actionMap[thisAction.ID].authzn;
				}
			}

			newMinMaxState = this.doMinMax(thisAction);
			newActionState = (newURLState && newACLState && newMinMaxState);
			if (thisAction.state != newActionState) {
				this.changeActionState(thisAction,  newActionState)
			}
		}
	} else {

		this.initializeContainerButtons();
		this.initializeAssets();
	}
}

ListControl_object.prototype.initializeContainerButtons = function () {

	for (var i = 0; i < this.toolBar.actions.length; i++) {
		newACLState = true;
		thisAction = this.toolBar.actions[i];
		if (this.containerAsset.actionMap[thisAction.ID]) {
			newACLState = this.containerAsset.actionMap[thisAction.ID].authzn;
		}
		newMinMaxState = this.doMinMax(thisAction);
		newActionState = (newACLState && newMinMaxState);
		this.changeActionState(thisAction,  newActionState);
	}
}





ListControl_object.prototype.initializeAssets = function () {

	if (this.selectionControls) {

		if (this.selectionControls.length != undefined) {
			for (i = 0; i < this.selectionControls.length; i++) {
				if (this.selectionControls[i].checked) {

					this.doSelection(this.selectionControls[i]);
				}
			}
		} else {
			if (this.selectionControls.checked) {

				doSelection(this.selectionControls);
			}
		}
	} 
}



function Toolbar_object () {

	this.actions = new Array();
	this.buttons = new Array();
	this.toolBarMenu = new Array();
	this.groupCount = 0;
	this.objType = "toolbar"
	this.listControlID = null;
	this.listViewRef = null;
	this.parentObject = null;
	this.stateOverClass = new Array(2);
		this.stateOverClass[true] = "vign-toolbarSpanOver";
		this.stateOverClass[false] = "vign-toolbarSpanOff";
	this.stateOutClass = new Array(2);
		this.stateOutClass[true] = "vign-toolbarSpan";
		this.stateOutClass[false] = "vign-toolbarSpanOff";
	this.stateOverClassMenuItem = new Array(2);
		this.stateOverClassMenuItem[true] = "vign-toolbarRoll";
		this.stateOverClassMenuItem[false] = "vign-toolbarOff";
	
}



function AssetList_object () {
	this.assets = new Array();
	this.selectedCount = 0;
}























var menuDelay = null;
var theMenus = new Array();
var undefined;
var consoleMenus;
var pathMenu = new Array();
var toolbarMenu = new Array();
var global_menuTimeOut = null;

function Menu_object (sID,oKeyElement, iXcoord, iYcoord,iWidth, sClassName, iMenuType
						) {
	this.ID = sID;
	this.keyElement = oKeyElement;
	this.xcoord = iXcoord;
	this.ycoord = iYcoord;
	this.width = iWidth;
	this.className = sClassName;
	this.menuItems= new Array();
	this.menuType = iMenuType;
	this.parentObject = null;
}





function clearTopMenu (sTopMenu,sClassName) {
	document.getElementById(sTopMenu).className = sClassName;

}

Menu_object.prototype.clearMenu = function () {
	document.getElementById(this.ID + "Block").style.visibility = 'hidden';
}

Menu_object.prototype.hideMenu = function() {

	global_menuTimeOut = this.ID;
	if (arguments.length > 0) {
		menuDelay = setTimeout("clearAll()", arguments[0]);
	} else {
		menuDelay = setTimeout("clearAll()", 300);
	}
	if (this.menuType == 0) {
		this.keyElement.firstChild.className="vign-menuLinkMain1";
	}
}

Menu_object.prototype.buildMenu = function(sThisMenu,iIndex,offClass,overClass) {


	if (this.width == 0) this.width = this.keyElement.offsetWidth;
	MenuStr = sThisMenu + "[" + iIndex + "]"
	document.write("<span class='" + this.className + "' id='" + this.ID + "Block' style='position:absolute; visibility:hidden; z-index:-1001; top:" + this.xcoord + "px ;left:" + this.ycoord + "px;'  onMouseOut='" + MenuStr + ".hideMenu()' onMouseOver='clearTimeout(menuDelay)'>");
	document.write("<table id='table_menu" + this.ID );
	document.write("' cellpadding='3' cellspacing='0' border='0'>");
	for (i=0;i<this.menuItems.length;i++) {
		theMenuItem=this.menuItems[i];
		if (theMenuItem.ID == undefined) {

			theMenuItem.ID = sThisMenu + iIndex + i;
		}
		theMenuItem.stateOutClass[true] = offClass;


		if (isIE()) {
			document.write("<tr><td nowrap='nowrap' class='" + offClass + "' id='td_" + theMenuItem.ID + "' onClick='this.childNodes(1).click(); " + MenuStr + ".hideMenu(0)' onMouseOut='" + sThisMenu + "[" + iIndex + "].menuItemOut(this,\"" + offClass + "\")' onMouseOver='" + sThisMenu + "[" + iIndex + "].menuItemOver(this,\""  + overClass + "\")'>&nbsp;");
		} else {
			document.write("<tr><td nowrap='nowrap' class='" + offClass + "' id='td_" + theMenuItem.ID + "' onClick='" + MenuStr + ".hideMenu(0)' onMouseOut='" + sThisMenu + "[" + iIndex + "].menuItemOut(this,\"" + offClass + "\")' onMouseOver='" + sThisMenu + "[" + iIndex + "].menuItemOver(this,\""  + overClass + "\")'>&nbsp;");
		}

		if (this.menuType == 1) {
			for (j=0;j<i;j++) {
				document.write("&nbsp;&nbsp;");
			}
		}
		if (theMenuItem.imagePath != "") {
			imageString = "<img src='" + theMenuItem.imagePath + "' border='0' align='absmiddle'>&nbsp;";
		} else {
			imageString = "";
		}
		document.write("<a id='href_" + this.menuItems[i].ID + "' style='text-decoration:none;color:#000000' href='" + theMenuItem.url + "'>" + imageString + theMenuItem.label + "</a>&nbsp;</td></tr>");
	}
	document.write("</table>");
	document.write("</span>");
}

Menu_object.prototype.fixPathWidth = function() {
	this.width = this.keyElement.offsetWidth;
	document.getElementById("table_menu" + this.ID).style.width = this.width;
}







//-------------------------------------------------------------------------







function isNetscape() {
	if(document.getElementById && !document.all)
		return true;
	return false;
}


function isIE() {
	 if (document.all)
	    return true;
	 return false;
}




function getLeft(oObject) {
	return (oObject.x) ? oObject.x : getPosition(oObject,"Left");
}

function getTop(oObject) {
	return (oObject.y) ? oObject.y : getPosition(oObject,"Top");
}

function getPosition(oObject,xyString) {
	inc = 0;
	var embeddedFlag = oObject.embedded;
	while (oObject != null) {
		if (isIE()) {
			if ((oObject.currentStyle.position == "absolute") &&  embeddedFlag) {
			   return inc;
			}
		}
		if (isNetscape()) {
			if (document.defaultView.getComputedStyle(oObject, null).getPropertyValue("position") == "absolute") {
			   return inc;
			}
		}
		inc = inc + oObject["offset" + xyString];
		oObject = oObject.offsetParent;
	}
	return inc;

}



var NN = isNetscape();
var IE = isIE();

listControl_hierarchyBrowserForm = new ListControl_object("listControl_hierarchyBrowserForm",450,200,0,450,0);
listControl_hierarchyBrowserForm.embedded = false;

if (listControl_hierarchyBrowserForm.embedded) { theSheet = document.styleSheets[document.styleSheets.length - 1]; }










function hidelayers()   {
    if(document.all)
    {
			
    for(i=1;i<=5;i++)       
    eval('document.all[\'Layer'+i+'\''+']'+'.style.visibility =\'hidden\'')
    }
    else if (document.layers){
    for(i=1;i<=5;i++)       
    eval('document.layers[\'Layer'+i+'\''+']'+'.visibility =\'hide\'')
    }
	else if(document.getElementById && !document.all)
	{
	for(i=1;i<=5;i++)
	document.getElementById('Layer'+i).style.visibility = "hidden";
	}
	}

function showlayer(val) {
hidelayers();
j=val;  

j=val;  
	if(document.all)
	{
	if(j==1){posx1=10;posy1=170;posx2=110;posy2=360;}
	else if(j==3){posx1=85;posy1=170;posx2=165;posy2=320;}
	eval('document.all[\'Layer'+j+'\''+']'+'.style.visibility =\'visible\'')
    }
    else if (document.layers){
    if(j==1){posx1=10;posy1=170;posx2=110;posy2=360;}
	else if(j==3){posx1=85;posy1=170;posx2=165;posy2=320;}
	eval('document.layers[\'Layer'+j+'\''+']'+'.visibility =\'show\'')      
    }
	else if(document.getElementById && !document.all && !document.layers)
	{
	if(j==1){posx1=10;posy1=170;posx2=110;posy2=360;}
	else if(j==3){posx1=85;posy1=170;posx2=165;posy2=320;}
	document.getElementById('Layer'+j).style.visibility = "visible";
	}
  }


function selectResults(formObj)
{ document.hierarchyForm.SelectedName.value = formObj; }


function ItemEdit(frmObj,frmHeight)
{
	if(document.hierarchyForm.SelectedName.value=="")
	{
	alert("Please select an item you want to "+frmObj+".");
	}
	else
	{
	window.open("common_opener.asp?act="+frmObj+"&id="+document.hierarchyForm.SelectedName.value,"Upload_Image","height="+frmHeight+",width=550,top=100,left=100,status=1")
	}
}


function ItemAdd(formtype)
{ window.open("common_opener.asp?ctype="+formtype+"&act=Add&id="+document.hierarchyForm.CurrentPg.value,"Upload_Image","height=550,width=550,top=100,left=100,status=1") }



function PagePreview(frmObj,frmHeight)
{
	if(document.hierarchyForm.SelectedName.value=="")
	{
	alert("Please select a page you want to Preview.");
	}
	else
	{
	window.open("page_preview.asp?act="+frmObj+"&id="+document.hierarchyForm.SelectedName.value,"Upload_Image","height="+frmHeight+",width=800,top=100,left=100,status=1,scrollbars=1,resizable=1")
	}
}



function changepass()
{
window.open("changepass.asp","Upload_Image","height=220,width=400,top=100,left=100")
}

