// External JavaScript Resource for MadPics.co.uk
// Last modified 25 June 2002 by Julian Madle

function read_cookie(key) {
	// Return value of cookie specified in key, else return "Empty"
	var cookie_string = "" + document.cookie;
	var cookie_array = cookie_string.split("; ");
	for (var i = 0; i < cookie_array.length; ++ i) {
		var single_cookie = cookie_array[i].split("=");
		if (single_cookie.length != 2) {continue}
		var name  = unescape (single_cookie [0]);
		var value = unescape (single_cookie [1]);
		if (key == name) {return value}
		}
	return "Empty";
	}

function write_cookie(name, value, path, hoursTillExpire) {
	// Write cookie, path optional
	var expiration_date = new Date();
	expiration_date . setHours (expiration_date.getHours() + hoursTillExpire);
	expiration_date = expiration_date.toGMTString();
	var cookie_string = escape(name) + "=" + escape(value) + "; expires=" + expiration_date;
	if (path != null) {cookie_string += "; path=" + path}
	document.cookie = cookie_string;
	}

function journal_jump(pagenameTemplate) {
	// Give user option to resume reading from previously visited page
	var PageNumber = read_cookie('JournalPage');
	if ((PageNumber != "") && (PageNumber != "Empty")) {if (confirm("Start reading from where you left off last time?")==true) {document.location = pagenameTemplate + PageNumber + ".asp"; return}}
	document.location = pagenameTemplate + "1.asp";
	}

function addToBasket(photoID) {
	// Opens AddToBasket page in a positioned window
	var x = 0, y = 0;
	if (document.all) {
		y = window.screenTop + 10;
		x = window.screenLeft + 10;
		}
	else if (document.layers) {
		x = window.screenX + 10;
		y = window.screenY + 10;
		}
	var popup = window.open('basketadd.asp?' + photoID,'BasketAdd','width=360,height=160,top='+y+',screenY='+y+',left='+x+',screenX='+x);
	}

function copyrightAlert() {alert("All photographs appearing in this web site are under the protection of International copyright laws. The photographs may not be reproduced, copied, stored, manipulated or used whole or in part of a derivate work without the written permission of Julian Madle or one of his agents. No images are within Public Domain. Use of any image as the basis for another photographic concept or illustration is a violation of copyright. Unauthorized use is subject to severe civil and criminal penalties under applicable laws.")}

function confirmDelete(delIndex) {if (confirm("Are you sure you want to remove this item?")) {document.forms[0].action="basket.asp?Action=DEL&Index=" + delIndex;document.forms[0].submit()}}

function confirmAbandon() {if (confirm("Are you sure you want to completely empty the basket?")) {window.location.href="basket.asp?Action=ABN"}}

function checkOrder() {
	if (document.forms[0].ContactName.value=="") {document.forms[0].ContactName.focus(); alert("Please enter your name"); return}
	var fieldStr = document.forms[0].ContactEmail.value;
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	if ((reg1.test(fieldStr)==false) && (reg2.test(fieldStr)==false)) {alert("Your email address must be valid\nie: name@domain.com"); document.forms[0].ContactEmail.focus(); return true}
	document.forms[0].action="thanks.asp";
	document.forms[0].submit();
	}

function sendOrder() {document.forms[0].action="basket.asp?Action=SEND";document.forms[0].submit()}

function changeKeyList(thisPos) {
	// This function is IE only!

	// Remove current OPTIONs from Keyword form element
	for (i=document.forms[0].Keyword.options.length; i>=0; i--) {document.forms[0].Keyword.options.remove(i)}

	// Add new OPTIONs
	for (i=0; i<keyArray[thisPos].length; i++) {
		var newElem = document.createElement("OPTION");
		newElem.text = keyArray[thisPos][i];
		newElem.value = keyArray[thisPos][i];
		document.forms[0].Keyword.options.add(newElem);
		}
	}
