function switchFormDiv(div){ 
    var f=document.getElementById(div);
    var a=document.getElementById('article_main');
    /*
     Nice idea, but doesn't work in Safari. doh.
     a.style.opacity=(a.style.opacity=='0.3'?'1.0':'0.3');
    */
    f.style.display=(f.style.display=='block'?'none':'block');
    return false;
}

function infobox(){ 
    var i=document.getElementById('infobox');
    i.style.display=(i.style.display=='block'?'none':'block');
    return false;
}

function sendEmail(){
    var to = document.email_form.to.value;
    var message = document.email_form.message.value;
    xmlHttp=GetXmlHttpObject();
    url = window.location+"email-story/"
    xmlHttp.open("POST", url , true);
    xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xmlHttp.onreadystatechange = function() {
            if (xmlHttp.readyState == 4) {
                    document.getElementById("email_tool").innerHTML = "<strong>E-MAILED</strong>";
                    document.getElementById("email_form").innerHTML = xmlHttp.responseText;
            }
    }
    if (to.length > 0){
        if(to.search("@") != -1){
            xmlHttp.send("to="+to+"&message="+message);
        }
        else{
           document.getElementById('email_error').innerHTML = "<strong>Please enter at least one valid email address</strong>"; 
        }
    }else{
        document.getElementById('email_error').innerHTML = "<strong>Please enter at least one valid email address</strong>";
    }
}

function bookmarkStory(){
    xmlHttp=GetXmlHttpObject();
    url = "http://"+window.location.hostname+window.location.pathname+"bookmark-story/";
    xmlHttp.open("GET", url , true);
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            var div = document.getElementById("bookmark_tool")
            if(div.innerHTML.search('BOOKMARKED') != -1){
                div.innerHTML = "BOOKMARK";
            }
            else{
                div.innerHTML = "BOOKMARKED";
            }
        }
    }
    xmlHttp.send("");
}

function bmlogin(){
    var a=document.getElementById('bmlogin');
    a.style.display=(a.style.display=='block'?'none':'block');  
}
function printStory(){
    url = window.location+"print-story/"
    window.open(url,"print story","width=600,height=500,scrollbars=yes");
}

function nextPrevious(page){
    f = document.article_search_form;
    f.action+="?page="+page;
    f.submit();
    return false;
}