﻿var displayElement;
var postbackElement;

Sys.Application.add_load(ApplicationLoadHandler);
function ApplicationLoadHandler() {
    Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(checkStatus);
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
}

function checkStatus(sender, args) {
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    var postbackEl = args.get_postBackElement();
    if (typeof (postbackElement) === "undefined")
        return;
        
    if (prm.get_isInAsyncPostBack() & postbackEl.id.toLowerCase().indexOf('_ftr') > -1) 
        prm.abortPostBack();
}


function beginRequest(sender, args) {
    postbackElement = args.get_postBackElement();
    if (typeof (postbackElement) === "undefined") {
        return;
    } //'loading...' when filters changed
    else {
        //filters & search
        if (sender._postBackSettings.panelID.indexOf('upFiltrs') > -1 || sender._postBackSettings.panelID.indexOf('upnlFindProperties') > -1) {
            showloading();
        }
        var el = $get('lst_load');
        if (el) {
            el.style.padding = "0px";
            el.style.fontWeight = "normal";
            el.innerHTML = "<div class='loading'>loading...</div>";
        }
        else {
            el = $get('lst-load1'); //empty
            if (el) {
                el.style.padding = "5px 15px";
                el.innerHTML = "<div class='loading'>loading...</div>";
            }
        }
    }
}



if (typeof (Sys) !== "undefined" && Sys.Application) Sys.Application.notifyScriptLoaded();

function onPostingUpdateSucceeded(returnmessage, context) {//debugger;
    var pairs = returnmessage.split("\n");
    for (i = 0; i < pairs.length; i++) {
        var value = pairs[i].split("=");
        var element = $get(value[0]);
        if (element != null) {
            if (element.nodeName.toLowerCase() == "input") {
                if (element.id.indexOf('hlBidHistory') != -1 && element.value != value[1])
                    blink($('#' + value[0]), '#f0a6a6', 300, 3);
                element.value = value[1];
            }
            else {
                if (element.id.indexOf('hlBidHistory') != -1 && element.innerHTML != value[1])
                    blink($('#' + value[0]), '#f0a6a6', 300, 3);
                element.innerHTML = value[1];
            }
        }
    }
}

function blink($target, $backgroundColor, $interval, $times) {
    var existingBgColor = $target.css('background-color');
    for (var i = 0; i != $times; ++i) {
        setTimeout(function () { $target.css('background-color', $backgroundColor); }, $interval * i * 2);
        setTimeout(function () { $target.css('background-color', existingBgColor); }, $interval * (i * 2 + 1));
    }
}

function onPostingUpdateFailed(returnmessage, context) {
    // --=Update list request failed=--
}
