<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="/benchmark/js/jquery.min.js"></script>
<script type="text/javascript" src="/benchmark/js/js.cookie.js"></script>
<title>BenchmarkTest00166</title>
</head>
<body>
<form action="/benchmark/weakrand-00/BenchmarkTest00166"  method="POST" id="FormBenchmarkTest00166">
    <div><label>Please explain your answer:</label></div>
    <br/>
	<div><textarea rows="4" cols="50" id="BenchmarkTest00166Area" name="BenchmarkTest00166Area"></textarea></div>
	<div><label>Any additional note for the reviewer:</label></div>
	<div><input type="text" id="answer" name="answer"></input></div>
    <br/>
    <div><label>An AJAX request will be sent with a header named BenchmarkTest00166 and value:</label> <input type="text" id="BenchmarkTest00166" name="BenchmarkTest00166" value="whatever" class="safe"></input></div>

	<div><input type="button" id="login-btn" value="Login" onclick="submitForm()" /></div>
</form>
<div id="ajax-form-msg1"><pre><code class="prettyprint" id="code"></code></pre></div>
<script>
$('.safe').keypress(function (e) {
  if (e.which == 13) {
    submitForm();
    return false;
  }
});

function submitForm() {
    var formData = $("#FormBenchmarkTest00166").serialize();
    var URL = $("#FormBenchmarkTest00166").attr("action");
    var text = $("#FormBenchmarkTest00166 input[id=BenchmarkTest00166]").val();
    
    var xhr = new XMLHttpRequest();
    xhr.open("POST", URL, true);

    xhr.setRequestHeader('BenchmarkTest00166', text );

    xhr.onreadystatechange = function () {
        if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
            $("#code").html(xhr.responseText);
        }else{
        	$("#code").html("Error " + xhr.status + " ocurred.");
        }
    }
    xhr.send(formData);
}

function escapeRegExp(str) {
    return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}

function replaceAll(str, find, replace) {
  return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}

String.prototype.decodeEscapeSequence = function() {
    var txt = replaceAll(this,";","");
    txt = replaceAll(txt,"&#","\\");
    return txt.replace(/\\x([0-9A-Fa-f]{2})/g, function() {
        return String.fromCharCode(parseInt(arguments[1], 16));
    });
};
</script>
</body>
</html>
