function checkForm(theForm) {    
    var why = "";
    why += checkText(theForm);
    why += checkLink(theForm);
    why += checkTitle(theForm.title.value);
    why += isAccept(theForm.accept.checked);
    if (why != "") {
        why = "Errors list:\n" + why;
        alert(why);
        return false;
    }
    return true;
}
function checkText(theForm) {
    var error = "";
    var text = theForm.text.value;
    if (theForm.imagebox.checked == false) {
        if (text == "") {
            error = "- Text cannot be left blank.\n";
        } else if (text.length > 50) {
            error = "- Text too long: max length is 50.\n";
        } else {
            var illegalChars = /[^a-zA-Z0-9\s_<>,:;\/\|\{\}\\\.£$%&\(\)=\?'\[\]\+\*!"#-]/;
            if (illegalChars.test(text)) {
                error = "- The text contains illegal characters.\n";
            }
        }
    }
    return error;
}
function checkLink(theForm) {
    var error = "";
    var link = theForm.link.value;
    if (link == "") {
        error = "- Website URL cannot be left blank.\n";
    } else if (link.length < 15) {
        error = "- Website URL [" + link + "] is invalid.\n";
    } else if (invalidAddress(link.substr(0, 8))) {
        error = "- Website URL has to start with 'http://' or with 'https://'\n";
    }     
    return error;
}
function invalidAddress(link) {
    var i = 0;
    if (link.charAt(i++) != "h") {
        return true;
    } else if (link.charAt(i++) != "t") {
        return true;
    } else if (link.charAt(i++) != "t") {
        return true;
    } else if (link.charAt(i++) != "p") {
        return true;
    }
    if (link.charAt(i) == "s") {
        i++;
    }
    if (link.charAt(i++) != ":") {
        return true;
    } else if (link.charAt(i++) != "/") {
        return true;
    } else if (link.charAt(i++) != "/") {
        return true;
    } 
    return false;
}
function checkTitle(title) {
    var error = "";
    if (title != "") {
        if (title.length > 100) {
            error = "- Title too long: max length is 100.\n";
        } else {
            var illegalChars = /[^a-zA-Z0-9\s_<>,:;\/\|\{\}\\\.£$%&\(\)=\?'\[\]\+\*!"#-]/;
            if (illegalChars.test(title)) {
                error = "- The title contains illegal characters.\n";
            }
        }
    }
    return error;
}
function isAccept(choice) {
    var error = "";
    if (choice == 0) {
        error = "- You must be accept the Terms of Service.\n";
    }
    return error;
}