
var news_year;
var news_url;
var news_linkto;
var news_load = false;

function loadNewsFeature(cyear,curl,linkto){
    
    var top = getTopWindow();
    
    if(top == null) {
        alert("ERROR: loadNewsFeature(); Can't find root of site");
    }else{
        top.news_year   = cyear;
        top.news_url    = curl;        
        top.news_linkto = linkto;
        top.news_load   = true;
        
        top.loadContent("home_resources_latest_" + cyear,"nogroup");
    }
}

function _loadNewsFeature(){
    
    var top = getTopWindow();
    
    if(top == null) {
        alert("ERROR: _loadNewsFeature(); Can't find root of site");
    }else{    
    
        var nav         = top.document.getElementById("navbox");
        var menu        = top.getTopNavigation("../sxml/primarynavigation.xml","5","1","1");
        nav.innerHTML   = menu;
        
        top.loadNewsStory(top.news_url,top.news_linkto);
        top.news_load = false;
    }
}

function loadNewsStory(url,linkto){
    
    var top = getTopWindow();
    
    if(top == null) {
        alert("ERROR: loadNewsStory(); Can't find root of site");
    }else{    
        if(linkto == "url"){
            top.openPressRelease(url);

        } else {
            top.news_url = url;
            top.getNews(url+"?pg=y");
        }
    }
}

function showNewsStory(txt){
    var content_url = news_url.replace(/\/news.*\.jsp/,"");
    var atxt        = txt.replace(/img src="[\.\/]*res\//g,"img src=\"" + content_url + "/news/res/");

    var img_url     = news_url.replace(/[^\/]*$/,"");
    var btxt        = atxt.replace(/img src="[\.\/]*\//g,"img src=\"" + img_url);
    //alert(btxt);
    
    var controls = getNewsControls();
    
    var div_content = controls + btxt;
    
    var con = document.getElementById('newscontent');
    con.innerHTML = div_content;
    
    var layer = document.getElementById('newslayer');
    layer.style.visibility = "visible";
}

function hideNewsStory(){
    var con = document.getElementById('newscontent');
    con.innerHTML = "";
    
    var layer = document.getElementById('newslayer');
    layer.style.visibility = "hidden";
}

function openPressRelease(url){
    var win = window.open(url,'release','width=750,height=600,scrollbars=yes,resizable=yes,toolbar=yes,status=no,location=no');
    win.focus();
}

function getNewsControls(){
    var controls =  "<div class=\"controls\">"+
                        "<div class=\"close\" onclick=\"hideNewsStory();\">CLOSE</div>"+
                        "<div class=\"print\" onclick=\"openPressRelease('"+ news_url +"');\">PRINT</div>"+
                        "<div style=\"clear:both;\"><!-- content --></div>"
                    "</div>";
    
    return controls;
}

//==========================================================
//ajax calls

//========================================================
//response handlers

    function handleResponse(req){
        var txt = req.responseText;
        processing = false;
        showNewsStory(txt);
    }
    
    function handleError(err_msg){
        alert(err_msg);
        processing = false;
    }

//========================================================
//set up the ajax manager

    var processing = false;
    var aman = null;
    
    function setAjax(){
        aman = new ajaxMan();
        aman.setResponseHandler(handleResponse);
        aman.setErrorHandler(handleError);
    }

//========================================================
//set up the interface call
                
    function getNews(url){        
        if(aman == null){ setAjax(); }        

        if(!(processing)){
            processing = true;
            aman.sendRequest(url);
        } else {
            alert("Processing in progress.\nPlease wait for the page to reload.");
        }
    }
    
    