// Global Variables -----------------------------------------------------------------------------------------------------------

	// Has the user typed any data yet?
	var userTyped	= false;

	// Get the screen dimensions.
	var isNetscape		= ( navigator.appName == "Netscape" ) ? 1 : 0;
	var screen_width	= isNetscape ? screen.availWidth : screen.width;
	var screen_height	= isNetscape ? screen.availHeight: screen.height;

// Function Definitions -------------------------------------------------------------------------------------------------------

	// This function retrieves a cookie value; returning def_value if a value hasn't been set for the specified cookie.
	function getCookie (c_name, def_value)
		{	if ( document.cookie.length > 0 )
				{	var c_start = document.cookie.indexOf(c_name + "=");
					if ( c_start != -1 )
						{	c_start = c_start + c_name.length + 1; 
						    c_end = document.cookie.indexOf(";", c_start);
						    if ( c_end == -1) c_end=document.cookie.length;
							return unescape(document.cookie.substring(c_start,c_end));
					    }; // if ( document.cookie.length > 0 )
				}; // if ( document.cookie.length > 0 )
			return def_value;
		}; // function getCookie (c_name, def_value)

	// ------------------------------------------------------------------------------------------------------------------------

	// This function sets a cookie value.
	function setCookie (c_name, value, expiredays)
		{	var exdate = new Date();
			exdate.setDate(exdate.getDate()+expiredays);
			var domain	= document.location.href;
			domain		= domain.replace(/http:\/\/([^$|\/]+)[^$]*/, "$1");
			domain		= domain.replace(/(.*?)\.([^\.]+\.[^$]+)/, ".$2");
			document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + ";path=/;domain=" + domain;
		}; // function setCookie (c_name, value, expiredays)


	function chompText (text, max_size)
		{	text		= text + "";
			var start	= Math.max(0, Math.min(max_size, text.length) - 1);
			var index	= start;

			for ( ; index > 0 && index < text.length; index-- )
				{	// Get the two input characters.
					var input1 = text.charAt(index);
					var input2 = text.charAt(index + 1);

					// Not on a word boundary.
					if ( !((input1 >= 'a' && input1 <= 'z') || (input1 >= 'A' && input1 <= 'Z')) )
						{	break;
						}; // if ( !((input1 >= 'a' && input1 <= 'z') || (input1 >= 'A' && input1 <= 'Z')) )

					// Not on a word boundary.
					if ( !((input2 >= 'a' && input2 <= 'z') || (input2 >= 'A' && input2 <= 'Z')) )
						{	break;
						}; // if ( !((input2 >= 'a' && input2 <= 'z') || (input2 >= 'A' && input2 <= 'Z')) )
				}; // for ( ; index > 0 && index < text.length; index-- )

			// Get the new text.
			var new_text = text.substring(0, index + 1);

			// Chop off any non-terminated tags at the end of the substring.
			new_text = new_text.replace(/<[^>]*$/, "");

			// Add ellipsis at the end as needed.
			new_text = new_text.replace(/\s*$/, "") + ( new_text.length < text.length ? "..." : "" );

			return new_text;
		}; // function chompText (text, max_size)

	// ------------------------------------------------------------------------------------------------------------------------

	// This function clears the specified field for the first time.
	function clearField (id)
		{	// Get the control.
			var control = document.getElementById(id);

			// Found the control; therefore, clear it.
			if ( control )
				{	control.value		= "";			
					control.onmousedown	= "";
					control.onkeypress	= "";
					control.focus();
				}; // if ( control )
		}; // function clearField (id)

	// ------------------------------------------------------------------------------------------------------------------------

	function getImageResFile (filename)
		{	if ( isScreen800x600() )
				{	var index = filename.lastIndexOf(".");
					filename  = filename.substring(0, index) + "_800x600" + filename.substring(index, filename.length);
				}; // if ( isScreen800x600() )
			return filename;
		}; // function getImageResFile (filename)

	// ------------------------------------------------------------------------------------------------------------------------

	// This function returns the value of the selected radio button in a group.
	function getSelectedRadioValue (form_id, radio_name)	
		{	// Get the form.
			var the_form = document.getElementById(form_id);

			// Get all the input controls in the form.
			var inputs = the_form ? the_form.getElementsByTagName("input") : new Array();

			// Find the input which has the specified name and is selected.
			for ( var index = 0; index < inputs.length; index++ )
				{	// Found a radio button with the given name.
					if ( inputs[index].getAttribute("name") == radio_name && inputs[index].getAttribute("type") == "radio" )
						{	if ( inputs[index].checked )
								{	return inputs[index].value;
								}; // if ( inputs[index].checked )
						}; // if ( inputs[index].getAttribute("name") == radio_name && inputs[index].getAttribute("type") == "radio" )
				}; // for ( index = 0; index < inputs.length; index++ )

			// A radio button isn't selected.
			return false;
		}; // function getSelectedRadioValue (form_id, radio_name)	

	// ------------------------------------------------------------------------------------------------------------------------

	// This function initializes the page.
	function initPage ()
		{	// Give the search box the focus.
			var control = document.getElementById("search_box_terms");
			
			if ( control )
				{	// Set the Javascript to clear the form when typing begins.
					control.onmousedown = Function("clearField('search_box_terms')");
					//control.onkeypress	= Function("clearField('search_box_terms')");
					
					// Set the focus.
					control.focus();
					//if ( control.setSelectionRange )
					//	{	control.setSelectionRange(0, 0);
						//}; // if ( control.setSelectionRange )
				}; // if ( control )	
		}; // function initPage ()

	// ------------------------------------------------------------------------------------------------------------------------

	// This function initializes the page.
	function initPageInner ()
		{	// Give the search box the focus.
			var control = document.getElementById("search_box_terms");
			
			if ( control )
				{	// Set the Javascript to clear the form when typing begins.
					control.onmousedown = Function("clearField('search_box_terms')");
					control.onkeypress	= Function("clearField('search_box_terms')");
				}; // if ( control )	
		}; // function initPageInner ()

	// ------------------------------------------------------------------------------------------------------------------------

	function initHomepage ()
		{	// Init the rest of the page.
			initPage();
		}; // function initHomepage ()

	// ------------------------------------------------------------------------------------------------------------------------

	// This function determines if the user's screen size is 800x600.
	function isScreen800x600 ()
		{	return screen.width == 800 && screen.height == 600;
		}; // function isScreen800x600 ()

	// ------------------------------------------------------------------------------------------------------------------------

	// This function looks up a value from the specified source.
	function lookup (form_id)
		{	// Get the looked source.
			var source = getSelectedRadioValue(form_id, "book");

			// The term to lookup.
			var term = "";

			// Get the form.
			var the_form = document.getElementById(form_id);

			// Get the term.
			var inputs = the_form ? the_form.getElementsByTagName("input") : new Array();

			// Find the term.
			for ( index = 0; index < inputs.length; index++ )
				{	if ( inputs[index].getAttribute("name") == "va" )
						{	term = inputs[index].value;
							break;
						}; // if ( inputs[index].getAttribute("name") == "va" )
				}; // for ( index = 0; index < inputs.length; index++ )

			// Lookup the term in the dictionary.
			if ( source == "dictionary" )
				{	document.location.href = "http://www.merriam-webster.com/dictionary/" + term;
				} // if ( source == "" )

			// Lookup the term in the thesaurus.
			else if ( source == "thesaurus" )
				{	document.location.href = "http://www.merriam-webster.com/thesaurus/" + term;
				} // else if ( source == "thesaurus" )

			// Lookup the term in the Spanish/English dictionary.
			else if ( source == "spanish_english" )
				{	document.location.href = "http://www.merriam-webster.com/spanish/" + term;
				} // else if ( source == "spanish_english" )
				
			// Lookup the term in the Medical dictionary.
			else if ( source == "medical" )
				{	document.location.href = "http://medical.merriam-webster.com/medical/" + term;
				} // else if ( source == "medical" )

			// Search the web for the term.
			else if ( source == "web" )
				{	document.location.href = "http://www.merriam-webster.com/cgi-bin/google_search.pl?q=" + term;
				} // else if ( source == "web" )

			// Invalid source specified.
			else
				{
				}; // else

			return false;
		}; // function lookup (form_id)

	// ------------------------------------------------------------------------------------------------------------------------

	// This function opens a popup window to playback the pronunciation of a word.
	function popWin (the_url)
		{	aWindow = window.open(the_url,"pron_window","toolbar=no,scrollbars=yes,status=no,resizable=yes,menubar=no,width=650,height=300");
		}; // function popWin (the_url)

	// ------------------------------------------------------------------------------------------------------------------------

	// This functions opens the Promo window for Merriam-Webster Unabridged.
	function promoWin ()
		{	aWindow=window.open("http://www.merriam-websterunabridged.com/intermed1.htm","promo_window","toolbar=yes,scrollbars=yes,status=yes,resizable=yes,menubar=yes,width=635,height=450");
		}; // function promoWin ()
	
	// ------------------------------------------------------------------------------------------------------------------------

	// This functions opens the Pronunciation Symbol window.
	function pronWin()
		{	aWindow=window.open("/pronsymbols.html","pron_window","toolbar=no,scrollbars=no,status=no,resizable=yes,menubar=no,width=456,height=350");
		}; // function pronWin()

// Code -----------------------------------------------------------------------------------------------------------------------

	// Adjust for the smaller screen resolution.
	if ( isScreen800x600() )
		{	document.write('<link href="/css/adjust_800x600.css" rel="stylesheet" type="text/css" />');
		}; // if ( isScreen800x600() )
