(function( $ ) {
	'use strict';
	/**
	 * All of the code for your admin-facing JavaScript source
	 * should reside in this file.
	 *
	 * Note: It has been assumed you will write jQuery code here, so the
	 * $ function reference has been prepared for usage within the scope
	 * of this function.
	 *
	 * This enables you to define handlers, for when the DOM is ready:
	 *
	 * $(function() {
	 *
	 * });
	 *
	 * When the window is loaded:
	 *
	 * $( window ).load(function() {
	 *
	 * });
	 *
	 * ...and/or other possibilities.
	 *
	 * Ideally, it is not considered best practise to attach more than a
	 * single DOM-ready or window-load handler for a particular page.
	 * Although scripts in the WordPress core, Plugins and Themes may be
	 * practising this, we should strive to set a better example in our own work.
	 */
	  jQuery(document).ready(function() { 
	 	jQuery('.rtwwpcp_watermark_img_upload').on('click',function(){
	 		var rtwwpcp_inputField = jQuery(this).parent('div');
	 		tb_show('watermark', 'media-upload.php?TB_iframe=true');
	 		window.send_to_editor = function(html)
	 		{  
	 			var rtwwpcp_url = jQuery(html).find('img').attr('src');
	 			if(typeof rtwwpcp_url == 'undefined')
	 				rtwwpcp_url = jQuery(html).attr('src');	
	 			jQuery( '#rtwwpcp_watermark_img_url' ).val( rtwwpcp_url );
	 			jQuery( '#rtwwpcp_watermark_img_backgrnd' ).find( 'img' ).attr( 'src', rtwwpcp_url );
	 			jQuery( '.rtwwpcp_watermark_remove_img' ).show();
	 			jQuery( '#rtwwpcp_watermark_img' ).show();
	 			tb_remove();
	 		};
	 		return false;
	 	});
	 	jQuery( document ).on( 'click', '.rtwwpcp_watermark_remove_img', function() {
	 		jQuery('#rtwwpcp_watermark_img_url').val('');
	 		jQuery('#rtwwpcp_watermark_img').attr('src', '');
	 		jQuery(this).hide();
	 		jQuery( '#rtwwpcp_watermark_img' ).hide();
	 		return false;
	 	});
	 	jQuery('.rtwwpcp_logo_img_upload').on('click',function(){
	 		var rtwwpcp_input_Field = jQuery(this).parent('div');
	 		tb_show('logo_image', 'media-upload.php?TB_iframe=true');
	 		window.send_to_editor = function(html)
	 		{  
	 			var rtwwpcp_url = jQuery(html).find('img').attr('src');
	 			if(typeof rtwwpcp_url == 'undefined')
	 				rtwwpcp_url = jQuery(html).attr('src');	
	 			jQuery( '#logo_image' ).val( rtwwpcp_url );
	 			jQuery( '#rtwwpcp_logo_img' ).find( 'img' ).attr( 'src', rtwwpcp_url );
	 			jQuery( '.rtwwpcp_logo_remove_img' ).show();
	 			jQuery( '#rtwwpcp_logo_image' ).show();
	 			tb_remove();
	 		};
	 		return false;
	 	});
	 	jQuery( document ).on( 'click', '.rtwwpcp_logo_remove_img', function() {
	 		jQuery('#logo_image').val('');
	 		jQuery('#rtwwpcp_logo_image').attr('src', '');
	 		jQuery(this).hide();
	 		jQuery( '#rtwwpcp_logo_image' ).hide();
	 		return false;
	 	});
	 	jQuery('.rtwwpcp_btn_img_upload').on('click',function(){
	 		var rtwwpcp_inputField = jQuery(this).parent('div');
	 		tb_show('Button_img', 'media-upload.php?TB_iframe=true');
	 		window.send_to_editor = function(html)
	 		{  
	 			var rtwwpcp_url = jQuery(html).find('img').attr('src');
	 			if(typeof rtwwpcp_url == 'undefined')
	 				rtwwpcp_url = jQuery(html).attr('src');	
	 			jQuery( '#rtwwpcp_img_url' ).val( rtwwpcp_url );
	 			jQuery( '#rtwwpcp_btn_img' ).find( 'img' ).attr( 'src', rtwwpcp_url );
	 			jQuery( '.rtwwpcp_btn_remove_img' ).show();
	 			jQuery( '#rtwwpcp_img_btn' ).show();
	 			tb_remove();
	 		};
	 		return false;
	 	});
	 	jQuery( document ).on( 'click', '.rtwwpcp_btn_remove_img', function() {
	 		jQuery('#rtwwpcp_img_url').val('');
	 		jQuery('#rtwwpcp_img_btn').attr('src', '');
	 		jQuery(this).hide();
	 		jQuery( '#rtwwpcp_img_btn' ).hide();
	 		return false;
	 	});
	 	
	 	$(document).on('click', '#rtwwpcp_verify_code', function(){
			if( $(document).find( "#rtwwpcp_verify" ).valid() )
			{
				var rtwwpcp_purchase_code = $(document).find('.rtwwpcp_purchase_code').val();
				var data = {	
					action	  		:'rtwwpcp_verify_purchase_code',
					purchase_code 	: rtwwpcp_purchase_code,
					security_check 	: rtwwpcp_global_param.rtwwpcp_nonce	
				};
				$.blockUI({ message: '',
				timeout: 20000000 });
				$.ajax({
					url: rtwwpcp_global_param.rtwwpcp_ajaxurl, 
					type: "POST",  
					data: data,
					dataType :'json',	
					success: function(response) 
					{  
						if( response.status )
						{
							$(document).find('.rtwwpcp_notice_success').removeClass('rtwwpcp_hide');
							$(document).find('.rtwwpcp_msg_response').addClass('rtwwpcp_success');
							$(document).find('.rtwwpcp_msg_response').html(response.message);
							window.setTimeout(function(){ 
								window.location.reload(true);
							}, 3000);
						}
						else{
							$(document).find('.rtwwpcp_notice_error').removeClass('rtwwpcp_hide');
							$(document).find('.rtwwpcp_msg_response').addClass('rtwwpcp_failed');
							$(document).find('.rtwwpcp_msg_response').html(response.message);
						}
						$.unblockUI();
					}
				});
			}
		});

	 	jQuery('#rtwwpcp_e1').select2();
	 	jQuery('#rtwwpcp_user_role').select2();
	 	jQuery('.rtwwpcp_btn_bckgrnd_img_upload').on('click',function(){
	 		var rtwwpcp_inputField = jQuery(this).parent('div');
	 		tb_show('Background_img', 'media-upload.php?TB_iframe=true');
	 		window.send_to_editor = function(html)
	 		{  
	 			var rtwwpcp_url = jQuery(html).find('img').attr('src');
	 			if(typeof rtwwpcp_url == 'undefined')
	 				rtwwpcp_url = jQuery(html).attr('src');	
	 			jQuery( '#rtwwpcp_bck_img_url' ).val( rtwwpcp_url );
	 			jQuery( '#rtwwpcp_bckgrnd_img' ).find( 'img' ).attr( 'src', rtwwpcp_url );
	 			jQuery( '.rtwwpcp_btn_remove_bckgrnd_img' ).show();
	 			jQuery( '#rtwwpcp_bckgrnd_img_btn' ).show();
	 			tb_remove();
	 		};
	 		return false;
	 	});
	 	jQuery('.rtwwpcp_cvr_img_upload').on('click',function(){
	 		var rtwwpcp_inputField = jQuery(this).parent('div');
	 		tb_show('Background_img', 'media-upload.php?TB_iframe=true');
	 		window.send_to_editor = function(html)
	 		{  
	 			var rtwwpcp_url = jQuery(html).find('img').attr('src');
	 			if(typeof rtwwpcp_url == 'undefined')
	 				rtwwpcp_url = jQuery(html).attr('src');	
	 			jQuery( '#rtwwpcp_cvr_img_url' ).val( rtwwpcp_url );
	 			jQuery( '#rtwwpcp_cover_img' ).find( 'img' ).attr( 'src', rtwwpcp_url );
	 			jQuery( '.rtwwpcp_remove_cvr_img' ).show();
	 			jQuery( '#rtwwpcp_cover_img_btn' ).show();
	 			tb_remove();
	 		};
	 		return false;
	 	});
	 	jQuery('.rtwwpcp_bck_cvr_img_upload').on('click',function(){
	 		var rtwwpcp_inputField = jQuery(this).parent('div');
	 		tb_show('Background_img', 'media-upload.php?TB_iframe=true');
	 		window.send_to_editor = function(html)
	 		{  
	 			var rtwwpcp_url = jQuery(html).find('img').attr('src');
	 			if(typeof rtwwpcp_url == 'undefined')
	 				rtwwpcp_url = jQuery(html).attr('src');	
	 			jQuery( '#rtwwpcp_bck_cvr_img_url' ).val( rtwwpcp_url );
	 			jQuery( '#rtwwpcp_bck_cover_img' ).find( 'img' ).attr( 'src', rtwwpcp_url );
	 			jQuery( '.rtwwpcp_remove_bck_cvr_img' ).show();
	 			jQuery( '#rtwwpcp_bck_cover_img_btn' ).show();
	 			tb_remove();
	 		};
	 		return false;
	 	});
	 	jQuery( document ).on( 'click', '.rtwwpcp_btn_remove_bckgrnd_img', function() {
	 		jQuery('#rtwwpcp_bck_img_url').val('');
	 		jQuery('#rtwwpcp_bckgrnd_img_btn').attr('src', '');
	 		jQuery(this).hide();
	 		jQuery( '#rtwwpcp_bckgrnd_img_btn' ).hide();
	 		return false;
	 	});
	 	jQuery( document ).on( 'click', '.rtwwpcp_remove_cvr_img', function() {
	 		jQuery('#rtwwpcp_cvr_img_url').val('');
	 		jQuery('#rtwwpcp_cover_img_btn').attr('src', '');
	 		jQuery(this).hide();
	 		jQuery( '#rtwwpcp_cover_img_btn' ).hide();
	 		return false;
	 	});
	 	jQuery( document ).on( 'click', '.rtwwpcp_remove_bck_cvr_img', function() {
	 		jQuery('#rtwwpcp_bck_cvr_img_url').val('');
	 		jQuery('#rtwwpcp_bck_cover_img_btn').attr('src', '');
	 		jQuery(this).hide();
	 		jQuery( '#rtwwpcp_bck_cover_img_btn' ).hide();
	 		return false;
	 	});
	 	$('.color-field').wpColorPicker(); 
	 	jQuery(document).on('click', '#rtwwpcfp_wtrmrk', function(){
	 		rtwwpcp_showHideCheck('rtwwpcp_text_add_watermark', this);
	 	});
	 	jQuery(document).on('click', '#rtwwpcfp_imgwtrmk', function(){
	 		rtwwpcp_showHideCheck('rtwwpcp_add_watermark_image', this);
	 	}); 
	 	jQuery(document).on('click', '#rtwwpcp_pswrd_prtcn', function(){
	 		rtwwpcp_addPasswordprotctn('rtwwpcp_add_pswrd_protctn', this);
	 	});
	 	jQuery(document).on('change', '#rtwwpcp_doc-add-watermark-image-pos-select', function(){
	 		rtwwpcp_showHidePos();
	 	}); 
	 	jQuery(document).on('change', '#rtwwpcp_doc-add-watermark-image-dimen-select', function(){
	 		var rtwwpcp_value=jQuery("#rtwwpcp_doc-add-watermark-image-dimen-select").val();
	 		rtwwpcp_showHideImage(rtwwpcp_value);
	 	});
	 	jQuery(document).on('click', '#rtwwpcp_cat_catalog', function(){
	 		rtwwpcp_show_catgry_list('rtwwpcp_show_cat_opt', this);
	 	});
	 	jQuery(document).on('click', '#rtwwpcp_cat_catalog', function(){
	 		rtwwpcp_show_btn_on_cat_page('rtwwpcp_show_btn_on_cat_page', this);
	 	});

	 	$(document).on( 'change', '.rtwwpcp_template_select', function(){
	 		if( $(this).val() == '1' ){
	 			$(document).find( '.rtwwpcp_template_1' ).show();
	 			$(document).find( '.rtwwpcp_template_2' ).hide();
	 			$(document).find( '.rtwwpcp_template_3' ).hide();
				$(document).find( '.rtwwpcp_template_4' ).hide();
	 		}
	 		if( $(this).val() == '2' ){
	 			$(document).find( '.rtwwpcp_template_1' ).hide();
	 			$(document).find( '.rtwwpcp_template_2' ).show();
	 			$(document).find( '.rtwwpcp_template_3' ).hide();
				$(document).find( '.rtwwpcp_template_4' ).hide();
	 		}
	 		if ( $(this).val() == '3' ) 
	 		{
	 			$(document).find( '.rtwwpcp_template_1' ).hide();
	 			$(document).find( '.rtwwpcp_template_2' ).hide();
	 			$(document).find( '.rtwwpcp_template_3' ).show();
				$(document).find( '.rtwwpcp_template_4' ).hide();
	 		}
			 if ( $(this).val() == '4' ) 
	 		{
	 			$(document).find( '.rtwwpcp_template_1' ).hide();
	 			$(document).find( '.rtwwpcp_template_2' ).hide();
	 			$(document).find( '.rtwwpcp_template_3' ).hide();
				$(document).find( '.rtwwpcp_template_4' ).show();
	 		}
	 	});
	 });
})( jQuery );
function rtwwpcp_showHideImage(rtwwpcp_value)
{ 
	if(rtwwpcp_value=='array')
	{
		jQuery('#rtwwpcp_add_watermark_image_dimension').show();
		jQuery('#rtwwpcp_add_watermark_image_dimen_integer').hide();
	}
	if(rtwwpcp_value=='INT')
	{
		jQuery('#rtwwpcp_add_watermark_image_dimen_integer').show();
		jQuery('#rtwwpcp_add_watermark_image_dimension').hide();
	}
	if(rtwwpcp_value!='INT' && rtwwpcp_value!='array')
	{
		jQuery('#rtwwpcp_add_watermark_image_dimension').hide();
		jQuery('#rtwwpcp_add_watermark_image_dimen_integer').hide();
	}
}
function rtwwpcp_showHideCheck(rtwwpcp_id,rtwwpcp_check) 
{
	if(rtwwpcp_check.checked) 
	{
		jQuery("#"+rtwwpcp_id).show();
		if(rtwwpcp_id=='rtwwpcp_add_watermark_image')
		{ 
			var rtwwpcp_value=jQuery("#rtwwpcp_doc-add-watermark-image-dimen-select").val();
			var rtwwpcp_value1=jQuery("#rtwwpcp_doc-add-watermark-image-pos-select").val();
			if(rtwwpcp_value=='array')
			{
				jQuery('#rtwwpcp_add_watermark_image_dimension').show();
			}
			if(rtwwpcp_value=='INT')
			{
				jQuery('#rtwwpcp_add_watermark_image_dimen_integer').show();
			}
			if(rtwwpcp_value1=='arrays')
			{
				jQuery('#rtwwpcp_add_watermark_image_pos').show();	
			} 
		}
	} 
	else 
	{
		jQuery("#"+rtwwpcp_id).hide();
		if(rtwwpcp_id=='rtwwpcp_add_watermark_image')
		{
			jQuery('#rtwwpcp_add_watermark_image_dimension').hide();
			jQuery('#rtwwpcp_add_watermark_image_dimen_integer').hide();
			jQuery('#rtwwpcp_add_watermark_image_pos').hide();
		}
	}
}
function rtwwpcp_showHidePos()
{
	var rtwwpcp_value=jQuery("#rtwwpcp_doc-add-watermark-image-pos-select").val();
	if(rtwwpcp_value=='arrays')
	{
		jQuery('#rtwwpcp_add_watermark_image_pos').show();
	}
	else
	{
		jQuery('#rtwwpcp_add_watermark_image_pos').hide();
	}
}
function rtwwpcp_addPasswordprotctn(rtwwpcp_id,rtwwpcp_check)
{
	if (rtwwpcp_check.checked) 
	{
		jQuery("#"+rtwwpcp_id).show();
	}
	else
	{
		jQuery("#"+rtwwpcp_id).hide();
	}
}
function rtwwpcp_show_catgry_list( rtwwpcp_id,rtwwpcp_check )
{
	if (rtwwpcp_check.checked) 
	{
		jQuery("#"+rtwwpcp_id).show();
	}
	else
	{
		jQuery("#"+rtwwpcp_id).hide();
	}
}
function rtwwpcp_show_btn_on_cat_page( rtwwpcp_id,rtwwpcp_check )
{
	if (rtwwpcp_check.checked) 
	{
		jQuery("#"+rtwwpcp_id).show();
	}
	else
	{
		jQuery("#"+rtwwpcp_id).hide();
	}
}

