<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{$language.lblAdmin} : {$language.lblSettings} : {$language.lblPaymentDiscounts} : {$language.lblEditShippingMethod}</title>
<link rel="stylesheet" type="text/css" href="{$view_styles}/popup.css" media="screen" />
<script type="text/javascript" src="{$common_js}/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="{$common_js}/jquery-migrate-1.4.1.js"></script>
<link rel="stylesheet" type="text/css" href="{$view_styles}/choosen.css" />
{form->basepath_script}
{form->rootpath_script}
</head>
<body>
{form->start name="formShippingMethod" method="post" action=""}
<div class="popup-block">
  <div class="form_listing clearfix">
    <div id="common_message" style="width:auto;"></div>
    <div class="clearfix"></div>
    <ul><li class="clearfix">
			<div class="inner-left fixing_left"><strong>{$language.lblShippingMethod}</strong></div>
			<div class="inner-right fixing_right"> 
				<div class="select-box">{if $smGroupID>0 &&  $smServiceID>0}
				{form->hidden name="action" value=0}
				{form->select name="sm_main_custom" tabindex="1" options=$resSmServices value=$smGroupID disabled="disabled"}
				{form->hidden name="sm_main" value=$smGroupID}				
				{else}
				{form->hidden name="action" value=1}
					{form->select name="sm_main" tabindex="1" options=$resSmServices value=$smGroupID validate="required" error=$language.lblErrorShippingMethod}
				{/if}
				</div>
			</div>
		</li>
		<li class="clearfix">
			<div class="inner-left fixing_left"><strong>{$language.lblShippingServiceType}</strong></div>
			<div class="inner-right fixing_right"> 
				<div class="select-box">
				  {if $smGroupID>0 &&  $smServiceID>0}
				  {form->select name="realtime_sm_services_custom" id="realtime_sm_services" tabindex="2" class="width_55" disabled="disabled"}
				  {form->hidden name="realtime_sm_services" id="realtime_sm_services_hid" value=$smServiceID}
				  {form->hidden name="realtime_sm_service_type" value=$smServiceTypeID}
				  {else}
					{form->select name="realtime_sm_services" id="realtime_sm_services" tabindex="2" class="width_55" validate="required" error=$language.lblErrorService}
				  {/if}
				</select>
				</div>
			</div>
      </li>			  
      <li id="shipping_service_li" class="rmv-padding">	  
      </li>	  
<li id="defaultBlock" class="rmv-padding" style="display: none">
  {include file='ShippingServiceDelZones.tpl'}  
 <li class="clearfix">
        <div class="submit-block clearfix textto_center"><span>&nbsp; </span>
         {form->submit name="submitSms" id="submitSms" class="curve-3" value="{$language.lblUpdate}"}
         {$language.lblOr}
         {html->anchor onclick="parent.$.colorbox.close();" id="cancel" caption="{$language.lblCancel}"}
        </div>
       </li>
    </ul>
  </div>
</div>
{form->close}  
{include file='CommonJavaScriptBottom.tpl'}
{form->validate_script form="formShippingMethod"}
<script type="text/javascript" src="{$common_js}/validate.plugin.js"></script>
<script type="text/javascript" src="{$view_javascript}/custom-radiobutton.js"></script>
<script type="text/javascript">
var editImageTitle = "{$language.lbleditImageTitle}";
var lblAlertOk = '{$language.lblAlertOk}';
var lblAlertCancel = '{$language.lblAlertCancel}';
var lblAlertYes = '{$language.lblAlertYes}';
var lblAlertNo = '{$language.lblAlertNo}';
var lblAlert = '{$language.lblAlert}';
$(function(){
	$('#perioddiv input').customInput('');
});
$(document).ready(function () {
	var onloadMainSmID = $("#sm_main").val();
	if(onloadMainSmID >0)
		fetchServices(onloadMainSmID);
		
	var onloadRealtimeServiceID = '{$smServiceID}';	//$("#realtime_sm_service_type").val();
	var onloadRealtimeServicetypeID = $("#realtime_sm_service_type").val();
	if(onloadRealtimeServiceID >0)
		fetchSettings(onloadRealtimeServiceID,onloadRealtimeServicetypeID);		
});
$("#sm_main").change(function(){
	var mainSmID = $(this).val();
	fetchServices(mainSmID);
	$('#realtime_sm_services').removeAttr('disabled');
});
$("#realtime_sm_services").change(function(){
	var realtimeServiceID = $(this).val();	
	fetchSettings(realtimeServiceID,realtimeServiceID);
});
$(document).on("click",'#isDefault',function()
{	
	if ($("#isDefault").is(':checked'))
	  $('#enableDefault').val('checked');
	else
	 $('#enableDefault').val('');
 });
$("#submitSms").click(function () {
	 if((($('li.search-choice').length)==0) && ($("#isDefault").is(':checked')))        
        $('#div_err__deliveryZoneID').removeClass('hide');
	else
	$('#div_err__deliveryZoneID').addClass('hide');		
    })
    
fetchServices = function (smID){
  var serviceId='{$smServiceID}';  
  var serviceTypeID='{$smServiceTypeID}';  
	$('#shipping_service_li').html('');
	var urlAppend = ('{$smServiceID}') ? "s_id/"+'{$smServiceID}'+"/t_id/"+'{$smServiceTypeID}' : '';
	$.ajax({
    	type: "GET",
        url: GLOBAL_BASE_PATH+"/shippingmethod/ajaxGetServices/group_id/"+smID+"/"+urlAppend,
		async: true,
		global: false,
        success: function(servicesHtml){
        	$('#realtime_sm_services').html('<option value="">{$language.lblSelect}</option>'+servicesHtml);
		if(serviceId=='')
		{
		
		  var serviceType =$('#realtime_sm_services').val();		    
		  if (serviceType=='free_custom' || serviceType=='flat_custom')
		  {
		  $('#realtime_sm_services').attr('disabled',true);	    
		   fetchSettings(0,serviceType);
		  }
		}
		
		}
		
	});
}

fetchSettings = function (realtimeServiceID,serviceType,actionType) {
  var actionType=$('#action').val();
  var urlAppend = (serviceType) ? "s_type/"+serviceType+"/" : '';
  var action=(actionType) ? "ac_type/"+actionType+"/" : '';
	$.ajax({
    	type: "GET",
        url: GLOBAL_BASE_PATH+"/shippingmethod/ajaxGetSettings/group_id/"+realtimeServiceID+"/"+urlAppend+action,
		async: true,
		global: false,
		success: function(data)
			{    
				var x = jQuery.parseJSON(data);
				$("#shipping_service_li").html('');				
				$("#shipping_service_li").html(x.html);				
				$("#defaultBlock").html('');
				$("#defaultBlock").html(x.zonehtml);
				 $('#defaultBlock').show();
			}
		
		
		
	});	
}


</script>
<script type="text/javascript">
 $(".chznDelivery").chosen();
 </script>
<script type="text/javascript" src="{$view_javascript}/message.plugin.js"></script>
<script type="text/javascript" src="{$view_javascript}/chosen.pluggin.js"></script>
{html->messages_script id="common_message"}
</body>
</html>