﻿// Precarga de imagenes
function PrecargarImagenes(array) {
    if (document.images) {
        if (array) {
            for (var i = 0; i < array.length; i++) {
                var preload_image_object = new Image();
                preload_image_object.src = array[i];
            }
        }
    }
}

function getAbsoluteLeft(obj) {
    // Get an object left position from the upper left viewport corner
    // Tested with relative and nested objects
    o = obj;
    oLeft = o.offsetLeft            // Get left position from the parent object
    while (o.offsetParent != null) {   // Parse the parent hierarchy up to the document element
        oParent = o.offsetParent    // Get parent object reference
        oLeft += oParent.offsetLeft // Add parent left position
        o = oParent
    }
    // Return left postion
    return oLeft
}

function getAbsoluteTop(obj) {
    // Get an object top position from the upper left viewport corner
    // Tested with relative and nested objects
    o = obj;

    oTop = o.offsetTop            // Get top position from the parent object
    while (o.offsetParent != null) { // Parse the parent hierarchy up to the document element
        oParent = o.offsetParent  // Get parent object reference
        oTop += oParent.offsetTop // Add parent top position
        o = oParent
    }
    // Return top position
    return oTop
}

function AjaxRequest(UrlAddress) {
    var i;

    for (i = 0; i < enProcesoN.length && enProcesoN[i] == true; i++);

    if (!httpN[i]) {
        enProcesoN.push(false);
        httpN.push(getHTTPObject());
    }

    if (!enProcesoN[i] && httpN[i]) {
        httpN[i].open("GET", UrlAddress, true);
        httpN[i].onreadystatechange = function() {
            if (httpN[i].readyState == 4) {
                if (httpN[i].status == 200) {
                    if (httpN[i].responseText.indexOf('invalid') == -1) {
                        eval(httpN[i].responseText);
                    }
                }
                //borrarEstado();
                enProcesoN[i] = false;
            }
        }
        //escribirEstado('PROCESANDO...');
        enProcesoN[i] = true;
        httpN[i].send(null);
    }
}

function getHTTPObject() {
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) { xmlhttp = false; }
    }
    @else
    xmlhttp = false;
    @end
    @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) { xmlhttp = false; }
    }
    return xmlhttp;
}

var enProcesoN = new Array();
var httpN = new Array();
var estado;

function syncHTTP(UrlAddress) {
    var http, flg;
    UrlAddress = UrlAddress;
    http = getHTTPObject();
    http.open("GET", UrlAddress, false);
    flg = true;
    http.send(null);
    eval(http.responseText);
    http = null;
}

function syncRequest(UrlAddress) {
    var http, flg, sRet;
    UrlAddress = UrlAddress;
    http = getHTTPObject();
    http.open("GET", UrlAddress, false);
    flg = true;
    http.send(null);
    sRet = http.responseText;
    http = null;
    return sRet;
}

function AjaxRequestPost(UrlAddress, params) {
    var i;

    for (i = 0; i < enProcesoN.length && enProcesoN[i] == true; i++);

    if (!httpN[i]) {
        enProcesoN.push(false);
        httpN.push(getHTTPObject());
    }

    if (!enProcesoN[i] && httpN[i]) {
        httpN[i].open("POST", UrlAddress, true);
        httpN[i].onreadystatechange = function() {
            if (httpN[i].readyState == 4) {
                if (httpN[i].status == 200) {
                    if (httpN[i].responseText.indexOf('invalid') == -1) {
                        eval(httpN[i].responseText);
                    }
                }
                borrarEstado();
                enProcesoN[i] = false;
            }
        }
        escribirEstado('PROCESANDO...');
        enProcesoN[i] = true;
        httpN[i].setRequestHeader('Content-type', 'application/x-www-form-urlencoded;charset=UTF-8;');
        httpN[i].send(params);
    }
}