<%
	polymorphic_filter = filter_session

	allSelection = false
	contactSelection = false
	accountSelection = false
	leadSelection = false
	if polymorphic_filter == '1' || polymorphic_filter.blank?
		allSelection = true
	end
%>
<% parent_id = 0 %>
<% parent_type = 'WkAccount' %>
<script type="text/javascript">
	$(document).ready(function()
	{
		<% if polymorphic_filter == '1' || polymorphic_filter.blank? %>
			<% allSelection = true %>
			$("#account_id").attr("disabled", true);
			$("#contact_id").attr("disabled", true);
			$("#lead_id").attr("disabled", true);
		<% elsif polymorphic_filter == '2' %>
			<% contactSelection = true %>
			<% parent_id = contact_id %>
			<% parent_type = 'WkCrmContact' %>
			$("#account_id").attr("disabled", true);
			$("#lead_id").attr("disabled", true);
			$("#contact_id").removeAttr("disabled");
		<% elsif polymorphic_filter == '4' %>
			<% leadSelection = true %>
			<% parent_id = lead_id %>
			<% parent_type = 'WkLead' %>
			$("#contact_id").attr("disabled", true);
			$("#account_id").attr("disabled", true);
			$("#lead_id").removeAttr("disabled");
		<% else  %>
			<% accountSelection = true %>
			<% parent_id = account_id %>
			<% parent_type = 'WkAccount' %>
			$("#contact_id").attr("disabled", true);
			$("#lead_id").attr("disabled", true);
			$("#account_id").removeAttr("disabled");
		<% end %>

	});
</script>
<% 
	contactArr = relatedValues('WkCrmContact', nil, controller.getOrderContactType, blankForContactDD, controller.additionalContactType, controller.additionalAccountType)
	accountArr = options_for_wktime_account(blankForActDD, controller.getOrderAccountType, controller.additionalAccountType)
	projects = Project.where("#{Project.table_name}.status not in(#{Project::STATUS_CLOSED},#{Project::STATUS_ARCHIVED})").order('name')
	leads = relatedValues('WkLead', nil, controller.getOrderContactType, false, controller.additionalContactType, controller.additionalAccountType)
	projArr = options_for_wktime_project(projects,true)
	isPjtBlank = true
	if pjtChanged
		accountProjects = getProjArrays(parent_id, parent_type)
		projArr = accountProjects.collect{|m| [ m.project_name, m.project_id ] } if !accountProjects.blank?
		if !project_id.blank? && polymorphic_filter != '1'
				projArr.unshift(["", '0'])
		end
	end

	if ['wkshipment', 'wkdelivery'].include? controller_name
		projArr[0] = [l(:label_all_projects),'AP']
		projArr.unshift(["",''])
	end
%>
<table>
<tr>
	<% if isAll %>
	<th align="left"><%= radio_button_tag 'polymorphic_filter', '1', allSelection, :onclick => " $('#contact_id').attr('disabled', true);$('#account_id').attr('disabled', true);$('#lead_id').attr('disabled', true);", :onchange => " getprojects(this, #{pjtChanged}, #{loadSIDD})" %>
	<%= l(:label_all).capitalize %></th>
	<td><td>
	<% end %>

	<th align="left"><%= radio_button_tag 'polymorphic_filter', '2', contactSelection, :onclick => " $('#account_id').attr('disabled', true);$('#contact_id').removeAttr('disabled');$('#lead_id').attr('disabled', true);if(#{controller.loadPurchaseDD}) { rfqTOQuoteChanged(#{User.current.id}, 'po_id');}", :onchange => " getprojects(this, #{pjtChanged}, #{loadSIDD})" %>
	<%= l(:label_contact) %></th>
	<td><%=h select_tag('contact_id', options_for_select(contactArr, :selected => contact_id.blank? ? contactArr : contact_id  ),
	:onchange => " if(#{pjtChanged}) { accProjChanged('', this.id, false, #{blankOptionForPjt}); } if(#{loadSIDD}) { getSupplierInvoice(#{User.current.id}, 'si_id'); } if(#{controller.loadPurchaseDD}) { rfqTOQuoteChanged(#{User.current.id}, 'po_id');} ") %>
	</td>

	<th align="left"><%= radio_button_tag 'polymorphic_filter', '3', accountSelection, :onclick => " $('#account_id').removeAttr('disabled');$('#contact_id').attr('disabled', true);$('#lead_id').attr('disabled', true);if(#{controller.loadPurchaseDD}) { rfqTOQuoteChanged(#{User.current.id}, 'po_id');}", :onchange => " getprojects(this, #{pjtChanged}, #{loadSIDD})" %><%= controller.getAccountDDLbl %></th>
	<td><%=h select_tag('account_id', options_for_select(accountArr, :selected => account_id.blank? ? accountArr : account_id ),
	:onchange => " if(#{pjtChanged}) { accProjChanged('', this.id, false, #{blankOptionForPjt}); } if(#{loadSIDD}) { getSupplierInvoice(#{User.current.id}, 'si_id'); } if(#{controller.loadPurchaseDD}) { rfqTOQuoteChanged(#{User.current.id}, 'po_id');} ") %></td>

	<% if controller.addLeadDD %>
		<th align="left"><%= radio_button_tag 'polymorphic_filter', '4', leadSelection, onclick: " $('#lead_id').removeAttr('disabled');$('#contact_id').attr('disabled', true);$('#account_id').attr('disabled', true);", onchange: " getprojects(this, #{pjtChanged}, #{loadSIDD})"%><%= l(:label_lead) %></th>
		<td><%= select_tag('lead_id', options_for_select(leads, selected: lead_id.blank? ? leads : lead_id ),
		:onchange => " if(#{pjtChanged}) { accProjChanged('', this.id, false, #{blankOptionForPjt}); }") %></td>
	<% end %>

	<% if isproject %>
		<th align="left" style="padding-left: 10px;"><label><%= l(:label_project) %></label></th>
		<td><%=h select_tag('project_id', options_for_select(projArr, :selected => project_id.nil? ? projArr : project_id)) %></td>
	<% end  %>

	<% unless controller.getAdditionalDD.blank?  %>
		<%= render partial: controller.getAdditionalDD, locals: { rfq_id: rfq_id, reqQuotePoDD: needQuotePoDD, onchngeMethodName: "", needRfqBlank: isFilter }%>
	<% end %>


<% if isapply %>
		<td><%= submit_tag l(:button_apply), :class => "small", :name => nil %>
		<%= link_to l(:button_clear), {:tab => controller_name, clear: true}, :class => 'icon icon-reload' %></td><td></td>
<% end  %>

<tr>
</table>
