// JavaScript Document

function actionMap(action){
    if (action == "Open"){
        $('#divTransparent').show();
        $('#divImgMap').show();
    } else {
        $('#divTransparent').hide();
        $('#divImgMap').hide();
    }
}

function imgCustomersOver(id){
    $("#" + id).addClass("divClientes_B");
    $("#" + id).removeClass("divClientes_A");
}

function imgCustomersOut(id){
    $("#" + id).addClass("divClientes_A");
    $("#" + id).removeClass("divClientes_B");
}

function showClients(id){

    $.ajax({
        type: "GET",
        url: "showClients.php",
        data: "id=" + id,
        success: function(xml){
            $('#divLogo').empty();
            $("#divLogo").append($('title', $(xml)).text());
            $("#divTrabajos").empty();
            $("#divTrabajos").append($('description', $(xml)).text());
        }
    });
}

function sendEmail(id) {
  
    $('#submit').attr('disabled','disabled');
    $('#submit').val('Enviando...');
    $('#tableForm').hide();
    $('#divEnviando').show();

    $('#' + id).ajaxSubmit({

        success:function(xml){
            if (manageAjaxResponse(xml) > -1) {
                $('#divEnviando').hide();
                $('#divEnviado').show();
            } else {
                $('#tableForm').show();
                $('#divEnviando').hide();
                $('#submit').attr('disabled','');
                $('#submit').val('Enviar Consulta');
            }
        }
    })
}


function manageAjaxResponse(resp) {
    var response = $('response', $(resp)).eq(0);

    if (response != null) {
        code = $('code', $(response)).text();
        msg = $('msg', $(response)).text();

        if ((code < 0)) {
            formReturnClass();
            //showError(msg)
            $('error', $(response)).each(function(){

                var campo = $(this).attr('field');

                $("#" + campo).addClass("formErrors");
            })

        //$('.errores').show();
        }
    } else {
        alert("La respuesta del servidor no es valida.");
    }

    return code;
}

function formReturnClass(){

    $("input").removeClass();
    $("select").removeClass();
    $("textarea").removeClass();


}

function formReset(){

    formReturnClass()

    //document.getElementById(formName).reset();


}

function errorCampo(id){

    idValue = "#"+id;

    alert(idValue);

    $(idValue).addClass("formErrors");
}

function showGallery(div){
 $("#" + div).dialog({
            bgiframe: false,
            height: 600,
            width: 800,
            modal: true,
            resizable: false,
            draggable: false
        });
}