function checkForm(){

    var formname = 'contactform';

    $('contact_hasJs').value = 1;

    var errorDetected = false;
    var alertcontainer = $('contact_alert');
    var errors = new Array();

    if($('contact_first_name').value.length < 2){
        errors.push("First name is required");
    }else if(!checkRule($('contact_first_name'),"alnum|2|A|0|1|1|\\\'-")){
        errors.push("First name is not valid (alphabetic characters only)");
    }
    if($('contact_last_name').value.length < 2){
        errors.push("Last name is required");
    }else if(!checkRule($('contact_last_name'),"alnum|2|A|0|1|1|\\\'-")){
        errors.push("Last name is not valid (alphabetic characters only)");
    }
    if($('contact_email').value.length < 6){
        errors.push("Email is required");
    }else if(!checkRule($('contact_email'),"email|2")){
        errors.push("Email is not valid");
    }
    if($('contact_subject').value.length < 2){
        errors.push("Subject is required");
    }else if(!checkRule($('contact_subject'),"alnum|2|A|1|1|1|\\\'-")){
        errors.push("Subject is not valid (contains bad characters)");
    }
    if($('contact_message').value.length < 2){
        errors.push("Message is required");
    }else if(!checkRule($('contact_message'),"length|8")){
        errors.push("Message is too short");
    }
    if($('contact_securitycode').value.length < 2){
        errors.push("Security code is required");
    }else if(!checkRule($('contact_securitycode'),"alnum|5|A|0|1|1|")){
        errors.push("Security code is not valid");
    }
    if(checkRule($('contact_securitycode'),"alnum|1|A|0|1|1|")){
    new Ajax.Request('/main/utils/securityimagecheck/codeid/' + $('contact_codeid').value + '/value/' + $('contact_securitycode').value,
        {
            method: 'get',
            asynchronous: false,
            onComplete: function(transport){
                var response = transport.responseText;
                if(transport.responseText != 1) errors.push("Security code is not correct");
            },
            onFailure: function(){ errors.push("Security code is not correct");}
        }
    );
    }

    if(errors.length > 0){
        alertcontainer.innerHTML = "Please correct the following fields:<br />";
        for(var i=0; i < errors.length; i++) alertcontainer.innerHTML += '<br />- ' + errors[i];
        alertcontainer.show();
        new Effect.Shake(alertcontainer);
        return false;
    } else return true;
}
