var bgen = {
	FCK: {
		open: function(attr) {
			var openFCK = false;
			if(typeof attr != 'object') {
				alert('ERROR - attr is not a object !!!!');
				return false;
			}
			var title = (attr.title) ? attr.title : 'HTML editor';
			var height = (attr.height) ? attr.height : 600;
			var width = (attr.width) ? attr.width : 800;
			var buttons =(typeof attr.buttons != 'undefined' && attr.buttons) ? attr.buttons : '';
			
			if(attr.value && attr.callback) {
				value = attr.value;
				var params = (attr.params) ? ",params: "+attr.params.toSource() : '';
				//alert(attr.params.toSource());
				var onSave = "{callback:\""+attr.callback+"\""+params+"}";
				openFCK = true;
			}
			else if(attr.form && attr.field) {
				try {
					eval('var value = document.'+attr.form+'.'+attr.field+'.value;');
					var onSave = "{form:\""+attr.form+"\", field:\""+attr.field+"\"}";
					openFCK = true;
				}
				catch(e) {
					alert('ERROR - form or field is not correctly !!!!');
					return false;
				}
			}			
			if(openFCK) {
				n2rent.dialog({	id:			'FCKdiv',
								msg:		'<form method="POST" action="" onsubmit=\'n2rent.FCK.save('+onSave+'); return false;\'><textarea id="fckeditor" name="fckeditor">'+value+'</textarea></form>', 
								title:		title,
								width: 		width,
								height:		height+30,
								style:		'padding:0px',
								buttons:	buttons
								});
				var oFCKeditor = new FCKeditor('fckeditor') ;
				oFCKeditor.BasePath	= "/system/pages/admin/fckeditor/" ;
				oFCKeditor.Height	= height+'px' ;
				oFCKeditor.Width	= width+'px' ;
				oFCKeditor.Config["DefaultLanguage"]    = 'es' ;
				oFCKeditor.Config["EnterMode"] = 'br';
				oFCKeditor.Config["ForceSimpleAmpersand"] = true;
				oFCKeditor.ToolbarSet = "Default";
				oFCKeditor.ReplaceTextarea();
			}
		},
		save: function(attr) {
			if(typeof attr != 'object') {
				alert('ERROR 689 in n2rent.FCK.save. attr is not a object.');
				return false;
			}
			try {
				var value = FCKeditorAPI.GetInstance('fckeditor').EditorDocument.body.innerHTML;
				value = value.replace(/\\/ig, "\\\\'");
				value = value.replace(/'/ig, "\\\'");
				value = value.replace(/"/ig, '\\\"');
				if(attr.form && attr.field) {
					eval("document."+attr.form+"."+attr.field+".value='"+value+"';");
				}
				if(attr.callback) {
					if(attr.params && typeof attr.params == 'object') {
						var params = attr.params;
						params.html = value;
						eval(attr.callback+params.toSource()+';');
					}
					else { 
						eval(attr.callback+'(\''+value+'\');');
					}
				}
				$('#FCKdiv').dialog('close');
			}
			catch(e) {
				alert('ERROR '+e.description);
			}
		}
	},
	alert: function(msg, title, width, height, style) {
		bgen.dialog({	id:			'dialog_temp',
						title:		title,
						msg:		msg,
						width:		width,
						height:		height,
						style:		style,
						buttons:	{ OK: function() { $(this).dialog("close"); }}
		});
		
	},
	popup: function(msg, title, width, height, style){
		bgen.dialog({	id:			'dialog_temp',
						style:		style,
						title:		title,
						msg:		msg,
						width:		width,
						height:		height
		});
	},
	dialog: function(attr) {
		if($('#'+attr.id).attr("id") == attr.id) {
			$('#'+attr.id).remove();
		}
		$('body').after('<div id="'+attr.id+'" style="'+attr.style+'"></div>');
		$('#'+attr.id).html(attr.msg);
		$("#"+attr.id).dialog({ 
			autoOpen: false,
			modal: true, 
			title: (attr.title != null) ? attr.title : 'Aviso', 
			width: (attr.width != null) ? attr.width : null,
			height: (attr.height != null) ? attr.height : '',
			overlay: { opacity: 0.1, background: "black" },
			buttons: attr.buttons
		});
		$('#'+attr.id).dialog('open');
	},
	gmap: function(options) {
		
	}
};

