/*
===========================================================================
Filename:		Master.js;
Description:	Common Javascript functions used within WebBuilder;
Created:		29-jun-2006
Author:			Ian Parry
===========================================================================
*/


		function ShowSubMenus(nodeID, directChildren, allChildren, bIsRoot) {
			var aList = directChildren.split(',');
			var iLength = aList.length;
			var cstyle = document.getElementById('navItem'+nodeID).style;
			var sTmp = '';
			var sTmp2 = '';
			var sStyle = '';
			var RootIsOpen = false;
			sTmp = allChildren;
				var aList = sTmp.split(',');
				var iLength = aList.length;
				//Close all children first
				//alert('Close ['+allChildren+']');
				for (i=0;i<=iLength;i++) {
					closeLayer('navItem'+aList[i]);
					
					//Loop through roots children and see if they are open
					sTmp2 = directChildren;					
					var aList2 = sTmp2.split(',');
					var iLength2 = aList2.length;
					//Now open correct node
					//alert('Open ['+directChildren+']');
					for (j=0;j<=iLength2;j++) {
						//toggleLayer('navItem'+aList[i]);
						//alert('navItem'+aList2[j]);
						if (document.getElementById('navItem'+aList2[j])) {
							sStyle = document.getElementById('navItem'+aList2[j]).style;
							//alert(sStyle.display);
							if ( sStyle.display == 'block' ) {
								RootIsOpen = true;
							}
						}
					}
					//alert('RootIsOpen: '+RootIsOpen);
				
				
				}
			
			
			
			if (!RootIsOpen) {
				//Open direct children for node
				sTmp = directChildren;
				var aList2 = sTmp.split(',');
				var iLength2 = aList2.length;
				//Now open correct node
				//alert('Open ['+directChildren+']');
				for (i=0;i<=iLength2;i++) {
					//toggleLayer('navItem'+aList[i]);
					openLayer('navItem'+aList2[i]);
				}
			}
			//alert('Found '+iLength+' items in list ['+directChildren+']\n\nFound '+iLength2+' items in list2 ['+allChildren+']');
		}
		
		function scrap() {
				if (style2.display == 'block') {
					// Node is open
					sTmp = allChildren;
					var aList2 = sTmp.split(',');
					var iLength2 = aList2.length;
					//Close all children first
					
	
					if (bIsRoot == 'True') {
						// Node is a root
						alert('Node is root');
						alert('Close ['+allChildren+']');
						for (i=0;i<=iLength2;i++) {
							closeLayer('navItem'+aList2[i]);
						}
					} else {
						sTmp = directChildren;
						var aList2 = sTmp.split(',');
						var iLength2 = aList2.length;
						//Now open correct node
						//alert('Open ['+allChildren+']');
						for (i=0;i<=iLength;i++) {
							toggleLayer('navItem'+aList[i]);
						}
					}
				} else {
					if (bIsRoot == 'True') {
						sTmp = directChildren;
						var aList2 = sTmp.split(',');
						var iLength2 = aList2.length;
						//Now open correct node
						alert('Open ['+allChildren+']');
						for (i=0;i<=iLength;i++) {
							toggleLayer('navItem'+aList[i]);
						}
					}
				}
		}
				
				
		function closeLayer(whichLayer)
		{
			if (document.getElementById)
			{
				if (document.getElementById(whichLayer)) 
				{
					// this is the way the standards work
					var style2 = document.getElementById(whichLayer).style;
//					if (style2.display == 'block') {
						style2.display = "none";						
//					}
				}
			}
			else if (document.all)
			{
				// this is the way old msie versions work
				var style2 = document.all[whichLayer].style;
				style2.display = style2.display? "":"block";
			}
			else if (document.layers)
			{
				// this is the way nn4 works
				var style2 = document.layers[whichLayer].style;
				style2.display = style2.display? "":"block";
			}
		}
		
		
		
		function openLayer(whichLayer)
		{
			if (document.getElementById)
			{
				if (document.getElementById(whichLayer)) 
				{
					// this is the way the standards work
					var style2 = document.getElementById(whichLayer).style;
//					if (style2.display == 'none') {
						style2.display = "block";						
//					}
				}
			}
			else if (document.all)
			{
				// this is the way old msie versions work
				var style2 = document.all[whichLayer].style;
				style2.display = style2.display? "":"block";
			}
			else if (document.layers)
			{
				// this is the way nn4 works
				var style2 = document.layers[whichLayer].style;
				style2.display = style2.display? "":"block";
			}
		}
		
		
		
		
		function toggleLayer(whichLayer)
		{
			if (document.getElementById)
			{
				if (document.getElementById(whichLayer)) 
				{
					// this is the way the standards work
					var style2 = document.getElementById(whichLayer).style;
					if (style2.display == 'none') {
						style2.display = style2.display? "":"block";
					} else {
						style2.display = style2.display? "":"none";						
					}
				}
			}
			else if (document.all)
			{
				// this is the way old msie versions work
				var style2 = document.all[whichLayer].style;
				style2.display = style2.display? "":"block";
			}
			else if (document.layers)
			{
				// this is the way nn4 works
				var style2 = document.layers[whichLayer].style;
				style2.display = style2.display? "":"block";
			}
		}
 
 
 // -------------------------------------------------------------------
// moveOptionUp(select_object)
//  Move selected option in a select list up one
// -------------------------------------------------------------------
function moveOptionUp(obj) {
	if (!hasOptions(obj)) { return; }
	for (i=0; i<obj.options.length; i++) {
		if (obj.options[i].selected) {
			if (i != 0 && !obj.options[i-1].selected) {
				swapOptions(obj,i,i-1);
				obj.options[i-1].selected = true;
				}
			}
		}
	}

// -------------------------------------------------------------------
// moveOptionDown(select_object)
//  Move selected option in a select list down one
// -------------------------------------------------------------------
function moveOptionDown(obj) {
	if (!hasOptions(obj)) { return; }
	for (i=obj.options.length-1; i>=0; i--) {
		if (obj.options[i].selected) {
			if (i != (obj.options.length-1) && ! obj.options[i+1].selected) {
				swapOptions(obj,i,i+1);
				obj.options[i+1].selected = true;
				}
			}
		}
	}

 // -------------------------------------------------------------------
// swapOptions(select_object,option1,option2)
//  Swap positions of two options in a select list
// -------------------------------------------------------------------
function swapOptions(obj,i,j) {
	var o = obj.options;
	var i_selected = o[i].selected;
	var j_selected = o[j].selected;
	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
	o[i] = temp2;
	o[j] = temp;
	o[i].selected = j_selected;
	o[j].selected = i_selected;
	}

 function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
		return false;
	}

function SelectAllList(obj){
	for(var i = 0;i < obj.length;i++){
		obj.options[i].selected = true;
	}
}

 
function PopReorderPages(sID) {
	window.open('reorderpages.asp?n='+sID+'','WebBuilderPopWinReorder','width=455,height=500,location=0,status=0');
}

function SwapImg(imgObj, imgSrc) {
	
}

function PopTitleWindow(sID) {
	window.open('title.asp?n='+sID+'','WebBuilderPopWinTitle','width=500,height=135,location=0,status=0');
}

function PopPageDescWindow(sID) {
	window.open('pagedesc.asp?n='+sID+'','WebBuilderPopWinPageDesc','width=500,height=250,location=0,status=0');
}

function PopKeywordWindow(sID) {
	window.open('keywords.asp?n='+sID+'','WebBuilderPopWinKeywords','width=500,height=250,location=0,status=0');
}

function PopNodeDropDownWindow(sID) {
	window.open('togglemenudropdown.asp?n='+sID+'','WebBuilderPopWinDropDown','width=500,height=250,location=0,status=0');
}

function PopSiteStatusWindow() {
	window.open('togglesitestatus.asp','WebBuilderPopWinDropDown','width=500,height=250,location=0,status=0');
}



function PopSubpageWindow(sID) {
	if (sID == '0') {
		window.open('subpage.asp?n='+sID+'&tlid=0','WebBuilderPopWinSubpage','width=500,height=250,location=0,status=0');
	} else if (sID == '1') {
		window.open('subpage.asp?n='+sID+'&tlid=1','WebBuilderPopWinSubpage','width=500,height=250,location=0,status=0');
	} else {
		window.open('subpage.asp?n='+sID+'','WebBuilderPopWinSubpage','width=500,height=250,location=0,status=0');
	}
	
}

function PopDeletePageWindow(sID) {
	window.open('deletepage.asp?n='+sID+'','WebBuilderPopWinDeletePage','width=500,height=350,location=0,status=0,scrollbars=1');
}