jQuery(document).ready(function(){
	  
   dap_member_tiny_editor();
   
   dap_member_profile_existing_page_select();
   
   dap_member_profile_tabs_Validation();
   
   //dap_member_profile_input_placeholder_change();
   dap_profile_show_section_option();
   dap_profile_option_customizer();
   
   dap_profile_file_upload()
});

function dap_profile_file_upload(){
	jQuery(document).on('change', '#check_enable_file_upload_cust', function(e){
		e.preventDefault();
		
		if(jQuery(this).prop('checked') == true){
			jQuery('.show_profile_file_upload').show();	
			jQuery('.fileUploadCommonClass').show();	
		}else{
			jQuery('.show_profile_file_upload').hide();	
			jQuery('.fileUploadCommonClass').hide();	
		}
		
	});
	
	jQuery(document).on('change', '#check_file_type_doc', function(e){
		e.preventDefault();
		if(jQuery(this).prop('checked') == true){
			jQuery('.file_type_doc_common').show();	
		}else{
			jQuery('.file_type_doc_common').hide();	
			jQuery('.file_type_doc_common').each(function(){
				jQuery(this).find('input[type=checkbox]').prop('checked', false);
			});
		}
	});	
	
	jQuery(document).on('change', '#check_file_type_image', function(e){
		e.preventDefault();
		if(jQuery(this).prop('checked') == true){
			jQuery('.file_type_image_common').show();	
		}else{
			jQuery('.file_type_image_common').hide();	
			jQuery('.file_type_image_common').each(function(){
				jQuery(this).find('input[type=checkbox]').prop('checked', false);
			});
		}
	});	
	
	jQuery(document).on('change', '#videoTypeFileEnable', function(e){
		e.preventDefault();
		if(jQuery(this).prop('checked') == true){
			jQuery('.videoTypeFileCommon').show();	
		}else{
			jQuery('.videoTypeFileCommon').hide();	
			jQuery('.videoTypeFileCommon').each(function(){
				jQuery(this).find('input[type=checkbox]').prop('checked', false);
			});
		}
	});	
	
	jQuery(document).on('change', '#audioTypeFileEnable', function(e){
		e.preventDefault();
		if(jQuery(this).prop('checked') == true){
			jQuery('.audioTypeFileCommon').show();	
		}else{
			jQuery('.audioTypeFileCommon').hide();	
			jQuery('.audioTypeFileCommon').each(function(){
				jQuery(this).find('input[type=checkbox]').prop('checked', false);
			});
		}
	});	
	
	jQuery(document).on('keyup', '#maxNumberOfFiles', function(e){
		e.preventDefault();
		
		var num = jQuery(this).val();
		if(num){
			var html = "<select class='form-control maxNumFilesSelect'>";
			var filehtml = "";
			for (i = 1; i <= num; i++) {
				html += "<option value="+i+">"+i+"</option>";	
				//filehtml += "<input type='file' name='formBuilderFile"+i+"'>";	
				var commonClass = '';
				if(i > 1){
					commonClass = 'commonUploadHideShow';	
				}
				filehtml += '<div class="file-upload-wrapper '+commonClass+' formBuilderFile'+i+'"><div class="file-upload"><div class="file-upload-message"><i class="fa fa-cloud-upload"></i><p>Drag and drop a file here or click</p><p class="file-upload-error">Ooops, something wrong happended.</p></div><input type="file" data-id="'+i+'" name="formBuilderFile'+i+'" id="input-file-max-fs" class="file_upload" data-max-file-size="2M"><button type="button" class="btn btn-danger">Remove<i class="far fa-trash-alt ml-1"></i></button><div class="file-upload-preview"><span class="file-upload-render"><img class="file-upload-preview-img" src=""></span><div class="file-upload-infos"><div class="file-upload-infos-inner"><p class="file-upload-filename"><span class="file-upload-filename-inner">about.jpg</span></p><p class="file-upload-infos-message">Drag and drop or click to replace</p></div></div></div></div><label class="uploadedFileName'+i+' uploadedFileNamePre" style="display:none"></label></div>';	
			}
			html += "</select>";
		}
		
		jQuery('.maxNumFilesSelectOuter').html(html);
		jQuery('.uploadFilesInputOuter').html(filehtml);
	});
	/******form builder file upload updates end*********/	
}


function dap_save_profile_info(go_tab = ''){
	template_html = jQueryDM('.profile_htm_cutomizer').html();
	//Display Options
	
	show_profile_account_info_section = jQueryDM('input[name="show_profile_account_info_section"]').prop('checked');
	show_first_name_section = jQueryDM('input[name="show_first_name_section"]').prop('checked');
	show_last_name_section = jQueryDM('input[name="show_last_name_section"]').prop('checked');
	show_email_section = jQueryDM('input[name="show_email_section"]').prop('checked');
	show_file_upload = jQueryDM('#check_enable_file_upload_cust').prop('checked');
	
	
	dispaly_opitons1 =  show_profile_account_info_section+'||'+show_first_name_section+'||'+show_last_name_section+'||'+show_email_section;
	
	show_profile_change_password_section = jQueryDM('input[name="show_profile_change_password_section"]').prop('checked');
	dispaly_opitons2 = show_profile_change_password_section;
	
	show_profile_billing_info_section = jQueryDM('input[name="show_profile_billing_info_section"]').prop('checked');
	show_profile_billing_address1_section = jQueryDM('input[name="show_profile_billing_address1_section"]').prop('checked');
	show_profile_billing_address2_section = jQueryDM('input[name="show_profile_billing_address2_section"]').prop('checked');
	show_profile_billing_city_section = jQueryDM('input[name="show_profile_billing_city_section"]').prop('checked');
	show_profile_billing_state_section = jQueryDM('input[name="show_profile_billing_state_section"]').prop('checked');
	show_profile_billing_postal_code_section = jQueryDM('input[name="show_profile_billing_postal_code_section"]').prop('checked');
	show_profile_billing_country_section = jQueryDM('input[name="show_profile_billing_country_section"]').prop('checked');

	
	
	
	dispaly_opitons3 = show_profile_billing_info_section+'||'+show_profile_billing_address1_section+'||'+show_profile_billing_address2_section+'||'+show_profile_billing_city_section+'||'+show_profile_billing_state_section+'||'+show_profile_billing_postal_code_section+'||'+show_profile_billing_country_section;
	
	

	show_profile_additional_info_section = jQueryDM('input[name="show_profile_additional_info_section"]').prop('checked');
	show_profile_additional_phone_section = jQueryDM('input[name="show_profile_additional_phone_section"]').prop('checked');
	show_profile_additional_fax_section = jQueryDM('input[name="show_profile_additional_fax_section"]').prop('checked');
	show_profile_additional_company_section = jQueryDM('input[name="show_profile_additional_company_section"]').prop('checked');
	show_additional_title_section = jQueryDM('input[name="show_additional_title_section"]').prop('checked');
	show_profile_additional_paypal_email_section = jQueryDM('input[name="show_profile_additional_paypal_email_section"]').prop('checked');
	show_profile_additional_opted_out_section = jQueryDM('input[name="show_profile_additional_opted_out_section"]').prop('checked');
	
	 
	
	
	dispaly_opitons4 = show_profile_additional_info_section+'||'+show_profile_additional_phone_section+'||'+show_profile_additional_fax_section+'||'+show_profile_additional_company_section+'||'+show_additional_title_section+'||'+show_profile_additional_paypal_email_section+'||'+show_profile_additional_opted_out_section;
	
	show_profile_gdpr_section = jQueryDM('input[name="show_profile_gdpr_section"]').prop('checked');
	
	dispaly_opitons5 = show_profile_gdpr_section;
	
	/* //cancel button style 
	cancel_btn_background_outer_color = jQueryDM('input[name="cancel_btn_background_outer_color"]').val();
	cancel_btn_frnt_bdr_style = jQueryDM('select[name="cancel_btn_frnt_bdr_style"]').val();
	cancel_btn_frnt_bdr_wid = jQueryDM('input[name="cancel_btn_frnt_bdr_wid"]').val();
	cancel_btn_frnt_br_radius = jQueryDM('input[name="cancel_btn_frnt_br_radius"]').val();
	cancel_btn_frnt_bdr_color = jQueryDM('input[name="cancel_btn_frnt_bdr_color"]').val();
	cancel_btn_frnt_wid = jQueryDM('input[name="cancel_btn_frnt_wid"]').val();
	
	dispaly_opitons6 = cancel_btn_background_outer_color+'||'+cancel_btn_frnt_bdr_style+'||'+cancel_btn_frnt_bdr_wid+'||'+cancel_btn_frnt_br_radius+'||'+cancel_btn_frnt_bdr_color+'||'+cancel_btn_frnt_wid;
	 */
	//update button style 
	update_btn_background_outer_color = jQueryDM('input[name="update_btn_background_outer_color"]').val();
	update_btn_frnt_bdr_style = jQueryDM('select[name="update_btn_frnt_bdr_style"]').val();
	update_btn_frnt_bdr_wid = jQueryDM('input[name="update_btn_frnt_bdr_wid"]').val();
	update_btn_frnt_br_radius = jQueryDM('input[name="update_btn_frnt_br_radius"]').val();
	update_btn_frnt_bdr_color = jQueryDM('input[name="update_btn_frnt_bdr_color"]').val();
	update_btn_frnt_wid = jQueryDM('input[name="update_btn_frnt_wid"]').val();
	
	dispaly_opitons7 = update_btn_background_outer_color+"||"+update_btn_frnt_bdr_style+"||"+update_btn_frnt_bdr_wid+"||"+update_btn_frnt_br_radius+"||"+update_btn_frnt_bdr_color+'||'+update_btn_frnt_wid;
	
	// custom fields 
	show_custom_fields_section = jQueryDM('input[name="show_custom_fields_section"]').prop('checked');
	custom_fields_style = jQuery("#custom_fields_style").val().toString();
	
	dispaly_opitons8 = show_custom_fields_section+'||'+custom_fields_style;
	
	
	show_profile_aff_req_section = jQueryDM('input[name="show_profile_aff_req_section"]').prop('checked');
	var display_options9 = show_profile_aff_req_section;
	
	var admin_email = '';

	if(display_options9 == true){
		admin_email = jQueryDM('input[name=req_aff_coupon_admin_email]').val();
		
		if(admin_email == ''){
			dap_member_sweet_alert_popup_with_msg_type('' , 'Please Enter Admin Email' , '');
			return false;
		}	
	}
	
	
	dispaly_opitons = dispaly_opitons1+'|||'+dispaly_opitons2+'|||'+dispaly_opitons3+'|||'+dispaly_opitons4+'|||'+dispaly_opitons5;  
	
	//External Shadow Customizer 
    sprd_radius = jQueryDM('#sprd_radius').val();
    blur_radius = jQueryDM('#blur_radius').val();
    hor_lnth = jQueryDM('#hor_lnth').val();
    ver_lnth = jQueryDM('#ver_lnth').val();
    shad_clr = jQueryDM('#shad_clr').val();
	external_shadow_customizer  = sprd_radius+'||'+blur_radius+'||'+hor_lnth+'||'+ver_lnth+'||'+shad_clr;
	
	//Template Style
     temp_frnt_wid = jQueryDM('#temp_frnt_wid').val();
     temp_background_outer_color = jQueryDM('#temp_background_outer_color').val();
     temp_frnt_bdr_style = jQueryDM('#temp_frnt_bdr_style').val();
     temp_frnt_bdr_wid = jQueryDM('#temp_frnt_bdr_wid').val();
     temp_frnt_br_radius = jQueryDM('#temp_frnt_br_radius').val();
     temp_frnt_bdr_color = jQueryDM('#temp_frnt_bdr_color').val();
     temp_frnt_padd_top = jQueryDM('#temp_frnt_padd_top').val();
     temp_frnt_padd_bottom = jQueryDM('#temp_frnt_padd_bottom').val();
     dm_profile_temp_aligment = jQueryDM('#dm_profile_temp_aligment').val();
     
     
    
     template_Style = temp_frnt_wid+'||'+temp_background_outer_color+'||'+temp_frnt_bdr_style+'||'+temp_frnt_bdr_wid+'||'+temp_frnt_br_radius+'||'+temp_frnt_bdr_color+'||'+temp_frnt_padd_top+'||'+temp_frnt_padd_bottom+'||'+dm_profile_temp_aligment;
	
	//Background Color
      
      account_background_color = jQueryDM('#account_background_color').val();
      change_pass_background_color = jQueryDM('#change_pass_background_color').val();
      billing_background_color = jQueryDM('#billing_background_color').val();
      additional_background_color = jQueryDM('#additional_background_color').val();
      gdpr_background_color = jQueryDM('#gdpr_background_color').val();
            
	 background_color = account_background_color+'||'+change_pass_background_color+'||'+billing_background_color+'||'+additional_background_color+'||'+gdpr_background_color;
	 var display_options10 = 'N|';
	 var allowed_types_of_file  = 'N';
	var showFileInfoError = jQuery('#showFileInfoError').val();	 
	
	 if(show_file_upload == true){
		 display_options10 = 'Y|';
		 allowed_types_of_file  = '';
		jQuery('.allowFileTypeCheckbox').each(function(){
			if(jQuery(this).prop('checked') == true){
				var tempName = jQuery(this).val();
				allowed_types_of_file += 	tempName+'|' ;
			}		
		});
		if(allowed_types_of_file == ''){
			swal('Please select file types that you want to allow users to upload.');	
			return false;
		}else if(showFileInfoError == 'Y'){
			swal('Sorry, it appears that a required php extension called "fileinfo" is missing on your server. This library needs to be enabled for file uploads feature. Please talk to your webhost and have them enable this extension.');	
			return false;	
		}
		var docAllowed = 'N';
		var imgAllowed = 'N';
		var videoAllowed = 'N';
		var audioAllowed = 'N';
		var show_existing_files = 'N';	
		if(jQuery('#check_file_type_doc').prop('checked') == true){
			docAllowed = 'Y';	
		}
		if(jQuery('#check_file_type_image').prop('checked') == true){
			imgAllowed = 'Y';	
		}
		if(jQuery('#videoTypeFileEnable').prop('checked') == true){
			videoAllowed = 'Y';	
		}
		if(jQuery('#audioTypeFileEnable').prop('checked') == true){
			audioAllowed = 'Y';	
		}
	
		
		var max_file_upload_size = jQuery('.maxFileUploadSize').val();
		var max_number_of_files = jQuery('#maxNumberOfFiles').val();
		if(jQuery('input[name=show_already_uploaded_files_section]').prop('checked') == true){
			show_existing_files = 'Y';	
		}
		
		display_options10 += show_existing_files+'|'+docAllowed+'|'+imgAllowed+'|'+videoAllowed+'|'+audioAllowed+'||'+allowed_types_of_file+'|'+max_file_upload_size+'||'+max_number_of_files;		
	}else{
		var docAllowed = 'N';
		var imgAllowed = 'N';
		var videoAllowed = 'N';
		var audioAllowed = 'N';
		var show_existing_files = 'N';	
		allowed_types_of_file  = 'N';
		jQuery('.allowFileTypeCheckbox').each(function(){
			if(jQuery(this).prop('checked') == true){
				var tempName = jQuery(this).val();
				allowed_types_of_file += 	tempName+'|' ;
			}		
		});
		var max_file_upload_size = jQuery('.maxFileUploadSize').val();
		var max_number_of_files = jQuery('#maxNumberOfFiles').val();
		 if(jQuery('input[name=show_already_uploaded_files_section]').prop('checked') == true){
			show_existing_files = 'Y';	
		}
		display_options10 += show_existing_files+'|'+docAllowed+'|'+imgAllowed+'|'+videoAllowed+'|'+audioAllowed+'||'+allowed_types_of_file+'|'+max_file_upload_size+'||'+max_number_of_files;		
	}
	
	var notifyFileUploadEmail = jQuery('#notifyFileUploadEmail').val();
	 
	 styling_options = dispaly_opitons+'|||'+external_shadow_customizer+'|||'+template_Style+'|||'+background_color+"|||"+dispaly_opitons7+'|||'+display_options9+'|||'+display_options10+'|||'+dispaly_opitons8;
	 edit_id =  jQueryDM('input[name="profile_edit_id"]').val();
	 template_selected_name =  jQueryDM('input[name="template_selected_name"]').val();
	 page_id = jQueryDM('input[name="page_id"]').val();
	 
	 redirect_url = jQueryDM('input[name="redirect_url"').val(); 
	 gdpr_msg_section = jQueryDM('input[name="gdpr_msg_section"]').val(); 
	
	 dap_member_show_loader();
		jQueryDM.post(ajaxurl, {
			action: 'save_dap_member_profile_page_save',
			styling_options:styling_options,
			template_html:template_html,
			edit_id:edit_id,
			template_selected_name:template_selected_name,
			page_id:page_id,
			redirect_url:redirect_url,
			gdpr_msg_section:gdpr_msg_section,
			admin_email:admin_email,
			notifyFileUploadEmail:notifyFileUploadEmail,
		}, function(response) {
			dap_member_hide_loader();
			response = JSON.parse(response);
			if(response.success){
				jQueryDM('input[name="profile_edit_id"]').val(response.edit_id);
				$title = "Saved";
				$message = '<div class="dap_member_popup_msg">'+response.html+"</div>";
				$type = "success";
				jQueryDM(".dap_member_profile_details .shortcode_display").html(response.short_code_html);
				jQueryDM(".dap_member_profile_details .selected_page_url").html(response.page_url_html);
				jQueryDM('.dap_member_content #profile_page_url,.dap_member_content input[name="profile_name"],.dap_member_profile_create_page_btn').attr('disabled','disabled');
				if(go_tab != ''){
				 dap_member_goto_next_tab(go_tab);	
				 return ;
				}
				
				
			}else if(response.error){
					$type = 'error';
					$title = 'Oops';
					$message = response.error;
			}
			 dap_member_sweet_alert_popup_with_msg_type($title,$message,$type);
		});	
	 
	 
}

function dap_profile_option_customizer(){
	
	// template outer style 
	var p_selector = '#dap_member_profile_outer .dap_member_profile_inner';
	
	// External Shadow Customizer
	jQueryDM('#hor_lnth').bootstrapSlider().change(function() {
		dap_profile_BoxShadow();
	});
	jQueryDM('#ver_lnth').bootstrapSlider().change(function() {
		dap_profile_BoxShadow();
	});
		jQueryDM('#blur_radius').bootstrapSlider().change(function() {
		dap_profile_BoxShadow();
	});
		jQueryDM('#sprd_radius').bootstrapSlider().change(function() {
		dap_profile_BoxShadow();
	});
	jQueryDM('#shad_clr,#shad_clr_div').colorpicker().on('changeColor', function() {
		
		dap_profile_BoxShadow(jQueryDM(this).colorpicker('getValue'));
	});
	
	
	// Background Color

    jQueryDM('#account_background_color,#account_background_color_div').colorpicker().on('changeColor', function() {
		
		jQueryDM(p_selector).find('.show_profile_account_info_section').css('background-color', jQueryDM(this).colorpicker('getValue'));
	});
	
	jQueryDM('#change_pass_background_color,#change_pass_background_color_div').colorpicker().on('changeColor', function() {
		
		jQueryDM(p_selector).find('.show_profile_change_password_section').css('background-color', jQueryDM(this).colorpicker('getValue'));
	});
	
	
	jQueryDM('#billing_background_color,#billing_background_color_div').colorpicker().on('changeColor', function() {
		
		jQueryDM(p_selector).find('.show_profile_billing_info_section').css('background-color', jQueryDM(this).colorpicker('getValue'));
	});
	
	jQueryDM('#additional_background_color,#additional_background_color_div').colorpicker().on('changeColor', function() {
		
		jQueryDM(p_selector).find('.show_profile_additional_info_section').css('background-color', jQueryDM(this).colorpicker('getValue'));
	});
	
	jQueryDM('#gdpr_background_color,#gdpr_background_color_div').colorpicker().on('changeColor', function() {
		
		jQueryDM(p_selector).find('.show_profile_gdpr_section').css('background-color', jQueryDM(this).colorpicker('getValue'));
	});
	
	
	// Template option 
	
	jQueryDM('#dm_profile_temp_aligment').on('change',function() {
		jQueryDM('.profile_htm_cutomizer').find('#dap_member_profile_outer').css('text-align',jQueryDM(this).val());
	});
	
	jQueryDM('#temp_frnt_wid').bootstrapSlider().change(function() {
		jQueryDM(p_selector).css('max-width', this.value + 'px');
	});
	jQueryDM('#temp_background_outer_color,#temp_background_outer_color_div').colorpicker().on('changeColor', function() {
		
		jQueryDM(p_selector).css('background-color', jQueryDM(this).colorpicker('getValue'));
	});
	
	
	jQueryDM('#temp_frnt_bdr_style').change(function(){
		jQueryDM(p_selector).css('border-style', jQueryDM(this).val());
	});
	
	jQueryDM('#temp_frnt_bdr_wid').bootstrapSlider().change(function() {
		jQueryDM(p_selector).css('border-width', this.value + 'px');
	});
	
	jQueryDM('#temp_frnt_br_radius').bootstrapSlider().change(function() {
		jQueryDM(p_selector).css('border-radius', this.value + 'px');
	});
	
	jQueryDM('#temp_frnt_bdr_color,#temp_frnt_bdr_color_div').colorpicker().on('changeColor', function() {
		
		jQueryDM(p_selector).css('border-color', jQueryDM(this).colorpicker('getValue'));
	});
	

	jQueryDM('#temp_frnt_padd_top').bootstrapSlider().change(function() {
		jQueryDM(p_selector).css('padding-top', this.value + 'px');
	});
	jQueryDM('#temp_frnt_padd_bottom').bootstrapSlider().change(function() {
		jQueryDM(p_selector).css('padding-bottom', this.value + 'px');
	});
	
	// cancel button option 
	/*
	var cancel_btn_selector = '.dap_member_profile_cancel_btn';
	jQueryDM('#cancel_btn_frnt_wid').bootstrapSlider().change(function() {
		jQueryDM(cancel_btn_selector).css('max-width', this.value + 'px');
	});
	jQueryDM('#cancel_btn_background_outer_color,#cancel_btn_background_outer_color_div').colorpicker().on('changeColor', function() {
		
		jQueryDM(cancel_btn_selector).css('background-color', jQueryDM(this).colorpicker('getValue'));
	});
	
	
	jQueryDM('#cancel_btn_frnt_bdr_style').change(function(){
		jQueryDM(cancel_btn_selector).css('border-style', jQueryDM(this).val());
	});
	
	jQueryDM('#cancel_btn_frnt_bdr_wid').bootstrapSlider().change(function() {
		jQueryDM(cancel_btn_selector).css('border-width', this.value + 'px');
	});
	
	jQueryDM('#cancel_btn_frnt_br_radius').bootstrapSlider().change(function() {
		jQueryDM(cancel_btn_selector).css('border-radius', this.value + 'px');
	});
	
	jQueryDM('#cancel_btn_frnt_bdr_color,#cancel_btn_frnt_bdr_color_div').colorpicker().on('changeColor', function() {
		
		jQueryDM(cancel_btn_selector).css('border-color', jQueryDM(this).colorpicker('getValue'));
	});
	
    */
	// update button option 
	
	var update_btn_selector = '.dap_member_profile_update_btn';
	jQueryDM('#update_btn_frnt_wid').bootstrapSlider().change(function() {
		jQueryDM(update_btn_selector).css('max-width', this.value + 'px');
	});
	jQueryDM('#update_btn_background_outer_color,#update_btn_background_outer_color_div').colorpicker().on('changeColor', function() {
		
		jQueryDM(update_btn_selector).css('background-color', jQueryDM(this).colorpicker('getValue'));
	});
	
	
	jQueryDM('#update_btn_frnt_bdr_style').change(function(){
		jQueryDM(update_btn_selector).css('border-style', jQueryDM(this).val());
	});
	
	jQueryDM('#update_btn_frnt_bdr_wid').bootstrapSlider().change(function() {
		jQueryDM(update_btn_selector).css('border-width', this.value + 'px');
	});
	
	jQueryDM('#update_btn_frnt_br_radius').bootstrapSlider().change(function() {
		jQueryDM(update_btn_selector).css('border-radius', this.value + 'px');
	});
	
	jQueryDM('#update_btn_frnt_bdr_color,#update_btn_frnt_bdr_color_div').colorpicker().on('changeColor', function() {
		
		jQueryDM(update_btn_selector).css('border-color', jQueryDM(this).colorpicker('getValue'));
	});
	
	
}	

function dap_profile_BoxShadow(colorval = '') {
	
	var hor_lnth = parseFloat(jQueryDM('#hor_lnth').val());
	var ver_lnth = parseFloat(jQueryDM('#ver_lnth').val());
	var blur_radius = parseFloat(jQueryDM('#blur_radius').val());
	console.log(blur_radius);
	var sprd_radius = parseFloat(jQueryDM('#sprd_radius').val());
	var shad_clr = jQueryDM('#shad_clr').val();
	hor_lnth = hor_lnth + 'px';
	ver_lnth = ver_lnth + 'px';
	blur_radius = blur_radius + 'px';
	sprd_radius = sprd_radius + 'px';
	var box_shadow = hor_lnth + ' ' + ver_lnth + ' ' + blur_radius + ' ' + sprd_radius + ' ' + shad_clr;
	var p_selector = '#dap_member_profile_outer .enter_name_outer';
	jQueryDM(p_selector).css('-webkit-box-shadow', box_shadow);
	jQueryDM(p_selector).css('-moz-box-shadow', box_shadow);
	jQueryDM(p_selector).css('box-shadow', box_shadow);
}

function dap_profile_show_section_option(){
     
    jQueryDM('.profile_show_section_option input[type="checkbox"]').on('change',function(){
	    dataid = jQueryDM(this).attr('data-id');
	    console.log("dataid: "+dataid);
       if(jQueryDM(this).prop('checked')){
		   jQueryDM('.'+dataid).show();
			if(dataid == 'show_profile_aff_req_section'){
				jQuery('.sub_req_aff_coupon_info_section').show();
			}
			if(dataid == 'show_profile_additional_opted_out_section'){
				jQuery('.show_profile_Opted').show();
			}
	   }else{
		   jQueryDM('.'+dataid).hide();
		   if(dataid == 'show_profile_aff_req_section'){
				jQuery('.sub_req_aff_coupon_info_section').hide();
			}
			if(dataid == 'show_profile_additional_opted_out_section'){
				jQuery('.show_profile_Opted').hide();
			}
	   }
    })
}


function dap_member_profile_input_placeholder_change(){
	
	//Placeholder  
	jQuery(document).on('focus','.profile_htm_cutomizer input[type=text], .profile_htm_cutomizer input[type=email]',function() {
		var text = jQuery(this).attr('placeholder');
		jQuery(this).val(text);
	});
	
	jQuery(document).on('focusout','.profile_htm_cutomizer input[type=text], .profile_htm_cutomizer input[type=email]',function() {
		jQuery(this).attr('placeholder',jQuery(this).val());
		jQuery(this).val('');
	});		

}

function dap_member_profile_name_tab_validation(){
	
	var validation_status = false;
	$parent_selector = '.dap_member_content';
	post_title = jQueryDM($parent_selector).find('input[name="profile_name"]').val();
	login_page_url = jQueryDM($parent_selector).find('select[name="profile_page_url"]').val();
	
	if(post_title == '' && login_page_url == ''){
		$message = "Please Enter a Name for your Profile Page";
		dap_member_sweet_alert_message($message);
		validation_status = true;
		return validation_status;
	}
	page_id = jQueryDM($parent_selector).find('input[name="page_id"]').val();
	if(post_title != '' && page_id == ''){
		$message = "Please 'Click To Create' button";
		dap_member_sweet_alert_message($message);
		validation_status = true;
		return validation_status;
		
	}
	
	var seleted_template = jQueryDM($parent_selector).find('input[name="template_selected_name"]').val();
    if(seleted_template ==''){
		validation_status = true;
		$message = "Please select template.";
		dap_member_sweet_alert_message($message);
		return validation_status;
	} 
	 
	return validation_status;
}

function dap_member_profile_tabs_Validation(){
	
	jQueryDM('#dap_member_profile_tabs li.nav-item').on('click','a', function (e) {
		if(e.target == e.currentTarget) {
			var current_tab_id = jQueryDM(e.target).attr("href"); // activated tab
		}else {
			var current_tab_id = jQueryDM(this).parents('li').find('a').attr("href"); // activated tab
		}	
		
		
		if(current_tab_id == '#dap_member_profile_general'){
			dap_member_show_tab_by_id(current_tab_id);
			return ;
		}
		
		if(dap_member_profile_name_tab_validation()){
			current_tab_id = '#dap_member_profile_general';
			dap_member_show_tab_by_id(current_tab_id);
			return ;
		}
		if(current_tab_id == '#dap_member_profile_shortdetails'){
			
			edit_id = jQueryDM('.dap_member_content').find('input[name="profile_edit_id"]').val();
			if(edit_id == ''){
				$message = "Please Save Template";
				dap_member_sweet_alert_message($message);
				
				return ;
			}
		}
		
		dap_member_show_tab_by_id(current_tab_id);
		});
	
}

function dap_member_profile_create_page_btn($obj){
	
	$parent_selector = '.dap_member_content';
	
	post_title = jQueryDM($parent_selector).find('input[name="profile_name"]').val();
	
	if(post_title == ''){
		$message = "Please Enter a Name for your Profile Page";
		dap_member_sweet_alert_message($message);
		return ;
	}
	
	dap_member_show_loader();
	jQueryDM($obj).text('Creating...');
	jQueryDM.post(ajaxurl, {
		action: 'dapMemberGenerateWpPage',
		post_title:post_title,
	}, function(response) {
		dap_member_hide_loader();
		jQueryDM($obj).text('Click to Create');
		$parent_selector = '.page_response';
		
		response = JSON.parse(response);
	
		jQueryDM($parent_selector).removeClass('text-success text-danger');
		if(response.status == 'yes'){
			$message = "Sorry, This Name is already taken. Please Try with another one.";
			jQueryDM($parent_selector).text($message).addClass('text-danger');
			return ;
		}else if(response.status == 'no'){
			$message = "Profile created successfully.";
			jQueryDM($parent_selector).text($message).addClass('text-success');
			jQueryDM('.dap_member_content input[name="page_id"]').val(response.post_id);
			return ;
		}
		
	    	
	});
	

}

function dap_member_profile_existing_page_select(){
	
	jQueryDM('#profile_page_url').on('change',function(){
		page_id = jQueryDM(this).val();
		dap_member_show_loader();
		jQueryDM.post(ajaxurl, {
			action: 'dap_checked_page_id_and_page_type_used',
			page_id:page_id,
			page_type : 'profile'
		}, function(response) {
			response = jQuery.trim(response);
			dap_member_hide_loader();
			if(response == 'yes'){
				$message = "This URL is already in use. Please select a different URL.";
				dap_member_sweet_alert_message($message);
				jQueryDM('#profile_page_url').val('');
				return ;
			}else if(response == 'no'){
				jQueryDM('input[name="page_id"]').val(page_id);
			}
	
		});
	});
}

function dap_member_profile_customize_temp(template_name , template_number_name){
	
	dap_member_show_loader();
	jQueryDM.post(ajaxurl, {
		action: 'dap_member_get_template',
		template_name:template_name,
		template_number_name: template_number_name,
	}, function(response) {
		response = JSON.parse(response);
		jQueryDM('.choices-template.row li').removeClass('activeCustomize');
		jQueryDM('.choices-template.row').find('li.'+template_number_name).addClass('activeCustomize');
		jQueryDM('.dap_member_content input[name="template_selected_name"]').val(template_number_name);
		jQueryDM('.profile_htm_cutomizer').html(response.html); 
		
		jQuery('#check_enable_file_upload_cust').prop('checked', false);
		jQuery('#check_file_type_image').prop('checked', false);
		jQuery('#check_file_type_doc').prop('checked', false);
		jQuery('#videoTypeFileEnable').prop('checked', false);
		jQuery('#audioTypeFileEnable').prop('checked', false);
		jQuery('.allowFileTypeCheckbox').prop('checked', false);
		jQuery('#maxNumberOfFiles').val(1);
		jQuery('#maxFileUploadSize').val(2);
		
		jQuery('#check_enable_file_upload_cust').trigger('change');
		jQuery('#check_file_type_doc').trigger('change');
		jQuery('#check_file_type_image').trigger('change');
		jQuery('#videoTypeFileEnable').trigger('change');
		jQuery('#audioTypeFileEnable').trigger('change');
		
		jQuery('input[name=show_already_uploaded_files_section]').prop('checked', false);
		
		jQuery('input[name=show_already_uploaded_files_section]').trigger('change');
		
		jQueryDM('.profile_htm_cutomizer_link').html('<link  rel="stylesheet" href="'+response.css_file_path+'">'); 
		dap_member_tiny_editor();
	 	
	 	dap_member_goto_next_tab('#dap_member_profile_preview');
	 	
	 	
	 	//set default values of color picker
	    if(response.default_colorpicker_values){
			var data = response.default_colorpicker_values;
			
			for (var key in data) {
				jQueryDM('#'+key).colorpicker('setValue',data[key]);
			}
		}	
		
		if(response.default_numaric_values){
			var data = response.default_numaric_values;
			
			for (var key in data) {
				jQueryDM('#'+key).bootstrapSlider('setValue',data[key]);
			}
		}
		
		if(response.default_style_values){
			var data = response.default_style_values;
			
			for (var key in data) {
				jQueryDM('#'+key).val(data[key]);
			}
		}
		
		if(response.default_checkedbox_values){
			var data = response.default_checkedbox_values;
			
			for (var key in data) {
				jQueryDM('input[name="'+key+'"]').prop('checked',data[key]).change();
			}
		}
	 	
	 	
	 	
	 	
	 	dap_member_hide_loader();
	 	
	 	
	});	
	
}

function dap_member_profile_preview_temp(template_name , template_number_name){
	
	
	
	dap_member_show_loader();
	jQueryDM.post(ajaxurl, {
		action: 'dap_member_get_template',
		template_name:template_name,
		template_number_name: template_number_name,
	}, function(response) {
		response = JSON.parse(response);
		jQueryDM('#dap_member_profile_preview_wrapper_modal .modal-body').html(response.html).append('<link rel="stylesheet"  href="'+response.css_file_path+'">');
		jQueryDM('#dap_member_profile_preview_wrapper_modal').modal('show');  
		dap_member_hide_loader();
	    	
	});
	
}
