﻿



var Fotos = new Array();
var Leyendas = new Array();
var Tamano = 0;
var Indice = 0;

function mensaje() {
    alert('Aaaa');
}



function CargarFotos(a, b) {
    Fotos = a;
    Leyendas = b;
    Tamano = Fotos.length;
    llenarCombo(Tamano);
    Indice = aleatorio(0, Tamano - 1);
    seleccionarCombo(Indice);
    pedirDatos('../Pages/ImgFotos.aspx?linkFoto=' + Fotos[Indice] + '&ly=' + Leyendas[Indice], 'idFotoR');
}

function aleatorio(inferior, superior) {
    numPosibilidades = superior - inferior
    aleat = Math.random() * numPosibilidades
    aleat = Math.round(aleat)
    return parseInt(inferior) + aleat
}

function imSiguiente() {
    Indice=Indice+1;
    if (Indice == Tamano) { Indice = 0; }
    seleccionarCombo(Indice);
    pedirDatos('../Pages/ImgFotos.aspx?linkFoto=' + Fotos[Indice] + '&ly=' + Leyendas[Indice], 'idFotoR');
}

function imAnterior() {
    Indice = Indice - 1;
    if (Indice == -1) { Indice = Tamano - 1; }
    seleccionarCombo(Indice);
    pedirDatos('../Pages/ImgFotos.aspx?linkFoto=' + Fotos[Indice] + '&ly=' + Leyendas[Indice], 'idFotoR');
}

function seleccionarCombo(i) {
    var combo = document.getElementById('combo');
    combo[i].selected = true;
}

function cambioSeleccion() {

    var combo = document.getElementById('combo');
        var cantidad = combo.length;
        for (i = 0; i < cantidad; i++) {
            if (combo[i].selected) {
                pedirDatos('../Pages/ImgFotos.aspx?linkFoto=' + Fotos[i] + '&ly=' + Leyendas[i], 'idFotoR');
                Indice = i;
            }
        }
}

function limpiarCombo(idSelect) {
    var select = document.getElementById(idSelect);
    while (select.length > 0) {
        select.remove(0);
    }
}

function llenarCombo(num) {

    limpiarCombo('combo');
    for (i = 0; i < num; i++) {
        var j = i + 1;
        var elOptNew = document.createElement('option');
        elOptNew.text = 'Foto ' + j + '/' + num;
        elOptNew.value = i;
        var elSel = document.getElementById('combo');
        try {
            elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
        }
        catch (ex) {
            elSel.add(elOptNew); // IE only
        }
    }
}



function nuevoAjax() {
    /* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
    lo que se puede copiar tal como esta aqui */
    var xmlhttp = false;
    try {
        // Creacion del objeto AJAX para navegadores no IE
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            // Creacion del objeto AJAX para IE
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (E) { xmlhttp = false; }
    }
    if (!xmlhttp && typeof XMLHttpRequest != "undefined") { xmlhttp = new XMLHttpRequest(); }

    return xmlhttp;
}


function pedirDatos(fuenteDatos, divID) {

    //	alert('entrada a pedirdatos')
    XMLHttpRequestObject = nuevoAjax();
    if (XMLHttpRequestObject) {
        var obj = document.getElementById(divID);
        XMLHttpRequestObject.open("GET", fuenteDatos);
        XMLHttpRequestObject.onreadystatechange = function() {
            if (XMLHttpRequestObject.readyState == 1) {

                obj.innerHTML = '<div class="CajaFotoCargando"><img src="../Images/loading.gif" width="32" height="32" /><br />Actualizando...</div>';

            }
            if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {

                obj.innerHTML = XMLHttpRequestObject.responseText;

           }
        }
        XMLHttpRequestObject.send(null);
    }
}