<%= javascript_include_tag 'index', :plugin => "redmine_wktime" %>
<script type="text/javascript"> 
	actRelatedUrl="<%= "#{url_for(:controller => "wkcrm", :action => 'getActRelatedIds', :additionalContactType => controller.additionalContactType, :additionalAccountType => controller.additionalAccountType )}" %>";
	accountUrl="<%= "#{url_for(:controller => "wkinvoice", :action => 'getAccountProjIds')}" %>";
</script>
<% wkcrm_helper = Object.new.extend(WkcrmHelper) %>
<% 
	parentArr = options_for_wktime_account(false, 'A', controller.additionalAccountType)
	if !parentObject.blank?
		ptype = parentObject.parent_type == "WkCrmContact" ? 'C' : 'A'
		parentArr = relatedValues(parentObject.parent_type, parentObject.parent_id, ptype, false, controller.additionalContactType, controller.additionalAccountType)	
  elsif !parentType.blank?
		ptype = parentType == "WkCrmContact" ? 'C' : 'A'
		parentArr = relatedValues(parentType, nil, ptype, false, controller.additionalContactType, controller.additionalAccountType)
	end
	#parentArr.unshift(["",''])
	relHash = wkcrm_helper.relatedHash
	relHash.delete("WkOpportunity")
	relHash.delete("WkLead") if !controller.addLeadDD 
	#unless index
	#	relHash.delete("")
	#end
	stylePadding = 40
	unless padding.blank?
		stylePadding = 20
	end
	
	if needblankType
		relHash.merge!('0' => '')
		parentArr.unshift(["",'0'])
	end
%>
<tr>
	<th align="left"><%= l(:field_type) %></th>
	<td style="padding-left:<%=stylePadding%>px;"><%=h select_tag('related_to', options_for_select(relHash.invert, :selected => parentObject.blank? ? (parentType.blank? ? "" : parentType) : parentObject.parent_type ), :onchange => "actRelatedDd(#{User.current.id}, #{needParentProject}, #{needblankType}, 'A', 'C', false); ") %></td>
<% if padding.blank? %>
</tr>
<tr>
<% end %>
	<th align="left"><%= l(:field_name) %></th>
	<td style="padding-left:<%=stylePadding%>px;"><%=h select_tag('related_parent', options_for_select(parentArr, :selected => parentObject.blank? ? (parentId.blank? ? "" : parentId) : parentObject.parent_id ), :onchange => "if(#{needParentProject}) {accProjChanged(#{User.current.id}, this.id, true, #{needblankType}); }") %></td>
</tr>