var objForm	= document.MyFORM;

function FunListRules(strFrom)
{
	var bSearchKMS = true;
	var strLoc,QSCatID;
	var bCheckTrue = true;
	var objSubmitForm	= document.frmSubmit;
	var StrKeywordValue	= trim(objForm.txtKeyword.value);
	var now		= new Date();
	var expdate = new Date(now.getTime() + 1000 * 60 * 60 * 24);
	
	var sInt = 0;
	var sCat = 0;
	var sTop = 0;
	var DispIntText	= "";
	var DispCatText	= "";
	var DispTopText	= "";

	if (objForm.cboInt){
		sInt		= objForm.cboInt.options[objForm.cboInt.selectedIndex].value;
		DispIntText	= objForm.cboInt.options[objForm.cboInt.selectedIndex].text;
	}
	if (objForm.cboCat){
		sCat		= objForm.cboCat.options[objForm.cboCat.selectedIndex].value;
		DispCatText	= objForm.cboCat.options[objForm.cboCat.selectedIndex].text;
	}
	if (objForm.cboTop){
		sTop		= objForm.cboTop.options[objForm.cboTop.selectedIndex].value;
		DispTopText	= objForm.cboTop.options[objForm.cboTop.selectedIndex].text;
	}

	var intRoleID		= "";
	var intUserID		= "";
	var intStatusID		= "";
	var DispRoleText	= "";
	var DispUserText	= ""
	var DispStatusText	= "";

	if (objForm.cboRole){
		intRoleID		= objForm.cboRole.options[objForm.cboRole.selectedIndex].value;
		DispRoleText	= objForm.cboRole.options[objForm.cboRole.selectedIndex].text;
	}
	if (objForm.cboUser){
		intUserID		= objForm.cboUser.options[objForm.cboUser.selectedIndex].value;
		DispUserText	= objForm.cboUser.options[objForm.cboUser.selectedIndex].text;
	}
	if (objForm.cboStatus){
		intStatusID		= objForm.cboStatus.options[objForm.cboStatus.selectedIndex].value;
		DispStatusText	= objForm.cboStatus.options[objForm.cboStatus.selectedIndex].text;
	}

	if (objForm.rdoPublish)
	{
		if ((!objForm.rdoPublish.checked) && ((intStatusID == "ALLWOR") || (intStatusID < 2000)))
		{
			FunSelSta();
			bSearchKMS	= false;
		}
	}

	if (bSearchKMS)
	{
		if (sTop != 0)
			QSCatID = sTop;
		else 
			if (sCat != 0)
				QSCatID = sCat;
			else
				QSCatID = sInt;


		var strMatchValue = 	"P";
		if ((objForm.rdoMatch) && (objForm.rdoMatch.checked))
			strMatchValue = 	"E";

		var strSelectedValue = 	"P";
		if ((objForm.rdoDes) && (objForm.rdoDes.checked))
			strSelectedValue = 	"F";

		var StrPublishType	= "P";
		if (objForm.rdoPublish)
		{
			if (objForm.rdoPublish.checked)
				StrPublishType	= "N"
		}

		// For Independent List Box
		var StrIndepList	= "";
		var StrIndepListText	= "";
		if (objForm.cboInDep1)
		{
			//for (i = 0; i < aIndepNode.length; i++)
			for (i = 0; i < 3; i++)
			{
				var objIndepNode	= eval("objForm.cboInDep" + (i+1));
				if (objIndepNode)
				{
					if (i > 0)
					{
						StrIndepList	= StrIndepList + "|" + objIndepNode.options[objIndepNode.selectedIndex].value;
						StrIndepListText= StrIndepListText + "|" + objIndepNode.options[objIndepNode.selectedIndex].text;
					}
					else
					{
						StrIndepList	= objIndepNode.options[objIndepNode.selectedIndex].value;
						StrIndepListText= objIndepNode.options[objIndepNode.selectedIndex].text;
					}
				}
			}
			if (StrIndepList != "")
			{
				objSubmitForm.IndepList.value		= StrIndepList;
				objSubmitForm.IndepListText.value	= StrIndepListText;
			}
		}

		var strSearchBy	= "D";
		if (objForm.cboSearchBy)
			strSearchBy	= objForm.cboSearchBy.options[objForm.cboSearchBy.selectedIndex].value;

		if (objForm.rdoPublish){
			if(objForm.rdoPublish.checked)
			{
				SetCookie("IDRU",intRoleID+"~"+intUserID+"~Y",expdate);
			}
			else{
				SetCookie("IDRU","~~N",expdate);
			}
		}
		
		// Get the status of the search display option checkboxes
		var StrSearchDisplayOpt	= "";
		if (document.MyFORM.chkField1 && document.MyFORM.chkField1.checked)
			StrSearchDisplayOpt	= "Y";
		else
			StrSearchDisplayOpt	= "N";

		if (document.MyFORM.chkField2 && document.MyFORM.chkField2.checked)
			StrSearchDisplayOpt	= StrSearchDisplayOpt + "|Y";
		else
			StrSearchDisplayOpt	= StrSearchDisplayOpt + "|N";

		if (document.MyFORM.chkField3 && document.MyFORM.chkField3.checked)
			StrSearchDisplayOpt	= StrSearchDisplayOpt + "|Y";
		else
			StrSearchDisplayOpt	= StrSearchDisplayOpt + "|N";

		if (document.MyFORM.chkField4 && document.MyFORM.chkField4.checked)
			StrSearchDisplayOpt	= StrSearchDisplayOpt + "|Y";
		else
			StrSearchDisplayOpt	= StrSearchDisplayOpt + "|N";

		if ((StrSearchDisplayOpt == "N|N|N|N") && ((document.MyFORM.chkField1) || (document.MyFORM.chkField2) || (document.MyFORM.chkField3) || (document.MyFORM.chkField4)))
		{
			if (document.MyFORM.chkField1)
				StrSearchDisplayOpt = "Y|N|N|N";
			else
				StrSearchDisplayOpt = "N|Y|N|N";
		}

		{
			if ((!document.MyFORM.chkField1) && (!document.MyFORM.chkField2) && (!document.MyFORM.chkField3) && (!document.MyFORM.chkField4))
				objSubmitForm.DisplayOpt.value		= "N|Y|N|N";
			else
				objSubmitForm.DisplayOpt.value		= StrSearchDisplayOpt;
			
			SetCookie("ICT",sInt+"~"+sCat+"~"+sTop+"~"+strSearchBy+"~"+strMatchValue+"~"+strSelectedValue+"~"+intStatusID+"~"+StrIndepList+"~"+StrSearchDisplayOpt,expdate);
			SetCookie("Keyword",objForm.txtKeyword.value,expdate);

			// Get the cookie value of rec/page
			var CookieValueRecPerpage	= SetValue("RecPerPage");
			var strRecPerpage;
			if (CookieValueRecPerpage == null){
				strRecPerpage	= CookieValueRecPerpage;
			}
			else if (CookieValueRecPerpage == ""){
				strRecPerpage	= CookieValueRecPerpage;
			}
			else{
				strRecPerpage	= CookieValueRecPerpage;
			}

			// User by all conditons
			objSubmitForm.QSCatID.value		= QSCatID;
			objSubmitForm.QSKeyword.value	= objForm.txtKeyword.value;
			objSubmitForm.QSStatus.value	= intStatusID;
			objSubmitForm.QSMatchType.value	= strMatchValue;
			objSubmitForm.QSDescType.value	= strSelectedValue;

			objSubmitForm.QSInt1.value		= sInt;
			objSubmitForm.QSCat1.value		= sCat;
			objSubmitForm.QSTop1.value		= sTop;

			objSubmitForm.DispInt.value		= DispIntText;
			objSubmitForm.DispCat.value		= DispCatText;
			objSubmitForm.DispTop.value		= DispTopText;
			objSubmitForm.DispStatus.value		= DispStatusText;

			objSubmitForm.PublishType.value		= StrPublishType;
			if (objSubmitForm.QSRole){
				objSubmitForm.QSRole.value			= intRoleID;
				objSubmitForm.QSUser.value			= intUserID;
				objSubmitForm.DispRole.value		= DispRoleText;
				objSubmitForm.DispUser.value		= DispUserText;
				objSubmitForm.qsRecPerpage.value	= strRecPerpage;
			}

			if (strSearchBy == "A")
			{
				objSubmitForm.action	= objForm.action + "MainDocSearch.asp?FieldType=A";
				objSubmitForm.submit();
			}
			else if (strSearchBy == "D")
			{
				objSubmitForm.action	= objForm.action + "ListRules.asp?FieldType=D";
				objSubmitForm.submit();
			}
			else if (strSearchBy == "T")
			{
				objSubmitForm.action	= objForm.action + "ListRules.asp?FieldType=T";
				objSubmitForm.submit();
			}
			else if (strSearchBy == "P")
			{
				objSubmitForm.action	= objForm.action + "ListRules.asp?FieldType=P";
				objSubmitForm.submit();
			}
			else if (strSearchBy == "Q")
			{
				objSubmitForm.action	= objForm.action + "SearchInteractive.asp";
				objSubmitForm.submit();		
			}
			else if (strSearchBy == "H")
			{
				objSubmitForm.action	= objForm.action + "MainDocSearch.asp?FieldType=H";
				objSubmitForm.submit();
			}
			else if (strSearchBy == "I")
			{
				if (StrKeywordValue == "")
					alert(plsenterakid);
				else if (isNaN(StrKeywordValue))
					alert(invalidkid);		 
				else
				{
					objSubmitForm.action	= objForm.action + "ValidateKBID.asp";
					objSubmitForm.submit();
				}
			}
		}
	}
}
