﻿// JScript File

function GetSearchQStr()
{
	var elem = document.getElementById("L_content");
	var chks = elem.getElementsByTagName ("input");
	
	
	var catsRA = new Array();
	/*
	for (cx = 0; cx < chks.length; cx++)
	{
		if (chks[cx].type == "checkbox")
		{	
			alert(chks[cx].attributes['catid'].value);
			if (chks[cx].attributes['catid'])
			{
					
				if (chks[cx].checked)
					catsRA.push(chks[cx].attributes['catid'].value);					
			}
		}
	}*/
	for (cx = 0; cx < chks.length; cx++)
		{
		
			if (chks[cx].type == "checkbox")
			{	

				var cat;			
				if (chks[cx].attributes['CatID'])
					cat=chks[cx].attributes['CatID'].value;
				else
				{
					var rx = /catid=['"]\d+['"]/i;
					//alert(rx);
					cat = rx.exec(chks[cx].outerHTML);
					var rxd = /\d+/;
					cat = rxd.exec(cat);
			
				}
					
				if(cat)
				{
					//alert(cat);
					if (chks[cx].checked)
					{
						
						catsRA.push(cat);
					}
				}
			}
		}
	
	var cats = catsRA.join(',');		
	if (cats != "")
		cats = "categories="+cats;
	
	var txtSearch = document.getElementById("txtSearchPhrase");
	if (txtSearch.value != '')
	{
		if (cats!='') cats+="&";
		cats+= "search="+encodeURIComponent(txtSearch.value);
	}
	
	
	return cats;
}

function Search()
{
	var searchStr = GetSearchQStr();
	if (searchStr != "" ) searchStr += "&";
	searchStr += "PageNum=0";
	if (window.location.href.toLowerCase().indexOf ("cape") > -1)
	{
	window.location = "\capeSearchResults.aspx?"+searchStr;
	}
	else
	{
	window.location = "\lpchSearchResults.aspx?"+searchStr;
	}
	
}
