var downloadUrl = "../root/servlet/method/com.serverside.fish.mail.Interface.download";

function download(file) {
    if (licenseAccepted()) {
        var msg = AJAX.get("../root/servlet/method/com.serverside.fish.mail.Interface.termsAccepted");
        document.location.href = downloadUrl + "?file=mail/" + file; 
    } else alert("In order to continue you have to accept the mailFISH license defined in our terms and conditions.");
}

function upgrade() {
	var email = document.getElementById("mail.email").value.trim();
	var select = document.getElementById("mail.product");
    var product = select.options[select.selectedIndex].value;
	if (!Validation.isEmail(email)) 
		alert("Please provide a valid E-Mail address.");
	else if (!termsAccepted())
		alert("In order to continue you have to accept our terms & conditions.");
	else {
		var msg = AJAX.get("../root/servlet/method/com.serverside.fish.mail.Interface.upgrade?product=" + product + "&email=" + escape(email));
		var ex = msg.split(" ");
		if (ex.length == 2 && ex[0] == "OK" && ex[1]) {
            document.location.href = ex[1];
		} else alert(msg);
	}
}

function termsAccepted() {
	var cb = document.getElementById("mail.terms");
	return cb.checked;
}

function licenseAccepted() {
    var cb = document.getElementById("mail.license");
    return cb.checked;
}

function toggleableScreenshot(id, url) {
    document.write("<a class=\"simple\" href=\"javascript:toggle('screenshot." + id + "')\"><img src=\"img/screen.png\" /></a>");
    document.write("<div id=\"screenshot." + id + "\" style=\"display:none;\"><img class=\"screenshot\" src=\"" + url + "\" /></div>");
}

function toggle(id) {
    var el = document.getElementById(id);
    if (el.style.display == "block") el.style.display = "none";
    else el.style.display = "block";
}

function boxedImage(url) {
    document.write("<table style=\"width:100%;height:110px;margin-top:10px;margin-bottom:10px;\"><tr><td style=\"background-color:#ffffff;border:1px solid #888888;text-align:center;padding-top:8px;\">");
    document.write("<img class=\"screenshot\" src=\"" + url + "\"/>");
    document.write("</td></tr></table>");
}

function init() {
}

EventHandler.add("window.onload", init);
