<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: 			*/
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004-2010 ARMIA INC                                    |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts VistaCart                     |
// +----------------------------------------------------------------------+
// | Authors: Jipson<jipson.thomas@armiasystems.com>             		  |
?>
<?php
   	echo $html->css('ui.datepicker.css');
	echo $javascript->link('jquery.js');		
	echo $javascript->link('alphanumeric.js'); 
	echo $javascript->link('ui.datepicker.js'); 
?>
<script>
	//Code for the project	
	$(document).ready(function()	
	{	
	$('#CouponFrom').datepick({minDate: '' , maxDate:'', 
	dateFormat: 'mm-dd-yy',closeAtTop: false, showStatus: true,  showOn: 'both', buttonImageOnly: true,
	 buttonImage: '<?php echo $cnfg["sitebasefolder"]."/img/calendar.gif";?>' });	
	 
	 $('#CouponTo').datepick({minDate: '' , maxDate:'', 
	dateFormat: 'mm-dd-yy',closeAtTop: false, showStatus: true,  showOn: 'both', buttonImageOnly: true,
	 buttonImage: '<?php echo $cnfg["sitebasefolder"]."/img/calendar.gif";?>' });	
	 
	});
</script>
<script language="javascript" type="text/javascript">
function chk(){
	    var i=0;
		var fcs_fld=new Array();
	    var errorstr = '';
	    var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";	

		if($.trim($('#CouponType').val())=='Perc')   
                {
                                        var discnt=$.trim($('#CouponGiftvalue').val());  
                                if(parseFloat(discnt) >= 100) 
                                        { errorstr += "- Discount percentage should be smaller than 100.\n"; fcs_fld[i]='CouponGiftvalue'; i++; }
                }		
		if ($.trim($('#CouponCode').val()) == '') { errorstr += "- Please Enter Coupon Code.\n";  fcs_fld[i]='CouponCode'; i++;}
		if ($.trim($('#CouponGiftvalue').val()) == '') { errorstr += "- Please Enter Gift Value.\n";  fcs_fld[i]='CouponGiftvalue'; i++;}
		if ($.trim($('#CouponFrom').val()) == '') { errorstr += "- Please Enter Start Date.\n";  fcs_fld[i]='CouponFrom'; i++;}
		if ($.trim($('#CouponTo').val()) == '') { errorstr += "- Please Enter End Date.\n";  fcs_fld[i]='CouponTo'; i++;}
		
		var sel_frmdate=$.trim($('#CouponFrom').val());
		var sel_todate=$.trim($('#CouponTo').val());
		var split_frmdate=sel_frmdate.split('-');
		var split_todate=sel_todate.split('-');		
		var final_frmdate=split_frmdate[2]+'-'+split_frmdate[0]+'-'+split_frmdate[1];
		var final_todate=split_todate[2]+'-'+split_todate[0]+'-'+split_todate[1];		
		final_frmdate=new Date(final_frmdate);
		final_todate=new Date(final_todate);
		
		if(final_todate < final_frmdate)
		{		
		  errorstr += "- End date should be greater than start date.\n";  fcs_fld[i]='CouponTo'; i++;
		}
		 if($.trim($('#CouponType').val())=='Amt')   
                {
                    
                     var discnt=$.trim($('#CouponGiftvalue').val()); 
                     var min_amount =$.trim($('#CouponMinamt').val());  
		        if(parseFloat(discnt) >= min_amount) 
			{ errorstr += "- Discount Amount should be smaller than Minimum Applicable Amount \n"; fcs_fld[i]='CouponGiftvalue'; i++; }
                
                }			
		
		if ($.trim($('#CouponMinamt').val())== '') { errorstr += "- Please Enter Minimum Applicable Amount.\n"; fcs_fld[i]='CouponMinamt'; i++;}	
		
	
	if (errorstr != '')
	{
		msgstr = msgstr + errorstr;
		alert(msgstr);
		$('#'+fcs_fld[0]+'').focus();$('#'+fcs_fld[0]+'').select();
		return false;
	}
	else
	{
		return true;
	}
} 
</script>
<div align="center" class="subheading">
              <div align="left">PROMOCODES</div>
            </div>
            <br />
<?php if($session->check('Message.flash')) { ?><div id="okbox"><font color="#446423"><?php $session->flash(); ?></font></div><?php } ?>
			
            <div align="left" id="item_details_admin">
              <!--items display area start -->
              <div align="center" id="items_display_area_admin">
                <div align="left" class="inner_content_area_admin">
				
				
                  <!--form area start -->
				<?php  echo $form->create('Coupon', array('name' =>'Coupon'));?>
                  <div id="admin_heading">Edit Promocode </div>
				  
						  <div id="grid_admin">
							<div align="left" id="inner_leftcontent">
							  <p class="maintext_inner">Coupon Code  <span class="required_field">*</span></p>
							</div>
							<div align="right" id="inner_rightcontent">
								<span class="toplinks">
								<?php if(isset($coupon["Coupon"]["code"]) && $coupon["Coupon"]["code"] <> " "){
								 echo $form->input('code', array('label' => ' ','class'=>'box2_admin','size'=>27, 'value' => $coupon["Coupon"]["code"])); 
								 }else{
								  echo $form->input('code', array('label' => ' ','class'=>'box2_admin','size'=>27));  }?>
								</span>							
							</div>
							<div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
						  </div>
						  
						  
						    <div id="grid_admin">
							<div align="left" id="inner_leftcontent">
							  <p class="maintext_inner">Discount type</p>
							</div>
							<div align="right" id="inner_rightcontent">
								<span class="toplinks">
									<?php echo $form->input('type', array('options' => array("Perc" => "Percentage","Amt" => "Amount"),'label' => ' ','class'=>'box2_admin','selected' => $coupon["Coupon"]["type"])); ?>
								</span>							
							</div>
							<div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
						  </div>
						  
						  
						    <div id="grid_admin">
							<div align="left" id="inner_leftcontent">
							  <p class="maintext_inner">Gift Value<span class="required_field">*</span></p>
							</div>
							<div align="right" id="inner_rightcontent">
								<span class="toplinks">
									<?php if(isset($coupon["Coupon"]["giftvalue"]) && $coupon["Coupon"]["giftvalue"] <> " "){
									 echo $form->input('giftvalue', array('label' => ' ','class'=>'box2_admin','size'=>27, 'value' => $coupon["Coupon"]["giftvalue"])); 
                                     }else{ echo $form->input('giftvalue', array('label' => ' ','class'=>'box2_admin','size'=>27));  }?>
								</span>							
							</div>
							<div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
						  </div>
						  
						  
						    <div id="grid_admin">
							<div align="left" id="inner_leftcontent">
							  <p class="maintext_inner">Start Date<span class="required_field">*</span></p>
							</div>
							<div align="right" id="inner_rightcontent">
								<span class="toplinks">
									<?php 
									$edit_fdate=array();									
									$edit_fdate=explode('-',$coupon["Coupon"]["from_date"]);				
									$fdate=$edit_fdate[1].'-'.$edit_fdate[2].'-'.$edit_fdate[0];					
									echo $form->input('From', array('size' => '10','label' => '','readonly' =>TRUE,'value' => $fdate));?>
								</span>							
							</div>
							<div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
						  </div>
						  
						      <div id="grid_admin">
							<div align="left" id="inner_leftcontent">
							  <p class="maintext_inner">End Date<span class="required_field">*</span></p>
							</div>
							<div align="right" id="inner_rightcontent">
								<span class="toplinks">
									<?php
									$edit_tdate=array();									
									$edit_tdate=explode('-',$coupon["Coupon"]["to_date"]);				
									$tdate=$edit_tdate[1].'-'.$edit_tdate[2].'-'.$edit_tdate[0];	
									 echo $form->input('To', array('size' => '10','label' => '','readonly' =>TRUE,'value' => $tdate));?>
								</span>							
							</div>
							<div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
						  </div>
						  
						  
						    <div id="grid_admin">
							<div align="left" id="inner_leftcontent">
							  <p class="maintext_inner">Minimum applicable amount ( <?php echo $curlogo; ?> )<span class="required_field">*</span></p>
							</div>
							<div align="right" id="inner_rightcontent">
								<span class="toplinks">
									<?php if(isset($coupon["Coupon"]["minamt"]) && $coupon["Coupon"]["minamt"] <> " "){
									 echo $form->input('minamt', array('label' => ' ','class'=>'box2_admin','size'=>27, 'value' => $coupon["Coupon"]["minamt"]));  }else{
									   echo $form->input('minamt', array('label' => ' ','class'=>'box2_admin','size'=>27)); }?>
								</span>							
							</div>
							<div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
						  </div>
						  
						  
						  
						    <div id="grid_admin">

							<div align="left" id="inner_leftcontent">
							  <p class="maintext_inner">Description</p>
							</div>
							<div align="right" id="inner_rightcontent">
								<span class="toplinks">
									<?php if(isset($coupon["Coupon"]["descr"]) && $coupon["Coupon"]["descr"] <> " "){
									 echo $form->input('descr', array('label' => ' ','class'=>'box2_admin','size'=>27, 'value' => $coupon["Coupon"]["descr"])); 
									  }else{  echo $form->input('descr', array('rows' => '5','label' => '','class'=>'box2_admin','size'=>27)); }?>
								</span>							
							</div>

							<div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
						  </div>
				  
				  
				
                   
							<div id="admin_bottom">
								<div align="left" id="inner_leftcontent">
								  <p class="maintext_inner">&nbsp;</p>
								</div>
								<div align="right" id="inner_rightcontent">
									<span class="toplinks">								
									<input type="submit" value="Update" class="buttn_admin"   onClick="return chk();">
									<input type="button" value="Cancel" class="buttn_admin"  onClick="javascript:history.go(-1);">
									</span>
								</div>
								<div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
								
				 <?php echo $form->end(); ?> 
                  <!--form area end -->			  
				  
                </div>
                <!--form area end -->
              </div>
              <div align="left" class="float_clear1"></div>
            </div>
            <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
            <br /> <br /> 
			<!-- End of Add Area -->
	<script>
	$('#CouponGiftvalue').numeric({allow:"."});	
	$('#CouponMinamt').numeric({allow:"."});	
	</script>