

function InsertEntities(str)
{
	str = str.replace(/\"/g, "&quot; ");
	str = str.replace(/</g, "&lt;");
	str = str.replace(/>/g, "&gt; ");
	
	if (navigator.userAgent.indexOf("Mozilla") != -1)
	{
		str = str.replace(/'/g, "&apos;");
		str = str.replace(/&middot;/g, "&#183;");
		str = str.replace(/&Alpha;/g, "&#913;");			
		str = str.replace(/&Beta;/g, "&#914;");			
		str = str.replace(/&Gamma;/g, "&#915;");			
		str = str.replace(/&Delta;/g, "&#916;");			
		str = str.replace(/&Epsilon;/g, "&#917;");			
		str = str.replace(/&Zeta;/g, "&#918;");			
		str = str.replace(/&Eta;/g, "&#919;");		
		str = str.replace(/&Theta;/g, "&#920;");			
		str = str.replace(/&Iota;/g, "&#921;");			
		str = str.replace(/&Kappa;/g, "&#922;");			
		str = str.replace(/&Lambda;/g, "&#923;");			
		str = str.replace(/&Mu;/g, "&#924;");		
		str = str.replace(/&Nu;/g, "&#925;");		
		str = str.replace(/&Xi;/g, "&#926;");		
		str = str.replace(/&Omicron;/g, "&#927;");			
		str = str.replace(/&Pi;/g, "&#928;");		
		str = str.replace(/&Rho;/g, "&#929;");		
		str = str.replace(/&Sigma;/g, "&#931;");			
		str = str.replace(/&Tau;/g, "&#932;");		
		str = str.replace(/&Upsilon;/g, "&#933;");			
		str = str.replace(/&Phi;/g, "&#934;");		
		str = str.replace(/&Chi;/g, "&#935;");		
		str = str.replace(/&Psi;/g, "&#936;");		
		str = str.replace(/&Omega;/g, "&#937;");			
		str = str.replace(/&alpha;/g, "&#945;");			
		str = str.replace(/&beta;/g, "&#946;");			
		str = str.replace(/&gamma;/g, "&#947;");			
		str = str.replace(/&delta;/g, "&#948;");			
		str = str.replace(/&epsilon;/g, "&#949;");			
		str = str.replace(/&zeta;/g, "&#950;");			
		str = str.replace(/&eta;/g, "&#951;");		
		str = str.replace(/&theta;/g, "&#952;");			
		str = str.replace(/&iota;/g, "&#953;");			
		str = str.replace(/&kappa;/g, "&#954;");			
		str = str.replace(/&lambda;/g, "&#955;");			
		str = str.replace(/&mu;/g, "&#956;");			
		str = str.replace(/&nu;/g, "&#957;");		
		str = str.replace(/&xi;/g, "&#958;");		
		str = str.replace(/&omicron;/g, "&#959;");			
		str = str.replace(/&pi;/g, "&#960;");		
		str = str.replace(/&rho;/g, "&#961;");		
		str = str.replace(/&sigmaf;/g, "&#962;");			
		str = str.replace(/&sigma;/g, "&#963;");			
		str = str.replace(/&tau;/g, "&#964;");		
		str = str.replace(/&upsilon;/g, "&#965;");			
		str = str.replace(/&phi;/g, "&#966;");		
		str = str.replace(/&chi;/g, "&#967;");		
		str = str.replace(/&psi;/g, "&#968;");		
		str = str.replace(/&omega;/g, "&#969;");			
		str = str.replace(/&thetasym;/g, "&#977;");				
		str = str.replace(/&upsih;/g, "&#978;");			
		str = str.replace(/&piv;/g, "&#982;");			
	}
	return str;
}


function DeletePopup()
{
	return window.confirm('Are you sure you want to delete this item?');

}

	function expand(src, id, str, clickedRow, mathml_type) 
	{ 
		var i = id.substring(3); 
		var source_name = src.substring(0, src.length - i.length); 
		//s = new String(str); 
		//s = s.replace(/</g, "&lt;"); 
		//s = s.replace(/>/g, "&gt; "); 
		//s = s.replace(/,/g, ", "); 
		//s = s.replace(/\+/g, " + "); 
		//s = s.replace(/\*/g, " * "); 

		str = str.replace(/</g, "&lt;"); 
		str = str.replace(/>/g, "&gt;"); 
		str = str.replace(/&gt;/g, "&gt; "); 
		str = str.replace(/,/g, ", "); 
		str = str.replace(/\+/g, " + "); 
		str = str.replace(/\*/g, " * "); 
		
		if (document.getElementById(id + "_hidden").value == (src + mathml_type)) 
		{ 
			document.getElementById(id).innerHTML = ''; 
			document.getElementById(id).className = 'NoExpression';
			document.getElementById(src).className = 'unSelected';
			document.getElementById(id + "_hidden").value = ''; 
		} 
		else if (mathml_type == "10" && document.getElementById(id + "_hidden").value.toLowerCase().indexOf('mathml') >= 0)
		{
			document.getElementById(id).innerHTML = ''; 
			document.getElementById(id).className = 'NoExpression';
			document.getElementById(src).className = 'unSelected';
			document.getElementById(id + "_hidden").value = ''; 
		}
		else 
		{ 
			var row = document.getElementById(clickedRow); 
			cells=row.getElementsByTagName('td'); 
			for (var j=0; j<cells.length; j++) 
			{ 
				if (cells[j].className == 'selectedExpression')  
					cells[j].className = 'unSelected'; 
			} 
			if (source_name == 'image')
 			{ 
	 			if (!isIE && supportsMathML) // are we ff?
	 			{
		 			// FF must be xml in order to render the mathml.
		 			// because of this we can't have '&' in the url of the image.  Change them to '&amp;'
					str = str.replace(/&/g, "&amp;"); 
	 			}
				document.getElementById(id).innerHTML = '<img alt="image" src="' + str + '"/>'; 
			} 
			else if (src.toLowerCase().indexOf('mathml') >= 0)
			{
				
				var rendered = "";
				if (supportsMathML)
				{
					rendered = ' | <a href="javascript:void 0;" onclick=\'expand("' + src + '", "' + id + '", rendered_mathml' + i + ', "' + clickedRow + '", "3");\'>Rendered</a> ';
				}

				var html = '<div class="mathLink">';
				if (mathml_type == "0" || mathml_type == "10")
				{
					html += 'Content | ';
					html += '<a href="javascript:void 0;" onclick=\'expand("' + src + '", "' + id + '", presentation_mathml' + i + ', "' + clickedRow + '", "1");\'>Presentation</a> | ';
					html += '<a href="javascript:void 0;" onclick=\'expand("' + src + '", "' + id + '", mathml' + i + ', "' + clickedRow + '", "2");\'>Both</a> ';
					html += rendered + "</div>";
				}
				else if (mathml_type == "1")
				{
					html += '<a href="javascript:void 0;" onclick=\'expand("' + src + '", "' + id + '", content_mathml' + i + ', "' + clickedRow + '", "0");\'>Content</a> | ';
					html += 'Presentation | ';					
					html += '<a href="javascript:void 0;" onclick=\'expand("' + src + '", "' + id + '", mathml' + i + ', "' + clickedRow + '", "2");\'>Both</a> ';
					html += rendered + "</div>";
				}
				else if (mathml_type == "2")
				{
					html += '<a href="javascript:void 0;" onclick=\'expand("' + src + '", "' + id + '", content_mathml' + i + ', "' + clickedRow + '", "0");\'>Content</a> | ';
					html += '<a href="javascript:void 0;" onclick=\'expand("' + src + '", "' + id + '", presentation_mathml' + i + ', "' + clickedRow + '", "1");\'>Presentation</a> | ';
					html += 'Both ';					
					html += rendered + "</div>";
				}
				else if (mathml_type == "3")
				{
					html += '<a href="javascript:void 0;" onclick=\'expand("' + src + '", "' + id + '", content_mathml' + i + ', "' + clickedRow + '", "0");\'>Content</a> | ';
					html += '<a href="javascript:void 0;" onclick=\'expand("' + src + '", "' + id + '", presentation_mathml' + i + ', "' + clickedRow + '", "1");\'>Presentation</a> | ';
					html += '<a href="javascript:void 0;" onclick=\'expand("' + src + '", "' + id + '", mathml' + i + ', "' + clickedRow + '", "2");\'>Both</a> ';
					html += ' | Rendered</div> ';					
					
					if (!isIE)
					{
						//str = str.replace(/&lt;/g, "<"); 
						//str = str.replace(/&gt;/g, ">"); 
						//str = str.replace(/<math>/g, "<math xmlns='http://www.w3.org/1998/Math/MathML'>");
						str = '<iframe frameborder="0" width="700" src="/ff_mathml/' + i + '.xhtml"></iframe>';
					}
					else
					{
						if (ieVersion() < 6.0)
						{
							str = "Please <a href='http://www.microsoft.com/windows/ie'>upgrade your version of IE</a> to view rendered MathML";
						}
						else if (!isMPInstalled())
						{
							str = '<a class="footer" href="http://www.dessci.com/en/products/mathplayer/download.htm">Download MathPlayer</a> to view rendered mathML.'
						}
						else
						{
							//str = str.replace(/&lt;/g, "<"); 
							//str = str.replace(/&gt;/g, ">"); 
							//str = str.replace(/<\//g, "</m:");
							//str = str.replace(/<([^\/])/g, "<m:$1");
							str = '<iframe frameborder="0" width="700" src="/ie_mathml/' + i + '.html"></iframe>';
						}
					}
				}
				document.getElementById(id).innerHTML = html + str; 
			}
			else 
			{ 
				document.getElementById(id).innerHTML = str; 
			} 
			document.getElementById(id + "_hidden").value = (src + mathml_type); 
			document.getElementById(src).className = 'selectedExpression'; 
			document.getElementById(id).className = 'code'; 
		} 
	} 


		
	function isMPInstalled()
	{
		try 
		{
			var oMP = new ActiveXObject('MathPlayer.Factory.1');
			return true;
		}
		catch(e) 
		{
			return false;
		}
	}
	
	// returns version of Internet Explorer
	function ieVersion()
	{
		var ieVer = 0;
		var start = navigator.appVersion.indexOf('MSIE '); 
		if (start != -1) 
		{ 
			ieVer = parseFloat(navigator.appVersion.substring(start+5)); 
		}
		return ieVer;
	}

