//<--------START----cookies-------->
function setCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}
function deleteCookie (name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
function getCookieVal(offset) {
                   var endstr = document.cookie.indexOf(";", offset);
                   if (endstr == -1) endstr = document.cookie.length;
                   return unescape(document.cookie.substring(offset, endstr));
}			   
function getCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}
//<--------END----cookies---------->
//<--------START----list-------->
function getListElement(num)
{			
	var returnElement = null;		
    var listDataLength=this.listData.length;
    var marker=0;
    var numOfSemicolon=0;	
	if (this.length !=0)
	{
		for (var position=0;position<listDataLength;position++)
		{			  
			if (this.listData.substring(position,position+1) ==";")
			{
				numOfSemicolon++;
				if ( num == numOfSemicolon)
				{
					returnElement=this.listData.substring(marker,marker+(position-marker));
					break;
				}
				marker=position+1;
				}
			}
		}                
    return returnElement;
}    
function listLength()
{
	var marker=0;
	var NumOfSemicolon=0;
   	if ( this.listData != '' )
	{
		for (var position=0;position<this.listData.length;position++)
		{
			if (this.listData.substring(position,position+1) ==";")
			{
				NumOfSemicolon++;
				marker = position + 1;
			}
		}
	}
    return NumOfSemicolon;
}	
function inList(element)
{
	var isIn = false;
    for (var position=1;position <= this.length;position++)
    {
    	if (this.getListElement(position) == element)
        {              
        	isIn = true;
            break;
        }
     }
     return isIn;
}
function removeListElement(element)
{	
	var newlistData = '';
	var lengthOfList = this.length;
    for (var position=1;position <= lengthOfList;position++)
    {
	    if (this.getListElement(position) == element)
        {
    	     newlistData="";
			 for (var index=1;index<= lengthOfList;index++)
             {
             	if (index != position)                   
                newlistData=newlistData + this.getListElement(index) + ";";
             }
             this.loadList(newlistData);
             break;
        }
    }
	return this;
}
function removeListPos(positionToRemove)
{
	var thisListLength = this.length;
	var newList = new List();
	if (thisListLength !=0)
		for (var position=1;position<=thisListLength;position++)
			if (position != positionToRemove)
				newList.addListElement(this.getListElement(position));
	if (newList.listData != '')
		this.loadList(newList.listData);	
	return this;
}
function addListElement(element)
{
        this.listData = this.listData + element + ";";
		this.length++;
		return this;
}
function listElementCount(element)
{
	var numElement = 0;
	for (var position=1;position <= this.length;position++)
		if (this.getListElement(position) == element)
			numElement++;	
	return numElement;
}
function appendList(list2)
{
	this.listData += list2.listData;	
}
function listPos(element)
{
	var pos = -1;
    for (var position=1;position <= this.length;position++)
    {
    	if (this.getListElement(position) == element)
        {              
        	pos = position;
            break;
        }
     }
     return pos;
}
function loadList(data)
{
	this.listData = new String(data);
	if (this.listData != null)	
		this.length = this.listLength();
	else
		this.length = 0;
	return this;
}
function staticLoadList(data)
{
	var list = new List()
	list.listData = data;
	list.length = list.listLength();	
	return list;
}
function List()
{
	this.listData = '';
	// Load list using functions arguments array
	for (var load=0;load<List.arguments.length;load++)
		this.listData = this.listData + List.arguments[load] + ";" ;	
	//Allow new List(String listData) constructor instead of new List().loadList(listData)
	var strArg = new String(List.arguments[0]);
	if (List.arguments.length == 1 && List.arguments[0]!=null && strArg.lastIndexOf(';')==strArg.length-1)
		this.listData = List.arguments[0];
	this.listLength = listLength;//method - used for length property
	this.length = this.listLength();//property
	this.getListElement = getListElement;//method
	this.listElementCount = listElementCount;//method
	this.inList = inList;//method
	this.remove = removeListElement;//method
	this.removePos = removeListPos;//method
	this.add = addListElement;//method
	this.appendList = appendList;//method
	this.loadList = loadList;//method
	this.listPos = listPos;//method
	return this;
}
//<--------END----list---------->
//<--------START----rgb_stuff-------->
function getY2kSafeYear()
{	
	var theYear = this.getYear();
	if (theYear< 999)
		theYear += 1900;
	return theYear;
}
Date.prototype.getY2kSafeYear = getY2kSafeYear;

function view_media(id, param, local, pathEnum)
{
	var url = 'media_viewer.asp?id='+id;
	if (local)
		url = 'media_viewer.asp?id='+id;
	if (param)
		url += '&'+param
	if (pathEnum)
		url += '&path='+pathEnum
	window.location = url;
}

function view_biog(id,path)
{
	var page = 'biog.asp?id='+id;
	var url = (path)? path+"/"+page : page;
	win = window.open(url, 'biog_win', 'status,resizable,scrollbars,toolbar,menubar,menubar="yes",toolbar="yes",width=520,height=400,');
	if (!win.opener) win.opener = self;
	win.opener = self;
}

function inBasket(id)
{
	var mediaCookie = getCookie('media');
	var mediaList = (mediaCookie!=null && mediaCookie!='')?new List(mediaCookie):new List();
	return mediaList.inList(id);
	
}

function basketAdd(id)
{
	var mediaCookie = getCookie('media');
	var mediaList = (mediaCookie!=null && mediaCookie!='')?new List(mediaCookie):new List();
	if (!mediaList.inList(id))
	{
		var newList = mediaList.add(id);
		var now = new Date();
		var expires = new Date();
		expires.setYear(now.getY2kSafeYear() + 1);
		setCookie('media',newList.listData,expires,'/');
	}
	view_lightbox();
}

function basketRemove(id)
{
	var mediaCookie = getCookie('media');
	if (mediaCookie !=null && mediaCookie != '')
	{
		var mediaList = new List(mediaCookie);
		if (mediaList.inList(id))
		{
			var newList = mediaList.remove(id);
			var now = new Date();
			var expires = new Date();
			expires.setYear(now.getY2kSafeYear() + 1);
			setCookie('media',newList.listData,expires,'/');
		}
	}
}

function getBasket()
{
	var mediaCookie = getCookie('media');
	return mediaCookie;
}

function emptyBasket()
{
	deleteCookie('media','/');
}

function view_lightbox()
{
	winL = window.open('lightbox.asp', 'lbox_win', 'status,resizable,scrollbars,toolbar,menubar,menubar="yes",toolbar="yes",width=520,height=400,');
	if (!winL.opener) winL.opener = self;
	winL.opener = self;
}
//<--------END----rgb_stuff---------->
