﻿// Loading msgbox
var _updateProgressDiv;
//Postback element
var _element;

Sys.Application.add_init(AppInit);

function AppInit() {
    Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(initializeRequest);
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
    Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(pageLoading);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);

    _updateProgressDiv = document.getElementById("updateProgressDiv");

} //end function


function initializeRequest(sender, args) {
    _element = args.get_postBackElement().id;
}


function pageLoading(sender, args) {
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    if (prm.get_isInAsyncPostBack()) {
        if (_element == "ctl00_cphBody_btnSearch1" || _element == "ctl00_cphBody_lbtnBackToList") {
            //Get Dropdown Objects
            var ddlAnimal = document.getElementById("ctl00_cphBody_ddlAnimal");
            var ddlGender = document.getElementById("ctl00_cphBody_ddlSex");
            var ddlAge = document.getElementById("ctl00_cphBody_ddlAge");
            //Get DropDown Selected Values
            var animal = ddlAnimal.options[ddlAnimal.selectedIndex].value;
            var gender = ddlGender.options[ddlGender.selectedIndex].value;
            var age = ddlAge.options[ddlAge.selectedIndex].value;
            //Assign New src to Frame
            var url = "http://sms.petpoint.com/webservices/adoptablesearch/wsAdoptableAnimals.aspx?&species=" + animal + "&sex=" + gender + "&agegroup=" + age + "&onhold=A&orderby=ID&colnum=2&authkey=nhmrlxi82fx1fhxhedho384o0i16uultel8ex5gmybby4g20fe&css=http://www.indepmo.org/health/css/PetPoint.css";
            document.getElementById("iframe").src = url;
            document.getElementById("divPetpoint").style.display = 'block';
        }
    }
}

function beginRequest(sender, args) {
    var tabContainer = document.getElementById("ctl00_cphBody_TabContainer1");
    if (_element == "ctl00_cphBody_btnSearch1" || _element == "ctl00_cphBody_lbtnBackToList") {
        _updateProgressDiv.style.display = 'block';
       // showProgressDiv(tabContainer);
    }
}

// This function is used to show the loading msg box
function showProgressDiv(value) {
    var tabContainer = value;
    //Make DIV visible
    _updateProgressDiv.style.display = 'block';
    //Get the bounds of both the gridview and the progress div
    var tabContainerBounds = Sys.UI.DomElement.getBounds(tabContainer);
    var updateProgressDivBounds = Sys.UI.DomElement.getBounds(_updateProgressDiv);
    //Center of gridview
    var x = tabContainerBounds.x + Math.round(tabContainerBounds.width / 2) - Math.round(updateProgressDivBounds.width / 2);
    var y = tabContainerBounds.y + Math.round(tabContainerBounds.height / 2) - Math.round(updateProgressDivBounds.height / 2);
    //Set the progress element to this position
    Sys.UI.DomElement.setLocation(_updateProgressDiv, x, y);
} //end function (showProgressDiv)

// This function occurs when the request cycle ends.
function endRequest(sender, args) {
    //Make invisible
    _updateProgressDiv.style.display = 'none';
}