function syncToc(a_orientPath)
{
	var url = "GetTocDescendants.do?maxChildrenInLevel=100&nodeId="+escape(a_orientPath);
	if (a_orientPath == "#node-id(1)")
		url = url + "&level=2";
	document.location = url;
}


// pre-loading the page toolbar images
function imagesPreload()
{
	var images = new Array();
		images[0] = {name:"headImg",src:"./Images/homeGray.gif"};
		images[1] = {name:"searchImg",src:"./Images/lenseGray.gif"};
		images[2] = {name:"jfsImg",src:"./Images/jfsGray.gif"};
		images[3] = {name:"helpImg",src:"./Images/helpGray.gif"};
		images[4] = {name:"headImgOver",src:"./Images/home.gif"};
		images[5] = {name:"searchImgOver",src:"./Images/lense.gif"};
		images[6] = {name:"jfsImgOver",src:"./Images/jfs.gif"};
		images[7] = {name:"helpImg",src:"./Images/help.gif"};

	for(var i=0; i<images.length; i++)
	{
		loadImage(images[i].name,images[i].src);
	}
}

//loading an image.
function loadImage(a_id , a_src)
{
	eval(a_id +"= new Image()");
	eval(a_id +".src ='"+ a_src +"'");

}

//log out function
function logOut()
{
	document.location = "LogOut.do";
}

//this function changes the toolbar's button classes
function changeClass(a_Obj,a_isDisable)
{
	var OverStrIndx = a_Obj.className.indexOf("Over"); // the index of the "Over" substring in the class
	if(a_Obj.firstChild.src)
		var image = a_Obj.firstChild.src; // get reference to image src
	else
		var image = null;
	if(a_isDisable==true)
	{
		a_Obj.className	= a_Obj.className+"Disabled";
		if(image != null)
			image = image.substring(0,image.indexOf(".gif"))+"Gray.gif";
	}
	else if(OverStrIndx==-1)                          // if classOver change class to default else change to class Over
	{
		//alert("image1=" + image);
                a_Obj.className = a_Obj.className+"Over";
		if(image != null)
			image = image.substring(0,image.indexOf("Gray"))+".gif";
	}
	else
	{
                //alert("image2=" + image);
		a_Obj.className = a_Obj.className.substring(0,OverStrIndx);
		if(image != null)
			image = image.substring(0,image.indexOf(".gif"))+"Gray.gif";
	}

	if(a_Obj.firstChild.src)
		a_Obj.firstChild.src = image;
}


//this function changes the page location to the new url
function gotoPage(a_nextURL)
{
	document.location = a_nextURL;
}

//validate function
function validate(formPointer,errMessage)
{
	var flag = false;

	for(i=0;i<formPointer.elements.length;i++)
	{
		var currentElement = formPointer.elements[i];
		if(currentElement.type == "text" || currentElement.type=="enigma:term" )
		{
			if(currentElement.value != '')
			{
				flag = true;
				break;
			}
		}
		else if(formPointer.elements[i].type.toString()=="select-one")
		{
			// check the relevant SELECT elements
			if(formPointer.elements[i].name =='control_Term_eIPC_ATANo')
			{
				if(formPointer.elements[i].options[formPointer.elements[i].selectedIndex].value != "")
				{
					flag = true;
					break;
				}
			}
			if( formPointer.elements[i].id.indexOf("_Day") != -1 ||
				formPointer.elements[i].id.indexOf("_Month") != -1 ||
				formPointer.elements[i].id.indexOf("_Year") != -1
			)
			{
				if(formPointer.elements[i].options[formPointer.elements[i].selectedIndex].value != "")
				{
					flag = true;
					break;
				}
			}
		}
	}
	if(!flag)
	{
		alert(errMessage);
		return false;
	}
}

//print function
function printPage(a_type)
{
	printPage(a_type, false);
}
function printPage(a_type, a_isSearchCleared)
{
	var sessionSuffix = sessionID.substring(sessionID.length-5,sessionID.length);



	if( a_type == 'no_operation' )
		return;

	var WinW = (ie5) ? document.body.clientWidth : window.innerWidth ;
	var WinH = (ie5) ? document.body.clientHeight : window.innerHeight;

	var win_url =  "ShowPrintPreview.do" + document.location.search;
	win_url = URLUtil.getVerifiedUrl(win_url,version);
	win_url = win_url +"&popup=true";
	switch(a_type)
	{
		case "XMLDoc" :
			win_url += "&pageType=XMLDoc";
			if (a_isSearchCleared == true)
				win_url += "&isSearchCleared=yes";
			var printWindow = window.open(win_url,sessionSuffix+"_Preview","height="+WinH*0.75+",width="+WinW*0.75+",resizable=yes,dependent=yes");
			if(window.focus)
				printWindow.focus();
			break;
		case "EIPC":
			win_url += "&pageType=eIPC";
		case "Illustration":
			var currentImg = document.getElementById("PicContainer").firstChild;
			var imgName = currentImg.src;
			var imgHeight = currentImg.height;
			var imgWidth = currentImg.width;
			win_url += "&img=" + imgName+"&imgHeight="+imgHeight+"&imgWidth="+imgWidth;
			if(a_type=="Illustration")
			{
				win_url += "&pageType=illustration";
				var printWindow = window.open(win_url,sessionSuffix+"_illustration","height="+WinH*0.75+",width="+WinW*0.75+",resizable=yes,dependent=yes");
				if(window.focus)
					printWindow.focus();
				break;
			}
		case "PartList":
			if(a_type=="PartList")
				win_url += "&pageType=partList";
			var printWindow = window.open(win_url,sessionSuffix+"_partList","height="+WinH*0.75+",width="+WinW*0.75+",resizable=yes,dependent=yes");
			if(window.focus)
				printWindow.focus();
			break;

		default:
	}
}

//show help function
function showHelp()
{
	var helpURL = "ShowHelp.do";
	helpURL = URLUtil.getVerifiedUrl(helpURL,version);
	var helpWindow = window.open(helpURL,"help","height="+document.body.clientHeight*0.9+",width="+document.body.clientWidth*0.9+",resizable=yes,status=yes,toolbar=yes,dependent=yes");
	if(window.focus)
		helpWindow.focus();
}

//load all toolbar images
imagesPreload();

