
String.prototype.endsWith = function(c) {
	if (c == this.substr((this.length - c.length), this.length - 1)) {
	    return true;
	} else {
	    return false;
	}
}

function checkForm(formObject) {
	checkboxoptionsValue = "";
	checkboxoptionsName = "";

	for (elementCounter=0; elementCounter < formObject.elements.length; elementCounter++) {
		currentElement = formObject.elements[elementCounter];

		if (false) {
		} else if (currentElement.name.endsWith("|checkboxoptions")) {
			checkboxoptionsName = currentElement.name.substr(0, currentElement.name.length - 16); //"|checkboxoptions".length

			//alert("checke: " + checkboxoptionsName);
			if (currentElement.checked) {
				if (checkboxoptionsValue.length > 0) {
					checkboxoptionsValue += ";";
				}

				checkboxoptionsValue += currentElement.value;

				//alert("setze: " + currentElement.value);
			}
		} else if (checkboxoptionsName.length > 0) {
			formObject.elements[elementCounter].name = checkboxoptionsName;
			formObject.elements[elementCounter].value = checkboxoptionsValue;

			//alert(checkboxoptionsName);
			//alert(checkboxoptionsValue);

			checkboxoptionsName = "";
			checkboxoptionsValue = "";
		} else if (currentElement.name.endsWith("[]")) {
			newValue = "";
			newName = "";

			for (optionsCounter = 0; optionsCounter < currentElement.options.length; optionsCounter++) with (currentElement.options[optionsCounter]) {
				if (selected) {
					if (newValue.length > 0) {
						newValue += ";";
					}

					newValue += value;
				}
			}

			newName = currentElement.name.substr(0, currentElement.name.length - 2);

			formObject.elements[elementCounter].options.length = 0;
			formObject.elements[elementCounter+1].name = newName;
			formObject.elements[elementCounter+1].value = newValue;
		}
	}

}