var $jq = jQuery.noConflict();
$jq(document).ready(function() {
	
	/*Show hide divs*/
	dap_member_show_divs();
	
    /* Colorpicker and range slider*/
	dap_member_customizer();
       
   /*Add or Remove bootstrap css*/
   dap_member_add_remove_scripts();
});

function dap_member_add_remove_scripts() {
        setInterval(function() {
            var filename = $jq("#bootstrap_css").val();
            var filename1 = '';
            var bodylast = $jq("body.modal-open");
            if(bodylast.length) {
                var head = $jq("head");
                var headlinklast = head.find("link[rel='stylesheet']:last");
                var linkElement = "<link title='mystyle' rel='stylesheet' href='" + filename + "' type='text/css' media='screen'>";
                if(headlinklast.length) {
                    headlinklast.after(linkElement);
                } else {
                    head.append(linkElement);
                }
            } else {
                $jq('link[title="mystyle"]').remove();

            }
        }, 1000);
}

function dap_member_customizer() {
        $jq('#bg_clr_div').colorpicker();
        $jq('#bg_clr_div1').colorpicker();
        $jq('#bg_clr_div2').colorpicker();
        $jq('#bg_clr_div3').colorpicker();
        $jq('#resetpass_btnbg_div').colorpicker();
        $jq('#forgotpass_btnbg_div').colorpicker();
        $jq('#prodtext_clr_div').colorpicker();
        $jq('#prodtext_clr_div1').colorpicker();
        
        $jq('#bg_clr_div_cs').colorpicker();
        $jq('#bg_clr_div_cs1').colorpicker();
        $jq('#bg_clr_div_cs2').colorpicker();
        $jq('#bg_clr_div_cs3').colorpicker();
        $jq('#bg_clr_div_cs4').colorpicker();
        $jq('#bg_clr_div_cs5').colorpicker();
        $jq('#bg_clr_div_cs6').colorpicker();
        $jq('#bg_clr_div_cs7').colorpicker();
        
        $jq('.pausebutton_customizer #btn_bg').colorpicker().on('changeColor',function(){
            var clr = $jq(this).colorpicker('getValue');
            $jq('#pausebutton').css('background-color',clr);
        });
         
        $jq('.pausebutton_customizer #btn_border_clr').colorpicker().on('changeColor',function(){
            var clr = $jq(this).colorpicker('getValue');
            $jq('#pausebutton').css('border-color',clr);
        });
        
        $jq('.pausebutton_customizer #btn_clr').colorpicker().on('changeColor',function(){
            var clr = $jq(this).colorpicker('getValue');
            $jq('#pausebutton').css('color',clr);
        });
        
        
        $jq('.cancelbutton_customizer #btn_bg').colorpicker().on('changeColor',function(){
            var clr = $jq(this).colorpicker('getValue');
            $jq('#cancelbutton').css('background-color',clr);
        });
        
        $jq('.cancelbutton_customizer #btn_border_clr').colorpicker().on('changeColor',function(){
            var clr = $jq(this).colorpicker('getValue');
            $jq('#cancelbutton').css('border-color',clr);
        });
        
        $jq('.cancelbutton_customizer #btn_clr').colorpicker().on('changeColor',function(){
            var clr = $jq(this).colorpicker('getValue');
            $jq('#cancelbutton').css('color',clr);
        });
        
        
        $jq('.resumebutton_customizer #btn_bg').colorpicker().on('changeColor',function(){
            var clr = $jq(this).colorpicker('getValue');
            $jq('#resumebutton').css('background-color',clr);
        });
        
        $jq('.resumebutton_customizer #btn_border_clr').colorpicker().on('changeColor',function(){
            var clr = $jq(this).colorpicker('getValue');
            $jq('#resumebutton').css('border-color',clr);
        });
        
        $jq('.resumebutton_customizer #btn_clr').colorpicker().on('changeColor',function(){
            var clr = $jq(this).colorpicker('getValue');
            $jq('#resumebutton').css('color',clr);
        });
         $jq('#boxWidth').bootstrapSlider({
        formatter: function(value) {
            return 'Current value: ' + value + 'px';
        }
    });
    
    
    $jq('.pausebutton_customizer #borderwidth').bootstrapSlider({
        formatter: function(value) {
            return 'Current value: ' + value ;
        }
    });
    
     $jq('.pausebutton_customizer #borderwidth').on('slide',function(){
		var vall = jQuery(this).val();
		$jq('#pausebutton').css('border-width',vall);
	});
    
    $jq('.resumebutton_customizer  #borderwidth').bootstrapSlider({
        formatter: function(value) {
            return 'Current value: ' + value ;
        }
    });
    
    $jq('.resumebutton_customizer  #borderwidth').on('slide',function(){
		var vall = jQuery(this).val();
		$jq('#resumebutton').css('border-width',vall);
	});
	
    $jq('.cancelbutton_customizer  #borderwidth').bootstrapSlider({
        formatter: function(value) {
            return 'Current value: ' + value ;
        }
    });
    
    $jq('.cancelbutton_customizer  #borderwidth').on('slide',function(){
		var vall = jQuery(this).val();
		$jq('#cancelbutton').css('border-width',vall);
	});
    

    $jq('.pausebutton_customizer #borderradius').bootstrapSlider({
        formatter: function(value) {
            return 'Current value: ' + value;
        }
    });
    
    $jq('.pausebutton_customizer #borderradius').on('slide',function(){
		var vall = jQuery(this).val();
		$jq('#pausebutton').css('border-radius',vall+"px");
	});
	
    $jq('.cancelbutton_customizer #borderradius').bootstrapSlider({
        formatter: function(value) {
            return 'Current value: ' + value;
        }
    });
    
    $jq('.cancelbutton_customizer #borderradius').on('slide',function(){
		var vall = jQuery(this).val();
		$jq('#cancelbutton').css('border-radius',vall+"px");
	});
    
    $jq('.resumebutton_customizer #borderradius').bootstrapSlider({
        formatter: function(value) {
            return 'Current value: ' + value;
        }
    });
    
    $jq('.resumebutton_customizer #borderradius').on('slide',function(){
		var vall = jQuery(this).val();
		$jq('#resumebutton').css('border-radius',vall+"px");
	});
    
    
    $jq('.cancelbutton_customizer #fontsize').bootstrapSlider({
        formatter: function(value) {
            return 'Current value: ' + value;
        }
    });
    
   $jq('.cancelbutton_customizer #fontsize').on('slide',function(){
		var vall = jQuery(this).val();
		$jq('#cancelbutton').css('font-size',vall+"px");
	});
	
	
    $jq('.pausebutton_customizer #fontsize').bootstrapSlider({
        formatter: function(value) {
            return 'Current value: ' + value;
        }
    });
    
    $jq('.pausebutton_customizer #fontsize').on('slide',function(){
		var vall = jQuery(this).val();
		$jq('#pausebutton').css('font-size',vall+"px");
	});
    
    $jq('.resumebutton_customizer #fontsize').bootstrapSlider({
        formatter: function(value) {
            return 'Current value: ' + value;
        }
    });
    
    $jq('.resumebutton_customizer #fontsize').on('slide',function(){
		var vall = jQuery(this).val();
		$jq('#resumebutton').css('font-size',vall+"px");
	});
    
    $jq('.pausebutton_customizer #buttonwidth').bootstrapSlider({
        formatter: function(value) {
            return 'Current value: ' + value ;
        }
    });
    
    $jq('.pausebutton_customizer #buttonwidth').on('slide',function(){
		var vall = jQuery(this).val();
		$jq('#pausebutton').css('width',vall);
	});
	
    $jq('.cancelbutton_customizer #buttonwidth').bootstrapSlider({
        formatter: function(value) {
            return 'Current value: ' + value ;
        }
    });
    
    $jq('.cancelbutton_customizer #buttonwidth').on('slide',function(){
		var vall = jQuery(this).val();
		$jq('#cancelbutton').css('width',vall);
	});
    
    $jq('.resumebutton_customizer #buttonwidth').bootstrapSlider({
        formatter: function(value) {
            return 'Current value: ' + value ;
        }
    });
    
    $jq('.resumebutton_customizer #buttonwidth').on('slide',function(){
		var vall = jQuery(this).val();
		$jq('#resumebutton').css('width',vall);
	});
    
    $jq('.pausebutton_customizer #buttonheight').bootstrapSlider({
        formatter: function(value) {
            return 'Current value: ' + value ;
        }
    });
    
     $jq('.pausebutton_customizer #buttonheight').on('slide',function(){
		var vall = jQuery(this).val();
		$jq('#pausebutton').css('height',vall);
	});
	
    $jq('.cancelbutton_customizer #buttonheight').bootstrapSlider({
        formatter: function(value) {
            return 'Current value: ' + value ;
        }
    });
    
    $jq('.cancelbutton_customizer #buttonheight').on('slide',function(){
		var vall = jQuery(this).val();
		$jq('#cancelbutton').css('height',vall);
	});
    
    $jq('.resumebutton_customizer #buttonheight').bootstrapSlider({
        formatter: function(value) {
            return 'Current value: ' + value ;
        }
    });
    
     $jq('.resumebutton_customizer #buttonheight').on('slide',function(){
		var vall = jQuery(this).val();
		$jq('#resumebutton').css('height',vall);
	});
    
    
    
    $jq('#prodfontsize').bootstrapSlider({
        formatter: function(value) {
            return 'Current value: ' + value + 'px';
        }
    });
    $jq('#prodfontsize1').bootstrapSlider({
        formatter: function(value) {
            return 'Current value: ' + value + 'px';
        }
    });
    $jq('#imageWidth').bootstrapSlider({
        formatter: function(value) {
            return 'Current value: ' + value + 'px';
        }
    });
    $jq('#imageHeight').bootstrapSlider({
        formatter: function(value) {
            return 'Current value: ' + value + 'px';
        }
    });
}
    
function dap_member_show_divs() {
    $jq('.dap_membership_div').show();
    $jq('.table_page_select').hide();
    $jq('.member_button').show();
    $jq('.dap_membership_images img').dblclick(function() {
        var selected_page = $jq(this).parent().find('input').val();
        if(selected_page == "DAP My Content") {
            $jq('#mycontent_shortcode_popup_button').trigger('click');
            $jq('#mycontent_shortcode_popup_inner').show();
            $jq('.table_page_select').show();
            $jq('.dap_membership_div').hide();
            $jq('.member_button').hide();
        } else if(selected_page == "DAP My Profile") {
            $jq('#myprofile_shortcode_popup_button').trigger('click');
            $jq('#myprofile_shortcode_popup_inner').show();
            $jq('.table_page_select').show();
            $jq('.dap_membership_div').hide();
            $jq('.member_button').hide();
        } else if(selected_page == "DAP Affiliate Info") {
            $jq('#affiliate_shortcode_popup_button').trigger('click');
            $jq('#affiliate_shortcode_popup_inner').show();
            $jq('.table_page_select').show();
            $jq('.dap_membership_div').hide();
            $jq('.member_button').hide();
        } else if(selected_page == "DAP Member Invoice") {
            $jq('#myinvoice_shortcode_popup_button').trigger('click');
            $jq('#myinvoice_shortcode_popup_inner').show();
            $jq('.table_page_select').show();
            $jq('.dap_membership_div').hide();
            $jq('.member_button').hide();
        } else if(selected_page == "DAP Member Cancel") {
            $jq('#mycancel_shortcode_popup_button').trigger('click');
            $jq('#mycancel_shortcode_popup_inner1').show();
            $jq('.table_page_select').show();
            $jq('.dap_membership_div').hide();
            $jq('.member_button').hide();
        } else if(selected_page == "DAP Member Cancel new") {
            $jq('#mycancel_shortcode_popup_button1').trigger('click');
            $jq('#mycancel_shortcode_popup_inner1').show();
            $jq('.table_page_select').show();
            $jq('.dap_membership_div').hide();
            $jq('.member_button').hide();
        }
        else if(selected_page == "DAP Login") {
            $jq('#login_shortcode_popup_button').trigger('click');
            $jq('#login_shortcode_popup_inner').show();
            $jq('.table_page_select').show();
            $jq('.dap_membership_div').hide();
            $jq('.member_button').hide();
        } else {
            $jq('.dap_membership_div').show();
            $jq('.table_page_select').hide();
            $jq('.member_button').show();
        }
    });
    $jq('.member_button').on('click', function() {
        var select_page = $jq('input[name="membership_page_option"]:checked').val();
        if(select_page == "DAP My Content") {
            $jq('#mycontent_shortcode_popup_button').trigger('click');
            $jq('#mycontent_shortcode_popup_inner').show();
            $jq('.table_page_select').show();
            $jq('.dap_membership_div').hide();
            $jq('.member_button').hide();
        } else if(select_page == "DAP My Profile") {
            $jq('#myprofile_shortcode_popup_button').trigger('click');
            $jq('#myprofile_shortcode_popup_inner').show();
            $jq('.table_page_select').show();
            $jq('.dap_membership_div').hide();
            $jq('.member_button').hide();
        } else if(select_page == "DAP Affiliate Info") {
            $jq('#affiliate_shortcode_popup_button').trigger('click');
            $jq('#affiliate_shortcode_popup_inner').show();
            $jq('.table_page_select').show();
            $jq('.dap_membership_div').hide();
            $jq('.member_button').hide();
        } else if(select_page == "DAP Member Invoice") {
            $jq('#myinvoice_shortcode_popup_button').trigger('click');
            $jq('#myinvoice_shortcode_popup_inner').show();
            $jq('.table_page_select').show();
            $jq('.dap_membership_div').hide();
            $jq('.member_button').hide();
        } else if(select_page == "DAP Member Cancel") {
            $jq('#mycancel_shortcode_popup_button').trigger('click');
            $jq('#mycancel_shortcode_popup_inner1').show();
            $jq('.table_page_select').show();
            $jq('.dap_membership_div').hide();
            $jq('.member_button').hide();
        }
        else if(select_page == "DAP Member Cancel new") {
            $jq('#mycancel_shortcode_popup_button1').trigger('click');
            $jq('#mycancel_shortcode_popup_inner1').show();
            $jq('.table_page_select').show();
            $jq('.dap_membership_div').hide();
            $jq('.member_button').hide();
        }
        
         else if(select_page == "DAP Login") {
            $jq('#login_shortcode_popup_button').trigger('click');
            $jq('#login_shortcode_popup_inner').show();
            $jq('.table_page_select').show();
            $jq('.dap_membership_div').hide();
            $jq('.member_button').hide();
        } else {
            $jq('.dap_membership_div').show();
            $jq('.table_page_select').hide();
            $jq('.member_button').show();
        }
    });
    $jq('select[name="selectmemberpages"]').on('change', function() {
        var Dap_val = $jq(this).val();
        $jq('#mycontent_shortcode_popup_inner').hide();
        $jq('#myprofile_shortcode_popup_inner').hide();
        $jq('#affiliate_shortcode_popup_inner').hide();
        $jq('#myinvoice_shortcode_popup_inner').hide();
        $jq('#mycancel_shortcode_popup_inner1').hide();
        $jq('#login_shortcode_popup_inner').hide();
        $jq('.dap_membership_div').hide();
        $jq('.table_page_select').show();
        if(Dap_val == "DAPMyContent") {
            $jq('#mycontent_shortcode_popup_button').trigger('click');
            $jq('#mycontent_shortcode_popup_inner').show();
        } else if(Dap_val == "DAPMyProfile") {
            $jq('#myprofile_shortcode_popup_button').trigger('click');
            $jq('#myprofile_shortcode_popup_inner').show();
        } else if(Dap_val == "DAPAffiliateInfo") {
            $jq('#affiliate_shortcode_popup_button').trigger('click');
            $jq('#affiliate_shortcode_popup_inner').show();
        } else if(Dap_val == "DAPMemberInvoice") {
            $jq('#myinvoice_shortcode_popup_button').trigger('click');
            $jq('#myinvoice_shortcode_popup_inner').show();
        } else if(Dap_val == "DAPMemberCancel") {
            $jq('#mycancel_shortcode_popup_button1').trigger('click');
            $jq('#mycancel_shortcode_popup_inner1').show();
        } else if(Dap_val == "DAPLogin") {
            $jq('#login_shortcode_popup_button').trigger('click');
            $jq('#login_shortcode_popup_inner').show();
        } else {
            $jq('.dap_membership_div').show();
            $jq('.table_page_select').hide();
            $jq('.member_button').show();
        }
    });
    $jq('.back-btn').on('click', function() {
        $jq('.dap_membership_div').show();
        $jq('.member_button').show();
        $jq('.table_page_select').hide();
        $jq('#mycontent_shortcode_popup_inner').hide();
        $jq('#myprofile_shortcode_popup_inner').hide();
        $jq('#affiliate_shortcode_popup_inner').hide();
        $jq('#myinvoice_shortcode_popup_inner').hide();
        $jq('#mycancel_shortcode_popup_inner').hide();
        $jq('#mycancel_shortcode_popup_inner1').hide();
        $jq('#login_shortcode_popup_inner').hide();
    });
}

function dap_open_front_page() {
    $jq('.dap_membership_div').show();
    $jq('.member_button').show();
    $jq('.table_page_select').hide();
    $jq('#mycontent_shortcode_popup_inner').hide();
    $jq('#myprofile_shortcode_popup_inner').hide();
    $jq('#affiliate_shortcode_popup_inner').hide();
    $jq('#myinvoice_shortcode_popup_inner').hide();
    $jq('#mycancel_shortcode_popup_inner1').hide();
    $jq('#mycancel_shortcode_popup_inner1').hide();
    $jq('#login_shortcode_popup_inner').hide();
    tinymce_editor();
}

function remove_css_popup() {
    $jq('#banSheet').attr('disabled', 'disabled');
}
