function setnotreg(){
    document.getElementById('notreg').style = "font-weight : bold;color : #FF6666;";
    
    return false;
}

function viewPrint(){
    var book = document.getElementById('book').value;
    var page = document.getElementById('page').value;
    
    window.open('print.php?type=c_page&book='+ book +'&page='+ page,'Print','width=800,height=500')
}

function toggle(id){
    //Close all windows
    var wins = ['font_win','size_win','color_win','index_win','search_win','bgcolor_win','fgcolor_win'];
    for(i = 0;i < wins.length;i++){
        if(id != wins[i]){
            if(typeof(document.getElementById(wins[i])) != "undefined" && document.getElementById(wins[i]) != null){
                document.getElementById(wins[i]).style.display = 'none';
            }
        }
    }
    
    var obj = document.getElementById(id);
    if(obj.style.display == 'none'){
        obj.style.display = 'block';
    }
    else{
        obj.style.display = 'none';
    }
}

function setfont(fname){
    document.getElementById('booktext').style.fontFamily = fname;
}

function setCardFont(fname){
    document.getElementById('card_text').style.fontFamily = fname;
}

function setsize(size){
    document.getElementById('booktext').style.fontSize = size +"px";
}

function setcolor(color){
    document.getElementById('booktext').style.color = color;
}

function highlight(searchText, treatAsPhrase){
    var warnOnFailure = false;

    // if the treatAsPhrase parameter is true, then we should search for 
    // the entire phrase that was entered; otherwise, we will split the
    // search string so that each word is searched for and highlighted
    // individually
    if (treatAsPhrase) {
        searchArray = [searchText];
    } else {
        searchArray = searchText.split(" ");
    }

    //var bodyText = document.getElementById('booktext').innerHTML;
    var bodyText = mainPage;
    for (var i = 0; i < searchArray.length; i++){
        bodyText = doHighlight(bodyText, searchArray[i]);
    }

    document.getElementById('booktext').innerHTML = bodyText;
return true;
}

function doHighlight(bodyText, searchTerm){
    // the highlightStartTag and highlightEndTag parameters are optional
    var highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
    var highlightEndTag = "</font>";

    // find all occurences of the search term in the given text,
    // and add some "highlight" tags to them (we're not using a
    // regular expression search, because we want to filter out
    // matches that occur within HTML tags and script blocks, so
    // we have to do a little extra validation)
    var newText = "";
    var i = -1;
    var lcSearchTerm = searchTerm.toLowerCase();
    var lcBodyText = bodyText.toLowerCase();

    while (bodyText.length > 0) {
        i = lcBodyText.indexOf(lcSearchTerm, i+1);
        if (i < 0) {
            newText += bodyText;
            bodyText = "";
        }
        else {
            // skip anything inside an HTML tag
            if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
                // skip anything inside a <script> block
                if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
                    newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
                    bodyText = bodyText.substr(i + searchTerm.length);
                    lcBodyText = bodyText.toLowerCase();
                    i = -1;
                }
            }
        }
    }

    return newText;
}

function CreateBookmarkLink(title,url){
    //var title = "Webpage Title"; 
    //var url = "Webpage URL";

    if (window.sidebar){ // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url,"");
    }
    else if(window.external){// IE Favorite
        window.external.AddFavorite(url, title);
    }
    else if(window.opera && window.print){// Opera Hotlist
        return true;
    }
}

var tmpStyle = "";
function toggleStyle(id,sw){
    var obj = document.getElementById(id);
    if(sw){
        tmpStyle = obj.className;
        obj.className+= "over";
    }
    else{
        obj.className = tmpStyle;
    }
}
