<%@ Control Language="C#" %>
<%@ Register TagPrefix="CS" Namespace="CommunityServer.Controls" Assembly="CommunityServer.Controls" %>
<%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %>
<%@ Register TagPrefix="CP" Namespace="CommunityServer.ControlPanel.Controls" Assembly="CommunityServer.Web" %>

<script language="javascript">

var startDateValue = new Date();
var endDateValue = new Date;
var prevDateComparerIndex = 0;

function DateComparerChange() 
{
	var dateComparerIndex = document.getElementById('<%=DateComparer.ClientID%>').selectedIndex;

	if (dateComparerIndex == 0 || prevDateComparerIndex == -1)
	{
		if (prevDateComparerIndex != -1)
			startDateValue = <%=this.StartDate.ClientID %>.GetSelectedDate();
			
		<%=this.StartDate.ClientID %>.ClearSelectedDate();
		document.getElementById('StartDateContainer').style.display = 'none';
	}
	else if (prevDateComparerIndex == 0)
	{
		<%=this.StartDate.ClientID%>.SetSelectedDate(startDateValue);
		document.getElementById('StartDateContainer').style.display = 'inline';
	}
	
	if (prevDateComparerIndex == 2 || prevDateComparerIndex == -1)
	{
		if (prevDateComparerIndex != -1)
			endDateValue = <%=this.EndDate.ClientID %>.GetSelectedDate();
			
		<%=this.EndDate.ClientID %>.ClearSelectedDate();
		document.getElementById('EndDateContainer').style.display = 'none';
	}
	else if (dateComparerIndex == 2)
	{
		<%=this.EndDate.ClientID %>.SetSelectedDate(endDateValue);
		document.getElementById('EndDateContainer').style.display = 'inline';
	}

	prevDateComparerIndex = dateComparerIndex;
}

function StartDateChange(picker)
{
	startDateValue = picker.GetSelectedDate();
	<%=this.StartDateCalendar.ClientID %>.SetSelectedDate(startDateValue);
	CheckEndDate(startDateValue);	
}
function StartDateCalendarChange(calendar)
{
	startDateValue = calendar.GetSelectedDate();
	<%=this.StartDate.ClientID %>.SetSelectedDate(startDateValue);
	CheckEndDate(startDateValue);
}

function EndDateChange(picker)
{
	endDateValue = picker.GetSelectedDate();
	<%=this.EndDateCalendar.ClientID %>.SetSelectedDate(endDateValue);
	CheckStartDate(endDateValue);
}
function EndDateCalendarChange(calendar)
{
	endDateValue = calendar.GetSelectedDate();
	<%=this.EndDate.ClientID %>.SetSelectedDate(endDateValue);
	CheckStartDate(endDateValue);
}

function CheckEndDate(date)
{
	if (date > endDateValue)
	{
		endDateValue = date;
		if (document.getElementById('EndDateContainer').style.display == 'inline')
		{
			<%=this.EndDate.ClientID %>.SetSelectedDate(endDateValue);
			<%=this.EndDateCalendar.ClientID %>.SetSelectedDate(endDateValue);
		}
	}
}

function CheckStartDate(date)
{
	if (date < startDateValue)
	{
		startDateValue = date;
		if (document.getElementById('StartDateContainer').style.display == 'inline')
		{
			<%=this.StartDate.ClientID %>.SetSelectedDate(startDateValue);
			<%=this.StartDateCalendar.ClientID %>.SetSelectedDate(startDateValue);
		}
	}
}

</script>

<div class="CommonContentArea">
	<h2 class="CommonTitle"><CS:ResourceControl ResourceName="SearchAdvanced_Title" runat="server" /></h2>
	<div class="CommonContent">
		<div class="CommonDescription"><CS:ResourceControl ResourceName="SearchAdvanced_Description" runat="server" /></div>

		<asp:CustomValidator Runat="server" id="Validator" Display="Dynamic" />

		<div class="CommonFormArea">
		<table cellpadding="0" cellspacing="0" border="0">

		<tr>
			<td class="CommonFormFieldName">
				<cp:helpicon id="Helpicon4" runat="Server" resourcename="SearchAdvanced_Keywords_Info" ResourceFile="Resources.xml"/>
				<CS:ResourceLabel runat="server" ResourceName="SearchAdvanced_Keywords" />
			</td>
			<td class="CommonFormField">
				<asp:textbox id="Keywords" runat="server" columns="60" />
			</td>
		</tr>
		
		<tr>
			<td class="CommonFormFieldName">
				<cp:helpicon runat="server" resourcename="SearchAdvanced_Tags_Info" ResourceFile="Resources.xml" />
				<CS:ResourceLabel runat="server" ResourceName="SearchAdvanced_Tags" />
			</td>
			<td class="CommonFormField">
				<asp:TextBox Runat="server" ID="Tags" Columns="60" />
			</td>
		</tr>

		<tr>
			<td class="CommonFormFieldName">
				<cp:helpicon id="Helpicon1" runat="Server" resourcename="SearchAdvanced_Users_Info" ResourceFile="Resources.xml"/>
				<CS:ResourceLabel runat="server" ResourceName="SearchAdvanced_Users" />
			</td>
			<td class="CommonFormField">
				<asp:textbox id="Users" runat="server" columns="60" />
			</td>
		</tr>
		
		<tr>
			<td class="CommonFormFieldName">
				<cp:helpicon id="Helpicon2" runat="Server" resourcename="SearchAdvanced_Date_Info" ResourceFile="Resources.xml"/>
				<CS:ResourceLabel runat="server" ResourceName="SearchAdvanced_Date" ID="Resourcelabel1"/>
			</td>
			<td class="CommonFormField">
				<asp:dropdownlist id="DateComparer" runat="server" />
				<span id="StartDateContainer" style="display: none;">
				<componentart:calendar id="StartDate" runat="server" pickerformat="Custom" pickercustomformat="MMMM d yyyy" controltype="Picker" pickercssclass="picker" ClientSideOnSelectionChanged="StartDateChange"></componentart:calendar>
				<img id="StartDateCalendarButton" alt="" onclick="<%=this.StartDateCalendar.ClientID %>.SetSelectedDate(<%=this.StartDate.ClientID %>.GetSelectedDate());<%=this.StartDateCalendar.ClientID %>.Show();" class="calendar_button" src="../themes/default/images/common/calendar.gif" width="25" height="22" align="absmiddle" />
				<componentart:calendar runat="server"
					id="StartDateCalendar" 
					allowmonthselection="false"
					allowmultipleselection="false"
					allowweekselection="false"
					calendarcssclass="calendar" 
					calendartitlecssclass="title" 
					clientsideonselectionchanged="StartDateCalendarChange" 
					controltype="Calendar"
					daycssclass="day" 
					dayheadercssclass="dayheader" 
					dayhovercssclass="dayhover" 
					daynameformat="FirstTwoLetters"
					monthcssclass="month"
					nextimageurl="../themes/default/images/common/cal_nextMonth.gif"
					nextprevcssclass="nextprev" 
					othermonthdaycssclass="othermonthday" 
					popup="Custom"
					popupexpandcontrolid="StartDateCalendarButton"
					previmageurl="../themes/default/images/common/cal_prevMonth.gif" 
					selecteddate="2005-9-14"
					selecteddaycssclass="selectedday" 
					selectmonthcssclass="selector"
					selectmonthtext="&curren;" 
					selectweekcssclass="selector"
					selectweektext="&raquo;" 
					swapduration="300"
					swapslide="Linear"
					/>
				</span>

				<span id="EndDateContainer" style="display: none;">
				<CS:ResourceControl ResourceName="SearchAdvanced_Date_Range_And" runat="server" />
				<componentart:calendar id="EndDate" runat="server" pickerformat="Custom" pickercustomformat="MMMM d yyyy" controltype="Picker" pickercssclass="picker" ClientSideOnSelectionChanged="EndDateChange"></componentart:calendar>
				<img id="EndDateCalendarButton" alt="" onclick="<%=this.EndDateCalendar.ClientID %>.SetSelectedDate(<%=this.EndDate.ClientID %>.GetSelectedDate());<%=this.EndDateCalendar.ClientID %>.Show();" class="calendar_button" src="../themes/default/images/common/calendar.gif" width="25" height="22" align="absmiddle" />
				<componentart:calendar runat="server"
					id="EndDateCalendar" 
					allowmonthselection="false"
					allowmultipleselection="false"
					allowweekselection="false"
					calendarcssclass="calendar" 
					calendartitlecssclass="title" 
					clientsideonselectionchanged="EndDateCalendarChange" 
					controltype="Calendar"
					daycssclass="day" 
					dayheadercssclass="dayheader" 
					dayhovercssclass="dayhover" 
					daynameformat="FirstTwoLetters"
					monthcssclass="month"
					nextimageurl="../themes/default/images/common/cal_nextMonth.gif"
					nextprevcssclass="nextprev" 
					othermonthdaycssclass="othermonthday" 
					popup="Custom"
					popupexpandcontrolid="EndDateCalendarButton"
					previmageurl="../themes/default/images/common/cal_prevMonth.gif" 
					selecteddate="2005-9-14"
					selecteddaycssclass="selectedday" 
					selectmonthcssclass="selector"
					selectmonthtext="&curren;" 
					selectweekcssclass="selector"
					selectweektext="&raquo;" 
					swapduration="300"
					swapslide="Linear"
					/>
				</span>
			</td>
		</tr>
		
		<tr>
			<td class="CommonFormFieldName">
				<cp:helpicon id="Helpicon5" runat="Server" resourcename="SearchAdvanced_Sort_Info" ResourceFile="Resources.xml"/>
				<CS:ResourceLabel runat="server" ResourceName="SearchAdvanced_Sort" ID="Resourcelabel3"/>
			</td>
			<td class="CommonFormField">
				<asp:DropDownList ID="SortBy" Runat="server" />
			</td>
		</tr>			
		
		<tr>
			<td class="CommonFormField" colspan="2">
				<asp:LinkButton id="SearchButton" runat="server" CssClass="CommonTextButton" />
			</td>
		</tr>
	</table>
	</div>
</div>
</div>

<script language="javascript">

document.getElementById('<%=DateComparer.ClientID%>').onchange = DateComparerChange;
document.getElementById('<%=DateComparer.ClientID%>').selectedIndex = 0;

</script>
