/**
 * IFR utility functions
 */
 
function SI_normalizeWhiteSpace(txt)
{
	var rE = /\s+/gi;
	return txt.replace(rE,' ');
}

function SI_forceRedraw()
{
	// Corrects a margin-bottom sum bug in Mozilla
	var d = document;
	if (d.body && d.body.style)
	{
		d.body.style.height = "1px";
		d.body.style.height = "auto";
	}
}	

/**
 * Finds and replaces the elements with Flash movie
 * 
 *  SI_replaceElement(elem,swf,w,h,afv)
 *  
 * 	elem (string) :
 * 		`div#header` will replace the `div` with the id of header
 * 		`div#primary-content>h1` will replace any `h1` tag whose direct parent is a
 * `div` with an id of `primary-content`
 * 		`h2.replaceme` will replace any `h2` tag with a className of `replaceme`
 * 	swf (string) :
 * 		full path to the swf
 * 	w (int) :
 * 		width
 * 	h (int) :
 * 		height
 * 	afv (string) :
 * 		used to pass additional flashVars to the movie
 * 	 
 *  The new replaced element will be placed in a div 
 *  with a className of `'replaced-'+r.e.tagName`
 */
function SI_replaceElement(elem,elem_t,swf,w,h,afv)
{
	//DEV NOTE: this changed from original SI function to use mootools selectors
	
	var e = $(elem).getElement(elem_t);

	var txt;
	txt = SI_normalizeWhiteSpace(e.innerHTML);
	var c = document.createElement('div');
	c.className = 'replaced-'+e.tagName;

	//@hack flash not printing bug
	//to help the print bug in Firefox and Safari
	e.parentNode.style.position = 'relative';
	e.style.position = 'absolute';
	e.className += ' Print';
	e.parentNode.appendChild(c);
				
	//txt = escape(txt);
	//special cases (add as req'd)
	txt = txt.replace(/ /g,'%20');
	txt = txt.replace(/&amp;/g,'%26');
	txt = txt.replace(/"/g,'%22');
	txt = txt.replace(/&uuml;/g,'%FC');
	if(afv)
		afv = '&'+afv;
	var fv = 'txt='+txt+afv;

	var swfHTML;

	swfHTML  = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+w+'" height="'+h+'">';
	swfHTML += '	<param name="movie" value="'+swf+'" />';
	swfHTML += '	<param name="flashvars" value="'+fv+'" />';
	swfHTML += '	<param name="wmode" value="transparent" />';
	swfHTML += '	<embed src="'+swf+'"';
	swfHTML += 		' wmode="transparent"';		
	swfHTML += 		' flashvars="'+fv+'" width="'+w+'" height="'+h+'" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" />';
	swfHTML += '<'+'/object>';

	c.innerHTML = swfHTML;
	txt='';
}