jQuery(window).on('load' , function(){
	var saved_id = jQuery('#saved_id').val();
	if(saved_id != '' && saved_id != 0){
		members_subaccount_customizer_default();		
	}
	
});

jQuery(document).ready(function(){
	members_subaccount_customizer();
	
	t_editor();
	
	jQuery('.saveSubaccountData').click(function(){
		saveSubaccountData();
	});
	
	
	jQuery('.check_availability_page_btn').click(function(e){
		e.preventDefault();
		dap_member_show_loader();
		
		var page_type = jQuery(this).attr('data-id');
		var page_name = jQuery('#'+page_type).val();
		
		jQuery('.success_'+page_type).hide();
		jQuery('.error_'+page_type).hide();
		
		if(page_name != '') {
			jQuery(this).text("Checking..."); 
			jQuery.post(ajaxurl, {
					action: 'dapcheckPageAvailabilityAjax',
					page_name: page_name,
			}, function(response) {
				dap_member_hide_loader(); 
				
				response = response.split("||");
				if (response[0] == 'yes') {
					jQuery('.success_'+page_type).hide();
					jQuery('.error_'+page_type).show();
				} else if (response[0] == 'no') {
					jQuery('.error_'+page_type).hide();
					jQuery('.success_'+page_type).show();
				}
				jQuery('.check_availability_page_btn').text("Check Availability");
				/*setTimeout(function(){ 
					jQuery('.success_'+page_type).hide();
					jQuery('.error_'+page_type).hide();
				 }, 3000);*/
				
			});
				
		}else{
			swal('Please enter a name. Name cannot be empty.')	
		}
	});
	
	
	jQuery('#billing_info').change(function(){
		if(jQuery(this).prop('checked') == true){
			jQuery('.show_subaccount_billing_info_section').attr('style',  'display:block !important');
			jQuery('.sub_billing_info_section').attr('style',  'display:flex !important');
			jQuery('.billingInfoCustomizeOuter').attr('style',  'display:flex !important');
		}else{
			jQuery('.show_subaccount_billing_info_section').attr('style',  'display:none !important');
			jQuery('.sub_billing_info_section').attr('style',  'display:none !important');
			jQuery('.billingInfoCustomizeOuter').attr('style',  'display:none !important');
		}
	});
	
	jQuery('#additional_info').change(function(){
		if(jQuery(this).prop('checked') == true){
			jQuery('.show_subaccount_additional_info_section').attr('style',  'display:block !important');
			jQuery('.sub_subaccount_custom_fields_section').attr('style',  'display:flex !important');
		}else{
			jQuery('.show_subaccount_additional_info_section').attr('style',  'display:none !important');
			jQuery('.sub_subaccount_custom_fields_section').attr('style',  'display:none !important');
		}
	});
	
	jQuery('.billing_info_toggle').change(function(){
		var key = jQuery(this).attr('data-id');
	
		if(jQuery(this).prop('checked') == true){
			jQuery('.u_'+key).attr('style',  'display:flex !important');
		}else{
			jQuery('.u_'+key).attr('style',  'display:none !important');
		}
	});
	
	
	/***Custom Fields ************/
	jQuery('.add_additional').change(function(e) {
		var add_additional_val = jQuery(this).val();
		var add_additional_name = jQuery(this).attr('data-id');
		var add_additional_type = jQuery(this).attr('data-type');
		var add_additional_label = jQuery(this).attr('data-label-type');
		if (this.checked == true) {
			var length_additional = jQuery('.addtional_info_outer').find('#id_' + this.id).length;
			if (length_additional == 0) {
				if (add_additional_type == "dropdown") {
					var split_data = add_additional_val.split(",");
					var selectedHtml = "";
					jQuery.each(split_data, function(key, value) {
						selectedHtml = selectedHtml + '<option value="' + value + '">' + value + '</option>';
					});
					//jQuery('.addtional_info_outer').find('.append_new').append("<div id='id_" + this.id + "' class='col-sm-12 input-col custom_add_fields input-field1 padding-rt-lt " + this.id + "'><label class='editable'>" + add_additional_label + "</label><select name='custom_" + add_additional_name + "' id='custom_" + add_additional_name + "'  class='form-control'>"+selectedHtml+"</select><div class='required_class' id='req_custom_" + add_additional_name + "' style='display:none'></div></div>");
					jQuery('.addtional_info_outer').find('.append_new').append("<div id='id_" + this.id + "' class='form-group row show_email_section " + this.id + "'><div class='col-sm-4 d-flex align-items-center'><label class='editable'>" + add_additional_label + "</label></div><div class='col-sm-8'><select name='custom_" + add_additional_name + "' id='custom_" + add_additional_name + "'  class='form-control'>"+selectedHtml+"</select></div></div>");	
					
				} else if (add_additional_type == "checkbox") {
					var split_data = add_additional_val.split(",");
					var selectedHtml = "";
					jQuery.each(split_data, function(key, value) {
						selectedHtml = selectedHtml + '<input type="checkbox" name="custom_chk_' + add_additional_name + '" id="custom_chk_' + add_additional_name + '" value="' + value + '" class="form-control"><span class="btn-labl">' + value + '</span>';
					});
					//jQuery('.addtional_info_outer').find('.append_new').append("<div id='id_" + this.id + "' class='col-sm-12 input-col custom_add_fields input-field1 padding-rt-lt " + this.id + "'><label class='editable'>" + add_additional_label + "</label>" + selectedHtml + "<input type='hidden'  class='form-control' name='custom_" + add_additional_name + "' id='custom_" + add_additional_name + "' /><div class='required_class' id='req_custom_" + add_additional_name + "' style='display:none'></div></div>");
					jQuery('.addtional_info_outer').find('.append_new').append("<div id='id_" + this.id + "' class='col-sm-12 input-col custom_add_fields input-field1 padding-rt-lt " + this.id + "'><label class='editable'>" + add_additional_label + "</label><div class='col-sm-8'>" + selectedHtml + "</div></div>	");		
					
				} else if (add_additional_type == "radio") {
					var split_data = add_additional_val.split(",");
					var selectedHtml = "";
					jQuery.each(split_data, function(key, value) {
						selectedHtml = selectedHtml + '<input type="radio" class="form-control" name="custom_' + add_additional_name + '"  id="custom_' + add_additional_name + '" value="' + value + '"><span class="btn-labl">' + value + '</span>';
					});
					//jQuery('.addtional_info_outer').find('.append_new').append("<div id='id_" + this.id + "' class='col-sm-12 input-col custom_add_fields input-field1 padding-rt-lt " + this.id + "'><label class='editable'>" + add_additional_label + "</label>" + selectedHtml + " <div class='required_class' id='req_custom_" + add_additional_name + "' style='display:none'></div>");
					jQuery('.addtional_info_outer').find('.append_new').append("<div id='id_" + this.id + "' class='form-group row show_email_section " + this.id + "'><div class='col-sm-4 d-flex align-items-center'><label class='editable'>" + add_additional_label + "</label></div><div class='col-sm-8'>" + selectedHtml + "</div></div>");
				} else if (add_additional_type == "textarea") {
					//jQuery('.addtional_info_outer').find('.append_new').append("<div id='id_" + this.id + "' class='col-sm-12 input-col custom_add_fields input-field1 padding-rt-lt " + this.id + "'><label class='editable'>" + add_additional_label + "</label><textarea type='text' name='custom_" + add_additional_name + "' id='custom_" + add_additional_name + "' class='form-control' rows='4' cols='10' placeholder='" + add_additional_label + "'></textarea><div class='required_class' id='req_custom_" + add_additional_name + "' style='display:none'></div></div>");
					jQuery('.addtional_info_outer').find('.append_new').append("<div id='id_" + this.id + "' class='form-group row show_email_section " + this.id + "'><div class='col-sm-4 d-flex align-items-center'><label class='editable'>" + add_additional_label + "</label></div><div class='col-sm-8'><textarea type='text' name='custom_" + add_additional_name + "' id='custom_" + add_additional_name + "' class='form-control' rows='4' cols='10' placeholder='" + add_additional_label + "'></textarea></div></div>");
					
				} else {
					//jQuery('.addtional_info_outer').find('.append_new').append("<div id='id_" + this.id + "' class='col-sm-12 input-col custom_add_fields input-field1 padding-rt-lt " + this.id + "'><label class='editable'>" + add_additional_label + "</label><input type='text' name='custom_" + add_additional_name + "' id='custom_" + add_additional_name + "' class='form-control' placeholder='" + add_additional_label + "' value='" + add_additional_val + "'><div class='required_class' id='req_custom_" + add_additional_name + "' style='display:none'></div></div>");
					jQuery('.addtional_info_outer').find('.append_new').append("<div id='id_" + this.id + "' class='form-group row show_email_section " + this.id + "'><div class='col-sm-4 d-flex align-items-center'><label class='editable'>" + add_additional_label + "</label></div><div class='col-sm-8'><input type='text' name='custom_" + add_additional_name + "' id='custom_" + add_additional_name + "' class='form-control' placeholder='" + add_additional_label + "' value=''></div></div>	");
				}
			
			}
		
		} else {
			jQuery('.addtional_info_outer').find('.' + this.id).remove();
		}
	});
	/***Custom Fields************/
	
	
	/*****Next previous button**********/
	
	jQuery('.next_btn').click(function(){
		gotoTab('next');
	});
	
	/*****Next previous button end**********/
	
	
});	


function members_subaccount_customizer_default(){
	
	/*****Table customizer***********/
	
	var tempWidth = jQuery('.manageSubaccountTableOuter').css('width');
	var tempBorderWidth = jQuery('.manageSubaccountTableOuter').css('border-width');
	var tempBorderRadius = jQuery('.manageSubaccountTableOuter').css('border-radius');
	var tempBorderColor = jQuery('.manageSubaccountTableOuter').css('border-color');
	var tempBorderStyle = jQuery('.manageSubaccountTableOuter').css('border-style');
	var tempFloat= jQuery('.manageSubaccountTableOuter').css('float');
	var tempBGColor = jQuery('.manageSubaccountTableOuter').css('background-color');
	var tableHeadBGColor = jQuery('.tableHead').css('background-color');
	
	tempWidth = tempWidth.split("px");
	var tempWidth = tempWidth[0];
	tempWidth = parseInt(tempWidth);
	jQuery("#table_width").bootstrapSlider('setValue', tempWidth); 
	
	tempBorderWidth = tempBorderWidth.split("px");
	var tempBorderWidth = tempBorderWidth[0];
	tempBorderWidth = parseInt(tempBorderWidth);
	jQuery("#table_border_width").bootstrapSlider('setValue', tempBorderWidth); 
	
	tempBorderRadius = tempBorderRadius.split("px");
	var tempBorderRadius = tempBorderRadius[0];
	tempBorderRadius = parseInt(tempBorderRadius);
	jQuery("#table_border_radius").bootstrapSlider('setValue', tempBorderRadius); 
		
	jQuery('#table_background_clr_div').colorpicker('setValue', tempBGColor);	
	jQuery('#table_section_header_background_clr_div').colorpicker('setValue', tableHeadBGColor);	
	jQuery('#table_border_clr_div').colorpicker('setValue', tempBorderColor);	
	
	
	/****Button customizer***********/
	
	var text = jQuery('.add_subaccount_btn').text();
	var buttonFontSize = jQuery('.add_subaccount_btn').css('font-size');
	var buttonBorderWidth = jQuery('.add_subaccount_btn').css('border-width');
	var buttonBorderRadius = jQuery('.add_subaccount_btn').css('border-radius');
	var buttonWidth = jQuery('.add_subaccount_btn').css('width');
	var buttonHeight = jQuery('.add_subaccount_btn').css('padding-top');
	var buttonBGColor = jQuery('.add_subaccount_btn').css('background-color');
	var buttonBorderColor = jQuery('.add_subaccount_btn').css('border-color');
	var buttonColor = jQuery('.add_subaccount_btn').css('color');
	var buttonBorderStyle = jQuery('.add_subaccount_btn').css('border-style');
	var buttonFontWeight = jQuery('.add_subaccount_btn').css('font-weight');
	
	jQuery('#add_new_btn_text').val(text);
	
	buttonFontSize = buttonFontSize.split("px");
	var buttonFontSize = buttonFontSize[0];
	buttonFontSize = parseInt(buttonFontSize);
	jQuery("#add_new_font_size").bootstrapSlider('setValue', buttonFontSize); 
	
	buttonBorderWidth = buttonBorderWidth.split("px");
	var buttonBorderWidth = buttonBorderWidth[0];
	buttonBorderWidth = parseInt(buttonBorderWidth);
	jQuery("#add_new_border_width").bootstrapSlider('setValue', buttonBorderWidth); 
	
	buttonBorderRadius = buttonBorderRadius.split("px");
	var buttonBorderRadius = buttonBorderRadius[0];
	buttonBorderRadius = parseInt(buttonBorderRadius);
	jQuery("#add_new_border_radius").bootstrapSlider('setValue', buttonBorderRadius); 
	
	buttonWidth = buttonWidth.split("px");
	var buttonWidth = buttonWidth[0];
	buttonWidth = parseInt(buttonWidth);
	jQuery("#add_new_button_width").bootstrapSlider('setValue', buttonWidth); 
	
	buttonHeight = buttonHeight.split("px");
	var buttonHeight = buttonHeight[0];
	buttonHeight = parseInt(buttonHeight);
	jQuery("#add_new_button_height").bootstrapSlider('setValue', buttonHeight); 
	
	
	jQuery('#add_new_background_clr_div').colorpicker('setValue', buttonBGColor);	
	jQuery('#add_new_border_clr_div').colorpicker('setValue', buttonBorderColor);	
	jQuery('#add_new_text_clr_div').colorpicker('setValue', buttonColor);	
	jQuery('#add_new_bdr_style').val(buttonBorderStyle);	
	jQuery('#add_new_font_weight').val(buttonFontWeight);	
	
	
	/*****Form Customizer*************/
	
	var tempBGColor = jQuery('.dap_member_subaccount_inner').css('background-color');
	var tempProBGColor = jQuery('.show_subaccount_product_details_section').css('background-color');
	var tempAccBGColor = jQuery('.show_subaccount_account_info_section').css('background-color');
	var tempBillBGColor = jQuery('.show_subaccount_billing_info_section').css('background-color');
	var tempAddBGColor = jQuery('.show_subaccount_additional_info_sections').css('background-color');
	var tempBorderColor = jQuery('.dap_member_subaccount_inner').css('border-color');
	var tempAlign = jQuery('.dap_member_subaccount_outer').css('text-align');
	var tempWidth = jQuery('.dap_member_subaccount_inner').css('width');
	var tempBorderWidth = jQuery('.dap_member_subaccount_inner').css('border-width');
	var tempBorderRadius = jQuery('.dap_member_subaccount_inner').css('border-radius');
	var temppaddingTop = jQuery('.dap_member_subaccount_inner').css('padding-top');
	var tempPaddingBottom = jQuery('.dap_member_subaccount_inner').css('padding-bottom');
	var tempBorderStyle = jQuery('.dap_member_subaccount_inner').css('border-style');
	
	jQuery('#temp_background_outer_color_div').colorpicker('setValue', tempBGColor);	
	jQuery('#product_background_color_div').colorpicker('setValue', tempProBGColor);	
	jQuery('#account_background_color_div').colorpicker('setValue', tempAccBGColor);	
	jQuery('#billing_background_color_div').colorpicker('setValue', tempBillBGColor);	
	jQuery('#additional_background_color_div').colorpicker('setValue', tempAddBGColor);	
	jQuery('#temp_frnt_bdr_color_div').colorpicker('setValue', tempBorderColor);	
	
	jQuery('#dm_subaccount_temp_aligment').val(tempAlign);
	
	tempWidth = tempWidth.split("px");
	var tempWidth = tempWidth[0];
	tempWidth = parseInt(tempWidth);
	jQuery("#temp_frnt_wid").bootstrapSlider('setValue', tempWidth); 
	
	tempBorderWidth = tempBorderWidth.split("px");
	var tempBorderWidth = tempBorderWidth[0];
	tempBorderWidth = parseInt(tempBorderWidth);
	jQuery("#temp_frnt_bdr_wid").bootstrapSlider('setValue', tempBorderWidth); 
	
	tempBorderRadius = tempBorderRadius.split("px");
	var tempBorderRadius = tempBorderRadius[0];
	tempBorderRadius = parseInt(tempBorderRadius);
	jQuery("#temp_frnt_br_radius").bootstrapSlider('setValue', tempBorderRadius); 
		
	temppaddingTop = temppaddingTop.split("px");
	var temppaddingTop = temppaddingTop[0];
	temppaddingTop = parseInt(temppaddingTop);
	jQuery("#temp_frnt_padd_top").bootstrapSlider('setValue', temppaddingTop); 
	
	tempPaddingBottom = tempPaddingBottom.split("px");
	var tempPaddingBottom = tempPaddingBottom[0];
	tempPaddingBottom = parseInt(tempPaddingBottom);
	jQuery("#temp_frnt_padd_bottom").bootstrapSlider('setValue', tempPaddingBottom); 

	jQuery('#temp_frnt_bdr_style').val(tempBorderStyle);
	
	
	
	/*********Create Button************/
	
	var createSubButtonWidth = jQuery('.createSubaccountButton').css('width');
	var createSubButtonBorderWidth = jQuery('.createSubaccountButton').css('border-width');
	var createSubButtonBorderRadius = jQuery('.createSubaccountButton').css('border-radius');
	var createSubButtonStyle = jQuery('.createSubaccountButton').css('border-style');
	var createSubButtonBorderColor = jQuery('.createSubaccountButton').css('border-color');
	var createSubButtonBGColor = jQuery('.createSubaccountButton').css('background-color');
	
	createSubButtonWidth = createSubButtonWidth.split("px");
	var createSubButtonWidth = createSubButtonWidth[0];
	createSubButtonWidth = parseInt(createSubButtonWidth);
	jQuery("#create_subaccount_btn_width").bootstrapSlider('setValue', createSubButtonWidth); 
	
	createSubButtonBorderWidth = createSubButtonBorderWidth.split("px");
	var createSubButtonBorderWidth = createSubButtonBorderWidth[0];
	createSubButtonBorderWidth = parseInt(createSubButtonBorderWidth);
	jQuery("#create_subaccount_btn_border_width").bootstrapSlider('setValue', createSubButtonBorderWidth); 
	
	createSubButtonBorderRadius = createSubButtonBorderRadius.split("px");
	var createSubButtonBorderRadius = createSubButtonBorderRadius[0];
	createSubButtonBorderRadius = parseInt(createSubButtonBorderRadius);
	jQuery("#create_subaccount_btn_border_radius").bootstrapSlider('setValue', createSubButtonBorderRadius); 
	
	jQuery('#create_subaccount_btn_frnt_bdr_style').val(createSubButtonStyle);
	jQuery('#create_subaccount_btn_background_outer_color_div').colorpicker('setValue', createSubButtonBGColor);	
	jQuery('#create_subaccount_btn_frnt_bdr_color_div').colorpicker('setValue', createSubButtonBorderColor);	
	
			
}


function members_subaccount_customizer(){
	
	/*****Table customizer***********/
	
	
	jQuery('#table_width').bootstrapSlider().change(function() {
		jQuery('.manageSubaccountTableOuter').css('width',this.value + 'px');
	});
	
	jQuery('#table_border_width').bootstrapSlider().change(function() {
		jQuery('.manageSubaccountTableOuter').css('border-width',this.value + 'px');
	});	
	
	jQuery('#table_border_radius').bootstrapSlider().change(function() {
		jQuery('.manageSubaccountTableOuter').css('border-radius',this.value + 'px');
	});	
	
	jQuery('#table_background_clr_div').colorpicker().on('changeColor',function(){
		jQuery('.manageSubaccountTableOuter').css('background-color', jQuery(this).colorpicker('getValue'));
	});
	
	jQuery('#table_section_header_background_clr_div').colorpicker().on('changeColor',function(){
		jQuery('.tableHead').css('background-color', jQuery(this).colorpicker('getValue'));
	});
	
	jQuery('#table_border_clr_div').colorpicker().on('changeColor',function(){
		jQuery('.manageSubaccountTableOuter').css('border-color', jQuery(this).colorpicker('getValue'));
	});
	
	jQuery('#table_bdr_style').change(function(){
		jQuery('.manageSubaccountTableOuter').css('border-style', jQuery(this).val());
	});
	
	jQuery('#table_alignment').change(function(){
		jQuery('.manageSubaccountTableOuter').css('float', jQuery(this).val());
	});
	
	/****Button customizer***********/
	
	jQuery('#add_new_btn_text').keyup(function() {
		jQuery('.add_subaccount_btn').text(jQuery(this).val());
	});
	
	jQuery('#add_new_font_size').bootstrapSlider().change(function() {
		jQuery('.add_subaccount_btn').css('font-size',this.value + 'px');
	});
	
	jQuery('#add_new_border_width').bootstrapSlider().change(function() {
		jQuery('.add_subaccount_btn').css('border-width',this.value + 'px');
	});	
		 
	jQuery('#add_new_border_radius').bootstrapSlider().change(function() {
		jQuery('.add_subaccount_btn').css('border-radius',this.value + 'px');
	});		 
	
	jQuery('#add_new_button_width').bootstrapSlider().change(function() {
		jQuery('.add_subaccount_btn').css('max-width', this.value + 'px');
		jQuery('.add_subaccount_btn').css('width', this.value + 'px');
	});
	
	jQuery('#add_new_button_height').bootstrapSlider().change(function() {
		jQuery('.add_subaccount_btn').css('padding-top', this.value + 'px');
		jQuery('.add_subaccount_btn').css('padding-bottom', this.value + 'px');
	});
	
	jQuery('#add_new_background_clr_div').colorpicker().on('changeColor',function(){
		jQuery('.add_subaccount_btn').css('background-color', jQuery(this).colorpicker('getValue'));
	});
	
	jQuery('#add_new_border_clr_div ').colorpicker().on('changeColor',function(){
		jQuery('.add_subaccount_btn').css('border-color', jQuery(this).colorpicker('getValue'));
	});
	
	jQuery('#add_new_text_clr_div').colorpicker().on('changeColor',function(){
		jQuery('.add_subaccount_btn').css('color', jQuery(this).colorpicker('getValue'));
	}); 
	                      	
	jQuery('#add_new_bdr_style').change(function(){
		jQuery('.add_subaccount_btn').css('border-style', jQuery(this).val());
	});
	                      	
	jQuery('#add_new_font_weight').change(function(){
		jQuery('.add_subaccount_btn').css('font-weight', jQuery(this).val());
	});

	/******bulk btn customizer start************/

	jQuery('#add_bulk_btn_text').keyup(function() {
		jQuery('.add_subaccount_bulk_btn').text(jQuery(this).val());
	});
	
	jQuery('#add_bulk_font_size').bootstrapSlider().change(function() {
		jQuery('.add_subaccount_bulk_btn').css('font-size',this.value + 'px');
	});
	
	jQuery('#add_bulk_border_width').bootstrapSlider().change(function() {
		jQuery('.add_subaccount_bulk_btn').css('border-width',this.value + 'px');
	});	
		 
	jQuery('#add_bulk_border_radius').bootstrapSlider().change(function() {
		jQuery('.add_subaccount_bulk_btn').css('border-radius',this.value + 'px');
	});		 
	
	jQuery('#add_bulk_button_width').bootstrapSlider().change(function() {
		jQuery('.add_subaccount_bulk_btn').css('max-width', this.value + 'px');
		jQuery('.add_subaccount_bulk_btn').css('width', this.value + 'px');
	});
	
	jQuery('#add_bulk_button_height').bootstrapSlider().change(function() {
		jQuery('.add_subaccount_bulk_btn').css('padding-top', this.value + 'px');
		jQuery('.add_subaccount_bulk_btn').css('padding-bottom', this.value + 'px');
	});
	
	jQuery('#add_bulk_background_clr_div').colorpicker().on('changeColor',function(){
		jQuery('.add_subaccount_bulk_btn').css('background-color', jQuery(this).colorpicker('getValue'));
	});
	
	jQuery('#add_bulk_border_clr_div ').colorpicker().on('changeColor',function(){
		jQuery('.add_subaccount_bulk_btn').css('border-color', jQuery(this).colorpicker('getValue'));
	});
	
	jQuery('#add_bulk_text_clr_div').colorpicker().on('changeColor',function(){
		jQuery('.add_subaccount_bulk_btn').css('color', jQuery(this).colorpicker('getValue'));
	}); 
	                      	
	jQuery('#add_bulk_bdr_style').change(function(){
		jQuery('.add_subaccount_bulk_btn').css('border-style', jQuery(this).val());
	});
	                      	
	jQuery('#add_bulk_font_weight').change(function(){
		jQuery('.add_subaccount_bulk_btn').css('font-weight', jQuery(this).val());
	});

	jQuery('#add_bulk_btn_enable').change(function(){
		if(jQuery(this).prop('checked') == true){
			if(jQuery('.add_bulk_btn_outer').length == 0){
				var html = '<div class="editable product_detail_inner add_bulk_btn_outer add_subaccount_bulk_btn common_btn mce-content-body" style="border: none rgb(102, 147, 183); font-weight: 600; box-shadow: rgba(0, 0, 0, 0.2) 2px 2px 10px; font-size: 16px; border-radius: 5px; padding: 15px 24px; background-color: rgb(102, 147, 183); color: rgb(255, 255, 255); position: relative; max-width: 140px; width: 140px;" id="mce_4" contenteditable="true" spellcheck="false">Add in Bulk</div>';
				jQuery('.top_product_actions').prepend(html);
			}
			jQuery('.add_bulk_btn_outer').show();
			jQuery('.customize_bulk_add_tab_outer').show();
		}else{
			jQuery('.add_bulk_btn_outer').hide();
			jQuery('.customize_bulk_add_tab_outer').hide();
		}
	});

	/******bulk btn customizer end************/



	
	
	/*****Form Customizer*************/
	
	jQuery('#temp_background_outer_color_div').colorpicker().on('changeColor',function(){
		jQuery('.dap_member_subaccount_inner').css('background-color', jQuery(this).colorpicker('getValue'));
	});
	
	jQuery('#product_background_color_div').colorpicker().on('changeColor',function(){
		jQuery('.show_subaccount_product_details_section').css('background-color', jQuery(this).colorpicker('getValue'));
	});
	
	jQuery('#account_background_color_div').colorpicker().on('changeColor',function(){
		jQuery('.show_subaccount_account_info_section').css('background-color', jQuery(this).colorpicker('getValue'));
	});
	
	jQuery('#billing_background_color_div').colorpicker().on('changeColor',function(){
		jQuery('.show_subaccount_billing_info_section').css('background-color', jQuery(this).colorpicker('getValue'));
	});
	
	jQuery('#additional_background_color_div').colorpicker().on('changeColor',function(){
		jQuery('.show_subaccount_additional_info_sections').css('background-color', jQuery(this).colorpicker('getValue'));
	});
	
	jQuery('#temp_frnt_bdr_color_div').colorpicker().on('changeColor',function(){
		jQuery('.dap_member_subaccount_inner').css('border-color', jQuery(this).colorpicker('getValue'));
	});
	
	jQuery('#dm_subaccount_temp_aligment').change(function(){
		jQuery('.dap_member_subaccount_outer').css('text-align', jQuery(this).val());
	});
	
	jQuery('#temp_frnt_wid').bootstrapSlider().change(function() {
		jQuery('.dap_member_subaccount_inner').css('max-width', this.value + 'px');
		jQuery('.dap_member_subaccount_inner').css('width', this.value + 'px');
	});
	
	jQuery('#temp_frnt_bdr_wid').bootstrapSlider().change(function() {
		jQuery('.dap_member_subaccount_inner').css('border-width',this.value + 'px');
	});	
	
	jQuery('#temp_frnt_br_radius').bootstrapSlider().change(function() {
		jQuery('.dap_member_subaccount_inner').css('border-radius',this.value + 'px');
	});	
	
	jQuery('#temp_frnt_padd_top').bootstrapSlider().change(function() {
		jQuery('.dap_member_subaccount_inner').css('padding-top',this.value + 'px');
	});	
	
	jQuery('#temp_frnt_padd_bottom').bootstrapSlider().change(function() {
		jQuery('.dap_member_subaccount_inner').css('padding-bottom',this.value + 'px');
	});	
		
	jQuery('#temp_frnt_bdr_style').change(function(){
		jQuery('.dap_member_subaccount_inner').css('border-style', jQuery(this).val());
	});
	

	/*******bulk action form start*******/

	jQuery('#product_background_bulk_color_div').colorpicker().on('changeColor',function(){
		jQuery('.show_subaccount_bulk_product_details_section').css('background-color', jQuery(this).colorpicker('getValue'));
	});
	
	jQuery('#csv_background_bulk_color_div').colorpicker().on('changeColor',function(){
		jQuery('.show_subaccount_bulk_csv_info_section').css('background-color', jQuery(this).colorpicker('getValue'));
	});
	
	jQuery('#fields_background_bulk_color_div').colorpicker().on('changeColor',function(){
		jQuery('.show_subaccount_bulk_field_info_section').css('background-color', jQuery(this).colorpicker('getValue'));
	});

	/*******bulk action form end*******/
	
	/*********Create Button************/
	
	jQuery('#create_subaccount_btn_width').bootstrapSlider().change(function() {
		jQuery('.createSubaccountButton').css('max-width', this.value + 'px');
		jQuery('.createSubaccountButton').css('width', this.value + 'px');
	});	
	
	jQuery('#create_subaccount_btn_background_outer_color_div').colorpicker().on('changeColor',function(){
		jQuery('.createSubaccountButton').css('background-color', jQuery(this).colorpicker('getValue'));
	});
	
	jQuery('#create_subaccount_btn_frnt_bdr_style').change(function(){
		jQuery('.createSubaccountButton').css('border-style', jQuery(this).val());
	});
	
	jQuery('#create_subaccount_btn_border_width').bootstrapSlider().change(function() {
		jQuery('.createSubaccountButton').css('border-width',this.value + 'px');
	});
	
	jQuery('#create_subaccount_btn_border_radius').bootstrapSlider().change(function() {
		jQuery('.createSubaccountButton').css('border-radius',this.value + 'px');
	});
	
	jQuery('#create_subaccount_btn_frnt_bdr_color_div').colorpicker().on('changeColor',function(){
		jQuery('.createSubaccountButton').css('border-color', jQuery(this).colorpicker('getValue'));
	});

	/******bulk create button start******/

	jQuery('#create_subaccount_bulk_btn_width').bootstrapSlider().change(function() {
		jQuery('.createSubaccountBulkButton').css('max-width', this.value + 'px');
		jQuery('.createSubaccountBulkButton').css('width', this.value + 'px');
	});	
	
	jQuery('#create_subaccount_bulk_btn_background_outer_color_div').colorpicker().on('changeColor',function(){
		jQuery('.createSubaccountBulkButton').css('background-color', jQuery(this).colorpicker('getValue'));
	});
	
	jQuery('#create_subaccount_bulk_btn_frnt_bdr_style').change(function(){
		jQuery('.createSubaccountBulkButton').css('border-style', jQuery(this).val());
	});
	
	jQuery('#create_subaccount_bulk_btn_border_width').bootstrapSlider().change(function() {
		jQuery('.createSubaccountBulkButton').css('border-width',this.value + 'px');
	});
	
	jQuery('#create_subaccount_bulk_btn_border_radius').bootstrapSlider().change(function() {
		jQuery('.createSubaccountBulkButton').css('border-radius',this.value + 'px');
	});
	
	jQuery('#create_subaccount_bulk_btn_frnt_bdr_color_div').colorpicker().on('changeColor',function(){
		jQuery('.createSubaccountBulkButton').css('border-color', jQuery(this).colorpicker('getValue'));
	});

	/******bulk create button end******/
	
			
}


function t_editor() {
	tinymce.init({
		selector: '.editable',
		inline: true,
		height: 500,
		theme: 'modern',
		force_br_newlines: true,
		force_p_newlines: false,
		resize: "both",
		object_resizing: "img",
		forced_root_block: '',
		fontsize_formats: "8pt 9pt 10pt 11pt 12pt 13pt 14pt 15pt 16pt 17pt 18pt 19pt 20pt 22pt 24pt 26pt 30pt",
		theme_advanced_fonts: "Andale Mono=andale mono,times;" + "Arial=arial,helvetica,sans-serif;" + "Arial Black=arial black,avant garde;" + "Book Antiqua=book antiqua,palatino;" + "Comic Sans MS=comic sans ms,sans-serif;" + "Courier New=courier new,courier;" + "Georgia=georgia,palatino;" + "Helvetica=helvetica;" + "Impact=impact,chicago;" + "Symbol=symbol;" + "Tahoma=tahoma,arial,helvetica,sans-serif;" + "Terminal=terminal,monaco;" + "Times New Roman=times new roman,times;" + "Trebuchet MS=trebuchet ms,geneva;" + "Verdana=verdana,geneva;" + "Webdings=webdings;" + "Wingdings=wingdings,zapf dingbats",
		/*plugins: ['advlist autolink lists link image charmap print preview hr anchor pagebreak', 'searchreplace wordcount visualblocks visualchars code fullscreen', 'insertdatetime media nonbreaking save table contextmenu directionality', 'emoticons template paste textcolor colorpicker textpattern imagetools'],*/
		plugins: [' advlist autolink lists link image charmap print preview hr anchor pagebreak', 'searchreplace wordcount visualblocks visualchars code fullscreen',  'table',  'emoticons template paste textcolor colorpicker textpattern imagetools'],
		toolbar1: 'insertfile undo redo | styleselect | bold italic |  fontselect | fontsizeselect | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
		toolbar2: 'print preview media | forecolor backcolor emoticons | codesample',
		image_advtab: true,
		templates: [{
			title: 'Test template 1',
			content: 'Test 1'
		}, {
			title: 'Test template 2',
			content: 'Test 2'
		}]
	});
}



function saveSubaccountData(){	
	jQuery(this).text('Saving..');
	var subaccountTableBody = jQuery('.subaccountTableBody').html();
//	var subaccountFrontendTableBody = jQuery('.frontendTableData').html();
	var firstName = jQuery('.subaccountTableBody').find('.tableFirstName').html();
	var lastName = jQuery('.subaccountTableBody').find('.tableLastName').html();
	var email = jQuery('.subaccountTableBody').find('.tableEmail').html();
	var productName = jQuery('.subaccountTableBody').find('.tableProduct').html();
	
	jQuery('.frontendTableData').find('.frontTableFirstName').html(firstName);
	jQuery('.frontendTableData').find('.frontTableLastName').html(lastName);
	jQuery('.frontendTableData').find('.frontTableEmail').html(email);
	jQuery('.frontendTableData').find('.frontTableProductName').html(productName);
	
	var subaccountFrontendTableBody = '<tr><td class="frontTableFirstName">'+firstName+'</td><td class="frontTableEmail">'+email+'</td><td><span title="[USERPRODUCTNAME]" class="frontTableProductName">'+productName+'</span></td><td class="select_action_outer"><div name="select_action" class="btn-group"><input type="hidden" id="" value=""><a class="edit_subaccount_btn edit-btn btn btn-secondary btn-sm" data-id="[ROWPRODUCTID]" data-key="[ROWUSERID]"  href="#"><i class="fas fa-pencil-alt"></i></a><a class="delete_subaccount_btn del-btn btn btn-danger btn-sm" title="Delete" data-id="[ROWPRODUCTID]" data-key="[ROWUSERID]"  href="#"><i class="fas fa-trash-alt"></i></a></div></td></tr>';
	
	jQuery('.frontendTableData').html(subaccountFrontendTableBody);
	
	if(jQuery('.frontendTableData').find('.frontTableFirstName').find(':first-child').find(':last').length == 0){
		if(jQuery('.frontendTableData').find('.frontTableFirstName').find(':first-child').length == 0){
			jQuery('.frontendTableData').find('.frontTableFirstName').text('[FIRST_NAME]');
		}else{
			jQuery('.frontendTableData').find('.frontTableFirstName').find(':first-child').text('[FIRST_NAME]');
		}
	}else{
		jQuery('.frontendTableData').find('.frontTableFirstName').find(':last').text('[FIRST_NAME]');
	}
	
	if(jQuery('.frontendTableData').find('.frontTableLastName').find(':first-child').find(':last').length == 0){
		if(jQuery('.frontendTableData').find('.frontTableLastName').find(':first-child').length == 0){
			jQuery('.frontendTableData').find('.frontTableLastName').text('[LAST_NAME]');
		}else{
			jQuery('.frontendTableData').find('.frontTableLastName').find(':first-child').text('[LAST_NAME]');
		}
	}else{
		jQuery('.frontendTableData').find('.frontTableLastName').find(':last').text('[LAST_NAME]');
	}
	
	if(jQuery('.frontendTableData').find('.frontTableEmail').find(':first-child').find(':last').length == 0){
		if(jQuery('.frontendTableData').find('.frontTableEmail').find(':first-child').length == 0){
			jQuery('.frontendTableData').find('.frontTableEmail').text('[EMAIL]');
		}else{
			jQuery('.frontendTableData').find('.frontTableEmail').find(':first-child').text('[EMAIL]');
		}
	}else{
		jQuery('.frontendTableData').find('.frontTableEmail').find(':last').text('[EMAIL]');
	}
	
	if(jQuery('.frontendTableData').find('.frontTableProductName').find(':first-child').find(':last').length == 0){
		if(jQuery('.frontendTableData').find('.frontTableProductName').find(':first-child').length == 0){
			jQuery('.frontendTableData').find('.frontTableProductName').text('[USERPRODUCTNAME]');
		}else{
			jQuery('.frontendTableData').find('.frontTableProductName').find(':first-child').text('[USERPRODUCTNAME]');
		}
	}else{
		jQuery('.frontendTableData').find('.frontTableProductName').find(':last').text('[USERPRODUCTNAME]');
	}
	
	/*Seats start*/
	
	var total_seats_backend = jQuery('.total_seats_backend').html();
	var used_seats_backend = jQuery('.used_seats_backend').html();
	var remaining_seats_backend = jQuery('.remaining_seats_backend').html();
	
	jQuery('.total_seats_frontend').html(total_seats_backend);
	jQuery('.used_seats_frontend').html(used_seats_backend);
	jQuery('.remaining_seats_frontend').html(remaining_seats_backend);
	
	if(jQuery('.total_seats_frontend').find(':first-child').find(':last').length == 0){
		if(jQuery('.total_seats_frontend').find(':first-child').length == 0){
			jQuery('.total_seats_frontend').text('[TOTALSEATS]');
		}else{
			jQuery('.total_seats_frontend').find(':first-child').text('[TOTALSEATS]');
		}
	}else{
		jQuery('.total_seats_frontend').find(':last').text('[TOTALSEATS]');
	}
	
	if(jQuery('.used_seats_frontend').find(':first-child').find(':last').length == 0){
		if(jQuery('.used_seats_frontend').find(':first-child').length == 0){
			jQuery('.used_seats_frontend').text('[USEDSEATS]');
		}else{
			jQuery('.used_seats_frontend').find(':first-child').text('[USEDSEATS]');
		}
	}else{
		jQuery('.used_seats_frontend').find(':last').text('[USEDSEATS]');
	}
	
	if(jQuery('.remaining_seats_frontend').find(':first-child').find(':last').length == 0){
		if(jQuery('.remaining_seats_frontend').find(':first-child').length == 0){
			jQuery('.remaining_seats_frontend').text('[REMAININGSEATS]');
		}else{
			jQuery('.remaining_seats_frontend').find(':first-child').text('[REMAININGSEATS]');
		}
	}else{
		jQuery('.remaining_seats_frontend').find(':last').text('[REMAININGSEATS]');
	}
	
	
	/*Seats end*/
	
	
	subaccountFrontendTableBody = jQuery('.frontendTableData').html();
	
	var tableData = jQuery('.inner_customizer_middle').html();
	
	jQuery('.tempHtml').html(tableData);
	
	jQuery('.tempHtml').find('.subaccountTableBody').html('[GROUPTABLEDATA]');
	
	var tableData = jQuery('.tempHtml').html();
	
	var formData = jQuery('#dap_member_subaccount_outer').html();
	
	var buttonHtml = jQuery('.add_new_btn_outer').html();

	var dap_member_subaccount_bulk_outer = jQuery('#dap_member_subaccount_bulk_outer').html();
	
	var overallData = tableData+'||'+subaccountFrontendTableBody+'||'+subaccountTableBody+'||'+buttonHtml+'||'+formData+'||'+dap_member_subaccount_bulk_outer;
	var actionType = 'groupmembers';
	var template = 'template1';

	/****for bulk style start**/

	var add_bulk_btn_enable = 'N';

	if(jQuery('#add_bulk_btn_enable').prop('checked') == true){
		add_bulk_btn_enable = 'Y';
	}
	var add_bulk_background_clr = jQuery('#add_bulk_background_clr').val();
	var add_bulk_button_width = jQuery('#add_bulk_button_width').val();
	var add_bulk_button_height = jQuery('#add_bulk_button_height').val();
	var create_subaccount_bulk_btn_width = jQuery('#create_subaccount_bulk_btn_width').val();
	var update_bulk_btn_background_outer_color = jQuery('#update_bulk_btn_background_outer_color').val();
	var product_background_bulk_color = jQuery('#product_background_bulk_color').val();
	var csv_background_bulk_color = jQuery('#csv_background_bulk_color').val();
	var fields_background_bulk_color = jQuery('#fields_background_bulk_color').val();
	/****for bulk style end**/

	var styling_options = add_bulk_btn_enable+'|'+add_bulk_background_clr+'|'+add_bulk_button_width+'|'+add_bulk_button_height+'|'+create_subaccount_bulk_btn_width+'|'+update_bulk_btn_background_outer_color+'|'+product_background_bulk_color+'|'+csv_background_bulk_color+'|'+fields_background_bulk_color;
	
	
	var pageType = '';
	
	/*var pageName = '';
	
	if(jQuery('#create_subaccount_page').val() != ''){
		pageType = 'new';	
		pageName = jQuery('#create_subaccount_page').val();
	}else if(jQuery('#subaccount_page_url').val() != ''){
		pageType = 'existing';		
		pageName = jQuery('#subaccount_page_url').val();
	}
	
	if(pageType == ''){
		alert('Please select a page');return;	
	}*/
	
	/*messages start*/
	
	var success_added_msg = jQuery('#success_added_msg').val();
	var limit_reached_msg = jQuery('#limit_reached_msg').val();
	var delete_confirm_msg = jQuery('#delete_confirm_msg').val();
	var deleted_msg = jQuery('#deleted_msg').val();
	var not_logged_in = jQuery('#not_logged_in').html();
	var no_access = jQuery('#no_access').html();
	var bulkNoAddUserMsg = jQuery('#bulkNoAddUserMsg').val();
	var no_field_select_msg = jQuery('#no_field_select_msg').val();
	var limit_reached_bulk = jQuery('#limit_reached_bulk').val();
	
	/*messages end*/
	
	
	
	var saved_id = jQuery('#saved_id').val();
	
	jQuery.post(ajaxurl, {
			action: 'dapSaveSubaccountDataAjax',
			edit_id: saved_id,
			overallData: overallData,
			actionType: actionType,
			template: template,
			styling_options: styling_options,
			success_added_msg: success_added_msg,
			limit_reached_msg: limit_reached_msg,
			delete_confirm_msg: delete_confirm_msg,
			deleted_msg: deleted_msg,
			not_logged_in: not_logged_in,
			no_access: no_access,
			bulkNoAddUserMsg: bulkNoAddUserMsg,
			no_field_select_msg: no_field_select_msg,
			limit_reached_bulk: limit_reached_bulk,
	}, function(response) {
		dap_member_hide_loader(); 
		
		response = JSON.parse(response);
		var edit_id = response.id;
		var copyButton = '<button data-id="shortcode_display" id="copy_shortcode" class="theme-button btn btn-warning" onclick="dap_member_copy_to_clipboard('+edit_id+')"> Copy</button>';
		jQuery('.saveSubaccountData').text('Save');
		jQuery('#shortcode_display').html(response.short_code_html);
		jQuery('.shortcodeOuter').show();
		jQuery('.shortcodeTab').show();
		jQuery('.shortcodeSaveOuter').show();
		jQuery('#shortcode_display_copy_outer').show();
		jQuery('#last_next_btn').show();
		jQuery('#saved_id').val(edit_id);
		jQuery('#shortcodeTab').trigger('click');
		
	});
	
}


function activaTab(name) {
	jQuery('html, body').animate({
		scrollTop: 0
	}, 100);
	jQuery('.nav-tabs a[href="#' + name + '" ]').tab('show');
	return true;
} 
