//
//	Copyright © 2005 Juha Leinonen. All Rights Reserved.
//
var kAlbumsBase	= 'picture%20gallery';

// Navigera till indexsidan för aktuell bild
function goindex() {
	// Get get relative part of base path of current url, and add index.htm
	var indexUrl = window.location.href.substring(location.href.lastIndexOf(kAlbumsBase),location.href.lastIndexOf("/") + 1) + 'index.htm';
//	alert('window.location.host= ' + window.location.host + '\n indexUrl=' + indexUrl + '\n curr=\n' + window.location.href);
	WriteCookie("newBodyframeTarget",escape(indexUrl),"","","");
   	window.location.href  = "../../index.html";
}

//jl/051227
//  Innan original body visas, kollas först om det ska vara något annat enligt cookie
function syncbody() {
	var target;
	target = unescape(ReadCookie("newBodyframeTarget"));
	if ((target != "") && (target != window.location) && (target != "EOD")) {
	// avoid empty window or endless loop
		window.location=target;
		WriteCookie("newBodyframeTarget","EOD","","","");
	} 
}


function ReadCookie(name) {
	var allCookie, v1, length, start, end;
	v1 = "";
	name = name + "=";
	allCookie = document.cookie;
	length = allCookie.length;
	if (length > 0) {
		start = allCookie.indexOf(name,0);
		if (start !=-1) {
			start += name.length;
			end = allCookie.indexOf(";",start);
			if (end == -1) { end = length;}
			v1 = unescape( allCookie.substring(start,end));
			}
		}
	return (v1);
}

function WriteCookie( name, value, expires, domain, path, secure) {
	var cv, cx;
	cv = cx="";
	path = "/";
	if (name) {
		cv = cv + escape(name) + "=";
		if (value) {
			cv = cv + escape(value);
			if (path) {
				cv = cv + "; path=" + path;
				}
			if (secure) {
				cv = cv + "; secure=";
				}
			}
		else {
			cx = cx + "Val err";
			}
		}
	else {
		cx = cx + "Name err";
		}
	if (!cx) {
		document.cookie = cv;
		if (value != ReadCookie(name)) {
			cx = "Write err";
			}
		}
	return cx;
	}

