function ShowSaved()
{

    var container = document.getElementById("Favourites");
    if (container !=null)
    {
    	container.innerHTML="";
    
	    var cookies = document.cookie.split(";");
		var i=0
	
	    for (var x=0;x<cookies.length;x++)
	    {
	        c=cookies[x];	

	        if (c.indexOf("JAG_")!=-1)
	        {
	          var bits = c.split("=");
	          var bits2 = bits[1].split("!");

			  var cook = "\""+bits[0]+"\"";

	          container.innerHTML = container.innerHTML + "<div style='padding-top:0px;float:left;cursor:hand' onclick='Remove("+cook+");'><img src='/images/GreyDelete.gif' alt='Remove Saved Page' title='Remove Saved Page'/></div><div style='float:left;padding-top:0px;'><a href='"+unescape(bits2[1])+"'>"+unescape(bits2[0])+"</a></div><div style='clear:both'></div>";
			  i++;
	        }
	    }
	    
	    var pageCount = document.getElementById("pageCount") ;
	    pageCount.innerHTML="("+i+")";   
    } 

}



function Remove( name ) 
{
var url="";
var PageTitle="";
var c = name+"=" + escape(PageTitle)+"!"+url + ";expires=Thu, 01-Jan-1970 00:00:01 GMT;path=/";
document.cookie = c;
 ShowSaved();
}


function GetNextId(increment)
{

    var previousId=0;

    var cookies = document.cookie.split(";");

    for (var x=0;x<cookies.length;x++)
    {
        if (cookies[x].indexOf("JAG_")!=-1)
        {
	        var bits = cookies[x].split("_");
	        var id = parseInt(bits[1]);
	        if (id>previousId)
		        previousId=id;
        }

    }

    if (increment)
    {
        var newId = previousId+1;
        return newId;
    }
    else    
    {
        return previousId;
    }
}


function PageAlreadySaved(pageurl)
{    
    var cookies = document.cookie.split(";");

    for (var x=0;x<cookies.length;x++)
    {
        if (cookies[x].indexOf("JAG_")!=-1)
        {
	        var bits = cookies[x].split("=");
	        var bits2 = bits[1].split("!");
	        if (unescape(bits2[1])==pageurl)
		{
	            return true;	        
		}
        }
    }
    return false;
}
 
 
function SetCookie()
{

    var PageTitle = document.title;

	if (PageTitle.indexOf("Forums")!=-1)
	{
		PageTitle="Forums";
	}
	else
	{
	    PageTitle = PageTitle.substring(6,PageTitle.length);
	}

    var url = document.location.href;
     
    var theDate = new Date();
    var oneYearLater = new Date( theDate.getTime() + 31536000000 );
    var expiryDate = oneYearLater.toGMTString();

    var Id= GetNextId(true);

    
    if (Id<=10)
    {
         if (!PageAlreadySaved(url))
         {
             // set cookie parameters
             var c = "JAG_"+Id+"=" + escape(PageTitle)+"!"+url + ";expires=" + expiryDate+";path=/";
             // write cookie
             document.cookie = c;
	     alert("This page has been addded to your saved pages, please note that your saved pages will only be available on this PC!");
         }
    }
    else
    {
        alert("Maximum pages you can store is 10");
    }

    
    ShowSaved();
}
 

function DoSearch()
{
	window.location='/search/search.cgi?zoom_query=' + document.getElementById("zoom_query").value;
}
