<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
body {
	font-family: Calibri, Arial, sans-serif;
	font-size: small;
	background-color: #E7D19A;
	text-align: center;
}
.content {
	width: 760px;
	margin: 0 auto;
	background-color: white;
	text-align: left;
	border-style: solid;
	border-width: 1px;
	border-color: #D0A760;
}
h1 {
	padding: 18px 7px;
	margin: 0 auto;
	background-color: #900;
	color: white;
	font-size: 200%;
	font-weight: bold;
}
p {
	margin: 7px;
}
button {
	margin: 0px 7px 7px;
}
#badge-state {
	font-size: 36px;
	text-align: center;
	padding: 10px 0;
	margin: 0;
	color: white;
}
#badge-state { display: none; }
</style>
<title>Flash proxy options</title>
</head>
<body>
<div class="content">
<div>
<h1>Flash proxy options</h1>
<p>
This page enables you to use your web browser as a proxy to help
censored Internet users. When you click yes, your browser will act as a
censorship circumvention proxy as long as you are viewing a page with
the flash proxy badge.
</p>
<p>
<a href="http://crypto.stanford.edu/flashproxy/">For more information on this system click here</a>.
</p>
<p>Do you want your browser to act as a proxy?</p>
</div>
<noscript>
<p>
While JavaScript is disabled, your computer will not be a proxy. Enable
JavaScript to change your options.
</p>
</noscript>
<div id="buttons" style="display: none;">
  <button onclick="set_allowed()">Yes</button>
  <button onclick="set_disallowed()">No</button>
</div>
<div id="badge-state">
  <p id="inactive">Proxy disabled</p>
  <p id="active">Proxy enabled</p>
</div>
<div id="cookies_disabled" style="display: none;">
<p>
It seems your browser has cookies disabled. You will need to enable them
in order to set flash proxy settings.
</p>
</div>
</div>
<script type="text/javascript">

var COOKIE_NAME = "flashproxy-allow";
/* max-age is not supported in IE. */
var COOKIE_LIFETIME = "Thu, 01 Jan 2038 00:00:00 GMT";

function set_cookie_allowed() {
    document.cookie = COOKIE_NAME + "=1 ;path=/ ;expires=" + COOKIE_LIFETIME;
}

function set_cookie_disallowed() {
    document.cookie = COOKIE_NAME + "=0 ;path=/ ;expires=" + COOKIE_LIFETIME;
}

function set_allowed() {
    set_cookie_allowed();
    refresh();
}

function set_disallowed() {
    set_cookie_disallowed();
    refresh();
}

function parse_cookie_string(cookies) {
    var strings;
    var result;

    result = {};
    if (cookies)
        strings = cookies.split(";");
    else
        strings = [];
    for (var i = 0; i < strings.length; i++) {
        var string = strings[i];
        var j, name, value;

        j = string.indexOf("=");
        if (j === -1) {
            return null;
        }
        name = decodeURIComponent(string.substr(0, j).trim());
        value = decodeURIComponent(string.substr(j + 1).trim());

        if (!(name in result))
             result[name] = value;
    }

    return result;
}

/* Returns the value of the cookie, or undefined
   if the cookie is not present. */
function read_cookie() {
    var cookies = parse_cookie_string(document.cookie);
    return cookies[COOKIE_NAME];
}

/* Updates the text telling the user what his current setting is.*/
function refresh() {
    var value = read_cookie();

    if (value === undefined || value === "1") {
        document.getElementById("active").style.display = "block";
        document.getElementById("inactive").style.display = "none";
        document.getElementById("badge-state").style.backgroundColor = "darkgreen";
    } else {
        document.getElementById("inactive").style.display = "block";
        document.getElementById("active").style.display = "none";
        document.getElementById("badge-state").style.backgroundColor = "red";
    }
}

window.onload = function() {
    if (navigator.cookieEnabled) {
        document.getElementById("buttons").style.display = "block";
        document.getElementById("badge-state").style.display = "block";
        refresh();
    } else {
        document.getElementById("cookies_disabled").style.display = "block";
    }
}
</script>
</body>
</html>
