var FORM_VALIDATION_FIELD_EMPTY = 'You did not enter field ';
var FORM_VALIDATION_SUBMIT_CONFIRM = 'Do you really want to send this message?';

function getCookie(name) {
    if (document.cookie.length > 0) {
        start = document.cookie.indexOf(name + "=");
        if (start != -1) { 
            start = start + name.length + 1; 
            end = document.cookie.indexOf(";", start);
            if (end == -1) end = document.cookie.length
                return unescape(document.cookie.substring(start, end));
        } 
    }
    return "";
}

function setCookie(name, value, seconds) {
    var expiration = new Date((new Date()).getTime() + seconds * 1000);
    document.cookie = name + "=" + escape(value) + ((seconds == null) ? "" : ";expires=" + expiration.toGMTString());
}

function validateFormField(fieldname, value) {
    with (fieldname) {
        if (document.getElementById(fieldname).value == value) {
            alert(FORM_VALIDATION_FIELD_EMPTY + value);
            return false;
        }
        else {
            return true;
        }
    }
}

function validateForm() { // arguments: fieldname_1, value_1, ... fieldname_n, value_n 
    with (arguments[0]) {
        for (var i = 0; i < (arguments.length - 2); i++) {
            if (i > 0) {
                i++;
            } 
            if (validateFormField(arguments[i + 1], arguments[i + 2]) == false) {
                document.getElementById(arguments[i + 1]).focus();
                return false;    
            }
        }
        return window.confirm(FORM_VALIDATION_SUBMIT_CONFIRM);
    } 
}
