jQuery(document).ready(function(){
   dap_member_login_mediauploader();
   dap_member_login_customize_template_style_events();
   dap_member_login_tabs_Validation();
   dap_member_tiny_editor();
   dap_member_login_existing_page_select();
   dap_member_login_save_to_config();
   jQueryDM('.dap_member_customize_template_div').show();
});


function dap_member_login_save_to_config(){
	jQuery('#changeConfigLoginUrl').change(function(){
		if(jQuery(this).prop('checked') == true){
			var page_id = jQueryDM('#login_page_id').val();
			jQueryDM.post(ajaxurl, {
				action: 'dap_member_login_save_to_config',
				page_id:page_id,
			}, function(response) {
				dap_member_hide_loader();
				jQueryDM('.savedConfigLoginUrl').show();
				
				jQueryDM('.savedConfigLoginUrl').fadeOut(3000);
				
				
				
			});	
		}
	});
}	

function dap_member_login_existing_page_select(){
	
	jQueryDM('#login_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:'login',
		}, function(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('#login_page_url').val('');
				return ;
			}else if(response == 'no'){
				
				jQueryDM('input[name="page_id"]').val(page_id);
			}
	
		});
	});
}

function dap_member_login_BoxShadow(colorval = '') {
	
	var hor_lnth = parseFloat(jQueryDM('#dm_login_temp_shadow_horizontal_length').val());
	var ver_lnth = parseFloat(jQueryDM('#dm_login_temp_shadow_vertical_length').val());
	var blur_radius = parseFloat(jQueryDM('#dm_login_temp_shadow_blur_radius').val());
	var sprd_radius = parseFloat(jQueryDM('#dm_login_temp_shadow_spread_radius').val());
	var shad_clr = jQueryDM('#dm_login_temp_shadow_color').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 cs_customize_template_outer_Selector = '#login_template_wrapper .login_outer';
	jQueryDM(cs_customize_template_outer_Selector).css('-webkit-box-shadow', box_shadow);
	jQueryDM(cs_customize_template_outer_Selector).css('-moz-box-shadow', box_shadow);
	jQueryDM(cs_customize_template_outer_Selector).css('box-shadow', box_shadow);
}

function dap_member_login_save($tab_action = ''){
	
	
	
	if(!dap_member_login_tabs_Validation()){
		$parent_selector = '.dap_member_content';
		post_title = jQueryDM($parent_selector).find('input[name="name"]').val();
		edit_id = jQueryDM($parent_selector).find('input[name="edit_id"]').val();
		gdpr_option = jQueryDM($parent_selector).find('select[name="gdpr_option"]').val();
		login_page_url = jQueryDM($parent_selector).find('select[name="login_page_url"]').val();
	    page_id = jQueryDM($parent_selector).find('input[name="page_id"]').val();
	    post_login_url = jQueryDM($parent_selector).find('input[name="post_login_url"]').val();
	    seleted_template = jQueryDM($parent_selector).find('input[name="template_selected_name"]').val();
	    template_html1 = jQueryDM($parent_selector).find('.dap_member_customize_template_div').html();
	    template_html2 = jQueryDM($parent_selector).find('.dap_member_customize_forgot_template_div').html();
	    template_html3 = jQueryDM($parent_selector).find('.dap_member_customize_reset_template_div').html();
	    template_html = template_html1+'%%DAPMEMBERLOGINTEMPLATE%%'+template_html2+'%%DAPMEMBERLOGINTEMPLATE%%'+template_html3;
	    
	    
	    
	    
	    /* Template customizer values */
		var dm_login_temp_wid =  jQueryDM($parent_selector).find('#dm_login_temp_wid').val();
		var dm_login_temp_border_width =  jQueryDM($parent_selector).find('#dm_login_temp_border_width').val();
		var dm_login_temp_border_radius =  jQueryDM($parent_selector).find('#dm_login_temp_border_radius').val();
		var dm_login_temp_border_color =  jQueryDM($parent_selector).find('#dm_login_temp_border_color').val();
		var dm_login_temp_background_color =  jQueryDM($parent_selector).find('#dm_login_temp_background_color').val();
		var dm_login_temp_border_style =  jQueryDM($parent_selector).find('#dm_login_temp_border_style').val();
		var dm_login_temp_img_show =  jQueryDM($parent_selector).find('#dm_login_temp_img_show').val();
		var dap_member_login_image_height =  jQueryDM($parent_selector).find('#dap_member_login_image_height').val();
		var dm_login_temp_captcha =  jQueryDM($parent_selector).find('#dm_login_temp_captcha').val();
		var dm_login_temp_aligment =  jQueryDM($parent_selector).find('#dm_login_temp_aligment').val();
		
		$template_option =  dm_login_temp_wid+'||'+dm_login_temp_border_width+'||'+dm_login_temp_border_radius+'||'+dm_login_temp_border_color+'||'+dm_login_temp_background_color+'||'+dm_login_temp_border_style+'||'+dm_login_temp_img_show+'||'+dap_member_login_image_height+'||'+dm_login_temp_captcha+'||'+dm_login_temp_aligment;
		
		
		
		
		
		/* Template additional values */
		var dm_login_temp_addit_create_account_link =  jQueryDM($parent_selector).find('#dm_login_temp_addit_create_account_link').val();
		var dm_login_temp_addit_width =  jQueryDM($parent_selector).find('#dm_login_temp_addit_width').val();
		var dm_login_temp_addit_border_width =  jQueryDM($parent_selector).find('#dm_login_temp_addit_border_width').val();
		var dm_login_temp_addit_border_radius =  jQueryDM($parent_selector).find('#dm_login_temp_addit_border_radius').val();
		var dm_login_temp_addit_background_color =  jQueryDM($parent_selector).find('#dm_login_temp_addit_background_color').val();
		var	dm_login_temp_addit_border_color =  jQueryDM($parent_selector).find('#dm_login_temp_addit_border_color').val();
		var dm_login_temp_addit_style =  jQueryDM($parent_selector).find('#dm_login_temp_addit_style').val();
		var dap_login_create_registration_link =  jQueryDM($parent_selector).find('#dap_login_create_registration_link').val();
		
		$template_additional_option =  dm_login_temp_addit_create_account_link+'||'+dm_login_temp_addit_width+'||'+dm_login_temp_addit_border_width+'||'+dm_login_temp_addit_border_radius+'||'+dm_login_temp_addit_background_color+'||'+dm_login_temp_addit_border_color+'||'+dm_login_temp_addit_style;
		/* Template sign in values */
		var dm_login_temp_signin_width =  jQueryDM($parent_selector).find('#dm_login_temp_signin_width').val();
		var dm_login_temp_signin_height =  jQueryDM($parent_selector).find('#dm_login_temp_signin_height').val();
		var dm_login_temp_signin_border_width =  jQueryDM($parent_selector).find('#dm_login_temp_signin_border_width').val();
		var dm_login_temp_signin_radius =  jQueryDM($parent_selector).find('#dm_login_temp_signin_radius').val();
		var dm_login_temp_signin_background_color =  jQueryDM($parent_selector).find('#dm_login_temp_signin_background_color').val();
		var dm_login_temp_signin_border_color =  jQueryDM($parent_selector).find('#dm_login_temp_signin_border_color').val();
		var	dm_login_temp_signin_border_style =  jQueryDM($parent_selector).find('#dm_login_temp_signin_border_style').val();
		
		
	    $template_signin_option =  dm_login_temp_signin_width+'||'+dm_login_temp_signin_height+'||'+dm_login_temp_signin_border_width+'||'+dm_login_temp_signin_radius+'||'+dm_login_temp_signin_background_color+'||'+dm_login_temp_signin_border_color+'||'+dm_login_temp_signin_border_style;
		
		
		/* Template fb button in values */
		var dm_fb_login_temp_width =  jQueryDM($parent_selector).find('#dm_fb_login_temp_width').val();
		var dm_fb_login_temp_height =  jQueryDM($parent_selector).find('#dm_fb_login_temp_height').val();
		var dm_fb_login_temp_border_width =  jQueryDM($parent_selector).find('#dm_fb_login_temp_border_width').val();
		var dm_fb_login_temp_radius =  jQueryDM($parent_selector).find('#dm_fb_login_temp_radius').val();
		var dm_fb_login_temp_background_color =  jQueryDM($parent_selector).find('#dm_fb_login_temp_background_color').val();
		var dm_fb_login_temp_border_color =  jQueryDM($parent_selector).find('#dm_fb_login_temp_border_color').val();
		var	dm_fb_login_temp_border_style =  jQueryDM($parent_selector).find('#dm_fb_login_temp_border_style').val();
		var	dm_fb_section_login_temp_background_color =  jQueryDM($parent_selector).find('#dm_fb_section_login_temp_background_color').val();
		
		
	    $template_fb_login_option =  dm_fb_login_temp_width+'||'+dm_fb_login_temp_height+'||'+dm_fb_login_temp_border_width+'||'+dm_fb_login_temp_radius+'||'+dm_fb_login_temp_background_color+'||'+dm_fb_login_temp_border_color+'||'+dm_fb_login_temp_border_style+'||'+dm_fb_section_login_temp_background_color;
		
		
		//shadow effect variable 
		var dm_login_temp_shadow_horizontal_length =    jQueryDM($parent_selector).find('#dm_login_temp_shadow_horizontal_length').val();
		var dm_login_temp_shadow_vertical_length =    jQueryDM($parent_selector).find('#dm_login_temp_shadow_vertical_length').val();
		var dm_login_temp_shadow_blur_radius = jQueryDM($parent_selector).find('#dm_login_temp_shadow_blur_radius').val();
		var dm_login_temp_shadow_spread_radius = jQueryDM($parent_selector).find('#dm_login_temp_shadow_spread_radius').val();
		var dm_login_temp_shadow_color =    jQueryDM($parent_selector).find('#dm_login_temp_shadow_color').val();
		
		$shadow_efferct = dm_login_temp_shadow_horizontal_length+'||'+dm_login_temp_shadow_vertical_length+'||'+dm_login_temp_shadow_blur_radius+'||'+dm_login_temp_shadow_spread_radius+'||'+dm_login_temp_shadow_color;
		
		// forgot pass
		var dm_login_temp_forgot_width = jQueryDM($parent_selector).find('#dm_login_temp_forgot_width').val();
		var dm_login_temp_forgot_height =  jQueryDM($parent_selector).find('#dm_login_temp_forgot_height').val();
		var dm_login_temp_forgot_background_color = jQueryDM($parent_selector).find('#dm_login_temp_forgot_background_color').val();
		var dm_login_temp_forgot_border_width = jQueryDM($parent_selector).find('#dm_login_temp_forgot_border_width').val();
		var dm_login_temp_forgot_border_style = jQueryDM($parent_selector).find('#dm_login_temp_forgot_border_style').val();
		var dm_login_temp_forgot_border_color = jQueryDM($parent_selector).find('#dm_login_temp_forgot_border_color').val();
		var dm_login_temp_forgot_radius = jQueryDM($parent_selector).find('#dm_login_temp_forgot_radius').val();
		
		$template_forgot_option =  dm_login_temp_forgot_width+'||'+dm_login_temp_forgot_height+'||'+dm_login_temp_forgot_background_color+'||'+dm_login_temp_forgot_border_width+'||'+dm_login_temp_forgot_border_style+'||'+dm_login_temp_forgot_border_color+'||'+dm_login_temp_forgot_radius;
		//======================
        // reset pass
		var dm_login_temp_reset_width = jQueryDM($parent_selector).find('#dm_login_temp_reset_width').val();
		var dm_login_temp_reset_height = jQueryDM($parent_selector).find('#dm_login_temp_reset_height').val();
		var dm_login_temp_reset_background_color = jQueryDM($parent_selector).find('#dm_login_temp_reset_background_color').val();
		var dm_login_temp_reset_border_width = jQueryDM($parent_selector).find('#dm_login_temp_reset_border_width').val();
		var dm_login_temp_reset_border_style = jQueryDM($parent_selector).find('#dm_login_temp_reset_border_style').val();
		var dm_login_temp_reset_border_color = jQueryDM($parent_selector).find('#dm_login_temp_reset_border_color').val();
		var dm_login_temp_reset_radius = jQueryDM($parent_selector).find('#dm_login_temp_reset_radius').val();
		
		$template_reset_option =  dm_login_temp_reset_width+'||'+dm_login_temp_reset_height+'||'+dm_login_temp_reset_background_color+'||'+dm_login_temp_reset_border_width+'||'+dm_login_temp_reset_border_style+'||'+dm_login_temp_reset_border_color+'||'+dm_login_temp_reset_radius;		
		
		
		$template_option = $template_option+'|||'+$template_additional_option+'|||'+$template_signin_option+'|||'+$shadow_efferct+'|||'+$template_forgot_option+'|||'+$template_reset_option+'|||'+$template_fb_login_option;
		
		
		
		var template_selected_action = jQueryDM('.dap_member_content input[name="template_selected_action"]').val();
		
		
		var form_data_array = { };
		form_data_array['template_option'] = $template_option;
		form_data_array['post_title'] = post_title;
		form_data_array['login_page_url'] = login_page_url;
		form_data_array['page_id'] = page_id;
		form_data_array['post_login_url'] = post_login_url;
		form_data_array['seleted_template'] = seleted_template;
		form_data_array['template_html'] = encodeURIComponent(template_html);
		form_data_array['edit_id'] = edit_id;
		form_data_array['gdpr'] = gdpr_option;
		form_data_array['dap_login_create_registration_link'] = dap_login_create_registration_link;
		form_data_array['template_selected_action'] = template_selected_action;
		
		
		dap_member_show_loader();
		jQueryDM.post(ajaxurl, {
			action: 'save_dap_member_login_page',
			data:form_data_array,
		}, function(response) {
			response = JSON.parse(response);
			dap_member_hide_loader();
				
			if(response.success){
				jQueryDM('#login_page_id').val(response.page_id);
				jQueryDM('.dap_member_content').find('input[name="edit_id"]').val(response.edit_id);
				jQueryDM('.dap_member_fb_login_details_outer').html(response.dap_member_fb_login_details);
				jQueryDM('.dap_member_login_details .shortcode_display').html(response.short_code_html);
				jQueryDM('.dap_member_login_details .shortcode_page_link').html(response.page_url_html);
			
			
				if(response.configlogin_url_html != ''){
					jQueryDM('.dap_member_login_config_inner_empty').html(response.configlogin_url_html);
					jQueryDM('.dap_member_login_config_outer_empty').show();	
				}
				if($tab_action != ''){
				 dap_member_goto_next_tab($tab_action);	
				 return ;
				}
				
				$title = "Saved";
				$message = '<div class="dap_member_popup_msg">'+response.html+"</div>";
				$type = "success";
				
			}else if(response.error){
					$type = 'error';
					$title = 'Oops';
					$message = response.error;
			}
			 dap_member_sweet_alert_popup_with_msg_type($title,$message,$type);
		});	
		
		
	}
	
	
}



function dap_member_login_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);
		
		if(template_name == 'loginFB'){
			jQueryDM('.fb_login_btn_style_outer').show();
			jQueryDM('.hide_for_fb_login').hide();
			//jQueryDM('.image_customizer_outer,.captcha_customzier_outer,.account_customzer_outer').hide();
			jQueryDM('.dap_member_content input[name="template_selected_action"]').val('loginFB');
			
		}else{
			jQueryDM('.fb_login_btn_style_outer').hide();
			jQueryDM('.hide_for_fb_login').removeClass('hide_fb_customizer_fields');
			jQueryDM('.hide_for_fb_login').show();
			//jQueryDM('.image_customizer_outer,.captcha_customzier_outer,.account_customzer_outer').show();
			jQueryDM('.dap_member_content input[name="template_selected_action"]').val('login');
		}
		jQueryDM('.dap_member_template_outer_link').html('<link  rel="stylesheet" href="'+response.css_file_path+'">'); 
		jQueryDM('.choices-template.row li').removeClass('activeCustomize');
		jQueryDM('.choices-template.row').find('li.onecolumn_'+template_number_name+'+'+template_name).addClass('activeCustomize');
		jQueryDM('.dap_member_content input[name="template_selected_name"]').val(template_number_name);
		
		jQueryDM('.dap_member_customize_template_div').html(response.html); 
		
		
		
		
		
		jQueryDM('.dap_member_customize_forgot_template_div').html(response.html_forgot_pass); 
		jQueryDM('.dap_member_customize_reset_template_div').html(response.html_reset_pass); 
		
		dap_member_tiny_editor();
	 	
	 
	 	
	 	
	 	//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]);
			}
		}
	 	
	 	
	 	setTimeout(function(){ 
			jQueryDM('.dap_member_customize_template_div').find('input[name="email"]').attr('placeholder','Enter Email'); 
			jQueryDM('.dap_member_customize_template_div').find('input[name="password"]').attr('placeholder','Password'); 
			dap_member_goto_next_tab('#dap_member_preview');
			dap_member_hide_loader(); }, 
		2500);

	 	
	 	
	 	
	});	
	
}

function dap_member_login_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_login_preview_wrapper_modal .modal-body').html(response.html).append('<link rel="stylesheet"  href="'+response.css_file_path+'">');
		jQueryDM('#dap_member_login_preview_wrapper_modal').modal('show');  
		dap_member_hide_loader();
	    	
	});
	
}

function dap_member_login_mediauploader(){
	
	var dap_member_login_img;
	
	jQueryDM(document).on('click','.dap_member_login_image_upload',function() {  
		
		if (dap_member_login_img) {
			dap_member_login_img.open();
			return;
		}
		dap_member_login_img = wp.media.frames.file_frame = wp.media({
			title: 'Choose Image',
			button: {
				text: 'Choose Image'
			},
			multiple: false
		});
		dap_member_login_img.on('select', function() {
			attachment = dap_member_login_img.state().get('selection').first().toJSON();	
			jQueryDM('#login_template_wrapper .login_img img').attr('src',attachment.url);
			
		});
		dap_member_login_img.open();
	});
	
	
}


function dap_member_login_customize_template_style_events(){
	
	// template outer style 
	var cs_customize_template_outer_Selector = '#login_template_wrapper .login_outer';
	jQueryDM('#dm_login_temp_aligment').on('change',function() {
		jQueryDM('.dap_member_customize_template_div').find('#login_template_wrapper').css('text-align',jQueryDM(this).val());
	});
	
	jQueryDM('#dm_login_temp_wid').bootstrapSlider().change(function() {
		jQueryDM(cs_customize_template_outer_Selector).css('max-width', this.value + 'px');
		jQueryDM('.dap_member_customize_forgot_template_div').find("#forgot_outer").css('max-width', this.value + 'px');
		jQueryDM('.dap_member_customize_reset_template_div').find("#reset_outer").css('max-width', this.value + 'px');
	});
	jQueryDM('#dm_login_temp_border_width').bootstrapSlider().change(function() {
		jQueryDM(cs_customize_template_outer_Selector).css('border-width', this.value + 'px');
	});
	jQueryDM('#dm_login_temp_border_radius').bootstrapSlider().change(function() {
		jQueryDM(cs_customize_template_outer_Selector).css('border-radius', this.value + 'px');
	});
	jQueryDM('#dm_login_temp_border_color,#dm_login_temp_border_color_div').colorpicker().on('changeColor', function() {
		jQueryDM(cs_customize_template_outer_Selector).css('border-color', jQueryDM(this).colorpicker('getValue'));
	});
	jQueryDM('#dm_login_temp_background_color,#dm_login_temp_background_color_div').colorpicker().on('changeColor', function() {
		jQueryDM(cs_customize_template_outer_Selector).css('background-color', jQueryDM(this).colorpicker('getValue'));
	});
	
	jQueryDM('#dm_login_temp_border_style').change(function(){
		jQueryDM(cs_customize_template_outer_Selector).css('border-style', jQueryDM(this).val());
	});
	
	jQueryDM('#dm_login_temp_img_show').on('change',function(){
		value = jQueryDM(this).val();
		
		if( value== 'no'){
			jQueryDM('#login_template_wrapper .login_img,.dap_member_login_image_upload_div').hide();
			
		}else if(value == 'yes'){
			jQueryDM('#login_template_wrapper .login_img,.dap_member_login_image_upload_div').show();
		}
	});
	
	
	jQueryDM('#dm_login_temp_captcha').on('change',function(){
		value = jQueryDM(this).val();
		if( value== 'no'){
			jQueryDM('#login_template_wrapper .captcha_wrapper_outer').hide();
			
		}else if(value == 'yes'){
			jQueryDM('#login_template_wrapper .captcha_wrapper_outer').show();
		}
	});
	
	
	
	jQueryDM(".dap_member_login_image_enter").keyup(function(){
		
		if(jQueryDM.trim(jQueryDM(this).val()) != ''){
			jQueryDM('#login_template_wrapper .login_img img').attr('src',jQueryDM(this).val());
		}	
	});
	
	
	
	jQueryDM('#dap_member_login_image_height').bootstrapSlider().change(function() {
		jQueryDM(cs_customize_template_outer_Selector).find('.login_img img').css('height', this.value + 'px');
	});
	
	
	// External Shadow Customizer

	jQueryDM('#dm_login_temp_shadow_vertical_length').bootstrapSlider().change(function() {
		dap_member_login_BoxShadow();
	});
	jQueryDM('#dm_login_temp_shadow_horizontal_length').bootstrapSlider().change(function() {
		dap_member_login_BoxShadow();
	});
		jQueryDM('#dm_login_temp_shadow_blur_radius').bootstrapSlider().change(function() {
		dap_member_login_BoxShadow();
	});
		jQueryDM('#dm_login_temp_shadow_spread_radius').bootstrapSlider().change(function() {
		dap_member_login_BoxShadow();
	});
	jQueryDM('#dm_login_temp_shadow_color_div,#dm_login_temp_shadow_color').colorpicker().on('changeColor', function() {
		
		dap_member_login_BoxShadow(jQueryDM(this).colorpicker('getValue'));
	});
	
	// additional style
	
	var additional_info = '#login_template_wrapper .additional_info';
	jQueryDM('#dm_login_temp_addit_create_account_link').on('change',function(){
		
		if(jQueryDM(this).val() == 'no'){
			jQueryDM(cs_customize_template_outer_Selector).find('.create_forgot_link .create_account').hide();
			jQueryDM("li.create_registration_link_option").hide();
			
		}else if(jQueryDM(this).val() == 'yes'){
			jQueryDM(cs_customize_template_outer_Selector).find('.create_forgot_link .create_account').show();
			jQueryDM("li.create_registration_link_option").show();
		}
	});
	
	
	jQueryDM("#dap_login_create_registration_link").keyup(function(){
		
		if(jQueryDM.trim(jQueryDM(this).val()) != ''){
			jQueryDM(cs_customize_template_outer_Selector).find('.create_forgot_link .create_account').attr('href',jQueryDM(this).val());
		}	
	});
	
	
	jQueryDM('#dm_login_temp_addit_width').bootstrapSlider().change(function() {
		jQueryDM(additional_info).css('max-width', this.value + 'px');
	});
	jQueryDM('#dm_login_temp_addit_border_width').bootstrapSlider().change(function() {
		jQueryDM(additional_info).css('border-width', this.value + 'px');
	});
	jQueryDM('#dm_login_temp_addit_border_radius').bootstrapSlider().change(function() {
		jQueryDM(additional_info).css('border-radius', this.value + 'px');
	});
	jQueryDM('#dm_login_temp_addit_background_color_div,#dm_login_temp_addit_background_color').colorpicker().on('changeColor', function() {
		jQueryDM(additional_info).css('background-color', jQueryDM(this).colorpicker('getValue'));
	});
	jQueryDM('#dm_login_temp_addit_border_color_div,#dm_login_temp_addit_border_color').colorpicker().on('changeColor', function() {
		jQueryDM(additional_info).css('border-color', jQueryDM(this).colorpicker('getValue'));
	});
	
	jQueryDM('#dm_login_temp_addit_style').change(function(){
		jQueryDM(additional_info).css('border-style', jQueryDM(this).val());
	});
	
	
	// signin button style
	var signin_btn_selector = '#login_template_wrapper .signin_btn';
	jQueryDM('#dm_login_temp_signin_width').bootstrapSlider().change(function() {
		jQueryDM(signin_btn_selector).css('max-width', this.value + 'px');
	});
	jQueryDM('#dm_login_temp_signin_height').bootstrapSlider().change(function() {
		jQueryDM(signin_btn_selector).css('line-height', this.value + 'px');
	});
	 
	jQueryDM('#dm_login_temp_signin_border_width').bootstrapSlider().change(function() {
		jQueryDM(signin_btn_selector).css('border-width', this.value + 'px');
	});
	jQueryDM('#dm_login_temp_signin_radius').bootstrapSlider().change(function() {
		jQueryDM(signin_btn_selector).css('border-radius', this.value + 'px');
	});
	jQueryDM('#dm_login_temp_signin_background_color_div,#dm_login_temp_signin_background_color').colorpicker().on('changeColor', function() {
		jQueryDM(signin_btn_selector).css('background-color', jQueryDM(this).colorpicker('getValue'));
	});
	jQueryDM('#dm_login_temp_signin_border_color,#dm_login_temp_signin_border_color_div').colorpicker().on('changeColor', function() {
		jQueryDM(signin_btn_selector).css('border-color', jQueryDM(this).colorpicker('getValue'));
	});
	
	jQueryDM('#dm_login_temp_signin_border_style').change(function(){
		jQueryDM(signin_btn_selector).css('border-style', jQueryDM(this).val());
	});
	
	
	
	// fb button style
	var fb_btn_selector = '.dap_member_customize_template_div .login_fb_btn';
	jQueryDM('#dm_fb_login_temp_width').bootstrapSlider().change(function() {
		jQueryDM(fb_btn_selector).css('max-width', this.value + 'px');
	});
	jQueryDM('#dm_fb_login_temp_height').bootstrapSlider().change(function() {
		jQueryDM(fb_btn_selector).css('line-height', this.value + 'px');
	});
	 
	jQueryDM('#dm_fb_login_temp_border_width').bootstrapSlider().change(function() {
		jQueryDM(fb_btn_selector).css('border-width', this.value + 'px');
	});
	jQueryDM('#dm_fb_login_temp_radius').bootstrapSlider().change(function() {
		jQueryDM(fb_btn_selector).css('border-radius', this.value + 'px');
	});
	jQueryDM('#dm_fb_login_temp_background_color_div,#dm_fb_login_temp_background_color').colorpicker().on('changeColor', function() {
		jQueryDM(fb_btn_selector).css('background-color', jQueryDM(this).colorpicker('getValue'));
	});
	jQueryDM('#dm_fb_login_temp_border_color,#dm_fb_login_temp_border_color_div').colorpicker().on('changeColor', function() {
		jQueryDM(fb_btn_selector).css('border-color', jQueryDM(this).colorpicker('getValue'));
	});
	
	jQueryDM('#dm_fb_login_temp_border_style').change(function(){
		jQueryDM(fb_btn_selector).css('border-style', jQueryDM(this).val());
	});
	
	/* fb outer section */
	var fb_btn_outer_selector = '.dap_member_customize_template_div .login-withfb-section';
	jQueryDM('#dm_fb_section_login_temp_background_color,#dm_fb_section_login_temp_background_color_div').colorpicker().on('changeColor', function() {
		jQueryDM(fb_btn_outer_selector).css('background-color', jQueryDM(this).colorpicker('getValue'));
	});
	
	
	
	//reset password button style
	var reset_btn_selector = '.dap_member_customize_reset_template_div #reset_outer .reset_pass_btn';
	jQueryDM('#dm_login_temp_reset_width').bootstrapSlider().change(function() {
		jQueryDM(reset_btn_selector).css('max-width', this.value + 'px');
	});
	jQueryDM('#dm_login_temp_reset_height').bootstrapSlider().change(function() {
		jQueryDM(reset_btn_selector).css('line-height', this.value + 'px');
	});
	 
	jQueryDM('#dm_login_temp_reset_border_width').bootstrapSlider().change(function() {
		jQueryDM(reset_btn_selector).css('border-width', this.value + 'px');
	});
	jQueryDM('#dm_login_temp_reset_radius').bootstrapSlider().change(function() {
		jQueryDM(reset_btn_selector).css('border-radius', this.value + 'px');
	});
	jQueryDM('#dm_login_temp_reset_background_color,#dm_login_temp_reset_background_color_div').colorpicker().on('changeColor', function() {
		jQueryDM(reset_btn_selector).css('background-color', jQueryDM(this).colorpicker('getValue'));
	});
	jQueryDM('#dm_login_temp_reset_border_color,#dm_login_temp_reset_border_color_div').colorpicker().on('changeColor', function() {
		jQueryDM(reset_btn_selector).css('border-color', jQueryDM(this).colorpicker('getValue'));
	});
	
	jQueryDM('#dm_login_temp_reset_border_style').change(function(){
		jQueryDM(reset_btn_selector).css('border-style', jQueryDM(this).val());
	});
	
	
	//forgot password button style
	var forgot_btn_selector = '.dap_member_customize_forgot_template_div #forgot_outer .forgot_btn';
	jQueryDM('#dm_login_temp_forgot_width').bootstrapSlider().change(function() {
		jQueryDM(forgot_btn_selector).css('max-width', this.value + 'px');
	});
	jQueryDM('#dm_login_temp_forgot_height').bootstrapSlider().change(function() {
		jQueryDM(forgot_btn_selector).css('line-height', this.value + 'px');
	});
	 
	jQueryDM('#dm_login_temp_forgot_border_width').bootstrapSlider().change(function() {
		jQueryDM(forgot_btn_selector).css('border-width', this.value + 'px');
	});
	jQueryDM('#dm_login_temp_forgot_radius').bootstrapSlider().change(function() {
		jQueryDM(forgot_btn_selector).css('border-radius', this.value + 'px');
	});
	jQueryDM('#dm_login_temp_forgot_background_color,#dm_login_temp_forgot_background_color_div').colorpicker().on('changeColor', function() {
		jQueryDM(forgot_btn_selector).css('background-color', jQueryDM(this).colorpicker('getValue'));
	});
	jQueryDM('#dm_login_temp_forgot_border_color,#dm_login_temp_forgot_border_color_div').colorpicker().on('changeColor', function() {
		jQueryDM(forgot_btn_selector).css('border-color', jQueryDM(this).colorpicker('getValue'));
	});
	
	jQueryDM('#dm_login_temp_forgot_border_style').change(function(){
		jQueryDM(forgot_btn_selector).css('border-style', jQueryDM(this).val());
	});
	 
	 
	//Placeholder 

   
	
	jQuery(document).on('focus','.dap_reset_re_pass,.dap_reset_pass,.dap_forgot_email,.dap_login_pass,.dap_login_email',function() {
		var text = jQuery(this).attr('placeholder');
		jQuery(this).val(text);
	});
	
	jQuery(document).on('focusout','.dap_reset_re_pass,.dap_reset_pass,.dap_forgot_email,.dap_login_pass,.dap_login_email',function() {
		jQuery(this).attr('placeholder',jQuery(this).val());
		jQuery(this).val('');
	});		
	
	
	 
}


function dap_member_login_tabs_Validation(){
	
		jQueryDM('#dap_member_login_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_general'){
			dap_member_show_tab_by_id(current_tab_id);
			return ;
		}
		
		if(dap_member_login_name_tab_validation()){
			current_tab_id = '#dap_member_general';
			dap_member_show_tab_by_id(current_tab_id);
			return ;
		}
		if(current_tab_id == '#dap_member_details'){
			
			edit_id = jQueryDM('.dap_member_content').find('input[name="edit_id"]').val();
			if(edit_id == ''){
				$message = "Please Save Template";
				dap_member_sweet_alert_message($message);
				//dap_member_show_tab_by_id('#dap_member_preview');
				return ;
			}
		}
		
		dap_member_show_tab_by_id(current_tab_id);
		});
}


function dap_member_login_name_tab_validation(){
	
	var validation_status = false;
	$parent_selector = '.dap_member_content';
	post_title = jQueryDM($parent_selector).find('input[name="name"]').val();
	login_page_url = jQueryDM($parent_selector).find('select[name="login_page_url"]').val();
	
	if(post_title == '' && login_page_url == ''){
		$message = "Please Enter a Name for your Login 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;
		
	}
	/*
	post_login_url = jQueryDM($parent_selector).find('input[name="post_login_url"]').val();
	if(post_login_url == ''){
		$message = "Enter Post Login URL";
		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_login_create_page($obj){
	
	$parent_selector = '.dap_member_content';
	post_title = jQueryDM($parent_selector).find('input[name="name"]').val();
	
	if(post_title == ''){
		$message = "Please Enter a Name for your Login 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 = "Login Page created successfully.";
			jQueryDM($parent_selector).text($message).addClass('text-success');
			jQueryDM('.dap_member_content input[name="page_id"]').val(response.post_id);
			return ;
		}
		
	    	
	});
	
}
