function htmlspecialchars(str,typ)
{
	if(typeof str=="undefined") str="";
	if(typeof typ!="number") typ=2;
	typ=Math.max(0,Math.min(3,parseInt(typ)));
	var html=new Array();
	html[38]="&amp;"; html[60]="&lt;"; html[62]="&gt;";
	if(typ==1 || typ==3) html[39]="&#039;";
	if(typ==2 || typ==3) html[34]="&quot;";
	for(var i in html) eval("str=str.replace(/"+String.fromCharCode(i)+"/g,\""+html[i]+"\");");
	return str;
}