// foi javascript

if(document.images)
{
	download_on = new Image();
	download_on.src = "http://www.foi.org.uk/images/download-button-over.jpg";
	
	
	download_off = new Image();
	download_off.src = "http://www.foi.org.uk/images/download-button.jpg";
	
}

function DownloadOn(img)
{
	if(document.images)
	{
		eval("document."+img+".src = download_on.src");
	}
}

function DownloadOff(img)
{
	if(document.images)
	{
		eval("document."+img+".src = download_off.src");
	}
}

function PopupAndPlay(movie)

	{
	var url = 'moviepopup.php?movie=' + movie;
	var features = 'menubar=0,toolbar=0,location=0,width=320,height=300,left=60,top=5,screenX=150,screenY=5';
	window.open(url,'infopopup',features);
	};
	
//################################# CART CODE #####################################
	
//Get Cookie

function AddCart(ThisOrder)

{

ThisQuantity = 1;
SetCookie(ThisOrder,ThisQuantity);
DisplayCart();

};

function GetCookie()

{	
	cookietemp = unescape(document.cookie);
	CartStr = cookietemp.toString();
	return CartStr;
};	
	
//Set Cookie

function SetCookie(ThisOrder,ThisQuantity)

{
	
	OldOrderCookie="";
	
	if(document.cookie)
		{
		var inc=0;
		//alert(document.cookie);
		cookietemp = unescape(document.cookie);
		OldOrderCookie = cookietemp.toString();
		//chop off order=
		OldOrderCookie = OldOrderCookie.substr(OldOrderCookie.indexOf("=")+1,OldOrderCookie.length);
		
		//go through the cookie and if ThisOrder == one of the current orders then increment the quantity
		
		//split the cookie into array
		OldOrderArray = OldOrderCookie.split('|');
		//loop through elements
		
			for (i=0;i<OldOrderArray.length;i++)
			{
			//alert(OldOrderArray);
			//split each element between item and quantity
			Lthisitem = OldOrderArray[i].substring(0,OldOrderArray[i].indexOf(','));
			Lthisquantity = OldOrderArray[i].substring(OldOrderArray[i].indexOf(',')+1,OldOrderArray[i].length);
			//alert("thiselement: " + OldOrderArray[i] + "\nitem: " + Lthisitem + "\nquantity: " + Lthisquantity + "\nThisOrder: "+ThisOrder);
			//compare and increment
			if (Lthisitem == ThisOrder) 
				{
				Lthisquantity++;
				OldOrderArray[i] = Lthisitem + ',' + Lthisquantity;
				inc=1;
				};
			//put the elements back together again
			//alert("new quantity: " + Lthisquantity + "\nnew element: " + OldOrderArray[i]);
			};
		
		//put the array back together again as a string
		
		OldOrderCookie = OldOrderArray.join('|');
		NewOrderCookie = "order=" + OldOrderCookie;
		if (inc==0) NewOrderCookie = NewOrderCookie + "|" + ThisOrder + "," + ThisQuantity;
		//alert(NewOrderCookie);
		document.cookie = NewOrderCookie;
		}
	else
		{
		document.cookie="order="+ThisOrder+","+ThisQuantity;
		};
	
};
	
//go to shopping cart

function DisplayCart()

{
	//CurrentOrder = GetCookie();
	//alert(CurrentOrder);
	self.location = "cart.php";
	
};	

function SendForm()

	{
	if(document.checkoutform.name.value=="")
		{
		alert("Please specify a Name");
		return;
		};
	if(document.checkoutform.address.value=="")
		{
		alert("Please specify an Address");
		return;
		};
	if(document.checkoutform.postcode.value=="")
		{
		alert("Please specify a Postcode");
		return;
		};
	if(document.checkoutform.country.value=="")
		{
		alert("Please specify a Country");
		return;
		};
	if(document.checkoutform.tel.value=="")
		{
		alert("Please specify a Telephone Number");
		return;
		};
	if(document.checkoutform.email.value=="")
		{
		alert("Please specify an email address");
		return;
		};
	document.checkoutform.submit();
	};

function SendRefForm()

	{
	if(document.refForm.name.value=="")
		{
		alert("Please specify a Name");
		return;
		};
	if(document.refForm.email.value=="")
		{
		alert("Please specify an Email address");
		return;
		};
	
	if(document.refForm.island_dest.value=="")
		{
		alert("Please specify an Island");
		return;
		};
		
	if(document.refForm.date.value=="")
		{
		alert("Please specify a Date");
		return;
		};
		
	if(document.refForm.ref.value=="")
		{
		alert("Please specify where you heard about us");
		return;
		};
	document.refForm.submit();
	};
	
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		corfu_over = newImage("images/corfu-over.jpg");
		paxos_over = newImage("images/paxos-over.jpg");
		lefkas_over = newImage("images/lefkas-over.jpg");
		ithaca_over = newImage("images/ithaca-over.jpg");
		kefalonia_over = newImage("images/kefalonia-over.jpg");
		zak_over = newImage("images/zak-over.jpg");
		kythira_over = newImage("images/kythira-over.jpg");
		preloadFlag = true;
	}
}

preloadImages();
