﻿

function DynamicScrollingLayout(){

    //used to avoid running the function several times on window resize
    /* Turn on scrolling div when the following conditions are met:
        1) Javascript Detected - this function will only runly if js is turned on and browser is capable
        2) Ajax capable - browser supports the XMLHttpObject
        3) Screen size - 800 x 600 or larger
    // change search result display to absolute layout
    */

    //
    var browser = navigator.appName;
    var useragent = navigator.userAgent;

    // turn off dynamic scrolling for Opera and IE 6 and below

    if (browser == "Microsoft Internet Explorer") {
        var ie_charindex = useragent.indexOf("MSIE") + 4;
        var version = parseFloat(useragent.substring(ie_charindex, ie_charindex + 4));
        if (version <= 6)
            return;
    }
    
    
    
    
    var ajax_support;
    try {
      ajax_support = window.XMLHttpRequest ? new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) {
        
      return;
    }
    
    
    var results = document.getElementById("results");
    var ajaxCompatibility = document.getElementById("dynamicScrollingOn");

    //exit if it does not meet a specific screen size
    
    
    // if width and height is smaller than a certain size, do not turn on ajax mode
    if(document.getElementById("viewport").clientHeight < 350 || document.getElementById("viewport").clientWidth < 785)
    {
        results.className = "standards_compliant";
        //document.body.style.overflow = "visible";  //this crashes ie6
        if (document.getElementById("pnlPaging"))
            document.getElementById("pnlPaging").style.display = "block";
        ajaxCompatibility.value = 0;
        results.style.display = "block";
        results.style.position = "static";
        results.style.overflow = "visible";  // Workaround for IE 6.
        //results.
        //alert("ajax off overflow:" + results.className);
        //alert("viewport clientWidth: " + document.getElementById("viewport").clientWidth + ",clientHeight: " + document.getElementById("viewport").clientHeight);
        
        return;
    }

    //document.documentElement.style.overflow = "visible";
    results.className = "ajax_scroll";
    results.style.overflow = "auto";  //
    results.style.position = "absolute";
    //alert("ajax on overflow:" + results.className);
    /*
    results.style.position = "absolute";
    results.style.top = "120px";
    results.style.left = "0px";
    results.style.right = "0px";
    results.style.bottom = "0px";
    results.style.overflow = "auto";
    */


    // if result_container (the inner container) is less than results (the outer container) then turn scrolling off, it isn't necessary
    if (document.getElementById("results_container").scrollHeight < document.getElementById("results").clientHeight) {

        //alert("results-clientHeight:" + document.getElementById("results").clientHeight + "/results-scrollHeight:" + document.getElementById("results_container").scrollHeight);
        results.className = "ajax_no_scroll";
    }
      //alert(document.getElementById("results").clientHeight) 
       //
   
    
    
    // turn off paging display
    if(document.getElementById("pnlPaging")){
        document.getElementById("pnlPaging").style.display = "none";
    }

    ajaxCompatibility.value = 1;
    

}


window.onload = DynamicScrollingLayout;
window.onresize = DynamicScrollingLayout;