jQuery(function($) {
codSend = {
settings: {
url: uscesL10n.requestFile,
type: 'POST',
cache: false,
success: function(data, dataType){
var str = 'success' == data ? usces_ini.cod_updated : data;
$("#cod-response").html( str );
if( 'fix' == $("input[name='cod_type']:checked").val() ){
$('#cod_type_field').html(usces_ini.cod_type_fix);
}else if( 'change' == $("input[name='cod_type']:checked").val() ){
$('#cod_type_field').html(usces_ini.cod_type_change);
}
},
error: function(msg){
$("#cod-response").html(usces_ini.cod_failure);
}
},
send : function() {
$("#cod-response").html('
');
var query = 'action=setup_cod_ajax';
var cod_type = $("input[name='cod_type']:checked").val();
if( 'fix' == cod_type ){
var cod_fee = $("input[name='cod_fee']").val();
var cod_limit_amount = $("#cod_limit_amount_fix").val();
query += '&cod_type=' + cod_type + '&cod_fee=' + cod_fee + '&cod_limit_amount=' + cod_limit_amount;
}else{
var cod_first_amount = $("input[name='cod_first_amount']").val();
var cod_limit_amount = $("#cod_limit_amount_change").val();
var cod_first_fee = $("input[name='cod_first_fee']").val();
var cod_end_fee = $("input[name='cod_end_fee']").val();
query += '&cod_type=' + cod_type + '&cod_first_amount=' + cod_first_amount + '&cod_limit_amount=' + cod_limit_amount + '&cod_first_fee=' + cod_first_fee + '&cod_end_fee=' + cod_end_fee;
var amounts = $("input[name^='cod_amounts']");
for(var i=0; i= limit ){
alert(usces_ini.cod_limit + pre + ':' + limit);
}
}
});
$("input[name^='cod_amounts']")
.change(function() {
var trs = $("input[name^='cod_amounts']");
var cnt = $(trs).length;
var id = $(trs).index(this);
if( id >= cnt-1 ){
$(end_amount).html( parseInt($(trs).eq(id).val()) + 1 );
}else if( id < cnt-1 ){
$('#amount_'+(id+1)).html( parseInt($(trs).eq(id).val()) + 1 );
}
});
$('#add_row')
.click(function() {
var trs = $("input[name^='cod_amounts']");
$(trs).unbind("change");
var first_amount = $("input[name='cod_first_amount']");
var first_fee = $("input[name='cod_first_fee']");
var end_amount = $("#end_amount");
var enf_fee = $("input[name='cod_enf_fee']");
//alert(parseInt(first_amount)+':'+first_fee+':'+end_amount+':'+enf_fee+':'+trs.length);
if( 0 == trs.length){
prep = ( $(first_amount).val() == '' ) ? '' : parseInt( $(first_amount).val() )+1;
}else if( 0 < trs.length){
prep = ( $(trs).eq(trs.length-1).val() == '' ) ? '' : parseInt( $(trs).eq(trs.length-1).val() )+1;
}
html = '| ' + prep + ' | ~ | | |
';
$('#cod_change_field').append(html);
trs = $("input[name^='cod_amounts']");
$(trs).bind("change", function(){
var cnt = $(trs).length;
var id = $(trs).index(this);
if( id >= cnt-1 ){
$(end_amount).html( parseInt($(trs).eq(id).val()) + 1 );
}else if( id < cnt-1 ){
$('#amount_'+(id+1)).html( parseInt($(trs).eq(id).val()) + 1 );
}
return false;
});
});
$('#del_row')
.click(function() {
var trs = $("input[name^='cod_amounts']");
$(trs).unbind("change");
var first_amount = $("input[name='cod_first_amount']");
var end_amount = $("#end_amount");
//alert(parseInt(first_amount)+':'+first_fee+':'+end_amount+':'+enf_fee+':'+trs.length);
var del_id = trs.length - 1;
//alert(trs.length);
if( 0 < trs.length){
$('#tr_'+del_id).remove();
}
trs = $("input[name^='cod_amounts']");
if( 0 == trs.length && $(first_amount).val() != '' ){
$(end_amount).html( parseInt($(first_amount).val())+1 );
}else if( 0 < trs.length && $(trs).eq(trs.length-1).val() != '' ){
$(end_amount).html( parseInt($(trs).eq(trs.length-1).val()) + 1 );
}
$(trs).bind("change", function(){
var cnt = $(trs).length;
var id = $(trs).index(this);
if( id >= cnt-1 && $(trs).eq(id).val() != '' ){
$(end_amount).html( parseInt($(trs).eq(id).val()) + 1 );
}else if( id < cnt-1 && $(trs).eq(id).val() != '' ){
$('#amount_'+(id+1)).html( parseInt($(trs).eq(id).val()) + 1 );
}
});
});
if( 'fix' == usces_ini.cod_type ){
$('#cod_type_field').html(usces_ini.cod_type_fix);
$('#cod_fix_table').css("display","");
$('#cod_change_table').css("display","none");
}else{
$('#cod_type_field').html(usces_ini.cod_type_change);
$('#cod_fix_table').css("display","none");
$('#cod_change_table').css("display","");
}
});