	/* this prevents the page from showing up inside another frame */
	if (parent.location.href != window.location.href)
		parent.location.href = window.location.href;
		
	PageLoaded = 0; // flag used in navigation bar

	IgnoreFields = 1; // flag that's used in CheckFields()
	
	JSClipID = 0; //if reset to non-0, this holds the Clip ID of the currently requested/loaded video clip; used in video clip navidation in v_tours_controls.cfm

	
	StatusMessage = "";	// initialized, when necessary, at page load and diosplayed in the window status box or text status box or TextBoxStatusBox

	SiteRoot = "/";	//this should be the same as the CF constant SiteRootURL that is set in application.cfm; this JS constant is used, e.g., when creating image variables for buttons; e.g., when SiteRoot is "/komm/" the path to images is /komm/images/ or SiteRoot + "images/"
	
	// images for the RussianEnglish button (switch languages)
	EngSwitchLangButtonUp = new Image(); //English-page button
	EngSwitchLangButtonUp.src = SiteRoot + "images/l_blue.gif";
	EngSwitchLangButtonHot = new Image();
	EngSwitchLangButtonHot.src = SiteRoot + "images/l_blue_on.gif";

	LEngSwitchLangButtonUp = new Image(); //English-page button
	LEngSwitchLangButtonUp.src = SiteRoot + "images/t_lang_switch-english.gif";
	LEngSwitchLangButtonHot = new Image();
	LEngSwitchLangButtonHot.src = SiteRoot + "images/t_lang_switch-english_on.gif";

	// images for the RussianEnglish button (switch languages)
	RusSwitchLangButtonUp = new Image(); //Russian-page button
	RusSwitchLangButtonUp.src = SiteRoot + "images/r_blue.gif";
	RusSwitchLangButtonHot = new Image();
	RusSwitchLangButtonHot.src = SiteRoot + "images/r_blue_on.gif";

	LRusSwitchLangButtonUp = new Image(); //Russian-page button
	LRusSwitchLangButtonUp.src = SiteRoot + "images/t_lang_switch-russian.gif";
	LRusSwitchLangButtonHot = new Image();
	LRusSwitchLangButtonHot.src = SiteRoot + "images/t_lang_switch-russian_on.gif";

	// images for the Both Languages button (display bilinguial view)
	BilingualButtonUp = new Image(); //English-page button
	BilingualButtonUp.src = SiteRoot + "images/lang.gif";
	BilingualButtonHot = new Image();
	BilingualButtonHot.src = SiteRoot + "images/lang_on.gif";

	LEngBilingualButtonUp = new Image(); //English-page button
	LEngBilingualButtonUp.src = SiteRoot + "images/t_lang-english.gif";
	LEngBilingualButtonHot = new Image();
	LEngBilingualButtonHot.src = SiteRoot + "images/t_lang-english_on.gif";

	LRusBilingualButtonUp = new Image(); //English-page button
	LRusBilingualButtonUp.src = SiteRoot + "images/t_lang-russian.gif";
	LRusBilingualButtonHot = new Image();
	LRusBilingualButtonHot.src = SiteRoot + "images/t_lang-russian_on.gif";

	// images for the Edit Tour button
	EditTourButtonUp = new Image(); // Russian-page button
	EditTourButtonUp.src = SiteRoot + "images/edit.gif";
	EditTourButtonHot = new Image();
	EditTourButtonHot.src = SiteRoot + "images/edit_on.gif";

	LEngEditTourButtonUp = new Image(); // Russian-page button
	LEngEditTourButtonUp.src = SiteRoot + "images/t_edit-english.gif";
	LEngEditTourButtonHot = new Image();
	LEngEditTourButtonHot.src = SiteRoot + "images/t_edit-english_on.gif";

	LRusEditTourButtonUp = new Image(); // Russian-page button
	LRusEditTourButtonUp.src = SiteRoot + "images/t_edit-russian.gif";
	LRusEditTourButtonHot = new Image();
	LRusEditTourButtonHot.src = SiteRoot + "images/t_edit-russian_on.gif";

	// images for the Create New Tour button
	NewTourButtonUp = new Image(); // Russian-page button
	NewTourButtonUp.src = SiteRoot + "images/new.gif";
	NewTourButtonHot = new Image();
	NewTourButtonHot.src = SiteRoot + "images/new_on.gif";

	LEngNewTourButtonUp = new Image(); // Russian-page button
	LEngNewTourButtonUp.src = SiteRoot + "images/t_new-english.gif";
	LEngNewTourButtonHot = new Image();
	LEngNewTourButtonHot.src = SiteRoot + "images/t_new-english_on.gif";

	LRusNewTourButtonUp = new Image(); // Russian-page button
	LRusNewTourButtonUp.src = SiteRoot + "images/t_new-russian.gif";
	LRusNewTourButtonHot = new Image();
	LRusNewTourButtonHot.src = SiteRoot + "images/t_new-russian_on.gif";

	// images for the Sign In button
	SignInButtonEngUp = new Image(); // Russian-page button
	SignInButtonEngUp.src = SiteRoot + "images/sign_in_eng.gif";
	SignInButtonEngHot = new Image();
	SignInButtonEngHot.src = SiteRoot + "images/sign_in_eng_on.gif";

	LSignInButtonEngUp = new Image(); // Russian-page button
	LSignInButtonEngUp.src = SiteRoot + "images/t_sign_in-english.gif";
	LSignInButtonEngHot = new Image();
	LSignInButtonEngHot.src = SiteRoot + "images/t_sign_in-english_on.gif";

	SignInButtonRusUp = new Image(); // Russian-page button
	SignInButtonRusUp.src = SiteRoot + "images/sign_in_rus.gif";
	SignInButtonRusHot = new Image();
	SignInButtonRusHot.src = SiteRoot + "images/sign_in_rus_on.gif";

	LSignInButtonRusUp = new Image(); // Russian-page button
	LSignInButtonRusUp.src = SiteRoot + "images/t_sign_in-russian.gif";
	LSignInButtonRusHot = new Image();
	LSignInButtonRusHot.src = SiteRoot + "images/t_sign_in-russian_on.gif";

	// images for the Sign Out button
	SignOutButtonEngUp = new Image(); // Russian-page button
	SignOutButtonEngUp.src = SiteRoot + "images/sign_out_eng.gif";
	SignOutButtonEngHot = new Image();
	SignOutButtonEngHot.src = SiteRoot + "images/sign_out_eng_on.gif";

	LSignOutButtonEngUp = new Image(); // Russian-page button
	LSignOutButtonEngUp.src = SiteRoot + "images/t_sign_out-english.gif";
	LSignOutButtonEngHot = new Image();
	LSignOutButtonEngHot.src = SiteRoot + "images/t_sign_out-english_on.gif";

	SignOutButtonRusUp = new Image(); // Russian-page button
	SignOutButtonRusUp.src = SiteRoot + "images/sign_out_rus.gif";
	SignOutButtonRusHot = new Image();
	SignOutButtonRusHot.src = SiteRoot + "images/sign_out_rus_on.gif";

	LSignOutButtonRusUp = new Image(); // Russian-page button
	LSignOutButtonRusUp.src = SiteRoot + "images/t_sign_out-russian.gif";
	LSignOutButtonRusHot = new Image();
	LSignOutButtonRusHot.src = SiteRoot + "images/t_sign_out-russian_on.gif";

	// images for the Search button
	SearchButtonUp = new Image(); //English-page button
	SearchButtonUp.src = SiteRoot + "images/mag_glass.gif";
	SearchButtonHot = new Image();
	SearchButtonHot.src = SiteRoot + "images/mag_glass_on.gif";

	LEngSearchButtonUp = new Image(); //English-page button
	LEngSearchButtonUp.src = SiteRoot + "images/t_mag_glass-english.gif";
	LEngSearchButtonHot = new Image();
	LEngSearchButtonHot.src = SiteRoot + "images/t_mag_glass-english_on.gif";

	LRusSearchButtonUp = new Image(); //English-page button
	LRusSearchButtonUp.src = SiteRoot + "images/t_mag_glass-russian.gif";
	LRusSearchButtonHot = new Image();
	LRusSearchButtonHot.src = SiteRoot + "images/t_mag_glass-russian_on.gif";

	// images for the Site Map button
	SiteMapButtonUp = new Image(); //English-page button
	SiteMapButtonUp.src = SiteRoot + "images/site_map.gif";
	SiteMapButtonHot = new Image();
	SiteMapButtonHot.src = SiteRoot + "images/site_map_on.gif";

	LEngSiteMapButtonUp = new Image(); //English-page button
	LEngSiteMapButtonUp.src = SiteRoot + "images/t_site_map-english.gif";
	LEngSiteMapButtonHot = new Image();
	LEngSiteMapButtonHot.src = SiteRoot + "images/t_site_map-english_on.gif";

	LRusSiteMapButtonUp = new Image(); //English-page button
	LRusSiteMapButtonUp.src = SiteRoot + "images/t_site_map-russian.gif";
	LRusSiteMapButtonHot = new Image();
	LRusSiteMapButtonHot.src = SiteRoot + "images/t_site_map-russian_on.gif";

	// images for the Tour Filter button
	TourFilterButtonUp = new Image(); //English-page button
	TourFilterButtonUp.src = SiteRoot + "images/filter.gif";
	TourFilterButtonHot = new Image();
	TourFilterButtonHot.src = SiteRoot + "images/filter_on.gif";

	LEngTourFilterButtonUp = new Image(); //English-page button
	LEngTourFilterButtonUp.src = SiteRoot + "images/t_filter-english.gif";
	LEngTourFilterButtonHot = new Image();
	LEngTourFilterButtonHot.src = SiteRoot + "images/t_filter-english_on.gif";

	LRusTourFilterButtonUp = new Image(); //English-page button
	LRusTourFilterButtonUp.src = SiteRoot + "images/t_filter-russian.gif";
	LRusTourFilterButtonHot = new Image();
	LRusTourFilterButtonHot.src = SiteRoot + "images/t_filter-russian_on.gif";

	// images for the Print button
	PrintButtonUp = new Image();
	PrintButtonUp.src = SiteRoot + "images/print.gif";
	PrintButtonHot = new Image();
	PrintButtonHot.src = SiteRoot + "images/print_on.gif";

	LEngPrintButtonUp = new Image();
	LEngPrintButtonUp.src = SiteRoot + "images/t_print-english.gif";
	LEngPrintButtonHot = new Image();
	LEngPrintButtonHot.src = SiteRoot + "images/t_print-english_on.gif";

	LRusPrintButtonUp = new Image();
	LRusPrintButtonUp.src = SiteRoot + "images/t_print-russian.gif";
	LRusPrintButtonHot = new Image();
	LRusPrintButtonHot.src = SiteRoot + "images/t_print-russian_on.gif";

	// images for the Close button
	CloseButtonUp = new Image();
	CloseButtonUp.src = SiteRoot + "images/close_red20-AA.jpg";
	CloseButtonHi = new Image();
	CloseButtonHi.src = SiteRoot + "images/close20-AA.jpg";

	// images for the ExpandCollapse buttons
	PlusButton = new Image(); // Russian-page button
	PlusButton.src = SiteRoot + "images/plus_blue4.gif";
	PlusButtonHot = new Image();
	PlusButtonHot.src = SiteRoot + "images/plus_blue5.gif";
	MinusButton = new Image(); // Russian-page button
	MinusButton.src = SiteRoot + "images/minus_blue4.gif";
	MinusButtonHot = new Image();
	MinusButtonHot.src = SiteRoot + "images/minus_blue5.gif";
		
	function SetOpenSections() {
	/* scans the text sections in the page and makes a list of those that are currently expanded;
		assigns the list to hidden field in the page so it can be passed on to the next load */
		
		var CurrPage = document.location.href;
		CurrPage = CurrPage.split("/");
		CurrPage = CurrPage[CurrPage.length-1]; // e.g. "v_tours.cfm" or "audio.cfm" or "about.cfm" etc.
		var OpenSections=""; // this will be a comma-separated list of the index numbers of those text sections that are currently open, e.g. "1,3"
		for (var i=0; i<document.images.length; i++) {
			var ButtonObj = document.images[i];
//alert(ButtonObj.id);
			if ((ButtonObj.id.indexOf("InnerTextBox_") > -1) && (ButtonObj.id.indexOf("_ToggleButton") > -1)) { // this is a page structured like about.cfm; this image is an expand-collapse button, and its id is of the form InnerTextBox_X_ToggleButton where X is the index of the section on the page (1-based)
				if (ButtonObj.src.indexOf("Minus") > -1) { // the section is expanded
			 		var SectionIndex = ButtonObj.id.split("_")[1]; // e.g., "1" if this is section 1
					if (OpenSections == "")
				 		OpenSections = SectionIndex;
					else
				 		OpenSections = OpenSections + "," + SectionIndex;
				}
			} else { // this may be a page structured like Video Tours
				if ((ButtonObj.id.indexOf("Cell_") > -1) && (ButtonObj.id.indexOf("_Button") > -1)) { // this is a page structured like v_tours.cfm; this image is an expand-collapse button for the tour, and its id is of the form Cell_X_Button where X is the index of the tour in the TOC (1-based)
					if (ButtonObj.src.indexOf("Minus") > -1) { // the tour contents are is expanded
				 		var SectionIndex = ButtonObj.id.split("_")[1]; // e.g., "1" if this is Tour 1
						if (OpenSections == "")
					 		OpenSections = SectionIndex;
						else
					 		OpenSections = OpenSections + "," + SectionIndex;
					}
				}			
			}
		}
		document.getElementById("VToursForm").elements["OpenSections"].value = OpenSections; // this list will be passed to the template when it is reloaded, and the same sections will be expanded on reload
	}
	
	function SwitchLanguage() {
	/* checks the value of hidden form field KommLanguage and switches it to the other language so that the cookie and variable KommLangauge are changed at the next load */

		if (document.getElementById("VToursForm").elements["KommLanguage"]) {
			var CurrLang = document.getElementById("VToursForm").elements["KommLanguage"].value;

			if (CurrLang == "Russian") CurrLang = "English"
			else  CurrLang = "Russian";
			
			document.getElementById("VToursForm").elements["KommLanguage"].value = CurrLang;
		}	
	}
	

	function CheckCookiesUNUSED() {
		/* determines if the required cookies have been set and redirects accordingly */
		var InPlayer = getCookie("INPLAYER");
		var VideoType = getCookie("VIDEOTYPE");
		var KommLanguage = getCookie("KOMMLANGUAGE");

		if ((VideoType == null) || (KommLanguage == null)) { // at least one cookie is missing, which means this is a first visit, or the cookies have been deleted
			var FirstVisit = 1;
		}

		if (FirstVisit) {
			window.location.href = SiteRoot + "cfm/options.cfm?Problem=FirstVisit";
			return null;
		}

		return null;
	}	// function CheckCookies
	
	function ShowStatusMessageUNUSED(Message, ShowArrow) {
		/* shows the text of Message in the window- or text-panel status bar;
			if ShowArrow is present and true, also shows the attention arrow that points at the status bar */

		if (Message != "") {
			if (typeof(ShowArrow) == "undefined") ShowArrow = true;	// show the arrow
			
			if (document.getElementById("WindowStatusBox")) {
				document.getElementById("WindowStatusBox").innerHTML = Message;
				document.getElementById("WindowStatusBoxDiv").style.borderWidth = "1px";
				document.getElementById("WindowStatusBoxDiv").style.scrollTop = 0;
			} else {
				if (document.getElementById("TextBoxStatusBox")) {
					document.getElementById("TextBoxStatusBox").innerHTML = Message;
					document.getElementById("TextBoxStatusBox").scrollTop = 0;
					document.getElementById("TextBoxStatusBoxDiv").style.borderWidth = "1px";
					document.getElementById("TextBoxStatusBox").style.visibility = "visible";
				}
			}
			if (ShowArrow) {
				document.getElementById("AttentionArrow").style.visibility = "visible";
				document.getElementById("AttentionCloseButton").style.visibility = "visible";
			}
		}
	}

	function ShowMessageBubble(Message) {
		/* shows div called "MessageBubble" and displays the text of Message in its scrollable text box */

		if (Message != "") {	// display bubble with its own message
			document.getElementById("MessageBubble").style.visibility = "visible";
			document.getElementById("BubbleMessage").innerHTML = Message;
			document.getElementById("BubbleMessage").scrollTop = 0;
		}	
	}

	function Trim(What) {
		/* strips leading and trailing spaces */

		if (What.length == 0) return What;
		What = What + "";
		while (What.charAt(0)==" ") What = What.substr(1,What.length-1);
		while (What.charAt(What.length-1)==" ") What = What.substr(0,What.length-1);
		return What;
	}

	function CheckFields(thisForm) {
		/* validates field values */

		if (IgnoreFields) return true;
		var CurrEmail = Trim(thisForm.elements["EmailAddress"].value);
		if (CurrEmail == "") {
			alert("Please type your email address.");
			thisForm.elements["EmailAddress"].focus();
			return false;
		} else {
			thisForm.elements["EmailAddress"].value = CurrEmail;
		 return true;
		}
	}

	function AdjustWindow(Width, Height){
	/* adjusts current window to Width x Height */
	 	if ((typeof(Width) != "number") || (typeof(Height) != "number")) {
			alert("AdjustWindow was called with invalid arguments.");
			window.close();
		}
		var WinWidth = Width;
		var WinHeight = Height;
 //alert(OSVersion);
//alert(BrowserName);
		switch (BrowserName) {
			case "IE" :
//alert(BrowserVersion);
				if (BrowserVersion < 7) {
					WinHeight = Height + 30 + 30; // 30 is the height of the title bar and status bar
					WinWidth = Width + 20 + 12; // 20 is the width of the vertical scroll bar; the rest is for the two vertical borders;
				} else {
					WinHeight = Height + 30 + 30; // 30 is the height of the title bar
					WinWidth = Width + 20 + 12; // 20 is the width of the vertical scroll bar; the rest is for the two vertical borders;
				}
				if (OSVersion >=6) {
					//Vista or later
					WinHeight = Height + 84 + 12;
					WinWidth = Width + 36;
// alert(WinHeight + " " + WinWidth);
				}
				break;
			case "FF" :
				WinHeight = Height + 60;
				WinWidth = Width + 30;
				if (OS == "Mac") {
					WinHeight = Height + 32;
					WinWidth = Width + 14;
				}
				
				if (OS == "Win") {				
					if (OSVersion >=6) {
						//Vista or later
						WinHeight = Height + 60;
						WinWidth = Width + 30;
	// alert(WinHeight + " " + WinWidth);
					} else {
						WinHeight = Height + 30 + 30; // 30 is the height of the title bar and the status bar; FF won't allow a window w/o a status bar
						WinWidth = Width + 8; // 20 is the width of the vertical scroll bar; the rest is for the two vertical borders;
				}
				} // OS == Win
				break;
			case "OP" :
				WinHeight = Height + 10;
				WinWidth = Width + 8; 
				break;
			case "SF" :
				WinHeight = Height + 30;
				WinWidth = Width + 16; 
				break;
		
		
		}
		window.resizeTo(WinWidth, WinHeight);
	}
	
	function OpenSmallWindow(URL, WindowName) {
	/* opens a small window, loads URL */
		if (arguments.length == 1) var WindowName = "KommSubWindow";
		SmallWindow=window.open(URL,WindowName,"toolbar=no,width=520,height=400,status=yes,scrollbars=yes,resizable=yes,menubar=yes");
		SmallWindow.focus();
	}

	function OpenEssay(ClipID, Language, CustomTourID, SearchTarget) {
	/* opens a browser window and loads view_text.cfm;
		if present, SearchTarget is a URLEncoded list of search terms (target words); we want these words to be highlighted when the texts are displayed */
		if (typeof(Language) == "undefined") {
			Language = getCookie("KOMMLANGUAGE");
			if (Language == null) Language = "Russian";
		}
		if ((Language != "Russian") && (Language != "English")) Language = "Russian";
		
		if (arguments.length < 3) {
			CustomTourID = 0;
			SearchTarget = "";
		}

		if (isNaN(CustomTourID)) CustomTourID = 0;
		
		var URL = "view_text.cfm?ClipID=" + ClipID + "&Field=NarrationTranscript&Language=" + Language + "&CustomTourID=" + CustomTourID + "&SearchTargetList=" + SearchTarget;
		ViewEssayWindow = open(URL,"ViewEssayWin","");
		ViewEssayWindow.focus();
	}

	function ResizeWindowTo(WinInnerWidth, WinInnerHeight) {
		switch (BrowserName) {
			case "IE" :
			// some versions of IE may refuse to let the window be resized
				if (BrowserVersion < 7) {
					WinWidth = WinInnerWidth + 12;
					WinHeight = WinInnerHeight + 51;
				} else {
					if (OSVersion < 6) { // Windows 2000 or XP
						WinWidth = WinInnerWidth + 12;
						WinHeight = WinInnerHeight + 60;
					} else { // Windows Vista
						WinWidth = WinInnerWidth + 20;
						WinHeight = WinInnerHeight + 92;
					}
				}

				window.resizeTo(WinWidth, WinHeight);
				break;
			case "FF" : //this works for Windows and Mac OS
				WinWidth = WinInnerWidth + 0;
				WinHeight = WinInnerHeight + 0;
				window.innerWidth = WinWidth;
				window.innerHeight = WinHeight;
				break;
			case "MZ" :
				WinWidth = WinInnerWidth + 0;
				WinHeight = WinInnerHeight + 0;
				window.innerWidth = WinWidth;
				window.innerHeight = WinHeight;
				break;
			case "NN" :
				WinWidth = WinInnerWidth + 0;
				WinHeight = WinInnerHeight + 0;
				window.innerWidth = WinWidth;
				window.innerHeight = WinHeight;
				break;
			case "OP" :
				WinWidth = WinInnerWidth + 0;
				WinHeight = WinInnerHeight + 40;
				window.resizeTo(WinWidth, WinHeight);
			case "CM" :
				WinWidth = WinInnerWidth + 0;
				WinHeight = WinInnerHeight + 40;
				window.resizeTo(WinWidth, WinHeight);
				break;
			case "SF" : //this works for Windows and Mac OS
				WinWidth = WinInnerWidth + 0;
				WinHeight = WinInnerHeight + 40;
				window.resizeTo(WinWidth, WinHeight);
				break;
		}
	
	}
	

	function OpenAudio(ClipID, ShowAddressBar, Language, ShowTexts, CustomTourID, SearchTarget) {
	/* opens a browser window and loads edit_text.cfm; if ShowAddressBar, shows address bar;
		if present, SearchTarget is a URLEncoded list of search terms (target words); we want these words to be highlighted when the texts are displayed */
		switch (arguments.length) {
			case 0 : // fatal error
				alert("Program error in OpenAudio: no parameters.")
				return;
			case 1 :
				ShowAddressBar = 0;
				Language = "FromCookie";
				ShowTexts = 0;				
				CustomTourID = 0;
				SearchTarget = "";
				break;
			case 2 :
				Language = "FromCookie";
				ShowTexts = 0;
				CustomTourID = 0;
				SearchTarget = "";
				break;
			case 3 :
				ShowAddressBar = 1;
				Language = "FromCookie";
				ShowTexts = 1;
				CustomTourID = 0;
				SearchTarget = "";
			case 4 :
				CustomTourID = 0;
				SearchTarget = "";
			case 5 :
				SearchTarget = "";
		}
		
		if (ShowTexts) {
			ShowAddressBar = true;
		}

//		alert("When programmed, this link will display the " + Language + " version of video clip " + ClipID)

		var WinWidth = 496;  // 480 (video and jumbo thumbnail width) + HorMargin * 2
		if (ShowTexts) { // don't try to control the window size
			var Props = "toolbar=no,location=yes,status=yes,scrollbars=yes,resizable=yes,menubar=no";
		} else {
			if (ShowAddressBar) {
				var Props = "toolbar=no,location=yes,width=" + WinWidth + ",height=130,status=yes,scrollbars=no,resizable=yes,menubar=no";
			} else {
				var Props = "toolbar=no,location=no,width=" + WinWidth + ",height=100,status=yes,scrollbars=no,resizable=yes,menubar=no";
			}
		}

		var URL = "audio_player.cfm?ClipID=" + ClipID + "&ShowAddressBar=" + ShowAddressBar + "&Language=" + Language + "&ShowTexts=" + ShowTexts + "&CustomTourID=" + CustomTourID + "&SearchTargetList=" + SearchTarget;
		HearClipWindow = window.open(URL,"HearClipWin",Props);
		HearClipWindow.focus();
	}
	
	function OpenClip(ClipID, ShowAddressBar, Language, ShowTexts, CustomTourID, SearchTarget) {
	/* opens a browser window and loads edit_text.cfm;
		if present, SearchTarget is a URLEncoded list of search terms (target words); we want these words to be highlighted when the texts are displayed */
		switch (arguments.length) {
			case 0 : // fatal error
				alert("Program error in OpenClip: no parameters.")
				return;
			case 1 :
				ShowAddressBar = 0;
				Language = "FromCookie";
				ShowTexts = 0;				
				CustomTourID = 0;
				SearchTarget = "";
				break;
			case 2 :
				Language = "FromCookie";
				ShowTexts = 0;
				CustomTourID = 0;
				SearchTarget = "";
				break;
			case 3 :
				ShowAddressBar = 1;
				Language = "FromCookie";
				ShowTexts = 1;
				CustomTourID = 0;
				SearchTarget = "";
			case 4 : // error
				CustomTourID = 0;
				SearchTarget = "";
			case 5 : // error
				SearchTarget = "";
		}
		
		if (ShowTexts) ShowAddressBar = true;

//		alert("When programmed, this link will display the " + Language + " version of video clip " + ClipID)
		if (ShowTexts) { // don't try to control the window size
			var Props = "toolbar=no,location=yes,status=yes,scrollbars=yes,resizable=yes,menubar=no";
		} else {
			if (ShowAddressBar) {
				var Props = "toolbar=no,location=yes,width=480,height=490,status=yes,scrollbars=no,resizable=yes,menubar=no";
			} else { //it seems that IE 7 will not let you hide the address bar (location)
				var Props = "toolbar=no,location=no,width=480,height=460,status=yes,scrollbars=no,resizable=yes,menubar=no";
			}
		}
		var URL = "video_player.cfm?ClipID=" + ClipID + "&ShowAddressBar=" + ShowAddressBar + "&Language=" + Language + "&ShowTexts=" + ShowTexts + "&CustomTourID=" + CustomTourID + "&SearchTargetList=" + SearchTarget;
		ViewClipWindow = window.open(URL,"ViewClipWin",Props);
		ViewClipWindow.focus();
	}

	function OpenImage(ClipID, ClipIDList, Language, SearchTarget) {
		/* opens a browser window and loads view_image.cfm */
		/* if present, ClipIDList is a URLEncoded CF list of clip IDs that are in the same group
		 as the ClipID, e.g. all photographs that are listed in the Details box of
		 the video clips fro which the ClipID is being displayed; this list is passed on to
		 the template as a URL param;
		 if present, SearchTarget is a URLEncoded list of search terms (target words); we want these words to be highlighted when the texts are displayed */
		if (arguments.length < 2) {
			ClipIDList = "";
			Language = "";
			SearchTarget = "";
		}
		if (arguments.length < 3) {
			Language = "";
			SearchTarget = "";
		}
		if (arguments.length < 4) {
			SearchTarget = "";
		}
		var Props = "";
		var URL = "view_image.cfm?ClipID=" + ClipID + "&ClipIDList=" + ClipIDList + "&Language=" + Language + "&SearchTargetList=" + SearchTarget;

		ImageWindow = open(URL,"ImageWin",Props);
		ImageWindow.focus();
	}

	function OpenImageWindow(URL, Caption, Width, Height, JumboImageAvailable) {
		/* opens a browser window, loads image URL */
		if (arguments.length < 5) JumboImageAvailable = false;

		var Props = "toolbar=no,scrollbars=no,resizable=yes,menubar=no,status=yes,width=" + Width + ",height=" + Height;
		var HTML = "<html><head><title>" + Caption + "</title></head><body style='padding:0px; margin:0px; '>";
		if (JumboImageAvailable) 
			HTML = HTML + " <a href='" + URL.replace('photo','photo_lg') + "' title='Click for the largest image available.' onclick='window.moveTo(0, 0); window.resizeTo(screen.width, screen.height)'>";
		HTML = HTML + "<img style='border: 0px; ' alt='' src='" + URL + "' width='" + Width + "' height='" + Height + "'";
		if (! JumboImageAvailable)
			HTML = HTML + " title='' "; // No larger version available.
		HTML = HTML + ">"
		if (JumboImageAvailable) HTML = HTML + "</a>";
		HTML = HTML + " </body></html>";

		ImageWindow=window.open("","ImageSubWindow",Props);
		if (BrowserName == "FF") {		
			ImageWindow.innerWidth = Width;
			ImageWindow.innerHeight = Height;
		} else {
			var WidthDelta = 0;
			var HeightDelta = 0;
			if (BrowserName == "IE") {
				if (BrowserVersion <= 6) {
					var WidthDelta = 12;
					if (OSVersion == 5.0) // Windows 2000
						var HeightDelta = 60;
					else
						var HeightDelta = 51;
				} else {
					if (OSVersion >= 6) { // Windows Vista
						var WidthDelta = 20;
						var HeightDelta = 88;
					} else {
						var WidthDelta = 12;
						var HeightDelta = 60;
					}
				}
			ImageWindow.resizeTo(Width + WidthDelta, Height + HeightDelta);
			}
		}
		ImageWindow.document.write(HTML);
		ImageWindow.document.close();
		ImageWindow.focus();
	}

	function OpenWinMediaWindow(URL, Caption, Width, Height) {
		/* opens a browser window, loads Windows Media HTML file at URL */

		var Props = "status=yes,toolbar=no,scrollbars=no,resizable=yes,menubar=no,width=" + Width + ",height=" + Height;
		WinMediaWindow=window.open(URL,"WinMediaSubWindow",Props);

		if (BrowserName == "FF") {		
			WinMediaWindow.innerWidth = Width;
			WinMediaWindow.innerHeight = Height;
		} else {
			WinMediaWindow.resizeTo(Width+12, Height+61);
		}	

		WinMediaWindow.focus();
	}

	function OpenRealMediaWindow(URL, Caption, Width, Height) {
		/* opens a browser window, loads Real media HTML file at URL */

		var Props = "status=yes,toolbar=no,scrollbars=no,resizable=yes,menubar=no,width=" + Width + ",height=" + Height;
		RealMediaWindow=window.open(URL,"RealMediaSubWindow",Props);

		if (BrowserName == "FF") {		
			RealMediaWindow.innerWidth = Width;
			RealMediaWindow.innerHeight = Height;
		} else {
			RealMediaWindow.resizeTo(Width+12, Height+60);
		}

		RealMediaWindow.focus();
	}

	function OpenQTWindow(URL, Caption, Width, Height) {
		/* opens a browser window, loads a QT HTML file at URL */

		var Props = "status=yes,toolbar=no,scrollbars=no,resizable=yes,menubar=no,width=" + Width + ",height=" + Height;
		QTWindow=window.open(URL,"QTSubWindow",Props);

		if (BrowserName == "FF") {		
			QTWindow.innerWidth = Width;
			QTWindow.innerHeight = Height;
		} else {
			QTWindow.resizeTo(Width+12, Height+60);
		}

		QTWindow.focus();
	}
	
	function SetLanguageUNUSED(Lang) {		
		/* sets cookie KOMMLANGUAGE and submits a form to reload this page */
		if (! document.getElementById) return;

		setCookie("KOMMLANGUAGE", Lang, "Feb 2, 2944 00:00:00", "/");
		
		if (document.getElementById("VToursForm")) {
			document.getElementById("VToursForm").elements["KommLanguage"].value = Lang; //this will make sure that the same cookie is also set by CF
			document.getElementById("VToursForm").submit();
		}

		return null;
	}
	
	function SetVideoTypeUNUSED(Type) {		
		/* sets cookie VIDEOTYPE and submits a form to reload this page */
		if (! document.getElementById) return;

		setCookie("VIDEOTYPE", Type, "Feb 2, 2944 00:00:00", "/");

		if (document.getElementById("VToursForm")) {
			document.getElementById("VToursForm").elements["VideoType"].value = Type; //this will make sure that the same cookie is also set by CF
			document.getElementById("VToursForm").submit();
		}

		return null;
	}
	
	function SetInPlayerUNUSED(What) {		
		/* sets cookie INPLAYER */
		if (! document.getElementById) return;

		var res = setCookie("INPLAYER", What, "Feb 2, 2944 00:00:00", "/");

		if (document.getElementById("VToursForm")) {
			document.getElementById("VToursForm").elements["InPlayer"].value = What; //this will make sure that the same cookie is also set by CF
			document.getElementById("VToursForm").submit();
		}
		return null;
	}

	function toggleVisibility(TargetTourID) {
		/* toggles style.display of TargetTourID between block and none; TargetTourID is a string */

		if (! document.getElementById) return;

		//if tour table TargetTourID is expanded, collapse it and do nothing else
		var obj = document.getElementById(TargetTourID);
		var TOCTableObj = document.getElementById("TOCTable");
		var TargetTourNumber = TargetTourID.split("_")[1];
		if (obj.style.display == 'block') {	//target tour is expanded
			obj.style.display = 'none';
//			ButtonCellObj = TOCTableObj.rows[TargetTourNumber - 1].cells[1];
			var ButtonImageObj = document.getElementById("Cell_" + TargetTourNumber + "_Button");
			ButtonImageObj.src = PlusButton.src;
//			ButtonCellObj.innerHTML = ButtonCellObj.innerHTML.replace(Minus, Plus);

			// see if all other tours are collapsed; if so, reset the Expand-Collapse-All-Tours button
			var AllCollapsed = true;
			for (var i=0; i<TOCTableObj.rows.length; i++) { //each row in the table is one tour
				var ButtonImageObj = document.getElementById("Cell_" + (i+1) + "_Button");
				if (ButtonImageObj.src.indexOf("Minus") >= 0)
					AllCollapsed = false;
//				var RowObj = TOCTableObj.rows[i];
//				var ButtonCellObj = RowObj.cells[1];
//				if (ButtonCellObj.innerHTML.indexOf(Minus) >= 0)
//					AllCollapsed = false;
			}
			if (AllCollapsed) {
				var ButtonImageObj = document.getElementById("ExpandCollapseAllToursButton");	//this is the Expand-Collapse-All-Tours image
				ButtonImageObj.src = PlusButton.src; // reset the Expand-Collapse-All-Tours button
//				ButtonCellObj = TOCTableObj.rows[0].cells[0];
//				ButtonCellObj.innerHTML = ButtonCellObj.innerHTML.replace(Minus, Plus);						
			}
		} else {	//target tour is collapsed
			//collapse all tour tables:
			for (var i=0; i<TOCTableObj.rows.length; i++) { //each row in the table is one tour
				var RowObj = TOCTableObj.rows[i];
				var ButtonCellObj = RowObj.cells[1];
				var TourNumber = ButtonCellObj.id.split("_")[1];

			var ButtonImageObj = document.getElementById("Cell_" + TourNumber + "_Button");
				ButtonImageObj.src = PlusButton.src;
				var TourTable = document.getElementById("TourTable_" + TourNumber);
				TourTable.style.display = 'none';
//				if (ButtonCellObj.innerHTML.indexOf(Plus) < 0)
//					ButtonCellObj.innerHTML = ButtonCellObj.innerHTML.replace(Minus, Plus);
			}

			//expand tour table TargetTourID
			obj.style.display = 'block';
			var ButtonImageObj = document.getElementById("Cell_" + TargetTourNumber + "_Button");
			ButtonImageObj.src = MinusButton.src;
//			ButtonCellObj = TOCTableObj.rows[TargetTourNumber - 1].cells[1];
//			ButtonCellObj.innerHTML = ButtonCellObj.innerHTML.replace(Plus, Minus);
			
			//reset the Expand-Collapse-All-Tours button
			var ButtonImageObj = document.getElementById("ExpandCollapseAllToursButton");	//this is the Expand-Collapse-All-Tours image
			ButtonImageObj.src = MinusButton.src; // reset the Expand-Collapse-All-Tours button
//			ButtonCellObj = TOCTableObj.rows[0].cells[0];
//			ButtonCellObj.innerHTML = ButtonCellObj.innerHTML.replace(Plus, Minus);			
		}
	}	//function toggleVisibility

	function ToggleAllTourTables() {
		/* sets style.display of all tour tables to block or none; 
			resets collapse-expand buttons accordingly */
		if (! document.getElementById) return;

		var TOCTableObj = document.getElementById("TOCTable");	//each row in the table pertains to one Tour
		var ButtonImageObj = document.getElementById("ExpandCollapseAllToursButton");	//this is the Expand-Collapse-All-Tours image

		if (ButtonImageObj.src.indexOf("plus") > 0) {	//all tours are collapsed
			var NewDisplay = "block"; // all tours will be expanded by setting their "display" property to "block"
			ButtonImageObj.src = MinusButton.src; // reset the Expand-Collapse-All-Tours button
		} else {
			var NewDisplay = "none"; // all tours will be collapsed by setting their "display" property to "none"
			ButtonImageObj.src = PlusButton.src; // reset the Expand-Collapse-All-Tours button
		}

		//collapse or expand all tour tables:
		for (var i=0; i<TOCTableObj.rows.length; i++) { //each row in the table is one tour
			var RowObj = TOCTableObj.rows[i];
			var ButtonCellObj = RowObj.cells[1]; // the expand-collapse button for the tour is always in cell 1
			var TourNumber = ButtonCellObj.id.split("_")[1]; // the IDs are of the form XXX_[Num] where Num is the tour number; first tour is number 1
			var ButtonImageObj = document.getElementById("Cell_" + TourNumber + "_Button");

			var TourTable = document.getElementById("TourTable_" + TourNumber);
			TourTable.style.display = NewDisplay;
			if (NewDisplay == "none")
				ButtonImageObj.src = PlusButton.src;
			else
				ButtonImageObj.src = MinusButton.src;
		}
	}	//function ToggleAllTourTables
	
	function ToggleTextBox(BoxID) {
		var ExpandButton = document.getElementById(BoxID + "_ToggleButton")
		var TextBox = document.getElementById(BoxID);

		if (TextBox.style.display == "block") {
			ExpandButton.src = PlusButton.src;
			TextBox.style.display = "none";
		} else
		{
			ExpandButton.src = MinusButton.src;
			TextBox.style.display = "block";
		}	
	}

	function ShowTourFilterForm(DisplayStyle) {
	/* sets "display" of the Tour selection form to string DisplayStyle */
		//alert(document.getElementById('FilterSelector').style.display);
		if (document.getElementById('FilterSelector')) {
			if (DisplayStyle == "block") {
				document.getElementById('FilterSelector').style.display = "block";
				document.getElementById('FilterButton').style.display = "none";
			} else {
				document.getElementById('FilterSelector').style.display = "none";
				document.getElementById('FilterButton').style.display = "block";
			}
		}
	}
	
	function CleanSkipToCell() {
		/* adjusts the appearance of cell SkipTo in v_tours_controls.cfm */
		var ClipSelector = document.getElementById("SkipToClipID");
		var SkipToCell = document.getElementById("SkipToCell");
		var Caption = document.getElementById("SkipToButtonCaption");
		
		if (ClipSelector.value == JSClipID) {	//clip currently selected in the dropdown list is the same that is displayed on the page
			// give the SkipTo cell a disabled appearance
			SkipToCell.style.color = "rgb(255, 255, 255)";
			SkipToCell.style.cursor = "default";
			ClipSelector.style.cursor = "default";
			Caption.innerHTML = "&nbsp";
		} else {
			// give the SkipTo cell an enabled appearance
			SkipToCell.style.color = "rgb(25,55,85)";
			SkipToCell.style.cursor = "pointer";
			ClipSelector.style.cursor = "pointer";			
			Caption.innerHTML = "go";
		}
	}

	function Bath() {
	/* displays a popup translator's note about the use of the word "bathroom" */
		var Note = "Bathroom, washroom, lavatory, toilet: In English usage, all these words refer to rooms with at least a toilet and a sink in them. In all Russian communal apartments, and many private apartments, the room with the toilet has only that; the room with a bath and possibly a sink is  separate. We have used the word lavatory for the first kind of room, and washroom or bathroom for the second.";
		if (document.getElementById("MessageBubble"))
			ShowMessageBubble(Note);
		else
			alert(Note);
	}
	
