// JavaScript Document

                        // the function confirms if the entry into the field is correct or
                        // not, entry into 'id' field of the form, 're' regular expression
                        // for the particular field
function FormControl(id,re) {

                       // decides the variable, the color of the field which is filled
                       // faulty
    var incorrect = '#ff3333';

                        //decides the variable, the color of the field which is filled
                        // correctly
    var correct = 'ffffff'

                        // decides the variable, where the particular fault in the form
                        // is marked
    var Fault;

                        //if the field is empty and it does not equal 're', than it sets
                        // Fault to true
    if (document.getElementById(id).value=="" && !re){
        Fault = true;
    }
    else if (window.RegExp && re) {
        var reg = new RegExp(re);

                        // if regular expression does not equal with the field entry
        if (!reg.test(document.getElementById(id).value)) {

                        // sets Fault as true
            Fault = true;
        }
    }

                        // if there is a fault in the entry
    if (Fault){

                        // sets cursor to faulty field
        document.getElementById(id).focus();
        document.getElementById(id).select();

                        // sets colour background of faulty field as red
        document.getElementById(id).style.backgroundColor = incorrect;

                        // if the variable Fault is true, value 1 belongs to the variable
        Fault = parseInt(1);
        return Fault;
    }
    else {

                        // Fault == 0
        Fault = parseInt(0);

                        // sets the colour of the correct field as green
        document.getElementById(id).style.backgroundColor = correct;
        return Fault;
    }
}

                        // checks all the fields concerned and sets the color
function form_clear(Items,State) {

                        //of the background as white
    for(var i = 0; i < Items.lenght; i++) {
        document.getElementById(Items[i]).style.backgroundColor = State;
    }
}

function trueFalse(Fault) {
    if(Fault) {

                        // if Fault is true, the trueFalse function returns the false ond
                        // form in not submitted
        return false;
    }
    else {

                        // if Fault equals zero, trueFalse function returns true and the
                        // form is submitted
        return true;
    }
}

                        // checks the form if it is filled in correctly
function CheckForm(form) {

                       // the array, which contains all the 'id' of the fields to be
                       // checked
    var Items = new Array('email');

                        // calling function, which sets all the fields to be checked to
                        // white background
    form_clear(Items, 'white');

                        // initialize Fault variable, which completes the information
                        // about the faults
    var Fault = 0;

                        // each row checks one item of the form with defined regexp and
                        // adds the fault (if applicable)
    Fault += FormControl('email',       '^([a-zA-Z][a-zA-Z0-9_\\.\\-%+]*[a-zA-Z0-9]){1,64}@([a-zA-Z0-9][a-zA-Z0-9_\\.\\-%+]*[a-zA-Z0-9]){1,252}[\.]([a-zA-Z]{2}|com|org|net|gov|biz|info|name|aero|biz|info|jobs|museum)$');


                        //calls function which decides if the function is sent or not
    return trueFalse(Fault);
}
