var gEXIFCookieName = "echeng.com.alwaysshowexif";
var gIMAGELISTCookieName = "echeng.com.alwaysshowimagelist";
var fAlwaysShowEXIF;
var fAlwaysShowIMAGELIST;
var bikky = document.cookie;

function getCookie(name) { // use: getCookie("name");
	var index = bikky.indexOf(name + "=");
	if (index == -1) return null;
	index = bikky.indexOf("=", index) + 1;
	var endstr = bikky.indexOf(";", index);
	if (endstr == -1) endstr = bikky.length;
	return unescape(bikky.substring(index, endstr));
}

function getEXIFCookie() {
   var exifCookie = getCookie (gEXIFCookieName);

   if (exifCookie == null || exifCookie == "0")
	fAlwaysShowEXIF = false;
   else if (exifCookie == "1") fAlwaysShowEXIF = true;

   return exifCookie;
}

function getIMAGELISTCookie() {
   var theCookie = getCookie (gIMAGELISTCookieName);

   if (theCookie == null || theCookie == "0")
	fAlwaysShowIMAGELIST = false;
   else if (theCookie == "1") fAlwaysShowIMAGELIST = true;

   return theCookie;
}

var today = new Date();
var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000); // plus one year days

function setEXIFCookie(name, value) { // use: setCookie("name", value);
	if (value != null && value != "")
	  document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString();
	bikky= document.cookie; // update bikky
}

function toggleAlwaysShowEXIF() {
	var myCookie = getEXIFCookie();

	fAlwaysShowEXIF = !fAlwaysShowEXIF;
	setEXIFCookie(gEXIFCookieName, fAlwaysShowEXIF ? "1" : "0");

	// refresh the screen
	window.location.reload( false );
}

function setEXIFCookie(name, value) { // use: setCookie("name", value);
	if (value != null && value != "")
	  document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString();
	bikky= document.cookie; // update bikky
}

function toggleAlwaysShowEXIF() {
	var myCookie = getEXIFCookie();

	fAlwaysShowEXIF = !fAlwaysShowEXIF;
	setEXIFCookie(gEXIFCookieName, fAlwaysShowEXIF ? "1" : "0");

	// refresh the screen
	window.location.reload( false );
}

function toggleAlwaysShowIMAGELIST() {
	var myCookie = getIMAGELISTCookie();

	fAlwaysShowIMAGELIST = !fAlwaysShowIMAGELIST;
	setEXIFCookie(gIMAGELISTCookieName, fAlwaysShowIMAGELIST ? "1" : "0");

	// refresh the screen
	window.location.reload( false );
}

// init exif cookie, if we have to
getEXIFCookie();
getIMAGELISTCookie();
