<?php

/**
* @version 2.8.11
* @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,$xhtml_url,$full_message;
include(DTreg::get_template_path('event'.DS.'tmpl'.DS.'event_header.php'));
?>

<div>

  <?php
     
      $tEvent = $this->tEvent;
	
      $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>
<?php
 if(isset($this->member_list) && count(($this->member_list))) {
	  		echo $this->loadTemplate('members');
	  }
?>
<div style="clear:both">
<?php 
 if(isset($this->pageTile)){
 	echo $this->pageTile;
 }
?>
</div>

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

     <?php
       
       echo $this->userFields($this->tEvent->usercreation);
	   
	 ?>
	
	 <?php if($this->tEvent->use_discountcode  && in_array($tEvent->discount_code_usagetype,array(2,3)) || ($this->tEvent->use_discountcode && DT_Session::get('Setting.User.type')=='I' )){?>
       <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 } ?>

     <?php

	   echo $this->form;
	   echo $this->capthaField();
	   echo $this->termsField($this->eventId);
	   echo $this->mailchimpRegister();

	 ?>
     
     <div id="dtnav_buttons" style="clear:both">
     <?php
     if((DTreg::check_com_menu_ItemId($Itemid) == "" || $tEvent->registration_type == 'both') && isset($this->member_list)  ) {
	 ?>
         <input type="button" class="button" onclick="window.location='<?php echo $this->back; ?>'" value="<?php echo JText::_('DT_BACK'); ?>" id="back" name="billingInfo"/>
         <?php
	 }
		 ?>
       <input type="submit" name="confirm" class="button" id="next" value="<?php echo JText::_( 'DT_NEXT_BUTTON' ); ?>" />
     </div>
   </div>
   
   <input type="hidden" name="option" value="com_dtregister" />
   <input type="hidden" name="controller" value="event" />
   <input type="hidden" name="Itemid" value="<?php echo $Itemid; ?>" />
   <input type="hidden" name="task" value="<?php echo $this->task; ?>" />
   <input type="hidden" name="Index" value="<?php echo $this->Index; ?>" />
   
</form>
<div id="debug">
</div>
<script type="text/javascript">
 
 var updateFee = function(){
	    
	   var prevtask = DTjQuery(document.frmcart.task).val();
	   var options = {
		               url : "<?php echo JRoute::_("index.php?test=1&no_html=1&dttmpl=price_header&controller=event",$xhtml_url);?>",
					   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().toLowerCase();
			if( DTjQuery(v).hasClass(element_class) ){
				DTjQuery(v).show();
			} else {
				DTjQuery(v).hide();
			}
			
	  })
	  }
	  
  }
  
  updateFee();
 update_discountcode_fields();
 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.validator.messages.required = " ";
    DTjQuery.validator.messages.remote = " ";
    DTjQuery(document.frmcart).validate({
	        success: function(label) {
				label.addClass("success");
			}

	});
	<?php if($this->tEvent->use_discountcode){?>
	 DTjQuery('#discount_code').rules('add',
	  {
		  remote: {url :"<?php echo JRoute::_('index.php?option=com_dtregister&controller=validate&task=discountcode&no_html=1',$xhtml_url); ?>"} ,
		  required : <?php echo ($this->tEvent->use_discountcode==2)?'true':'false'?>
		  
      });
	<?php } ?>
	
 })

</script>