﻿function MostarFU(max) {

    var aux = window.location.href.split("/");
    var loc = aux[0] + "//" + aux[2] + "/shared/Ajax.aspx";

    var indice = loc.indexOf("?");
    if (indice != -1)
        loc = loc.substr(0, indice);

    $.ajax({
        type: "POST",
        url: loc + "/MostarFU",
        data: "{max: '" + max + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        success: function(msg) {
            if (msg.d != "false") {
                $("#ctl00_uxcph_content_uxf_ficheros_imagen" + max).removeAttr("style");
                var c = max + 1;
                
                $("#ctl00_uxcph_content_uxf_ficheros_uxbt_add").unbind();
                $("#ctl00_uxcph_content_uxf_ficheros_uxbt_add").removeAttr("onclick");
                $("#ctl00_uxcph_content_uxf_ficheros_uxbt_add").bind("click", function(e) { e.preventDefault(); MostarFU(c); return false; });

                var bt_del = document.getElementById("ctl00_uxcph_content_uxf_ficheros_uxbt_del");
                if (bt_del == null) {
                    $("#ctl00_uxcph_content_uxf_ficheros_uxbt_add").before("<input type='submit' class='submit' name='ctl00_uxcph_content_uxf_ficheros_uxbt_del' id='ctl00_uxcph_content_uxf_ficheros_uxbt_del' Value='Eliminar Imagen'>");
                }
                $("#ctl00_uxcph_content_uxf_ficheros_uxbt_del").unbind();
                $("#ctl00_uxcph_content_uxf_ficheros_uxbt_del").bind("click", function(e) { e.preventDefault(); BorrarFU(max); return false; });
            }
          
        }
    });
}



function MostrarHotel() {

    var al = document.getElementById("ctl00_uxcph_content_uxddl_hotel");
    al.value;

    var aux = window.location.href.split("/");
    var loc = aux[0] + "//" + aux[2] + "/shared/Ajax.aspx";

    var indice = loc.indexOf("?");
    if (indice != -1)
        loc = loc.substr(0, indice);

    $.ajax({
        type: "POST",
        url: loc + "/CargarHotel",
        data: "{id: '" + al.value + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        success: function(msg) {
            $(".enlace_hotel").html(msg.d);
            externalLinks();
        }
    });

}


function BorrarFU(max) {

    var aux = window.location.href.split("/");
    var loc = aux[0] + "//" + aux[2] + "/shared/Ajax.aspx";

    var indice = loc.indexOf("?");
    if (indice != -1)
        loc = loc.substr(0, indice);

    $.ajax({
        type: "POST",
        url: loc + "/BorrarFU",
        data: "{max: '" + max + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        success: function(msg) {
            if (msg.d != "false") {
                $("#ctl00_uxcph_content_uxf_ficheros_imagen" + max).attr("style", "display:none");
                var c = max - 1;

                $("#ctl00_uxcph_content_uxf_ficheros_uxbt_add").unbind();
                $("#ctl00_uxcph_content_uxf_ficheros_uxbt_add").bind("click", function(e) { e.preventDefault(); MostarFU(max); return false; });

                $("#ctl00_uxcph_content_uxf_ficheros_uxbt_del").unbind();
                $("#ctl00_uxcph_content_uxf_ficheros_uxbt_del").bind("click", function(e) { e.preventDefault(); BorrarFU(c); return false; });
            }
          
        }
    });

}


function Vota(id) {

    var aux = window.location.href.split("/");
    var loc = aux[0] + "//" + aux[2] + "/shared/Ajax.aspx";

    var indice = loc.indexOf("?");
    if (indice != -1)
        loc = loc.substr(0, indice);

    $.ajax({
        type: "POST",
        url: loc + "/Votar",
        data: "{id: '" + id + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        success: function(msg) {
            var al = document.getElementById("ctl00_uxcph_content_uxlbl_mensaje");

            var txt = (msg.d).split("###");
            $(".votos_h1").html(txt[2]);

            al.innerHTML = txt[1];

            if (txt[0] == 2) {
                $("#ctl00_uxcph_content_mensaje").attr("class", "success");
            }
            else
                $("#ctl00_uxcph_content_mensaje").attr("class", "error");

            $("#ctl00_uxcph_content_mensaje").removeAttr("style");

            $("#votacion").attr("style", "display:none");

            
        }
    });     
}


function VotaListado(id) {

    var aux = window.location.href.split("/");
    var loc = aux[0] + "//" + aux[2] + "/shared/Ajax.aspx";

    var indice = loc.indexOf("?");
    if (indice != -1)
        loc = loc.substr(0, indice);

    $.ajax({
        type: "POST",
        url: loc + "/Votar",
        data: "{id: '" + id + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        success: function(msg) {
            var al = document.getElementById("ctl00_uxcph_content_uxlbl_mensaje");

            var txt = (msg.d).split("###");
            $("#votos" + id).html(txt[2]);
            $("#votosu" + id).html(txt[2]);
            al.innerHTML = txt[1];

            if (txt[0] == 2) {
                $("#ctl00_uxcph_content_mensaje").attr("class", "success");
            }
            else
                $("#ctl00_uxcph_content_mensaje").attr("class", "error");

            $("#ctl00_uxcph_content_mensaje").removeAttr("style");
            $("#votar" + id).attr("style", "display:none");

        }
    });
}


function CargarCombo() {
    
    var al = document.getElementById("ctl00_uxcph_content_uxddl_poblacion");
    al.value;

    var aux = window.location.href.split("/");
    var loc = aux[0] + "//" + aux[2] + "/shared/ajax.aspx";

    var indice = loc.indexOf("?");
    if (indice != -1)
        loc = loc.substr(0, indice);

    $.ajax({
        type: "POST",
        url: loc + "/CargarDDL",
        data: "{id: '" + al.value + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        success: function(msg) {
            $(".p_hoteles").addClass("borrame");
            $(".p_hoteles").before("<p class=\"p_general p_hoteles\">" + msg.d + "</p>");
            $(".borrame").remove();
        }
    });
    
}




function VaciarFicheros() {
    var aux = window.location.href.split("/");
    var loc = aux[0] + "//" + aux[2] + "/shared/Ajax.aspx";

    var indice = loc.indexOf("?");
    if (indice != -1)
        loc = loc.substr(0, indice);

    $.ajax({
        type: "POST",
        url: loc + "/VaciarFicheros",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        success: function(msg) {
            $("#ctl00_uxcph_content_ficheros").removeAttr("style");
            $("#resumen").hide();
            //$("#resumen").after(msg.d);
        }
    });
}

