<?php

/**
* @version 2.8.16
* @package Joomla 2.5
* @subpackage DT Register
* @copyright Copyright (C) 2006 DTH Development
* @copyright contact dthdev@dthdevelopment.com
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/

global $Itemid,$full_message,$xhtml_url,$group_size_warning;

include(DTreg::get_template_path('event'.DS.'tmpl'.DS.'event_header.php'));
?>
<div style="clear:both">
  <?php
     $tEvent = $this->tEvent;
	  $waiting = $tEvent->waiting_list;
     $registered = $tEvent->getTotalregistered($tEvent->slabId);
     $message = ($registered >= $tEvent->max_registrations && $tEvent->max_registrations !=0 &&$tEvent->max_registrations!="")?$full_message:$this->tEvent->topmsg;
	  
	 echo ($message!="")?$message."":'';
	 
  ?>
</div>
<div id="price_header" style="clear:both">
<?php
//include(JPATH_SITE.DS.'components'.DS.'com_dtregister'.DS.'views'.DS.'event'.DS.'tmpl'.DS.'price_header.php');

 $action = JRoute::_("index.php?option=com_dtregister&controller=event&Itemid=".$Itemid,false);
?>
</div>
<form name="frmcart" method="post" action="<?php echo $action ?>" enctype="multipart/form-data">

 <div id="dtgroup_member" style="clear:both; margin:5px 0 0 0">

 <strong><?php echo JText::_( 'DT_MEMBER' ) . ' ' .($this->memberIndex). ' ' . JText::_( 'DT_INFORMATION' ); //$currentMember; ?></strong>

 </div>

 <?php
       if($tEvent->use_discountcode && in_array($tEvent->discount_code_usagetype,array(1,3)) ) { ?>
	   		   
        <dl>
         <dt class="dtlabel">
           <?php echo JText::_( 'DT_DISCOUNT_CODE'); ?>:
         </dt>
         <dd class="dtfield">
           <input type="text" name="discount_code" id="discount_code" value="" class="inputbox" /><label for="discount_code" style="display:none" generated="true" class="error"></label>
         </dd>
         <dd class="dttip"> </dd>
      </dl>
            
	   <?php }
       echo $this->form;

	 ?>

  <div style="clear:both; padding: 5px 0 0 0">
 <?php

$tEvent->registered = $tEvent->getTotalregistered($tEvent->slabId);

$show_add_member_button = true;

if(intval($tEvent->max_registrations) > 0) {
	if(($tEvent->registered + $this->memtot) >= $tEvent->max_registrations) {
		$show_add_member_button = false;
	}
}

if((DT_SESSION::get('Setting.Member.Index')=== false && DT_SESSION::get('Setting.Member.Add') === false) || (DT_SESSION::get('Setting.Member.Index') !== false && $this->memberIndex == $this->memtot)) {
 ?>    
    <input type="button" class="button" onclick="window.location='<?php echo $this->back; ?>'" value="<?php echo JText::_('DT_BACK'); ?>" id="back" name="billingInfo"/>
   <?php if($this->memberIndex != 1 && $tEvent->min_group_size < $this->memtot || $waiting ) {?>
    <input type="button" value="<?php echo JText::_( 'DT_CANCEL_MEMBER' );?>" onclick="window.location='<?php echo JRoute::_('index.php?option=com_dtregister&controller=event&task=member_cancel&Itemid='.$Itemid); ?>'" class="button"  id="cancel" />
    <?php } ?>
   <?php if(($tEvent->max_group_size > $this->memtot || $tEvent->max_group_size == 0 || $tEvent->max_group_size == "") && $show_add_member_button || $waiting ) {?>
    <input type="submit" value="<?php echo JText::_( 'DT_ADD_MEMBER' );?>" class="button" id="next" />
    <?php } ?>
 <?php
}
 ?>
  <?php
  if($tEvent->min_group_size == 0 || $tEvent->min_group_size == "") {
     $minimum_size = $this->memtot;
  } else {
    $minimum_size = $tEvent->min_group_size;
  } 
  ?>
    <?php if((DT_SESSION::get('Setting.Member.Index') !== false && ($this->memtot >= $minimum_size)) || (DT_SESSION::get('Setting.Member.Index')=== false && $this->memtot >= $minimum_size ) || $waiting) { ?>
    <input type="submit" value="<?php echo JText::_( 'DT_COMPLETE_GROUP' );?>" class="button" id="billing" />
    <?php } ?>

  </div>
<?php
//echo "<pre>";
//print_r($tEvent->max_registrations);
//print_r($group_size_warning);
$spots = $tEvent->max_registrations - $tEvent->registered - $this->memtot; 
//print_r($spots);
if(intval($tEvent->max_registrations) > 0 && $group_size_warning) {
	
	if( $spots <= $group_size_warning || $group_size_warning == 1 ) {
	if($spots < 0) { $spots = 0;}
       ?>
        <div class="dt_groupwarning">
          <?php echo JText::sprintf('DT_GROUPSIZE_WARNING',$spots); ?>
        </div>
       <?php
	}
}
?>
  <input type="hidden" name="option" value="com_dtregister" />

  <input type="hidden" name="controller" value="event" />

  <input type="hidden" name="task" value="memberdata" />
  
  <input type="hidden" name="member_data" value="member_data" />
  
  <input type="hidden" id ="flow" name="flow" value="memberdata" />
  <input type="hidden" name="Index" value="<?php echo ($this->memberIndex -1);?>" />

  <input type="hidden" name="Itemid" value="<?php echo $Itemid;?>" />

</form>
<script type="text/javascript">

 var updateFee = function(){
	   
	   var options = {
		               url : "<?php echo JRoute::_("index.php?no_html=1");?>",
					   data : {task:'price_header'},
					   
					   success : function(responseText){
						             DTjQuery("#price_header").html(responseText);
					              }
		   }
	   
	   DTjQuery(document.frmcart).ajaxSubmit(options);
	   
  }
   function update_discountcode_fields() {
  	  var element_class = "";
	  if(DTjQuery("#discount_code").size()){
	  DTjQuery.each(DTjQuery(".discountcode_show"),function(k,v){
	  		 element_class = "code_"+DTjQuery("#discount_code").val();
			if( DTjQuery(v).hasClass(element_class) ){
				DTjQuery(v).show();
			} else {
				DTjQuery(v).hide();
			}
			
	  })
	  }
	  
  }
  
 update_discountcode_fields();
  
  updateFee();
    DTjQuery.validator.messages.required = " ";
    DTjQuery.validator.messages.remote = " ";
    DTjQuery(document.frmcart).validate({
	        success: function(label) {
				label.addClass("success");
			}

	});
	DTjQuery(function(){
    	
		 DTjQuery('#next').live('click',function(){
		 
		 if(DTjQuery(document.frmcart).valid()){
		   DTjQuery.each(DTjQuery(".discountcode_show"),function(k,v){
				  
				  if( DTjQuery(v).is(':visible') ){
					 
				  } else {
					  DTjQuery(v).remove();
				  }
				  
			})
		   DTjQuery('select').removeAttr('disabled');
		   DTjQuery('input').removeAttr('disabled');
		   DTjQuery('textarea').removeAttr('disabled');
		   DTjQuery("#flow").val('memberdata');
		   
		 }
	  });
	  
	      DTjQuery('#billing').live('click',function(){
		 
		 if(DTjQuery(document.frmcart).valid()){
		   DTjQuery.each(DTjQuery(".discountcode_show"),function(k,v){
				  
				  if( DTjQuery(v).is(':visible') ){
					 
				  } else {
					  DTjQuery(v).remove();
				  }
				  
			})
		   DTjQuery('select').removeAttr('disabled');
		   DTjQuery('input').removeAttr('disabled');
		   DTjQuery('textarea').removeAttr('disabled');
		   DTjQuery("#flow").val('billinginfo');
		 }
	  });	
		
	})
  <?php  if($tEvent->use_discountcode && in_array($tEvent->discount_code_usagetype,array(1,3)) ) { ?>
	 DTjQuery('#discount_code').rules('add',
	  {
		  remote:{ 
		     url :"<?php echo JRoute::_('index.php?option=com_dtregister&controller=validate&task=discountcode&no_html=1&type=M',$xhtml_url); ?>"
		  },
		  required : <?php echo ($this->tEvent->use_discountcode==2)?'true':'false'?>
		  
      });
	<?php } ?>
</script>