// Individual.js
//

function replace(string, text, by)
{
    var i = string.indexOf(text);
    if (string.length == 0)
        return string;
    if ((!i) && (text != string.substring(0, text.length)))
        return string;
    if (i == -1)
        return string;

    var newstr = string.substring(0, i) + by;

    if (i + text.length < string.length)
        newstr += replace(string.substring(i + text.length, string.length), text, by);

    return newstr;
}


function IND_Small_Male(file, ind, begin, end, img)
{
    begin = replace(begin, " ", "&nbsp;");
    end = replace(end, " ", "&nbsp;");

    document.write("<center><table cellspacing=0 cellpadding=1>");
    document.write("<tr><td class=IND_Small_Name>");
    if (file.length > 0) {
        document.write("<a href=\"", file, "\">", ind, "</a></td>");
    }
    else {
        document.write(ind, "</td>");
    }
    if (img.length > 0) {
        document.write("<td rowspan=2><img width=50 height=60 src=\"", img, "\"></td>");
    }
    document.write("</tr><tr><td class=IND_Small_Span>");
    if (begin.length == 0 && end.length == 0) {
        document.write("&nbsp;");
    }
    else if (end.length == 0) {
        document.write("b.&nbsp;", begin);
    }
    else if (begin.length == 0) {
        document.write("d.&nbsp;", end);
    }
    else {
        document.write(begin, " - ", end);
    }
    document.write("</td></tr></table></center>");
}

function IND_Small_Female(file, ind, begin, end, img)
{
    begin = replace(begin, " ", "&nbsp;");
    end = replace(end, " ", "&nbsp;");

    document.write("<center><table cellspacing=0 cellpadding=1><tr>");
    if (img.length > 0) {
        document.write("<td rowspan=2><img width=50 height=60 src=\"", img, "\"></td>");
    }
    document.write("<td class=IND_Small_Name>");
    if (file.length > 0) {
        document.write("<a href=\"", file, "\">", ind, "</a></td></tr>");
    }
    else {
        document.write(ind, "</td></tr>");
    }
    document.write("<tr><td class=IND_Small_Span>");
    if (begin.length == 0 && end.length == 0) {
        document.write("&nbsp;");
    }
    else if (end.length == 0) {
        document.write("b.&nbsp;", begin);
    }
    else if (begin.length == 0) {
        document.write("d.&nbsp;", end);
    }
    else {
        document.write(begin, " - ", end);
    }
    document.write("</td></tr></table></center>");
}

function IND_Small_Child(file, ind, begin, end, img)
{
    begin = replace(begin, " ", "&nbsp;");
    end = replace(end, " ", "&nbsp;");

    document.write("<center><table cellspacing=0 cellpadding=1>");
    document.write("<tr><td class=IND_Small_Name>");
    if (file.length > 0) {
        document.write("<a href=\"", file, "\">", ind, "</a></td></tr>");
    }
    else {
        document.write(ind, "</td></tr>");
    }
    document.write("<tr><td class=IND_Small_Span>");
    if (begin.length == 0 && end.length == 0) {
        document.write("&nbsp;");
    }
    else if (end.length == 0) {
        document.write("b.&nbsp;", begin);
    }
    else if (begin.length == 0) {
        document.write("d.&nbsp;", end);
    }
    else {
        document.write(begin, " - ", end);
    }
    if (img.length > 0) {
        document.write("</tr><tr><td><img width=50 height=60 src=\"", img, "\"></td>");
    }
    document.write("</td></tr></table></center>");
}

function IND_Medium(ind, event1, date1, place1, event2, date2, place2)
{
    document.write("<table cellspacing=0 cellpadding=1>");
    document.write("<tr><td colspan=5 class=IND_Medium_Name>", ind, "</td></tr>");
    document.write("<tr><td class=IND_Medium_Event>", event1, "</td>");
    document.write("<td class=IND_Medium_Token>:</td>");
    document.write("<td class=IND_Medium_Date>", date1, "</td>");
    document.write("<td class=IND_Medium_Token>-</td>");
    document.write("<td class=IND_Medium_Place>", place1, "</td></tr>");
    document.write("<tr><td class=IND_Medium_Event>", event2, "</td>");
    document.write("<td class=IND_Medium_Token>:</td>");
    document.write("<td class=IND_Medium_Date>", date2, "</td>");
    document.write("<td class=IND_Medium_Token>-</td>");
    document.write("<td class=IND_Medium_Place>", place2, "</td></tr>");
    document.write("</table>");
}

function IND_Begin()
{
    document.write("<table cellspacing=0 cellpadding=1><tr>");
}

function IND_End()
{
    document.write("</tr></table>");
}

function IND_Portrait(filename)
{
    document.write("<td class=IND_Portrait>");
    document.write("<img src=", filename, ">");
    document.write("</td>");
}

function IND_Data_Begin()
{
    document.write("<td valign=top><table cellspacing=0 cellpadding=1>");
}

function IND_Data_End()
{
    document.write("</table></td>");
}

function IND_Name(name)
{
    document.write("<tr><td class=IND_Name>", name, "</td></tr>");
}

function IND_EventTable_Begin()
{
    document.write("<tr><td><table cellspacing=0 cellpadding=1 align=left>");
}

function IND_Event_Begin()
{
    document.write("<tr>");
}

function IND_EventType(type)
{
    document.write("<td class=IND_EventType>", type, ":</td>");
}

function IND_Attribute(value)
{
    document.write("<td colspan=2 class=IND_EventPlace>", value, "</td>");
}

function IND_EventDate(date)
{
    date = replace(date, " ", "&nbsp;");
    document.write("<td class=IND_EventDate>", date, "</td>");
}

function IND_EventPlace(place)
{
    place = replace(place, " ", "&nbsp;");
    if (place.length) {
        document.write("<td>-</td>");
        document.write("<td class=IND_EventPlace>", place, "</td>");
    }
    else {
        document.write("<td></td>");
    }
}

function IND_Event_End()
{
    document.write("</tr>");
}


function IND_EventTable_End()
{
    document.write("</table></td></tr>");
}

function IND_SpouseTable_Begin()
{
    document.write("<tr><td><table cellspacing=0 cellpadding=1 align=left>");
}

function IND_Spouse(type, link, name)
{
    document.write("<tr><td class=IND_EventType>", type, ":</td>");
    document.write("<td class=IND_EventPlace>");
    if (link.length > 0) {
        document.write("<a href=\"", link, "\">", name, "<\a>");
    }
    else {
        document.write(name);
    }
    document.write("</td></tr>");
}

function IND_SpouseTable_End()
{
    document.write("</table></td></tr>");
}

function IND_Gallery_Begin(size)
{
    document.write("</tr><tr><td colspan=2 class=IND_Gallery>");
    if (size > 0) {
        document.write("<div class=IND_GalleryScroll>");
    }
    else {
        document.write("<div>");
    }
}

function IND_Gallery_End()
{
    document.write("</div></td>");
}

function IND_Gallery_Item(type, title, link)
{
    switch (type) {
    case 0:
        document.write("<img src=\"photo.gif\">");
        break;
    case 1:
        document.write("<img src=\"text.gif\">");
        break;
    case 2:
        document.write("<img src=\"both.gif\">");
        break;
    }

    document.write("<a href=\"", link, "\">", title, "</a><br>");
}

