/***************************************************************************
*
* IMPORTANT: This is a commercial product made by AntonLV and cannot be modified for other than personal usage. 
* This product cannot be redistributed for free or a fee without written permission from AntonLV. 
* This notice may not be removed from the source code.
*
***************************************************************************/

var obj = null;

function popupPBlock(e, ID, textID, comp){
	var element = e;
	var coverLeft = 0;
	var coverTop = 0;
	var coverWidth = element.width;
	var coverHeight = element.height;
	
	
	while (element.offsetParent) {
		coverLeft += element.offsetLeft;
		coverTop += element.offsetTop;
		element = element.offsetParent;
	}

	obj = this;
	var text = '';
	
	var block_content = $('#new_block_content' + ID).val();
	var block_title = comp !='' ? comp : $('#' + textID).val();
	
	if (block_content.length == 0 || block_title.length == 0) 
		{
			alert('Body and Title of the Block can not be empty!!!'); return 0;
		}
	
	var type = $("input[@name^='rad" + ID + "']:radio:checked").val(); 
	if (type == null) type = $("input[@id='rad" + ID + "']").val();
	
	$.ajax({
		type: "POST",
		url: "../alv/ppcomposer/exec/preview.php",
		data: "content=" + encodeURIComponent(block_content) + "&title=" + block_title + "&type=" + type,
		success:function(msg){
			
			if ($('#preview_cont').length > 0) $('#preview_cont').remove();
			if ($('#close_prew').length > 0) $('#close_prew').remove();
			 //alert(msg);
			$('body').append('<div class="block_container" id="preview_cont">' + msg + '</div>');
			$('#preview_cont').css('top',coverTop + 20);
			$('#preview_cont').css('left',coverLeft);
			
			$("embed").attr('width','100%');
			$("object").attr('width','100%');
	
	
			var html = '<div style = "position:absolute;" id="close_prew"><a href = "javascript:void(0);" id = "close_l"><b>X</b></a></div>';
			$(html).appendTo('body');
			$('#close_prew').css('top',coverTop);
			$('#close_prew').css('left',coverLeft + 65);
			$('#close_l').bind('click', function()
					{
						if ($('#close_prew').length > 0) $('#close_prew').remove();
						if ($('#preview_cont').length > 0) $('#preview_cont').remove();	
					});
			
	
		}
		
	});
			
	return false;
};
