<!--

/*
============================================================================

							folderUpdate.js

 ===========================================================================

  AUTHOR :					Svetlana Freytsis

  DESCRIPTION :				JavaScript functions for 
							Update folder by calling remote script. 

 ===========================================================================

  $Header: //baikal/eparchive/BLL/ASP/script/updateFolder.js 1.30 2002/10/21 10:54:27 yvoznyuk Exp $
  
  $Log: updateFolder.js $  
  Revision 1.30  2002/10/21 10:54:27  yvoznyuk  
  fixed update folder script (cc #10946)  
  Revision 1.29  2002/09/19 09:52:34  yvoznyuk  
  fixed frames and nested frames "navigation links" and   
  "back to main session" bugs and issues.  
  Revision 1.28  2002/08/22 14:41:52  mikec  
  Corrected an issue from previous revision.  PageSubmit from externalFrameHeader  
  referred to "top", and should refer to "parent".  
  Revision 1.27  2002/08/22 14:20:32  mikec  
  Added a condition in PageSubmit when operating within frames.  
  Because some customers use frames, adds a condition to check if window.location has "externalFrameHeader.asp"  
  Revision 1.26  2002/08/22 12:54:49  mikec  
  Added period to "Folder has X items" message  
  Revision 1.25  2002/08/19 10:14:47  mikec  
  Added conditional "Folder has X items" to use correct items or item depending on quantity  
  Revision 1.24  2002/08/15 16:18:38  yvoznyuk  
  Added new boolean variable to define update folder or not if user has changed any folder item on a page.  
  Revision 1.23  2002/07/09 08:37:07  mikec  
  Removed extra period from dynamic "Folder has X Item(s)."  
  Revision 1.22  2002/06/26 17:48:39  yvoznyuk  
  added new condition for Netscape 4.08  
  Revision 1.21  2002/06/17 14:15:48  ctuomi  
  Remove changed search logic  
  Revision 1.20  2002/06/14 13:15:53  cgodfrey  
  Handle case when no folder items are present  
  Revision 1.19  2002/06/14 12:03:57  cgodfrey  
  CC Issue 8122 - search input invokes pagesubmit to extract folder   
  items on searchpost  
  Revision 1.18  2002/06/11 09:11:30  ctuomi  
  In pageSubmit(), check to make sure that a form exists before trying  
  to use the "chs" element.  (for CC #8033)  
  Revision 1.17  2002/06/07 11:27:54  yvoznyuk  
  fixed page reloading in Netscape 4.08  
  Revision 1.16  2002/05/24 16:09:40  ctuomi  
  Incorporate MarkSearchChanged() functionality  
  Revision 1.15  2002/05/21 09:06:30  ctuomi  
  Add handling of changed search string  
  Revision 1.14  2002/05/06 18:31:30  cpaladug  
  Fandango Merge  
  Revision 1.13.1.4  2002/04/30 15:38:35  cpaladug  
  Popup window target is fixed while we are on the resultlist page  
  Revision 1.13.1.3  2002/04/18 13:28:01  ctuomi  
  - Changes to allow updating of folder count dynamically.  
  Revision 1.13.1.2  2002/04/11 15:35:46  cpaladug  
  Renamed folder images  
  Revision 1.13  2002/03/29 10:44:08  cgodfrey  
  Added a nestedext_frame case for PageSubmit function.  CC Issue  
  6895. Navigation is special in this case - there are 3 frames. Initial   
  session (with toolbar), external frame with navigation elements and   
  frame for PDF from Content Server. Links for naviagation need to work off  
  parent.window.location.href  
  Revision 1.12  2002/03/14 17:13:52  yvoznyuk  
  added new functionality for popup window  
  Revision 1.11  2002/03/12 15:10:53  yvoznyuk  
  fixed previous changes of code (strType== "ext_frame")  
  and added return(false) for event onClick  
  Revision 1.10  2002/03/07 11:50:28  cgodfrey  
  CC Issue 6895 - To use FT Viewer in an external frame and not   
  navigate from the top - include indicator of ext_frame  
  Revision 1.9  2002/03/06 18:58:48  yvoznyuk  
  Removed all unused functionality  
  Revision 1.8  2002/03/04 13:44:36  yvoznyuk  
  Fixed Netscape and Opera PDF files opening in external frame  
  Revision 1.7  2002/03/02 16:46:35  yvoznyuk  
  Removed java remote scripting and implemented   
  new javascript Folder Functionality  
  Revision 1.6  2002/02/14 17:41:47  yvoznyuk  
  Moved JavaScript alert to XSL template to have dynamic text.  
  Revision 1.5  2002/02/14 14:01:11  yvoznyuk  
  checked if Java Enabled from browserUtil.js file  
  Revision 1.4  2002/02/14 13:52:14  yvoznyuk  
  Added new functionality to support popup   
  alert message when the Folder List will interact   
  with the "Maximum Results Before Warning"   
  admin parameter.  
  Revision 1.3  2002/01/24 12:24:15  sfreytsi  
  session params added to TryAddAll  
  Revision 1.2  2002/01/21 18:00:44  sfreytsi  
  added parameter for passing all session URL params  
   

 ===========================================================================
 */

var imgFolderOn = "folderon.gif";
var imgFolderOff = "folderoff.gif";
var imgFolderAddAll = "folderaddall.gif";
var imgFolderRemoveAll = "folderremoveall.gif";
var blnSubmit = false;
var blnUpdateFolder = false;

function PageSubmit(strType, strValue)
{
	blnSubmit = true;
	var strAddItems = "";
	var strRemoveItems = "";
	var lngPageImages = document.images.length;
	
	for(var i=0;i<lngPageImages;i++)
	{
		if(document.images[i].src.indexOf(imgFolderOn)>0)
		{
			if(i == lngPageImages-1)
				strAddItems += document.images[i].name;
			else
				strAddItems += document.images[i].name + ",";
		}
		else if(document.images[i].src.indexOf(imgFolderOff)>0)
		{
			if(i == lngPageImages-1)
				strRemoveItems += document.images[i].name;
			else
				strRemoveItems += document.images[i].name + ",";
		}
	}
	
	if(strType == "form_input")
 	{
 		document.forms[0].formitem.value = strValue;
 		strValue = "";
 	} 	
 	
	if(document.all && window.event)
		window.event.returnValue = false;
	
	if((strAddItems != "" || strRemoveItems != "") && blnUpdateFolder)
	{		
 		if(strType == "win_popup" && strValue != "")
		{
			window.open(strValue,"_blank","");
		}
 		else
 		{
 			if(strValue == "")
 				document.forms[0].pg.value = document.forms[0].action;
			else
 				document.forms[0].pg.value = strValue;		
		
			document.forms[0].afi.value = strAddItems;
			document.forms[0].rfi.value = strRemoveItems;
			
			if(strValue != "")
			{
				document.forms[0].action = "UpdateFolder.asp";
			}
			
			document.forms[0].submit();

		}	
	}	
	else if(strType == "win_popup")
	{
		window.open(strValue,"_blank","");
	}
	else
	{
 		if(strValue == "")
 		{
 			document.forms[0].submit();
 		}
		else
		{			
			var blnExtFrame = (self.window.location.toString().toLowerCase().indexOf("externalframe") > 0);
			if ((strType == "nestedext_frame") || blnExtFrame) //reloading parent window
 			{
				if(typeof(parent.window) == "object")
				{
					if(parent.window.frames.length > 0)
					{
						if(parent.window.frames[0].name == "ebscoheader")
						{
							if(IsReplaceRequired())
								parent.window.location.replace(strValue);
							else
								parent.window.location = strValue;
							return(false);						
						}
					}
				}
 			}
			
			//reloading self window
			if(IsReplaceRequired())
 				self.window.location.replace(strValue);
 			else
 				self.window.location = strValue;
 		}
	}
	return(false);
}

function AddOneRec(objImg)
{
	blnUpdateFolder = true;
	var objImg = document.images[objImg];
	if(objImg)
	{
		if(objImg.src.indexOf(imgFolderOn)>0)
		{
			objImg.src = strImagePath + imgFolderOff;
			lngFolderCount --;
		}
		else
		{
			if (lngFolderCount < lngMaxResultsBW)
			{
				objImg.src = strImagePath + imgFolderOn;
				lngFolderCount ++;
			}
			else
			{
				MaxResultsAlert();
			}
		}
	}
	SetFolderCount(lngFolderCount);	
}

function AddAllRec(objImg)
{
	blnUpdateFolder = true;
	var objImg = document.images[objImg];
	var lngPageImages = document.images.length;
	
	if(objImg)
	{
		if(objImg.src.indexOf(imgFolderAddAll)>0)
		{
			for(var i=0;i<lngPageImages;i++)
			{
				if(document.images[i].src.indexOf(imgFolderOff)>0)
				{
					if (lngFolderCount < lngMaxResultsBW)
					{
						document.images[i].src = strImagePath + imgFolderOn;
						lngFolderCount ++;
					}
					else
					{
						MaxResultsAlert();
						break;
					}
				}
			}
		}
		else
		{
			for(var i=0;i<lngPageImages;i++)
			{
				if(document.images[i].src.indexOf(imgFolderOn)>0)
				{
					document.images[i].src = strImagePath + imgFolderOff;
					lngFolderCount --;
				}
			}
		}
	}
	SetFolderCount(lngFolderCount);
}

function SetFolderCount(folderCount)
{
	if(document.layers)
	{
		// Display image link
		var tmpFolderString = '<a href=\"';
		tmpFolderString += folderSubmitURL;
		tmpFolderString += '\"';
		tmpFolderString += ' onClick=\"return PageSubmit(\'\',\'';
		tmpFolderString += folderSubmitURL;
		tmpFolderString += '\')\">'
		tmpFolderString += '<img border=\"0\" id=\"' +  folderImageId + '\"';
		tmpFolderString += ' alt=\"' + folderSubmitLinkTitle + '\"';
		
		if (folderCount > 0) {
			tmpFolderString += ' src=\"' + folderImagePath  + 'folderLargeOn.gif\"';	
		}
		else {
			tmpFolderString += ' src=\"' + folderImagePath  + 'folderLargeOff.gif\"';
		}
		tmpFolderString += '></img></a>';

		if (folderCount == 1){var tmpItemsAddS = '.';}
		else {var tmpItemsAddS = 's.';}
		
		// then text link
		tmpFolderString += '<font class=\"text-bold\"><a href=\"';
		tmpFolderString += folderSubmitURL;
		tmpFolderString += '\"';
		tmpFolderString += ' onClick=\"return PageSubmit(\'\',\'';
		tmpFolderString += folderSubmitURL;
		tmpFolderString += '\')\">Folder has ' + folderCount + ' item' + tmpItemsAddS + '</a></font>';
		WriteToLayer("folderItemsDiv",tmpFolderString);
		
	}
	else if (!(GetBrowserName() == "explorer" && GetBrowserVersion() == "4")) 
	{
		var countElement = document.getElementById("folderItemsLink");			
		if (countElement)
		{
			if (folderCount == 1){var tmpItemsAddS = '.';}
			else {var tmpItemsAddS = 's.';}
			countElement.innerHTML = "Folder has " + folderCount + " item" + tmpItemsAddS;
			var containsImg = document.images["folderItems"];
			var strFolderContainsSrc = containsImg.src;	
			var strImageBase = strFolderContainsSrc.substring(0, strFolderContainsSrc.indexOf("folderLarge"));	

			if (folderCount > 0)
				containsImg.src = strImageBase + "folderLargeOn.gif";
			else
				containsImg.src = strImageBase + "folderLargeOff.gif";
		}
	}
}

//-->
