var receivedCookie = "false";
var loggedCookie = "false";
var sIndiName = "";
var sIndiKey = "";
var bDoPopUp = 0;
var bDoPedIcons = 0;

var hideMarriages = "f";     //  1
var hideDatePlace = "f";     //  2
var hidePlace = "f";         //  3
var hideChildren = "f";      //  4
var hideParents = "f";       //  5
var hideSiblings = "f";      //  6
var hideFamily = "f";        //  7
var hideNotes = "f";         //  8
var hidePhotos = "f";        //  9
var hideSecondFamily = "f";  // 10
var hideAll = "f";           // 11
var hideRepDatePlace = "f";  // 12
var hideRepPlace     = "f";  // 13
var hideRepParents   = "f";  // 14
var hideRepSiblings  = "f";  // 15
var hideRepFamily    = "f";  // 16
var hideRepChildren  = "f";  // 17
var hideRepAll       = "f";  // 18
var sIndividual1 = "hcm920"; 
var sIndividual2 = "jam757";
var sReportType  = "PedigreeReport";
var iGenerations = "4";

var iMaxPriPhotoHeight = 400;
var iMaxPriPhotoWidth  = 400;

dspMarriages = "";
dspDatePlace = "";
dspPlace = "";
dspChildren = "";
dspParents = "";
dspSiblings = "";
dspFamily = "";
dspNotes = "";
dspPhotos = "";
dspSecondFamily = "";
dspAll = "";
bLogged = 0;
bPhotoPage = 0;

function ResetCookie(){
		receivedCookie = "false";
		
		hideMarriages = "f";     //  1
		hideDatePlace = "f";     //  2
		hidePlace = "f";         //  3
		hideChildren = "f";      //  4
		hideParents = "f";       //  5
		hideSiblings = "f";      //  6
		hideFamily = "f";        //  7
		hideNotes = "f";         //  8
		hidePhotos = "f";        //  9
		hideSecondFamily = "f";  // 10
		hideAll = "f";           // 11
		hideRepDatePlace = "f";  // 12
		hideRepPlace     = "f";  // 13
		hideRepParents   = "f";  // 14
		hideRepSiblings  = "f";  // 15
		hideRepFamily    = "f";  // 16
		hideRepChildren  = "f";  // 17
		hideRepAll       = "f";  // 18
		sIndividual1 = "hcm920"; 
		sIndividual2 = "jam757";
		sReportType  = "PedigreeReport";
		iGenerations = "4";
    bDoPopUp = 0;
    bDoPedIcons = 0;
		
		iMaxPriPhotoHeight = 400;
		iMaxPriPhotoWidth  = 400;
		
		dspMarriages = "";
		dspDatePlace = "";
		dspPlace = "";
		dspChildren = "";
		dspParents = "";
		dspSiblings = "";
		dspFamily = "";
		dspNotes = "";
		dspPhotos = "";
		dspSecondFamily = "";
		dspAll = "";
		SetCookie();
} // ResetCookie

function ClearCookie() {
  var exp = new Date();
  var SixtyDays = exp.getTime() + 60*24*60*60*1000;
  var path = "; path=/";
  exp.setTime(SixtyDays);
  var expTime = "; expires=" + exp.toGMTString();
  var value = "@";
	document.cookie =  value + path + expTime;
}


function SetCookie() {
  var exp = new Date();
  var SixtyDays = exp.getTime() + 60*24*60*60*1000;
  //var OneWeek = exp.getTime() + 7*24*60*60*1000;
  //var OneDay = exp.getTime() + 24*60*60*1000;
  //var OneHour = exp.getTime() + 60*60*1000;
  //var TenSeconds = exp.getTime() + 10*1000;
  var path = "; path=/";

    if ((100 > iMaxPriPhotoHeight) || (2000 < iMaxPriPhotoHeight))
				iMaxPriPhotoHeight = 400;
    if ((100 > iMaxPriPhotoWidth) || (2000 < iMaxPriPhotoWidth))
				iMaxPriPhotoWidth = 400;
		if (sIndividual1.length < 6) sIndividual1 = "hcm920";
		if (sIndividual2.length < 6) sIndividual2 = "jam881";
		if (sReportType == "") sReportType = "PedigreeReport";

  exp.setTime(SixtyDays);
  var expTime = "; expires=" + exp.toGMTString();
  var value = "@";
  value += hideMarriages;
  value += hideDatePlace;
  value += hidePlace;
  value += hideChildren;
  value += hideParents;
  value += hideSiblings;
  value += hideFamily;
  value += hideNotes;
  value += hidePhotos;
  value += hideSecondFamily;
  value += hideAll;
	value += hideRepDatePlace;
  value += hideRepPlace;
  value += hideRepParents;
  value += hideRepSiblings;
  value += hideRepFamily;
  value += hideRepChildren;
  value += hideRepAll;
  value += "@";
	if (iMaxPriPhotoHeight < 100) iMaxPriPhotoHeight = 400;
	value += iMaxPriPhotoHeight;
  value += "@";
	if (iMaxPriPhotoWidth < 100) iMaxPriPhotoWidth = 400;	
  value += iMaxPriPhotoWidth;
  value += "@";
	if (sIndividual1.length != 6) sIndividual1 = "hcm920";
  value += sIndividual1;
  value += "@";
	if (sIndividual2.length != 6) sIndividual2 = "jam757";
	value += sIndividual2;
  value += "@";
	if (sReportType.length < 6) sReportType = "PedigreeReport";
  value += sReportType;
  value += "@";
	if (iGenerations < 2) iGenerations = 2;
  value += iGenerations;
  value += "@";
  value += bDoPopUp;
  value += "@";
  value += bDoPedIcons;
  value += "@#";
	document.cookie =  value + path + expTime;
	//document.cookie = path + expTime;
  //alert("Value = " + value + "\nSetCookie= " + document.cookie);
} // SetCookie

function SetCookieVars(hide) {
    var dsp;
    if (hide == "t") {
	dsp = "none";
    } else {
	dsp = "";
    }
    return dsp;
} // SetCookieVars

function GetChar(str) {
    if ((str=="t") || (str=="f")) 
	return(str);
    else
	return("f");
} // GetChar

function LogCookie() {
		if ((loggedCookie=="true") && bPhotoPage) return;
    loggedCookie = "true";
}

function GetCookie() {
		var sCookieData;

    var cStart = document.cookie.indexOf("@");
    var cEnd = document.cookie.indexOf("@#",cStart+1);
    var cEnd2 = document.cookie.indexOf("@@");
    //alert("Getting Cookie");
		if ((cEnd <= 0) || (cEnd2 >= 0)) {
				//alert("Resetting cookie");
				ResetCookie();
				var cStart = document.cookie.indexOf("@");
				var cEnd = document.cookie.indexOf("@#",cStart+1);
        var cEnd2 = document.cookie.indexOf("@@");
				if ((cEnd <= 0) || (cEnd2 >= 0)) {
						//alert("Bad cookie: " + document.cookie);
						ClearCookie();
						return;
				}
		}
		sCookieData = document.cookie.substring(cStart+1,cEnd+2);
		//alert("Cookie: " + sCookieData)

    var cStart = document.cookie.indexOf("@");
    var cEnd = document.cookie.indexOf("@",cStart+1);
    var cData = document.cookie.substring(cStart+1,cEnd);
    if (cData.length != 18) {
				ResetCookie;
				return;
				cData = "";
				for (i=0; i<18; i++)
						cData += "f";
		}
    //alert("GetCookie = " + cData + ", Len=" + cData.length);
    cStart = cEnd + 1;
		//alert("cData: " + cData + ", Cookie: " + document.cookie);
    var cEnd = document.cookie.indexOf("@",cStart+1);
		if (cEnd > 0)
				iMaxPriPhotoHeight = document.cookie.substring(cStart,cEnd);
		else
				iMaxPriPhotoHeight = 400;
    cStart = cEnd + 1;
    var cEnd = document.cookie.indexOf("@",cStart+1);
		if (cEnd > 0)
				iMaxPriPhotoWidth = document.cookie.substring(cStart,cEnd);
		else
				iMaxPriPhotoWidth = 400;
    cStart = cEnd + 1;
    var cEnd = document.cookie.indexOf("@",cStart+1);
		if (cEnd > 0) 
				sIndividual1 = document.cookie.substring(cStart,cEnd);
		else
				sIndividual1 = "hcm920";
    cStart = cEnd + 1;
    var cEnd = document.cookie.indexOf("@",cStart+1);
	  if (cEnd > 0)
				sIndividual2 = document.cookie.substring(cStart,cEnd);
		else
				sIndividual2 = "jam757";
    cStart = cEnd + 1;
    var cEnd = document.cookie.indexOf("@",cStart+1);
		if (cEnd > 0)
				sReportType = document.cookie.substring(cStart,cEnd);
		else
				sReportType = "PedigreeReport";
    cStart = cEnd + 1;
    var cEnd = document.cookie.indexOf("@",cStart+1);
		if (cEnd > 0) {
				iGenerations = document.cookie.substring(cStart,cEnd);
				//alert("cStart" + cStart + ", cEnd: " + cEnd + ", Gen: " + iGenerations);
				if ((iGenerations < 2) || (iGenerations > 999) || (iGenerations.length > 3)) {
						iGenerations = 4;
						//alert("iGenerations : " + iGenerations);
				} else {
						//alert("xiGenerations : " + iGenerations);
				}
       cStart = cEnd + 1;
		} else
				iGenerations = 5;
    var cEnd = document.cookie.indexOf("@",cStart+1);
    if (cEnd > 0){
				bDoPopUp = document.cookie.substring(cStart,cEnd);
        cStart = cEnd + 1;
    }
    var cEnd = document.cookie.indexOf("@",cStart+1);
    if (cEnd > 0){
				bDoPedIcons = document.cookie.substring(cStart,cEnd);
        cStart = cEnd + 1;
    }

		if (sIndividual1.length < 6) sIndividual = "hcm920";
		if (sIndividual2.length < 6) sIndividual2 = "jam881";
		if (sReportType == "") sReportType = "PedigreeReport";

    if ((iMaxPriPhotoHeight < 100) || (iMaxPriPhotoHeight > 2000))
				iMaxPriPhotoHeight = 400;
    if ((iMaxPriPhotoWidth < 100) || (iMaxPriPhotoWidth > 2000))
				iMaxPriPhotoWidth = 400;
    //alert("Height: " + iMaxPriPhotoHeight + ", Width: " + iMaxPriPhotoWidth);

    hideMarriages = GetChar(cData.substring(0,1));
    dspMarriages = SetCookieVars(hideMarriages);
    hideDatePlace = GetChar(cData.substring(1,2));
    dspDatePlace = SetCookieVars(hideDatePlace);
    hidePlace = GetChar(cData.substring(2,3));
    dspPlace = SetCookieVars(hidePlace);
    hideChildren = GetChar(cData.substring(3,4));
    dspChildren = SetCookieVars(hideChildren);
    hideParents = GetChar(cData.substring(4,5));
    dspParents = SetCookieVars(hideParents);
    hideSiblings = GetChar(cData.substring(5,6));
    dspSiblings = SetCookieVars(hideSiblings);
    hideFamily = GetChar(cData.substring(6,7));
    dspFamily = SetCookieVars(hideFamily);
    hideNotes = GetChar(cData.substring(7,8));
    dspNotes =  SetCookieVars(hideNotes);
    hidePhotos = GetChar(cData.substring(8,9));
    dspPhotos = SetCookieVars(hidePhotos);
    hideSecondFamily = GetChar(cData.substring(9,10));
    dspSecondFamily = SetCookieVars(hideSecondFamily);
    hideAll = GetChar(cData.substring(10,11));
    dspAll = SetCookieVars(hideAll);
		hideRepDatePlace = GetChar(cData.substring(11,12));
		hideRepPlace = GetChar(cData.substring(12,13));
		hideRepParents = GetChar(cData.substring(13,14));
		hideRepSiblings = GetChar(cData.substring(14,15));
		hideRepFamily = GetChar(cData.substring(15,16));
		hideRepChildren = GetChar(cData.substring(16,17));
    hideRepAll = GetChar(cData.substring(17,18));
    receivedCookie = "true";
		if (loggedCookie == "false")
				LogCookie();
} // GetCookie

GetCookie();

var bcookieloaded = true;
