﻿$(function () {
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_pageLoaded(GLB_UpdatePanelRefreshed); //add update panel post request ping
    try {
        prm.add_pageLoaded(initsub); //add update panel post request ping
        //initpage();
    }
    catch (err) {
    }
    //prm.add_initializeRequest(EVT_UpdatePanelInitialiseRequest); //add update panel pre request ping
    GLB_UpdatePanelRefreshed(undefined, undefined);
});
function GLB_UpdatePanelRefreshed(sender, args) {
    try {
        $('.datepicker').datepicker({ dateFormat: 'dd/mm/yy' });
    }
    catch (err) {
        //Handle errors here
    }
}

// $(function () {
//    //Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(); //add update panel post request ping
//    //prm.add_initializeRequest(EVT_UpdatePanelInitialiseRequest); //add update panel pre request ping
//    init();
//    //Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(GLB_BeginRequest);
//    //Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(GLB_EndRequest);
//});

//function init() {
//    //$('a.lightbox').lightBox();
//    try {
//        initsub();
//    }
//    catch (err) {
//    }
//}

//****** The Patch for the "Crash of 2010" bug *********************//
function GLB_BeginRequest(sender, args) {
    if (sender._postBackSettings !== undefined && sender._postBackSettings !== null) {
        try {
            var componentsOfName = sender._postBackSettings.panelsToUpdate[0].split("$");
            var panelID = "Content_" + componentsOfName[componentsOfName.length - 1];

            $('#' + panelID + ' input[type=submit]').attr('disabled', true);
            //$('#' + panelID + ' a').css("visibility", "hidden");

            if (sender._activeElement.id != "") {
                if ($('#' + sender._activeElement.id).hasClass("aButton")) {
                    $('#' + sender._activeElement.id).attr({ "disabled": "disabled", "href": "" }).css("background", "url(/images/animations/button-loader.gif) center no-repeat #999").removeAttr("onclick").html("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                }
                $('#' + sender._activeElement.id).attr({ "disabled": "disabled", "onclick": "return false;", "href": "" });
            }
        }
        catch (err) {
        }
        //$('input[type=submit]').attr('disabled', true).css("background","url(/images/layout/container-header-background.jpg) repeat-x scroll left top transparent;");
        //$('a').hide();
    }
}
function GLB_EndRequest(sender, args) {
    try {
        if (sender._postBackSettings !== undefined && sender._postBackSettings !== null) {

            var componentsOfName = sender._postBackSettings.panelsToUpdate[0].split("$");
            var panelID = "Content_" + componentsOfName[componentsOfName.length - 1];

            $('#' + panelID + ' input[type=submit]').removeAttr('disabled');
            //$('input[type=submit]').attr('disabled', false);

            if (sender._activeElement.id != "") {
                $('#' + sender._activeElement.id).removeAttr("disabled").removeAttr("style");
            }
        }
        GLB_UpdatePanelRefreshed(sender, args);
    } catch (err) {
    }
    init();
}


function trackClick(el) {
    alert('asd');
    $.ajax({
        type: "GET",
        url: "/inc/track.aspx?url=" + el.href
    });
    //alert(el.href);
    //alert(1);
}


function DoRollOver(name, over) {
    if (window.document.images) {
        var sExt;
        if (window.document.images[name].src.indexOf('.jpg') > 0) {
            sExt = ".jpg";
        } else {
            if (window.document.images[name].src.indexOf('.gif') > 0) {
                sExt = ".gif";
            } else {
                sExt = ".png";
            }
        }

        if (over)
            window.document.images[name].src = window.document.images[name].src.replace(sExt, '-hover' + sExt);
        else
            window.document.images[name].src = window.document.images[name].src.replace("-hover", "");
    }
}
function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
}
