function FChkSrchTxt(wz)
{
	var ws=/^[\s]*$/;
	return wz&&!ws.test(wz);
}

function FocSrchTxt(o)
{
	if (o && o.value)
	{
		if (strNonSearchString != null && strNonSearchString != 'undefined' && o.value == strNonSearchString && !fEnteredText)
		{
			o.value = '';
		}
		else
		{
			o.select();
		}
		setSearchOnColor(o);
		fEnteredText=true;
	}
}

function FTrySearch(e, strFormName, index)
{
	fSearchFocus = false;
	searchclose();

	var oSrchFrm = document.getElementById(strFormName);

	if ('undefined' != typeof(oSrchFrm) && null != oSrchFrm && SelectAction(oSrchFrm, index))
		{

		try {external.AutoCompleteSaveForm(oSrchFrm);} catch (err) {}
		oSrchFrm.submit();
		}

	if (e && e.stopPropagation)
		e.stopPropagation(); 

	return false;
}

function FEntTextbox(e, strFormName, index)
{
	if (e && 13 == e.keyCode)
		return FTrySearch(e, strFormName, index);

	return true;
}

function FBSCTrySearch(strFrmName, strSrchErr, strResultsUrl, iScope)
{
	var oSrchFrm = G(strFrmName);

	if (!oSrchFrm)
		return false;

	if (!FChkSrchTxt(G('BSCQU').value))
	{
		alert(strSrchErr);
		return false;
	}

	if (!oSrchFrm.av)
	{
		var inputAV = document.createElement("input");
		inputAV.id = "av";
		inputAV.name = "av";
		inputAV.type = "hidden";		
		oSrchFrm.appendChild(inputAV);
	}

	oSrchFrm.qu.value = G('BSCQU').value;
	oSrchFrm.av.value = G('BSCAV').value;
	oSrchFrm.sc.value = iScope;
	oSrchFrm.action = strResultsUrl;
	oSrchFrm.submit();
	return false;
}

function FOnClipartSearchKey(e)
{
	if (e && 13 == e.keyCode)
		SearchClipartFromCM();

	return true;
}

function SearchClipartFromCM()
{
	var nScope = 20; 

	if (document.getElementById("inputClpSrchClipart").checked)
		nScope = 21; 

	if (document.getElementById("inputClpSrchPhotos").checked)
		nScope = 22; 

	if (document.getElementById("inputClpSrchAnimations").checked)
		nScope = 23; 

	if (document.getElementById("inputClpSrchSounds").checked)
		nScope = 24; 

	var strQuery = document.getElementById("inputClpSrchText").value;
	if (null == strQuery || 0 >= strQuery.length || !FChkSrchTxt(strQuery))
	{
		alert(strClpSrchEmptyQuery);
		return;
	}

	var frm = document.getElementById("frmClipartSearch");
	frm.qu.value = strQuery;
	frm.sc.value = nScope.toString();
	frm.submit();
}

function FBSCEndTextbox(e, strFrmName, strSrchErr, strResultsUrl, iScope)
{
	if (e&&e.keyCode == 13) return FBSCTrySearch(strFrmName, strSrchErr, strResultsUrl, iScope);
	return true;
}

function FBSSCTrySearch(strSrchErr)
{
	var oSrchFrm = G('frmBSSC');

	if (!oSrchFrm)
		return false;

	if (!FChkSrchTxt(G('txtBSSC').value))
	{
		alert(strSrchErr);
		return false;
	}

	oSrchFrm.submit();
	return false;
}

function FBSSCEndTextbox(e, strSrchErr)
{
	if (e && 13 == e.keyCode)
		return FBSSCTrySearch(strSrchErr);
	return true;
}

function TbrGet(tb)
{
	tb=G(tb);
	if(tb&&tb.tagName=="TABLE")
		return tb.rows[0];
	return null;
}

function setNonSearchString(searchBox)
{
	if (searchBox != null && searchBox != 'undefined' && searchBox.value == '')
	{
		searchBox.value = strNonSearchString;
		setSearchOffColor(searchBox);
		fEnteredText = false;
	}
}

function setSearchOffColor(searchBox)
{
	searchBox.className = 'cdsearchbox cdSearchBoxOffColor';
}

function setSearchOnColor(searchBox)
{
	searchBox.className = 'cdsearchbox cdSearchBoxOnColor';
}

function delayedclose()
{
	fSearchFocus = false;
	window.setTimeout('searchclose()', 400);
}

function setSearchFocus()
{
	fSearchFocus = true;
}

function searchclose()
{
	var searchdrop = document.getElementById('cdsearchoutcdsdrop');
	if (searchdrop != null && searchdrop != 'undefined')
	{
		if (fSearchFocus == false)
		{
			searchdrop.style.display = 'none';
			fSearchOn = false;
		}
	}
}

function searchout()
{
	var searchdrop = document.getElementById('cdsearchoutcdsdrop');
	if (searchdrop != null && searchdrop != 'undefined' && fSearchOn == true)
	{
		searchdrop.style.display = 'none';
		fSearchOn = false;
	}
	else
	{
		var buttonleft = document.getElementById('cdsdropleft');
		var buttonmiddle = document.getElementById('cdsdrop');

		if (buttonleft != null && buttonleft != 'undefined' &&
			buttonmiddle != null && buttonmiddle != 'undefined' && 
			searchdrop != null && searchdrop != 'undefined')

		{
			var newleft = offset(buttonleft, 'x');
			var newtop = offset(buttonleft, 'y');

			searchdrop.style.display = 'none';
			searchdrop.style.position = 'absolute';

			if (fIsRTL)
			{				
				newleft = offset(buttonmiddle, 'x');
				searchdrop.style.left = newleft + 'px';
			}
			else
			{			
				searchdrop.style.left = newleft + 'px';
			}
			searchdrop.style.top = newtop + buttonmiddle.offsetHeight + 'px';

			searchdrop.style.display = 'block';

			fSearchOn = true;
		}
	}
}

function resizeSearchBox()
{
	var input = document.getElementById('frmSearch_tbQueryStr');
	var container = document.getElementById('tdSearchBox');
	if (input != null && input != 'undefined' && container != null && container != 'undefined')
	{
		var conwidth = container.offsetWidth;
		input.style.width = conwidth - 10 + 'px';

		if (input.value != strNonSearchString)
		{
			fEnteredText = true;
			setSearchOnColor(input);
		}
	}
}

function offset(object, alignment) {
	var nOffset = 0;

	if (object == null)
		return nOffset;

	while (object.offsetParent) {
		nOffset += ((alignment == 'x') ? object.offsetLeft : object.offsetTop);
		object = object.offsetParent;
	}

	return nOffset;
}
