Converted from C# to HTML5