<?php 

// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
?>
<table align="left" border="0" width="75%" cellspacing="0" cellpadding="<?php echo CELLPADDING_SUB; ?>">
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10');
		
		$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);
		}?></td>
      </tr>
<?php if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_top(true, false, $header_text);
} 
?> 
<?php   $gparam="";
if($HTTP_GET_VARS['view']=='month')
	$gparam='&view=month';?>
  <?php echo tep_draw_form("services_attributes",tep_href_link(FILENAME_SERVICES_ATTRIBUTES,  '&service_action=buy_service&service_id=' . $HTTP_GET_VARS['service_id']),'post');?>
		<tr>
	  <td colspan="2" align="left" valign="top" width="75%">
	   <table border="0" width="100%" align="left" cellpadding="0" cellspacing="0">
		 <?php 	// select the options
				
				if ($rows>0){
			?>
					<tr class='eventListing-data'>
						
						<td width="75%" align="left" valign="top" ><?php //echo '<b>' . TEXT_SERVICE_OPTIONS . '</b>';
						 ?>
						<table border="0" cellpading="2" cellspacing="0" width="0">
						<tr>
		   					<td colspan="2" align="left" valign="top" width="160" 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");
									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['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']. ']';
									//echo tep_draw_pull_down_menu( $services_options_name_values['services_options_id'] , $services_options_array, (($option_id>0)?$option_id:$cart->contents[$HTTP_GET_VARS['service_id']]['attributes'][$services_options_name_values['services_options_id']]),'onChange=price();');
									//echo tep_draw_pull_down_menu($id1, $services_options_array, (($option_id>0)?$option_id:$cart->contents[$HTTP_GET_VARS['service_id']]['attributes'][$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:$cart->contents[$HTTP_GET_VARS['service_id']]['attributes'][$services_options_name_values['services_options_id']]),' id="'.$id1.'"onchange="javascript:price();"') ;?>
								</td>
								<!--  <td align="right" class="smallText">&nbsp;<input type="text" name="favourite" id="favourite"  size="6">&nbsp;</td>-->
								<!--<input type="button" onclick="getOptionIndex()" value="How many options in the list?">-->
							</tr>
							<tr>
								<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '5'); ?></td>
							</tr>
						<?php } // while option name ?>							
						</table>
						</td>
					</tr>
				<?php }else { 
				   }	if($error){ ?>
					<tr><td colspan="2" align="center" class="smalltext"><?php echo '<font color="red">'.$error . '</font>';?></td>	</tr>	
				<?php }?>
	   </table>
	  </td>
	
	</tr>
<?php //print_r($services);?>
<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 service_costs=parseInt("<?php echo (($services->resource_id)?$services->resource_costs:$services->resource_costs);?>");
		var qty="<?php echo $services->bookings/$service_info['service_total_time']*$services->qty;?>";
		var price=0;
		var tot="";
		if(service_costs){	
		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+parseInt(attrb_splt[4]);	
				}	
				pre_id=attrb_splt[0];	
			 }
		 }
		tot=dollarAmount((qty*service_costs)+price);
		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="2">
		<table cellpadding="0" cellspacing="0" width="100%">
			<tr><td  align="left"><?php echo '<a href="'.tep_href_link((($HTTP_POST_VARS['resource_ids']>0)?FILENAME_SERVICE_RESOURCES:FILENAME_SERVICES_INFO),'service_id='.$HTTP_GET_VARS['service_id'] .'&action_edit=edit'.$gparam).'">'. tep_template_image_button('button_back.gif', IMAGE_BUTTON_BACK).'</a>';?></td>
			<td align="right" valign="top"><?php   echo  (($error=='')?tep_template_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE):'');?></td></tr>
		</table>
	</td>
</tr>			
<!--<input type="hidden" name="category_id" value="<?php echo $category_id;?>" />-->
</table>
<table border="0" cellspacing="3" cellpadding="2" width="25%">
	<tr>
		<td width="25%" align="right" valign="top">
			<?php include('service_board.php')?>
		</td>	
	</tr>
</table>
</form>