var selectedBucketType = '';

//localized vars
//localized vars values should be set from corresponding LocalizedVars.js file
//for example, english values are assigned from /js/en/LocalizedVars.js file

var sEntKW, sPlsEntSrchTrm;
var sLess;
var sMore;

//End localized Vars

window.onload = function()
{
	searchFieldSetFocus();
	searchFieldSetDefaultText();
}

function searchFieldSetFocus()
{
	var searchField = document.getElementById('SearchText');
	if (searchField != null)
	{
		searchField.focus();
	}
}

function searchFieldSetDefaultText()
{
	var searchField = document.getElementById('SearchText');
	if (searchField != null && searchField.value == '')
	{
		searchField.value = sEntKW; //'Enter Keywords';
		searchField.select();
	}
}

function ClearSearchField(formitem)
{
	if (formitem.value== sEntKW) //'Enter Keywords'
	{
		formitem.value = '';
	}
}

function toggleLayer(sourceElement, elementId)
{
	var element;

	if (document.getElementById)
	{
		// this is the way the standards work
		element = document.getElementById(elementId);
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		element = document.all[elementId];
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		element = document.layers[elementId];
	}

	element.style.display = element.style.display ? '' : 'inline';
	
	sourceElement.innerHTML = element.style.display ? '<img src="/images/zibbArrowLeft.gif" hspace="2" alt="" style="border:0;"/><strong style="text-decoration:none;">' + sLess + '</strong>' : '<strong style="text-decoration:none;">' + sMore + '</strong><img src="/images/zibbArrow.gif" hspace="2" alt="" style="border:0;"/>';
}

function ss(w, id)
{
	window.status = w;
	return true;
}

function cs()
{
	window.status = "";
}

function checkSearch()
{
	var searchField = document.getElementById('SearchText');

	switch (searchField.value)
	{
		case "":
		case sEntKW: //"Enter Keywords":
			window.alert(sPlsEntSrchTrm); //"Please enter a search term."
			searchField.focus();
			return false;
	}

	var form = document.getElementById('SearchForm');
	var industryCurrent = document.getElementById('IndustryCurrent');
	var industryAll = document.getElementById('IndustryAll');

	if (industryCurrent != null && industryAll != null)
	{
		var industry;
		var actionUrl = form.action;

		if (industryCurrent.checked)
		{
			industry = industryCurrent.value;
		}
		else
		{
			industry = industryAll.value;
		}

		actionUrl = actionUrl.replace(/^http\:\/\/[^\/]+/i, '');
		actionUrl = actionUrl.replace(/^\/[^\/]+/i, '/' + industry.toLowerCase());
		form.action = actionUrl;
	}

	return true;    
}
						 
function jump(url)
{
	if (document.images && url)
	{
		if (arguments.length > 1)
		{
			type = arguments[1];
		}
		else
		{
			type = 'result';
		}
	
		new Image().src = '/images/_jump.gif?url=' + escape(url).replace(/\+/g, '%2B') + '&type=' + type;
	}
	
	return true;
}

function industrySelectionOnClick()
{
	searchFieldSetFocus();
	
	return true;
}

function bucketTypeTabOnClick(li, bucketType)
{   
	var ul = li.parentNode;

	// reset previous tab selection	
	for (var liIndex = 0; liIndex < ul.childNodes.length; liIndex++)
	{
		childLi = ul.childNodes[liIndex];
		
		if (childLi.id == 'current')
		{
			childLi.id = '';
			break;
		}
	}
	
	// select current tab selection
	li.id = 'current';

	// update form action attribute
	var form = document.getElementById('SearchForm');
	var radioFields = document.getElementById('radiofields');
	var actionUrl = form.action;

	selectedBucketType = bucketType.toLowerCase();

	if (radioFields != null)
	{
		radioFields.style.display = 'block';
	}
	
	actionUrl = actionUrl.replace(/^http\:\/\/[^\/]+/i, '');
	actionUrl = actionUrl.replace(/^(\/[^\/]+\/[^\/]+\/)[^\?]+(.*)/i, '$1' + bucketType.toLowerCase() + '$2');
	form.action = actionUrl;

	searchFieldSetFocus();

	return true;
}
