
function addtomyreflist(nr, btn){
	if( ! in_array(nr, myrefs)){
		createCookie('myreflist['+myrefs.length+']', nr, 30);
		myrefs[myrefs.length]=nr;
		alert('Entry added to your reference list.');
		if(document.images && btn.firstChild && btn.firstChild.src) btn.firstChild.src='/buttons/clearfromlist.gif'
	}else{
		kjeks=document.cookie.split(';');
		for(i=0; i<kjeks.length; i++){
			pair=kjeks[i].split('=');
			if(pair[1]==nr) deleteCookie(pair[0]);
		}
		myrefs=array_remove_value(nr, myrefs);
		alert('Entry removed from your reference list.');
		if(document.images && btn.firstChild && btn.firstChild.src) btn.firstChild.src='/buttons/addtolist.gif';
	}
}

function createCookie(name,value,days) {
  if (days) {
  	expires=getExpDate(30);
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function deleteCookie(name){
	document.cookie=name+'=; expires='+getExpDate(-30);
}

function in_array(val, ar){
	for(i=0; i<ar.length; i++){
		if(ar[i]==val) return true;
	}
	return false;
	
}
function array_remove_value(val, ar){
	for(i=0; i<ar.length; i++){
		if(ar[i]==val) ar[i]='';
	}
	return ar;
	
}


function getExpDate(offset){
    var date = new Date();
    date.setTime(date.getTime()+(offset*24*60*60*1000));
    return expires = "; expires="+date.toGMTString();

}
