<?php 
/*
	osCommRes, Services Oline 
	http://www.oscommres.com 
	Copyright (c) 2005 osCommRes 
	
	Freeway eCommerce 
	http://www.zac-ware.com/freeway 
	Copyright (c) 2007 ZacWare
	
	Released under the GNU General Public License
*/


// Set flag that this is a parent file
	define( '_FEXEC', 1 );
	
	   $dis_time_format="";
	   if(defined('TIME_FORMAT')) 
	   $dis_time_format=TIME_FORMAT;	   
	   $service_start_date=$services->start_date;	   
	   $service_end_date=$services->end_date;
	   $service_start_time=$services->start_time;	
	   $service_end_time=$services->end_time;	   
	   $qty=$services->qty;
	   $products_costs=0;	
	   $time_booking=tep_time_diff($service_start_date.' ' .$service_start_time,$service_end_date.' ' . $service_end_time);	   
       $booking_total=sprintf(TEXT_HOURS,$time_booking['hours']);
       $booking=$time_booking['hours'];
	   if($service_info['booking_type']=='D'){
		$booking=$time_booking['days'];	
		$booking_total=sprintf(TEXT_DAYS,$time_booking['days']);
	   }
	   $products_price=$service_info['service_costs'];
	   $products_tax=tep_get_tax_rate($service_info['service_tax_class_id']);
	   if($service_info['include_resource_price']=='N') $products_costs=tep_add_tax($products_price,$products_tax);
	   if($services->resource_id && $service_info['include_resource']=='Y' && $service_info['include_resource_price']=='Y'){
		$products_tax=tep_get_tax_rate(tep_get_resource('resource_tax_class_id',(int)$services->resource_id,(int)$languages_id));
		$products_price=tep_get_resource('resource_costs',(int)$services->resource_id,(int)$languages_id);
		$products_costs=tep_add_tax($products_price,$products_tax);	
	  }
	  $time_diff=1;
	  if($booking && $service_info['service_total_time']) $time_diff=($booking/$service_info['service_total_time']); 
	  $service_quantity=$qty * $time_diff;		  
	  if($service_info['include_resource_price']=='N' || $services->resource_id){
	  	    $time_diff=1;
	  	    if($services->bookings && $service_info['service_total_time']) $time_diff=$services->bookings/$service_info['service_total_time'];
	  	    $price=$time_diff*$products_costs;
	  	    $service=$services_info;	  	    
			$loading_price_dates=get_loading_array($service_id);
			$loading_price=round(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;
			$loading_price=tep_add_tax($loading_price,tep_get_tax_rate($services->tax_class_id));
			$service_display_price=$currencies->format($loading_price + $price);
	 }
	?>
<table width="100%" align="right" style="border-left:solid 1px #666666; border-bottom:solid 1px #666666;border-top:solid 1px #666666;border-right:solid 1px #666666"  cellspacing="0" cellpadding="0" border="0">
	<tr height="25"class="headerCalendar">
		<td class="availability" align="center"><?php echo TEXT_BOARD; ?></td>
	</tr>
	<tr><td valign="top" class="tab_strip">
		<table cellpadding="3" cellspacing="0" width="100%" border="0" >
	<?php
	if($service_start_date && $service_start_time){ ?>
	<tr style="height:15">
		<td class="main" align="left" nowrap="nowrap">
			<?php echo TEXT_START_DATE?>
		</td>
		<td class="main" align="left" nowrap="nowrap" id="div_start_date">
			<?php echo (($error)?'<font color="red">'. format_date($service_start_date) . '</font>':format_date($service_start_date));?>
		</td>
	</tr>
	<tr style="height:15" class="service_dataTableRowSelected">
		<td class="main" align="left" nowrap="nowrap">
			<?php echo TEXT_START_TIME;?>
		</td>
		<td class="main"  nowrap="nowrap" align="left" id="div_start_time">
			<?php		
			if($service_start_time) {
				$s_time=date("h:i A",@strtotime($service_start_time));
				if($dis_time_format!="" && $dis_time_format=='24') 
					$s_time=date("H:i",@strtotime($service_start_time));				
			}	
			echo (($error)?'<font color="red">'. $s_time.'</font>':$s_time);?>
		</td>
	</tr>
	<?php }
	   if($service_end_date && $service_end_time){
			$str_time=@strtotime($service_end_date .' '.$service_end_time)+60;
			$service_end_date=date('Y-m-d',$str_time);
			$service_end_time=date('H:i:s',$str_time);
	   }
	 if($service_end_date && $service_end_time){	 
	 ?>
	<tr   style="height:15" >
		<td class="main" align="left" nowrap="nowrap">
			<?php echo TEXT_END_DATE?>
		</td>
		<td class="main" nowrap="nowrap" align="left" id="div_end_date">
			<?php echo (($error)?'<font color="red">'. format_date($service_end_date).'</font>':format_date($service_end_date));?>
		</td>
	</tr>
	<tr style="height:15" class="service_dataTableRowSelected">
		<td class="main" align="left" nowrap="nowrap">
			<?php echo TEXT_END_TIME;?>
		</td>
		<td class="main" nowrap="nowrap" align="left" id="div_end_time">
			<?php
			if($service_end_time) {
				$e_time=date("h:i A",@strtotime($service_end_time));
				if($dis_time_format!="" && $dis_time_format=='24') 
					$e_time=date("H:i",@strtotime($service_end_time));				
			}	
			echo (($error)?'<font color="red">' . $e_time.'</font>':$e_time);?>
		</td>
	</tr>
	<?php }
	$icnt=0;
	
	if($services->resource_id && $error=="" && basename($PHP_SELF)=='services_attributes.php'){ 
	$icnt=1;
	?>
		<tr style="height:15">
			<td class="main"align="left" valign="top"  >
				<?php echo TEXT_RESOURCE ;?>
			</td>	
			<td class="main" align="left">
				<?php echo tep_get_resource('resource_name',(int)$services->resource_id,(int)$languages_id);?>
			</td>	
		</tr>
	<?php } 
	if($error==""){ 
		if($icnt=="1")
			$class='class="service_dataTableRowSelected"';
		else
			$class='';	
	?>
	<tr style="height:15" <?php echo $class; ?>>
		<td class="main" align="left">
			<?php echo (($service_display_price)?TEXT_PRICE:'<div id="txt_price" style="display:none">'.TEXT_PRICE.'</div>');?>
		</td>
		<td class="main" align="left" colspan="2">
			<?php echo '<div id="no_resource">' . $service_display_price  . '</div>';?>
		</td>
	</tr>
	<?php } ?>
	</table>
</td></tr>	
</table>
	<?php
$tax_class_array = array(array('id' => '0', 'text' => TEXT_NONE));
$tax_class_query = tep_db_query("SELECT tax_class_id, tax_class_title from " . TABLE_TAX_CLASS . " order by tax_class_title");
	while ($tax_class = tep_db_fetch_array($tax_class_query)) {
		  $tax_class_array[] = array('id' => $tax_class['tax_class_id'],
							 'text' => $tax_class['tax_class_title']);
	}?>
<script language="javascript">
	var tax_rates = new Array();
		<?php 
			for ($i=0, $n=sizeof($tax_class_array); $i<$n; $i++) {
			  if ($tax_class_array[$i]['id'] > 0) {
				echo 'tax_rates["' . $tax_class_array[$i]['id'] . '"] = ' . tep_get_tax_rate($tax_class_array[$i]['id']) . ';' . "\n";
			  }
		}
	?>
	function doRound(x, places) {
	  	return Math.round(x * Math.pow(10, places)) / Math.pow(10, places);
	} 
	
	function getTaxRate(parameterVal) {
	  if ( (parameterVal > 0) && (tax_rates[parameterVal] > 0) ) {
		return tax_rates[parameterVal];
	  } else {
		return 0;
	  }
	}
 
	function updateGross(grossValue,taxRate,total) {
	  var qty="<?php echo $service_quantity;?>";
	   if (taxRate > 0) {
		grossValue = grossValue * ((taxRate / 100) + 1);
	  }
	ret_value=doRound(grossValue, 4);
	if(total){ 
		ret_value=dollarAmount(qty*ret_value);
	}
	return ret_value;
	}
	function dollarAmount(Num) {
		var sym_left="<?php echo $currencies->currencies[$currency]['symbol_left'];?>";
		var sym_right="<?php echo $currencies->currencies[$currency]['symbol_right'];?>";
		
		if (typeof(Num)=="number") {
			Num=doRound(Num,2);
			Num=""+Num;
		} else {
			Num=""+doRound(parseFloat(Num),2);
		}
		
		dec = Num.indexOf(".");
		end = ((dec > -1) ? "" + Num.substring(dec,Num.length) : ".00");
		Num = "" + parseInt(Num);
	
		var temp1 = "";
		var temp2 = "";
		
		if (end.length == 2) end += "0";
		if (end.length == 1) end += "00";
		if (end == "") end += ".00";
	
		var count = 0;
		for (var k = Num.length-1; k >= 0; k--) {
		var oneChar = Num.charAt(k);
		if (count == 3 && oneChar!="-") {
		temp1 += ",";
		temp1 += oneChar;
		count = 1;
		continue;
		}
		else {
		temp1 += oneChar;
		count ++;
		   }
		}
		for (var k = temp1.length-1; k >= 0; k--) {
		var oneChar = temp1.charAt(k);
		temp2 += oneChar;
		}
		temp2 = sym_left + temp2 + end + sym_right;
		return temp2;
	} 
</script>