//<![CDATA[
function SubmitWithGet(bFirstSearch, languages)
{	
	var submitLocation;
	if (bFirstSearch)
	{	
		submitLocation = "SearchSummary.aspx?f=1";
	}
	else
	{
		submitLocation = "SearchResultList.aspx?f=1";
	}
	//var submitLocation = "SearchSummary.aspx?f=1";
	var desc = document.productsearch.Desc.value;
	//remove & if exists in string
	var tdesc = '';

	for (i = 0; i < desc.length; i++)
	{
		if (desc.charAt(i) != '&')
			tdesc += desc.charAt(i);
	}
	document.productsearch.Desc.value = tdesc;	
	if (languages == "")
	{	
		for (i = 0; i < document.productsearch.ProdLang.options.length; i++)
		{
			if (document.productsearch.ProdLang.options[i].selected)
			{
				submitLocation = submitLocation + "&ProdLang=" + document.productsearch.ProdLang.options[i].value;
			}
		}
	}
	else
	{	
		submitLocation = submitLocation + "&ProdLang=" + languages;
	}
	// pass all of the imputs of the form; manually pass ProdLang because it is not an input
	for (i = 0; i < document.productsearch.length; i++)
	{
		if ((document.productsearch[i].tagName == "INPUT") && (document.productsearch[i].name!="LastItemName"))
			submitLocation = submitLocation + "&" + document.productsearch[i].name + "=" + document.productsearch[i].value;
		
		if ((document.productsearch[i].tagName == "INPUT") && (document.productsearch[i].name=="LastItemName"))
		{
			var lastItemNameValue = encodeURIComponent(document.productsearch[i].value);			
			submitLocation = submitLocation + "&" + document.productsearch[i].name + "=" + lastItemNameValue;
		}
	}	
	location.href=submitLocation;
}

function getLanguageString()
{
	LanguageString = '';
	firstLanguage = true;
	
	for (i = 1; i < document.productsearch.ProdLang.length; i++)
	{
		if (document.productsearch.ProdLang[i].selected)
		{
			if (!firstLanguage)
				LanguageString += ',';
			LanguageString += document.productsearch.ProdLang[i].value;
			firstLanguage = false;
		}
	}
	return LanguageString;
}

function FollowBreadCrumb(WinnowLevel, Languages)
{	
	document.productsearch.WinnowCount.value = WinnowLevel;
	document.productsearch.ItemType.value = "";
	document.productsearch.ProductType.value = "";
	document.productsearch.ProductFamily.value = "";	
	for (i = 1; i <= WinnowLevel; i++)
	{		
		document.all(document.all("Winnow" + i).value).value = document.all("Winnow" + i + "Code").value
	}
	document.productsearch.FromWinnow.value = 0;
	document.all("LastItemName").value="";
	document.all("LastItemKey").value="0";
	document.all("UseForProductFamilyNext").value="";
	document.all("ListPage").value="1";
	document.all("Count").value="0";			
	SubmitWithGet (false, Languages);
}

function SearchByItemType(ItemCode, ItemName, withSearch)
{
	document.productsearch.WinnowCount.value++;
	document.all("Winnow" + document.all("WinnowCount").value).value = "ItemType";
	document.all("Winnow" + document.all("WinnowCount").value + "Code").value = ItemCode;
	document.all("Winnow" + document.all("WinnowCount").value + "Name").value = ItemName;

	document.all("ItemTypeWinnowUsed").value = ItemName;
	document.all("ItemType").value = ItemCode;
	if (withSearch)
	{
		document.productsearch.FromWinnow.value = 1;
		SubmitWithGet(false, "");
	}
}

function SearchByProductTypeFromSummary(ItemCode, ItemName, ProductCode, ProductName, ListPage, Count, KitSearchOnly, languages)
{	
	if (document.all("ItemTypeWinnowUsed").value == '')
		SearchByItemType(ItemCode,ItemName, false);
		
	document.all("WinnowCount").value = 2;
	
	document.all("Winnow" + document.all("WinnowCount").value).value = "ProductType";
	document.all("Winnow" + document.all("WinnowCount").value + "Code").value = ProductCode;
	document.all("Winnow" + document.all("WinnowCount").value + "Name").value = ProductName;

	document.all("ProductTypeWinnowUsed").value = ProductName;
	
	document.all("ProductType").value = ProductCode;
	document.all("ListPage").value = ListPage;
	document.all("Count").value = Count;
	document.productsearch.FromWinnow.value = 1;
	document.productsearch.SearchKitsOnly.value = KitSearchOnly;
	SubmitWithGet(false, languages);
}

function SearchByProductFamily(ProductFamilyCode, ProductFamilyName, ListPage, Count, languages)
{
	if (document.all("WinnowCount").value != 3)
		document.all("WinnowCount").value++;
	
	document.all("Winnow" + document.all("WinnowCount").value).value = "ProductFamily";
	document.all("Winnow" + document.all("WinnowCount").value + "Code").value = ProductFamilyCode;
	document.all("Winnow" + document.all("WinnowCount").value + "Name").value = ProductFamilyName;

	document.all("ProductFamilyWinnowUsed").value = ProductFamilyName;	
	document.all("ProductFamily").value = ProductFamilyCode;
	document.all("ListPage").value = ListPage;
	document.all("Count").value = Count;
	document.productsearch.FromWinnow.value = 1;
	SubmitWithGet(false, languages);
}


function SearchByMediaKit(desc)
{
	document.productsearch.Desc.value = desc;
	document.productsearch.ProductType.value = "sub','ckt";
	document.productsearch.FromWinnow.value = 0;
	document.productsearch.SearchKitsOnly.value = 1;
	document.all("ListPage").value = 1;
	document.all("Count").value = 0;
	
	SubmitWithGet(true, "");
}

function SearchByKeyWord(desc)
{
	
	var bFirstSearch = true;
	
	document.productsearch.Desc.value = desc;
	document.productsearch.ProductType.value = "";
	document.productsearch.ProductFamily.value = "";
	document.productsearch.ItemType.value = "";
	document.productsearch.SearchKitsOnly.value = 0;
	if (document.productsearch.ItemTypeBox != null)
	{
		bFirstSearch = false;		
		if (document.productsearch.ItemTypeBox.checked)
		{			
			document.productsearch.ItemType.value = document.productsearch.ItemTypeBox.value;
		}
		else 
		{		
			document.productsearch.ItemTypeWinnowUsed.value = "";
			document.productsearch.WinnowCount.value--;
		}
	}  
	if (document.productsearch.ProductTypeBox != null)
	{
		bFirstSearch = false;
		if (document.productsearch.ProductTypeBox.checked)
		{
			document.productsearch.ProductType.value = document.productsearch.ProductTypeBox.value;			
		}
		else 
		{
			document.productsearch.ProductTypeWinnowUsed.value = "";
			document.productsearch.WinnowCount.value--;
		}
	}  
	if (document.productsearch.ProductFamilyBox != null)
	{
		bFirstSearch = false;
		if (document.productsearch.ProductFamilyBox.checked)
		{
			document.productsearch.ProductFamily.value = document.productsearch.ProductFamilyBox.value;
		}
		else 
		{
			document.productsearch.ProductFamilyWinnowUsed.value = "";
			document.productsearch.WinnowCount.value--;
		}
	}  
	
	if (document.productsearch.Winnow1.value == "")
	{
		document.productsearch.Winnow1Name.value = "";
		document.productsearch.Winnow1Code.value = "";
	}			
		
	document.productsearch.Winnow2Name.value = "";
	document.productsearch.Winnow3Name.value = "";
	
	document.productsearch.Winnow2Code.value = "";
	document.productsearch.Winnow3Code.value = "";
	document.productsearch.FromWinnow.value = 0;

	//ItemTypeWinnowUsed	
	document.all("LastItemName").value="";
	document.all("LastItemKey").value="0";
	document.all("UseForProductFamilyNext").value="";
	document.all("ListPage").value="1";
	bFirstSearch = true;
	//
	
	SubmitWithGet(bFirstSearch, "");
}

function SubmitWithGetNextItemList()
{	
	SubmitWithGet(false, "");
}

function KitDetailByMonth(itemKey, startDate)
{
	location.href='KitDetail.aspx?itemKey=' + itemKey + '&productType=SUB&startDate=' + startDate;
}

//]]>
