document.existenceImpliesKnowledgeDocument = "x";
// Used by sectional menu
function submitSimpleSearchForm(initTextValue) {
	if (document.sectionalMenuSearchForm.keyword.value == initTextValue) {
		var kType = document.sectionalMenuSearchForm.Ktype.value;
		document.sectionalMenuSearchForm.keyword.value = "";
		loadPage("/Knowledge/Search/Search.cfm?sSearchType=Contents&kType=" + kType);
		return false;
	}
	if (document.summaryWindowReference) {
		// if the popup window exists, close it to do a new search
		document.summaryWindowReference.close();
	}
	return true;
}
function clearSearchHelp(initTextValue) {
	if (document.sectionalMenuSearchForm.keyword.value == initTextValue) {
		document.sectionalMenuSearchForm.keyword.value = "";
	}
}
function putBackSearchHelp(initTextValue) {
	if (document.sectionalMenuSearchForm.keyword.value == "") {
		document.sectionalMenuSearchForm.keyword.value = initTextValue;
	}
}
function submitSmartSearchForm(kType, initDefaultOptionValue) {
	var si = document.sectionalMenuSmartSearchForm.smartSearchType.options.selectedIndex;
	var val = document.sectionalMenuSmartSearchForm.smartSearchType.options[si].value;
	if (val.length > 0) {
		loadPage('/Knowledge/Search/Search.cfm?kType=' + kType + '&sSearchType=' + val);
	} else {
		document.sectionalMenuSmartSearchForm.smartSearchType.options[0].text = initDefaultOptionValue;
	}
}
function clearFetchHelp(initTextValue) {
	if (document.sectionalMenuFetchForm.filter.value == initTextValue) {
		document.sectionalMenuFetchForm.filter.value = "";
	}
}
function putBackFetchHelp(initTextValue) {
	if (document.sectionalMenuFetchForm.filter.value == "") {
		document.sectionalMenuFetchForm.filter.value = initTextValue;
	}
}
function submitFetchForm(initTextValue) {
	if (document.sectionalMenuFetchForm.filter.value == initTextValue) {
		document.sectionalMenuFetchForm.filter.value = "";
	}
	return true;
}
function submitLBLFetchForm(initTextValue) {
	var iSelectedIndex = document.sectionalMenuLBLFetchForm.filterType.options.selectedIndex;
	var sPrepend = document.sectionalMenuLBLFetchForm.filterType.options[iSelectedIndex].value;
	document.sectionalMenuLBLFetchForm.btnFetchType.value = iSelectedIndex + 1;
	document.sectionalMenuLBLFetchForm.filter.value = sPrepend + document.sectionalMenuLBLFetchForm.filter.value;
	return true;
}
// Used by Home & Search Results
function addMultipleToBriefcase(kType) {
	var docIDs = "";
	if (document.checkboxesForm) {
		for (i=0 ; i<document.checkboxesForm.elements.length ; i++) {
			if (document.checkboxesForm.elements[i].checked) {
				docIDs = docIDs + escape(document.checkboxesForm.elements[i].value) + ",";
			}
		}
		if (docIDs.length > 0) {
			PopupWindow('/Knowledge/Briefcase/AddToBriefcase.cfm?docids=' + docIDs + '&kType=' + kType, 'AddCasesWin', "480x360", "scrollbars");
		} else {
			alert ("You have not chosen any documents.");
		}
	} else {
		alert ("You have not chosen any documents.");
	}
}
// Used by ContentsSearch.cfm and Document.cfm
function jumpWithinPage(anchorName) {
	var scrollToPosition = document[anchorName];
	var hideLeftHandContentsPane = false;
	if (jumpWithinPage.arguments.length > 1) {
		hideLeftHandContentsPane = jumpWithinPage.arguments[1];
	}
	if (document.all) {
		var scrollToPos = document.all[anchorName];
		if (scrollToPos) {
			scrollToPos.scrollIntoView();
			var distanceFromLeft = 0 - document.body.scrollLeft;
			window.scrollBy(distanceFromLeft, 0);
		}
		if (hideLeftHandContentsPane) {
			ChangeShowHide(false);
		}
	} else {
		window.location = "#" + anchorName;
	}
}
// ASSISTANCE POPUP, KEYWORDS
document.sKeywordFormName = "";
document.sKeywordTextboxName = "";
document.sPageLanguageAbbr = "eng";
function openKeywordsAssistanceWindow (iKtype, sTextboxName, sPageLanguage)
{
	var sFormName;
	document.sKeywordTextboxName = sTextboxName;
	document.sPageLanguageAbbr = sPageLanguage;
	if (openKeywordsAssistanceWindow.arguments.length > 3)
	{
		sFormName = openKeywordsAssistanceWindow.arguments[3];
	}
	else
	{
		sFormName = "SearchForm";
	}
	document.sKeywordFormName = sFormName;
	var bOpen = true;
	if (document[sFormName][sTextboxName].value.length > 0)
	{
		if (sPageLanguage == "fre")
		{
			var sConfirmQuestion = "Les mots clés que vous avez entrés seront perdus si vous utilisez la fenêtre d'aide pour mots clés.";
		}
		else
		{
			var sConfirmQuestion = "You will lose the keywords that you have entered if you use the keyword assistance window.";
		}
		if (!confirm(sConfirmQuestion))
		{
			bOpen = false;
		}
	}
	if (bOpen)
	{
		window.open("/Knowledge/Search/AssistanceKeywords.cfm?kType=" + iKtype, "assistWin", "width=640,height=320,resizable=yes,scrollbars=yes")
	}
}
function saveKeywordsAssistance()
{
	var sTemp = "", sWord;
	var bFirst, bTemp=false;
	var sSaveString = "";
	// AND words
	bFirst = true;
	sTemp = document.KeywordAssistanceSearchForm.andKeyWords.value;
	while (sTemp.length > 0)
	{
		sWord = listFirst(sTemp);
		sTemp = listRest(sTemp);
		if (bFirst)
		{
			bFirst = false
		}
		else
		{
			sSaveString = sSaveString + " AND ";
		}
		sSaveString = sSaveString + sWord;
	}
	// OR words
	bFirst = true;
	sTemp = document.KeywordAssistanceSearchForm.orKeyWords.value;
	if (sTemp.length > 0)
	{
		if (sSaveString.length > 0)
		{
			sSaveString = sSaveString + " AND "
		}
		sSaveString = sSaveString + "("
		bTemp = true;
	}
	while (sTemp.length > 0)
	{
		sWord = listFirst(sTemp);
		sTemp = listRest(sTemp);
		if (bFirst)
		{
			bFirst = false
		}
		else
		{
			sSaveString = sSaveString + " OR ";
		}
		sSaveString = sSaveString + sWord;
	}
	if (bTemp)
	{
		sSaveString = sSaveString + ")"
	}
	// NEAR words
	bFirst = true;
	sTemp = document.KeywordAssistanceSearchForm.nearKeyWords.value;
	while (sTemp.length > 0)
	{
		sWord = listFirst(sTemp);
		sTemp = listRest(sTemp);
		if (bFirst)
		{
			bFirst = false
			if (sSaveString.length > 0)
			{
				sSaveString = sSaveString + " AND ";
			}
		}
		else
		{
			sSaveString = sSaveString + " NEAR ";
		}
		sSaveString = sSaveString + sWord;
	}
	// PHRASE words
	sTemp = document.KeywordAssistanceSearchForm.keyPhrase.value;
	if (sTemp.length > 0)
	{
		if (sSaveString.length > 0)
		{
			sSaveString = sSaveString + " AND ";
		}
		sSaveString = sSaveString + "\"" + sTemp + "\"";
	}
	// NOT words
	bFirst = true;
	sTemp = document.KeywordAssistanceSearchForm.notKeyWords.value;
	if (sTemp.length > 0 && sSaveString.length == 0)
	{
		if (self.opener.document.sPageLanguageAbbr == "fre")
		{
			alert ("Vous devez fournir un terme de recherche dans au moins un autre champ (c.-à.-d. autre que \"aucun de ces mots\").");
		}
		else
		{
			alert ("You must provide a search term in at least one other field (i.e. other than \"none of these words\").");
		}
		return;
	}
	while (sTemp.length > 0)
	{
		sWord = listFirst(sTemp);
		sTemp = listRest(sTemp);
		sSaveString = sSaveString + " AND NOT " + sWord;
	}
	var sFormName = self.opener.document.sKeywordFormName;
	var sTextboxName = self.opener.document.sKeywordTextboxName;
	self.opener.document[sFormName][sTextboxName].value = sSaveString;
	self.close();
}
// return the first element of the specified list
function listFirst (ls) {
	if (ls.indexOf(" ") > 0) {
		return (ls.substring(0, ls.indexOf(" ")));
	} else {
		return (ls);
	}
}
// return the specified list with the first element removed
function listRest (ls) {
	if (ls.indexOf(" ") > 0) {
		return (ls.substring(ls.indexOf(" ")+1, ls.length));
	} else {
		return ("");
	}
}

// 
function showTDSResultsPopup(sFetchSection, sPageTitle, iLookupInKtype)
{
	// find ktype in the url
	var thisPage = window.location.toString().toLowerCase();
	var thisPageKtype = 0;
	if (thisPage.indexOf("linktype=") >= 0)
	{
		thisPage = thisPage.substring(0, thisPage.indexOf("linktype=")) + thisPage.substring(thisPage.indexOf("linktype=")+9, thisPage.length);
	}
	if (thisPage.indexOf("ktype=") >= 0) {
		thisPageKtype = parseInt(thisPage.substring(thisPage.indexOf("ktype=")+6, thisPage.length));
	}
	// open the TDS window
	if (thisPageKtype > 0)
	{
		var iShrinkVertical = 95 - 20;
		var iShrinkHorizontal = 10;
		var iHeight = 540 - iShrinkVertical;
		var iWidth = 720 - iShrinkHorizontal;
		var TDSMagicWindow = window.open("/Knowledge/Search/TDSMagic.cfm?kType=" + thisPageKtype + "&iFetchIn=" + iLookupInKtype + "&sFetchSection=" + escape(sFetchSection) + "&sPageTitle=" + escape(sPageTitle), "winLBLAnnotations", "width=" + iWidth.toString() + ",height=" + iHeight.toString() + ",scrollbars=yes,status=yes,toolbar=yes");
		TDSMagicWindow.focus();
		iHeight += iShrinkVertical;
		iWidth += iShrinkHorizontal;
		TDSMagicWindow.moveTo((window.screen.width - iWidth) / 2, (window.screen.height - iHeight) / 2);
	}
}

function openPopupInformationForProduct(iProductID)
{
	PopupWindow("/Knowledge/PopupInformation.cfm?kType=" + iProductID.toString() + "&printFriendly=1", "winPopupInfo", "600x450", "toolbar=yes,scrollbars=yes");
}

