
var textButton = ["Enviar consulta", "Procesando ... enví­o"];
var textAlerts = ["Ha ocurrido un problema inesperado. Intentelo de nuevo."];

var clickSpecific  = function(){


        // return a public interface
        return {

                reloadCaptcha  : function(){
                        document.getElementById('captcha').src = '/library/securimage/securimage_show.php?' + Math.random();
                        document.getElementById('captcha_code').value = '';
                }

        };
}();
function showRequest(responseText, statusText) {
        $('#btnSubmit').disabled = true;
        $('#btnSubmit').val( textButton[1] );
}
function showResponse(responseText, statusText) {
        try{
                var responseArray = $.evalJSON(responseText);
                if ( !responseArray.success ) {
                        var dataError = responseArray.dataError;
                        // Ocurrio un error
                        alert(dataError);
                        clickSpecific.reloadCaptcha();
                }else{
                        document.forms.frmEnvio.action = "confirmacionconsulta.php";
                        document.forms.frmEnvio.submit();
                }
        }catch(e){
                alert(textAlerts[0]);
                clickSpecific.reloadCaptcha();
        }

        $('#btnSubmit').val( textButton[0] );
        $('#btnSubmit').disabled = false;
        return true;
}

// prepare the form when the DOM is ready
$(document).ready(function() {
        var options = {
                success:       showResponse,  // post-submit callback
                beforeSubmit:  showRequest,   // pre-submit callback
                // other available options:
                url:       'sendconsulta.php'         // override for form's 'action' attribute
                // $.ajax options can be used here too, for example:
                //timeout:   3000
        };

        // bind to the form's submit event
        $('#frmEnvio').submit(function() {
        	
//        		alert('Temporalmente deshabilitado, disculpe las molestias.');
//        		return false;

                // inside event callbacks 'this' is the DOM element so we first
                // wrap it in a jQuery object and then invoke ajaxSubmit
                $(this).ajaxSubmit(options);

                // !!! Important !!!
                // always return false to prevent standard browser submit and page navigation
                return false;
        });
});
