<%-# Fedena
#Copyright 2010 Foradian Technologies Private Limited
#
#This product includes software developed at
#Project Fedena - http://www.projectfedena.org/
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing,
#software distributed under the License is distributed on an
#"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#KIND, either express or implied.  See the License for the
#specific language governing permissions and limitations
#under the License. -%>

<table border="0" align="center" width="100%" id="table" cellspacing="0"  >
      <tr>
        <td><div class="blank"></div></td>
        <td><div class="blank"></div></td>
        <% @class_timing.each do |ct| %>
          <td class="td"><div class="top"><%= ct.start_time.strftime("%I:%M%p")  unless ct.start_time.nil? %> - <%= ct.end_time.strftime("%I:%M%p")  unless ct.end_time.nil? %></div></td>
        <% end %>
        <% @weekday.each do |wk| %>
        <tr>
          <td class="td"><div class="name"><%= t(Date::DAYNAMES[wk.day_of_week].downcase).upcase %></div></td>
          <td class="td-blank"></td>
          <% @class_timing.each do |ct| %>
            <% @tte = @timetable[wk.id][ct.id] %>
            <td class="td">
              <div id="drop_<%= "#{wk.id}_#{ct.id}" %>"  class="drop"onClick="update_selected_divs('<%= "#{wk.id}_#{ct.id}" %>');">
                <div class="tt-subject" id="subject_name_<%= @tte.id %>">
                  <% if @tte.is_a? TimetableEntry  %>
                    <div class="subject">
                      <% unless @tte.subject.nil? %>
                        <% unless @tte.subject.elective_group_id.nil?   %>
                          <%= shorten_string(@tte.subject.elective_group.name.to_s,10) %>
                        <% else %>
                          <%= @tte.subject.code  %>
                        <% end %>
                        <span>
                          <% unless @tte.subject.elective_group_id.nil?   %>
                            <% @subj_in_elective = Subject.find_all_by_elective_group_id(@tte.subject.elective_group_id,:conditions=>'is_deleted = false')   %>
                            <% @subj_in_elective.each do |s| %>
                              <%= s.name unless s.nil? %>
                              <% @sub_emp = EmployeesSubject.find_by_subject_id(s.id) %>
                              <div class="emp-name"><%= @sub_emp.employee.full_name unless @sub_emp.nil? %></div>
                            <% end %>
                          <% else %>
                            <%= @tte.subject.name unless @tte.subject.nil? %>
                            <div class="emp-name"><%= @tte.employee.full_name unless @tte.employee.nil? %></div>
                          <% end %>
                        </span>
                      <% end %>
                    </div>
                    <div class="employee"><%= link_to_remote image_tag("/images/buttons/delete-new.png", :border => 0),
                        :url => {:action => "delete_employee2", :id => @tte.id},
                        :complete => "clear_selected_divs();",
                        :before => "Element.show('loader')",
                        :success => "Element.hide('loader')",
                        :update => "timetable" \
                        unless @tte.subject.nil?  -%>
                      <% unless @tte.subject.nil? %>
                        <% unless @tte.subject.elective_group_id.nil?   %>
                          <%= t('elective') %>
                        <% else %>
                          <%= @tte.employee.first_name unless @tte.employee.nil? %>
                        <% end %>
                      <% end %>
                    </div>
                  <% else %>
                    <div class="subject"></div>
                    <div class="employee"></div>
                  <% end %>
                </div>
              </div>
              <%= drop_receiving_element("drop_#{wk.id}_#{ct.id}",
                :accept => "employees_subject",
                :onDrop => "function(draggable_element, droppable_element) { $(droppable_element).highlight(); make_ajax_calls('#{wk.id}_#{ct.id}', draggable_element.id.split('_').last()); }") -%>
            </td>
          <% end %>
        </tr>
      <% end %>
      </tr>
    </table>