﻿// This file contains all custom JavaScript for Manticore


/* Primary Navigation JavaScript */
sfHover = function() {
    if (document.getElementById("userNav") != null){
	    var sfEls = document.getElementById("userNav").getElementsByTagName("LI");
	    for (var i=0; i<sfEls.length; i++) {
		    sfEls[i].onmouseover=function() {
			    this.className+=" sfhover";
		    }
		    sfEls[i].onmouseout=function() {
			    this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		    }
	    }
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


/*######################################################
Following code makes sure the update progress is 
displayed on any asynchronous call
######################################################*/
var prm;
var postBackElement;

function AssociateAjaxUiEvents()
{
    prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_initializeRequest(InitializeRequest);
    prm.add_endRequest(EndRequest);
}

function Cover(bottom, loadingBackground, elemToCenter, ignoreSize) {
    var elementLocation = Sys.UI.DomElement.getLocation(bottom);
    loadingBackground.style.position = 'absolute';
    loadingBackground.style.top = (elementLocation.y) + 'px';
    loadingBackground.style.left = (elementLocation.x) + 'px';
    
    //alert(elemToCenter.offsetHeight);
    
    var dimensions = Sys.UI.DomElement.getBounds(elemToCenter);
    elemToCenterHeight = 28/2;//dimensions.height/2;
    elemToCenterWidth = 92/2;//dimensions.width/2;
    
    //var offSetHeight = (bottom.offsetHeight/2) - (elemToCenter.offsetHeight/2) + 'px';
    //var offSetWidth = (bottom.offsetWidth/2) - (elemToCenter.offsetWidth/2) + 'px';
    
    var offSetHeight = (bottom.offsetHeight/2) - elemToCenterHeight + 'px';
    var offSetWidth = (bottom.offsetWidth/2) - elemToCenterWidth + 'px';
    
    if (!ignoreSize) {
        loadingBackground.style.height = bottom.offsetHeight + 'px';
        loadingBackground.style.width = bottom.offsetWidth + 'px';
    }
    if(elemToCenter){
        elemToCenter.style.left = offSetWidth;
        elemToCenter.style.top = offSetHeight;
        //alert(offSetHeight + ' ' + offSetWidth);
    }
}

function InitializeRequest(sender, args) {
    var ownerId = sender._postBackSettings.sourceElement.id;    
    var elementToOverlap = $get('contentWrapper');
    var elementLoadingBackground = $get('ajaxLoadingBackground');
    
    Cover(elementToOverlap, elementLoadingBackground, $get('ajaxLoadingMessage'));
    
    if (prm.get_isInAsyncPostBack()) {
        args.set_cancel(true);
    }
    postBackElement = args.get_postBackElement();
    $get('ajaxLoadingBackground').style.display = 'block';
}

function EndRequest(sender, args) {
    $get('ajaxLoadingBackground').style.display = 'none';
}

function pageLoad(){
    //Set parameters for ajax calls
    setTimeout('AssociateAjaxUiEvents()', 2000);
}

if(typeof(Sys) != 'undefined') Sys.Application.notifyScriptLoaded();

/*######################################################
End update progress display
######################################################*/