var arr_Wd_Edit_Removed=new Array();

function wd_Edit_MkCellsHn(theCreator, theNode, sValue, bReversing) {
	if (!bReversing) var bReversing=0;
	var arrCells=new Array();
	if (wd_IsEl(theNode, 'TABLE') || wd_IsEl(theNode, 'THEAD') || wd_IsEl(theNode, 'TBODY') || wd_IsEl(theNode, 'TFOOT')) {
		var iI=0;
		for (iI=0; iI<theNode.rows.length; iI++) {
			var iJ=0; var theRow=theNode.rows[iI];
			for (iJ=0; iJ<theRow.cells.length; iJ++) {
				var theCell=theRow.cells[iJ];
				arrCells[arrCells.length]=theCell;
			}
		}
	} else if (wd_IsEl(theNode, 'TR')) {
		var iJ=0;
		for (iJ=0; iJ<theNode.cells.length; iJ++) {
			var theCell=theNode.cells[iJ];
			arrCells[arrCells.length]=theCell;
		}
	} else if (wd_IsEl(theNode, 'TD') || wd_IsEl(theNode, 'TH')) {
		arrCells[arrCells.length]=theNode;
	}
	//
	for (iJ=0; iJ<arrCells.length; iJ++) {
		var theCell=arrCells[iJ];
		var bOnly=(theCell.childNodes.length===1);
		var bP=wd_IsEl(theCell.childNodes[0], 'P');
		var bDIV=wd_IsEl(theCell.childNodes[0], 'DIV');
		var bH1=wd_IsEl(theCell.childNodes[0], 'H1');
		var bH2=wd_IsEl(theCell.childNodes[0], 'H2');
		var bH3=wd_IsEl(theCell.childNodes[0], 'H3');
		var bH4=wd_IsEl(theCell.childNodes[0], 'H4');
		if (bOnly && (bP || bDIV || bH1 || bH2 || bH3 || bH4)) {
			var theCh0=theCell.childNodes[0];
			if (bReversing && theCh0.tagName===sValue) sValue='DIV';
			var theDiv=theCreator.createElement(sValue);
			theDiv.innerHTML=theCh0.innerHTML;
			theDiv=theCh0.replaceNode(theDiv);
		} else {
			var theDiv=theCreator.createElement(sValue);
			//
			while (theCell.childNodes.length) {
				var theNext=theCell.childNodes[0].removeNode(true);
				theDiv.insertBefore(theNext);
			}
			theCell.insertBefore(theDiv);
		}
		arr_Wd_Edit_Removed[arr_Wd_Edit_Removed.length]=theCell;
	}
}

function wd_Edit_MkNodeHn(theCreator, theNode, sValue, bReversing) {
	if (!bReversing) var bReversing=0;
	if (wd_IsEl(theNode, 'P') || wd_IsEl(theNode, 'DIV') || wd_IsEl(theNode, 'H1') || wd_IsEl(theNode, 'H2') || wd_IsEl(theNode, 'H3') || wd_IsEl(theNode, 'H4')) {
		if (bReversing && wd_IsEl(theNode, sValue)) sValue='DIV';
		var theDiv=theCreator.createElement(sValue);
		theDiv.innerHTML=theNode.innerHTML;
		theDiv=theNode.replaceNode(theDiv);
			// validate DIV adjacents
				// previous
			var theDivPrev=theDiv.previousSibling;
			while (wd_IsEl(theDivPrev, theDiv.tagName) && !theDivPrev.className.length) {
				theDiv=theDiv.removeNode(true);
				theDivPrev.insertBefore(theDiv);
				theDiv.removeNode(false);
				theDiv=theDivPrev;
				theDivPrev=theDiv.previousSibling;
			}
				// next
			var theDivNext=theDiv.nextSibling;
			while (wd_IsEl(theDivNext, theDiv.tagName) && !theDivNext.className.length) {
				theDiv=theDiv.removeNode(true);
				if (theDivNext.childNodes.length) {
					theDivNext.insertBefore(theDiv, theDivNext.childNodes[0]);
				} else {
					theDivNext.insertBefore(theDiv);
				}
				theDiv.removeNode(false);
				theDiv=theDivNext;
				theDivNext=theDiv.nextSibling;
			}
			// validate DIV itself
			var theDivParent=theDiv.parentNode;
			while (wd_IsEl(theDivParent, theDiv.tagName) && !theDivParent.className.length) {
				if (!theDiv.innerHTML.length) {
					var theBR=theCreator.createElement('BR');
					theDiv.insertBefore(theBR);
				}
				theDiv.removeNode(false);
				theDiv=theDivParent;
				theDivParent=theDiv.parentNode;
			}
			//
			if (theDivParent && (wd_IsEl(theDivParent, 'OL')||wd_IsEl(theDivParent, 'UL')) && wd_IsEl(theDivParent.parentNode, theDiv.tagName) && !theDivParent.className.length) {
				theDiv.removeNode(false);
				theDiv=theDivParent;
				theDivParent=theDiv.parentNode;
			}
			//
			if (theDiv.childNodes[0] && wd_IsEl(theDiv.childNodes[0], 'BR')) {
				theDiv.childNodes[0].removeNode(true);
			}
			//
			if (theDivParent && wd_IsEl(theDivParent, 'LI') && ((wd_IsEl(theDivParent.parentNode, theDiv.tagName) && !theDivParent.parentNode.className.length)||(wd_IsEl(theDivParent.parentNode.parentNode, theDiv.tagName) && !theDivParent.parentNode.parentNode.className.length))) {
				theDiv.removeNode(false);
			} else if (wd_IsEl(theDivParent, theDiv.tagName) && !theDivParent.className.length && theDivParent.innerText===theDiv.innerText) {
				theDivParent.className=theDiv.className;
				theDiv.removeNode(false);
			}
	} else if (wd_IsEl(theNode, 'TABLE') || wd_IsEl(theNode, 'THEAD') || wd_IsEl(theNode, 'TBODY') || wd_IsEl(theNode, 'TFOOT') || wd_IsEl(theNode, 'TR') || wd_IsEl(theNode, 'TD') || wd_IsEl(theNode, 'TH')) {
		wd_Edit_MkCellsHn(theCreator, theNode, sValue, bReversing);
	} else {
		// climb to inblock
		while (theNode.parentNode && !wd_IsBlockEl(theNode.parentNode)) theNode=theNode.parentNode;
		// v=== make paragraph: ===========================v
		var arrNodes=new Array();
		var thePrevNode=theNode.previousSibling;
		while (thePrevNode) {
			if (!wd_IsEl(thePrevNode) || (!wd_IsBlockEl(thePrevNode) && wd_IsContEl(thePrevNode))) {
				arrNodes[arrNodes.length]=thePrevNode;
				thePrevNode=thePrevNode.previousSibling;
			} else if (wd_IsEl(thePrevNode, 'BR')) {
				arrNodes[arrNodes.length]=thePrevNode;
				thePrevNode=thePrevNode.previousSibling;
				break;
			} else {
				break;
			}
		}
		arrNodes=arrNodes.reverse();
		//
		arrNodes[arrNodes.length]=theNode;
		//
		var theNextNode=theNode.nextSibling;
		while (theNextNode) {
			if (!wd_IsEl(theNextNode) || (!wd_IsBlockEl(theNextNode) && wd_IsContEl(theNextNode))) {
				arrNodes[arrNodes.length]=theNextNode;
				theNextNode=theNextNode.nextSibling;
			} else if (wd_IsEl(theNextNode, 'BR')) {
				arrNodes[arrNodes.length]=theNextNode;
				theNextNode=theNextNode.nextSibling;
				break;
			} else {
				break;
			}
		}
		// ^=== :make paragraph ===========================^
		var theElToInsert=theNode.parentNode;
		if (theElToInsert) {
			var theDiv=theCreator.createElement(sValue);
			theElToInsert.insertBefore(theDiv, arrNodes[0]);
			var thePreNode=theDiv.previousSibling;
			if (thePreNode && thePreNode.id && thePreNode.id==="wd_576879_Start") hePreNode=thePreNode.previousSibling;
			var bPreBlock=wd_IsBlockEl(thePreNode);
			var thePostNode=theDiv.nextSibling;
			if (thePostNode && thePostNode.id && thePostNode.id==="wd_576879_Fin") thePostNode=thePostNode.nextSibling;
			var bPostBlock=wd_IsBlockEl(thePostNode);
			var iI=0;
			for (iI=0; iI<arrNodes.length; iI++) {
				var theTmpNode=arrNodes[iI];
				var bFirstNode=(iI===0); var bLatestNode=(iI===(arrNodes.length-1));
				var bNonUsed=false;
				//var bNonUsed=(wd_IsEl(theTmpNode, 'BR') && ((bFirstNode && bPreBlock)||(bLatestNode && bPostBlock)));
				theTmpNode=theTmpNode.removeNode(true);
				if (!bNonUsed) theDiv.insertBefore(theTmpNode);
				arr_Wd_Edit_Removed[arr_Wd_Edit_Removed.length]=theTmpNode;
			}
			// validate DIV adjacents
				// previous
			var theDivPrev=theDiv.previousSibling;
			while (wd_IsEl(theDivPrev, sValue) && !theDivPrev.className.length) {
				theDiv=theDiv.removeNode(true);
				theDivPrev.insertBefore(theDiv);
				theDiv.removeNode(false);
				theDiv=theDivPrev;
				theDivPrev=theDiv.previousSibling;
			}
				// next
			var theDivNext=theDiv.nextSibling;
			while (wd_IsEl(theDivNext, sValue) && !theDivNext.className.length) {
				theDiv=theDiv.removeNode(true);
				if (theDivNext.childNodes.length) {
					theDivNext.insertBefore(theDiv, theDivNext.childNodes[0]);
				} else {
					theDivNext.insertBefore(theDiv);
				}
				theDiv.removeNode(false);
				theDiv=theDivNext;
				theDivNext=theDiv.nextSibling;
			}
			// validate DIV itself
			var theDivParent=theDiv.parentNode;
			while (wd_IsEl(theDivParent, sValue) && !theDivParent.className.length) {
				if (!theDiv.innerHTML.length) {
					var theBR=theCreator.createElement('BR');
					theDiv.insertBefore(theBR);
				}
				theDiv.removeNode(false);
				theDiv=theDivParent;
				theDivParent=theDiv.parentNode;
			}
			//
			if (theDivParent && (wd_IsEl(theDivParent, 'OL')||wd_IsEl(theDivParent, 'UL')) && wd_IsEl(theDivParent.parentNode, sValue) && theDivParent.parentNode.className===theDiv.className) {
				theDiv.removeNode(false);
				theDiv=theDivParent;
				theDivParent=theDiv.parentNode;
			}
			//
			if (theDiv.childNodes[0] && wd_IsEl(theDiv.childNodes[0], 'BR')) {
				theDiv.childNodes[0].removeNode(true);
			}
			//
			if (theDivParent && wd_IsEl(theDivParent, 'LI') && ((wd_IsEl(theDivParent.parentNode, sValue) && !theDivParent.parentNode.className.length)||(wd_IsEl(theDivParent.parentNode.parentNode, sValue) && !theDivParent.parentNode.parentNode.className.length))) {
				theDiv.removeNode(false);
			} else if (wd_IsEl(theDivParent, sValue) && !theDivParent.className.length && theDivParent.innerText===theDiv.innerText) {
				theDivParent.className=theDiv.className;
				theDiv.removeNode(false);
			}
		}
	}
}

function wd_Edit_MkCellsPStyle(theCreator, theNode, sValue, bReversing) {
	if (!bReversing) var bReversing=0;
	var arrCells=new Array();
	if (wd_IsEl(theNode, 'TABLE') || wd_IsEl(theNode, 'THEAD') || wd_IsEl(theNode, 'TBODY') || wd_IsEl(theNode, 'TFOOT')) {
		var iI=0;
		for (iI=0; iI<theNode.rows.length; iI++) {
			var iJ=0; var theRow=theNode.rows[iI];
			for (iJ=0; iJ<theRow.cells.length; iJ++) {
				var theCell=theRow.cells[iJ];
				arrCells[arrCells.length]=theCell;
			}
		}
	} else if (wd_IsEl(theNode, 'TR')) {
		var iJ=0;
		for (iJ=0; iJ<theNode.cells.length; iJ++) {
			var theCell=theNode.cells[iJ];
			arrCells[arrCells.length]=theCell;
		}
	} else if (wd_IsEl(theNode, 'TD') || wd_IsEl(theNode, 'TH')) {
		arrCells[arrCells.length]=theNode;
	}
	//
	for (iJ=0; iJ<arrCells.length; iJ++) {
		var theCell=arrCells[iJ];
		if (theCell.childNodes.length===1 && wd_IsEl(theCell.childNodes[0], 'P') || wd_IsEl(theCell.childNodes[0], 'DIV')) {
			var theCh0=theCell.childNodes[0];
			if (bReversing && theCh0.className===sValue) {
				theCh0.className="";
			} else {
				theCh0.className=sValue;
			}
		} else {
			var theDiv=theCreator.createElement('DIV');
			theDiv.className=sValue;
			//
			while (theCell.childNodes.length) {
				var theNext=theCell.childNodes[0].removeNode(true);
				theDiv.insertBefore(theNext);
			}
			theCell.insertBefore(theDiv);
		}
		arr_Wd_Edit_Removed[arr_Wd_Edit_Removed.length]=theCell;
	}
}
function wd_Edit_MkNodePStyle(theCreator, theNode, sValue, bReversing) {
	if (!bReversing) var bReversing=0;
	if (wd_IsEl(theNode, 'P') || wd_IsEl(theNode, 'DIV')) {// || wd_IsEl(theNode, 'H1') wd_IsEl(theNode, 'H2') wd_IsEl(theNode, 'H3') wd_IsEl(theNode, 'H4')
		if (bReversing && theNode.className===sValue) {
			theNode.className="";
		} else {
			theNode.className=sValue;
		}
		var theDiv=theNode;
			// validate DIV adjacents
				// previous
			var theDivPrev=theDiv.previousSibling;
			while (wd_IsEl(theDivPrev, 'DIV') && theDivPrev.className===theDiv.className) {// && theDivPrev.style.cssText===theDiv.style.cssText
				theDiv=theDiv.removeNode(true);
				theDivPrev.insertBefore(theDiv);
				theDiv.removeNode(false);
				theDiv=theDivPrev;
				theDivPrev=theDiv.previousSibling;
			}
				// next
			var theDivNext=theDiv.nextSibling;
			while (wd_IsEl(theDivNext, 'DIV') && theDivNext.className===theDiv.className) {// && theDivNext.style.cssText===theDiv.style.cssText
				theDiv=theDiv.removeNode(true);
				if (theDivNext.childNodes.length) {
					theDivNext.insertBefore(theDiv, theDivNext.childNodes[0]);
				} else {
					theDivNext.insertBefore(theDiv);
				}
				theDiv.removeNode(false);
				theDiv=theDivNext;
				theDivNext=theDiv.nextSibling;
			}
			// validate DIV itself
			var theDivParent=theDiv.parentNode;
			while (wd_IsEl(theDivParent, 'DIV') && theDivParent.className===theDiv.className) {// && theDivParent.style.cssText===theDiv.style.cssText
				if (!theDiv.innerHTML.length) {
					var theBR=theCreator.createElement('BR');
					theDiv.insertBefore(theBR);
				}
				theDiv.removeNode(false);
				theDiv=theDivParent;
				theDivParent=theDiv.parentNode;
			}
			//
			if (theDivParent && (wd_IsEl(theDivParent, 'OL')||wd_IsEl(theDivParent, 'UL')) && wd_IsEl(theDivParent.parentNode, 'DIV') && theDivParent.parentNode.className===theDiv.className) {
				theDiv.removeNode(false);
				theDiv=theDivParent;
				theDivParent=theDiv.parentNode;
			}
			//
			if (theDiv.childNodes[0] && wd_IsEl(theDiv.childNodes[0], 'BR')) {
				theDiv.childNodes[0].removeNode(true);
			}
			//
			if (theDivParent && wd_IsEl(theDivParent, 'LI') && ((wd_IsEl(theDivParent.parentNode, 'DIV') && theDivParent.parentNode.className===theDiv.className)||(wd_IsEl(theDivParent.parentNode.parentNode, 'DIV') && theDivParent.parentNode.parentNode.className===theDiv.className))) {
				theDiv.removeNode(false);
			} else if (wd_IsEl(theDivParent, 'DIV') && theDivParent.className.substr(0, 9)==='tpl_style' && theDivParent.innerText===theDiv.innerText) {
				theDivParent.className=theDiv.className;
				theDiv.removeNode(false);
			}
	} else if (wd_IsEl(theNode, 'TABLE') || wd_IsEl(theNode, 'THEAD') || wd_IsEl(theNode, 'TBODY') || wd_IsEl(theNode, 'TFOOT') || wd_IsEl(theNode, 'TR') || wd_IsEl(theNode, 'TD') || wd_IsEl(theNode, 'TH')) {
		wd_Edit_MkCellsPStyle(theCreator, theNode, sValue, bReversing);
	} else {
		// climb to inblock
		while (theNode.parentNode && !wd_IsBlockEl(theNode.parentNode)) theNode=theNode.parentNode;
		// v=== make paragraph: ===========================v
		var arrNodes=new Array();
		var thePrevNode=theNode.previousSibling;
		while (thePrevNode) {
			if (!wd_IsEl(thePrevNode) || (!wd_IsBlockEl(thePrevNode) && wd_IsContEl(thePrevNode))) {
				arrNodes[arrNodes.length]=thePrevNode;
				thePrevNode=thePrevNode.previousSibling;
			} else if (wd_IsEl(thePrevNode, 'BR')) {
				arrNodes[arrNodes.length]=thePrevNode;
				thePrevNode=thePrevNode.previousSibling;
				break;
			} else {
				break;
			}
		}
		arrNodes=arrNodes.reverse();
		//
		arrNodes[arrNodes.length]=theNode;
		//
		var theNextNode=theNode.nextSibling;
		while (theNextNode) {
			if (!wd_IsEl(theNextNode) || (!wd_IsBlockEl(theNextNode) && wd_IsContEl(theNextNode))) {
				arrNodes[arrNodes.length]=theNextNode;
				theNextNode=theNextNode.nextSibling;
			} else if (wd_IsEl(theNextNode, 'BR')) {
				arrNodes[arrNodes.length]=theNextNode;
				theNextNode=theNextNode.nextSibling;
				break;
			} else {
				break;
			}
		}
		// ^=== :make paragraph ===========================^
		var theElToInsert=theNode.parentNode;
		if (theElToInsert) {
			var theDiv=theCreator.createElement('DIV');
			/*if (bReversing && theDiv.className===sValue) {
				theDiv.className="";
			} else {
				theDiv.className=sValue;
			}*/
			theDiv.className=sValue;
			theElToInsert.insertBefore(theDiv, arrNodes[0]);
			var thePreNode=theDiv.previousSibling;
			if (thePreNode && thePreNode.id && thePreNode.id==="wd_576879_Start") hePreNode=thePreNode.previousSibling;
			var bPreBlock=wd_IsBlockEl(thePreNode);
			var thePostNode=theDiv.nextSibling;
			if (thePostNode && thePostNode.id && thePostNode.id==="wd_576879_Fin") thePostNode=thePostNode.nextSibling;
			var bPostBlock=wd_IsBlockEl(thePostNode);
			var iI=0;
			for (iI=0; iI<arrNodes.length; iI++) {
				var theTmpNode=arrNodes[iI];
				var bFirstNode=(iI===0); var bLatestNode=(iI===(arrNodes.length-1));
				var bNonUsed=false;
				//var bNonUsed=(wd_IsEl(theTmpNode, 'BR') && ((bFirstNode && bPreBlock)||(bLatestNode && bPostBlock)));
				theTmpNode=theTmpNode.removeNode(true);
				if (!bNonUsed) theDiv.insertBefore(theTmpNode);
				arr_Wd_Edit_Removed[arr_Wd_Edit_Removed.length]=theTmpNode;
			}
			// validate DIV adjacents
				// previous
			var theDivPrev=theDiv.previousSibling;
			while (wd_IsEl(theDivPrev, 'DIV') && theDivPrev.className===theDiv.className) {// && theDivPrev.style.cssText===theDiv.style.cssText
				theDiv=theDiv.removeNode(true);
				theDivPrev.insertBefore(theDiv);
				theDiv.removeNode(false);
				theDiv=theDivPrev;
				theDivPrev=theDiv.previousSibling;
			}
				// next
			var theDivNext=theDiv.nextSibling;
			while (wd_IsEl(theDivNext, 'DIV') && theDivNext.className===theDiv.className) {// && theDivNext.style.cssText===theDiv.style.cssText
				theDiv=theDiv.removeNode(true);
				if (theDivNext.childNodes.length) {
					theDivNext.insertBefore(theDiv, theDivNext.childNodes[0]);
				} else {
					theDivNext.insertBefore(theDiv);
				}
				theDiv.removeNode(false);
				theDiv=theDivNext;
				theDivNext=theDiv.nextSibling;
			}
			// validate DIV itself
			var theDivParent=theDiv.parentNode;
			while (wd_IsEl(theDivParent, 'DIV') && theDivParent.className===theDiv.className) {// && theDivParent.style.cssText===theDiv.style.cssText
				if (!theDiv.innerHTML.length) {
					var theBR=theCreator.createElement('BR');
					theDiv.insertBefore(theBR);
				}
				theDiv.removeNode(false);
				theDiv=theDivParent;
				theDivParent=theDiv.parentNode;
			}
			//
			if (theDivParent && (wd_IsEl(theDivParent, 'OL')||wd_IsEl(theDivParent, 'UL')) && wd_IsEl(theDivParent.parentNode, 'DIV') && theDivParent.parentNode.className===theDiv.className) {
				theDiv.removeNode(false);
				theDiv=theDivParent;
				theDivParent=theDiv.parentNode;
			}
			//
			if (theDiv.childNodes[0] && wd_IsEl(theDiv.childNodes[0], 'BR')) {
				theDiv.childNodes[0].removeNode(true);
			}
			//
			if (theDivParent && wd_IsEl(theDivParent, 'LI') && ((wd_IsEl(theDivParent.parentNode, 'DIV') && theDivParent.parentNode.className===theDiv.className)||(wd_IsEl(theDivParent.parentNode.parentNode, 'DIV') && theDivParent.parentNode.parentNode.className===theDiv.className))) {
				theDiv.removeNode(false);
			} else if (wd_IsEl(theDivParent, 'DIV') && theDivParent.className.substr(0, 9)==='tpl_style' && theDivParent.innerText===theDiv.innerText) {
				theDivParent.className=theDiv.className;
				theDiv.removeNode(false);
			}
		}
	}
}
function wd_Edit_MkNodeTAlign(theCreator, theNode, sValue) {
	if (wd_IsBlockEl(theNode) || wd_IsEl(theNode, 'THEAD') || wd_IsEl(theNode, 'TBODY') || wd_IsEl(theNode, 'TFOOT')) {
		wd_Edit_MkBlockTAlign(theCreator, theNode, sValue);
	} else {
		// climb to inblock
		while (theNode.parentNode && !wd_IsBlockEl(theNode.parentNode)) theNode=theNode.parentNode;
		// v=== make paragraph: ===========================v
		var arrNodes=new Array();
		var thePrevNode=theNode.previousSibling;
			while (thePrevNode) {
				if (!wd_IsEl(thePrevNode) || (!wd_IsBlockEl(thePrevNode) && wd_IsContEl(thePrevNode))) {
					arrNodes[arrNodes.length]=thePrevNode;
					thePrevNode=thePrevNode.previousSibling;
				} else if (wd_IsEl(thePrevNode, 'BR')) {
					arrNodes[arrNodes.length]=thePrevNode;
					break;
				} else {
					break;
				}
			}
			arrNodes=arrNodes.reverse();
		//
		arrNodes[arrNodes.length]=theNode;
		//
		var theNextNode=theNode.nextSibling;
		while (theNextNode) {
			if (!wd_IsEl(theNextNode) || (!wd_IsBlockEl(theNextNode) && wd_IsContEl(theNextNode))) {
				arrNodes[arrNodes.length]=theNextNode;
				theNextNode=theNextNode.nextSibling;
			} else if (wd_IsEl(theNextNode, 'BR')) {
				arrNodes[arrNodes.length]=theNextNode;
				break;
			} else {
				break;
			}
		}
		// ^=== :make paragraph ===========================^
		var theElToInsert=theNode.parentNode;
		if (theElToInsert) {
			var theDiv=theCreator.createElement('DIV');
			theDiv.style.setAttribute('textAlign', sValue, 0);
			theElToInsert.insertBefore(theDiv, arrNodes[0]);
			var thePreNode=theDiv.previousSibling;
			if (thePreNode && thePreNode.id && thePreNode.id==="wd_576879_Start") hePreNode=thePreNode.previousSibling;
			var bPreBlock=wd_IsBlockEl(thePreNode);
			var thePostNode=theDiv.nextSibling;
			if (thePostNode && thePostNode.id && thePostNode.id==="wd_576879_Fin") thePostNode=thePostNode.nextSibling;
			var bPostBlock=wd_IsBlockEl(thePostNode);
			var iI=0;
			for (iI=0; iI<arrNodes.length; iI++) {
				var theTmpNode=arrNodes[iI];
				var bFirstNode=(iI===0); var bLatestNode=(iI===(arrNodes.length-1));
				var bNonUsed=false;
				//var bNonUsed=(wd_IsEl(theTmpNode, 'BR') && ((bFirstNode && bPreBlock)||(bLatestNode && bPostBlock)));
				theTmpNode=theTmpNode.removeNode(true);
				if (!bNonUsed) theDiv.insertBefore(theTmpNode);
				arr_Wd_Edit_Removed[arr_Wd_Edit_Removed.length]=theTmpNode;
			}
			// validate DIV adjacents
				// previous
			var theDivPrev=theDiv.previousSibling;
			while (wd_IsEl(theDivPrev, 'DIV') && theDivPrev.className===theDiv.className && theDivPrev.style.cssText===theDiv.style.cssText) {
				theDiv=theDiv.removeNode(true);
				theDivPrev.insertBefore(theDiv);
				theDiv.removeNode(false);
				theDiv=theDivPrev;
				theDivPrev=theDiv.previousSibling;
			}
				// next
			var theDivNext=theDiv.nextSibling;
			while (wd_IsEl(theDivNext, 'DIV') && theDivNext.className===theDiv.className && theDivNext.style.cssText===theDiv.style.cssText) {
				theDiv=theDiv.removeNode(true);
				if (theDivNext.childNodes.length) {
					theDivNext.insertBefore(theDiv, theDivNext.childNodes[0]);
				} else {
					theDivNext.insertBefore(theDiv);
				}
				theDiv.removeNode(false);
				theDiv=theDivNext;
				theDivNext=theDiv.nextSibling;
			}
			// validate DIV itself
			var theDivParent=theDiv.parentNode;
			if (wd_IsEl(theDivParent, 'DIV') && theDivParent.className===theDiv.className && theDivParent.childNodes.length===1) {
				theDivParent.style.setAttribute('textAlign', sValue, 0);
				if (!theDiv.innerHTML.length) {
					var theBR=theCreator.createElement('BR');
					theDiv.insertBefore(theBR);
				}
				theDiv.removeNode(false);
			}
		}
	}
}
function wd_Edit_MkBlockTAlign(theCreator, theNode, sValue) {
	if (wd_IsBlockEl(theNode) || wd_IsEl(theNode, 'THEAD') || wd_IsEl(theNode, 'TBODY') || wd_IsEl(theNode, 'TFOOT')) {
		if (wd_IsContEl(theNode)) theNode.style.setAttribute('textAlign', sValue, 0);
		var arrChs=theNode.childNodes; var iI=0;
		for (iI=0; iI<arrChs.length; iI++) {
			arr_Wd_Edit_Removed[arr_Wd_Edit_Removed.length]=arrChs[iI];
			wd_Edit_MkBlockTAlign(theCreator, arrChs[iI], sValue);
		}
	}
}
function wd_Edit_TNodeToSpan(theCreator, theTNode, arrAttributes, arrValues) {
	// validate input:
	if (!arrAttributes) var arrAttributes=new Array();
	if (!arrValues) var arrValues=new Array();
	if (typeof(arrAttributes)==='string') {var sTmp=arrAttributes; var arrAttributes=new Array(sTmp);}
	if (typeof(arrValues)==='string') {var sTmp=arrValues; var arrValues=new Array(sTmp);}
	// collect attributes need to be setted according to parent formatting:
	var theParent=theTNode.parentNode;
	var arrNeedAttrs = new Array(); var arrNeedVals = new Array();
	var iI=0; for (iI=0; iI<arrAttributes.length; iI++) {
		var sAttrName=arrAttributes[iI];
		var vAtrrVal=''; if (typeof(arrValues[iI])!=='undefined') vAtrrVal=arrValues[iI];
		if (sAttrName==='fontWeight') {
			if (wd_Edit_TestNeedFWeight(theParent)===vAtrrVal) {
				arrNeedAttrs[arrNeedAttrs.length]=sAttrName;
				arrNeedVals[arrNeedVals.length]=vAtrrVal;
			}
		} else if (sAttrName==='fontStyle') {
			if (wd_Edit_TestNeedFStyle(theParent)===vAtrrVal) {
				arrNeedAttrs[arrNeedAttrs.length]=sAttrName;
				arrNeedVals[arrNeedVals.length]=vAtrrVal;
			}
		} else {
			if (theParent.currentStyle.getAttribute(sAttrName)!==vAtrrVal) {
				arrNeedAttrs[arrNeedAttrs.length]=sAttrName;
				arrNeedVals[arrNeedVals.length]=vAtrrVal;
			}
		}
	}
	// convert to span if need;
	if (arrNeedAttrs.length) {
		var theNewSpan=theCreator.createElement('SPAN');
		var iI=0; for (iI=0; iI<arrNeedAttrs.length; iI++) {
			var sNextAttr=arrNeedAttrs[iI];
			if (sNextAttr==='className') {
				theNewSpan.setAttribute(sNextAttr, arrNeedVals[iI], 0);
			} else {
				theNewSpan.style.setAttribute(sNextAttr, arrNeedVals[iI], 0);
			}
		}
		theNewSpan.innerText=theTNode.nodeValue;
		theTNode.replaceNode(theNewSpan);
		//
//alert("wd_Edit_TNodeToSpan Before validating:\n"+wd_NodeValEx(theNewSpan));
		wd_ValidateSpanAdjacents(theNewSpan);
//alert("wd_Edit_TNodeToSpan After validating:\n"+wd_NodeValEx(theNewSpan));
	} else {
		var theNewSpan=theTNode;
	}
	// return new or old node;
	return theNewSpan;
}

function wd_Edit_MkNodeFill(theCreator, theNode, sValue) {
	if (wd_IsEl(theNode)) {
		if (wd_IsContEl(theNode)) theNode.style.setAttribute('backgroundColor', sValue, 0);
		var arrChs=theNode.childNodes; var iI=0;
		for (iI=0; iI<arrChs.length; iI++) {
			if (wd_IsEl(arrChs[iI])) wd_Edit_MkNodeFill(theCreator, arrChs[iI], sValue);
		}
		wd_ValidateSpanAdjacents(theNode);
	} else if (theNode.nodeType) {
		wd_Edit_TNodeToSpan(theCreator, theNode, 'backgroundColor', sValue);
	}
}
function wd_Edit_MkNodeBgColor(theCreator, theNode, sValue) {
	if (wd_IsEl(theNode)) {
		var arrChs=theNode.childNodes; var iI=0;
		if (wd_IsBlockEl(theNode)) {
			for (iI=0; iI<arrChs.length; iI++) wd_Edit_MkNodeBgColor(theCreator, arrChs[iI], sValue);
		} else {
			if (wd_IsContEl(theNode)) theNode.style.setAttribute('backgroundColor', sValue, 0);
			for (iI=0; iI<arrChs.length; iI++) {
				if (wd_IsEl(arrChs[iI])) wd_Edit_MkNodeBgColor(theCreator, arrChs[iI], sValue);
			}
		}
		wd_ValidateSpanAdjacents(theNode);
	} else if (theNode.nodeType) {
		wd_Edit_TNodeToSpan(theCreator, theNode, 'backgroundColor', sValue);
	}
}

function wd_Edit_SetSAttr(theCreator, theNode, sAttrName, sValue) {
	if (wd_IsEl(theNode)) {
		var arrContEls=wd_PickupContEls(theNode);
		if (arrContEls.length) {
			var iI=0; for (iI=0; iI<arrContEls.length; iI++) {
				if (sAttrName==='className') {
					arrContEls[iI].setAttribute(sAttrName, sValue, 0);
				} else {
					arrContEls[iI].style.setAttribute(sAttrName, sValue, 0);
				}
			}
		}
		wd_ValidateSpanAdjacents(theNode);
	} else if (theNode.nodeType) {
		wd_Edit_TNodeToSpan(theCreator, theNode, sAttrName, sValue);
	}
}
function wd_Edit_MkNodeFSize(theCreator, theNode, sValue) {
	wd_Edit_SetSAttr(theCreator, theNode, 'fontSize', sValue);
}
function wd_Edit_MkNodeFFamily(theCreator, theNode, sValue) {
	wd_Edit_SetSAttr(theCreator, theNode, 'fontFamily', sValue);
}
function wd_Edit_MkNodeFColor(theCreator, theNode, sValue) {
	wd_Edit_SetSAttr(theCreator, theNode, 'color', sValue);
}

function wd_Edit_MkNodeClass(theCreator, theNode, sValue, bReversing) {
	if (!bReversing) var bReversing=0;
	//wd_Edit_SetSAttr(theCreator, theNode, 'className', sValue);
//alert("wd_Edit_MkNodeClass:\n"+wd_NodeValEx(theNode));
	if (wd_IsEl(theNode)) {
//alert("wd_Edit_MkNodeClass: Element");
		var arrChs=theNode.childNodes; var iI=0;
		if (wd_IsBlockEl(theNode)) {
//alert("wd_Edit_MkNodeClass: Block"+wd_NodeValEx(theNode));
			for (iI=0; iI<arrChs.length; iI++) {
				wd_Edit_MkNodeClass(theCreator, arrChs[iI], sValue, bReversing);
			}
		} else {
//alert("wd_Edit_MkNodeClass: NonBlock"+wd_NodeValEx(theNode));
			if (wd_IsContEl(theNode)) {
				if (bReversing && theNode.getAttribute('className', 0)===sValue) {
					theNode.setAttribute('className', "", 0);
				} else {
					theNode.setAttribute('className', sValue, 0);
				}
			}
			for (iI=0; iI<arrChs.length; iI++) {
				if (wd_IsEl(arrChs[iI])) wd_Edit_MkNodeClass(theCreator, arrChs[iI], sValue, bReversing);
			}
		}
		wd_ValidateSpanAdjacents(theNode);
	} else if (theNode.nodeType) {
//alert("wd_Edit_MkNodeClass: TextNode\n"+wd_NodeValEx(theNode));
		wd_Edit_TNodeToSpan(theCreator, theNode, 'className', sValue);
	}
}

function wd_Edit_TestNeedFStyle(theTestEl) {
	var sValue="italic";
	if (wd_IsEl(theTestEl)) {
		var sCurrS=theTestEl.currentStyle.fontStyle;
		if (sCurrS==='italic' || sCurrS==='oblique') sValue="normal";
	}
	return sValue;
}
function wd_Edit_MkNodeItalic(theCreator, theNode, sValue) {
	if (wd_IsEl(theNode)) {
		var arrContEls=wd_PickupContEls(theNode);
		if (arrContEls.length) {
			if (!sValue) {var theTestEl=arrContEls[0]; var sValue=wd_Edit_TestNeedFStyle(theTestEl);}
			var iI=0;
			for (iI=0; iI<arrContEls.length; iI++) arrContEls[iI].style.setAttribute('fontStyle', sValue, 0);
		}
		wd_ValidateSpanAdjacents(theNode);
	} else if (theNode.nodeType) {
		if (!sValue) {
			var theTestEl=theNode.parentNode;
			var sValue=wd_Edit_TestNeedFStyle(theTestEl);
		}
		wd_Edit_TNodeToSpan(theCreator, theNode, 'fontStyle', sValue);
	}
}

function wd_Edit_TestNeedFWeight(theTestEl) {
	var sValue="bold";
	if (wd_IsEl(theTestEl)) {
		var sCurrW=theTestEl.currentStyle.fontWeight;
		var iCurrW=parseInt(sCurrW);
		if (iCurrW>=600 || sCurrW==='bold' || sCurrW==='bolder' || sCurrW==='600' || sCurrW==='700' || sCurrW==='800' || sCurrW==='900') sValue="normal";
	}
	return sValue;
}
function wd_Edit_MkNodeBold(theCreator, theNode, sValue) {
	if (wd_IsEl(theNode)) {
		var arrContEls=wd_PickupContEls(theNode);
		if (arrContEls.length) {
			if (!sValue) {var theTestEl=arrContEls[0]; var sValue=wd_Edit_TestNeedFWeight(theTestEl);}
			var iI=0;
			for (iI=0; iI<arrContEls.length; iI++) arrContEls[iI].style.setAttribute('fontWeight', sValue, 0);
		}
		wd_ValidateSpanAdjacents(theNode);
	} else if (theNode.nodeType) {
		if (!sValue) {
			var theTestEl=theNode.parentNode;
			var sValue=wd_Edit_TestNeedFWeight(theTestEl);
		}
		wd_Edit_TNodeToSpan(theCreator, theNode, 'fontWeight', sValue);
	}
}
// v=== formatting validating: ================================================v
function wd_ClearStylesByParent(theNode) {
//alert("wd_ClearStylesByParent:\n"+wd_IsEl(theNode)+"\n"+theNode.className.length);
	if (wd_IsEl(theNode) && !theNode.className.length) {
//alert("WORK wd_ClearStylesByParent");
		var theParent=theNode.parentNode;
		if (wd_IsEl(theParent)) {
			if (wd_Edit_TestNeedFWeight(theNode)===wd_Edit_TestNeedFWeight(theParent)) theNode.style.fontWeight='';
			if (theNode.style.fontSize===theParent.currentStyle.fontSize) theNode.style.fontSize='';
			if (theNode.style.fontStyle===theParent.currentStyle.fontStyle) theNode.style.fontStyle='';
			if (theNode.style.color===theParent.currentStyle.color) theNode.style.color='';
			if (theNode.style.backgroundColor===theParent.currentStyle.backgroundColor) theNode.style.backgroundColor='';
		}
	}
}
function wd_FillStylesByParent(theNode) {
	if (wd_IsEl(theNode)) {
		var theParent=theNode.parentNode;
		if (theParent && theParent.className===theNode.className) {
			if (theParent.style.fontWeight && !theNode.style.fontWeight) theNode.style.fontWeight=theParent.style.fontWeight;
			if (theParent.style.fontSize && !theNode.style.fontSize) theNode.style.fontSize=theParent.style.fontSize;
			if (theParent.style.fontStyle && !theNode.style.fontStyle) theNode.style.fontStyle=theParent.style.fontStyle;
			if (theParent.style.color && !theNode.style.color) theNode.style.color=theParent.style.color;
			if (theParent.style.backgroundColor && !theNode.style.backgroundColor) theNode.style.backgroundColor=theParent.style.backgroundColor;
		}
	}
}
function wd_ValidateSpanAdjacents(theEl) {
//alert("wd_ValidateSpanAdjacents 1:\n"+wd_NodeValEx(theEl));
	if (theEl.childNodes && theEl.childNodes.length) {
		// remove same children
		if (wd_IsEl(theEl, 'SPAN')) {
			var theNode=theEl.childNodes(0);
			while (theNode.nextSibling) {
				if (theNode.tagName===theEl.tagName && theNode.className===theEl.className) {
					wd_FillStylesByParent(theNode);
					if (theNode.style.cssText===theEl.style.cssText && theNode.className===theEl.className) {
						theNode.removeNode(false);
					}
				}
				if (theNode.nextSibling) theNode=theNode.nextSibling;
			}
		}
	}
//alert("wd_ValidateSpanAdjacents 2:\n"+wd_NodeValEx(theEl));
	if (theEl.childNodes && theEl.childNodes.length) {
		// remove empty spans
		var theNextNode=theEl.childNodes(0);
		while (theNextNode) {
			if (wd_IsEl(theNextNode, 'SPAN')) {
				wd_ClearStylesByParent(theNextNode);
				if (!theNextNode.className.length && !theNextNode.style.cssText.length) {
					theTmpNode=theNextNode.nextSibling;
					theNextNode.removeNode(false);
					theNextNode=theTmpNode;
				} else {
					theNextNode=theNextNode.nextSibling;
				}
			} else {
				theNextNode=theNextNode.nextSibling;
			}
		}
	}
//alert("wd_ValidateSpanAdjacents 3:\n"+wd_NodeValEx(theEl));
	if (theEl.childNodes && theEl.childNodes.length) {
		// join serial tags
		var theNode=theEl.childNodes(0);
		while (theNode.nextSibling) {
			var theNextNode=theNode.nextSibling;
			if (wd_IsEl(theNode, 'SPAN') && theNode.tagName===theNextNode.tagName && theNode.className===theNextNode.className && theNode.style.cssText===theNextNode.style.cssText) {
				var sHtml=theNode.innerHTML+theNextNode.innerHTML;
				theNextNode.removeNode(true);
				theNode.innerHTML=sHtml;
			} else {
				theNode=theNextNode;
			}
		}
	}
//alert("wd_ValidateSpanAdjacents 4:\n"+wd_NodeValEx(theEl));
	if (wd_IsEl(theEl, 'SPAN')) {
		// remove self
		var theParentEl=theEl.parentNode;
		var bSelfRemoved=false;
		if (!bSelfRemoved) {
			// remove self by same parent
			wd_FillStylesByParent(theEl);
			if (wd_IsEl(theParentEl) && theParentEl.style.cssText===theEl.style.cssText && theParentEl.className===theEl.className) {
				theEl.removeNode(false);
				bSelfRemoved=true;
			}
		}
//alert("wd_ValidateSpanAdjacents 41:\n"+wd_NodeValEx(theEl));
		if (!bSelfRemoved) {
			// remove self by empty span
			wd_ClearStylesByParent(theEl);
			if (!theEl.className.length && !theEl.style.cssText.length) {
				theEl.removeNode(false);
				bSelfRemoved=true;
			}
		}
//alert("wd_ValidateSpanAdjacents 42:\n"+wd_NodeValEx(theEl));
		if (!bSelfRemoved) {
			// join self with same siblings
			var thePrev=theEl.previousSibling;
			if (wd_IsEl(thePrev, 'SPAN') && thePrev.className===theEl.className && thePrev.style.cssText===theEl.style.cssText) {
				var sHtml=thePrev.innerHTML+theEl.innerHTML;
				thePrev.removeNode(true);
				theEl.innerHTML=sHtml;
			}
//alert("wd_ValidateSpanAdjacents 421:\n"+wd_NodeValEx(theEl));
			var theNext=theEl.nextSibling;
			if (wd_IsEl(theNext, 'SPAN') && theNext.className===theEl.className && theNext.style.cssText===theEl.style.cssText) {
				var sHtml=theEl.innerHTML+theNext.innerHTML;
				theNext.removeNode(true);
				theEl.innerHTML=sHtml;
			}
		}
	}
//alert("wd_ValidateSpanAdjacents 5:\n"+wd_NodeValEx(theEl));
}
// ^=== :formatting validating ================================================^