<?php

/**
* @version 2.7.26
* @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
*/

	$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/validate.js');
   
?>
 <?php
 $row = $this->row;
 $this->assign('row',$row);
 $config = $this->getModel('config');
 $paymentmethod = $this->getModel('paymentmethod');
 $cardtype = $this->getModel('cardtype');
 $paylater = $this->getModel('paylater');
 $currency = $this->getModel('currency');
  
 ?>
<script type="text/javascript">

DTjQuery(function(){

    DTjQuery(document.adminForm).validate({
		    rules :{
			      "data[paylater][]"	: {
					   uniquevalue : true ,
					   required :true
					  }
			},
	        success: function(label) {
				label.addClass("success");
			}

	});

 })

function submitbutton(pressbutton){
    if(pressbutton != 'cancel'){
		if(DTjQuery(document.adminForm).valid()){
		 submitform(pressbutton);
		}
	}else{
	  submitform(pressbutton);	
	}
}

</script>

<form action="index.php" method="post" name="adminForm" id="adminForm" enctype="multipart/form-data">

<table class="adminform" width="100%" cellpadding="10" cellspacing="10">
 <tr>

      <td><strong><?php echo JText::_( 'DT_PAYMENT_NAME'); ?></strong></td>

      <td> 
                      
              <input type="text" size="30" name="data[payment][name]" value="<?php echo $row->name?>" />
              <input type="hidden" size="30" name="data[payment][id]" value="<?php echo $row->id?>" />
              <input type="hidden" size="30" name="data[payment][default]" value="<?php echo $row->default; ?>" />
              
      </td>

	  <td><?php echo JHTML::tooltip((JText::_( 'DT_PAYMENT_NAME_HELP' )), '', 'tooltip.png', '', ''); ?> </td>

      <td rowspan="3"> </td>

   </tr>
    <tr align="center" valign="middle">
	
	  <td align="left" valign="top"><strong><?php echo JText::_( 'DT_CURRENCY_CODE' );?>:</strong></td>

      <td align="left" valign="top">

		<?php			

			$options=DtHtml::options($currency->getCurrency());

			if(!isset($row->config['currency_code']) || $row->config['currency_code']==""){
				$currency_code='USD';
			}else{

			   $currency_code = $row->config['currency_code'];

			}

			echo JHTML::_('select.genericlist', $options,'data[config][currency_code]','','value','text',$currency_code);

         ?>

	  </td>

      <td><?php echo JHTML::tooltip((JText::_( 'DT_CURRENCY_CODE_HELP' )), '', 'tooltip.png', '', ''); ?> </td>

    </tr>
    
    <tr align="center" valign="middle">
	
	    <td align="left" valign="top"><strong><?php echo JText::_( 'CURRENCY_SEPARATOR' );?>:</strong></td>

		<td align="left" valign="top">

                <?php

                   	$options=array();
					$options[]=JHTML::_('select.option', '0', JText::_( 'NONE' ));
					$options[]=JHTML::_('select.option', '1', JText::_( 'COMMA' )." ( , )");

					$options[]=JHTML::_('select.option', '2', JText::_( 'DOT' )." ( . )");
                    if(!isset($row->config['currency_separator']) || $row->config['currency_separator']==""){
						 $currency_separator=2;
					}else{

			             $currency_separator = $row->config['currency_separator'];

			         }
					echo JHTML::_('select.genericlist', $options, 'data[config][currency_separator]',' ', 'value','text', $currency_separator);

				?>

		</td>

		<td><?php echo JHTML::tooltip((JText::_( 'CURRENCY_SEPARATOR_HELP' )), '', 'tooltip.png', '', ''); ?> </td>

    </tr>
    
                 <tr valign="middle"><td align="left" class="dt_heading" colspan="4"><?php echo JText::_( 'DT_GENERAL_PAY_OPTIONS' ); ?></td></tr>

								 <!-- ********** General Payment Options ******************	-->
<tr align="center" valign="middle">  <td align="left" valign="top"><strong><?php echo JText::_( 'DT_PAYMENT_MODE' );?>:</strong></td>

							    <td align="left" valign="top">

							    <?php

								    $options=array();

								    $options[]=JHTML::_('select.option', 'test', JText::_( 'DT_TEST' ));

								    $options[]=JHTML::_('select.option', 'live', JText::_( 'DT_LIVE' ));

								    echo JHTML::_('select.genericlist', $options,'data[config][paymentmode]','','value','text',$row->config['paymentmode']);

							     ?>

							    </td>

								  <td><?php echo JHTML::tooltip((JText::_( 'DT_PAYMENT_MODE_HELP' )), '', 'tooltip.png', '', ''); ?> </td>
								
								<td valign="top" rowspan="3"> </td>

							  </tr>
							   <tr align="center" valign="middle">

                   <td width="210" align="left" valign="top"><strong><?php echo JText::_( 'PAYMENT_METHOD' ); ?>:</strong></td>

							     <td width="200" align="left" valign="top">

							     <!-- Here we will need to select payment methods-->
								 <table>
							     <?php
                                   
                                   //Create the selected array
                                    $options=DtHtml::options($paymentmethod->getMethods());
									 echo DtHtml::checkboxListrows('data[config][paymentmethod]',$paymentmethod->getMethods(),1,isset($row->config['paymentmethod'])?$row->config['paymentmethod']:array());

							     ?>
								</table>
							     </td>

								   <td width="40"><?php echo JHTML::tooltip((JText::_( 'DT_PAYMENT_METHOD_HELP' )), '', 'tooltip.png', '', ''); ?> </td>

							   </tr>
<tr align="center" valign="middle">  <td align="left" valign="top"><strong><?php echo JText::_( 'DT_CARD_TYPE' ); ?>:</strong></td>

							    <td align="left" valign="top">
                                <?php
								 
								 echo DtHtml::checkboxList('data[config][cardtype]',$cardtype->gettypes(),$row->config['cardtype']);
								?>
                               </td>

									<td><?php echo JHTML::tooltip((JText::_( 'DT_CARD_TYPE_HELP' )), '', 'tooltip.png', '', ''); ?> </td>

							  </tr>
 <tr align="center" valign="middle">  <td align="left" valign="top"><strong><?php echo JText::_( 'DT_CURL_SWITCH' ) ?>:</strong></td>

							   <td align="left" valign="top">

								   <?php

								   $options=array();

								   $options[]=JHTML::_('select.option', '0', JText::_( 'DT_CURL_METHOD1' ));

								   $options[]=JHTML::_('select.option', '1', JText::_( 'DT_CURL_METHOD2' ));

  					if(!isset($row->config['godaddy_hosting']) || $row->config['godaddy_hosting']==""){
						 $godaddy_hosting=0;
					}else{

			             $godaddy_hosting = $row->config['godaddy_hosting'];

			         }

								   echo JHTML::_('select.genericlist', $options,'data[config][godaddy_hosting]','','value','text',$godaddy_hosting);

								   ?>

							   </td>

								<td align="center"><?php echo JHTML::tooltip((JText::_( 'DT_CURL_SWITCH_HELP' )), '', 'tooltip.png', '', ''); ?> </td>

						</tr>
                               
        <?php echo $this->loadTemplate('offline'); ?>
                 		
		<?php echo  $this->loadTemplate('authorizenet'); ?>

        <?php echo $this->loadTemplate('paypal_pro'); ?>

        <?php echo $this->loadTemplate('paypal'); ?>
							  
        <?php echo $this->loadTemplate('saferpay'); ?>
                                 
        <?php echo $this->loadTemplate('psigate'); ?>                                  
                                 
	    <?php echo $this->loadTemplate('eway'); ?>
	
        <?php echo $this->loadTemplate('usaepay'); ?>

        <?php echo $this->loadTemplate('ideal'); ?>

        <?php echo $this->loadTemplate('idealRabo'); ?>

        <?php echo $this->loadTemplate('Sage'); ?>

        <?php echo $this->loadTemplate('NetDeposit'); ?>

        <?php echo $this->loadTemplate('worldpay'); ?>

        <?php echo $this->loadTemplate('quickbook'); ?>
                 
		<?php echo $this->loadTemplate('paylater'); ?>
        
        <?php echo $this->loadTemplate('payfast'); ?>

	 </table>
     <input type="hidden" name="option" value="com_dtregister" />
     <input type="hidden" name="controller" value="payoption" />

     <input type="hidden" id="task" name="task" value="" />
</form>
 <span style="display:none">
  <span id="newelement">
     <span>
     <input type="checkbox" class="checkboxes" name="data[config][pay_later_options][]" value="" /> 
     <input type="text" name="data[paylater][]" /><input type="hidden" name="data[paylaterIds][]" value="new" /> <a href="#" class="remove"><?php echo JText::_('DT_REMOVE'); ?></a>
     <br/>
     </span>
  </span>
</span>
<script type="text/javascript">
var display;
if(navigator.appName.indexOf("Micro") >=0){

	display = 'block';

}else{

	display = 'table-row';

}

 <?php
			    $row->config['field_options'] = (isset($row->config['field_options']))?$row->config['field_options']:array();
			   if(is_array($row->config['field_options']) && count($row->config['field_options'])){
				   ?>
				    var selection_values = <?php echo json_encode($row->config['field_options']);?>;
				   <?php
			    }elseif($row->config['field_options']!= "" && !is_array($row->config['field_options'])){
					 ?>
				    var selection_values = <?php echo json_encode(explode(",",$row->config['field_options']));?>;
				   <?php
				}else{
					?>
					var selection_values = [];
					<?php
				   	
				}
			 
			?>
			<?php
			   $row->config['paylater_field_options'] = (isset($row->config['paylater_field_options']))?$row->config['paylater_field_options']:array();
			   if(is_array($row->config['paylater_field_options']) && count($row->config['paylater_field_options'])){
				   ?>
				    var pay_later_selection_values = <?php echo json_encode($row->config['paylater_field_options']);?>;
				   <?php
			    }elseif($row->config['paylater_field_options']!= "" && !is_array($row->config['paylater_field_options'])){
					 ?>
				    var pay_later_selection_values = <?php echo json_encode(explode(",",$row->config['paylater_field_options']));?>;
				   <?php
				}else{
					?>
					var pay_later_selection_values = [];
					<?php
				   	
				}
			 
			?>
   DTjQuery(function(){
	   
	   DTjQuery("input[name='data\\[config\\]\\[paymentmethod\\]\\[\\]'] ").change(function(){
	   		
			if(this.checked) {
			   
			   DTjQuery("."+this.value).css({display:display});;
			   
			} else {
				DTjQuery("."+this.value).css({display:'none'});
			}
			
	   })
	   DTjQuery("input[name='data\\[config\\]\\[paymentmethod\\]\\[\\]']").each(function(){
	   		
			DTjQuery("."+this.value).css({display:'none'});
	   })
	   DTjQuery("input[name='data\\[config\\]\\[paymentmethod\\]\\[\\]']:checked").trigger('change');
	   DTjQuery("#addmore").click(function(){
		   DTjQuery('.container').append(DTjQuery("#newelement").html());
		   arrangeAddmoreValues();
		   return false;
	   });
		 
	   DTjQuery('.remove').live('click',function(){
		  
		    if(DTjQuery(this).prev().val() != 'new'){
				   DTjQuery(this).prev().prev().rules("remove", "uniquevalue");
				   var ajaxcontext = this;
			       DTjQuery("form input[name='"+DTjQuery(this).prev().prev().attr('name')+"']").rules("add", { 
				   remote: {
					   url:"index.php?option=com_dtregister&controller=paylater&task=validate&no_html=1&value="+DTjQuery(this).prev().val(), 
					   error:function(){
						    DTjQuery("form input[name='"+DTjQuery(ajaxcontext).prev().prev().attr('name')+"']").rules("add", { uniquevalue: true});
							arrangeAddmoreValues();
						   },
					   success: function (data){
						    if(data == 'false'){
							     
					             DTjQuery(ajaxcontext).prev().prev().rules("remove", "remote");
				                 DTjQuery("form input[name='"+DTjQuery(ajaxcontext).prev().prev().attr('name')+"']").rules("add", { uniquevalue: true});
							}else{
								alert('<?php echo addslashes(JText::_('DT_PAYLATER_REMOVED'));?>');
					            DTjQuery(ajaxcontext).prev().prev().rules("remove", "remote");
				                DTjQuery("form input[name='"+DTjQuery(ajaxcontext).prev().prev().attr('name')+"']").rules("add", { uniquevalue: true});
					            DTjQuery(ajaxcontext).parent().remove();
							}
						    arrangeAddmoreValues();
						  }
					   }});
				   DTjQuery(document.adminForm).validate().element( DTjQuery(this).prev().prev());
			  
			}else{
			   	DTjQuery(this).parent().remove();
			}
        
		   arrangeAddmoreValues();
		   
		   return false;   
	   })
	   
	     DTjQuery('#dataconfigdepend_on_field').change(function(){

				  if(DTjQuery(this).val()!=""){

				      DTjQuery('#parentoptions').load("index.php?option=<?php echo DTR_COM_COMPONENT; ?>&controller=field&task=options&field_name=data[config][field_options]&no_html=1&id="+DTjQuery(this).val(),function(){

		 	DTjQuery('#parentoptions').find('input').val(selection_values);

			selection_values = [];

		})

				  }

			   })

		DTjQuery('#dataconfigdepend_on_field').trigger('change');
		
		 DTjQuery('#dataconfigpaylater_field').change(function(){

				  if(DTjQuery(this).val()!=""){

				      DTjQuery('#paylater_parentoptions').load("index.php?option=<?php echo DTR_COM_COMPONENT; ?>&controller=field&task=options&field_name=data[config][paylater_field_options]&no_html=1&id="+DTjQuery(this).val(),function(){

		 	DTjQuery('#paylater_parentoptions').find('input').val(pay_later_selection_values);

			pay_later_selection_values = [];

		})

				  }

			   })

		DTjQuery('#dataconfigpaylater_field').trigger('change');
		   
   })
   
   function arrangeAddmoreValues(){
	   
	   DTjQuery.each(DTjQuery('.container').find(".checkboxes"),function(k,v){
		   
		   v.value = k;
		 
	  });
	      
   }
</script>
