protected ReferenceSearchCriteria GetSelectedCriteria(CriteriaController criteriaController)
		{
			/* Get selected user group criteria value */
			ReferenceSearchCriteria referenceSearchCriteria = new ReferenceSearchCriteria();
			string documentSearchCriteria = string.Empty;
			List<Thinkgate.Controls.E3Criteria.DropDownList.ValueObject> selectedCriteria = null;

			selectedCriteria = criteriaController.ParseCriteria<Thinkgate.Controls.E3Criteria.DropDownList.ValueObject>("UserGroup").ToList();
			if (selectedCriteria.Count > 0)
			{
                /* TFS 9069 In case of 'All' UserGroup option selected, the default search is be run. Skip condition in this case. */
                if (selectedCriteria[0].Value != Convert.ToInt32(LookupDetail.All).ToString() && selectedCriteria[0].Text != LookupDetail.All.ToString())
                {
                    documentSearchCriteria += " UserGroup = '" + selectedCriteria[0].Value + "' ";
                }
			}
			selectedCriteria = criteriaController.ParseCriteria<Thinkgate.Controls.E3Criteria.DropDownList.ValueObject>("Category").ToList();
			if (selectedCriteria.Count > 0)
			{
				documentSearchCriteria += string.IsNullOrWhiteSpace(documentSearchCriteria) ? string.Empty : " AND ";
				documentSearchCriteria += " CategoryList = '" + selectedCriteria[0].Value + "' ";
			}
			selectedCriteria = criteriaController.ParseCriteria<Thinkgate.Controls.E3Criteria.DropDownList.ValueObject>("Component").ToList();
			if (selectedCriteria.Count > 0)
			{
				documentSearchCriteria += string.IsNullOrWhiteSpace(documentSearchCriteria) ? string.Empty : " AND ";
				documentSearchCriteria += " Component = '" + selectedCriteria[0].Value + "' ";
			}
			selectedCriteria = criteriaController.ParseCriteria<Thinkgate.Controls.E3Criteria.DropDownList.ValueObject>("Type").ToList();
			if (selectedCriteria.Count > 0)
			{
				documentSearchCriteria += string.IsNullOrWhiteSpace(documentSearchCriteria) ? string.Empty : " AND ";
				documentSearchCriteria += " FileTypes = '" + selectedCriteria[0].Value + "' ";
			}
          
			string searchText = string.Empty;
			string searchOption = string.Empty;
			List<TextWithDropdown.ValueObject> textSearchList = criteriaController.ParseCriteria<TextWithDropdown.ValueObject>("TextSearch");
			if (textSearchList.Count > 0)
			{
				NameValue confirmedOption = TextSearchDropdownValues().Find(x => x.Name == textSearchList[0].Option) ?? TextSearchDropdownValues().First();
				if (!String.IsNullOrEmpty(textSearchList[0].Text))
				{
					searchText = textSearchList[0].Text;
					searchOption = confirmedOption.Value;
					string[] searchWords = System.Text.RegularExpressions.Regex.Split(searchText, " ");
					string[] searchColumns = new string[] { "Title", "Description", "Keyword" };

					documentSearchCriteria += string.IsNullOrWhiteSpace(documentSearchCriteria) ? string.Empty : " AND ";

					if (searchOption == "key")
					{
						documentSearchCriteria += " (Keyword LIKE '%" + searchText + "%') ";
					}
					else if (searchOption == "any")
					{
						string anyWordsCondition = TextSearchCondition(searchWords, searchColumns, true);
						documentSearchCriteria += anyWordsCondition;
					}
					else if (searchOption == "all")
					{
						string allWordsCondition = TextSearchCondition(searchWords, searchColumns, false);
						documentSearchCriteria += allWordsCondition;
					}
					else if (searchOption == "exact")
					{
						documentSearchCriteria += " ( Title LIKE '%" + searchText + "%' ";
						documentSearchCriteria += " OR Keyword LIKE '%" + searchText + "%' ";
						documentSearchCriteria += " OR Description LIKE '%" + searchText + "%') ";
					}
				}
			}
            
			var dateSelected = criteriaController.ParseCriteria<Thinkgate.Controls.E3Criteria.DateRange.ValueObject>("DateAdded").ToList();
			if (dateSelected.Count > 0)
			{
                documentSearchCriteria += string.IsNullOrWhiteSpace(documentSearchCriteria) ? string.Empty : " AND ";
               
                Master.ChangeCriteriaOrder(ref dateSelected);
                if (dateSelected[0].Type == "Start")
                {
                    documentSearchCriteria += " (convert(varchar,DateAdded,111) >= convert(datetime,'" + dateSelected[0].Date + "',111) ";
                    if (dateSelected.Count > 1 && !string.IsNullOrEmpty(dateSelected[1].Date))
                        documentSearchCriteria += " And convert(varchar,DateAdded,111) <= convert(datetime,'" + dateSelected[1].Date + "',111)) ";
                    else
                        documentSearchCriteria += ")";
                }
                else if (!string.IsNullOrEmpty(dateSelected[0].Date))
                { documentSearchCriteria += " (convert(varchar,DateAdded,111) <= convert(datetime,'" + dateSelected[0].Date + "',111))"; }

			}
			referenceSearchCriteria.SearchCriteria = documentSearchCriteria;
			return referenceSearchCriteria;
		}
		protected List<Reference> SearchReferences(ReferenceSearchCriteria referenceSearchCriteria, string orderBy = "Title ASC")
		{
			
			/* Kentico related parameters like site name, username etc would go configurable */
			List<Reference> references = new List<Reference>();

			SessionObject obj = (SessionObject)Session["SessionObject"];
            UserInfo userinfo = (UserInfo)Session["KenticoUserInfo"];
			TreeNodeDataSet referencesDataSet = CMS.DocumentEngine.DocumentHelper.GetDocuments(ConfigurationManager.AppSettings["CMSSiteName"], ConfigurationManager.AppSettings["CMSTreePathToReferences"], "en-us", true, "Thinkgate.ReferenceCenter", referenceSearchCriteria.SearchCriteria, orderBy.ToString().ToUpper().Contains("FORMAT") ? "Title ASC" : orderBy, 5, false, treeProvider);
            
			if (referencesDataSet != null && referencesDataSet.Tables.Count > 0 && referencesDataSet.Tables[0].Rows.Count > 0)
			{
                List<TreeNode> treeNodes = referencesDataSet.ToList();
				table = referencesDataSet.Tables[0];
				foreach (DataRow row in referencesDataSet.Tables[0].Rows)
				{
                    TreeNode documentNode = treeNodes.Find(tn => tn.DocumentID == Convert.ToInt32(row["DocumentID"].ToString()));
					if (!string.IsNullOrEmpty(row["DocumentID"].ToString()))
					{
                      //  bool includeForAllClients = false;
                        bool isGlobal = false;
                      //  includeForAllClients =row["ClientTargets"].ToString().ToUpperInvariant() == "ALL";
                        isGlobal = Convert.ToBoolean(row["IsGlobal"].ToString());

                        if (IsReferenceSearchable(row, obj, userinfo, isGlobal))
                        { references.Add(AddReference(row, documentNode)); }
                        }
										}
                return references;
									}
            else
										{
                return (new List<Reference>());
										}
									}
		protected void PopulateGridWithCMSData(ReferenceSearchCriteria where, string orderBy)
		{
            lookupData = KenticoHelper.GetLookupDetailsByClient(null, null);
			List<Reference> references = SearchReferences(where, orderBy);
           
			//Format Search Functionality
			CriteriaController criteriaController = this.Master.CurrentCriteria();

			List<Thinkgate.Controls.E3Criteria.DropDownList.ValueObject> selectedCriteria = null;
			selectedCriteria = criteriaController.ParseCriteria<Thinkgate.Controls.E3Criteria.DropDownList.ValueObject>("Format").ToList();
			if (selectedCriteria.Count > 0)
			{

				references = references.Where(r => r.Format == selectedCriteria[0].Text).ToList();

			}

			radGridResults.DataSource = references;
			radGridResults.DataBind();

			gridResultsPanel.Visible = true;
			initMessage.Visible = false;
		}