
var alreadySent = false;

function validate(idForm,mode) {

	if(alreadySent) { 
        return false;
    }
    
	$.blockUI({ 
        message: lang('enviando'),
        showOverlay: true, 
        forceIframe: true,
    	css: {
    		width: '350px', 
    		border: 'none', 
    		padding:'10px',
    		size:'12.0pt',
    		backgroundColor:'#900',
    		'-webkit-border-radius': '10px', 
    		'-moz-border-radius': '10px',
            'border-radius': '10px',
    		opacity: .9,
            baseZ: 500,
    		color:'#fff'
    	}
    });

	var data = getIdsInputs(idForm);
    var noValidate = getIdsInputsNoValidate(idForm);
    data = data.split(',');
	var params = parseParams(data) + '&noValidate=' + noValidate + '&mode='+mode+'&root='+ROOT;
	
	$.ajax({
        
        type: "POST",
        url: AJAXPATH+"validate.php",
        data: params,
        
        success: function(msg){
        	
            msg = eval('(' + msg + ')');
            
        	// debugin
        	if(DEBUGIN) {
                if(window.console) {
                    console.log(msg);
                }
            }
            
            $.each(msg.data, function(fieldId, value) {
                highlightField(value.status,fieldId);
            });
        	
        	// MANAJE ERRORS
        	if(msg.errors > 0) {
        	   
        		var mensaje = lang('validate.errors.verify') + ': ' + msg.errors;
                
                $.blockUI({ 
                    message: mensaje.replace(/\n/gi,'<br/>'),
                    showOverlay: true, 
                    forceIframe: true,
                	css: {
                		width: '350px', 
                		border: 'none', 
                		padding:'10px',
                		size:'12.0pt',
                		backgroundColor:'#900',
                		'-webkit-border-radius': '10px', 
                		'-moz-border-radius': '10px',
                        'border-radius': '10px',
                		opacity: .9,
                        baseZ: 500,
                		color:'#fff'
                	}
                });
                
               	window.setTimeout($.unblockUI, 2500);
                
        	}
        	
        	// NO ERRORS
        	else{
                
                $('#'+msg.mode).submit();

        		/*alreadySent = true;
                
        		mensaje = 'Done.';
                
                $.blockUI({ 
                    message: mensaje.replace(/\n/gi,'<br/>'),
                    showOverlay: true, 
                    forceIframe: true,
                	css: {
                		width: '350px', 
                		border: 'none', 
                		padding:'10px',
                		size:'12.0pt',
                		backgroundColor:'#900',
                		'-webkit-border-radius': '10px', 
                		'-moz-border-radius': '10px',
                        'border-radius': '10px',
                		opacity: .9,
                        baseZ: 500,
                		color:'#fff'
                	}
                });
                
               	window.setTimeout($.unblockUI, 2500);*/
                
        	}
        
        }
        
	});
    
}
