jQuery(document).ready(function($){
	
	$("#ezee_cprt_protector_dialog-message").dialog({
		modal: true,
		autoOpen: false,
		closeOnEscape: false,
		width: 'auto',
		resizable: false,
		draggable: false,
		open: function() {
			
				/****css compatibility fix May 14 2020****/
				var ezeeParent = $(this).parents('.ui-dialog');
				$(ezeeParent).prop("id", "ezee_cprt_protector_dialog-parent");
				/****end css compatibility*****/
			
				//fix ezdialog hidden by header problem July 6 2020
				/****July 10 2020****/
				//$('.ui-widget-overlay:eq('+ezIdx+')').css({'background-color': '#000000', 'z-index': 1000000, 'opacity': '0.7'});
				
				var ezee_version_flag = ezee_version.ezee_version_flag;
				
				if(ezee_version_flag == 1)
				{
					$("#ezee_cprt_protector_dialog-parent").prevAll('.ui-widget-overlay:eq(0)').prop('id', 'ezee_cprt_protector_dialog-overlay');
				}
				else
				{
					$("#ezee_cprt_protector_dialog-parent").nextAll('.ui-widget-overlay:eq(0)').prop('id', 'ezee_cprt_protector_dialog-overlay');
				}
				
				
				$('#ezee_cprt_protector_dialog-overlay').css({'background-color': '#000000', 'z-index': 1000000, 'opacity': '0.7'});
				
				/****End July 10****/
				
				$('#ezee_cprt_protector_dialog-parent').css({'z-index': 1000001 });
				//end July 6 2020
				
				/****Media element Fix June 2 2020***/
				var ezVidHeight = $("#ezee_cprt_protector_dialog-parent mediaelementwrapper .wp-video-shortcode").prop("height");
				
				$("#ezee_cprt_protector_dialog-parent .wp-video-shortcode").height(ezVidHeight);
				/**end media element fix**/
				
				/*--adjust popup to follow scrolling 15 April 2020--*/
				
				var ezwinHeight = $(window).innerHeight();
				
				var ezpopupHeight = $("#ezee_cprt_protector_dialog-message").outerHeight(); 
				
				if(ezpopupHeight < ezwinHeight)
				{
					$(this).parent().css('position', 'fixed');
				}
				
				//blur 
				
				$(this).parents('.ui-dialog').prop('tabindex', -2)[0].focus(); //comment July 8 2020 
				
				//end blur
				
				/*----------end popup----------*/
				
				ezee_cprt_preventDeleteDialog();
				
		}
	});	

	ezee_cprt_preventDeleteDialog();
	
	//popup adjustment on scroll April 15 2020
	var ezlastScrollTop = 0;	
	
	$(window).scroll(function(e){
		
		var ezst = $(this).scrollTop();
		
		var ezdirection = '';
		
		if (ezst > ezlastScrollTop){
			// downscroll code
			ezdirection = 'down';
			
		} else {
			// upscroll code
			ezdirection = 'up';
		}
		ezlastScrollTop = ezst;
				
		var ezpopupHeight = $("#ezee_cprt_protector_dialog-message").outerHeight();
		
		var ezfromTop = $(window).scrollTop();
		
		var ezdocuHeight = $(document).height();
		
		var ezdialogBottom = $("#ezee_cprt_protector_dialog-message").offset().top + $("#ezee_cprt_protector_dialog-message").outerHeight(true);
		
		var ezremaining = 0;
		
		if(ezpopupHeight > window.innerHeight && ezpopupHeight < ezdocuHeight)
		{
			if(window.innerHeight + ezfromTop >= ezdialogBottom) //don't change this logic
			{	
				
				$("#ezee_cprt_protector_dialog-message").closest(".ui-dialog").position({ my: 'bottom', at: 'bottom', of: window });	
				
				
			}
			else{
				
				if(ezdirection == 'up')
				{
					
					var ezdialog = $('#ezee_cprt_protector_dialog-message');
					var ezoffset = ezdialog.offset();
					dialogViewportOffsetTop = ezoffset.top - $(document).scrollTop(); //don't change logic
					
					if(dialogViewportOffsetTop >= 0)
					{
						$("#ezee_cprt_protector_dialog-message").closest(".ui-dialog").position({ my: 'top', at: 'top', of: window });
					}
				}
				
			}
			
		}
		
	});	
	//end adjustment
	
});

jQuery(window).on("load", function($){
	
	var ezmaxWidth = Math.max.apply(Math, jQuery('#ezee_cprt_protector_dialog-message>div').map(function(){ return jQuery(this).width(); }).get());
	
	if(jQuery("#ezee_cprt_protector_dialog-message audio").width() < ezmaxWidth)
	{
		jQuery("#ezee_cprt_protector_dialog-message audio").css("width", ezmaxWidth+'px');
	}
	
	jQuery("#ezee_cprt_protector_dialog-message").css("height", "auto");
	
});
				
function ezee_cprt_preventDeleteDialog()
{
	//prevent inspect element right click
	document.addEventListener('contextmenu', function(e){
		jQuery("#ezee_cprt_protector_dialog-message").dialog("open");
		e.preventDefault();
	});
					
	//prevent dev shortcuts on Edge, FF, Chrome, Opera
	document.onkeydown = function(e){
		if(event.keyCode == 123) {
			
			jQuery("#ezee_cprt_protector_dialog-message").dialog("open");
			return false;
		}
		if(e.ctrlKey && e.shiftKey && e.keyCode == 'I'.charCodeAt(0)){
			jQuery("#ezee_cprt_protector_dialog-message").dialog("open");
			return false;
		}
		else if(e.ctrlKey && e.shiftKey && e.keyCode == 'C'.charCodeAt(0)){
			jQuery("#ezee_cprt_protector_dialog-message").dialog("open");
			return false;
		}
		else if(e.ctrlKey && e.shiftKey && e.keyCode == 'J'.charCodeAt(0)){
			jQuery("#ezee_cprt_protector_dialog-message").dialog("open");
			return false;
		}
		
		if(e.ctrlKey && e.keyCode == 'U'.charCodeAt(0)){
			jQuery("#ezee_cprt_protector_dialog-message").dialog("open");
			return false;
		}
		else{
			
			jQuery('body').bind('copy paste cut', function(e){
				jQuery("#ezee_cprt_protector_dialog-message").dialog("open");
				e.preventDefault();
			});
		}
		if(e.ctrlKey && e.keyCode == 'S'.charCodeAt(0)){
			jQuery("#ezee_cprt_protector_dialog-message").dialog("open");
			return false;
		}
		if(e.ctrlKey && e.keyCode == 'A'.charCodeAt(0)){
			jQuery("#ezee_cprt_protector_dialog-message").dialog("open");
			return false;
		}
		//firefox
		
		if(navigator.userAgent.search("Firefox") != -1)
		{

			if(e.ctrlKey && e.shiftKey && e.keyCode == 'K'.charCodeAt(0)){
				jQuery("#ezee_cprt_protector_dialog-message").dialog("open");
				return false;
			}
			
		}
		
	}
	
	document.onmousedown = function(e) //new function for mouse func like drag/drop July 7 2020
	{
		jQuery('body').bind('drag drop', function(e){
			jQuery("#ezee_cprt_protector_dialog-message").dialog("open");
			e.preventDefault();
		});
	}
}


//cookie related functions

function EzeeCpysetCookie(cname, cvalue, exdays) {
  var d = new Date();
  d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
  var expires = "expires="+d.toUTCString();
  document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}

function EzeeCpygetCookie(cname) {
  var name = cname + "=";
  var ca = document.cookie.split(';');
  for(var i = 0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }
  return "";
} 

/****Refresh BTN Opera May 3 2020****/
function EzeeCpysetAutoExpireCookie(cname, cvalue){
  
  document.cookie = cname + "=" + cvalue + ";path=/";
}
/****Refresh BTN Opera May 2020 END*****/

/***Refesh Btn May 5 2020****/
function EzeeCpydeleteCookie(cname){

  var cvalue = getCookie(cname);
  var d = new Date();
  d.setTime(0);
  var expires = "expires="+d.toUTCString();
  document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
/***End refresh Btn May 5 2020****/