// Array to hold all the elements to be toggled about
var aFoldOutElems = new Array();


/* Toggle box menus on the right column of the layout. */
function showFoldoutMenu(idno) {
		
    if(document.getElementById) {
        
        var elem = document.getElementById(idno);
        
        if (elem) {
            
            // Hide all the others but the clicked
            for (var i=0; i<aFoldOutElems.length; i++) {
                if (aFoldOutElems[i] != idno) {
                    var e = document.getElementById(aFoldOutElems[i]);
                    if (e) {
                        e.className = e.className.replace("show", "");
                    }
                }
            }

            // Toggle visibility of the clicked one
            if(elem.className.indexOf('show') == -1) { 
                elem.className += " show";
            } else {
                elem.className = elem.className.replace("show", "");
            }
            
        }
    }		
}


/* Show the book selected from the book menu. */
function showBook(obj, subcategory_id) {

    if (obj && obj.value && obj.form) {
        // var gotourl = obj.form.action;
        var gotourl = window.location.href;
        
        gotourl = removeUrlItem(gotourl, 'book_id');
        gotourl = removeUrlItem(gotourl, 'subcategory_id');
        
        var parameter = "book_id=" + obj.value + "&subcategory_id=" + subcategory_id;
        
        parameter = fixParameter(gotourl, parameter);
        
        window.location = gotourl + parameter;
    }
    
}


/* Used to show extra stuff about a book. */
function openBookAddon(pname,iden) {
    newwin=window.open(pname,'bookcard_' + iden,'width=536,height=580,scrollbars=1,resizable=1,toolbar=0,menubar=0,location=0,statusbar=0');newwin.focus();
}


/*
* removeUrlItem will remove given item and it's value from given url string.
* 
* @param	urlstring		Url string to be parsed.
* 			name			Name of the item to be ripped.
* @return	Returns the same string with parameter 'name' ripped.
* @author	mika.laukka@ch5finland.com
* @version	1.0, 22.05.2003
*/
function removeUrlItem(urlstring, name) {
    var myRegExp = new RegExp;
    myRegExp = eval("/" + name + "=[^&]+($|&)/i;");
    var temp = urlstring.replace(myRegExp, "");
    // no params left? clear the '?' or the '&'
    if ( temp.substr(temp.length-1, 1) == "?" || temp.substr(temp.length-1, 1) == "&" )
        temp = temp.substr(0, temp.length-1);
    return temp;
}


/* Add a leading ? or & to a query string, depending on the existing url */
function fixParameter(gotourl, parameter) {
    var newparam = parameter;
    if (gotourl.indexOf('?') > -1) {
        newparam = "&" + newparam;
    }
    else {
        newparam = "?" + newparam;
    }
    return newparam;
}


/* Switch textbook category. */
function switchTextbookCategory(obj) {

    if (obj && obj.value && obj.form) {
        // var gotourl = obj.form.action;
        var gotourl = window.location.href;
        
        gotourl = removeUrlItem(gotourl, 'series_id');
        gotourl = removeUrlItem(gotourl, 'tbcategory_id');
	        
        var parameter = "tbcategory_id=" + obj.value;
        
        parameter = fixParameter(gotourl, parameter);
        alert("moi");
        window.location = gotourl + parameter;
    }
    
}


/* Show selected tect book. */
function showTextbook(obj) {
    if (obj && obj.value && obj.form) {
        
        if (obj.value == "") return;
	
//        var gotourl = window.location.href;

//        obj.value = "series_id="; 

	window.location = obj.value;
        
        
	
	/*
        
        gotourl = removeUrlItem(gotourl, 'tbcategory_id');
        gotourl = removeUrlItem(gotourl, 'series_id');
        
        var parameter = "series_id=" + obj.value + "&tbcategory_id=" + tbcategory_id;
        
        parameter = fixParameter(gotourl, parameter);
        
        window.location = gotourl + parameter;
        */
    }

}


