/**
 * @author SoyDigital.com digital@soydigital.com
 *
 * @version 1.0
 *
 * @copyleft 2008
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/**
 * Método para enviar los parametros usando la AjaxLib.js
 * @param {string} url
 * @param {string} param
 */
function validate_AJAX(url, param){
    $Ajax(url, {
        metodo: $metodo.POST,
        parametros: param,
        onfinish: validate,
        tipoRespuesta: $tipo.JSON,
        /*onerror: function(e, id){
            alert($H(e).inspect())
        }*/
    });
}

/**
 * Método para mostrar los errores en pantalla
 * @param {Object} thename
 */
function showEMsg(thename){
    $(thename + "Icono").className = "iconovalidar iconoerroneo";
}

/**
 * Metodo para limpiar los errores de pantalla
 * @param {Object} thename
 */
function clearEMsg(thename){
    $(thename + "Icono").className = "iconovalidar iconovalido";
}

/**
 * Metodo para verificar los INPUT
 * @param {String} objID
 * @param {String} objName
 * @param {String} objValue
 */
function verify_input(objID, objName, objValue){
    var attr = $(objID).getAttribute("type");
    var url = "../registro/process_regs.php";
    var param = "verify=1&" + objName + "=" + objValue;
    if (attr == "checkbox") {
        $(objID).checked == true ? $(objID + "Icono").className = "iconovalidar iconovalido" : $(objID + "Icono").className = "iconovalidar iconoerroneo";
    }
    else {
        if (objValue === null || objValue.length === 0 || (/^\s+$/.test(objValue))) {
            showEMsg(objName);
        }
        else {
            validate_AJAX(url, param);
        }
    }
}

/**
 * Método para cambiar
 * @param {Object} respuestas
 */
function validate(respuestas){
    respuestas.each(function(s, index){
        var respuesta = respuestas[index];
        respuesta.valor == 1 ? $(respuesta.clave + "Icono").className = "iconovalidar iconovalido" : $(respuesta.clave + "Icono").className = "iconovalidar iconoerroneo"
    });
}

function verify_input_mb(objID, objName, objValue){
    var serverPage = "../registro/process_mb.php";
    var str = "verify=1&" + objName + "=" + objValue;
    if (objValue === null || objValue.length === 0 || (/^\s+$/.test(objValue))) {
        showEMsg(objName);
    }
    else {
        validate_AJAX(url, param);
    }
}

function verify_input_login(objID, objName, objValue){
    var url = "../clientes/process_login.php";
    var param = "verify=1&" + objName + "=" + objValue;
    if (objValue === null || objValue.length === 0 || (/^\s+$/.test(objValue))) {
        showEMsg(objName);
    }
    else {
        validate_AJAX(url, param);
    }
}

function verify_input_remail(objID, objName, objValue){
    var url = "../registro/process_remail.php";
    var param = "verify=1&" + objName + "=" + objValue;
    if (objValue === null || objValue.length === 0 || (/^\s+$/.test(objValue))) {
        showEMsg(objName);
    }
    else {
        validate_AJAX(url, param);
    }
}
