function prepareForFlash()
{		
	var html = EditableFlashContent;	
	
	// convert: <h1><a href="">$2</a></h1>
	// to: @item@ 
	//			@header@ $2 @/header@ 
	//			@link@ $1 @/link@
	var xml = html.replace(/<[hH]1><[aA].*?href="([^"]*)".*?>([^<]*)<\/[aA]><\/[hH]1>/gi, "@item@@header@$2@/header@@link@$1@/link@");
	
	// convert: <p><img src="$1"></p>
	// to:		@img@ $1 @/img@ 
	//		@/item@
	xml = xml.replace(/<[pP]><[imgIMG].*?src="([^"]*)".*?><\/[pP]>/gi, "@img@$1@/img@@/item@");
	
	// convert: <p>$1</p>
	// to: @text@ $1 @/text@
	xml = xml.replace(/<[pP]>([^<]*?)<\/[pP]>/gi, "@text@$1@/text@");

	// Recreate tags
	xml = xml.replace(/@(\/?(header|link|img|text|item))@/g, "<$1>");
	
	xml = "<items>" + xml + "</items>";
	xml = escape(xml);
	xml = xml.replace(/%250A%250D%250D/g,"");
	xml = xml.replace(/%26nbsp%3B/g, "%20");	
	xml = xml.replace(/%26%23/g , "%2526%2523");
	xml = xml.replace(/%26amp%3B/g , "%2526");
	xml = xml.replace(/%3B/g , "%253B");
	return xml;
}

var img = "";
var a = "";
var text = "";
var heading = "";
var innerxml = "";

function xmlescape(s)
{
	xml = escape(s);
	xml = xml.replace(/%A0/g , " ");
	xml = xml.replace(/%20/g , " ");
	xml = xml.replace(/%/g ,"%25");
	
	return xml;
}

function addPage()
{
	innerxml += "\t<item>\r\n";
	if (img=="") img = " ";
	if (a=="") a = " ";
	if (text=="") text=" ";
	if (heading=="") heading=" ";
	
	if (img!="") innerxml += "\t\t<img>" + escape(img) + "</img>\r\n";
	if (text!="") innerxml += "\t\t<text>" + xmlescape(text) + "</text>\r\n";
	if (heading!="") innerxml += "\t\t<header>" + xmlescape(heading) + "</header>\r\n";
	if (a!="") innerxml+="\t\t<link>" + escape(a) + "</link>\r\n";
	img = "";
	a = "";
	text = "";
	heading = "";
	innerxml += "\t</item>\r\n";
}

function recurse(node,inheadertag)
{
	var n = node;
	var inht = inheadertag;
	
	if (!inheadertag)
	{
		if (n.nodeName=="IMG") 
		{
			if (img!="") addPage();
			img = n.src;
		}
		
		if (n.nodeName=="H1") 
		{
			inht = true;
		}
		
		if (n.nodeName=="P")
		{
			if (text!="" ) text += "\r\r";
		}
		
		if (n.nodeName=="BR")
		{
			text += "\r";
		}
		
		
		if (n.nodeName=="#text")
		{			
			text += n.nodeValue;
		}
	} else
	{
		if (n.nodeName=="A")
		{
			if (a!="") addPage();
			a = n.href;
		}
		if (n.nodeName=="#text")
		{
			if (heading!="") addPage();
			heading = n.nodeValue;
		}
	}
	
	if (n.nodeName=="HR")
	{
		addPage();
		return;
	}
	
	
	//if (n.nodeType==1)
	{
		var idx=0;
		for (idx=0;idx<n.childNodes.length;idx++)
		{
			recurse(n.childNodes[idx],inht);
		}
	}
}

function ConstructEDxml(contentobjectid)
{
	var contentobject = document.getElementById(contentobjectid);
	if (contentobject!=null)
	{
		img = "";
		a = "";
		text = "";
		heading="";
		innerxml = "";
		recurse(contentobject,false);
		if (img!="" || a!="" ||heading!="" ) addPage();
		return "<items>" + innerxml + "</items>";
	}
}