function updateType() {
	var type = getRadioValue(document.submitform.type);
	var bulk = (type == "bulk");
	document.getElementById("title.url").innerHTML = (bulk) ? "Your URLs (<b>1 per line</b>):" : "Your URL:";
	document.getElementById("input.url").style.display = (bulk) ? "none" : "";
	if (bulk) document.getElementById("input.url").value = "";
	document.getElementById("input.urls").style.display = (bulk) ? "" : "none";
	if (!bulk) document.getElementById("input.urls").value = "";
	document.getElementById("row.code").style.display = (bulk) ? "" : "none";
}

function updateTo() {
	var to = getRadioValue(document.submitform.to);
	var all = (to == "all");
	document.getElementById("row.engines").style.display = (all) ? "none" : "";
	if (all) checkAllCheckboxes(document.submitform.engines);
	document.getElementById("title.some").innerHTML = (all) ? "only some search engines" : "only some search engines (<a href='#' onclick='selectAllEngines();return false;'>select all</a>, <a href='#' onclick='deselectAllEngines();return false;'>deselect all</a>)";
}

function selectAllEngines() {
	checkAllCheckboxes(document.submitform.engines);
}

function deselectAllEngines() {
	uncheckAllCheckboxes(document.submitform.engines);
}

function execute() {
	var email = document.getElementById("input.email").value.trim();
	var captcha = document.getElementById("input.captcha").value.trim();
	if (!Validation.isEmail(email)) 
		alert("Please provide a valid E-Mail address: " + email);
	else if (captcha.length < 3)
		alert("Please solve the 'Are you human' puzzle by entering the distorted text in the associated text field.");
	else if (!termsAccepted())
		alert("In order to continue you have to accept our terms & conditions.");
	else {
		var w = window.open("", "results", "width=600,height=400,scrollbars=1");
		var url = "submit.x";
		// use of SSL prohibits correct functionality of window.reset() which is called by popup
		// if (ServerSettings.HTTPS_ROOT) url = ServerSettings.HTTPS_ROOT + "/submit/" + url;
		document.submitform.action = url;
		document.submitform.target = "results";
		document.submitform.submit();
	}
}

function onPopup() {
	showCaptcha();
}

function purchaseKey() {
	var email = document.getElementById("input.email").value.trim();
	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.submit.Interface.registerKey?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("input.terms");
	return cb.checked;
}

function showCaptcha() {
	document.getElementById("image.captcha").src = "../root/captcha.x?t=" + new Date().getTime();
	document.getElementById("input.captcha").value = "";
}

function reset() {
	showCaptcha();
	document.getElementById("input.email").value = "";
	document.getElementById("input.url").value = "";
	document.getElementById("input.urls").value = "";
	checkRadioValue(document.submitform.type, "single");
	updateType();
}

function init() {
	if (document.submitform) {
		updateType();
		updateTo();
		showCaptcha();
		document.getElementById("input.url").focus();
	}
}

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