<?php 

// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
?>
<table border="0" width="100%" cellspacing="0" cellpadding="<?php echo CELLPADDING_SUB;?>">
<?php $serverDate = date('Y-m-d H:i:s',getServerDate(false));
  $max_attendees=$cart->get_max_attendees();  
  if ($event_check['total'] < 1) {?>
	<tr>
		<td class="main"><?php new infoBox(array(array('text' => '<b>' . TEXT_EVENT_NOT_FOUND . '</b>'))); ?>
	</td>
	</tr>

	<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td></tr>

	<tr>
		<td>
			<table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
				<tr class="infoBoxContents">
					<td>
						<table border="0" width="100%" cellspacing="0" cellpadding="2">
              				<tr>
								<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
								<td align="right"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_template_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>'; ?></td>
								<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
              				</tr>
						</table>
					 </td>
          		</tr>
			</table>
		</td>
	</tr>
<?php
  } else { 
	$mode=(isset($HTTP_GET_VARS['mode'])?$HTTP_GET_VARS['mode']:'');
	$orders_id=(isset($HTTP_GET_VARS['oID'])?(int)$HTTP_GET_VARS['oID']:0);	
	$reminder_mode=false;
	$event_info_query = tep_db_query("select e.events_id, ed.events_name, ed.events_description, e.events_image, ed.events_url, e.events_date_added, e.events_date_available ,e.events_tax_class_id, e.events_fees,e.refund_percentage1," .
									"e.refund_percentage2,e.refund_percentage3,date_format('". $serverDate ."','%Y-%m-%d') as cur_date,e.events_instructor,e.display_instructor,time_format(e.events_start_time,'%h:%i %p') as events_start_time,time_format(e.events_start_time,'%H:%i') as events_stime,time_format(e.events_end_time,'%h:%i %p') as events_end_time,time_format(e.events_end_time,'%H:%i') as events_etime,e.events_location," . 
									"e.sessions_date_count,e.sessions_select_count,e.sessions_select_interval,e.events_wait_list,e.priority_question,e.waitsize_custom,e.events_conditions,e.events_forward_period,e.events_forward_length,e.session_style,events_group_bookings,events_group_min,events_group_max,link_service,service_id from " .
									 TABLE_EVENTS . " e, " . TABLE_EVENTS_DESCRIPTION . " ed where e.events_id = '" . (int)$HTTP_GET_VARS['events_id'] . "' " . EVENTS_CONDITION_STATUS . " and ed.events_id = e.events_id and ed.language_id = '" . (int)$languages_id . "'");
									 	
	$event_info = tep_db_fetch_array($event_info_query);
	
	tep_db_query("update " . TABLE_EVENTS_DESCRIPTION . " set events_viewed = events_viewed+1 where events_id = '" . (int)$HTTP_GET_VARS['events_id'] . "' and language_id = '" . (int)$languages_id . "'");
	 

	if ($mode=='remind' && $orders_id>0){
		$reminder_details=tep_get_events_reminder_fees($orders_id,$events_id,$event_info["session_style"]);
		if (sizeof($reminder_details["session_ids"])>0){
			$reminder_mode=true;
		}
	}

	$events_name = $event_info['events_name'];
	$refund_percentage1=$event_info['refund_percentage1'];
	$refund_percentage2=$event_info['refund_percentage2'];
	$refund_percentage3=$event_info['refund_percentage3'];
	$question_query=tep_db_query("SELECT e.waitsize_custom,p.question_title,p.question_description,p.answer_type from " . TABLE_EVENTS . " e, " . TABLE_POP_QUESTIONS . " p where e.events_id='" . $events_id . "' and e.priority_question=p.question_id");
	$question_result=tep_db_fetch_array($question_query);
	
	$question_result_error=sprintf(ERR_INVALID_ANSWER,$question_result["question_title"]);
	$ques_cnt=tep_db_num_rows($question_query);

	$header_text =  $events_name .'<br>' . tep_draw_separator('pixel_trans.gif', '100%', '4');

	$events_gross=tep_add_tax($event_info['events_fees'],tep_get_tax_rate($event_info['events_tax_class_id']));
// BOF: Lango Added for template MOD
if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_top(false, false, $header_text);
}
// EOF: Lango Added for template MOD
?>
<?php 
	if ($event_check['total'] >= 1)
	{
		$session_type=tep_get_session_type($HTTP_GET_VARS['events_id']);		
		$add_option='';
		if ($event_info['events_forward_period']=='Y'){
			$check_date=date('Y-m-d',tep_dateadd(time(),'day',(int)$event_info['events_forward_length']));
			$add_option=" and s.start_date<='" . $check_date . "' ";
		}
		$session_dates_sql = "select s.sessions_id,s.start_date as start_date from " . TABLE_EVENTS_SESSIONS . " s where s.events_id='" . (int)$HTTP_GET_VARS['events_id'] . "' and s.start_date>'".getServerDate()."' and s.sessions_type!='' " . $add_option . " order by s.start_date";
		$session_dates_query=tep_db_query($session_dates_sql);
		if ($session_type=='R'){
			$session_details_sql = "select	sessions_type_option,sessions_type_daily_days,sessions_type_weekly_weeks,sessions_type_weekly_days,sessions_type_monthly_days," .
													"sessions_type_monthly_months,sessions_type_monthly_weeks,sessions_type_monthly_weekdays,sessions_type_monthly_weekmonths,sessions_type_yearly_months,sessions_type_yearly_monthdays,sessions_type_yearly_weeks,sessions_type_yearly_weekdays,sessions_type_yearly_weekmonths from " . TABLE_RECURSIVE_SESSIONS . " where  events_id = '" . (int)$HTTP_GET_VARS['events_id'] . "' and (sessions_start_date>curdate() || sessions_end_date>curdate())";
			$session_details_query = tep_db_query($session_details_sql);
													
		$session_result=tep_db_fetch_array($session_details_query);
		$event_daytext=tep_get_event_daytext($session_result);
		$max_dates=(int)$event_info['sessions_date_count'];
		$select_count=(int)$event_info['sessions_select_count'];
		$select_interval=(int)$event_info['sessions_select_interval'];
	}
	$selected_session_id=(isset($HTTP_GET_VARS["sID"])?(int)$HTTP_GET_VARS["sID"]:0);
	$sessions_dates_array=array();
	$sessions_dates_array_selectmenu=array();
	$rows=0;
	while ($sessions_dates_result=tep_db_fetch_array($session_dates_query)) {
		$sessions_dates_array[] = array('id' => $sessions_dates_result['sessions_id'],
										'text' => $sessions_dates_result['start_date']);
										
		$sessions_dates_array_selectmenu[] = array('id' => $sessions_dates_result['sessions_id'],
											'text' => format_date($sessions_dates_result['start_date']));										
		$rows++;
		if ($session_type=='R'){ 
			if ($rows>=$max_dates) break;
		}
	}

	$discount_query=tep_db_query("SELECT discount_value,discount_type,discount_start_date,discount_end_date from " . TABLE_EVENTS_DISCOUNTS . " where events_id='" . $events_id . "' order by discount_start_date");
	if (tep_db_num_rows($discount_query)>0){
		$display_discount=true;
	}
	if ($session_type=='R' && $rows>0){
		$count_element=$select_interval;
		$sessions_select_array=array();
		for($icnt=1;$icnt<=$select_count;$icnt++,$count_element+=$select_interval)
			$sessions_select_array[]=array('id'=>''. $count_element,'text'=>$count_element .  TEXT_FOR . $currencies->format($count_element*$events_gross,2));
	}
	if($event_info['link_service']=='L'){
	$location_query=tep_db_query("SELECT location_name,location_details from " . TABLE_EVENTS_LOCATIONS . " where location_id='" . (int)$event_info["events_location"] . "'");
	} else if($event_info['link_service']=='S'){
		$location_query=tep_db_query("SELECT sl.service_location_name as location_name,sl.service_location_details as location_details from " . TABLE_SERVICES." s, ".TABLE_SERVICES_LOCATIONS ." sl where  s.service_location=sl.service_location_id and s.service_id='".(int)$event_info["service_id"] ."'");
	}
	if($location_query)$location=tep_db_fetch_array($location_query);
	
?>
<script language='javascript'>
var current_date_string="<?php echo $event_info['cur_date']; ?>";
var temp1=current_date_string.split("-");
var current_date=new Date(temp1[0],temp1[1]-1,temp1[2]);
var all_refund=false;
var discount_start_date=new Array();
var discount_end_date=new Array();
var discount_start_date1=new Array();
var discount_end_date1=new Array();
var discount_amount=new Array();
var baby=new Array();
var events_fees="<?php echo number_format(tep_add_tax($event_info['events_fees'],tep_get_tax_rate($event_info['events_tax_class_id'])),2);?>";
function move_cart(){
}

	function convert_date(php_string){
		var cdate;
		var temp1=php_string.split("-");
		if (temp1.length!=3) return null;
		cdate=new Date(temp1[0],temp1[1]-1,temp1[2]);
		return cdate;
	}
	function DisplayPercentage(combo){
		var days_percentage;
		var number_days;
		var format_date_string="<?php echo EVENTS_DATE_FORMAT ?>";
		if(document.getElementById('stype').value=='S') { //SS
			var select_date_string=document.getElementById('session_date_text').value;
		} else if(document.getElementById('stype').value=='R') {//SS
			var select_date_string=combo.options.item(combo.selectedIndex).text;
		}	
		if (select_date_string=='' || (format_date_string!="d-m-Y" && format_date_string!="m-d-Y" && format_date_string!="Y-m-d")) return;
		var temp2=select_date_string.split("-");
		var format_split=format_date_string.split("-");
		var lday,lmonth,lyear;
		var select_date;
		for (icnt=0;icnt<=2;icnt++){
			if (format_split[icnt]=="d") {
				lday=temp2[icnt];
				if (lday.substr(0,1)=="0") lday=lday.substr(1);
			} else if (format_split[icnt]=='m') { 
				lmonth=temp2[icnt];
				if (lmonth.substr(0,1)=="0") lmonth=lmonth.substr(1);
			} else if (format_split[icnt]=='Y') { 
				lyear=temp2[icnt];
			}
		}
		select_date=new Date(lyear,parseInt(lmonth)-1,parseInt(lday));
		number_days=dateDiff(select_date,current_date);
		var date_check=0;
		days_percentage=0;
		<?php 
			if ($display_discount==true) { 
				$icnt=0;
				while($result=tep_db_fetch_array($discount_query))
				{
		?>
					discount_start_date[<?php echo $icnt;?>]="<?php echo $result['discount_start_date']; ?>";
					discount_start_date1[<?php echo $icnt;?>]="<?php echo format_date($result['discount_start_date']); ?>";
					discount_end_date[<?php echo $icnt;?>]="<?php echo $result['discount_end_date']; ?>";
					discount_end_date1[<?php echo $icnt;?>]="<?php echo format_date($result['discount_start_date']); ?>";
					discount_amount[<?php echo $icnt;?>]="<?php echo $result['discount_type']=='P'?number_format($result['discount_value'],0) . '%':$currencies->format($result["discount_value"]);?>";
					
		<?php 
					$icnt++;
					}
			}
		?>
		<?php /*final_data+="<?php echo '<b>' . addslashes(stripslashes(TEXT_REFUND)) . '</b>' . '<br>' ;?>";
		if (number_days<=2)
			days_percentage="<?php echo (int)$refund_percentage3; ?>";
		else if (number_days<=7)
			days_percentage="<?php echo (int)$refund_percentage2; ?>";
		else if (number_days<=14)
			days_percentage="<?php echo (int)$refund_percentage1; ?>";
		else
		   date_check=1;
		if (date_check==1){
			if (all_refund==false){
			  document.getElementById("refund_text").innerHTML="<?php echo addslashes(stripslashes(TEXT_REFUND_FULL)); ?>";
			}
			all_refund=true;
		} else {
			if (all_refund==true){
				document.getElementById("refund_text").innerHTML="<?php echo addslashes(stripslashes(TEXT_REFUND_LIST)); ?>";
			}
			document.getElementById("no_days").innerHTML=number_days;
			document.getElementById("percentage").innerHTML=days_percentage;
			all_refund=false;
		}*/?>
	  <?php if ($display_discount==true) { ?>
		var amount="";
		var sdate;
		var edate;
		var icnt;
		var found;
		var ohtml="";
		var temp1;
		var temp2;
		icnt=-1;
		for (icnt=0;icnt<discount_start_date.length;icnt++){
			sdate=convert_date(discount_start_date[icnt]);
			edate=convert_date(discount_end_date[icnt]);
			if (select_date>=sdate && select_date<=edate){
				break;
			}
		}

		if (icnt>-1 && icnt<discount_start_date.length){
			
			//temp1=sdate.getDate() + '-' + (sdate.getMonth()+1) + '-' + sdate.getFullYear();
			//temp2=edate.getDate() + '-' + (edate.getMonth()+1) + '-' + edate.getFullYear();
			
			ohtml="<?php echo TEXT_INFO_DISCOUNT1;?> <b>"+discount_amount[icnt] + "</b> <?php echo TEXT_INFO_DISCOUNT2;?>"+discount_start_date1[icnt]+"<?php echo TEXT_INFO_DISCOUNT3;?>"+discount_end_date1[icnt];
			document.getElementById("discount_text").innerHTML=ohtml;
			document.getElementById("discount_text").style.visibility="visible";
		} else {
			document.getElementById("discount_text").style.visibility="hidden";
		}
	  <?php } ?>
}
function showConditions(){
	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 ;	

	handle=window.open("","conditions",feats);
	handle.document.open();
	handle.document.write('<html><head><title>Conditions</title><base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>"><link rel="stylesheet" type="text/css" href="<?php echo TEMPLATE_STYLE;?>"></head>');
	handle.document.write('<body class="conditions">');
	handle.document.write(baby[1]);
	handle.document.write('</body></html>');
	handle.document.close();
}
function DisplayEventsFees(combo){
		if(document.getElementById('stype').value=='S') {//SS
			var no_sessions=document.getElementById('session_date_text').value;
		} else if(document.getElementById('stype').value=='R') {//SS
			var no_sessions=combo.options.item(combo.selectedIndex).text;
		}	
//	var no_sessions=combo.options.item(combo.selectedIndex).value;
	var sym_left="<?php echo $currencies->currencies[$currency]['symbol_left'];?>";
	var sym_right="<?php echo $currencies->currencies[$currency]['symbol_right'];?>";
	if (no_sessions==1){
		document.getElementById("fees").innerHTML= sym_left + format2digit(events_fees) + sym_right ;
	} else {
		document.getElementById("fees").innerHTML=sym_left + format2digit(events_fees) + sym_right +  ' x ' + no_sessions + ' = ' +sym_left+format2digit((events_fees*no_sessions))+sym_right;
	}
}
function setpopup(){
	document.getElementById("agree").className="hovers-in";
	//showpopup();
}
function killpopup(){
	document.getElementById("agree").className="hovers-out";
	//kill();
}
function validateForm(){
	var error="";
	
	if (document.cart_session.agreed.checked==false){
		alert("<?php echo addslashes(TEXT_ERR_AGREED);?>");
		return false;
	}else if (document.cart_session.question_type.value!=""){
		if (document.cart_session.question_type.value=="D"){
			if (isDate(document.cart_session.question_month.value+"/"+document.cart_session.question_day.value+"/"+document.cart_session.question_year.value)==false){
				error="<?php echo addslashes(stripslashes($question_result_error));?>";
			} else {
				document.cart_session.question_value_data.value=document.cart_session.question_year.value + "-" + document.cart_session.question_month.value + "-" + document.cart_session.question_day.value;
			}
		} else if (document.cart_session.question_type.value=="T" && document.cart_session.question_value_data.value==""){
				error="<?php echo addslashes(stripslashes($question_result_error));?>";
		} else if (document.cart_session.question_type.value=="N" && isNaN(parseInt(document.cart_session.question_value_data.value))){
				error="<?php echo addslashes(stripslashes($question_result_error));?>";
		}
	}
	if(error=="" && document.cart_session.select_attendees){ 
		max_attendees="<?php echo $max_attendees;?>"; 
		sel_attendees=document.cart_session.select_attendees.value;
/*		if(max_attendees>0 && max_attendees-1!=sel_attendees)
  	       error="<?php //echo sprintf(ATTENDEE_ERROR,$max_attendees-1,$max_attendees-1);?>";
*/		if(max_attendees>0 && ((max_attendees<sel_attendees) || (max_attendees>sel_attendees)) )
  	       error="<?php echo sprintf(ATTENDEE_ERROR,$max_attendees,$max_attendees);?>";
	}
	if (error!=""){
		alert(error);
		return false;
	}
	if (document.cart_session.select_attendees){
	//	document.cart_session.no_attendees.value=parseInt(document.cart_session.select_attendees.value)+1;
		document.cart_session.no_attendees.value=parseInt(document.cart_session.select_attendees.value)
	}
	return true;
}


function isDate(dateStr) {

  var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
  var matchArray = dateStr.match(datePat); // is format OK?

  if (matchArray == null) {
    return false;
  }

  // parse date into variables
  month = matchArray[1];
  day = matchArray[3];
  year = matchArray[5];

  if (month < 1 || month > 12) { // check month range
    return false;
  }

  if (day < 1 || day > 31) {
    return false;
  }

  if ((month==4 || month==6 || month==9 || month==11) && day==31) {
    return false;
  }

  if (month == 2) { // check for february 29th
    var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
    if (day > 29 || (day==29 && !isleap)) {
      return false;
    }
  }
  return true;  // date is valid
}

function dateDiff(date1,date2) {
diff  = new Date();

diff.setTime(Math.abs(date1.getTime() - date2.getTime()));

timediff = diff.getTime();

days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
return days;
}
function dateAdd(indt, days, sign) {
	var d = new Date(indt);
	var dv = d.valueOf();
	var ndv;
	if (sign == "+")
		ndv = dv + (days*(1000*60*60*24));
	else
		ndv = dv - (days*(1000*60*60*24));
	var nd = new Date(ndv);
	return (nd.getDate() + "-" + (nd.getMonth()+1) + "-" + nd.getFullYear());
}
function format2digit(s)
		{
			s=s +'';					
			if(s != null &&  !isNaN(s)) 
			{
				var len = s.length;
				var decfound = false;
				var i;
				for (i = 0; i < len ; i++)
				{
					var c = s.charAt(i);
					if (c == '.')  decfound = true;
					if (decfound==true) 
					{
						if (i == (len-3)) break; //if 0.00
						if (i == (len-2)) {s=s+'0';  break;} //if 0.0
						s = s.substring(0, i + 3 ) ;  break; //if 0.000000
					}
				}
				if (decfound==false) s=s +'.00';
				return s;
			}
			else 
			{
				return '0.00';
			}
		}

</script>
<?php   } 
 if ($reminder_mode==true) { ?>
	<tr>
		<td class="main"><?php echo TEXT_INFO_PAY_REMINDER; ?></td>
	</tr>
<?php } 
?>
	<tr>
	<td class="main">
		<table width='100%' border="0" cellspacing="0" cellpadding="2" align="left">
			<tr class='eventListing-data'>
				<td colspan="2">
					<table border="0" cellspacing="0" cellpadding="0" width="100%">
						<tr>
							<td valign="top" align="left" width="<?php echo SMALL_IMAGE_WIDTH;?>"><?php echo ($event_info['events_image']==''?'':tep_image(DIR_WS_IMAGES . $event_info['events_image'] , $event_info['events_image'],SMALL_IMAGE_WIDTH,'')); ?></td>
							<td class="smalltext" width='80%' valign=top><?php if($event_info['events_description']!='')echo '<b>' . TEXT_EVENTS_DESCRIPTION . '</b><br>' . tep_draw_separator('pixel_trans.gif', '100%', '3') . $event_info['events_description']; ?>	
						</tr>
						<tr>
						  <td>&nbsp;</td>
						  <td>
						    <table border="0" cellspacing="0" cellpadding="2" valign="top" width="100%">
								<?php if ($rows>0) {?>
									<tr>
									  <td>
										<table border="0" cellspacing="0" cellpadding="2" valign="top">
											<tr><td>
												<table border=1 class=formArea width=100% style='display:none' id=popup_contents>
												<tr><td class="main" height="70" valign="top">
												   <?php 
														echo '<b>' . TEXT_EVENT_NAME . '</b><br>' . $event_info['events_name'] . '<p>';
														if ($event_info['events_conditions']!='')
													   		echo '<b>' . TEXT_CONDITIONS . '</b><br>' . $event_info['events_conditions'] .  '<p>';
													 	echo '<b>' . TEXT_REFUND . '</b>' . '<br><span id=refund_text>' . TEXT_REFUND_LIST . '</span>'; ?>
											   </table>
										   </td></tr>			
								    	 </table>
								      </td>
								  </tr>
	  							<?php } ?>	
	  							<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td></tr>
								<tr class='eventListing-data' valign=top >
								     
								    <?php
										if ($reminder_mode==true) { 
											echo '<td><b>' . TEXT_REMINDER_FEE . '</b><br>' . tep_draw_separator('pixel_trans.gif','100%','3') .'<b>' . $currencies->format($reminder_details['amount']) . "</b><td>";
							
								   		} else {
												echo '<td><b>' . TEXT_AMOUNT  . ': </b>' . tep_draw_separator('pixel_trans.gif', '3', '3') ;
												if($session_type=='R' || ($session_type=='S' && sizeof($sessions_dates_array)>1))
													echo '<br><span id=fees>' . sprintf(TEXT_NORMAL_PRICE,'<b>'.$currencies->format($events_gross,2).'</b>') . '</span> ' . '<span id=discount_text style="visibility:hidden" class="main" valign="top"></span>';
												else {
													echo $currencies->format($events_gross);
													$discount_query=tep_db_query("SELECT discount_value,discount_type,discount_start_date,discount_end_date from " . TABLE_EVENTS_DISCOUNTS . " where events_id='" . $events_id . "' and date_format(discount_start_date,'%Y-%m-%d')<='" . $sessions_dates_array[0]['text'] . "' and date_format(discount_end_date,'%Y-%m-%d')>='" . $sessions_dates_array[0]['text']. "' order by discount_start_date");
													if (tep_db_num_rows($discount_query)>0) { 
														$result=tep_db_fetch_array($discount_query);
														echo  '<br><b>' .TEXT_INFO_DISCOUNT1 . '</b>' . ($result['discount_type']=='P'?number_format($result['discount_value'],0) . '%':$currencies->format($result["discount_value"])) ;
													}	
												}	
										}
									?><td>
									 	<?php echo '<b>' . TEXT_LOCATION . '</b><br>' . tep_draw_separator('pixel_trans.gif', '100%', '3') .  $location['location_name'].'<br>'.substr($location["location_details"],0,100); ?>
									</td>
							     	</tr>
								    <tr><td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '5'); ?></td></tr>
							
								    <tr class='eventListing-data'>
										
										<?php 											
											if ($reminder_mode==false) {
												echo tep_draw_form('cart_session' , tep_href_link(FILENAME_CHECKOUT_EVENT, tep_get_all_get_params(array('action','mode','oID'))),'post','onSubmit="return validateForm()"'); 												
												if ($rows>0) {//SS
													if($session_type=='S' && sizeof($sessions_dates_array)==1) {
														echo '<td><b>' . TEXT_EVENT_DATE . '</b>' . tep_draw_separator('pixel_trans.gif', '3', '3') . format_date($sessions_dates_array[0]['text']);
														echo '<input type=hidden name="products_id" value="' . $sessions_dates_array[0]['id'] . '" id="products_id">' .'<input type=hidden name="session_date_text" value="' .format_date($sessions_dates_array[0]['text']) . '" id="session_date_text">';
														echo '<input type=hidden name="stype" value="S" id="stype">';
													}	else {//SS
														echo '<td><b>' . TEXT_START_DATE . '</b><br>' . tep_draw_separator('pixel_trans.gif', '100%', '3') . tep_draw_pull_down_menu('products_id', $sessions_dates_array_selectmenu,$selected_session_id,'onChange="DisplayPercentage(this)"');
														echo '<input type=hidden name="stype" value="R" id="stype">';
													}
													echo '<input type=hidden name="type" value="' . $session_type .'" id="type">';
													if($session_type=='R' || $session_type=='S' && sizeof($sessions_dates_array)>1)
													echo '<script language=javascript>DisplayPercentage(document.cart_session.products_id);</script>';
												}else{
													echo '<td><b>' . TEXT_NO_SESSIONS . '</b>'; 
												}
											} else {
												echo tep_draw_form('cart_session' , tep_href_link(FILENAME_CHECKOUT_EVENT, tep_get_all_get_params(array('action','mode','oID')) . "event_action=buy_product&element_type=E"),'post');					 
											}
											echo "<td>";
											if($event_info['display_instructor']=='Y')
												echo '<b>' . TEXT_INSTRUCTOR . '</b><br>' . tep_draw_separator('pixel_trans.gif', '100%', '3') . tep_get_instructor_name($event_info['events_instructor']);
										?>
									</tr>
							
								    <tr><td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td></tr>
								    <tr class='eventListing-data'>
										<?php 
											$dis_time_format="";
											$eve_stime=$event_info['events_start_time'];
											$eve_etime=$event_info['events_end_time'];
											if(defined('TIME_FORMAT')) $dis_time_format=TIME_FORMAT;
											if($dis_time_format!="") {
												if($dis_time_format=='24') {
													$eve_stime=$event_info['events_stime'];
													$eve_etime=$event_info['events_etime'];
												}
											}
											if ($reminder_mode==false){
												// group bookings start
													if($event_info["events_group_bookings"]=='Y' && $event_info["events_group_min"]<=$event_info["events_group_max"]){
														$group_array=array();
														if($event_info["events_group_min"]!=1 && $event_info["events_group_min"]>0) 	$group_array[]=array('id'=>1,'text'=>1);
														for ($i=$event_info["events_group_min"];$i<=$event_info["events_group_max"];$i++){
															$group_array[]=array('id'=>$i,'text'=>($i==0)?'Nil':$i);
														}													     
														 echo '<td><b>'.TEXT_NO_ATTENDEES.'</b><br>' .  tep_draw_separator('pixel_trans.gif', '100%', '3') . tep_draw_pull_down_menu('select_attendees',$group_array,'','id="select_attendees"');
													 } 
													 echo '<input type=hidden name=no_attendees value="1">';
												// group bookings end
												echo '<td><b>' . TEXT_TIME . '</b><br>';
												echo tep_draw_separator('pixel_trans.gif', '100%', '3') . (($event_daytext!='' && $rows>0)?$event_daytext . '<br>':'') . $eve_stime . '-' . $eve_etime;
												if ($session_type=='R' && $rows>0) {
													if($event_info["events_group_bookings"]=='Y' && $event_info["events_group_min"]<=$event_info["events_group_max"]) echo '<tr class=eventListing-data>';
													echo '<td colspan="2" valign="top"><b>' . TEXT_COUNT_SESSIONS . '</b><br>' . tep_draw_separator('pixel_trans.gif', '100%', '3') . tep_draw_pull_down_menu('products_qty', $sessions_select_array);
												} else {
													echo '<td>' . tep_draw_hidden_field('products_qty','1');
												}
												echo "</tr>";
											} else {
												echo '<td><b>' . TEXT_SESSION_DATES . '</b><br><br>';
												for ($icnt=0;$icnt<sizeof($reminder_details["session_ids"]);$icnt++){
													if ($icnt>0) echo ", ";
													echo date(EVENTS_DATE_FORMAT,strtotime($reminder_details["session_dates"][$icnt]));
													echo '<input type=hidden name="session_select_' . $reminder_details["session_ids"][$icnt] . '" value="1">';
													echo '<input type=hidden name="session_id[]" value="' . $reminder_details["session_ids"][$icnt] . '">';
													echo '<input type=hidden name="session_type[]" value="U">';
													echo '<input type=hidden name="session_group[]" value="">';
													echo '<input type=hidden name="session_date[]" value="' . $reminder_details["session_dates"][$icnt] . '">';
												}
											}
										?>
							     	    </tr>
										<?php if ($rows>0 && $reminder_mode==false) {?>							    
											<tr><td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td></tr>										
											<tr class='eventListing-data'>
												<td colspan="2"><?php echo tep_draw_checkbox_field('agreed','1',false) . TEXT_AGREEMENT . '<b><a id="agree" href="javascript:showConditions();" class="infoBoxHeadingPage">' . TEXT_TERMS . '</a></b>';?></td>
											</tr>
											
											<tr>
												<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
											</tr>
											
											<?php 
												echo tep_draw_hidden_field('question_type',$question_result['answer_type']);
												if ($ques_cnt>0 && $question_result['waitsize_custom']>0) { ?>
													<tr class='eventListing-data'>
														<td><?php echo $question_result['question_title'];?>
													</tr>
													<tr><td colspan=2>
														<table border="0" width=100% cellspacing="2" cellpadding="2" align=left class=formArea>
															<tr><td class=main width=50%><?php echo $question_result['question_description']; ?>
															<td class=main width=50%><?php echo tep_get_question_input($question_result['answer_type']); ?>
															</tr>
														</table></td>
													</tr>
													
													<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td></tr>
											<?php 
												} else { 
													tep_draw_hidden_field('question_type','');
												}
											}
											if ($rows>0 || $reminder_mode==true) {
												if ($reminder_mode==true){
													echo '<input type=hidden name="old_orders_id" value="' . $orders_id . '">';
													echo '<input type=hidden name="events_id" value="' . $events_id . '">';
												}
											?>
											 <tr>
												<td colspan="2" align="left"><?php echo tep_template_image_submit('button_reserve.gif', IMAGE_BUTTON_RESERVE,'border="0"');?>
											 </tr>
								    		<?php } ?>	    
						    </table>
						  </td>
						</tr>
					</table>
				</td>
			</tr>	
	    </table>
        </td>
      </tr>
<?php
// BOF: Lango Added for template MOD
if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_bottom();
}
// EOF: Lango Added for template MOD
?>
<?php } ?>
</table>
</form>

<?php 
   function tep_get_event_daytext($session_result)
   {
     $type=$session_result['sessions_type_option'];
     $result_text='';
     //$days_array=array('1'=>'Sunday','2'=>'Monday','3'=>'Tuesday','4'=>'Wednesday','5'=>'Thursday','6'=>'Friday','7'=>'Saturday');
     $days_array=array('1'=>'Monday','2'=>'Tuesday','3'=>'Wednesday','4'=>'Thursday','5'=>'Friday','6'=>'Saturday','7'=>'Sunday');
     $count_array=array('1'=>'first','2'=>'second','3'=>'third','4'=>'fourth');
     $months_array=array('1'=>'January','2'=>'February','3'=>'March','4'=>'April','5'=>'May','6'=>'June','7'=>'July','8'=>'August','9'=>'September','10'=>'October','11'=>'November','12'=>'December');
     switch($type)
     {
        case 'DD':
	  if ($session_result['sessions_type_daily_days']<=1){
	    $result_text=TEXT_DAILY_DAY;}
	  else
	    $result_text=sprintf(TEXT_DAILY_DAYS,$session_result['sessions_type_daily_days']);
	  break;
        case 'WW':
	  $temp_string=$session_result['sessions_type_weekly_days'];
	  $day_string="";
	  for ($icnt=0;$icnt<strlen($temp_string);$icnt++){
	     if (substr($temp_string,$icnt,1)=='1'){
	       if ($day_string!='') $day_string=$day_string . ", ";
	       $day_string=$day_string . $days_array[$icnt+1];
	     }
	  }
	  if ($session_result['sessions_type_weekly_weeks']<=1)
	    $result_text=sprintf(TEXT_WEEKLY_WEEK,$day_string);
	  else
	    $result_text=sprintf(TEXT_WEEKLY_WEEKS,$session_result['sessions_type_weekly_weeks'],$day_string);
	  break;
	case 'MD':
	  if ($session_result['sessions_type_monthly_months']>1)
 	    $result_text=sprintf(TEXT_MONTHLY_DAYS,$session_result['sessions_type_monthly_months'],$session_result['sessions_type_monthly_days']);
          else
	    $result_text=sprintf(TEXT_MONTHLY_DAY,$session_result['sessions_type_monthly_days']);
	  break;
        case 'MM':
	  if ($session_result['sessions_type_monthly_weekmonths']>1)
	      $result_text=sprintf(TEXT_MONTHLY_WEEKS,$session_result['sessions_type_monthly_weekmonths'],$count_array[$session_result['sessions_type_monthly_weeks']],$days_array[$session_result['sessions_type_monthly_weekdays']]);
          else
	      $result_text=sprintf(TEXT_MONTHLY_WEEK,$count_array[$session_result['sessions_type_monthly_weeks']],$days_array[$session_result['sessions_type_monthly_weekdays']]);	  
	  break;
        case 'YM':
	  $result_text=sprintf(TEXT_YEARLY_MONTHS,$months_array[$session_result['sessions_type_yearly_months']],$session_result['sessions_type_yearly_monthdays']);
	  break;
        case 'YY':
	  $result_text=sprintf(TEXT_YEARLY_WEEKS,$count_array[$session_result['sessions_type_yearly_weeks']],$days_array[$session_result['sessions_type_yearly_weekdays']],$months_array[$session_result['sessions_type_yearly_weekmonths']]);
	  break;
     }
     return $result_text;   
   }
   ?>
  <script>
  		var final_data="<table height='90%' border=0 width=100% align=center><tr><td class=main height=70 valign=top>";
		
		final_data+="<?php echo '<b>' . addslashes(stripslashes(TEXT_EVENT_NAME)) . '</b><br>' . str_replace(chr(13). chr(10),"<br>",tep_output_string($event_info['events_name'])) . '<p>'; ?>";
		<?php if ($event_info['events_conditions']!=''){ ;?>
			 final_data+="<?php echo '<b>' . addslashes(stripslashes(TEXT_CONDITIONS)) . '</b><br>' . str_replace(array(chr(13). chr(10),"\n",chr(10),chr(13)),"<br>",tep_output_string($event_info['events_conditions'])) .  '<p>';?>";
		<?php } ?>
		final_data+='</table><table width="100%"><tr><td align="right" class="main"><a href="javascript:window.close();">[ close ]</a></td></tr></table>';
		if (document.getElementById("popup_contents")){
			if (document.getElementById("popup_contents").innerHTML!="")
				baby[1]=final_data;
		}else
			baby[1]="";

  </script> 