<?php 

// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
?>
 <script language="javascript">
   function showConditions(s_id,o_id,o_v_id){
	var handle;
	var feats;
	vtop=screen.availHeight /2 - screen.availHeight /6;
	vleft=screen.availWidth/2 - screen.availWidth/6;
	feats="height=350,width=350,location=no,menubar=no,resizable=no,scrollbars=yes,toolbar=no,status=no,left=" + vleft + ",top=" + vtop ;	
	window.open("service_details.php<?php echo '?category_id='.$category_id;?>&service_id="+s_id+"&option_id="+o_id,"servicedetails",feats);
   }
   
   function do_radio(cou){
	 var frm=document.services_list.elements["service_id[]"];
	  if(frm.length>0 && ((cou) || cou==0)){ frm[cou].checked=true;  } else {frm.checked=true; }  
		if(frm.length>1){
			for(i=0;i<frm.length;i++){
			 if(frm[i].checked==true){
			  service_split=frm[i].value;
			  service=service_split.split('-');
			  service_id=service[1];
			  option_id=service[3];
			 }
			}
		 }else {
		   service_split=frm.value;
		   service=service_split.split('-');
		   service_id=service[1];
		   option_id=service[3];
		 }
	 document.services_list.service_ids.value=service_id;
	 document.services_list.option_id.value=option_id;
	 
   }
   function Validate_form(service_id){
   	 if(document.services_list.service_ids.value>0){
	   return true;
	 }else { 
	   alert("Please select service");
	   return false;
	 } 
   }
 </script>
<table align="left" border="0" width="100%" cellspacing="0" cellpadding="<?php echo CELLPADDING_SUB; ?>">
	<?php if(!isset($hide_row_top)) { ?>
      <tr>
        <td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
	 <?php } ?> 
<?php if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_top(true, false, sprintf(HEADING_TITLE,$category_name));
} 
?> 
  <?php echo tep_draw_form("services_list",tep_href_link(FILENAME_SERVICES_LIST,'action=do_service'),'post','onsubmit="javascript:return Validate_form();"');?>
	<tr>
	  <td class="main" align="left" colspan="4">
	    <?php echo sprintf(TEXT_SELECT_PLEASE,$category_name);?>
	  </td>
	</tr>
	<tr>
	 <Td class="main" align="left" colspan="4"><?php echo '<b>'.TEXT_BASE_RATE_FOR.'</b>';?></Td>
	</tr>
	<?php 
	 if(sizeof($service_list_array)>0){ ?>
	<tr>
	  <td class="main" align="left" width="160">
	    <?php echo sprintf(TEXT_SERVICE_NAME,$category_name);?>
	  </td>
	  <td class="main" align="left" width="210">
	    <?php echo sprintf(TEXT_SERVICE_TYPE,$category_name);?>
	  </td>
	  <td class="main" align="left" width="100">
	   <?php echo TEXT_DURATION;?>
	  </td>
	  <td class="main" align="left" width="100">
	   <?php echo TEXT_SERVICE_RATE;?>
	  </td>
	</tr>
	<?php for($i=0;$i<=sizeof($service_list_array);$i++){
		  $result = tep_db_query("SELECT * FROM " . TABLE_SERVICES_ATTRIBUTES . " sa LEFT JOIN " . TABLE_SERVICES_OPTIONS . " so ON so.services_options_id=sa.options_id LEFT JOIN " . TABLE_SERVICES_OPTIONS_VALUES . " sov ON sov.services_options_values_id=sa.options_values_id WHERE sa.service_id='" . (int)$service_list_array[$i]['service_id'] . "' and so.language_id='" . $languages_id . "' and sov.language_id='" . $languages_id . "' group by services_options_id");
	      $service_costs=$service_list_array[$i]['service_costs'];
		  $duration='0 Day(s)';
		  if($service_list_array[$i]['booking_type']=='D'){
		    $duration=$service_list_array[$i]['max_bookings'].' - Day(s)';
		  }else if($service_list_array[$i]['booking_type']=='H'){
		    $diff=get_diff_time($service_list_array[$i]['start_time'],$service_list_array[$i]['end_time'])/60;
		    $duration=$diff.' - Hour(s)';  
		  }
		  if(tep_db_num_rows($result)>0){
		  $count=$count;
		  while ($services_options_name_values = tep_db_fetch_array($result)) {
	       $services_options = tep_db_query("select sa.services_options_sort_order, sov.services_options_values_id, sov.services_options_values_name, sa.options_values_price, sa.price_prefix,sa.options_values_id from " . TABLE_SERVICES_ATTRIBUTES . " sa, " . TABLE_SERVICES_OPTIONS_VALUES . " sov where sa.service_id = '" . $service_list_array[$i]['service_id'] . "' and sa.options_id = '" . $services_options_name_values['services_options_id'] . "' and sa.options_values_id = sov.services_options_values_id and sov.language_id = '" . $languages_id . "'" . " order by sa.services_options_sort_order, sa.options_values_price");
	       while ($services_options_values = tep_db_fetch_array($services_options)) {
		     $service_costs=$service_costs+$services_options_values['options_values_price'];
			 $services_array='service_id-' . $service_list_array[$i]['service_id'] . '-options_id-'. $services_options_values['services_options_values_id'];
             if($class=="dataServiceRowOdd"){
			  $class="dataServiceRowEven";
			 }else {
			   $class="dataServiceRowOdd";
			 }
			 echo "<tr class='".$class."' onmouseover=this.style.cursor='hand' onclick='javascript:do_radio(".$count.");'>";
			 echo "<td class='main' align='left'>".tep_draw_radio_field("service_id[]",$services_array,'','onclick="javascript:do_radio();"') . '&nbsp;' . $service_list_array[$i]["service_name"] . "</td>";
			 echo "<td class='main' align='left'><a href='javascript:showConditions(".$service_list_array[$i]['service_id'].','.$services_options_values['services_options_values_id'].','.$services_options_values['options_values_id'].");'>".$services_options_name_values['services_options_name'] . '&nbsp;'.$services_options_values['services_options_values_name']."</a></td>";
		     echo "<td class='main' align='left'>".$duration."</td>";
			 echo "<td class='main' align='left'>".$currencies->display_price($service_costs,tep_get_tax_rate($service_list_array[$i]["service_tax"]))."</td>";
			 echo "</tr>";
			 $count+=1;
		   }
		  }
		 }else if($service_list_array[$i]['service_id']){
		  if($class=="dataServiceRowOdd"){
			  $class="dataServiceRowEven";
		  }else {
			   $class="dataServiceRowOdd";
		  }
		  $services_array='service_id-' . $service_list_array[$i]['service_id'] . '-options_id-0';
		  echo "<tr class=".$class." onclick='javascript:do_radio(".$count.");' onmouseover=this.style.cursor='hand'>";
		  echo "<td class='main' align='left'>".tep_draw_radio_field("service_id[]",$services_array,'','onclick="javascript:do_radio();"') . '&nbsp;' . $service_list_array[$i]["service_name"] . "</td>";
		  echo "<td class='main' align='left'><a href='javascript:showConditions(".$service_list_array[$i]['service_id'].',0,0'.")'>No Attributes</a></td>";
		  echo "<td class='main' align='left'>".$duration."</td>";
		  echo "<td class='main' align='left'>".$currencies->display_price($service_costs,tep_get_tax_rate($service_list_array[$i]["service_tax"]))."</td>";
		  echo "</tr>";
		  $count+=1;
		 }
		 ?>
		</td>
	 </tr>
	 <tr>
      <td colspan="4"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '1'); ?></td>
     </tr>
	<?php  
	 }
	}else {
	   echo "<tr><td class='main' colspan='4' align='center'><b><font color='red'>".TEXT_SERVICE_NOT_FOUND."</font></b></td></tr>";
	}
	echo '<Tr><td colspan="4" align="left" class="main">'.tep_service_categories_name($category_id,'notes').'</td><tr>';
	echo '<input type="hidden" name="service_ids">';
	echo '<input type="hidden" name="option_id">';
	echo '<input type="hidden" name="category_id" value="'.$category_id.'">';?>
<?php if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_bottom();
} ?>  
<tr>
    <td colspan="4"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>
<tr>
	<td align="left" colspan="4">
	  <table width="100%" align="center" cellpadding="0" cellspacing="0" border="0">
	    <tr>
		 <td class="main" align="left"><?php echo '<a href="'.tep_href_link(FILENAME_SERVICES_SEARCH,'secPath='.$category_id).'">'. tep_template_image_button('button_back.gif', IMAGE_BUTTON_BACK).'</a>';?></td>
		 <td class="main" align="right"><?php echo tep_template_image_submit('button_continue.gif', IMAGE_BUTTON_RESERVE);?></td>
		</tr>
	  </table>
	</td>
</tr>
</form>
</table