<?php

/**
* @version 2.7.14
* @package Joomla 1.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
*/

  jimport('joomla.html.pane');

 // $pane =& JPane::getInstance('tabs');

  $document	=& JFactory::getDocument();

  $document->addScript( JURI::root(true).'/components/com_dtregister/assets/js/dt_jquery.js');
  $document->addScript( JURI::root(true).'/components/com_dtregister/assets/js/addmore.js');
  $document->addScript( JURI::root(true).'/components/com_dtregister/assets/js/mousewheel.js');
  $document->addScript( JURI::root(true).'/components/com_dtregister/assets/js/timeEntry.js');
  
  $document->addStyleSheet(JURI::root(true).'/components/com_dtregister/assets/css/south-street/jquery-ui.css');

  $copy_event_field  = "";
  if(isset($this->copy)){
	
	$copy_event_field = '<input type="hidden" name="copy_event" value="'.$this->copy.'" /> ';
    unset($this->row->slabId);
    
    $this->row->slabId = "";

 }
  $timeformatArray = array(1=>'false','2'=>'true');
?>
<script type="text/javascript">
    DTjQuery(function(){
	  DTjQuery(".timeEntry").timeEntry({show24Hours:true,spinnerImage:'<?php echo JUri::root()."components/com_dtregister/assets/images/timeEntry/spinnerOrange.png" ?>',spinnerBigImage:'<?php echo JUri::root()."components/com_dtregister/assets/images/timeEntry/spinnerOrangeBig.png" ?>'});
	  
	   DTjQuery('#dataeventtimeformat').change(function(){
		   var format = DTjQuery(this).val();
		   
		   var readonly = DTjQuery("*[readonly]");
		   
		   DTjQuery.each(readonly,function(k,v){
			  DTjQuery(v).removeAttr('readonly');
		   });
		  
		   DTjQuery(".timeEntry").timeEntry();
		   if(format == 2){
			   
		       DTjQuery(".timeEntry").timeEntry('change','show24Hours',true);
		   }else{
			   DTjQuery(".timeEntry").timeEntry('change','show24Hours',false); 
			   DTjQuery(".timeEntry").timeEntry('change','ampmPrefix',' ');  
		   }
		    DTjQuery.each(readonly,function(k,v){
			  DTjQuery(v).attr('readonly',true);
		   });
		   
		   
	  });
	  DTjQuery('#dataeventtimeformat').trigger('change');
	})
</script>
<div>
<h3>
  <?php 
  
  echo (isset($this->row->slabId)&& $this->row->slabId !="")?$this->row->displayTitle().' ':''; ?>
</h3>
</div>
 <form name="adminForm" id="newDiscountCode" method="post" action="index2.php" enctype="multipart/form-data">

   <table>

     <tr><td width="100%">
     
     <div id="tabs">
        <ul>
          <li>
            <a href="#general">
            <?php echo JText::_( 'DT_REGISTER_GENERAL' ); ?></a></li>
           
            <li>
            <a href="#discountfee">
            <?php echo JText::_( 'DT_DISCOUNT_FEE' ); ?></a></li>
            
            <li>
            <a href="#message">
            <?php echo JText::_( 'DT_REGISTER_EMAIL' ); ?></a></li>
            
            <li>
            <a href="#emailtab">
            <?php echo JText::_( 'DT_EMAILS' ); ?></a></li>
            
            <li>
            <a href="#field">
            <?php echo JText::_( 'DT_REGISTER_FIELDS' ); ?></a></li>
            
            <li>
            <a href="#userpanel">
            <?php echo JText::_( 'DT_USER_PANEL' ); ?></a></li>
                            
        
        </ul>
        <div id="general">
          <?php echo $this->loadTemplate('tab.general'); ?>
        </div>
        <div id="discountfee">
          <?php echo $this->loadTemplate('tab.discountfee'); ?>
        </div>
        <div id="message">
          <?php echo $this->loadTemplate('tab.message'); ?>
        </div>
         <div id="emailtab">
          <?php echo $this->loadTemplate('tab.email'); ?>
        </div>
        <div id="field">
          <?php echo $this->loadTemplate('tab.field'); ?>
        </div>
        <div id="userpanel">
          <?php echo $this->loadTemplate('tab.userpanel'); ?>
        </div>
     </div>
     
    </td></tr>
   </table>
    <?php echo $copy_event_field; ?>
    <input type="hidden" name="option" value="<?php echo DTR_COM_COMPONENT;?>" />

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

    <input type="hidden" name="data[event][slabId]" value="<?php echo $this->row->slabId; ?>" />

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

 </form>

 <script type="text/javascript">

 DTjQuery(function(){
    var event_tabs =  DTjQuery("#tabs").tabs();
    DTjQuery('#dataeventeventId').change(function(){

	   DTjQuery.ajax({

	      url:'index.php?option=com_dtregister&controller=event&format=raw&task=getjevent&eventId='+DTjQuery(this).val(),

		   dataType :'json',

		   success :function(response){

			 DTjQuery("#summary").val(response.summary);

			 var startdate = new Date(response.dtstart*1000);

			 var enddate   = new Date(response.dtend*1000);

			 DTjQuery("#dtstart").val(response.dtstart_date);

			 DTjQuery("#dtstarttime").val(response.dtstart_time);

			 DTjQuery("#dtend").val(response.dtend_date);

			 DTjQuery("#dtendtime").val(response.dtend_time);
             DTjQuery(".jeventdisable").attr('disabled','true');
			 if(typeof(response.reprules) != 'undefined'){

			    // data[event][repeatType]

				DTjQuery("input[name='data\\[event\\]\\[repeatType\\]\\[\\]'] ").val(response.reprules.repeatType);
				               DTjQuery("input[name='data\\[event\\]\\[repeatType\\]'][value='"+response.reprules.repeatType+"']").attr('checked',true).trigger('change');

				DTjQuery("#rpinterval").val(response.reprules.rpinterval);

				DTjQuery("#rpcount").val(response.reprules.rpcount);

				DTjQuery("#rpuntil").val(response.reprules.rpuntil);

				var func = 'set'+response.reprules.repeatType;

				dispatch(func,[response.reprules]);

			 }
             DTjQuery('#dataeventtimeformat').trigger('change');
		  }
          
	   });

	});

 });

function setdaily(rules){

}

function setmonthly(rules){

	DTjQuery("#monthdays").val(rules.monthdays);

	//data[event][monthweekdays][]

	DTjQuery.each(rules.monthweekdays,function(k,v){

		DTjQuery("input[name='data\\[event\\]\\[monthweekdays\\]\\[\\]'][value='"+v+"']").attr('checked',true);

	});

	DTjQuery.each(rules.monthweeks,function(k,v){

		DTjQuery("input[name='data\\[event\\]\\[monthweeks\\]\\[\\]'][value='"+v+"']").attr('checked',true);

	});	

}

function setweekly(rules){

	DTjQuery.each(rules.weekdays,function(k,v){	

		DTjQuery("input[name='data\\[event\\]\\[weekdays\\]\\[\\]'][value='"+v+"']").attr('checked',true);

	});

}

function setyearly(rules){

	DTjQuery("#yeardays").val(rules.yeardays);

}

</script>