﻿

$.fn.popupBox = function (options) {
    var title = options['title'];
    var cssClass = options['cssClass'];
    var key = options['key'];
    var autoOpen = options['autoOpen'];
    var content = $(this);
	//alert(autoOpen);
   // alert($(form).html());
	$('.popup-content-' + key).dialog({
					minWidth: 640,
					minHeight: 320,
					dialogClass : cssClass,
					title: title,
					resizable: true,
					draggable: true,
					modal : true,
					close: function(e){
						//$('.popup-content-' + key + ' .form-fields .html-editor textarea:first').ckeditorGet().destroy();
						  //$(this).remove();
					},
					open: function(e){
						//alert($('.popup-content-' + key + ' .form-fields .html-editor').html());
						//if($('.popup-content-' + key + ' .form-fields .html-editor div:first').css('class') != 'cleditorMain'){
						if($('.popup-content-' + key + ' .form-fields .html-editor textarea:first').cleditor()[0] != null){
							$('.popup-content-' + key + ' .form-fields .html-editor textarea:first').cleditor()[0].disable(false).refresh();
						}
						if($('.popup-content-' + key + ' .form-fields .html-editor-disabled .html-editor textarea:first').cleditor()[0] != null){
							$('.popup-content-' + key + ' .form-fields .html-editor-disabled .html-editor textarea:first').cleditor()[0].disable(true).refresh();
						}
						$('.form-box').tooltip({tooltipcontentclass:"tooltip-text"});
						//}
						//$('.popup-content-' + key + ' .form-fields .html-editor textarea:first').htmlarea();
						//alert('popup-content-' + key);
					},
					autoOpen: autoOpen
			 });
	
	//alert($(form).html());
	$('.ui-icon-closethick').click(function(e){
							//document.location.reload();
						});
	//$('.popup-link:first', content).unbind('click');
	$('.popup-link:first', content).click( function(e){
		//alert($(form).html());
		$('.popup-content-' + key).dialog('open');		
	});
}

