// <script language="JavaScript">

// <!-- Begin

// ** Random Image Display

var rand1 = 0;
var useRand = 0;

images = new Array;
images[1] = new Image();
images[1].src = "lima/Alameda-Barranco-Lima.jpg";
images[2] = new Image();
images[2].src = "lima/Arquitectura-Colonial-Lima.jpg";
images[3] = new Image();
images[3].src = "lima/Caballos-de-Paso-Lima.jpg";
images[4] = new Image();
images[4].src = "lima/Paseo-de-Aguas-Lima.jpg";
images[5] = new Image();
images[5].src = "lima/Catedral-de-Lima.jpg";
images[6] = new Image();
images[6].src = "lima/Catedral-Lima.jpg";
images[7] = new Image();
images[7].src = "lima/Convento-de-Santo-domingo-lima.jpg";
images[8] = new Image();
images[8].src = "lima/Corrida-de-Toros-Lima.jpg";
images[9] = new Image();
images[9].src = "lima/Costa-Verde-Lima.jpg";
images[10] = new Image();
images[10].src = "lima/El-festejo-Lima.jpg";
images[11] = new Image();
images[11].src = "lima/Iglesia-de-Barranco-Lima.jpg";
images[12] = new Image();
images[12].src = "lima/Alameda-Barranco-Lima.jpg";
images[13] = new Image();
images[13].src = "lima/Iglesia-san-Francisco-Lima.jpg";
images[14] = new Image();
images[14].src = "lima/Incahuasi-canete-Lima.jpg";
images[15] = new Image();
images[15].src = "lima/la-Costa-Verde-Lima.jpg";
images[16] = new Image();
images[16].src = "lima/Ruinas-Pachacamac-Lima.jpg";
images[17] = new Image();
images[17].src = "lima/Palacio-de-Gobierno-Lima.jpg";
images[18] = new Image();
images[18].src = "lima/Incahuasi-canete-Lima.jpg";
images[19] = new Image();
images[19].src = "lima/Pachacamac2-Lima.jpg";
images[20] = new Image();
images[20].src = "lima/Palacio-arzobispal-Lima.jpg";

function swapPic() {
var imgnum = images.length - 1;
do {
var randnum = Math.random();
rand1 = Math.round((imgnum - 1) * randnum) + 1;
} while (rand1 == useRand);
useRand = rand1;
document.randimg.src = images[useRand].src;
}

// ** bookmark functions

var sepchar   = "@";	// unique separator character
var BMtotal   = 6;	// max number of bookmarks permitted
var ShowCount = 0;
var expDays   = 30;	// cookie variables - expiry # days

var exp       = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function ListBookmarks()
{
	var NumBookmarks = GetCookie('PT_NumBookmarks');
	var i;
	var Bookmark;

	// alert("ListBookMarks started");

	if (NumBookmarks == null) 
	{
		NumBookmarks = 0;
	}
	ShowCount = 0; SwapColour = 0;
 
	for (i=1; i <= NumBookmarks ; i++)
	{
		Bookmark = GetCookie('PT_Bookmark'+i);
		if (Bookmark != null)
		{
			PrintBookmark(Bookmark, i);
		}
	}
}

function DeleteBookmark(Count)
{
	DeleteCookie('PT_Bookmark'+Count);
	window.location = window.location;
}

function PrintBookmark (Bookmark, Count)
{

	var color = "";
	//alert("hello 6");
	var pairs = Bookmark.split(sepchar);
	pairs[0]= unescape(pairs[0]);
	pairs[1]= unescape(pairs[1]);
	// alert(Bookmark+" "+sepchar);
	var BMtitle = pairs[0];
	var BMaddress = pairs[1];
	//alert(BMaddress);

	// SwapColour = 1 - SwapColour;
	// if (SwapColour==1) {color = "bgcolor='#c0c0c0'"} ;	

	ShowCount++;
	document.write("<table border=0 width=100% cellspacing=0 cellpadding=3><tr>");
	document.write("<td>"+"<a href='javascript:DeleteBookmark(" + Count + ")'>&nbsp;<img border=0 alt='remove link' src='http://www.sudamerika.biz/images/common/xbox.gif'></a></td>");
	//alert("hmmm");
	document.write("<td width=80%><a href='"+BMaddress+"'>"+BMtitle+"</a></td></tr></table>");
	//document.write("");
}

function AddBookmark(BMtitle, BMaddress)
{

	var NumBookmarks = GetCookie('PT_NumBookmarks');
	var i;
	var ToDoItem;
	var Bookmark;
	var OldestBookmark = 0;
	var CountBookmarks = 0;

	if (NumBookmarks == null) 
	{	NumBookmarks = 0;	}
	
	// check if already exists, and count bookmarks 
	for (i=1; i <= NumBookmarks ; i++)
	{
		Bookmark = GetCookie('PT_Bookmark'+i);
		if (Bookmark != null) 
		{	CountBookmarks++;			
			if (OldestBookmark == 0)
			{	OldestBookmark = i;	}	
		}
	
		if (Bookmark == BMtitle+sepchar+BMaddress)
		{	alert("Bookmark added for "+BMtitle);
			return;			}
	}

	// check if limit reached
	if (CountBookmarks > BMtotal)
	{	DeleteBookmark(OldestBookmark);
	}

	// now add it
	NumBookmarks++;
	//alert('PT_Bookmark'+NumBookmarks);
	SetCookie('PT_Bookmark'+NumBookmarks, BMtitle+sepchar+BMaddress, exp);
	SetCookie('PT_NumBookmarks',NumBookmarks, exp);
	alert("'"+BMtitle+"' bookmark has been added to your bookmarks list in the (grey) page margin, scroll down to see it.");
	window.location = window.location;
}

// cookie functions

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;
}

function SetCookie (name, value) {  

	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  

	document.cookie = name + "=" + escape (value) + 
			((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
			((path == null) ? "" : ("; path=" + path)) +  
			((domain == null) ? "" : ("; domain=" + domain)) +    
			((secure == true) ? "; secure" : "");

}

function DeleteCookie (name) {  

	var exp = new Date();  

	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

	//  End -->

// </script>
