﻿//show or hide ArionPreloader.ascx
function showPreloader() {    
    $("preloader").show(); 
    $('<%= litMessage.ClientID %>').value = "";
}
function hidePreloader() {
    $("preloader").hide();
}

function runAdsRotator(currentIndex) {
    var images = $$("#adsRotator .adsImage");
    
    if (images != "" && images != null) {
        //if the current index is the last index,
        //move the current index to the first image
        if (currentIndex == images.length - 1) {
            currentIndex = 0;
        } else {
            currentIndex++;
        }
        //get and set src, title, and link of the new image
        var src = images[currentIndex].select("img")[0].readAttribute("src");
        var link = images[currentIndex].select("a")[0].readAttribute("href");
        var title = images[currentIndex].select("a")[0].readAttribute("title");
        var a_tag = $$("#blendimage a")[0];
        var img_tag = $$("#blendimage img")[0];
        a_tag.writeAttribute("href", link);
        a_tag.writeAttribute("title", title);
        img_tag.writeAttribute("title", title);
        img_tag.writeAttribute("alt", title);
        //stop previous animation first
        if (typeof (to_adsRotator) != 'undefined' && to_adsRotator != null) {
            stopAnimation(to_adsRotator);
        }
        //start animation
        to_adsRotator = blendimage("blenddiv", "blendimage", src, _ADS_ROTATOR_ANIMATION_INTERVAL);
        //display next ads
        setTimeout("runAdsRotator(" + currentIndex + ")", _ADS_ROTATOR_SWAP_INTERVAL);
    }
}

//put all body onload events here
function pageLoaded() {
    //start ads rotator
    setTimeout("runAdsRotator(0)", _ADS_ROTATOR_SWAP_INTERVAL);
}

//this method is called when tree menu item is selected
function menuItem_onSelected(item) {
    //clear any already selected items
    $$("ul#tree a").each(function(link) {
        link.removeClassName("selectedCriteriaItem");
        if (link.hasClassName("nobranch_on")) {
            link.className = "nobranch";
        }
    });
    //select the current item
    if (item.hasClassName("nobranch")) {
        item.className = "nobranch_on";
    } 
    else  {
        item.addClassName("selectedCriteriaItem");
    } 
}
//load report based on report index
function loadReport(index) {
    var src = $$('iframe.pedigreeReportFrame' + index)[0].src;
    //if aspx page, it's still loading, skip.
    if (src.indexOf('.aspx') != -1) {
        return;
    }
    //refresh the report frame
    $$('iframe.pedigreeReportFrame' + index)[0].src = src;
    
    //if error page or source page is empty, hide links
    if (src.indexOf('ReportLoadError.htm') != -1 || src == '') {
        hideReportLinks(index);
    }
    else {
        showReportLinks(index);
    }
    
}

//hide or show the subitems in tree menu, not used atm
/*
function toggleTreeView(item_id) {
    var item = $(item_id);
    if (item.hasClassName("expand")) {
        item.removeClassName("expand");
    } else {
        item.addClassName("expand");
    }
}
*/

//apply style sheet for safari on mac, safari on windows, and chrome.
if (BrowserDetect.OS == "Mac" && BrowserDetect.browser == "Safari") {
    document.write("<link type=\"text/css\" rel=\"stylesheet\" href=\"/App_Themes/Default/Styles/mac_safari.css\" />");
} else if (BrowserDetect.browser == "Chrome") {
    document.write("<link type=\"text/css\" rel=\"stylesheet\" href=\"/App_Themes/Default/Styles/chrome.css\" />");
} else if (BrowserDetect.OS == "Windows" && BrowserDetect.browser == "Safari") {
    document.write("<link type=\"text/css\" rel=\"stylesheet\" href=\"/App_Themes/Default/Styles/win_safari.css\" />");
}