<?php

/**
* @version 2.8.11
* @package Joomla 1.7/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;
//include(JPATH_SITE.DS.'components'.DS.'com_dtregister'.DS.'views'.DS.'user'.DS.'tmpl'.DS.'event_header.php');
include(DTreg::get_template_path('user'.DS.'tmpl'.DS.'event_header.php'));
?>
<div id="price_header">
<?php
	// pr($this->partial_payment_enable);
 
?>
</div>
<?php
  
  if(DT_Session::get('Setting.process') === 'change'){
  	 if($this->feeObj->changefee > 0){
	     $paying_amount = $this->feeObj->changefee - $this->feeObj->paid_amount + ($this->feeObj->fee - $this->feeObj->changefee);
	 }else{
	     $paying_amount = 0;
	 }
	
  }elseif(DT_Session::get('Setting.process') === 'cancel'){
     $paying_amount = $this->feeObj->cancelfee - $this->feeObj->paid_amount;
  }else{
	 $paying_amount = $this->feeObj->fee - $this->feeObj->paid_amount;
  }
  
  ?>
<form name="frmcart" method="post" action = "index.php?option=com_dtregister&Itemid=<?php echo $Itemid ?>" enctype="multipart/form-data">

   <div id="dtregform">

     <?php

       echo $this->viewFields;

	   echo $this->viewMemFields;
	   
	   if($this->partial_payment_enable && $paying_amount > 0){
	    
	 ?>

     <dl>
     	<dt class="dtlabel">
         <?php echo JText::_('DT_PARTIAL_PAYMENT');?>:
     	</dt>
     	<dd class="dtfield">
        <input type="radio" class="partial_payment" name="partial_payment" value="partial" />
        <input type="text" id="partial_payment_amount" name="partial_payment_amount" size="10" value="" disabled="disabled" /> &nbsp;(<?php echo JText::_('DT_DONT_ENTER_CURRENCY');?>)
     	</dd>
     </dl>
     
     <dl>
     	<dt class="dtlabel">
         <?php echo JText::_('DT_DUE_PAYMENT');?>:
     	</dt>
     	<dd class="dtfield">
         <input type="radio" class="partial_payment" name="partial_payment" value="full" checked="checked" />
        <input type="hidden" name ="paying_amount" value="<?php echo $paying_amount; ?>" /> &nbsp;<?php echo   DTreg::displayRate($paying_amount,$currency_code); ?>
     	</dd>
     </dl>
     <?php
	   }else{
		 
		 ?>
           <input type="hidden" name ="paying_amount" value="<?php echo $paying_amount; ?>" /> 
         <?php	
			   
	   }
	 ?>
     
     <div id="dtnav_buttons" style="clear:both">

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

       &nbsp;

       <input type="button" class="button" name="confirm" 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="user" />

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

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

</form>
<?php
if(DT_Session::get('Setting.process') != 'duepayment'){

?>
<script type="text/javascript">
   DTjQuery(function(){
   DTjQuery("#price_header").load("<?php echo JRoute::_("index.php?option=com_dtregister&controller=user&task=price_header&no_html=1&dttmpl=confirm_price_header",$xhtml_url);?>");
  })

</script>
<?php
}
?>
<script type="text/javascript">
  DTjQuery(function(){
	 DTjQuery.validator.messages.required = " ";
  	 DTjQuery(document.frmcart).validate({

	        success: function(label) {

				label.addClass("success");

			}

	});
	 DTjQuery('input[name="partial_payment"]').change(function(){
	 	
		 if(this.checked) {
		 	if(this.value == "full") {
				DTjQuery("#partial_payment_amount").val('');
				DTjQuery("#partial_payment_amount").attr('disabled','disabled');
				DTjQuery("#partial_payment_amount").rules('remove','required');
			} else {
				DTjQuery("#partial_payment_amount").removeAttr('disabled');
				DTjQuery("#partial_payment_amount").rules('add','required');
				
			}
		 }
	 })
     DTjQuery('#next').removeAttr('disabled');
	 DTjQuery('#next').live('click',function(){
		 if(DTjQuery(document.frmcart).valid()){
		
		   DTjQuery(this).attr('disabled','disabled');
		   <?php
if(!(DT_Session::get('Setting.process') == 'duepayment' || DT_Session::get('Setting.process') =='cancel')){
?>
		   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){
				    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&controller=user&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&controller=user&Itemid=$Itemid",$xhtml_url);?>";
				   }
				}
			  });		
		<?php } else { ?>		
		     document.frmcart.submit();
		<?php } ?>
	     }
		
	  });
	 DTjQuery(".partial_payment").trigger('change');

  });
</script>