<?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,$xhtml_url,$currency_code,$partial_payment_group_reg;

include(DTreg::get_template_path('event'.DS.'tmpl'.DS.'event_header.php'));
?>
<div id="dtform_message" style="clear:both">
<?php echo JText::_('DT_CONFIRM_PAGE_HELP'); ?>
</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" action="<?php echo $action ?>" method="post" enctype="multipart/form-data">

   <div id="dtregform" style="clear:both">

      <?php

	    $temp = $this->currentfee;

        if($this->event->partial_payment ==1 && $temp > 0){

			?>

           <?php
                 	if($this->event->partial_minimum_amount!="" && $this->event->partial_minimum_amount > 0 ){
					   $minimum_amount = $this->event->partial_minimum_amount;
					}else{
					    $minimum_amount = $this->event->partial_amount;
					}
				 ?>

			<dl>
			   <dt class="dtlabel"><?php echo JText::_( 'DT_DEPOSIT_AMOUNT'); ?>:</dt>
               
               <dd class="dtfield"><input type="text" name="paying_amount" id="paying_amount" size="10" value="<?php echo $minimum_amount; ?>" />

              ( <?php echo JText::_( 'DT_MINIMUM_DEPOSIT'); ?> = 

                <?php echo DTreg::displayRate($this->event->partial_minimum_amount,$currency_code); ?> 
                <?php
                if($partial_payment_group_reg == "eachmember") {
					echo JText::_( 'DT_PER_MEMBER');
                }
				?>
               )

                  <label for="paying_amount" generated="true" class="error" style="display:none"></label>
			  
                <script type="text/javascript">
                    DTjQuery(function(){
				         
				         DTjQuery(document.frmcart).validate();
						 DTjQuery.validator.messages.required = " ";
						 DTjQuery.validator.messages.min = " ";
						 DTjQuery("#paying_amount").rules("add", {
													   min: <?php echo $minimum_amount; ?>
													  });

					});

				 </script>
                
                </dd>

            </dl>

            <?php

            }else if($this->event->partial_payment == 2 && $temp > 0){

			 ?>

            <dl>

             <dt class="dtlabel"> </dt>

               <dd class="dtfield">
                 <?php
                 	if($this->event->partial_minimum_amount!="" && $this->event->partial_minimum_amount > 0 ){
					   $minimum_amount = $this->event->partial_minimum_amount;
					}else{
					    $minimum_amount = $this->event->partial_amount;
					}
				 ?>
                 <input type="" readonly="readonly" value="<?php echo $minimum_amount; ?>" size="10" name="paying_amount" />

                  ( <?php echo JText::_( 'DT_DEPOSIT_AMOUNT'); ?> = 

              <?php echo DTreg::displayRate($this->event->partial_amount,$currency_code); ?> 
               
                  <?php
                if($partial_payment_group_reg == "eachmember") {
					echo JText::_( 'DT_PER_MEMBER');
                }
				?>
               
               )

               </dd>

             </dl>

             <?php

			}else{

			  ?>

              <input type="hidden" name ="paying_amount" value="<?php echo $this->paying_amount; ?>" />

              <?php	

		    }

		?>

     <?php

       echo $this->viewFields;

	   echo $this->viewUserField();

	   echo $this->viewMemFields;

	 ?>

     <div id="dtnav_buttons" style="clear:both">

       <input type="button" id="backbutton" class="button" onclick="window.location='<?php echo $this->back; ?>'" value="<?php echo JText::_('DT_BACK'); ?>" name="billingInfo"/>	

       &nbsp;

       <input type="button" name="confirm" class="button" id="next" value="<?php echo JText::_( 'DT_NEXT_BUTTON' ); ?>" />

     </div>

   </div>

   <input type="hidden" name="step" value="confirm" />

   <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="Index" value="<?php echo $this->Index; ?>" />

   <input type="hidden" name="task" value="confirm" />

</form>
<script type="text/javascript">
  DTjQuery(function(){
	 // DTjQuery('#backbutton').click(function(){
	  		
			DTjQuery('#backbutton').removeAttr('disabled');
			DTjQuery('#next').removeAttr('disabled');
			//console.log('test');
			
	 // })
	  
	  DTjQuery("#price_header").load("<?php echo JRoute::_("index.php?option=com_dtregister&controller=event&task=price_header&no_html=1&dttmpl=confirm_price_header",$xhtml_url);?>");
	  DTjQuery('#next').live('click',function(){
		 if(DTjQuery(document.frmcart).valid()) {
		 	DTjQuery(this).attr('disabled','disabled');
		 	DTjQuery.ajax({
			  url: "<?php echo JRoute::_("index.php?option=com_dtregister&controller=event&task=check_waiting&no_html=1",$xhtml_url);?>",
			  dataType: 'html',
			  success: function(data){
				  data = DTjQuery.trim(data);
				 if(data == 'regular') {
				 	document.frmcart.submit();
				 } else if(data == "waiting"){
				 	var result = confirm("<?php echo JText::_("DT_WAITING_CONTINUE")?>");
					if(result) {
						document.frmcart.submit();
					} else {
						window.location = "<?php echo JRoute::_("index.php?option=com_dtregister&Itemid=$Itemid",$xhtml_url);?>";
					}
				 } else if(data == 'full') {
				 	 alert("<?php echo JText::_("DT_EVENT_FULL")?>");
					 window.location = "<?php echo JRoute::_("index.php?option=com_dtregister&Itemid=$Itemid",$xhtml_url);?>";
				 }
			  }
			});	
		 }
		 
	  });
  })
</script>