﻿function set_num_results(num){
    document.getElementById("ctl00_ctl00_cphBody_cphBody_res_hidNumResults").value = num;
}

function set_sort(sort){
    document.getElementById("ctl00_ctl00_cphBody_cphBody_res_hidSort").value = sort;
}



// dhtml_pages
// created by: Michael Sean Hansen
// 3 Oct 2008
//
// Description:
//    Breaks lengthy content into nice-looking,
//    fast-loading pages.
//
// Usage:
// 1) Place <div id="dhtml_page_buttons"> </div>
//    where you want the buttons to appear.
// 2) Place the content for each page in
//    divs of class "dhtml_page".
//
// Optional:
//    As is, you will see all of the pages displayed
//    for a split second before they are hidden. To
//    avoid this, add the following to a css file:
//      
//    .dhtml_page{ display:none;}
//
// Styling:
//    The buttons are placed within dhtml_page_buttons.
//    It consists of an unordered list with a link in
//    each, so style those to your heart's content!
//


var pages = [];
var buttons = [];
var c_page = 0;
var c_button = 0;

function update_buttons(num){
    // reset style of previous button
    var c_link = buttons[c_button].getElementsByTagName("a")[0];
    c_link.style.backgroundColor = "#fff";
    c_link.style.color = "#003D7B";

    // set c_button to proper index   
    if(num == 0){
        c_button = 1;
    } else if(num == pages.length - 1){
        c_button = buttons.length - 2;
    } else{
        c_button = num + 2;
    }    
    
    // set style of new button
    var my_link = buttons[c_button].getElementsByTagName("a")[0];
    my_link.style.backgroundColor = "#ccc";
    my_link.style.color = "#555";
    
    
    
    
    // show appropriate buttons
    if(pages.length > 10){
    
        // hide all but first and last page initially
        for(var i = 2; i < buttons.length - 2; i++)
            buttons[i].style.display = "none";
            
        if(c_button < 10){
            // show first 10
            buttons[buttons.length - 3].style.display = "";
            for(var i = 3; i < 12; i++)
                buttons[i].style.display = "";
        } else if(c_button > buttons.length - 12){
            // show last 10
            buttons[2].style.display = "";
            for(var i = buttons.length - 12; i < buttons.length - 3; i++)
                buttons[i].style.display = "";
        } else{
            // show a few around current page
            buttons[2].style.display = "";
            buttons[buttons.length - 3].style.display = "";
            for(var i = c_button - 4; i < c_button + 5; i++)
                buttons[i].style.display = "";
        }
    } else {
        buttons[2].style.display = "none";
        buttons[buttons.length - 3].style.display = "none";
    }
}

function show_page(num){
    if(num >= 0 && num < pages.length){
        pages[c_page].style.display = "none";
        pages[num].style.display = "block";
        update_buttons(num);
        c_page = num;
    }
}

function dhtml_pages_load(){
    pages = [];
    buttons = [];
    c_page = 0;
    c_button = 0;
    
    // create array of pages
    var tmp = document.getElementsByTagName("div");
    for(var i = 0; i < tmp.length; i++){
        if(tmp[i].className == "dhtml_page"){
            tmp[i].style.display = "none";
            pages.push(tmp[i]);
        }
    }
    
    // create page buttons
    if(pages.length > 1){
        
        var str = "<ul id='dhtml_page_buttons'>";
        str += "<li><a href='#error' onclick='show_page(c_page-1); return false;'>&lt;</a></li>";
        str += "<li><a href='#error' onclick='show_page(0); return false;'>1</a></li>";
        str += "<li>...</li>";
        
        for(i = 1; i < pages.length - 1; i++){
            str += "<li><a href='#error' onclick='show_page(" + i + "); return false;'>";
            str += (i+1) + "</a></li>";
        }
        
        str+= "<li>...</li>";
        str += "<li><a href='#error' onclick='show_page(" + (pages.length-1) + "); return false;'>";
        str += pages.length + "</a></li>";
        str += "<li><a href='#error' onclick='show_page(c_page+1); return false;'>";
        str += "&gt;</a></li></ul>";
        
        document.getElementById("dhtml_page_buttons").innerHTML = str;
        buttons = document.getElementById("dhtml_page_buttons").getElementsByTagName("li");        
        show_page(0);
        
    } else if(pages.length == 1){
    
        // show the one and only page, how boring
        pages[0].style.display = "block";
    }
}












function append_functions(f1, f2){
    return function(){
        if(f1){ f1();}
        if(f2){ f2();}
    };
}

window.onload = append_functions(window.onload, dhtml_pages_load);