Index: /CKEditor/branches/prototype/_source/core/dom/node.js
===================================================================
--- /CKEditor/branches/prototype/_source/core/dom/node.js	(revision 2755)
+++ /CKEditor/branches/prototype/_source/core/dom/node.js	(revision 2756)
@@ -357,9 +357,13 @@
 		 * Gets the closes ancestor node of a specified node name.
 		 * @param {String} name Node name of ancestor node.
+		 * @param {Boolean} includeSelf (Optional) Whether to include the current
+		 * node in the calculation or not.
 		 * @returns {CKEDITOR.dom.node} Ancestor node.
 		 */
-		getAscendant : function( name )
+		getAscendant : function( name, includeSelf )
 		{
 			var node = this.$;
+			if ( includeSelf && node.nodeName.toLowerCase() == name )
+				return this;
 			while ( ( node = node.parentNode ) )
 			{
Index: /CKEditor/branches/prototype/_source/plugins/link/dialogs/link.js
===================================================================
--- /CKEditor/branches/prototype/_source/plugins/link/dialogs/link.js	(revision 2755)
+++ /CKEditor/branches/prototype/_source/plugins/link/dialogs/link.js	(revision 2756)
@@ -72,9 +72,14 @@
 		anchorRegex = /^#(.*)$/,
 		urlRegex = /^((?:http|https|ftp|news):\/\/)?(.*)$/,
+		selectableTargets = /^(_(?:self|top|parent|blank))$/,
+		popupRegex = 
+		/\s*window.open\(\s*this\.href\s*,\s*(?:'([^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*;\s*return\s*false;*\s*/,
+		popupFeaturesRegex = /(?:^|,)([^=]+)=(\d+|yes|no)/gi,
 		loadLink = function( editor, selection, ranges, element )
 	{
-		var href = element.getAttribute( '_cksavedhref' ) || element.getAttribute( 'href' ),
+		var href = element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ),
 			emailMatch = href.match( emailRegex ),
-			anchorMatch = href.match( anchorRegex );
+			anchorMatch = href.match( anchorRegex ),
+			me = this;
 
 		// Load the link type and URL.
@@ -102,9 +107,62 @@
 		}
 
-		// Load target.
-
-		// Load popup settings.
+		// Load target and popup settings.
+		var target = element.getAttribute( 'target' );
+		if ( target == null )
+		{
+			var onclick = element.getAttribute( '_cke_saved_onclick' ) || element.getAttribute( 'onclick' );
+				onclickMatch = onclick && onclick.match( popupRegex );
+			if ( onclickMatch )
+			{
+				this.setValueOf( 'target', 'linkTargetType', 'popup' );
+				this.setValueOf( 'target', 'linkTargetName', onclickMatch[1] );
+				
+				var featureMatch;
+				while ( ( featureMatch = popupFeaturesRegex.exec( onclickMatch[2] ) ) )
+				{
+					if ( featureMatch[2] == 'yes' || featureMatch[2] == '1' )
+						this.setValueOf( 'target', featureMatch[1], true );
+					else if ( isFinite( featureMatch[2] ) )
+						this.setValueOf( 'target', featureMatch[1], featureMatch[2] );
+				}
+			}
+			else
+			{
+				this.setValueOf( 'target', 'linkTargetType', 'notSet' );
+				this.setValueOf( 'target', 'linkTargetName', '' );
+			}
+		}
+		else
+		{
+			var targetMatch = target.match( selectableTargets );
+			if ( targetMatch )
+			{
+				this.setValueOf( 'target', 'linkTargetType', target );
+				this.setValueOf( 'target', 'linkTargetName', target );
+			}
+			else
+			{
+				this.setValueOf( 'target', 'linkTargetType', 'frame' );
+				this.setValueOf( 'target', 'linkTargetName', target );
+			}
+		}
 
 		// Load advanced attributes.
+		var advAttr = function( inputName, attrName )
+		{
+			var value = element.getAttribute( attrName );
+			if ( value != null )
+				me.setValueOf( 'advanced', inputName, value );
+		};
+		advAttr( 'advLangDir', 'dir' );
+		advAttr( 'advAccessKey', 'accessKey' );
+		advAttr( 'advName', 'name' );
+		advAttr( 'advLangCode', 'lang' );
+		advAttr( 'advTabIndex', 'tabindex' );
+		advAttr( 'advTitle', 'title' );
+		advAttr( 'advContentType', 'type' );
+		advAttr( 'advCSSClasses', 'class' );
+		advAttr( 'advCharset', 'charset' );
+		advAttr( 'advStyles', 'style' );
 
 		// Record down the selected element in the dialog.
@@ -389,5 +447,5 @@
 										labelLayout : 'horizontal',
 										label : editor.lang.linkPopupWidth,
-										id : 'popupWidth'
+										id : 'width'
 									},
 									{
@@ -396,5 +454,5 @@
 										widths : [ '55%', '45%' ],
 										label : editor.lang.linkPopupLeft,
-										id : 'popupLeft'
+										id : 'left'
 									}
 								]
@@ -409,5 +467,5 @@
 										widths : [ '30%', '70%' ],
 										label : editor.lang.linkPopupHeight,
-										id : 'popupHeight'
+										id : 'height'
 									},
 									{
@@ -416,5 +474,5 @@
 										label : editor.lang.linkPopupTop,
 										widths : [ '55%', '45%' ],
-										id : 'popupTop'
+										id : 'top'
 									}
 								]
@@ -609,5 +667,5 @@
 			{
 				var rangeRoot = ranges[0].getCommonAncestor(),
-					element = rangeRoot && ( ( rangeRoot.getName() == 'a' && rangeRoot ) || rangeRoot.getAscendant( 'a' ) );
+					element = rangeRoot.getAscendant( 'a', true );
 				if ( element && element.getAttribute( 'href' ) )
 				{
@@ -636,8 +694,8 @@
 			{
 				case 'url':
-					attributes._cksavedhref = this.getValueOf( 'info', 'protocol' ) + this.getValueOf( 'info', 'url' );
+					attributes._cke_saved_href = this.getValueOf( 'info', 'protocol' ) + this.getValueOf( 'info', 'url' );
 					break;
 				case 'anchor':
-					attributes._cksavedhref = '#' + ( this.getValueOf( 'info', 'anchorName' ) || this.getValueOf( 'info', 'anchorId' ) );
+					attributes._cke_saved_href = '#' + ( this.getValueOf( 'info', 'anchorName' ) || this.getValueOf( 'info', 'anchorId' ) );
 					break;
 				case 'email':
@@ -653,5 +711,5 @@
 						linkList.push( argList.join( '&' ) );
 					}
-					attributes._cksavedhref = linkList.join( '' );
+					attributes._cke_saved_href = linkList.join( '' );
 					break;
 				default:
@@ -666,19 +724,19 @@
 						'scrollbars', 'dependent' ],
 					featureLength = featureList.length,
-					addFeature = function( inputName, featureName )
-					{
-						if ( me.getValueOf( 'target', inputName ) != '' )
-							featureList.push( featureName + '=' + me.getValueOf( 'target', inputName ) );
+					addFeature = function( featureName )
+					{
+						if ( me.getValueOf( 'target', featureName ) != '' )
+							featureList.push( featureName + '=' + me.getValueOf( 'target', featureName ) );
 					};
 
 				for ( var i = 0 ; i < featureLength ; i++ )
 					featureList[i] = featureList[i] + ( this.getValueOf( 'target', featureList[i] ) ? '=yes' : '=no' );
-				addFeature( 'popupWidth', 'width' );
-				addFeature( 'popupLeft', 'left' );
-				addFeature( 'popupHeight', 'height' );
-				addFeature( 'popupTop', 'top' );
+				addFeature( 'width' );
+				addFeature( 'left' );
+				addFeature( 'height' );
+				addFeature( 'top' );
 
 				onclickList.push( featureList.join( ',' ), '\'); return false;' );
-				attributes._cksavedonclick = onclickList.join( '' );
+				attributes._cke_saved_onclick = onclickList.join( '' );
 			}
 			else
@@ -717,5 +775,5 @@
 				if ( ranges.length == 1 && ranges[0].collapsed )
 				{
-					ranges[0].insertNode( new CKEDITOR.dom.text( attributes._cksavedhref, editor.document ) );
+					ranges[0].insertNode( new CKEDITOR.dom.text( attributes._cke_saved_href, editor.document ) );
 					selection.selectRanges( ranges );
 				}
