
var $jq = jQuery.noConflict();

$jq(document).ready(function(){
	dap_member_tiny_editor();
	//dap_member_login_mediauploader();
	//dap_customize_template_style_option();
	//dap_customize_button_style_option();
	//dap_BoxShadow_setting();
	dap_member_content_existing_page_select();

	var edit_id  = $jq('#edit_id').val();
	if(edit_id !="0" || edit_id != 0){	
		var template  = $jq('#sel_template').val();
		var type  = $jq('#template_selected_name').val();
		var temp_type  = $jq('#temp_type').val();	
		dap_customize_template_style_option();
		dap_customize_button_style_option(); 
		showhideoptions_template(template, type, temp_type);
		
	}
	
	$jq('#dap_member_preview_link, .dap_member_preview_link').on('click', function(e) {
		e.preventDefault();
		dap_show_preview();
		
	});
		
	$jq('#selecttemplate').on('change', function() {
		var selectdrop = $jq(this).val();
	   dap_selecttemplate(selectdrop);
	});
	  
	
	/********Save data********************/
	$jq(document).on('click', '#save_data',function() {			 
	   save_mycontent_data();
	});
	
	 
	
 /********change templates********************/
	$jq('#selecttemplate').on('change', function() {
		var temp = jQuery(this).val(); 
		 
		jQuery(".sel_template_outer").hide(); 
		jQuery("#"+temp+"_id").show(); 
		 
	});

 /********Sort Products********************/
    $jq(".sortProduct").click(function() {
        var select_prod = jQuery("#sortProduct_val").val();
        if (select_prod == "desc") {
            sortProductslist('showprod','id', 'desc');
            jQuery("#sortProduct_val").val('asc');
        } else {
            sortProductslist('showprod','id', 'asc');
            jQuery("#sortProduct_val").val('desc');
        }
    });
     $jq(".sortProductName").click(function() {
        var select_prod = jQuery("#sortProduct_val").val();
        if (select_prod == "desc") {
            sortProductslist('showprod','name', 'desc');
            jQuery("#sortProduct_val").val('asc');
        } else {
            sortProductslist('showprod','name', 'asc');
            jQuery("#sortProduct_val").val('desc');
        }
    });
     $jq(".sortProduct1").click(function() {
       var select_prod = jQuery("#sortProduct1_val").val();
        if (select_prod == "desc") {
            sortProductslist('hideprod','id', 'desc');
            jQuery("#sortProduct1_val").val('asc');
        } else {
            sortProductslist('hideprod','id', 'asc');
            jQuery("#sortProduct1_val").val('desc');
        }
    });
     $jq(".sortProductName1").click(function() {
       var select_prod = jQuery("#sortProduct1_val").val();
        if (select_prod == "desc") {
            sortProductslist('hideprod','id', 'desc');
            jQuery("#sortProduct1_val").val('asc');
        } else {
            sortProductslist('hideprod','name', 'asc');
            jQuery("#sortProduct1_val").val('desc');
        }
    });
    /******Create page*******/
	jQuery('#create_page_button').click(function() { 
			 		
			var post_title = jQuery('.page_name').val();
			post_title = jQuery.trim(post_title);
 			if (post_title != '') {
				 jQuery('.create_page_btn').text("Creating...") 
				jQuery.post(ajaxurl, {
					action: 'dapMemberGenerateWpPage',
					post_title: post_title,
				}, function(response) {
					response = JSON.parse(response); 
 
					jQuery('#page_id').val(response.post_id); 
					if (response.status == 'yes') {
						jQuery('.success_msg').hide();
						jQuery('.error_msg').show();
					} else {
						jQuery('.error_msg').hide();
						jQuery('.success_msg').show();
					}
					
					jQuery('.create_page_btn').text("Click to Create");
					setTimeout(function(){ 
						jQuery('.success_msg').hide();
						jQuery('.error_msg').hide();
					 }, 3000);
					
				});
			} else {
				swal('Please enter a name.');
			}

	});
    	
	/*******For Img Resolution****/
	$jq(document).on("change",'#dm_img_type', function(){
		var selval= $jq(this).val();
		 
		if(selval =="img_slider"){
			$jq(".img_slider_part").show();
			$jq(".img_res_part").hide();
		}else{
			$jq(".img_slider_part").hide();
			$jq(".img_res_part").show();
		}
		 
	});
	 
   /*****Not allow to edit the text****/
   
   jQuery(document).on('keydown',".notallowtoedit_cls",function(e){ 	     
	   jQuery(this).attr('contenteditable', false); 
	   jQuery(this).attr('contenteditable', true) ;
	    s = window.getSelection();
    
      var range = s.getRangeAt(0);

      var node = s.anchorNode;
      
      while (range.toString().indexOf(' ') != 0) {
        if(range.startOffset > 0){
            range.setStart(node, (range.startOffset - 1));
        }else{break;}

      }
     // range.setStart(node, range.startOffset + 1);

      do {
			range.setEnd(node, range.endOffset + 1);
      }

      while (range.toString().indexOf(' ') == -1 && range.toString().trim() != '');
      var str = range.toString().trim();
		e.preventDefault();
		return false;
	});
	
  jQuery(document).on('click',".notallowtoedit_cls",function(e){ 	     

		 s = window.getSelection();
    
      var range = s.getRangeAt(0);

      var node = s.anchorNode;
      
      while (range.toString().indexOf(' ') != 0) {
        if(range.startOffset > 0){
            range.setStart(node, (range.startOffset - 1));
        }else{break;}

      }
     // range.setStart(node, range.startOffset + 1);

      do {
			range.setEnd(node, range.endOffset + 1);
      }

      while (range.toString().indexOf(' ') == -1 && range.toString().trim() != '');
      var str = range.toString().trim();
		e.preventDefault();
		return false;
	});
 
   
    /* tabs section click event */
	jQuery('.dap_member_setting_outer a[data-toggle="tab"]').on('show.bs.tab', function (e) {
		
		$validation_step = jQuery(e.target).attr("id");		
		/*console.log($validation_step);*/
		$status = true;
		if( $validation_step == 'dap_member_general_tab'){
			 
		}else if($validation_step == "dap_member_customize_tab"){			
			$status = dap_member_customize_val();			
		}else if($validation_step == "dap_member_preview_link"){			
			$status = dap_member_shortcode_val();			
			
		}else if($validation_step == "dap_member_details_tab"){			
			$status = dap_member_shortcode_val();				
		}else {			
			$status = dap_member_shortcode_val();
		}

		if($status == false){
			e.preventDefault();
			return ;
		}
	});
        
});


	
	

function cs_img_customizer(selimgval, pic){
		 
		if(selimgval ==1){
			var maxWidth = 150; 
			var maxHeight = 150;   
		}
		if(selimgval ==2){
			var maxWidth = 200; 
			var maxHeight = 200;   
		}
		if(selimgval ==3){
			var maxWidth = 250; 
			var maxHeight = 250;   
		}
		if(selimgval ==4){
			var maxWidth = 300; 
			var maxHeight = 300;   
		}
		if(selimgval ==5){
			var maxWidth = 350; 
			var maxHeight = 350;   
		}
		if(selimgval ==6){
			var maxWidth = 400; 
			var maxHeight = 400;   
		}
		 		
		if(selimgval ==7){
			var maxWidth = 200; 
			var maxHeight = 150;   
		}
		if(selimgval ==8){
			var maxWidth = 250; 
			var maxHeight = 200;   
		}
		if(selimgval ==9){
			var maxWidth = 300; 
			var maxHeight = 250;   
		}
		if(selimgval ==10){
			var maxWidth = 350; 
			var maxHeight = 200;   
		}
		if(selimgval ==11){
			var maxWidth = 400; 
			var maxHeight = 350;   
		}
		if(selimgval ==12){
			var maxWidth = 200; 
			var maxHeight = 100;   
		}
		if(selimgval ==13){
			var maxWidth = 250; 
			var maxHeight = 150;   
		}
		if(selimgval ==14){
			var maxWidth = 300; 
			var maxHeight = 200;   
		}
		if(selimgval ==15){
			var maxWidth = 350; 
			var maxHeight = 250;   
		}
		if(selimgval ==16){
			var maxWidth = 400; 
			var maxHeight = 300;   
		}
		
		if(selimgval ==17){
			var maxWidth = 250; 
			var maxHeight = 100;   
		}
		if(selimgval ==18){
			var maxWidth = 300; 
			var maxHeight = 150;   
		}
		if(selimgval ==19){
			var maxWidth = 350; 
			var maxHeight = 200;   
		}
		if(selimgval ==20){
			var maxWidth = 400; 
			var maxHeight = 250;   
		}
		if(selimgval ==21){
			var maxWidth = 450; 
			var maxHeight = 300;   
		}
		if(selimgval ==22){
			var maxWidth = 500; 
			var maxHeight = 350;   
		}
		if(selimgval ==23){
			var maxWidth = 300; 
			var maxHeight = 100;   
		}
		if(selimgval ==24){
			var maxWidth = 350; 
			var maxHeight = 150;   
		}
		if(selimgval ==25){
			var maxWidth = 400; 
			var maxHeight = 200;   
		}
		if(selimgval ==26){
			var maxWidth = 450; 
			var maxHeight = 250;   
		}
		if(selimgval ==27){
			var maxWidth = 500; 
			var maxHeight = 300;   
		}
		
		 
		// need to remove these in of case img-element has set width and height
		pic.removeAttr("width"); 
		pic.removeAttr("height");
		pic.removeAttr("style");
		
		pic.attr('width',maxWidth);
		pic.attr('height',maxHeight);
		
		$jq("#cs_customize_template_tab .product_img .frontend_visibility").attr('width', maxWidth);
		$jq("#cs_customize_template_tab .product_img .frontend_visibility").attr('height',maxHeight);
		$jq("#cs_customize_template_tab .product_img .frontend_visibility").removeAttr("style");
			
		jQuery('.creditStore_frontend_wrapper').matchHeight();
}

function sortProductslist(showhideprod, orderBy, orderHow) { 
 		
		dap_member_show_loader();
		$jq.post(ajaxurl, {
			action: 'ajaxDapSortProducts',
			orderBy:orderBy,
			orderHow:orderHow,
		}, function(response) {
			//response = JSON.parse(response);
			if(showhideprod =="hideprod"){
				var startingdata= '<option value="NONE" selected="selected">NONE</option>';
				$jq('#hideproductid').html(startingdata+response);
			}else{
				var startingdata= '<option value="ALL" selected="selected">ALL</option>';
				$jq('#productid').html(startingdata+response);
			}		
			dap_member_hide_loader();
		});			
}

 /********preview the template********************/
function dap_member_mycontent_preview_temp(template , type, temp_type){
	 
	 
	dap_member_show_loader();
	$jq.post(ajaxurl, {
		action: 'dapMemberGetContentTemplate',
		template:template,
		type: type,
		temp_type: temp_type,
	}, function(response) {
		response = jQuery.parseJSON(response); 
		 
		$jq('#dap_member_login_preview_wrapper_modal .modal-body').html(response['cssstyle']+response['temp_html']);	
		
		$jq("#openpreview").trigger("click");		
 	
		dap_member_hide_loader();
	 	
	});	
	
}

 /********Get data of the template********************/
function dap_member_mycontent_customize_temp(template , type, temp_type){
	 
	$jq('.pre-box-div').removeClass("activecls");   
	$jq('.'+temp_type+'_'+type+' .pre-box-div').addClass("activecls");	
	
	showhideoptions_template(template, type, temp_type);
	
	dap_member_show_loader();
	$jq.post(ajaxurl, {
		action: 'dapMemberGetContentTemplate',
		template:template,
		type: type,
		temp_type: temp_type,
	}, function(response) {
		response = jQuery.parseJSON(response);
	 
		$jq('.css_container').html(response['cssstyle']);
		$jq('#dap_customize_template').html(response['temp_html']);		
		$jq('#template_selected_name').val(type);
		$jq('#sel_template').val(template);
		$jq('#temp_type').val(temp_type);
		$jq('.choices-template li').removeClass('activeCustomize');
		$jq('.choices-template').find('li.onecolumn_'+template).addClass('activeCustomize');
		 dap_customize_template_style_option();
		 dap_customize_button_style_option();
		dap_customize_template_style_option_set_defaultvalues(template , type, temp_type);
		dap_customize_button_style_option_set_defaultvalues(template , type, temp_type);
		dap_customize_toggle_set_defaultvalues(template , type, temp_type);
				
 		dap_member_tiny_editor();
	 	dap_member_hide_loader();
	 	dap_member_goto_next_tab('#dap_member_customize');
	 	
	});	
	
}

/**** select template options*****/
function showhideoptions_template(template, type,temp_type){
	
	$jq('.button_style, .image_customizer, .show_display_options_cls').show();
	$jq('.dm_padd_top_cls, .dm_padd_bottom_cls').show(); 
	$jq('.dm_background_cls, .upcoming_background_cls').show(); 
	$jq('.available_background_cls, .upcoming_background_cls, .clicktostart_cls').show(); 
	$jq('.dm_av_padd_top_cls').show(); 
	$jq('.product_name_bg_cls').hide(); 
	$jq('.show_up_content_cls, .show_av_content_cls').show();	
	$jq('.button_style, .image_customizer, .display_options').show();		  
	$jq('.dm_av_padd_top_cls, .dm_box_padd_bottom_cls').show(); 
	$jq('.available_background_cls, .upcoming_background_cls, .clicktostart_cls').show(); 
	$jq('.show_up_content_cls').show();	
	
	$jq('.customized_optional_multi_column').hide();    
	$jq('.temp_width_outer_mulcol').hide(); 
	$jq('.temp_width_outer_onecol').show(); 
	   
	if(temp_type == "singlecol" && type == "inpage"){
		$jq('.button_style').hide();
	}
	if(temp_type == "singlecol" && type == "postmetadata"){
		$jq('.button_style').hide();
	}
	
	if(temp_type == "multicol"){
		$jq('.customized_optional_multi_column').show();   
		$jq('.temp_width_outer_mulcol').show();
		$jq('.temp_width_outer_onecol').hide();    
		   
	} 
	
	if(type == "redirect"){
		$jq('.available_background_cls, .upcoming_background_cls, .clicktostart_cls').hide(); 
		$jq('.dm_av_padd_top_cls').hide(); 		
		$jq('.show_up_content_cls, .show_av_content_cls').hide(); 
	}
	
	
	if(type == "coursestyle"){
		$jq('.button_style, .image_customizer, .show_display_options_cls').hide();
		$jq('.show_prod_desc_cls, .product_name_bg_cls').show(); 
		$jq('.dm_padd_top_cls, .dm_padd_bottom_cls').hide(); 
		$jq('.dm_background_cls, .upcoming_background_cls').hide(); 		 
	}
	
	if(temp_type == "productlist"){
		$jq('.button_style, .image_customizer, .display_options').hide();		  
		$jq(' .dm_av_padd_top_cls, .dm_box_padd_bottom_cls').hide(); 
		$jq('.available_background_cls, .upcoming_background_cls, .clicktostart_cls').hide(); 	
		$jq('.product_name_bg_cls').show(); 	  
	} 
	
	if(temp_type == "payperpost"){
		$jq('.button_style, .image_customizer, .display_options').hide();		  
		$jq(' .dm_av_padd_top_cls, .dm_box_padd_bottom_cls').hide(); 
		$jq('.available_background_cls, .upcoming_background_cls, .clicktostart_cls').hide(); 	
		$jq('.product_name_bg_cls').show(); 	  
	} 
	
	if(temp_type == "contentlinks"){
		$jq('.button_style, .image_customizer').hide();		  
		$jq('.show_up_content_cls').hide();		  
		$jq(' .dm_av_padd_top_cls, .dm_box_padd_bottom_cls').hide(); 
		$jq('.available_background_cls, .upcoming_background_cls, .clicktostart_cls').hide(); 	
		$jq('.product_name_bg_cls').show(); 	  
	} 
	
	if( type =="postmetadata"  ){	
		jQuery(".show_access_start_date_outer , .show_access_end_date_outer, .img_size_outer, .show_img_outer, .metadata_temp_hide").addClass('hide_cls');
		jQuery(".img_size_outer1 , .metadata_temp").addClass('show_cls');
	}else{
		jQuery(".show_access_start_date_outer , .show_access_end_date_outer, .img_size_outer, .show_img_outer, .metadata_temp_hide").removeClass('hide_cls');
		jQuery(".img_size_outer1 , .metadata_temp").removeClass('show_cls');
	}
}


/*****validation***/
 function validation_mycontent(){ 
	 var validationattr = false;
	 $parent_selector = '.dap_member_content';
	 page_id = jQueryDM($parent_selector).find('#page_id').val();
	 selecttemplate_type = jQueryDM($parent_selector).find('#sel_template').val();
	 selecttemplate = jQueryDM($parent_selector).find('#selecttemplate').val();
	 temp_type = jQueryDM($parent_selector).find('#temp_type').val();
	 select_prod = jQueryDM($parent_selector).find('#select_prod').val();

		if(page_id =="" || page_id == null || typeof page_id == undefined || page_id == 0){
			swal("Please select a page");
			jQueryDM($parent_selector).find('#pagename').focus(); 
			return false;
		}
		
		if(selecttemplate =="contentlinks"){
			if(select_prod =="" || select_prod == null || typeof select_prod == undefined || select_prod == 0){
				swal("Please select a product");
				jQueryDM($parent_selector).find('#select_prod').focus(); 
				return false;
			}
		}
		
		if(selecttemplate_type =="" || selecttemplate_type == null || typeof selecttemplate_type == undefined || selecttemplate_type == 0){
			swal("Please select a template");			
			return false;
		}
		
		
		return validationattr = true;
				
 }
 
 function validation_mycontent_firsttab(dap_member_customize){ 
	 var validationattr = validation_mycontent();
	 if(validationattr == true){
		 dap_member_goto_next_tab(dap_member_customize);
	 }
 }
 
  function validation_mycontent_secondtab(dap_member_preview){ 
	 var validationattr = dap_member_shortcode_val();
	 if(validationattr == true){
		 dap_member_goto_next_tab(dap_member_preview);
	 }
 }
 
  function validation_mycontent_thirdtab(dap_member_details){ 
	 var validationattr = dap_member_shortcode_val();
	 if(validationattr == true){
		 dap_member_goto_next_tab(dap_member_details);
	 }
 }
 
 
 function dap_member_customize_val( ){ 
	  $parent_selector = '.dap_member_content';
	 page_id = jQueryDM($parent_selector).find('#page_id').val();
	 selecttemplate_type = jQueryDM($parent_selector).find('#sel_template').val();
	 selecttemplate = jQueryDM($parent_selector).find('#selecttemplate').val();
	 temp_type = jQueryDM($parent_selector).find('#temp_type').val();
	 select_prod = jQueryDM($parent_selector).find('#select_prod').val();

		if(page_id =="" || page_id == null || typeof page_id == undefined || page_id == 0){
			swal("Please select a page");
			jQueryDM($parent_selector).find('#pagename').focus(); 
			return false;
		}
		
		if(selecttemplate =="contentlinks"){
			if(select_prod =="" || select_prod == null || typeof select_prod == undefined || select_prod == 0){
				swal("Please select a product");
				jQueryDM($parent_selector).find('#select_prod').focus(); 
				return false;
			}
		}
		
		if(selecttemplate_type =="" || selecttemplate_type == null || typeof selecttemplate_type == undefined || selecttemplate_type == 0){
			swal("Please select a template");			
			return false;
		}
		
		
 }
 
 function dap_member_preview_val( ){ 
 
	 /* check previous tab validation */
		$status = dap_member_customize_val();		
		if($status == false){
			return false;			
		}	
				
 }

 function dap_member_shortcode_val( ){ 
 
	 /* check previous tab validation */
		$status = dap_member_customize_val();		
		if($status == false){
			return false;			
		}
		
		$parent_selector = '.dap_member_content';
		edit_id = jQueryDM($parent_selector).find('#edit_id').val();
		if(edit_id =="" || edit_id == null || typeof edit_id == undefined || edit_id == 0){
			swal("Please save the template");			
			return false;
		}
				
 }

 /********Save data of the template********************/
function save_mycontent_data(tabtogo){ 
		 
		
		$parent_selector = '.dap_member_content';
		
		post_title = jQueryDM($parent_selector).find('#pagename').val();
		edit_id = jQueryDM($parent_selector).find('#edit_id').val();
		page_id = jQueryDM($parent_selector).find('#page_id').val();
		showunavailableproducts = jQueryDM($parent_selector).find('input[name="showunavailableproducts"]:checked').val();
		productid = jQueryDM($parent_selector).find('#productid').val();
		hideproductid = jQueryDM($parent_selector).find('#hideproductid').val();	   
		template_selected_name = jQueryDM($parent_selector).find('#template_selected_name').val();		 
		selecttemplate_type = jQueryDM($parent_selector).find('#sel_template').val();		 
		sel_template = jQueryDM($parent_selector).find('#selecttemplate').val();
		selected_template = template_selected_name+'||'+selecttemplate_type+'||'+sel_template;		  
		
		/*****validation***/
		var val_mycontent = validation_mycontent();
		if(val_mycontent == false){
			return false;
		}
		dap_member_show_loader();
		
		/*****update the fields/data with customize style***/		
		addStyleToFrontendDiv(sel_template, template_selected_name);
				
		template_html_data = jQueryDM($parent_selector).find('#dap_customize_template').html();	 
		
		if(sel_template  =="singlecol"){
			if( template_selected_name !="redirect"){
				click_to_start = jQueryDM($parent_selector).find('.firstchild .click_to_start').html();
				upcoming_days = jQueryDM($parent_selector).find('.upcoming_days').html();	    
				available_data = jQueryDM($parent_selector).find('#dap_customize_template_content .firstchild td div').html();	    
				upcoming_data = jQueryDM($parent_selector).find('#dap_customize_template_content_upcoming .firstchild td div').html();	    
				template_html = template_html_data +"|:|"+click_to_start+"|:|"+upcoming_days+"|:|"+available_data+"|:|"+upcoming_data+"|:|"+"available_up_data";	
			}else{
				template_html = template_html_data +"|:|"+"click_to_start"+"|:|"+"upcoming_days"+"|:|"+"available_data"+"|:|"+"upcoming_data"+"|:|"+"available_up_data";
			}				
					
		}
		
		if(sel_template  =="multicol" ){		  
			
			if( template_selected_name =="popup"){
				template_html_data = jQueryDM($parent_selector).find('.dap_multicol_outer').html(); 
				available_up_data = jQueryDM($parent_selector).find('.multicol_table_outer').html();		
				click_to_start = jQueryDM($parent_selector).find('.firstchild .click_to_start').html();
				upcoming_days = jQueryDM($parent_selector).find('.upcoming_days').html();
				available_data = jQueryDM($parent_selector).find('#dap_customize_template_content .firstchild td div').html();	
				upcoming_data = jQueryDM($parent_selector).find('#dap_customize_template_content_upcoming .firstchild td div').html();	    
				template_html = template_html_data +"|:|"+click_to_start+"|:|"+upcoming_days+"|:|"+available_data+"|:|"+upcoming_data+"|:|"+available_up_data; 		
			}else{
				template_html = template_html_data +"|:|"+"click_to_start"+"|:|"+"upcoming_days"+"|:|"+"available_data"+"|:|"+"upcoming_data"+"|:|"+"available_up_data";
			}	
		}
		
		if(sel_template  =="productlist"){			 
			productlist_data = jQueryDM($parent_selector).find('.porduct_list.backend_visibility .firstchild').html(); 
			template_html = template_html_data +"|:|"+"click_to_start"+"|:|"+"upcoming_days"+"|:|"+productlist_data; 
		}
		
		
		if(sel_template  =="payperpost"){			 
			productlist_data = jQueryDM($parent_selector).find('.porduct_list.backend_visibility .firstchild').html(); 
			template_html = template_html_data +"|:|"+productlist_data; 
		}
		 
		if(sel_template  =="contentlinks"){	 
			content_links_data = jQueryDM($parent_selector).find('.content_links.backend_visibility .firstchild').html(); 
			template_html = template_html_data +"|:|"+"click_to_start"+"|:|"+"upcoming_days"+"|:|"+content_links_data; 
		}
		
		if(sel_template  =="singlecol"){
			if( template_selected_name =="postmetadata"){
				
			}
		}
		var prod_per_row ='col-sm-4';	
		var dm_wid_outer =900;	
		var box_wid =300;	
	    var dm_border_color_top="#03A9F4";
	    var modulebg="#d9edf7";
	    /* Template customizer values */
		dm_wid =  jQueryDM($parent_selector).find('#dm_wid').val();		
		dm_bdr_style =  jQueryDM($parent_selector).find('#dm_bdr_style').val();
		dm_bdr_wid =  jQueryDM($parent_selector).find('#dm_bdr_wid').val(); 
		dm_bdr_color =  jQueryDM($parent_selector).find('#dm_bdr_color').val();
		dm_padd_top =  jQueryDM($parent_selector).find('#dm_padd_top').val();
		dm_padd_bottom =  jQueryDM($parent_selector).find('#dm_padd_bottom').val();
		dm_av_padd_top =  jQueryDM($parent_selector).find('#dm_av_padd_top').val();
		dm_box_padd_bottom =  jQueryDM($parent_selector).find('#dm_box_padd_bottom').val();
		dm_background =  jQueryDM($parent_selector).find('#dm_background').val();
		available_background =  jQueryDM($parent_selector).find('#available_background').val();
		upcoming_background =  jQueryDM($parent_selector).find('#upcoming_background').val();
		clicktostart =  jQueryDM($parent_selector).find('#clicktostart').val();
		product_name_bg =  jQueryDM($parent_selector).find('#product_name_bg').val();
		prod_per_row =  jQueryDM($parent_selector).find('#prod_per_row').val();
		dm_wid_outer =  jQueryDM($parent_selector).find('#dm_wid_outer').val();
		dm_temp_align =  jQueryDM($parent_selector).find('#dm_temp_align').val();
		select_prod =  jQueryDM($parent_selector).find('#select_prod').val();
		box_wid =  jQueryDM($parent_selector).find('#box_wid').val();
		dm_border_color_top =  jQueryDM($parent_selector).find('#dm_border_color_top').val();
		modulebg =  jQueryDM($parent_selector).find('#modulebg').val();
	
	
		if(sel_template  !="multicol" ){		  
			var box_wid =300;
		}
		$template_option =  dm_wid+'||'+dm_bdr_style+'||'+dm_bdr_wid +'||'+dm_bdr_color+'||'+dm_padd_top+'||'+dm_padd_bottom+'||'+dm_av_padd_top+'||'+dm_box_padd_bottom+'||'+dm_background+'||'+available_background+'||'+upcoming_background+'||'+clicktostart+'||'+product_name_bg+'||'+prod_per_row+'||'+dm_wid_outer+'||'+dm_temp_align+'||'+box_wid+'||'+dm_border_color_top+'||'+modulebg;
		
		  
		/* image cutomizer */
		show_img =  jQueryDM($parent_selector).find('#show_img').val();
		dm_img_type =  jQueryDM($parent_selector).find('#dm_img_type').val();
		dm_img_res =  jQueryDM($parent_selector).find('#dm_img_res').val();
		dm_img_wid =  jQueryDM($parent_selector).find('#dm_img_wid').val();
		dm_img_wid1 =  jQueryDM($parent_selector).find('#dm_img_wid1').val();
		dm_img_height =  200;
		 
		$img_options =  show_img+'||'+dm_img_type+'||'+dm_img_res+'||'+dm_img_wid+'||'+dm_img_height+'||'+dm_img_wid1;
		 
		/*Display options */
		show_prod_name =  jQueryDM($parent_selector).find('#show_prod_name').prop('checked'); 
		show_prod_desc =  jQueryDM($parent_selector).find('#show_prod_desc').prop('checked'); 
		show_access_start_date =  jQueryDM($parent_selector).find('#show_access_start_date').prop('checked'); 
		show_access_end_date =  jQueryDM($parent_selector).find('#show_access_end_date').prop('checked'); 
		show_av_content =  jQueryDM($parent_selector).find('#show_av_content').prop('checked'); 
		show_up_content =  jQueryDM($parent_selector).find('#show_up_content').prop('checked'); 
	 
		$display_options =  show_prod_name+'||'+show_prod_desc+'||'+show_access_start_date+'||'+show_access_end_date+'||'+show_av_content+'||'+show_up_content;
		
		/*Btn options */
		dm_btn_wid= 150;
		dm_btn_height= 8;
		dm_btn_wid =  jQueryDM($parent_selector).find('#dm_btn_wid').val();
		dm_btn_height =  jQueryDM($parent_selector).find('#dm_btn_height').val();
		dm_backgroud_color =  jQueryDM($parent_selector).find('#dm_backgroud_color').val();		 
		dm_border_style =  jQueryDM($parent_selector).find('#dm_border_style').val();
		dm_border_wid =  jQueryDM($parent_selector).find('#dm_border_wid').val();
		dm_border_color =  jQueryDM($parent_selector).find('#dm_border_color').val();
		dm_border_rad =  jQueryDM($parent_selector).find('#dm_border_rad').val();
		
	    $btn_option = dm_btn_wid+'||'+dm_btn_height+'||'+dm_backgroud_color+'||'+dm_border_style+'||'+dm_border_wid+'||'+dm_border_color+'||'+dm_border_rad;
			
		//shadow effect variable 		
		var sprd_radius = jQueryDM($parent_selector).find('#sprd_radius').val();
		var blur_radius = jQueryDM($parent_selector).find('#blur_radius').val();
		var hor_lnth = jQueryDM($parent_selector).find('#hor_lnth').val();
		var ver_lnth = jQueryDM($parent_selector).find('#ver_lnth').val();
		var shad_clr = jQueryDM($parent_selector).find('#shad_clr').val();
		
		$shadow_effect = sprd_radius+'||'+blur_radius+'||'+hor_lnth+'||'+ver_lnth+'||'+shad_clr;
		 
		$template_option = $template_option+'|||'+$img_options+'|||'+$display_options+'|||'+$btn_option+'|||'+$shadow_effect;
		 
		var form_data_array = { };
		form_data_array['template_option'] = $template_option;
		form_data_array['post_title'] = post_title;
		form_data_array['page_id'] = page_id;
		form_data_array['edit_id'] = edit_id;
		form_data_array['showunavailableproducts'] = showunavailableproducts;
		form_data_array['productid'] = productid;
		form_data_array['hideproductid'] = hideproductid;
		form_data_array['selected_template'] = selected_template;
		form_data_array['template_html'] = template_html;
		form_data_array['sel_template'] = sel_template;
		form_data_array['select_prod'] = select_prod;
		
		
			
		jQueryDM.post(ajaxurl, {
			action: 'saveDapMemberContentAjax',
			data:form_data_array,
		}, function(response) {
			/*console.log(response);*/
			response = JSON.parse(response);
			dap_member_hide_loader();
					
			if(response.success){
				jQueryDM('.dap_member_content').find('input[name="edit_id"]').val(response.edit_id);
				jQueryDM('.mycontent_shrt').html(response.short_code_html);				
				dap_show_preview();		
				
				$title = "Saved";
				$message ="";
				$type = "success";
				
			}else if(response.error){
					$type = 'error';
					$title = 'Oops';
					$message = response.error;
			}
			
			if(tabtogo !=""){
				 dap_member_goto_next_tab(tabtogo); 
			}else{
				dap_member_sweet_alert_popup_with_msg_type($title,$message,$type);
			}
		});	
		
 
	
}


function save_mycontent_data_tab(tabtogo){	 
		 
		
		$parent_selector = '.dap_member_content';
		
		post_title = jQueryDM($parent_selector).find('#pagename').val();
		edit_id = jQueryDM($parent_selector).find('#edit_id').val();
		page_id = jQueryDM($parent_selector).find('#page_id').val();
		showunavailableproducts = jQueryDM($parent_selector).find('input[name="showunavailableproducts"]:checked').val();
		productid = jQueryDM($parent_selector).find('#productid').val();
		hideproductid = jQueryDM($parent_selector).find('#hideproductid').val();	   
		template_selected_name = jQueryDM($parent_selector).find('#template_selected_name').val();		 
		selecttemplate_type = jQueryDM($parent_selector).find('#sel_template').val();		 
		sel_template = jQueryDM($parent_selector).find('#selecttemplate').val();
		selected_template = template_selected_name+'||'+selecttemplate_type+'||'+sel_template;		  
		
		/*****validation***/
		var val_mycontent = validation_mycontent();
		if(val_mycontent == false){
			return false;
		}
		dap_member_show_loader();
		
		/*****update the fields/data with customize style***/		
		addStyleToFrontendDiv(sel_template, template_selected_name);
				
		template_html_data = jQueryDM($parent_selector).find('#dap_customize_template').html();	 
		
		if(sel_template  =="singlecol"){
			if( template_selected_name !="redirect"){
				click_to_start = jQueryDM($parent_selector).find('.firstchild .click_to_start').html();
				upcoming_days = jQueryDM($parent_selector).find('.upcoming_days').html();	    
				available_data = jQueryDM($parent_selector).find('#dap_customize_template_content .firstchild td div').html();	    
				upcoming_data = jQueryDM($parent_selector).find('#dap_customize_template_content_upcoming .firstchild td div').html();	    
				template_html = template_html_data +"|:|"+click_to_start+"|:|"+upcoming_days+"|:|"+available_data+"|:|"+upcoming_data+"|:|"+"available_up_data";	
			}else{
				template_html = template_html_data +"|:|"+"click_to_start"+"|:|"+"upcoming_days"+"|:|"+"available_data"+"|:|"+"upcoming_data"+"|:|"+"available_up_data";
			}				
					
		}
		
		if(sel_template  =="multicol" ){		  
			
			if( template_selected_name =="popup"){
				template_html_data = jQueryDM($parent_selector).find('.dap_multicol_outer').html(); 
				available_up_data = jQueryDM($parent_selector).find('.multicol_table_outer').html();		
				click_to_start = jQueryDM($parent_selector).find('.firstchild .click_to_start').html();
				upcoming_days = jQueryDM($parent_selector).find('.upcoming_days').html();
				available_data = jQueryDM($parent_selector).find('#dap_customize_template_content .firstchild td div').html();	
				upcoming_data = jQueryDM($parent_selector).find('#dap_customize_template_content_upcoming .firstchild td div').html();	    
				template_html = template_html_data +"|:|"+click_to_start+"|:|"+upcoming_days+"|:|"+available_data+"|:|"+upcoming_data+"|:|"+available_up_data; 		
			}else{
				template_html = template_html_data +"|:|"+"click_to_start"+"|:|"+"upcoming_days"+"|:|"+"available_data"+"|:|"+"upcoming_data"+"|:|"+"available_up_data";
			}	
		}
		
		if(sel_template  =="productlist"){			 
			productlist_data = jQueryDM($parent_selector).find('.porduct_list.backend_visibility .firstchild').html(); 
			template_html = template_html_data +"|:|"+"click_to_start"+"|:|"+"upcoming_days"+"|:|"+productlist_data; 
		}
		
		if(sel_template  == "payperpost"){			 
			productlist_data = jQueryDM($parent_selector).find('.porduct_list.backend_visibility .firstchild').html(); 
			template_html = template_html_data +"|:|"+productlist_data; 
		}
		 
		if(sel_template  =="contentlinks"){	 
			content_links_data = jQueryDM($parent_selector).find('.content_links.backend_visibility .firstchild').html(); 
			template_html = template_html_data +"|:|"+"click_to_start"+"|:|"+"upcoming_days"+"|:|"+content_links_data; 
		}
			
	    
	    /* Template customizer values */
		dm_wid =  jQueryDM($parent_selector).find('#dm_wid').val();		
		dm_bdr_style =  jQueryDM($parent_selector).find('#dm_bdr_style').val();
		dm_bdr_wid =  jQueryDM($parent_selector).find('#dm_bdr_wid').val(); 
		dm_border_color =  jQueryDM($parent_selector).find('#dm_border_color').val();
		dm_padd_top =  jQueryDM($parent_selector).find('#dm_padd_top').val();
		dm_padd_bottom =  jQueryDM($parent_selector).find('#dm_padd_bottom').val();
		dm_av_padd_top =  jQueryDM($parent_selector).find('#dm_av_padd_top').val();
		dm_box_padd_bottom =  jQueryDM($parent_selector).find('#dm_box_padd_bottom').val();
		dm_background =  jQueryDM($parent_selector).find('#dm_background').val();
		available_background =  jQueryDM($parent_selector).find('#available_background').val();
		upcoming_background =  jQueryDM($parent_selector).find('#upcoming_background').val();
		clicktostart =  jQueryDM($parent_selector).find('#clicktostart').val();
		product_name_bg =  jQueryDM($parent_selector).find('#product_name_bg').val();
		prod_per_row =  jQueryDM($parent_selector).find('#prod_per_row').val();
		dm_wid_outer =  jQueryDM($parent_selector).find('#dm_wid_outer').val();
		dm_temp_align =  jQueryDM($parent_selector).find('#dm_temp_align').val();
		select_prod =  jQueryDM($parent_selector).find('#select_prod').val();
		box_wid =  jQueryDM($parent_selector).find('#box_wid').val();
	 
		$template_option =  dm_wid+'||'+dm_bdr_style+'||'+dm_bdr_wid +'||'+dm_border_color+'||'+dm_padd_top+'||'+dm_padd_bottom+'||'+dm_av_padd_top+'||'+dm_box_padd_bottom+'||'+dm_background+'||'+available_background+'||'+upcoming_background+'||'+clicktostart+'||'+product_name_bg+'||'+prod_per_row+'||'+dm_wid_outer+'||'+dm_temp_align+'||'+box_wid;
		
		
		/* image cutomizer */
		show_img =  jQueryDM($parent_selector).find('#show_img').val();
		dm_img_type =  jQueryDM($parent_selector).find('#dm_img_type').val();
		dm_img_res =  jQueryDM($parent_selector).find('#dm_img_res').val();
		dm_img_wid =  jQueryDM($parent_selector).find('#dm_img_wid').val();
		dm_img_wid1 =  jQueryDM($parent_selector).find('#dm_img_wid1').val();
		dm_img_height =  jQueryDM($parent_selector).find('#dm_img_height').val();
		 
		$img_options =  show_img+'||'+dm_img_type+'||'+dm_img_res+'||'+dm_img_wid+'||'+dm_img_height+'||'+dm_img_wid1;
		
		/*Display options */
		show_prod_name =  jQueryDM($parent_selector).find('#show_prod_name:checked').prop('checked'); 
		show_prod_desc =  jQueryDM($parent_selector).find('#show_prod_desc').prop('checked'); 
		show_access_start_date =  jQueryDM($parent_selector).find('#show_access_start_date').prop('checked'); 
		show_access_end_date =  jQueryDM($parent_selector).find('#show_access_end_date').prop('checked'); 
		show_av_content =  jQueryDM($parent_selector).find('#show_av_content').prop('checked'); 
		show_up_content =  jQueryDM($parent_selector).find('#show_up_content').prop('checked'); 
	 
		$display_options =  show_prod_name+'||'+show_prod_desc+'||'+show_access_start_date+'||'+show_access_end_date+'||'+show_av_content+'||'+show_up_content;
		
		/*Btn options */
		dm_btn_wid =  jQueryDM($parent_selector).find('#dm_btn_wid').val();
		dm_btn_height =  jQueryDM($parent_selector).find('#dm_btn_height').val();
		dm_backgroud_color =  jQueryDM($parent_selector).find('#dm_backgroud_color').val();		 
		dm_border_style =  jQueryDM($parent_selector).find('#dm_border_style').val();
		dm_border_wid =  jQueryDM($parent_selector).find('#dm_border_wid').val();
		dm_border_color =  jQueryDM($parent_selector).find('#dm_border_color').val();
		dm_border_rad =  jQueryDM($parent_selector).find('#dm_border_rad').val();
		
	    $btn_option = dm_btn_wid+'||'+dm_btn_height+'||'+dm_backgroud_color+'||'+dm_border_style+'||'+dm_border_wid+'||'+dm_border_color+'||'+dm_border_rad;
			
		//shadow effect variable 		
		var sprd_radius = jQueryDM($parent_selector).find('#sprd_radius').val();
		var blur_radius = jQueryDM($parent_selector).find('#blur_radius').val();
		var hor_lnth = jQueryDM($parent_selector).find('#hor_lnth').val();
		var ver_lnth = jQueryDM($parent_selector).find('#ver_lnth').val();
		var shad_clr = jQueryDM($parent_selector).find('#shad_clr').val();
		
		$shadow_effect = sprd_radius+'||'+blur_radius+'||'+hor_lnth+'||'+ver_lnth+'||'+shad_clr;
		
		$template_option = $template_option+'|||'+$img_options+'|||'+$display_options+'|||'+$btn_option+'|||'+$shadow_effect;
		 
		var form_data_array = { };
		form_data_array['template_option'] = $template_option;
		form_data_array['post_title'] = post_title;
		form_data_array['page_id'] = page_id;
		form_data_array['edit_id'] = edit_id;
		form_data_array['showunavailableproducts'] = showunavailableproducts;
		form_data_array['productid'] = productid;
		form_data_array['hideproductid'] = hideproductid;
		form_data_array['selected_template'] = selected_template;
		form_data_array['template_html'] = template_html;
		form_data_array['sel_template'] = sel_template;
		form_data_array['select_prod'] = select_prod;
		
			
		jQueryDM.post(ajaxurl, {
			action: 'saveDapMemberContentAjax',
			data:form_data_array,
		}, function(response) {
			/*console.log(response);*/
			response = JSON.parse(response);
			dap_member_hide_loader();
					
			if(response.success){
				jQueryDM('.dap_member_content').find('input[name="edit_id"]').val(response.edit_id);
				jQueryDM('.mycontent_shrt').html(response.short_code_html);				
				dap_show_preview();		
				
				$title = "Saved";
				$message ="";
				$type = "success";
				 dap_member_goto_next_tab(tabtogo); 
			}else if(response.error){
					$type = 'error';
					$title = 'Oops';
					$message = response.error;
			}
			 //dap_member_sweet_alert_popup_with_msg_type($title,$message,$type);
		});	
		
 
	    
	}
	    
/********add Style To Frontend Div *********/
function addStyleToFrontendDiv(sel_template, type){
	
		if(sel_template  =="singlecol" || sel_template  =="multicol"){		
			/**product name*/ 			
			var prodname_data = jQueryDM(".product_name .backend_visibility").html(); 			 
			prodname_data = prodname_data.replace(/(<br>)*/g, '');	 
			var result_prodname_data = prodname_data.replace("Product Name", "%%PRODUCT_NAME%%");
			jQueryDM(".product_name .frontend_visibility").html(result_prodname_data); 
			 
			 /**product description*/ 		
			 var proddesc_data = jQueryDM(".product_description .backend_visibility").html(); 	
			proddesc_data = proddesc_data.replace(/(<br>)*/g, '');		 
			var result_proddesc_data = proddesc_data.replace("Lorem Ipsum is simply dummy text of the printing and typesetting industry.", "%%PRODUCT_DESC%%");
			jQueryDM(".product_description .frontend_visibility").html(result_proddesc_data); 	
			
			
			if(type  =="inpage" || type  =="redirect" ){	
				 /**access start date*/ 		
				var prodasd_data = jQueryDM(".access_start_date .backend_visibility").html(); 
				prodasd_data = prodasd_data.replace(/(<br>)*/g, '');			 
				var result_prodasd_data = prodasd_data.replace("2019-07-14", "%%ASD%%");
				jQueryDM(".access_start_date .frontend_visibility").html(result_prodasd_data); 	
				
				/**access end date*/ 	
				var prodaed_data = jQueryDM(".access_end_date .backend_visibility").html(); 
				prodaed_data = prodaed_data.replace(/(<br>)*/g, ''); 			 
				var result_prodaed_data = prodaed_data.replace("9999-12-30", "%%AED%%");
				jQueryDM(".access_end_date .frontend_visibility").html(result_prodaed_data); 
					
			}
			
			
			if( sel_template  =="multicol"){
				if(type =="popup"){
					/**access content*/ 	
					var btn_data = jQueryDM(".dap_btn_container.backend_visibility").html();			 
					jQueryDM(".frontend_visibility .dap_btn_container").html(btn_data); 
				}
			}	
			if(type =="redirect"){
				/**access content*/ 	
				var btn_data = jQueryDM(".dap_btn_container.backend_visibility").html();			 
				jQueryDM(".frontend_visibility .dap_btn_container").html(btn_data); 
			}
	 	
	}
	
	if(sel_template  =="contentlinks"){			
			/**product name*/ 			
			var prodname_data = jQueryDM(".product_name_li .backend_visibility").html(); 			 
			var result_prodname_data = prodname_data.replace("Product A", "%%PRODUCT_NAME%%");
			jQueryDM(".product_name_li .frontend_visibility").html(result_prodname_data); 
				
			 /**product description*/ 		
			 var proddesc_data = jQueryDM(".product_desc_li .backend_visibility").html(); 			 
			var result_proddesc_data = proddesc_data.replace("Lorem Ipsum is simply dummy text of the printing and typesetting industry", "%%PRODUCT_DESC%%");
			jQueryDM(".product_desc_li .frontend_visibility").html(result_proddesc_data); 	
			
			 /**access start date*/ 		
			var prodasd_data = jQueryDM(".access_start_date_li .backend_visibility").html(); 			 
			var result_prodasd_data = prodasd_data.replace("2019-07-14", "%%ASD%%");
			jQueryDM(".access_start_date_li .frontend_visibility").html(result_prodasd_data); 	
			
			/**access end date*/ 	
			var prodaed_data = jQueryDM(".access_end_date_li .backend_visibility").html(); 			 
			var result_prodaed_data = prodaed_data.replace("9999-12-30", "%%AED%%");
			jQueryDM(".access_end_date_li .frontend_visibility").html(result_prodaed_data); 	
	}
	

	
	
}


/**** select template options*****/
function dap_selecttemplate(selectdrop){
	if(selectdrop == "template1") {
		$jq('#multicolumn').hide();
		$jq('#onecolumn').show();
		$jq('#show_only_products').hide();
		$jq('#show_productslinks_noimage').hide();

	} else if(selectdrop == "template2") {
		$jq('#multicolumn').show();
		$jq('#onecolumn').hide();
		$jq('#show_only_products').hide();
		$jq('#show_productslinks_noimage').hide();
		
	} else if(selectdrop == "template3") {
	   $jq('#multicolumn').hide();
		$jq('#onecolumn').hide();
		$jq('#show_only_products').show();
		$jq('#show_productslinks_noimage').hide();
		
	} else if(selectdrop == "template4") {
		$jq('#multicolumn').hide();
		$jq('#onecolumn').hide();
		$jq('#show_only_products').hide();
		$jq('#show_productslinks_noimage').show();
	}
 }
		

/**** template style options set default values*****/
function dap_customize_template_style_option_set_defaultvalues(template , type, temp_type){
	 
	var template_outer_class_selector = 'dap_frontend_wrapper';
	
	if(temp_type =="singlecol" || temp_type =="productlist" || temp_type =="contentlinks" || temp_type =="postmetadata"){
		var dm_wid = $jq('.dap_frontend_wrapper_outer').css('width'); 
		dm_wid = dm_wid.split("px");
		var dm_wid = dm_wid[0];
		dm_wid = parseInt(dm_wid);
		jQuery("#dm_wid").bootstrapSlider('setValue', dm_wid); 
	}
	 
	var dm_background_div = $jq('.'+template_outer_class_selector).css('background-color');
	$jq('#dm_background_div').colorpicker('setValue', dm_background_div);
	
	
	if(temp_type =="singlecol" ||  temp_type =="multicol" ){
		if(type =="inpage"  || type =="popup" || type =="coursestyle" || type =="postmetadata" ){			 
			var available_background_div = $jq('#dap_customize_template_content table thead').css('background-color');
			$jq('#available_background_div').colorpicker('setValue', available_background_div);
			
			var dm_av_padd_top = $jq('#dap_customize_template_content').css('margin-top');
			dm_av_padd_top = dm_av_padd_top.split("px");
			var dm_av_padd_top = dm_av_padd_top[0];
			dm_av_padd_top = parseInt(dm_av_padd_top);
			$jq('#dm_av_padd_top').val(dm_av_padd_top);
		}	
		if(type =="inpage"  || type =="popup"  || type =="postmetadata"){	
			var upcoming_background_div = $jq('#dap_customize_template_content_upcoming table thead').css('background-color');
			$jq('#upcoming_background_div').colorpicker('setValue', upcoming_background_div);
		}
		
		
	}	
	 
	var dm_bdr_style = $jq('.'+template_outer_class_selector).css('border-style');
	$jq('#dm_bdr_style').val(dm_bdr_style);
	
	var dm_temp_align = $jq('.'+template_outer_class_selector).css('float');
	$jq('#dm_temp_align').val(dm_temp_align);
	
	
	
	if(temp_type =="singlecol"   ){
		if(type =="inpage"  || type =="popup" || type =="redirect" || type =="postmetadata"  ){			 
			var show_img = $jq('.product_img').css('display');
			if(show_img =="none"){
				$jq('#show_img').val("no");
			}else{
				$jq('#show_img').val("yes");
			}
			
			var dm_img_wid = $jq('.product_img').css('width');
			dm_img_wid = dm_img_wid.split("px");
			var dm_img_wid = dm_img_wid[0];
			dm_img_wid = parseInt(dm_img_wid);
			$jq('#dm_img_wid').val(dm_img_wid);
		 	
		 	if(type =="postmetadata"  ){	
				var dm_img_wid1 = $jq('.product_img1').css('width');
				dm_img_wid1 = dm_img_wid1.split("px");
				var dm_img_wid1 = dm_img_wid1[0];
				dm_img_wid1 = parseInt(dm_img_wid1);
				$jq('#dm_img_wid1').val(dm_img_wid1);
			 
			} 
		} 
		
		if(temp_type =="coursestyle" || temp_type =="productlist" || temp_type =="contentlinks" ){
			var product_name_bg_div = $jq('.'+template_outer_class_selector+' .prod_name').css('background-color');
			$jq('#product_name_bg_div').colorpicker('setValue', product_name_bg_div);			 
		}	
		if( type =="postmetadata"  ){	
			var dm_border_color_top_div = $jq('.'+template_outer_class_selector).css('border-top-color');
			$jq('#dm_border_color_top_div').colorpicker('setValue', dm_border_color_top_div);	
		}
					 
	}
	if( temp_type =="multicol" ){
		if(type =="inpage"  || type =="popup" || type =="redirect"  ){			 
			var show_img = $jq('.product_img').css('display');
			if(show_img =="none"){
				$jq('#show_img').val("no");
			}else{
				$jq('#show_img').val("yes");
			}
			
			var dm_img_wid = $jq('.product_img').css('height');
			dm_img_wid = dm_img_wid.split("px");
			var dm_img_wid = dm_img_wid[0];
			dm_img_wid = parseInt(dm_img_wid);			 
			$jq('#dm_img_wid').val(dm_img_wid);

		}
		
		if(temp_type =="coursestyle" || temp_type =="productlist" | temp_type =="contentlinks" ){
			var product_name_bg_div = $jq('.'+template_outer_class_selector+' .prod_name').css('background-color');
			$jq('#product_name_bg_div').colorpicker('setValue', product_name_bg_div);			 
		}	
					 
	}
	
	
		
	var dm_br_radius = $jq('.'+template_outer_class_selector).css('border-radius'); 
	dm_br_radius = dm_br_radius.split("px");
	var dm_br_radius = dm_br_radius[0];
	dm_br_radius = parseInt(dm_br_radius);
 	$jq('#dm_br_radius').val(dm_br_radius);
	
	var dm_bdr_wid = $jq('.'+template_outer_class_selector).css('border-width');
	dm_bdr_wid = dm_bdr_wid.split("px");
	var dm_bdr_wid = dm_bdr_wid[0];
	dm_bdr_wid = parseInt(dm_bdr_wid);
	$jq('#dm_bdr_wid').val(dm_bdr_wid);
	
	
	var dm_bdr_color_div = $jq('.'+template_outer_class_selector).css('border-bottom-color');
	$jq('#dm_bdr_color_div').colorpicker('setValue', dm_bdr_color_div);	
	
	
	var clicktostart_div = $jq('.click_to_start_btn div').css('background-color');
	$jq('#clicktostart_div').colorpicker('setValue', clicktostart_div);	
 
	var dm_padd_top = $jq('.product_item_details').css('margin-top');
	dm_padd_top = dm_padd_top.split("px");
	var dm_padd_top = dm_padd_top[0];
	dm_padd_top = parseInt(dm_padd_top);
	$jq('#dm_padd_top').val(dm_padd_top);
	
	var dm_padd_bottom = $jq('.product_item_details').css('margin-bottom');
	dm_padd_bottom = dm_padd_bottom.split("px");
	var dm_padd_bottom = dm_padd_bottom[0];
	dm_padd_bottom = parseInt(dm_padd_bottom);
	$jq('#dm_padd_bottom').val(dm_padd_bottom);	
		
	var dm_box_padd_bottom = $jq('.'+template_outer_class_selector).css('margin-top');
	dm_box_padd_bottom = dm_box_padd_bottom.split("px");
	var dm_box_padd_bottom = dm_box_padd_bottom[0];
	dm_box_padd_bottom = parseInt(dm_box_padd_bottom);
	$jq('#dm_box_padd_bottom').val(dm_box_padd_bottom);
		 
}

/**** access content set default values*****/
 
function dap_customize_button_style_option_set_defaultvalues(template , type, temp_type){	 
	var template_outer_class_selector = 'dap_frontend_wrapper';
	
	if(temp_type =="singlecol" ||  temp_type =="multicol" ){
		if(type =="inpage"  || type =="popup" || type =="redirect"  ){	
			var dm_btn_wid = $jq('.access_content_btn').css('width');
			dm_btn_wid = dm_btn_wid.split("px");
			var dm_btn_wid = dm_btn_wid[0];
			dm_btn_wid = parseInt(dm_btn_wid);
			$jq('#dm_btn_wid').val(dm_btn_wid);
			
			var dm_btn_height = $jq('.access_content_btn').css('padding-top');
			dm_btn_height = dm_btn_height.split("px");
			var dm_btn_height = dm_btn_height[0];
			dm_btn_height = parseInt(dm_btn_height);
			$jq('#dm_btn_height').val(dm_btn_height);
			
			var dm_border_wid = $jq('.access_content_btn').css('border-width');
			dm_border_wid = dm_border_wid.split("px");
			var dm_border_wid = dm_border_wid[0];
			dm_border_wid = parseInt(dm_border_wid);
			$jq('#dm_border_wid').val(dm_border_wid);
			
			var dm_border_rad = $jq('.access_content_btn').css('border-radius');
			dm_border_rad = dm_border_rad.split("px");
			var dm_border_rad = dm_border_rad[0];
			dm_border_rad = parseInt(dm_border_rad);
			$jq('#dm_border_rad').val(dm_border_rad);
			
			var dm_border_style = $jq('.access_content_btn').css('border-style');
			$jq('#dm_border_style').val(dm_border_style);
			 
			var dm_bdr_color_div = $jq('.'+template_outer_class_selector).css('border-bottom-color');
			$jq('#dm_bdr_color_div').colorpicker('setValue', dm_bdr_color_div);	
	
			var dm_backgroud_color_div = $jq('.access_content_btn').css('background-color');
			$jq('#dm_backgroud_color_div').colorpicker('setValue', dm_backgroud_color_div);	
			
		}
		if( type =="postmetadata"  ){	
			var dm_border_color_top_div = $jq('.'+template_outer_class_selector).css('border-top-color');
			$jq('#dm_border_color_top_div').colorpicker('setValue', dm_border_color_top_div);	
		}
	} 
	  
}

/**** access content set default values*****/
 
function dap_customize_toggle_set_defaultvalues(template , type, temp_type){	 
	 
	var product_name_display = jQuery('.product_name').css('display'); 
	if (product_name_display == "none") {		
		jQuery("#show_prod_name").bootstrapToggle('off');
	} else {
		jQuery("#show_prod_name").bootstrapToggle('on');
	}
	
	var product_description_display = jQuery('.product_description').css('display'); 
	if (product_description_display == "none") {		
		jQuery("#show_prod_desc").bootstrapToggle('off');
	} else {
		jQuery("#show_prod_desc").bootstrapToggle('on');
	}
	
	var access_start_date_display = jQuery('.access_start_date').css('display'); 
	if (access_start_date_display == "none") {		
		jQuery("#show_access_start_date").bootstrapToggle('off');
	} else {
		jQuery("#show_access_start_date").bootstrapToggle('on');
	}
	
	var access_end_date_display = jQuery('.access_end_date').css('display'); 
	if (access_end_date_display == "none") {		
		jQuery("#show_access_end_date").bootstrapToggle('off');
	} else {
		jQuery("#show_access_end_date").bootstrapToggle('on');
	}
 
	var dap_customize_template_content = jQuery('#dap_customize_template_content').css('display'); 
	if (dap_customize_template_content == "none") {		
		jQuery("#show_av_content").bootstrapToggle('off');
	} else {
		jQuery("#show_av_content").bootstrapToggle('on');
	}
 
	var access_end_date_display = jQuery('#dap_customize_template_content_upcoming').css('display'); 
	if (access_end_date_display == "none") {		
		jQuery("#show_up_content").bootstrapToggle('off');
	} else {
		jQuery("#show_up_content").bootstrapToggle('on');
	}
  
	  
}


/**** template style options*****/
function dap_customize_template_style_option(){
	
	var template_outer_class_selector = 'dap_frontend_wrapper';
	$jq('#dm_wid').bootstrapSlider().change(function() {	
		$jq('.dap_frontend_wrapper_outer').css('width', this.value + 'px');
	});
	$jq('#dm_wid_outer').bootstrapSlider().change(function() {	
		$jq('.dap_member_preview_outer').css('width', this.value + 'px');
	});
	
	$jq('#dm_background_div').colorpicker().on('changeColor', function() {
		$jq('.'+template_outer_class_selector).css('background-color', $jq(this).colorpicker('getValue'));
	});	
	
	$jq('#available_background_div').colorpicker().on('changeColor', function() {
		$jq('#dap_customize_template_content table thead').css('background-color', $jq(this).colorpicker('getValue'));
	});	
	$jq('#upcoming_background_div').colorpicker().on('changeColor', function() {
		$jq('#dap_customize_template_content_upcoming table thead').css('background-color', $jq(this).colorpicker('getValue'));
	});	
 
	$jq('#dm_bdr_style').change(function(){
		var style1 = $jq(this).val();
		$jq('.'+template_outer_class_selector).css('border-style', style1);
	});
	
	$jq('#dm_temp_align').change(function(){
		var dm_temp_align = $jq(this).val();
		$jq('.dap_frontend_wrapper_outer').css('float', dm_temp_align);
	}); 
	/*
	$jq('#show_img').change(function(){
		var show_img = $jq(this).val();	 
		if(show_img =="no"){
			$jq('.product_img').hide();
			$jq('.product_item_details').addClass("wid-full");
			$jq('.dap_btn_container').addClass("relative-cls");
		}else{
			$jq('.product_img').show();
			$jq('.product_item_details').removeClass("wid-full");
			$jq('.dap_btn_container').removeClass("relative-cls");
		}		
	});
	  $jq('#dm_img_height').bootstrapSlider().change(function() {		 
		$jq('.product_img img').css('height', this.value + 'px');
	});
	  */
 
	$jq('#dm_br_radius').bootstrapSlider().change(function() {	
		$jq('.'+template_outer_class_selector).css('border-radius', this.value + 'px');
	});
 
	$jq('#dm_bdr_wid').bootstrapSlider().change(function() {
		$jq('.'+template_outer_class_selector).css('border-width', this.value + 'px');
	}); 
	
	$jq('#dm_bdr_color_div').colorpicker().on('changeColor', function() {
		
      
       if($jq('#template_selected_name').val() == 'postmetadata'){
		$jq('.'+template_outer_class_selector).css('border-bottom-color', $jq(this).colorpicker('getValue'));
		$jq('.'+template_outer_class_selector).css('border-right-color', $jq(this).colorpicker('getValue'));
		$jq('.'+template_outer_class_selector).css('border-left-color', $jq(this).colorpicker('getValue'));
	   }else {
		   $jq('.'+template_outer_class_selector).css('border-color', $jq(this).colorpicker('getValue'));
	   }
	});
	$jq('#dm_border_color_top_div').colorpicker().on('changeColor', function() {
		$jq('.'+template_outer_class_selector).css('border-top-color', $jq(this).colorpicker('getValue'));
	});
	$jq('#clicktostart_div').colorpicker().on('changeColor', function() {
		$jq(' .click_to_start_btn div').css('background-color', $jq(this).colorpicker('getValue'));
	});
	$jq('#modulebg_div').colorpicker().on('changeColor', function() {
		//$jq(' .click_to_start_btn div').css('background-color', $jq(this).colorpicker('getValue'));
	});
	$jq('#product_name_bg_div').colorpicker().on('changeColor', function() {
		$jq('.'+template_outer_class_selector+' .prod_name').css('background-color', $jq(this).colorpicker('getValue'));
	});
	
	$jq('#dm_padd_top').bootstrapSlider().change(function() {
		$jq('.product_item_details').css('margin-top', this.value + 'px');
	});
	$jq('#dm_padd_bottom').bootstrapSlider().change(function() {		 
		$jq('.product_item_details').css('margin-bottom', this.value + 'px');
	});
	
	$jq('#dm_av_padd_top').bootstrapSlider().change(function() {
		$jq('#dap_customize_template_content').css('margin-top', this.value + 'px');
	});
	$jq('#dm_box_padd_bottom').bootstrapSlider().change(function() {
		$jq('.'+template_outer_class_selector).css('margin-bottom', this.value + 'px');
	});
	$jq('#dm_img_wid').bootstrapSlider().change(function() {
		 
       if($jq('#temp_type').val() == 'multicol'){
		   $jq('.product_img').css('height', this.value + 'px');
	   }else{
		   $jq('.product_img').css('width', this.value + 'px');
	   }
		
	});
	$jq('#dm_img_wid1').bootstrapSlider().change(function() {
		$jq('.product_img1').css('width', this.value + 'px');
	});
	  
	jQuery("#hor_lnth").bootstrapSlider().change(function() {		 
		var hor_lnth = jQuery(this.value);	 
		var colorval = jQuery("#shad_clr").val();		 
		dap_BoxShadow(colorval);
	});

	jQuery("#ver_lnth").bootstrapSlider().change(function() {
		var ver_lnth = jQuery(this.value);
		var colorval = jQuery("#shad_clr").val();
		dap_BoxShadow(colorval);
	}); 
	jQuery("#blur_radius").bootstrapSlider().change(function() {
		var blur_radius = jQuery(this.value);
		var colorval = jQuery("#shad_clr").val();
		dap_BoxShadow(colorval);
	}); 
	jQuery("#sprd_radius").bootstrapSlider().change(function() {
		var sprd_radius = jQuery(this.value);
		var colorval = jQuery("#shad_clr").val();
		dap_BoxShadow(colorval);
	});
	  
	jQuery("#show_prod_name").change(function() {
		if (this.checked == true) {
			jQuery('.product_name').show();			 
		} else {
			jQuery('.product_name').hide();			
		}
	});
	 
	jQuery("#show_prod_desc").change(function() {
		if (this.checked == true) {
			jQuery('.product_description').show();			 
		} else {
			jQuery('.product_description').hide();			
		}
	});
	
	jQuery("#show_access_start_date").change(function() {
		if (this.checked == true) {
			jQuery('.access_start_date').show();			 
		} else {
			jQuery('.access_start_date').hide();			
		}
	});
	
	jQuery("#show_access_end_date").change(function() {
		if (this.checked == true) {
			jQuery('.access_end_date').show();			 
		} else {
			jQuery('.access_end_date').hide();			
		}
	});
	
	jQuery("#show_av_content").change(function() {
		if (this.checked == true) {
			jQuery('#dap_customize_template_content').show();			 
		} else {
			jQuery('#dap_customize_template_content').hide();			
		}
	});
	
	jQuery("#show_up_content").change(function() {
		if (this.checked == true) {
			jQuery('#dap_customize_template_content_upcoming').show();			 
		} else {
			jQuery('#dap_customize_template_content_upcoming').hide();			
		}
	}); 
	 
}

 /**access content  button customizer */
function dap_customize_button_style_option(){	 
	/*box width*/
	$jq('#box_wid').bootstrapSlider().change(function() {
		$jq('.preview_inner_div').find('.dap_multi_column_outer').css('width', this.value + 'px');
	});
	
	 
	/*box width*/
	
	$jq('#dm_btn_wid').bootstrapSlider().change(function() {
		$jq('.access_content_btn').css('width', this.value + 'px');
	});
	
	$jq('#dm_btn_height').bootstrapSlider().change(function() {
		$jq('.access_content_btn').css('padding-top', this.value + 'px');
		$jq('.access_content_btn').css('padding-bottom', this.value + 'px');
	});
		
	$jq('#dm_backgroud_color_div').colorpicker().on('changeColor', function() {
		$jq('.access_content_btn').css('background-color', $jq(this).colorpicker('getValue'));
	});	
	
	$jq('#dm_border_wid').bootstrapSlider().change(function() {
		$jq('.access_content_btn').css('border-width', this.value + 'px');
	});
	
	$jq('#dm_border_style').change(function(){
		var style = $jq(this).val();
		$jq('.access_content_btn').css('border-style', style);
	});
	
	$jq('#dm_border_color_div').colorpicker().on('changeColor', function() {
		$jq('.access_content_btn').css('border-color', $jq(this).colorpicker('getValue'));
	});
	$jq('#dm_border_rad').bootstrapSlider().change(function() {
		$jq('.access_content_btn').css('border-radius', this.value + 'px');
	});
	jQuery('#shad_clr_div,#shad_clr').colorpicker().on('changeColor', function() {
		dap_BoxShadow(jQuery(this).colorpicker('getValue'));
	});
	  
}

function dap_BoxShadow_setting() {
	var li_boxshadow = jQuery('.dap_frontend_wrapper').css('box-shadow').match(/(-?\d+px)|(rgb\(.+\))/g);
	var li_boxshadow0 = li_boxshadow[0];
	var li_boxshadow1 = li_boxshadow[1];
	var li_boxshadow2 = li_boxshadow[2];
	var li_boxshadow3 = li_boxshadow[3];
	var li_boxshadow4 = li_boxshadow[4];
	jQuery('#shad_clr').colorpicker('setValue', li_boxshadow0);
	var li_boxshadow_val1 = li_boxshadow1.split("px");
	li_boxshadow_val1 = li_boxshadow_val1[0];
	li_boxshadow_val1 = parseInt(li_boxshadow_val1);
	jQuery("#hor_lnth").bootstrapSlider('setValue', li_boxshadow_val1);
	var li_boxshadow_val2 = li_boxshadow2.split("px");
	li_boxshadow_val2 = li_boxshadow_val2[0];
	li_boxshadow_val2 = parseInt(li_boxshadow_val2);
	jQuery("#ver_lnth").bootstrapSlider('setValue', li_boxshadow_val2);
	var li_boxshadow_val3 = li_boxshadow3.split("px");
	li_boxshadow_val3 = li_boxshadow_val3[0];
	li_boxshadow_val3 = parseInt(li_boxshadow_val3);
	jQuery("#blur_radius").bootstrapSlider('setValue', li_boxshadow_val3);
	var li_boxshadow_val4 = li_boxshadow4.split("px");
	li_boxshadow_val4 = li_boxshadow_val4[0];
	li_boxshadow_val4 = parseInt(li_boxshadow_val4);
	jQuery("#sprd_radius").bootstrapSlider('setValue', li_boxshadow_val4);
	dap_BoxShadow();
}

function dap_BoxShadow(colorval) {
	var hor_lnth = parseFloat(jQuery('#hor_lnth').val());
	var ver_lnth = parseFloat(jQuery('#ver_lnth').val());
	var blur_radius = parseFloat(jQuery('#blur_radius').val());
	var sprd_radius = parseFloat(jQuery('#sprd_radius').val());
	var shad_clr = colorval;
	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;
	jQuery('.dap_frontend_wrapper').css('-webkit-box-shadow', box_shadow);
	jQuery('.dap_frontend_wrapper').css('-moz-box-shadow', box_shadow);
	jQuery('.dap_frontend_wrapper').css('box-shadow', box_shadow);
}



function dap_show_preview(){
	 
	$jq('#dap_member_preview').find('.dap_member_preview_outer').html('');
	var preview_html ="";
	var temp_type =  $jq('#temp_type').val();		
	var dm_wid =  $jq('.dap_member_content').find('#dm_wid').val();		
			
	var dm_wid_outer =  $jq('.dap_member_content').find('#dm_wid_outer').val();		
	var preview_html = $jq('#dap_customize_template').html();	
	var width =  $jq('#dap_customize_template').find('.dap_multi_column_outer').css('width');	
	 
	if(temp_type =="multicol"){
		var finalWidth = parseInt(dm_wid_outer) + parseInt(60);
	}else{
	 var finalWidth = parseInt(dm_wid) + parseInt(60);
	}
	
	
	$jq('#dap_member_preview').find('.dap_member_preview_outer').css('width' , finalWidth+'px');
	
	if($jq('#selecttemplate').children("option:selected").val() == 'singlecol'){
		
		$jq('#box_width_outer').hide();		
		 
		preview_html = $jq('#dap_customize_template').html();
		
		var i;
		for (i = 0; i < 1; i++) { 
			$jq('#dap_member_preview').find('.dap_member_preview_outer').append("<div class='col-md-12 preview_inner_div'>"+preview_html+"</div>");
		}	
	}else if($jq('#selecttemplate').children("option:selected").val() == 'multicol'){
		
		var prod_per_row = $jq('#prod_per_row').val();
		var preview_html = $jq('.dap_multicol_outer').html();
		var box_wid =  $jq('.dap_member_content').find('#box_wid').val();
		
		$jq('#box_width_outer').show();
		 
		var i;
		for (i = 0; i < 6; i++) { 
			$jq('#dap_member_preview').find('.dap_member_preview_outer').append("<div class='"+prod_per_row+" preview_inner_div'>"+preview_html+"</div>");
			$jq('#dap_member_preview').find('.dap_multi_column_outer').css('width', box_wid);
			
		}		
	}else{
		preview_html = $jq('#dap_customize_template').html();
		
		$jq('#dap_member_preview').find('.dap_member_preview_outer').append("<div class='col-md-12 preview_inner_div'>"+preview_html+"</div>");
	}
	$jq("#dap_member_preview").find('.dap_member_tiny_editor').attr("contenteditable" , "false");
	$jq('#dap_member_preview').find('.dap_member_preview_outer').find('.dap_multi_column_outer').css('max-width' , '100%');
}


function dap_member_content_existing_page_select(){
	 
	$jq('#page_url').on('change',function(){
		var page_id = $jq(this).val();
		dap_member_show_loader();
		$jq.post(ajaxurl, {
			action: 'dap_checked_page_id_and_page_type_used',
			page_id:page_id,
			page_type:'mycontent',
		}, 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);
				$jq('#page_url').val('');
				return ;
			}else if(response == 'no'){				
				$jq('#page_id').val(page_id);
			}
	
		});
	});
}
