// source --> https://atifonline.org/wp-content/plugins/presspoint/paupay/assets/j/paupay-universal.js?ver=3.9.9.983 
jQuery.noConflict();

/*	------------------------------------------------------- 
	TAB FUNCTIONS
	------------------------------------------------------- */

function paupay_theme_tab_toggle() {
	var activeholder = jQuery(this).closest('.paupay-holder').attr('id');
	var activeTab = jQuery(this).attr('title');	//Find the rel attribute value to identify the active tab + content
	jQuery('#'+activeholder+' .paupay-tab').removeClass('on'); //Remove any "active" class
	jQuery(this).addClass('on'); //Add "active" class to selected tab
	jQuery('#'+activeholder+' .paupay-section').hide(); //Hide all tab content
	jQuery('#'+activeholder+' .paupay-section').find('input, select, textarea').attr('disabled', 'disabled');
	jQuery('#'+activeTab).show(); //Fade in the active content
	jQuery('#'+activeTab).find('input, select, textarea').removeAttr('disabled');
	return false;
}

function paupay_theme_radio_toggle() {
	var activeholder = jQuery(this).closest('.paupay-holder').attr('id');
	var activeTab = jQuery(this).attr('title');	//Find the rel attribute value to identify the active tab + content
	//jQuery('#'+activeholder+' .paupay-tab').removeClass('on'); //Remove any "active" class
	//jQuery(this).addClass('on'); //Add "active" class to selected tab
	jQuery('#'+activeholder+' .paupay-section').hide(); //Hide all tab content
	jQuery('#'+activeholder+' .paupay-section').find('input, select, textarea').attr('disabled', 'disabled');
	jQuery('#'+activeTab).show(); //Fade in the active content
	jQuery('#'+activeTab).find('input, select, textarea').removeAttr('disabled');
	return false;
}

function paupay_theme_tabs() {
	// TABBED SECTIONS: SETUP
	jQuery('.paupay-holder').hide(); // HIDE ALL CONTENT
	jQuery('.paupay-holder .paupay-section').find('input, select, textarea').attr('disabled', 'disabled');
	if ( jQuery('.paupay-holder.on .paupay-section').hasClass('on') ) {
		jQuery('.paupay-holder.on .paupay-section.on').find('input, select, textarea').removeAttr('disabled');
		jQuery('.paupay-holder.on .paupay-section').hide();
		jQuery('.paupay-holder.on .paupay-section.on').show();
		jQuery('.paupay-holder.on').fadeIn('slow');
	} else {
		jQuery('.paupay-holder.on .paupay-section:first').find('input, select, textarea').removeAttr('disabled');
		jQuery('.paupay-holder.on .paupay-section').hide();
		jQuery('.paupay-holder.on .paupay-section:first').show();
		jQuery('.paupay-holder.on .paupay-tab:first').addClass('on');
		jQuery('.paupay-holder.on').fadeIn('slow');
	}
	
	jQuery('#transaction_types').change(function(){
		var type = jQuery(this).val();
		jQuery('.paupay-holder').hide();
		jQuery('.paupay-holder').find('input, select, textarea').attr('disabled', 'disabled');
		jQuery('#paupay_'+type+'_holder').find('input, select, textarea').removeAttr('disabled');
		jQuery('#paupay_'+type+'_holder').fadeIn('slow');
		jQuery('#paupay_'+type+'_holder .paupay-section').hide(); // HIDE ALL CONTENT
		jQuery('#paupay_'+type+'_holder .paupay-tab:first').addClass('on'); // ACTIVATE FIRST TAB
		jQuery('#paupay_'+type+'_holder .paupay-section:first').fadeIn('slow'); // SHOW FIRST TAB CONTENT
	});
	
}


function paupay_toggle_refunds( status ) {

	if ( 'refunded' == status ) {
		jQuery('#refund-form').show();
		var goauto = false;
		var payment = jQuery('#_pp_item_payment').val();
		
		jQuery.each( jQuery.parseJSON(paupayAjax.refundArray), function (k, v) {
			if ( payment == v ) {
				goauto = true;
				return false;
			}
		});
		if ( goauto ) {
			jQuery('.refund-notice').append(paupayAjax.refundAuto);
		} else {
			jQuery('.refund-notice').append(paupayAjax.refundManual);
		}
	} else if ( 'credited' == status ) {
		jQuery('#refund-form').show();
	} else {
		jQuery('#refund-form').hide();
	}
	
}

function edit_renewal_plan(){
	var rid = jQuery(this).data('id');
	var pid = jQuery(this).data('plan');
	jQuery('#recur-detail').empty();
	jQuery('#recur-detail').slideToggle('fast');
	jQuery('#recur-detail').html('<div class="pau_loader"><img src="'+paupayAjax.ajaxload+'" /></div>');
	jQuery.post( 
		paupayAjax.ajaxurl, { 
			action : 'paupay_edit_renewal_plan', 
			data : rid, 
			plan : pid, 
		},
		function( response ) {
			jQuery('#recur-detail').html(response);
		}
	);
}

function edit_renewal(){
	if ( jQuery(this).data('url') ) {
		parent.document.location.href = jQuery(this).data('url');
	} else {
		var rid = jQuery(this).data('id');
		var typ = jQuery(this).data('type');
		jQuery('#recur-detail').empty();
		jQuery('#recur-detail').slideToggle('fast');
		jQuery('#recur-detail').html('<div class="pau_loader"><img src="'+paupayAjax.ajaxload+'" /></div>');
		jQuery.post( 
			paupayAjax.ajaxurl, { 
				action : 'paupay_edit_renewal', 
				data : rid, 
				type : typ, 
			},
		    function( response ) {
		    	jQuery('#recur-detail').html(response);
		    }
		);
	}
}

function post_renewal(){
	
	var errors = pp_errors_two('recur-detail');
	if ( errors ) {
		return false;
	}
			
	var data = jQuery('#recur-detail').find('[name]').serialize();
	jQuery.post( 
		paupayAjax.ajaxurl, { 
			action : 'paupay_post_renewal', 
			data : data, 
		},
	    function( response ) {
	    	jQuery('#recur-detail').slideToggle('fast');
	    	if ( jQuery('#recur-history').hasClass('pp-recur-asc') ) {
	    		jQuery('#recur-history').append(response);
	    	} else {
	    		jQuery('#recur-history').prepend(response);
	    	}
	    	jQuery('#recur-detail').empty();
	    }
	);
}
function post_renewal_options(){
	
	var errors = pp_errors_two('recur-detail');
	if ( errors ) {
		return false;
	}
			
	var data = jQuery('#recur-detail').find('[name]').serialize();
	jQuery('#recur-detail').html('<div class="pau_loader"><img src="'+paupayAjax.ajaxload+'" /></div>');
	jQuery.post( 
		paupayAjax.ajaxurl, { 
			action : 'paupay_post_renewal_options', 
			data : data, 
		},
		function( response ) {
			jQuery('#recur-detail').html(response);
			/*
			jQuery('#recur-detail').slideToggle('fast');
			if ( jQuery('#recur-history').hasClass('pp-recur-asc') ) {
				jQuery('#recur-history').append(response);
			} else {
				jQuery('#recur-history').prepend(response);
			}
			jQuery('#recur-detail').empty();
			*/
		}
	);
}

function edit_renewal_child(){
	var rid = jQuery(this).data('id');
	if ( jQuery('#pp-item-child-detail-'+rid).is(':visible') ) {
		jQuery('#pp-item-child-detail-'+rid).slideToggle('fast');
		jQuery('#pp-item-child-detail-'+rid).empty();
	} else {
		jQuery('#pp-item-child-detail-'+rid).empty().html('<div class="pau_loader"><img src="'+paupayAjax.ajaxload+'" /></div>');
		jQuery('#pp-item-child-detail-'+rid).slideToggle('fast');
		jQuery.post( 
			paupayAjax.ajaxurl, { 
				action : 'paupay_edit_renewal_child', 
				data : rid, 
			},
		    function( response ) {
		    	jQuery('#pp-item-child-detail-'+rid).html(response);
		    }
		);
	}
}
function paupay_item_edit(){
	var rid = jQuery(this).data('id');
	var vid = jQuery(this).data('view');
	if ( jQuery('#pp-item-edit-'+rid).is(':visible') ) {
		jQuery('#pp-item-edit-'+rid).slideToggle('fast');
		jQuery('#pp-item-edit-'+rid).empty();
	} else {
		jQuery('#pp-item-edit-'+rid).empty().html('<div class="pau_loader"><img src="'+paupayAjax.ajaxload+'" /></div>');
		jQuery('#pp-item-edit-'+rid).slideToggle('fast');
		jQuery.post( 
			paupayAjax.ajaxurl, { 
				action : 'paupay_item_edit', 
				data : rid, 
				view : vid, 
			},
		    function( response ) {
		    	jQuery('#pp-item-edit-'+rid).html(response);
		    }
		);
	}
}

function paupay_item_post(){
	var rid = jQuery(this).data('id');
	var vid = jQuery(this).data('view');
	var stat = jQuery('#_pp_item_status_'+rid).val();
	var date = jQuery('#_pp_item_child_dates_'+rid).val();
	
	var reference = 'pp-item-edit-'+rid;
	var errors = pp_errors_two(reference);
	if ( errors ) {
		return false;
	}
	
	if ( 'completed' == stat && !date ) {
		alert(paupayAjax.childEditError);
		return false;
	}
	var data = jQuery('#pp-item-edit-'+rid).find('[name]').serialize();
	jQuery.post( 
		paupayAjax.ajaxurl, { 
			action : 'paupay_item_post', 
			data : data, 
			view : vid, 
		},
	    function( response ) {
	    	jQuery('#pp-item-edit-'+rid).slideToggle('fast');
	    	jQuery('#pp-item-'+rid).html(response);
	    }
	);
}

function post_delete_child(){
	var rida = jQuery(this).data('id');
	jQuery.post( 
		paupayAjax.ajaxurl, { 
			action : 'paupay_post_delete_child', 
			data : rida, 
		},
	    function( response ) {
	    	jQuery('#pp-item-child-detail-'+rida).slideToggle('fast');
	    	jQuery('#pp-item-child-'+rida).html(response);
	    	setTimeout(function() {
	    		jQuery('#pp-item-child-'+rida).fadeOut('slow');
	    	}, 2000);
	    }
	);
}

function paupay_item_stop(){
	var rida = jQuery(this).data('id');
	jQuery('#pp-item-edit-'+rida).slideToggle('fast').html('');
}

function edit_disc(){
	var rid = jQuery(this).data('id');
	var vid = jQuery(this).data('view');
	if ( jQuery('#pp-item-disc-'+rid).is(':visible') ) {
		jQuery('#pp-item-disc-'+rid).slideToggle('fast');
		jQuery('#pp-item-disc-'+rid).empty();
	} else {
		jQuery('#pp-item-disc-'+rid).empty().html('<div class="pau_loader"><img src="'+paupayAjax.ajaxload+'" /></div>');
		jQuery('#pp-item-disc-'+rid).slideToggle('fast');
		jQuery.post( 
			paupayAjax.ajaxurl, { 
				action : 'paupay_edit_disc', 
				data : rid, 
				view : vid, 
			},
		    function( response ) {
		    	jQuery('#pp-item-disc-'+rid).html(response);
		    }
		);
	}
}
function view_disc(){
	var rid = jQuery(this).data('id');
	var vid = jQuery(this).data('view');
	var did = jQuery(this).val();
	var sid = jQuery(this).data('disc');
	if ( sid.length != '' ) {
		sid = jQuery(this).val();
		did = jQuery(this).data('disc');
	}
	jQuery('#pp-item-disc-view-'+rid).empty().html('<div class="pau_loader"><img src="'+paupayAjax.ajaxload+'" /></div>');
	if ( !jQuery('#pp-item-disc-view-'+rid).is(':visible') ) {
		jQuery('#pp-item-disc-view-'+rid).slideToggle('fast');
	}
		
	jQuery.post( 
		paupayAjax.ajaxurl, { 
			action : 'paupay_view_disc', 
			item : rid, 
			disc : did, 
			view : vid, 
			swap : sid, 
		},
	    function( response ) {
	    	jQuery('#pp-item-disc-view-'+rid).html(response);
	    }
	);
}
function post_disc(){
	var rida = jQuery(this).data('id');
	var vida = jQuery(this).data('view');
	var dida = jQuery('#pp-item-disc-select-'+rida).val();
	var data = jQuery('#pp-item-disc-'+rida).find('[name]').serialize();
	jQuery('#pp-item-disc-'+rida).empty().html('<div class="pau_loader"><img src="'+paupayAjax.ajaxload+'" /></div>');
	jQuery.post( 
		paupayAjax.ajaxurl, { 
			action : 'paupay_post_disc', 
			data : data, 
			item : rida, 
			disc : dida, 
			view : vida, 
		},
	    function( response ) {
	    	jQuery('#pp-item-disc-'+rida).html(response);
	    	/*
	    	jQuery('#pp-item-disc-'+rida).on('click','.pp-refresh',function(e){
	    		e.preventDefault();
	    		document.location.reload();
	    	});
	    	*/
	    	//jQuery('#pp-item-disc-'+rida).empty().slideToggle('fast');
	    	//jQuery('#pp-item-child-detail-'+rida).empty().slideToggle('fast');
	    }
	);
}
function stop_disc(){
	var rida = jQuery(this).data('id');
	jQuery('#pp-item-disc-'+rida).slideToggle('fast').html('');
}


function edit_debt(){
	var rid = jQuery(this).data('id');
	if ( jQuery('#pp-item-debt-'+rid).is(':visible') ) {
		jQuery('#pp-item-debt-'+rid).slideToggle('fast');
		jQuery('#pp-item-debt-'+rid).empty();
	} else {
		jQuery('#pp-item-debt-'+rid).empty().html('<div class="pau_loader"><img src="'+paupayAjax.ajaxload+'" /></div>');
		jQuery('#pp-item-debt-'+rid).slideToggle('fast');
		jQuery.post( 
			paupayAjax.ajaxurl, { 
				action : 'paupay_edit_debt', 
				data : rid, 
			},
		    function( response ) {
		    	jQuery('#pp-item-debt-'+rid).html(response);
		    }
		);
	}
}
function post_debt(){
	var rida = jQuery(this).data('id');
	var type = jQuery(this).data('type');
	var data = jQuery('#pp-item-debt-'+rida).find('[name]').serialize();
	jQuery.post( 
		paupayAjax.ajaxurl, { 
			action : 'paupay_post_debt', 
			data : data, 
			type : type, 
		},
	    function( response ) {
	    	jQuery('#pp-item-debt-'+rida).html(response);
	    }
	);
}
function stop_debt(){
	var rida = jQuery(this).data('id');
	jQuery('#pp-item-debt-'+rida).slideToggle('fast').html('');
}

function paupay_plan_bill(){
	var data = jQuery(this).closest('.paupress').data('id');
	var uniq = jQuery(this).closest('.paupress').data('non');
	var view = jQuery(this).closest('.paupress').data('view');
	var type = jQuery(this).val();
	jQuery('#pp-plan-bill-'+data).empty();
	jQuery('#pp-plan-bill-'+data).html('<div class="pau_loader"><img src="'+paupayAjax.ajaxload+'" /></div>');
	jQuery.post( 
		paupayAjax.ajaxurl, { 
			action : 'paupay_bill_renewal', 
			data : data, 
			type : type, 
			view : view, 
			uniq : uniq, 
		},
	    function( response ) {
	    	jQuery('#pp-plan-bill-'+data).html(response);
	    }
	);
}

function paupay_item_bill(){
	var data = jQuery(this).data('id');
	var view = jQuery(this).data('view');
	if ( jQuery('#pp-item-bill-'+data).is(':visible') ) {
		jQuery('#pp-item-bill-'+data).slideToggle('fast');
		jQuery('#pp-item-bill-'+data).empty();
	} else {
		jQuery('#pp-item-bill-'+data).empty().html('<div class="pau_loader"><img src="'+paupayAjax.ajaxload+'" /></div>');
		jQuery('#pp-item-bill-'+data).slideToggle('fast');
	}
	jQuery.post( 
		paupayAjax.ajaxurl, { 
			action : 'paupay_bill_renewal', 
			data : data, 
			view : view, 
		},
	    function( response ) {
	    	jQuery('#pp-item-bill-'+data).html(response);
	    }
	);
}


function edit_dates_child() {
	var rid = jQuery(this).data('id');
	var val = jQuery(this).val();
	var dat =jQuery('#pp-item-child-dates-'+rid).data('date');
	if ( 'today' == val ) {
		jQuery('#pp-item-child-dates-'+rid).find('.pp-item-child-date input').val(dat);
		jQuery('#pp-item-child-dates-'+rid).find('.pp-item-child-date input').removeAttr('disabled');
		jQuery('#pp-item-child-dates-'+rid).find('.pp-item-child-date').css('display','none');
	} else if ( 'choose' == val ) {
		jQuery('#pp-item-child-dates-'+rid).find('.pp-item-child-date input').each(function(){
			jQuery(this).val(jQuery(this).data('value'));
		});
		jQuery('#pp-item-child-dates-'+rid).find('.pp-item-child-date input').removeAttr('disabled');
		jQuery('#pp-item-child-dates-'+rid).find('.pp-item-child-date').show();
	} else {
		jQuery('#pp-item-child-dates-'+rid).find('.pp-item-child-date input').attr('disabled','disabled');
		jQuery('#pp-item-child-dates-'+rid).find('.pp-item-child-date').css('display','none');
	}
}

function recuring_unit_toggle() {
	jQuery('.recurring-wrap').each(function(){
		if ( jQuery(this).hasClass('recurring-check-done') ) {
			return false;
		}
		jQuery(this).find('.recurring-switch').removeAttr('disabled');
		var status = jQuery(this).find('.recurring-switch').val();
		var name = jQuery(this).find('.recurring-switch').attr('name');
		if ( status != '' ) {
			jQuery(this).find('input, select').attr('disabled','disabled');
			jQuery(this).find('.recurring-switch').removeAttr('disabled');
			
			jQuery(this).find('.recur-wrap'+status+'').show();
			jQuery(this).find('.recur-wrap'+status+'').find('input, select').removeAttr('disabled');
			
			// DATE TOGGLE
			jQuery('.recur-unit-switch').each(function(){
				var unit = jQuery(this).val();
				if ( 'date' == unit ) {
					jQuery(this).closest('.multilist').find('.recur-unit').hide();
					jQuery(this).closest('.multilist').find('.recur-date').show();
				} else {
					jQuery(this).closest('.multilist').find('.recur-unit').show();
					jQuery(this).closest('.multilist').find('.recur-date').hide();
				}
			});
		}
		jQuery(this).addClass('recurring-check-done');
	});
}


function cancel_subscription(){
	var tid = jQuery(this).attr('id');
	var val = jQuery(this).attr('rel');
	var que = jQuery(this).attr('title');
	var answer = confirm(que);
	if (answer) {
		jQuery.post( 
	    	paupayAjax.ajaxurl, { 
	    		action : 'paupay_cancel_subscription', 
	    		data : val, 
	    		paupay_admin_nonce : paupayAjax.paupay_admin_nonce 
	    	},
	        function( response ) {
	            jQuery('#'+tid).html(response);
	            setTimeout(function() {
	            	jQuery('#'+tid).fadeOut('slow');
	            }, 3000);
	            self.parent.tb_remove();
	        }
	    );
    }
    return false;
}

function paupay_clicky(){

	jQuery('.shipping-info :input').each(function(i){
		
		var mark = jQuery(this).attr('id').substring(8);
		/*
		if (jQuery('input#paupress-copy').is(':checked')) {
			jQuery(this).val(mark);
		} else {
			jQuery(this).val('#billing'+mark);
		}
		*/
		if (jQuery('#paupress-copy').is(':checked')) {
			if ( jQuery(this).is('select') ) {
				svar = jQuery('#billing'+mark).val();
				jQuery('option[value="' + svar + '"]', this).attr("selected", "selected");
			} else {
				jQuery(this).val(jQuery('#billing'+mark).val());
			}
			if ( jQuery(this).hasClass('halt') ) {
				jQuery(this).removeClass('halt');
			}
		} else {
			if ( jQuery(this).is('select') ) {
				svar = '';
				jQuery('option[value="' + svar + '"]', this).attr("selected", "selected");
			} else {
				jQuery(this).val('');
			}
		}

	});
}

function paupay_clicky_acct(){
	if (jQuery('#paupress-copy-acct').is(':checked')) {
		jQuery('#billing_first').val(jQuery('#first_name').val());
		jQuery('#billing_last').val(jQuery('#last_name').val());
		if ( jQuery('#billing_first').hasClass('halt') ) {
			jQuery('#billing_first').removeClass('halt');
		}
		if ( jQuery('#billing_last').hasClass('halt') ) {
			jQuery('#billing_last').removeClass('halt');
		}
	} else {
		jQuery('#billing_first').val('');
		jQuery('#billing_last').val('');
	}
}


jQuery(document).ready(function() {
	
	jQuery(document).on('click','#cart-detail-suggestions-expander',function(){
		jQuery('#cart-detail-suggestions-holder').slideToggle('fast');
		if ( jQuery(this).hasClass('expander-closed') ) {
			jQuery(this).removeClass('expander-closed');
			jQuery(this).addClass('expander-open');
			jQuery(this).html('<span class="dashicons dashicons-arrow-up-alt2"></span>');
		} else {
			jQuery(this).removeClass('expander-open');
			jQuery(this).addClass('expander-closed');
			jQuery(this).html('<span class="dashicons dashicons-arrow-down-alt2"></span>');
		}
		event.stopPropagation();
	});
	jQuery(document).on('click','.cart-detail-toggle',function(){
		jQuery('#cart-detail-wrapper').slideToggle('fast');
		//jQuery(this).toggleClass('paupress-collapse');
		if ( jQuery(this).hasClass('toggle-closed') ) {
			jQuery(this).removeClass('toggle-closed');
			jQuery(this).addClass('toggle-open');
			jQuery(this).html('<span class="dashicons dashicons-arrow-up-alt2"></span>');
		} else {
			jQuery(this).removeClass('toggle-open');
			jQuery(this).addClass('toggle-closed');
			jQuery(this).html('<span class="dashicons dashicons-arrow-down-alt2"></span>');
		}
		event.stopPropagation();
	});
	jQuery(document).on('click','.cart-detail-suggestions',function(){
		var clicktoadd = jQuery(this).data('code');
		jQuery('#apply-discount').val(clicktoadd).focus();
		jQuery('#update-button').click();
		event.stopPropagation();
	});
	jQuery(document).on('mouseover','.cart-detail-suggestions',function(){
		jQuery(this).removeClass('pp-data');
		jQuery(this).addClass('pp-success');
	});
	jQuery(document).on('mouseout','.cart-detail-suggestions',function(){
		jQuery(this).removeClass('pp-success');
		jQuery(this).addClass('pp-data');
	});

	jQuery(document).dblclick(function(e){
		e.preventDefault();
	});
	
	jQuery('#transaction_types').change(function(){
			var type = jQuery(this).val();
			var ptid = jQuery(this).attr('title');
			jQuery('.pp-transaction-holder').html('<div class="pau_loader"><img src="'+paupayAjax.ajaxload+'" /></div>');
			jQuery.post( 
				paupayAjax.ajaxurl, { 
					action : 'paupay_get_trans_type', 
					type : type, 
					post : ptid, 
				},
			    function( response ) {
			    	jQuery('.pp-transaction-holder').html(response);
			    }
			);
		});
		
		jQuery(document).on('change','.recurring-switch',function(){
			var status = jQuery(this).find(':selected').val();
			jQuery(this).closest('.recurring-wrap').find('input, select').attr('disabled','disabled');
			jQuery(this).removeAttr('disabled');
			jQuery(this).closest('.recurring-wrap').find('.wrap-recur').hide();
			jQuery(this).closest('.recurring-wrap').find('.recur-wrap'+status+'').show();
			jQuery(this).closest('.recurring-wrap').find('.recur-wrap'+status+'').find('input, select').removeAttr('disabled');
		});
		
		jQuery(document).on('change','.recur-unit-switch',function(){
			var unit = jQuery(this).find(':selected').val();
			if ( 'date' == unit ) {
				jQuery(this).closest('.multilist').find('.recur-unit').val('').hide();
				jQuery(this).closest('.multilist').find('.recur-date').show();
			} else {
				jQuery(this).closest('.multilist').find('.recur-unit').show();
				jQuery(this).closest('.multilist').find('.recur-date').val('').hide();
			}
		});
		
		jQuery(document).on('change','.recur-installment-balance',function(){
			var unit = jQuery(this).find(':selected').val();
			if ( 'manual' == unit ) {
				jQuery(this).closest('.recur-wrapinstallment').find('.balance-manual').show();
				jQuery(this).closest('.recur-wrapinstallment').find('.balance-count').val('').hide();
				jQuery(this).closest('.recur-wrapinstallment').find('.balance-date').val('').hide();
			} else if ( 'count' == unit ) {
				jQuery(this).closest('.recur-wrapinstallment').find('.balance-manual').hide();
				jQuery(this).closest('.recur-wrapinstallment').find('.balance-count').show();
				jQuery(this).closest('.recur-wrapinstallment').find('.balance-date').val('').hide();
			} else if ( 'date' == unit ) {
				jQuery(this).closest('.recur-wrapinstallment').find('.balance-manual').hide();
				jQuery(this).closest('.recur-wrapinstallment').find('.balance-count').val('').hide();
				jQuery(this).closest('.recur-wrapinstallment').find('.balance-date').show();
			}
		});
		
		jQuery(document).on('change','.recur-term-switch',function(){
			var unit = jQuery(this).find(':selected').val();
			if ( 'year' == unit ) {
				jQuery(this).closest('.wrap-recur').find('.recur-term-option').show();
				jQuery(this).closest('.wrap-recur').find('.recur-term-year').show();
				jQuery(this).closest('.wrap-recur').find('.recur-term-month').show();
			} else if ( 'month' == unit ) {
				jQuery(this).closest('.wrap-recur').find('.recur-term-option').show();
				jQuery(this).closest('.wrap-recur').find('.recur-term-year').hide();
				jQuery(this).closest('.wrap-recur').find('.recur-term-month').show();
			} else {
				jQuery(this).closest('.wrap-recur').find('.recur-term-option').hide();
			}
		});
	
		jQuery('.env').click(function(){
			var env = jQuery(this).attr('id');
			jQuery('.env-opt').hide();
			jQuery('#'+env+'-opt').show();
		});
		
		
		jQuery(document).on('change', '#_pp_item_status', function() {
			var status = jQuery(this).val();
			var bulkexc = jQuery(this).closest('li').find('.paupress-label a').attr('title');
			
			jQuery(this).closest('.paupress-field').addClass('mod-status');
			
			if ( bulkexc ) {
				jQuery('option[value="refunded"]',this).attr('disabled','disabled');
				jQuery('option[value="credited"]',this).attr('disabled','disabled');
				jQuery('option[value="returned"]',this).attr('disabled','disabled');
				jQuery('option[value="lost"]',this).attr('disabled','disabled');
				if ( 'refunded' == status || 'credited' == status || 'returned' == status || 'lost' == status ) {
					jQuery('.refund-notice').detach();
					jQuery('.mod-status').append(paupayAjax.refundBulk);
					jQuery(this).val('');
				}
				return false;
			}
			
			if ( 'refunded' == status || 'credited' == status || 'returned' == status || 'lost' == status ) {
				jQuery('.refund-notice').detach();
				jQuery('.mod-status').append(paupayAjax.refundForm);
				var curamt = jQuery('#_pp_item_amount').val();
				var curdis = jQuery('#_pp_item_discount').val();
				var curadj = curamt - curdis;
				if ( curadj < 0 ) {
					var curadj = 0;
				}
				var curqty = jQuery('#_pp_item_quantity').val();
				var curshi = jQuery('#_pp_item_shipping').val();
				var curtax = jQuery('#_pp_item_tax').val();
				jQuery('#_pp_ref_amt').val(curadj);
				jQuery('#_pp_ref_qty').val(curqty);
				jQuery('#_pp_ref_shi').val(curshi);
				jQuery('#_pp_ref_tax').val(curtax);
				
				// LET'S PERFORM THE RIGHT ACTION
				if ( 'returned' == status || 'lost' == status ) {
					jQuery('.refund-notice').prepend(paupayAjax.retlosForm);
					
					jQuery('.refund-notice').on('change','#retlos-select',function(){
						var newstatus = jQuery(this).val();
						paupay_toggle_refunds( newstatus );
					});
				} else {
					paupay_toggle_refunds( status );
				}
			} else {
				jQuery('.refund-notice').detach();
			}
		});
		
		jQuery(document).on('click', '.recur-detail-change', edit_renewal_plan);
		jQuery(document).on('click', '.recur-detail-toggle', edit_renewal);
		jQuery(document).on('click', '#recur-update', post_renewal);
		jQuery(document).on('click', '#recur-update-cancel', function(){
			jQuery('#recur-detail').slideToggle('fast');
			jQuery('#recur-detail').empty();
		});
		jQuery(document).on('click', '#recur-options-update', post_renewal_options);
		jQuery(document).on('click', '#recur-options-update-cancel', function(){
			jQuery('#recur-detail').slideToggle('fast');
			jQuery('#recur-detail').empty();
		});
		//jQuery(document).on('click', '.pp-item-child', edit_renewal_child);
		jQuery(document).on('click', '.pp-item-disc-wrap', edit_renewal_child);
		jQuery(document).on('click', '.recur-delete-child', post_delete_child);
		jQuery(document).on('click', '.pp-item-stop', paupay_item_stop);
		jQuery(document).on('click', '.pp-item-edit', paupay_item_edit);
		jQuery(document).on('click', '.pp-item-post', paupay_item_post);
		jQuery(document).on('click', '.pp-item-disc', edit_disc);
		jQuery(document).on('change', '.pp-item-disc-select', view_disc);
		jQuery(document).on('click', '.pp-item-disc-post', post_disc);
		jQuery(document).on('click', '.pp-item-disc-stop', stop_disc);
		jQuery(document).on('click', '.pp-item-debt', edit_debt);
		jQuery(document).on('click', '.pp-item-debt-post', post_debt);
		jQuery(document).on('click', '.pp-item-debt-stop', stop_debt);
		jQuery(document).on('change', '.pp-item-child-dates', edit_dates_child);
		
		jQuery(document).on('click', '.pp-item-bill', paupay_item_bill);
		jQuery(document).on('change', '.pp-plan-bill', paupay_plan_bill);
		
		jQuery(document).on('click', '.recur-child', function() {
			jQuery(this).next('.recur-child-detail').slideToggle('fast');
		});
		
		jQuery(document).on('click', '#cancel-subscription', cancel_subscription );
		jQuery(document).on('change','.paupay-radios',paupay_theme_radio_toggle);
		
		
		jQuery(document).on('click','#paupress-copy',paupay_clicky);
		jQuery(document).on('click','#paupress-copy-acct',paupay_clicky_acct);
		
		jQuery(document).on('click', '.pp-add-on', function(){
			var addid = jQuery(this).data('id');
			var arent = jQuery(this).closest('ul').siblings('.pp'+addid);
			var ahref = jQuery(arent).attr('href');
			var abase = ahref.split('-', 2);
			var alink = abase[0];
			jQuery(this).closest('ul').find('.pp-add-on').each(function(){
				if ( jQuery(this).is(':checked') ){
					alink += ('-' + jQuery(this).val());
				}
			});
			jQuery(arent).attr('href',alink);
		});
	
});
// source --> https://atifonline.org/wp-content/plugins/presspoint/paupay/assets/j/paupay.js?ver=3.9.9.983 
jQuery.noConflict();

function pp_ajax_cart(e){
	e.preventDefault();

	var ami = jQuery(this);
	var url = jQuery(this).attr('href');
	jQuery(this).addClass('selected').html('<img src="'+paupayAjax.ajaxload+'" />');
	/*
	var amt = jQuery(this).data('amount');
	var typ = jQuery(this).data('type');
	var qty = jQuery(this).data('quantity');
	var pid = jQuery(this).data('id');
	*/
	jQuery.post( 
		paupayAjax.ajaxurl, { 
			action : 'paupay_ajax_cart', 
			/*
			amount : amt, 
			type : typ, 
			id : pid, 
			quantity : qty, 
			ajx : '1', 
			*/
			data : url, 
		},
	    function( response ) {
	    	var data = jQuery.parseJSON(response);
	    	jQuery.cookie( 'paupay_cart', data.cart_id, { expires:  data.ttl, path: '/' } );
	    	jQuery.cookie( 'paupay_count',  data.items, { expires:  data.ttl, path: '/' } );
	    	if (jQuery(ami).hasClass('paupay-select-button')){
	    		var referee = jQuery(ami).data('id');
	    	} else {
					var referee = 'pp'+ data.id;
				}
	    	jQuery('.'+referee).addClass('selected').removeClass('pp-close');
	    	if ( !jQuery('.'+referee).hasClass('credit') ) {
	    		jQuery('.'+referee).attr('rel','paupayShowCart');
	    		jQuery('.'+referee).attr('href',data.url).removeClass('pp-cart-ajax');
	    		jQuery('.'+referee).html(paupayAjax.cartupto);
	    		setTimeout( function() { 
	    			jQuery('.'+referee).html(paupayAjax.cartitem);
	    		}, 800 );
	    	} else {
	    		var rand = jQuery('.'+referee).attr('title').split('-');
	    		var intv = rand[0]+'-'+rand[1]+'-'+rand[2]+1;
	    		jQuery('.'+referee).attr('title',intv);
	    	}
	    	jQuery('.pp-cart .pp-cart-ct').html(data.notice).fadeIn('fast').addClass('pp-cart-on');
	    }
	);
}

function pp_ajax_checkout(e){
	e.preventDefault();

	var ami = jQuery(this);
	var url = jQuery(this).attr('href');
	var usr = jQuery(this).data('user');
	jQuery(this).addClass('selected').html('<img src="'+paupayAjax.ajaxload+'" />');
	jQuery.post( 
		paupayAjax.ajaxurl, { 
			action : 'paupay_ajax_checkout', 
			data : url, 
			user : usr, 
		},
	    function( response ) {
	    	var data = jQuery.parseJSON(response);
	    	console.log(data);
	    	if (jQuery(ami).hasClass('paupay-select-button')){
	    		var referee = jQuery(ami).data('id');
	    	} else {
					var referee = 'pp'+ data.id;
				}
	    	jQuery('.'+referee).addClass('selected').removeClass('pp-close');
	    	if ( !jQuery('.'+referee).hasClass('credit') ) {
	    		//jQuery('.'+referee).attr('rel','paupayShowCart');
	    		//jQuery('.'+referee).attr('href',data.url).removeClass('pp-cart-ajax');
	    		jQuery('.'+referee).attr('href',window.location.href);
	    		jQuery('.'+referee).removeClass('pp-cart-ajax');
	    		jQuery('.'+referee).removeClass('pp-checkout-ajax');
	    		jQuery('.'+referee).html(data.notice);
	    	} else {
	    		var rand = jQuery('.'+referee).attr('title').split('-');
	    		var intv = rand[0]+'-'+rand[1]+'-'+rand[2]+1;
	    		jQuery('.'+referee).attr('title',intv);
	    	}
	    }
	);
}

// WHEN THE DOM IS READY...
jQuery(document).ready(function () {

	jQuery(document).on('click', '.variable-wrapper', function(){
		jQuery(this).children().children('.variable-options').toggle();
	});
	if ( jQuery('.pp-cart a').length !== 0 ) {
		jQuery('.pp-cart a').html('<span class="dashicons dashicons-cart"></span><span class="pp-cart-ct"></span>');
	}
	if ( jQuery.cookie( 'paupay_count' ) ) {
		var cartcount = jQuery.parseJSON(jQuery.cookie('paupay_count'));
		// FIRST UPDATE THE CART ICON
		jQuery('.pp-cart-ct').html(cartcount.length).fadeIn('fast').addClass('pp-cart-on');
		// NEXT MOD THE BUTTONS AS NEEDED
		jQuery.each(cartcount, function() {
			if ( 'string' === jQuery.type( this ) || 'number' === jQuery.type( this ) ) {
				//jQuery('.pp'+this).addClass('selected').removeClass('pp-close').attr('rel','paupayShowCart').html('&nbsp;');
				if ( jQuery('.pp'+this).hasClass('ppinstant') ) {
					var butdir = paupayAjax.ajaxhome+'/paupress/checkout';
				} else {
					var butdir = paupayAjax.ajaxhome+'/paupress/cart';
				}
				jQuery('.pp'+this).addClass('selected').removeClass('pp-close');
				if ( jQuery('.pp'+this).hasClass('pp-cart-ajax') ) { jQuery('.pp'+this).removeClass('pp-cart-ajax'); }
				if ( jQuery('.pp'+this).hasClass('credit') ) {
				} else if ( jQuery('.pp'+this).parent().is('select') ) {
					jQuery('.pp'+this).attr('selected','selected');
					if ( !jQuery('.pp'+this).hasClass('disabled') ) {
						jQuery('.pp'+this).parent().next('div').children('a').removeClass('disabled');
					}
					jQuery('.pp'+this).parent().next('div').children('a').html(paupayAjax.cartitem);
					jQuery('.pp'+this).parent().next('div').children('a').attr('href',butdir);
				} else if ( jQuery('.ppa'+this).closest('ul').siblings('a').hasClass('selected') ) {
					jQuery('.ppa'+this).prop('checked',true).prop('disabled',true);
				} else {
					jQuery('.pp'+this).attr('href',butdir).html(paupayAjax.cartitem);					
				}
			}
		});
	}
	
	jQuery(document).on('change','.paupay-select-list',function(){
		var selval = jQuery(this).val();
		var selusr = jQuery('option:selected',this).data('user');
		jQuery(this).next('div').children('a').removeClass('disabled paudirect pp-cart-ajax');
		jQuery(this).next('div').children('a').html('');
		jQuery(this).next('div').children('a').removeAttr('href');
		jQuery(this).next('div').children('a').removeData('paudirect');
		
		// MODIFY THE ACTION
		if ( jQuery('option:selected',this).hasClass('disabled') ) {
			jQuery(this).next('div').children('a').addClass('disabled');
		} else if ( jQuery('option:selected',this).hasClass('selected') ) {
			if ( jQuery('option:selected',this).hasClass('ppinstant') ) {
				var butdir = paupayAjax.ajaxhome+'/paupress/checkout';
			} else {
				var butdir = paupayAjax.ajaxhome+'/paupress/cart';
			}
			jQuery(this).next('div').children('a').attr('href',butdir).data('user',selusr);
		} else {
			jQuery(this).next('div').children('a').attr('href',selval).data('user',selusr);
		}
		
		// MODIFY THE TEXT
		if ( jQuery('option:selected',this).hasClass('selected') ) {
			jQuery(this).next('div').children('a').html(paupayAjax.cartitem);
		} else {
			jQuery(this).next('div').children('a').html(paupayAjax.adtocart);
		}
		
		// MODIFY THE REDIRECT
		if ( jQuery('option:selected',this).hasClass('paudirect') ) {
			var mydata = jQuery('option:selected',this).data('paudirect');
			jQuery(this).next('div').children('a').data('paudirect',mydata);
			jQuery(this).next('div').children('a').addClass('paudirect');
		}
		
		// MODIFY THE CLASS FOR AJAX TO CART
		if ( jQuery('option:selected',this).hasClass('pp-cart-ajax-list') ) {
			jQuery(this).next('div').children('a').addClass('pp-cart-ajax');
		}
		
		// MODIFY THE CLASS FOR AJAX TO CHECKOUT
		if ( jQuery('option:selected',this).hasClass('pp-checkout-ajax-list') ) {
			jQuery(this).next('div').children('a').addClass('pp-checkout-ajax');
		} else if ( !jQuery('option:selected',this).hasClass('pp-checkout-ajax-list') ) {
			jQuery(this).next('div').children('a').removeClass('pp-checkout-ajax');
		}
	});
	
	if ( jQuery('#pp-title').is(':hidden') && jQuery('.pp-cart a').is(':hidden') ) {
		jQuery('#paupanels-tabs').css('height', '0');
	}
	
	//  TABBED SECTIONS: HANDLE TRANSITIONS
	jQuery('.pauf-frame').on('click','.paupay-tab',paupay_theme_tab_toggle);
	
	// PROCESS RETURN LINKS AS NEEDED
	jQuery(document).on('click', '.paudirect', function(e){
		e.preventDefault();
		var pathname = jQuery(this).data('paudirect');
		var thisname = jQuery(this).attr('href');
		if ( thisname ) {
			jQuery.cookie( 'pauDirect', pathname, { path: '/' } );
			if ( paupanelsAjax.panel_embed ) {
				window.location.href = thisname;
			} else {
				var ref = thisname.split('?');
				var ref = ref[1];
				var action = '';
				var title = 'paudirect';
				paupanels_toggle(ref,title,action); 
			}
		}
	});
	
	jQuery(document).on('click', '.pp-cart-ajax', pp_ajax_cart);
	jQuery(document).on('click', '.pp-checkout-ajax', pp_ajax_checkout);
		
});