function getCookieValue(cookieName)
{
	var cookieValue = document.cookie;
	var cookieStartsAt = cookieValue.indexOf(" "+ cookieName+"=");
	if (cookieStartsAt == -1)
	{
		cookieStartsAt = cookieValue.indexOf(cookieName+"=");
	}
	if (cookieStartsAt == -1)
	{
		cookieValue = null;
	}else {
		cookieStartsAt = cookieValue.indexOf("=", cookieStartsAt)+1;
		var cookieEndsAt = cookieValue.indexOf(";",cookieStartsAt);
		if (cookieEndsAt == -1)
		{
			cookieEndsAt = cookieValue.length;
		}
			cookieValue = unescape(cookieValue.substring(cookieStartsAt,cookieEndsAt))
		}
	return cookieValue;
}

function setCookieValue(name,value,path,expires,domain,secure) {

    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires : "") +
        ( (path) ? ";path=" + path : "") +
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

function WishList(name)
{
//*********************************************************
//*          WishList Object                              *
//*          ===============                              *
//*   Properties                                          *
//*   lifetime - Wishlist cookie lifetime (Months)        *
//*   maxsize - Maximium number of items in list          *
//*   list - Array containing the items in the wishlist   *
//*                                                       *
//*   addItem - Add item to list                          *
//*   dropItem - Drop item from the list                  *
//*   isEmptyList - Check if the list is empty            *
//*   isFull - Check if list is full                      *
//*   showItems - Display items in the list               *
//*   getListContents - Get the list contents from cookie *
//*   setListContents - Write list array to list cookie   *
//*   dropList - Flush entire wishlist                    *
//*                                                       *
//*********************************************************
this.name = name
this.lifetime = 1
this.maxsize=5
this.list = new Array()
WishList.prototype.addItem = addItem
WishList.prototype.dropItem = dropItem
WishList.prototype.isEmptyList = isEmptyList
WishList.prototype.isFullList = isFullList
WishList.prototype.showItems = showItems
WishList.prototype.getListContents = getListContents
WishList.prototype.setListContents = setListContents
WishList.prototype.dropList = dropList

this.getListContents()

//************************************************************
//*   Method : dropList(f,pfx)                               *
//*	  Parameters : f =  form object containing checkbox used *
//*                to select wishlist items.                 *
//*                pfx = Prefix for names of chkbox objects  *
//*                representing each wishlist item.          *
//*   Returns: None                                          *
//*   Synopsis: Deletes all entries in the wishlist          *
//************************************************************
function dropList(f,pfx)
{


ix=0
pageItems = eval('f.'+pfx+'Items.value')
for (ix=1;ix <= pageItems;ix++)
{
	e = eval('f.' + pfx + ix )
	if (e.checked)
	{
		e.checked = false;
	}

}
pageItems = 0
this.list.length = 0;
this.list[0]= "";
this.setListContents()
}



function getListContents()
{
	var wshCookie = getCookieValue(this.name)
	if (wshCookie!=null)
	{
		this.list = wshCookie.split("~")
		this.list.length--
        if(this.list[0]=="" || this.list[0]==null){this.list[0]=""}
	}else{
		this.list[0]=""
	}

}



function isFullList()
{
	return(this.list.length >= this.maxsize)
}

function isEmptyList()
{
var isEmpty
	if (this.list[0]=="")
	{
		isEmpty = true
	}
	else
	{
		isEmpty = false
	}
return(isEmpty)
}

function addItem(Item,f,pfx)
{
	if(this.isFullList())
    {
    	alert('Maximum 5 items in Wish List')
        eval('f.'+pfx+Item+'.checked=false')
    }
    else
    {
	pageItems = eval('f.'+pfx+'Items.value')
	if(this.isEmptyList())
    {
    	this.list[0]=Item
        pageItems++

    }
    else
    {
		found=false;
		for (z in this.list)
    	{
    		if (this.list[z]==Item)
        	{
        		found = true;

        	}
    	}

		if (!found)
   	   	{
    		this.list[this.list.length] = Item;
            pageItems++
    	}
    }
        this.setListContents()
    }
}

function dropItem(Item,f,pfx)
{

    found=false;
	for (z in this.list)
    {
    	if (found)
        {
        	this.list[z-1]=this.list[z]
        }
    	if (this.list[z]==Item)
        {
        	found=true;
            i=z
        }

    }
    if (found)
    {
        this.list.length--
        this.setListContents()
    }
}



function setListContents()
{
	var wshCookie
	var dtToday = new Date()
	dtToday.setMonth(dtToday.getMonth()+this.lifetime)
	var cookieExpires = dtToday.toGMTString()
	if (!this.isEmptyList())
	{

		wshCookie = this.list.join("~")+"~"
	}
	else
	{
		dtToday.setMonth(dtToday.getMonth()-this.lifetime)
		cookieExpires = dtToday.toGMTString()
		wshCookie =""
	}
	setCookieValue(this.name, wshCookie, "", cookieExpires,"","")
}



function showItems()
{
	this.getListContents()
    msg=""
 if(this.list[0]==""){return("")}
 msg = this.list.join(',')

 return(msg)

}
//end of function
}

