<?php 

// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
?>
<table align="left" border="0" width="100%" cellspacing="0" cellpadding="<?php echo CELLPADDING_SUB; ?>">
	<tr>
		<td  valign="top">
			<table cellpadding="0" cellspacing="0" width="100%" >
				<?php if(!isset($hide_row_top)) { ?>
			  <tr>
				<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
			  </tr>
				  <?php } ?>
	<?php 
	$header_text=HEADING_TITLE;
	if($category_id>0){
		// $header_text=tep_service_categories_name($category_id,'name');
		$header_text=tep_get_services_name($service_id,$language_id);
	}
	if (MAIN_TABLE_BORDER == 'yes'){
		table_image_border_top(true, false, $header_text);
	}
  	$gparam="";
	if($HTTP_GET_VARS['view']=='month')
	$gparam='&view=month';?>
 	<?php echo tep_draw_form("services_attributes",tep_href_link(FILENAME_SERVICES_SURVEYS_ANSWER, 'service_id=' . $HTTP_GET_VARS['service_id'].'&type=CD'),'post');?>
			<tr>
			  <td colspan="2" align="left" valign="top" >
				   <table border="0" align="left" cellpadding="0" cellspacing="0" width="100%">
					 <?php 	// select the options
						if ($rows>0){
					?>
						<tr style="height:10"><td></td></tr>
						<tr><td class="smalltext"><?php echo  ATTRIBUTE_CONDITION;?></td></tr>
						<tr class='eventListing-data' >
							<td width="75%" valign="top" ><?php //echo '<b>' . TEXT_SERVICE_OPTIONS . '</b>';	 ?>
								<table border="0" cellpading="5" cellspacing="0" width="100%">
									<tr> 
		   								<td colspan="2" align="left" valign="top" width="260" class="main" ><?php  echo TEXT_SERVICE_ATT_NAME;?></td>
					  					<td align="left" valign="top" class="main" nowrap="nowrap" ><?php echo TEXT_SERVICE_ATT_VALUE;?></td>
					 				</tr>
									<?php $display_array=array();
										  while ($services_options_name_values = tep_db_fetch_array($result)) {
											  $selected = 0;
											  $services_options_array = array();	
										?>
										<tr> 
											<td class="main" nowrap="nowrap"><?php echo $services_options_name_values['services_options_name'];?>: </td>
											<td valign="top" aign="left" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
											<?php
												$service_tax_class_id=(isset($services->tax_class_id)?$services->tax_class_id:0);	
												$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 = '" . $HTTP_GET_VARS['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");
												$services_options_array[0]['text'] = TEXT_SERVICE_NOT_REQUIRED; 
												while ($services_options_values = tep_db_fetch_array($services_options)) {
												$display_array[]=array('attrib_id'=>$services_options_name_values['services_options_id'],'attrib_name'=>$services_options_name_values['services_options_name'],'option_id'=>$services_options_values['services_options_values_id'],'option_name'=>$services_options_values['services_options_values_name'],'option_price'=>tep_add_tax(($services_options_values['price_prefix'] . $services_options_values['options_values_price']),tep_get_tax_rate($service_tax_class_id)));
												$services_options_array[] = array('id' => $services_options_values['services_options_values_id'], 'text' => $services_options_values['services_options_values_name']);
													if ($services_options_values['options_values_price'] != '0') {
														$services_options_array[sizeof($services_options_array)-1]['text'] .= ' ' .  $services_options_values['price_prefix'] . $currencies->display_price($services_options_values['options_values_price'], tep_get_tax_rate($service_tax_class_id),'1',true);
													}
												} // while option values
												$id= $services_options_name_values['services_options_id'];
												$id1='id[' . $services_options_name_values['services_options_id']. ']';
											?>
											</td> 
											<td><?php  echo  tep_draw_pull_down_menu($id1, $services_options_array, (($option_id>0)?$option_id:$services->attributes[$id]),' id="'.$id1.'" onchange="javascript:price();"') ;?></td>
										</tr>
										<tr>
											<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '5'); ?></td>
										</tr>
								<?php } // while option name  
								?>							
								</table>
							</td>   
							<td width="25%" valign="top" align="right"> 
								<table border="0" cellspacing="0" cellpadding="0" width="100%">
									<tr>  
										<td width="100%" align="right" valign="top">
											<?php include(CHECK_CON . $freeway_path_after_joomla.'service_board.php')?>
										</td> 	
									</tr>
								</table> 
							</td>
						</tr> 
						<?php }else { 
					  	if($error){ ?>
						<tr style="height:20"><td></td></tr>					  		
						<tr><td colspan="2" align="center" class="smalltext"><?php echo '<font color="red">'.$error . '</font>';?></td>	</tr>	
				<?php }
				 }
				 ?>
				   </table>
				  </td>
				</tr>
	<script type="text/javascript"> 
		 var option_array=Array();
		 <?php 		 
		 for($i=0;$i<sizeof($display_array);$i++){?>
		option_array[<?php echo $i;?>]="<?php echo $display_array[$i]['attrib_id'].'#'.$display_array[$i]['attrib_name'].'#'.$display_array[$i]['option_id'].'#'.$display_array[$i]['option_name'].'# '.$display_array[$i]['option_price'];?>";		
		<?php  } ?>
		function price(){
			var qty="<?php echo round($services->qty * ($services->bookings/$service_info['service_total_time']));?>"; 
			var service_costs=parseFloat("<?php  
				    if($services->resource_id) $price=tep_get_resource('resource_costs',$services->resource_id,$languages_id);
				    $tax_class_id=tep_get_resource('resource_tax_class_id',$services->resource_id,$languages_id);
					$service=$services_info;
					if($service_info['include_resource_price']=='N'){
						$price=$service_info['service_costs'];
				    	$tax_class_id=$service_info['service_tax_class_id'];	
					}
					$loading_price_dates=get_loading_array($service_id);
					$loading_price=tep_loading_price($loading_price_dates,$services->start_date,$services->end_date,$services->start_time,$services->end_time,$service["booking_type"],$price);
					if($loading_price<0) $loading_price=0;
					echo tep_add_tax($loading_price + $price,tep_get_tax_rate($tax_class_id));
				?>
			");
			 
			var price=0;
			var tot="";										
			 for(i=0;i<option_array.length;i++){
				  attrb_splt=option_array[i].split("#");
				  var at_id="id["+parseInt(attrb_splt[0])+"]";
				  opt_id=document.getElementById(at_id).value;
				  pre_id="";
				  if(pre_id!=attrb_splt[0]){
					if(opt_id==attrb_splt[2]){
						price=price+parseFloat(attrb_splt[4]);	
					}
					pre_id=attrb_splt[0];
				 }
			 }
			tot=dollarAmount(qty * (service_costs+price));
			if(document.getElementById("no_resource")) document.getElementById("no_resource").innerHTML=tot;			
		}
		function getOptionIndex()
		{
			var x=document.getElementById("<?php echo $id;?>")
			alert(x.selectedIndex)
		}
 	 </script>	
	<?php if (MAIN_TABLE_BORDER == 'yes'){
	table_image_border_bottom();
	} ?>  
	<tr><td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td></tr>
	<tr>
		<td colspan="3">
			<table cellpadding="0" cellspacing="0" width="100%">
				<tr><td  align="left" width="40%"><?php
					echo '<a href="'.tep_href_link((($service->resource_id)?FILENAME_SERVICE_RESOURCES:FILENAME_SERVICES_INFO),'service_id='.$HTTP_GET_VARS['service_id']).'">'.tep_template_image_button('button_back.gif', IMAGE_BUTTON_BACK).'</a>';
					?></td>
					<td width="35%" align="right" valign="top"><?php   echo  (($error=='')?tep_template_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE):'');?></td>
					<td width="25%"></td>
				</tr>
			</table>
		</td>
	</tr>	
</table>
</td>
</tr>
</table>
<?php 
if($HTTP_POST_VARS['temp_start_date'] && $HTTP_POST_VARS['temp_start_time'] && $HTTP_POST_VARS['temp_end_date'] && $HTTP_POST_VARS['temp_end_time']){
	$HTTP_POST_VARS['start_date']=tep_db_prepare_input($HTTP_POST_VARS['temp_start_date']);
	$HTTP_POST_VARS['end_date']=tep_db_prepare_input($HTTP_POST_VARS['temp_end_date']);
	$HTTP_POST_VARS['start_time']=tep_db_prepare_input($HTTP_POST_VARS['temp_start_time']);
	$HTTP_POST_VARS['end_time']=tep_db_prepare_input($HTTP_POST_VARS['temp_end_time']);
	tep_set_session_value('time_details',$HTTP_POST_VARS);   	
}
?>
</form>	
<script language="javascript">if("<?php echo $error;?>"=="") {
price(); }</script>
<!-- <table border="0" cellspacing="0" cellpadding="0" width="100%">
	<?php /*$header_text=TEXT_BOARD;
		  if (MAIN_TABLE_BORDER == 'yes'){
				table_image_border_top(false, false, $header_text);
		 	}*/ ?>
	<tr>
		<td width="100%" align="right" valign="top">
			<?php //include('service_board.php')?>
		</td>	
	</tr>
	<?php /* if (MAIN_TABLE_BORDER == 'yes'){
				table_image_border_bottom();
			}*/ ?>
</table> -->

