function checkFields() {
    this.fields = new Array('name','mail','subj','msg');
    this.succ = 0;    
    this.res = 0;
    this.not_empty = 0;
}


checkFields.prototype = {

    checkAllFields : function() {
        var not_empty = true;
        
        for(i=0;i<this.fields.length;i++) {
            var el = document.getElementById(this.fields[i]);
            if(el.value.length == 0) {
                not_empty = false;
                break;
            }
        }
        var div = document.getElementById('result');
        if(div) {
            if(!not_empty) {
                div.style.color = '#ff0000';
            } else {
                div.style.color = '#887d67';
            }
        } else {
            div.style.color = '#887d67';
        }
        
        var capt = document.getElementById('captcha');
        if(capt) {
            this.isCorrect(capt.value);
        }
        
        this.not_empty = not_empty;
        /*
        if(not_empty && (this.succ == 1)) {            
            var frm = document.getElementById('frm_feedback');
            if(frm) {                
                frm.submit();
            }
        }
        */
    },
    
    
	isCorrect : function(captcha) {			
        var _this = this;                
        var queryOpts = {
            method:'post',
            asynchronous:true,
            postBody:'captcha=' + captcha,
            onSuccess:_this.successFunction.bind(this)
        }                
        var data = new Ajax.Request('feedback.php?checknum', queryOpts);   		
	},

	successFunction : function(handler)
    {        	    	    	
    	var resp = handler.responseText;
    	this.res = resp;
    	var div = document.getElementById('check');
    	if(div) {
    	   if(resp == 0) {    	                           
                div.style.color = '#ff0000';
                this.succ = 0;
           } else {    	   
                div.style.color = '#887d67';                
                if(this.not_empty) {                
                    var frm = document.getElementById('frm_feedback');
                    if(frm) {                
                        frm.submit();
                    }
                }                                    
           }    	    
    	}    	
    }    
}