// JavaScript Document
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

if (!Array.prototype.indexOf)
{
    /**
     * Add array.indexOf() functionality (exists in >FF 1.5 but not in IE)
     *
     * @param {Object} elem Element to find.
     * @param {Number} [from] Position in array to look from.
     */
    Array.prototype.indexOf = function(elem /*, from*/) {
        var len = this.length;

        var from = Number(arguments[1]) || 0;
        from = (from < 0) ? Math.ceil(from) : Math.floor(from);
        if (from < 0) {
            from += len;
        }

        for (; from < len; from++) {
            if (from in this && this[from] === elem) {
                return from;
            }
        }

        return -1;
    };
}
Array.prototype.remove=function(s){	
	var i = this.indexOf(s);
	if(i != -1) this.splice(i, 1);
}

function aHref(url, newTarget, focusWin){
	if (newTarget) {
		var newW = window.open(url);
		if(focusWin)
			newW.focus();
	} else {
		window.location.href = url;
	}		   
}

function bkFilterClick(elem) {
	var cookieName = 'filterBks';
	if (elem) {
		var bksStr = readCookie(cookieName);		
		var bksArr = [];
		if (bksStr) {
			bksArr = bksStr.split("|");
		}		
		if (elem.checked) {
			//alert('checked '+elem.value);
			bksArr.push(elem.value);
		} else {
			//alert('not checked');
			bksArr.remove(elem.value);
		}		
		var coo = bksArr.join("|");				
		createCookie(cookieName, coo, 365);
		//alert(readCookie(cookieName));
	}
}