//<!--
/* >-- > for search small WebPart */
function findWichRadioIsChecked()//idWP,oForm)
{
//alert('[findWichRadioIsChecked]');
//get arguments
	var i = 0, oForm = null, idWP = null;
	for(i=0;i<arguments.length;i++)
	{
		switch(i)
		{
			case 0:
				idWP = arguments[i];
				break;
			case 1:
				oForm = arguments[i];
				break;
		}
	}
//alert('[findWichRadioIsChecked] : 1');
// search for radio button wich is checked (category, global or other)
	var defaultChecked = 2, numberOfCheckedRadio = 0, numberOfCurrentRadio = 0;
	if(!idWP || "" == idWP) {/*alert("idWP=''"); */return defaultChecked;}
	if(!oForm) oForm = document.getElementById("SmallSearchForm" + idWP);
	if(!oForm) return defaultChecked;
//alert('[findWichRadioIsChecked] : 2');
	//var oInputCollection = oForm.getElementsByTagName("input");
	//srchtype
	var oInputCollection = oForm.elements;
//alert('[findWichRadioIsChecked] : oInputCollection : ' + oInputCollection);
	if(!oInputCollection) return defaultChecked;
//alert('[findWichRadioIsChecked] : 3 input coll length: ' + oInputCollection.length);
	
	for(i=0;i<oInputCollection.length;i++)
	{
		obj = oInputCollection[i];
		
		if(obj)
		{
			if(obj.type)
			{
				if('radio' == obj.type.toLowerCase())
				{
					numberOfCurrentRadio = numberOfCurrentRadio  + 1;
					if(obj.checked)
					{
						switch (obj.value.toLowerCase())
						{
							case "spc":
							case "sml":
								numberOfCheckedRadio = 1;
								break;
							case "pic":
								numberOfCheckedRadio = 3;
								break;
							default://global
								numberOfCheckedRadio = 2;
								break;
						}
					break;
					}
				}
			}
		}
	}
//alert('[findWichRadioIsChecked] 5');
	if(0 == numberOfCheckedRadio)
	{
		if(0 < numberOfCurrentRadio && defaultChecked <= numberOfCurrentRadio) numberOfCheckedRadio = defaultChecked;
		else numberOfCheckedRadio = numberOfCurrentRadio;
	}
//alert('[findWichRadioIsChecked] : numberOfCheckedRadio : ' + numberOfCheckedRadio);
	return numberOfCheckedRadio;
}

function postSearchFormByRadio(nRadio,idWP)
{
// function checks on wich radio click made, switch some parameters and posts form
//SmallSearchForm
//searchCategoryId
//defCtgId
//homeCtgId
//alert('[postSearchFormByRadio]');

	if(!idWP || "" == idWP) return false;
	var oForm = document.getElementById("SmallSearchForm" + idWP);
	if(!oForm) return false;
	
	var tmpV = useCorrectCtgIdForSearchByCheckedRadio(nRadio,idWP);
	if(!tmpV) return false;

	if(!checkSmallSearchFormForRadio(oForm,idWP)) return false;

	try{event.returnValue = true;}
	catch(e){}
	
	oForm.submit();
	return true;
}

function postSearchSpecialFormByRadio(nRadio,idWP)
{
// function checks on wich radio click made, switch some parameters and posts form
//SmallSearchForm
//searchCategoryId
//defCtgId
//homeCtgId
//alert('[postSearchFormByRadio]');

	if(!idWP || "" == idWP) return false;
	var oForm = document.getElementById("SmallSearchForm" + idWP);
	if(!oForm) return false;
	
	var tmpV = useCorrectCtgIdForSearchByCheckedRadio(nRadio,idWP);
	if(!tmpV) return false;
//alert('aaa');
	if(!checkSpecialSearchForm("SmallSearchForm",idWP)) return false;

	try{event.returnValue = true;}
	catch(e){}
	
	oForm.submit();
	return true;
}

function useCorrectCtgIdForSearchByCheckedRadio()//nRadio,idWP,oForm)
{
//alert('[useCorrectCtgIdForSearchByCheckedRadio]');
//get arguments
	var i = 0, nRadio = null, idWP = null, oForm = null;
	for(i=0;i<arguments.length;i++)
	{
		switch(i)
		{
			case 0:
				nRadio = arguments[i];
				break;
			case 1:
				idWP = arguments[i];
				break;
			case 2:
				oForm = arguments[i];
				break;
		}
	}

	if(!idWP || "" == idWP) return false;
	if(!oForm) oForm = document.getElementById("SmallSearchForm" + idWP);
//alert('[useCorrectCtgIdForSearchByCheckedRadio] : oForm: ' + oForm);
	if(!oForm) return false;
//alert('[useCorrectCtgIdForSearchByCheckedRadio] : a1');
	nRadio = parseInt(nRadio);
	if(isNaN(nRadio)) nRadio = 1;
//alert('[useCorrectCtgIdForSearchByCheckedRadio] : nRadio: ['+nRadio+']');
	if(1 == nRadio || 2 == nRadio)
	{
		var idDefCtg = document.getElementById("defCtgId" + idWP);
		if(!idDefCtg) return false;
		idDefCtg = idDefCtg.value;
		if(!idDefCtg) return false;
		var idHomeCtg = document.getElementById("homeCtgId" + idWP);
		if(!idHomeCtg) return false;
		idHomeCtg = idHomeCtg.value;
		if(!idHomeCtg) return false;
		var oSearchCategoryId = document.getElementById("searchcategoryid" + idWP);
		if(!oSearchCategoryId) return false;
//alert('[useCorrectCtgIdForSearchByCheckedRadio] : oSearchCategoryId : ' + oSearchCategoryId);
		if(!oSearchCategoryId.value) return false;
	}			
//alert('[useCorrectCtgIdForSearchByCheckedRadio] : a5');
	switch(nRadio)
	{
		case 1:
			oSearchCategoryId.value = idDefCtg;
			break;
		case 2:
			oSearchCategoryId.value = idHomeCtg;
			break;
	}
//if(nRadio < 3) alert('[useCorrectCtgIdForSearchByCheckedRadio] : oSearchCategoryId: [' + oSearchCategoryId.value + ']');
	return true;
}

function checkSmallSearchFormForRadio(oForm,idWP)
{
//alert('[checkSmallSearchFormForRadio]');
	try
	{
		var oInput = document.getElementById(CONST_PARAM_searchStr_NAME + idWP);
	}
	catch(e)
	{
		return false;
	}

	if(!oForm || !oInput)
	{
		return false;
	}

	var searchStr = oInput.value;
	if(3 > searchStr.length)
	{
//alert(getConstStr("CONST_JS_Fulfil_search_field","Please fulfil search field.."));
		return false;
	}

	return true;
}

function checkAndUseRadioElements(oForm,idWP)
{
//alert('[checkAndUseRadioElements]');
	if(!oForm) return false;
	if(!idWP) idWP = "";
	var i, cRadios, obj;
	var tmpId, selectedRadioNumber = 0;
	for(i=1;i<100;i++)
	{
		tmpId = "rd" + i + idWP;
		obj = document.getElementById(tmpId);
		if(!obj) break;
		if("input" == obj.nodeName.toLowerCase())
			if("radio" == obj.type.toLowerCase())
				if(obj.checked) selectedRadioNumber = i;
	}
	if(0 < selectedRadioNumber)
	{
		var tmpV = useCorrectCtgIdForSearchByCheckedRadio(selectedRadioNumber,idWP);
	}
	return tmpV;
}

function runCategorySearch(idWP)
{
	return true;
}

function runGlobalSearch(idWP)
{
	return true;
}

function runPictureSearch(idWP)
{
	return true;
}
/* <--< for search small WebPart*/
//-->