<!--contact_involved_qtip
	<div class="qtip_panel">
		
		<dl>
			[%
			if(contact.phoneNumbers!=null && contact.phoneNumbers.phoneNumber!=null){
				%]<dt>Telephone</dt><dd><a href="callto://[%=contact.phoneNumbers.phoneNumber[0].number%]">[%=contact.phoneNumbers.phoneNumber[0].number%]</a></dd>[%
			}
			%]
			
			[%
			if(contact.emailAddresses!=null && contact.emailAddresses.emailAddress!=null){
				%]<dt>Email</dt><dd><a href="mailto:[%=contact.emailAddresses.emailAddress[0].email%]">[%=contact.emailAddresses.emailAddress[0].email%]</a></dd>[%
			}
			%]
		</dl>
	</div>
-->

<!--user_involved_qtip
	<div class="qtip_panel">
		<dl>
			
		
			[%
			if(user.email!=''){
				%]<dt>Email</dt><dd><a href="mailto:[%=user.email%]">[%=user.email%]</a></dd>[%
			}
			%]
		
			[%
			if(user.phoneNumber!=null && user.phoneNumber.length!=0){
				if(user.phoneNumber[0]!=''){
				%]<dt>Telephone</dt><dd><a href="callto://[%=user.phoneNumber[0]%]">[%=user.phoneNumber[0]%]</a></dd>[%
				}
			}
			%]
			
		</dl>
	</div>
-->

<!--deal_task
	[%
        var usr=get_user(task.assignedTo);
    %]
    <dd class="task" rel="[%=task.id%]">
        <dl>
            <dd class="check-mark"><input type="checkbox" class="task-checkbox" [%=(task.complete=='true')?'checked=\'checked\'':''%] value="16"/></dd>
            <dd class="left-item-panel"><strong class="assignee">[%=user_fullname(usr)%]</strong>&nbsp;-&nbsp;[%=task.title%]</dd>
            <dd class="right-item-panel"><strong class="type">[%=lookup_task_type(task_types,task.type).name%]</strong>&nbsp;-&nbsp;<strong class="due-date"><abbr class="timeago" title="[%=task.dueOn%]"></abbr></strong></dd>
        </dl>
    </dd>
-->
<!--contact_involved
	<dd class="" letter="" rel="[%=contact.id%]">
		<img src="/api/contacts/[%=contact.id%]/avatar"/><a href="/contacts/#[%=contact.id%]" rel="2" style="">[%=contact_fullname(contact)%]</a>
	</dd>
	-->
	
<!--user_involved
	<dd class="" letter="" rel="[%=user.id%]">
		<img src="/api/users/[%=user.id%]/avatar"/><a href="/profile/[%=user.id%]" rel="2" style="">[%=user_fullname(user)%]</a>
	</dd>
	-->
<!--deal_task_holder
	<dl class="task-list tasks-overdue hide">
		<dt class="task-group">
			Overdue
		</dt>
	</dl>
	<dl class="task-list tasks-due-today hide">
		<dt class="task-group">
			Today
		</dt>
	</dl>
	<dl class="task-list tasks-due-tomorrow hide">
		<dt class="task-group">
			Tomorrow
		</dt>
	</dl>
	<dl class="task-list tasks-due-this-year hide">
		<dt class="task-group">
			Future
		</dt>
	</dl>
	<dl class="task-list complete-tasks hide">
		<dt class="task-group">
			Complete
		</dt>
	</dl>
	<div class="Actions" style="display: none;">
		<ul>
			<li>
				<a href="#" id="show_me_more_notes" name="show_me_more_notes">Show me 10 more</a>
			</li>
		</ul>
	</div>
	
-->

<!--deal_note_holder
	<dl class="note-list notes-left-today hide">
		<dt class="note-group">Left Today</dt>
	</dl>
	
	<dl class="note-list notes-left-yesterday hide">
		<dt class="note-group">Left Yesterday</dt>
	</dl>
	
	<dl class="note-list notes-left-recently hide">
		<dt class="note-group">Left Recently</dt>
	</dl>
	
-->
<!--deal_note
	<dd rel="[%=note.id%]">
<dl>
    [%
    var user = get_user(note.createdBy);
    %]
    <dd class="note-meta">
        <span class="">
            <a href="/profile/[%=user.id%]">[%=user_fullname(user)%]</a>
        </span>
        <em>
            <abbr class="published updated timeago" title="[%=note.createdAt%]">[%=note.createdAt%]</abbr>
        </em>
    </dd>
    <dd class="note-actions ">
        <ul>
        <li id="edit-action"><a href="" >[%=resource_string('action.contacts.index.edit')%]</a></li>
        <li id="delete-action"><a href="">[%=resource_string('action.contacts.index.delete')%]</a></li>
        <li id="confirm-action"><a href="" >[%=resource_string('action.contacts.index.done')%]</a></li>
        <li id="cancel-action"><a href="">[%=resource_string('action.contacts.index.cancel')%]</a></li>
        </ul>
    </dd>
    <dd class="note-info">
        <img alt="" src="/api/users/[%=user.id%]/avatar" class="photo avatar _hide"/>
    </dd>
    <dd class="note-body" id="view-box">
        <div id="note-body-box">[%=parse_note_body(note.body)%]</div>
        [% if(note.contact != undefined) { 
        	var note_contact = get_deal_contact(note.contact);
        %]
        	<p><span class="relates-to-contact">Contact</span> <a href="/contacts/#[%=note_contact.id%]" rel="[%=note_contact.id%]" style="">[%=contact_fullname(note_contact)%]</a>
        [% } %]
    </dd>

    <dd class="note-body" id="edit-box">
        <span class="Field"><textarea>[%=parse_note_body(note.body)%]</textarea></span>
    </dd>
	<dd style="clear:both!important;"></dd>
</dl>
</dd>

-->


<div class="deals-holder" style="display: block;">
	<div class="deals-card-panel">
		<div class="gen-toolbar toolbar">
			<ul id="general_toolbar">
				<li>
					<a id="link-deal-edit" href="#" title="Edit" name="link-deal-edit">Edit</a>
					
				</li>
				
				
			</ul><span class="contact-name">[%=deals[deal].name%]</span>
		</div>
		<div class="deals-info-header">
			<p>Created <strong class="due-date"><abbr class="timeago" title="[%=deals[deal].createdAt%]">[%=format_created_date(deals[deal].createdAt)%]</abbr></strong> by [%=user_fullname(users[deals[deal].createdBy])%] and assigned to [%=user_fullname(users[deals[deal].assignedTo])%]<span>[%=format_currency(deals[deal].amount)%]</span></p>
		</div>
		
	</div>


	<div id="deals-NT" class="deals-information-pane">
		<div class="Tabs">
			<ul>
				<li>
					<a href="#deals-overview">Overview</a>
				</li>
				<li>
					<a href="#deals-notes">Notes</a>
				</li>
				<li>
					<a href="#deals-tasks">Tasks</a>
				</li>
			</ul>
		</div>
		
	
		<div class="contact-information contact-tab-panel" id="contact-detail" style="display: block;">
				<dl class="note-list notes-left-today">
					[%
					if(is_in_progress(deals[deal])){
					%]
					<dt>Forecasts</dt>
					<dd>There is currently a <strong>[%=deals[deal].probability%]%</strong> probability of securing this deal.</dd>
						[%
						if(deals[deal].expectedClose != undefined){
						%]
						<dd>This deal is expected to be closed by <strong>[%=format_expectedClose(deals[deal].expectedClose)%]</strong>.</dd>
						[%
						} else {
						%]
						<dd>This deal doesn't have an expected close date.</dd>
						[%
						}
						%]
					[%
					}
					%]
					<dt>Description</dt>
					<dd>[%=format_description(deals[deal])%]</dd>
				</dl>
					
		</div>
		
		<div class="contact-tab-panel" id="contact-notes" style="display: none;">
			[%
				if(is_in_progress(deals[deal])){
			%]
			<div rel="id-add-note-panel" class="show-hide" id="id-add-note-container">
				<div class="_hide" id="id-add-note-panel">
					<h2 class="title hide">
						<span>Add Note</span>
					</h2>
					<form id="add-note-form" action="/api/notes" name="add-note-form">
						<span class="Field ClearedField"><textarea class="expanding" id="add-note-body"></textarea></span>
						<span class="Field ClearedField" id="note-deal-field">
							<label for="note-deal">Associate with a contact?</label>
	                        <select id="add-note-contact" name="add-note-deal">
								<option value="">Do not associate</option>
								[%
								var _current_letter='_';
								
								$.each(_sorted_indeces,function(i,m){
									n = all_contacts[m.id];
									
									if(n.lastName.length > 0) {
						                var _this_letter=n.lastName.substring(0,1).toUpperCase();
						            } else {
						                var _this_letter=n.firstName.substring(0,1).toUpperCase();
						            }
									
									
									if(_this_letter!='' && _current_letter!=_this_letter){
						            %]
										<optgroup style="text-align:right;" rel="[%=_this_letter%]" label="[%=_this_letter%]&nbsp;">
						            [%
						            }
						
									
									%]<option style="text-align:left;" value="[%=n.id%]">[%=contact_fullname(n)%]</option>[%
									
									if(_this_letter!='' && _current_letter!=_this_letter){
						                _current_letter=_this_letter;
						            }
								});
								%]
							</select>
	                    </span>
						<div class="Actions">
							<ul>
								<li>
									<input type="button" id="add-note-action" value="Add Note">
								</li>
							</ul>
						</div>
					</form>
				</div>
			</div>
			[%
				}
			%]
			<div id="deal-notes-list" class="">
				<p>NOTES GO HERE</p>
			</div>
		</div>
		<div class="contact-tab-panel" id="contact-tasks" style="">
			[%
				if(is_in_progress(deals[deal])){
			%]
			<div rel="id-add-note-panel" class="show-hide" id="id-add-task-container">
				<div class="" id="id-add-task-panel">
					<form id="add-task-form" action="/api/task" name="add-task-form">
						<span class="Field ClearedField"><input type="text" name="description" id="add-task-title"></span>
						<fieldset style="clear: both;">
							<span class="Field"><label>Type</label> <select name="taskType">
								[% 								
								$.each(task_types,function(i,n){
									%]
									<option value="[%=n.id%]">
										[%=n.name%]
									</option>
									[%
								}); 
								%]
							</select></span> <span class="Field"><label>Assigned To</label> <select name="assignTo">
							[%
                                $.each(users,function(o,p){
	if(p.enabled=='true'){
                            %]
                                <option value="[%=p.id%]">[%=user_fullname(p)%]</option>
                            [%
}
                                });
                            %]
							</select></span> 
							<span class="Field">
                                <label>Due</label>
                                <input type="text" name="due"/>
                            </span>
							<span class="Field ClearedField" id="note-deal-field">
								<label for="note-deal">Associate with a contact?</label>
		                        <select id="add-task-contact" name="add-note-deal">
									<option value="">Do not associate</option>
									[%
									var _current_letter='_';
									
									$.each(_sorted_indeces,function(i,m){
										n = all_contacts[m.id];
										
										if(n.lastName.length > 0) {
							                var _this_letter=n.lastName.substring(0,1).toUpperCase();
							            } else {
							                var _this_letter=n.firstName.substring(0,1).toUpperCase();
							            }
										
										
										if(_this_letter!='' && _current_letter!=_this_letter){
							            %]
											<optgroup style="text-align:right;" rel="[%=_this_letter%]" label="[%=_this_letter%]&nbsp;">
							            [%
							            }
							
										
										%]<option style="text-align:left;" value="[%=n.id%]">[%=contact_fullname(n)%]</option>[%
										
										if(_this_letter!='' && _current_letter!=_this_letter){
							                _current_letter=_this_letter;
							            }
									});
									%]
								</select>
		                    </span>
						</fieldset>
						<div class="Actions">
							<ul>
								<li>
									<input type="button" id="add-task-action" value="Add Task">
								</li>
							</ul>
						</div>
					</form>
				</div>
			</div>
			[%
				}
			%]
			<div id="deal-tasks-list">
				<p>THE TASKS GO HERE</p>
			</div>
		</div>
		
	</div>
	<div id="" class="deals-meta-pane">
		<h2>Status</h2>
		[%
		var stat=status_map(deal,deals);
		%]
		<ul class="status">
			<li class="[%=stat[0]%]"><a title="Mark deal as in progress" id="inprogress" href="#">In Progress</a></li>
			<li class="[%=stat[1]%]"><a title="Mark deal as won" id="won" href="#">Won</a></li>
			<li class="[%=stat[2]%] last"><a title="Mark deal as lost" id="lost"href="#">Lost</a></li>
		</ul>
		
		
		<dl id="deals-involved-list">
			<dt style="" id="contacts-involved" rel="Contacts">Contacts</dt>
			<dt style="" id="users-involved" rel="Users">Users</dt>
		</dl>
	</div>	
	
</div>
