function setupAjaxForm(form_id, form_validations){
    var form = '#' + form_id;
    var form_message = form + '-message';
 
    // en/disable submit button
    var disableSubmit = function(val){
        $(form + ' input[type=submit]').attr('disabled', val);
    };
 
    // setup loading message
    $(form).ajaxSend(function(){
        $(form_message).removeClass().addClass('loading').html('Loading...').fadeIn();
    });
 
    // setup jQuery Plugin 'ajaxForm'
    var options = {
        dataType:  'json',
        url:  'data/transferir.php',
        beforeSubmit: function(){
            // run form validations if they exist
            if(typeof form_validations == "function" && !form_validations()) {
                // this will prevent the form from being subitted
                return false;
            }
            disableSubmit(true);
        },
        success: function(json){
            $(form_message).hide();
            $(form_message).removeClass();//.addClass(json.type).html(json.message).fadeIn('slow');
            disableSubmit(false);
            if(json.type == 'success') {
                $(form).clearForm();
				interstitialBox.showcontainer(json.message);
				animatedcollapse.hide('fcourriel');
            }
            else {
             	$(form_message).removeClass().addClass(json.type).html(json.message).fadeIn('slow');
            }
        }
    };
    $(form).ajaxForm(options);
}

function isAlphabet(elem){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		return false;
		elem.focus();
	}
}

function emailValidator(elem){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		return false;
		elem.focus();
	}
}

function destValidator(elem){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	var destination = elem.value.split(",");
	for(i=0; i<destination.length; i++){
		if(!destination[i].match(emailExp)){
			return false;
			break;
			elem.focus();
		}
	}
	return true;
}

$(document).ready(function() {
    new setupAjaxForm('tform'/*, function(){
		var nom = document.getElementById('tnom');
		var courriel = document.getElementById('tcourriel');
		var email = document.getElementById('tmail');
		var alphaExp = /^[a-zA-Z]+$/;
		var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
		if(isAlphabet(nom)){
			if(emailValidator(email)){
				if(destValidator(courriel)){
					return true;
				}
			}
		}
		return false;
    }*/);
});

