var prevDiv = false ;

function showSuggestionDiv(theID) {
	// Show New
	document.getElementById('misspelledWordSuggestions[' + theID + ']').style.display = 'block' ;
	
	var scrollPos = 0 ;
	if(checkBrowser() != "ie") {
		scrollPos = document.getElementById('misspelledWordContainer[' + theID + ']').scrollTop ;
	}

	var x = findPosXById('misspelledWordContainer[' + theID + ']') ;
	var y = findPosYById('misspelledWordContainer[' + theID + ']') ;
	
	// Set position
	document.getElementById('misspelledWordSuggestions[' + theID + ']').style.left = x + 'px';
	document.getElementById('misspelledWordSuggestions[' + theID + ']').style.top = (y + 16 - scrollPos) + 'px';
	
	prevDiv = theID ;
}

function hideSuggestionDiv(theID) {
	// Hide Div
	document.getElementById('misspelledWordSuggestions[' + theID + ']').style.display = 'none' ;
}

function replaceWord(theID, word) {
	document.getElementById('misspelledWordContainer[' + theID + ']').innerHTML = word + " " ;
}

function openWindow(word) {
	var filename = 'add-word-to-dictionary.php?newWord=' + word ;
	var popwidth = 200 ;
	var popheight = 200 ;
	var configz = config='height=200,width=200,toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=no,directories=no,status=no,left='+(screen.width - popwidth)/2+',top='+((screen.height - popheight)/2-25)+',screenX='+(screen.width - popwidth)/2+',screenY='+((screen.height - popheight)/2-25)+''

	window.open(filename, '', configz) ;
}

function toggleWarning() {
	if(document.getElementById('recursive').checked) {
		document.getElementById('warning').style.display = 'block' ;
	}
	else {
		document.getElementById('warning').style.display = 'none' ;	
	}
}

function switchedAdvanced() {
	theCurrentDisplay = document.getElementById('advanced').checked ;
	
	if(theCurrentDisplay == false) {
		document.getElementById('AdvancedOptions').style.display = 'none' ;
	}
	else {
		document.getElementById('AdvancedOptions').style.display = 'block' ;
	}
	
}

/*****************************************************************************************************************************************/

/*************************************************************
 * findPosX
 *
 * The findPosX function just finds the X offset of the top left
 * corner of the object id it's given.
 *
 * @param object The id of the object that you want to find the 
 *               upper left X coordinate of.
 * @return int The X coordinate of the object
 *************************************************************/
function findPosXById(object)
{
	var curleft = 0;
	var obj = document.getElementById(object);
	if(obj.offsetParent)
	{
		while(obj.offsetParent)
		{
			curleft += obj.offsetLeft - obj.scrollLeft;
			obj = obj.offsetParent;
		}
	}
	else if(obj.x)
	{
		curleft += obj.x;
	}
	return curleft;
}; // end findPosX


/*************************************************************
 * findPosY
 *
 * The findPosY function just finds the Y offset of the top left
 * corner of the object id it's given.
 *
 * @param object The id of the object that you want to find the 
 *               upper left Y coordinate of.
 * @return int The Y coordinate of the object
 *************************************************************/
function findPosYById(object)
{
	var curtop = 0;var curtop = 0;
	var obj = document.getElementById(object);
	if(obj.offsetParent)
	{
		while(obj.offsetParent)
		{
			curtop += obj.offsetTop - obj.scrollTop;
			obj = obj.offsetParent;
		}
	}
	else if(obj.y)
	{
		curtop += obj.y;
	}
	return curtop;
}; // end findPosY

/*************************************************************
 * checkBrowser()
 *
 * The checkBrowser function simply checks to see what browser
 * the user is using and returns a string containing the browser
 * type.
 *
 * @return string The browser type
 *************************************************************/
function checkBrowser()
{
	var theAgent = navigator.userAgent.toLowerCase();
	if(theAgent.indexOf("msie") != -1)
	{
		if(theAgent.indexOf("opera") != -1)
		{
			return "opera";
		}
		else
		{
			return "ie";
		}
	}
	else if(theAgent.indexOf("netscape") != -1)
	{
		return "netscape";
	}
	else if(theAgent.indexOf("firefox") != -1)
	{
		return "firefox";
	}
	else if(theAgent.indexOf("mozilla/5.0") != -1)
	{
		return "mozilla";
	}
	else if(theAgent.indexOf("\/") != -1)
	{
		if(theAgent.substr(0,theAgent.indexOf('\/')) != 'mozilla')
		{
			return navigator.userAgent.substr(0,theAgent.indexOf('\/'));
		}
		else
		{
			return "netscape";
		} 
	}
	else if(theAgent.indexOf(' ') != -1)
	{
		return navigator.userAgent.substr(0,theAgent.indexOf(' '));
	}
	else
	{ 
		return navigator.userAgent;
	}
}; // end checkBrowser
