Index: FCKeditor/trunk/_whatsnew.html
===================================================================
--- FCKeditor/trunk/_whatsnew.html	(revision 1503)
+++ FCKeditor/trunk/_whatsnew.html	(revision 1504)
@@ -85,4 +85,8 @@
 		<li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/1613">#1613</a>] The editor was surrounded
 			by a &lt;div&gt; element that wasn't really needed.</li>
+		<li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/676">#676</a>] If a form control was moved
+			in IE after creating it, then it did lose its name.</li>
+		<li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/738">#738</a>] It wasn't possible to change
+			the type of an existing button.</li>
 	</ul>
 	<p>
Index: FCKeditor/trunk/editor/dialog/common/fck_dialog_common.js
===================================================================
--- FCKeditor/trunk/editor/dialog/common/fck_dialog_common.js	(revision 1503)
+++ FCKeditor/trunk/editor/dialog/common/fck_dialog_common.js	(revision 1504)
@@ -207,2 +207,131 @@
 		window.open( url, 'FCKBrowseWindow', sOptions ) ;
 }
+
+/**
+ Utility function to create/update an element with a name attribute in IE, so it behaves properly when moved around
+ It also allows to change the name or other special attributes in an existing node
+	oEditor : instance of FCKeditor where the element will be created
+	oOriginal : current element being edited or null if it has to be created
+	nodeName : string with the name of the element to create
+	oAttributes : Hash object with the attributes that must be set at creation time in IE
+								Those attributes will be set also after the element has been
+								created for any other browser to avoid redudant code
+*/
+function CreateNamedElement( oEditor, oOriginal, nodeName, oAttributes )
+{
+	var oNewNode ;
+
+	// IE doesn't allow easily to change properties of an existing object, 
+	// so remove the old and force the creation of a new one.
+	var oldNode = null ;
+	if ( oOriginal && oEditor.FCKBrowserInfo.IsIE )
+	{
+		// Force the creation only if some of the special attributes have changed:
+		var bChanged = false;
+		for( var attName in oAttributes )
+			bChanged |= ( oOriginal.getAttribute( attName, 2) != oAttributes[attName] ) ;	
+
+		if ( bChanged )
+		{
+			oldNode = oOriginal ;
+			oOriginal = null ;
+		}
+	}
+
+	// If the node existed (and it's not IE), then we just have to update its attributes
+	if ( oOriginal )
+	{
+		oNewNode = oOriginal ;
+	}
+	else
+	{
+		// #676, IE doesn't play nice with the name or type attribute
+		if ( oEditor.FCKBrowserInfo.IsIE )
+		{
+			var sbHTML = [] ;
+			sbHTML.push( '<' + nodeName ) ;
+			for( var prop in oAttributes )
+			{
+				sbHTML.push( ' ' + prop + '="' + oAttributes[prop] + '"' ) ;
+			}
+			sbHTML.push( '>' ) ;
+			if ( !oEditor.FCKListsLib.EmptyElements[nodeName.toLowerCase()] )
+				sbHTML.push( '</' + nodeName + '>' ) ;
+
+			oNewNode = oEditor.FCK.EditorDocument.createElement( sbHTML.join('') ) ;
+			// Check if we are just changing the properties of an existing node: copy its properties
+			if ( oldNode )
+			{
+				CopyAttributes( oldNode, oNewNode, oAttributes ) ;
+				MoveContents( oldNode, oNewNode ) ;
+				oldNode.parentNode.removeChild( oldNode ) ;
+				oldNode = null ;
+
+				if ( oEditor.FCKDialog.SelectionData )
+				{
+					// Trick to refresh the selection object and avoid error in fckdialog.html Selection.EnsureSelection
+					var oSel = oEditor.FCK.EditorDocument.selection ;
+					oEditor.FCKDialog.SelectionData = oSel.createRange() ; // Now oSel.type will be 'None' reflecting the real situation
+				}
+			}
+			oNewNode = oEditor.FCK.InsertElement( oNewNode ) ;
+
+			// FCKDialog.SelectionData is broken by now since we've deleted the previously selected element.
+			// So we need to reassign it.
+			if ( oEditor.FCKDialog.SelectionData )
+			{
+				var range = oEditor.FCK.EditorDocument.body.createControlRange() ;
+				range.add( oNewNode ) ;
+				oEditor.FCKDialog.SelectionData = range ;
+			}
+		}
+		else
+		{
+			oNewNode = oEditor.FCK.InsertElement( nodeName ) ;
+		}
+	}	
+
+	// Set the basic attributes
+	for( var attName in oAttributes )
+		oNewNode.setAttribute( attName, oAttributes[attName], 0 ) ;	// 0 : Case Insensitive
+
+	return oNewNode ;
+}
+
+// Copy all the attributes from one node to the other, kinda like a clone
+// But oSkipAttributes is an object with the attributes that must NOT be copied
+function CopyAttributes( oSource, oDest, oSkipAttributes )
+{
+	var aAttributes = oSource.attributes ;
+
+	for ( var n = 0 ; n < aAttributes.length ; n++ )
+	{
+		var oAttribute = aAttributes[n] ;
+
+		if ( oAttribute.specified )
+		{
+			var sAttName = oAttribute.nodeName ;
+			// We can set the type only once, so do it with the proper value, not copying it.
+			if ( sAttName in oSkipAttributes )
+				continue ;
+
+			var sAttValue = oSource.getAttribute( sAttName, 2 ) ;
+			if ( sAttValue == null )
+				sAttValue = oAttribute.nodeValue ;
+
+			oDest.setAttribute( sAttName, sAttValue, 0 ) ;	// 0 : Case Insensitive
+		}
+	}
+	// The style:
+	oDest.style.cssText = oSource.style.cssText ;
+}
+
+// Move the contents from one node to the other
+function MoveContents( oSource, oDest )
+{
+	while ( oSource.firstChild )
+	{
+		var oNode = oSource.removeChild( oSource.firstChild ) ;
+		oDest.appendChild( oNode ) ;
+	}
+}
Index: FCKeditor/trunk/editor/dialog/fck_button.html
===================================================================
--- FCKeditor/trunk/editor/dialog/fck_button.html	(revision 1503)
+++ FCKeditor/trunk/editor/dialog/fck_button.html	(revision 1504)
@@ -48,6 +48,4 @@
 		GetE('txtValue').value	= oActiveEl.value ;
 		GetE('txtType').value	= oActiveEl.type ;
-
-		GetE('txtType').disabled = true ;
 	}
 	else
@@ -63,12 +61,6 @@
 	oEditor.FCKUndo.SaveUndoStep() ;
 	
-	if ( !oActiveEl )
-	{
-		oActiveEl = oEditor.FCK.EditorDocument.createElement( 'INPUT' ) ;
-		oActiveEl.type = GetE('txtType').value ;
-		oActiveEl = oEditor.FCK.InsertElement( oActiveEl ) ;
-	}
+	oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'INPUT', {name: GetE('txtName').value, type: GetE('txtType').value } ) ;
 
-	oActiveEl.name = GetE('txtName').value ;
 	SetAttribute( oActiveEl, 'value', GetE('txtValue').value ) ;
 
Index: FCKeditor/trunk/editor/dialog/fck_checkbox.html
===================================================================
--- FCKeditor/trunk/editor/dialog/fck_checkbox.html	(revision 1503)
+++ FCKeditor/trunk/editor/dialog/fck_checkbox.html	(revision 1504)
@@ -61,13 +61,5 @@
 	oEditor.FCKUndo.SaveUndoStep() ;
 	
-	if ( !oActiveEl )
-	{
-		oActiveEl = oEditor.FCK.EditorDocument.createElement( 'INPUT' ) ;
-		oActiveEl.type = 'checkbox' ;
-		oActiveEl = oEditor.FCK.InsertElement( oActiveEl ) ;
-	}
-
-	if ( GetE('txtName').value.length > 0 )
-		oActiveEl.name = GetE('txtName').value ;
+	oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'INPUT', {name: GetE('txtName').value, type: 'checkbox' } ) ;
 
 	if ( oEditor.FCKBrowserInfo.IsIE )
Index: FCKeditor/trunk/editor/dialog/fck_hiddenfield.html
===================================================================
--- FCKeditor/trunk/editor/dialog/fck_hiddenfield.html	(revision 1503)
+++ FCKeditor/trunk/editor/dialog/fck_hiddenfield.html	(revision 1504)
@@ -71,13 +71,6 @@
 	oEditor.FCKUndo.SaveUndoStep() ;
 	
-	if ( !oActiveEl )
-	{
-		oActiveEl = FCK.EditorDocument.createElement( 'INPUT' ) ;
-		oActiveEl.type = 'hidden' ;
+	oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'INPUT', {name: GetE('txtName').value, type: 'hidden' } ) ;
 
-		oFakeImage = null ;
-	}
-
-	oActiveEl.name = GetE('txtName').value ;
 	SetAttribute( oActiveEl, 'value', GetE('txtValue').value ) ;
 
@@ -86,10 +79,10 @@
 		oFakeImage	= oEditor.FCKDocumentProcessor_CreateFakeImage( 'FCK__InputHidden', oActiveEl ) ;
 		oFakeImage.setAttribute( '_fckinputhidden', 'true', 0 ) ;
-		oFakeImage	= FCK.InsertElement( oFakeImage ) ;
+
+		oActiveEl.parentNode.insertBefore( oFakeImage, oActiveEl ) ;
+		oActiveEl.parentNode.removeChild( oActiveEl ) ;
 	}
 	else
 		oEditor.FCKUndo.SaveUndoStep() ;
-
-	oEditor.FCKFlashProcessor.RefreshView( oFakeImage, oActiveEl ) ;
 
 	return true ;
Index: FCKeditor/trunk/editor/dialog/fck_radiobutton.html
===================================================================
--- FCKeditor/trunk/editor/dialog/fck_radiobutton.html	(revision 1503)
+++ FCKeditor/trunk/editor/dialog/fck_radiobutton.html	(revision 1504)
@@ -61,13 +61,5 @@
 	oEditor.FCKUndo.SaveUndoStep() ;
 	
-	if ( !oActiveEl )
-	{
-		oActiveEl = oEditor.FCK.EditorDocument.createElement( 'INPUT' ) ;
-		oActiveEl.type = 'radio' ;
-		oActiveEl = oEditor.FCK.InsertElement( oActiveEl ) ;
-	}
-
-	if ( GetE('txtName').value.length > 0 )
-		oActiveEl.name = GetE('txtName').value ;
+	oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'INPUT', {name: GetE('txtName').value, type: 'radio' } ) ;
 
 	if ( oEditor.FCKBrowserInfo.IsIE )
Index: FCKeditor/trunk/editor/dialog/fck_select.html
===================================================================
--- FCKeditor/trunk/editor/dialog/fck_select.html	(revision 1503)
+++ FCKeditor/trunk/editor/dialog/fck_select.html	(revision 1504)
@@ -83,10 +83,6 @@
 		sSize = '' ;
 
-	if ( !oActiveEl )
-	{
-		oActiveEl = oEditor.FCK.InsertElement( 'select' ) ;
-	}
+	oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'SELECT', {name: GetE('txtName').value} ) ;
 
-	SetAttribute( oActiveEl, 'name'	, GetE('txtName').value ) ;
 	SetAttribute( oActiveEl, 'size'	, sSize ) ;
 	oActiveEl.multiple = ( sSize.length > 0 && GetE('chkMultiple').checked ) ;
Index: FCKeditor/trunk/editor/dialog/fck_textarea.html
===================================================================
--- FCKeditor/trunk/editor/dialog/fck_textarea.html	(revision 1503)
+++ FCKeditor/trunk/editor/dialog/fck_textarea.html	(revision 1504)
@@ -60,11 +60,7 @@
 {
 	oEditor.FCKUndo.SaveUndoStep() ;
-	
-	if ( !oActiveEl )
-	{
-		oActiveEl = oEditor.FCK.InsertElement( 'textarea' ) ;
-	}
 
-	oActiveEl.name = GetE('txtName').value ;
+	oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'TEXTAREA', {name: GetE('txtName').value} ) ;
+
 	SetAttribute( oActiveEl, 'cols', GetE('txtCols').value ) ;
 	SetAttribute( oActiveEl, 'rows', GetE('txtRows').value ) ;
Index: FCKeditor/trunk/editor/dialog/fck_textfield.html
===================================================================
--- FCKeditor/trunk/editor/dialog/fck_textfield.html	(revision 1503)
+++ FCKeditor/trunk/editor/dialog/fck_textfield.html	(revision 1504)
@@ -50,6 +50,4 @@
 		GetE('txtMax').value	= GetAttribute( oActiveEl, 'maxLength' ) ;
 		GetE('txtType').value	= oActiveEl.type ;
-
-		GetE('txtType').disabled = true ;
 	}
 	else
@@ -76,13 +74,8 @@
 	}
 
-	if ( !oActiveEl )
-	{
-		oActiveEl = oEditor.FCK.EditorDocument.createElement( 'INPUT' ) ;
-		oActiveEl.type = GetE('txtType').value ;
-		oEditor.FCKUndo.SaveUndoStep() ;
-		oActiveEl = oEditor.FCK.InsertElement( oActiveEl ) ;
-	}
+	oEditor.FCKUndo.SaveUndoStep() ;
 
-	oActiveEl.name = GetE('txtName').value ;
+	oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'INPUT', {name: GetE('txtName').value, type: GetE('txtType').value } ) ;
+
 	SetAttribute( oActiveEl, 'value'	, GetE('txtValue').value ) ;
 	SetAttribute( oActiveEl, 'size'		, GetE('txtSize').value ) ;
