/*
 * Copyright (c) 2008, Intel Corporation.
 * All Rights Reserved.
 *
 * $id$
 *
 */

/*
 * fill innerHTML of element 'id' with the output of 'url' 
 */
function ajax_fill(id, url) 
{
    var req;
    var obj;

    // store the DOM object
    obj = (typeof id == 'string')? document.getElementById(id) : id;

    req = (window.XMLHttpRequest)? new XMLHttpRequest() :
                                   new ActiveXObject("Microsoft.XMLHTTP");
    if (!req)
        return false;

    // state change handler
    function fill_onchange()
    {
        if (req.readyState != 4)
            return;                     // ignore everything until done

        switch (req.status) {
        case 200:                       // success, add content
            obj.innerHTML = req.responseText;
            var title = document.getElementById("title");
            if(title){
            	document.title = title.textContent;
 						}
            return;

        default:                        // everything else, report error.
            obj.innerHTML = "Data not available";
            return;
        }
    }

    req.onreadystatechange = fill_onchange;
    req.open('get', url, true);
    req.send(null);
    return true;
}

/* 
 * load the main page content base on the actual URI (the search 
 * field). this is done to avoid losing history information (i.e., 
 * back-button functionality). 
 */ 
function load_page_content()
{
    var subpage; 
    var menutab; 
    var ts = new Date(); 

    subpage = document.location.search.split("?"); 
    if (!subpage[1]) 
	subpage[1] = 'home'; 

    ajax_fill('content', subpage[1] + '.html' + "?" + ts.getSeconds()); 

    // fill this element with 

    // set the current tab to bold
    menutab = document.getElementById(subpage[1]);
    if (menutab)
	menutab.style.fontWeight = 'bold';
}

/*
 * toggle visibility of an item 
 */ 
function toggle(id) 
{ 
    x = document.getElementById(id); 
    x.style.display = (x.style.display == 'none')? 'block' : 'none'; 
}
 

/* 
 * set the menu item in bold
 */ 
function setbold(pagename)
{
    menutab = document.getElementById(pagename); 
    if (menutab)
	menutab.style.fontWeight = 'bold';
}

