﻿/* This Javascript actually makes modifications to the HTML in the Guildomatic (GOM) Rendered Pages */

function findElement(ele,theText)
{
   /* Finds an element on the element on the page containing theText from bottom to top */
   var e=document.getElementsByTagName(ele);
   for(var i=e.length-1;i>0;i--)
   {
        if (e[i].innerHTML.indexOf(theText) != -1)
        {
            return e[i];
            break;
        }
   }
}


function init() {
  
    
    if (document.getElementById("pageContent") != null)
    {
        var pageContent = document.getElementById("pageContent").innerHTML;
        document.getElementById("pageContent").innerHTML = "<table id='pageContentTable' cellpadding=0 cellspacing=0><tr><td id='col1'>&nbsp;</td><td id='col2'>"+pageContent+"</td><td id='col3'>&nbsp;</td></tr></table>";
    }

    
    
    if (document.getElementById("adminConsoleContainer") != null)
    {
        /*Add the admin option to the menu if the adminConsoleContainer is here */
        document.getElementById("menuSection").innerHTML = document.getElementById("menuSection").innerHTML+" - <a href='/console'>Admin</a> - <a href='http://valiant.guildomatic.com/page/show/16309'>Banner Admin</a>";
    
    }
    
    if (document.getElementById("guildApplicationsNib") != null)
    {
        //document.getElementById("guildApplicationsNib").innerHTML = document.getElementById("guildApplicationsNib").innerHTML.replace("Apply Now","Apply Here");
    }

    var isForum = findElement("a", "phpBB");
    if (isForum != null) {
        document.getElementById("menuSection").style.left = "0px";
        document.getElementById("flashSection").style.display = "none";
        if (document.getElementById("page") != null) {
            var pageContent = document.getElementById("page").innerHTML;
            document.getElementById("page").innerHTML = "<table id='pageContentTable' cellpadding=0 cellspacing=0><tr><td id='col1'>&nbsp;</td><td id='col2'>" + pageContent + "</td><td id='col3'>&nbsp;</td></tr></table>";
        }
    
        return;
    } else {
    

    }


    if (document.getElementById("pageTitle") != null) {
        var pageTitle = document.getElementById("pageTitle").innerHTML;
        document.getElementById("pageTitle").innerHTML = "<table id='pageTitleTable' cellpadding=0 cellspacing=0><tr><td id='col1head'><img src='http://valiant.wowinsomniac.com/images/bdy-tl.gif'></td><td id='col2head'>&nbsp;</td><td id='col3head'><img src='http://valiant.wowinsomniac.com/images/bdy-tr.gif'></td></tr><tr><td id='col1'>&nbsp;</td><td id='col2'>" + pageTitle + "</td><td id='col3'>&nbsp;</td></tr></table>";
    }

    if (document.getElementById("guildMain") != null) {
        var guildMain = document.getElementById("guildMain").innerHTML;
        document.getElementById("guildMain").innerHTML = "<table id='guildMainHeader' cellpadding=0 cellspacing=0><tr><td id='col1head'><img src='http://valiant.wowinsomniac.com/images/bdy-tl.gif'></td><td id='col2head'>&nbsp;</td><td id='col3head'><img src='http://valiant.wowinsomniac.com/images/bdy-tr.gif'></td></tr></table>" + guildMain;
    }


    /* The last row in the GOM root_table contains only a span for the "Powered by Guildomatic" message.
    And we want to format it with a table so it can house the rounded corner and bottom to our template. */
    var bottomLine = findElement("td", "Powered by");
    if (bottomLine != null) {
        bottomLine.id = "poweredByCol";
        newCopyLine = "DarkBreak by <a target='_blank' href='http://www.dzinerstudio.com'>DzinerStudio</a> adapted to Guildomatic by <b style='font-weight:bold;'>Staxxis of Blackhand<br>";
        leftCol = "<td id='bottomLeft' style='background-image:url(http://valiant.wowinsomniac.com/images/foot-m.gif)'><img src='http://valiant.wowinsomniac.com/images/foot-l.gif'></td>";
        middleCol = "<td id='bottomMiddle' style='background-image:url(http://valiant.wowinsomniac.com/images/foot-m.gif)'><div id='copyLine'>" + newCopyLine + bottomLine.innerHTML + "</div></td>";
        rightCol = "<td id='bottomRight' style='background-image:url(http://valiant.wowinsomniac.com/images/foot-m.gif)' ><img src='http://valiant.wowinsomniac.com/images/foot-r.gif'></td>";
        bottomLine.innerHTML = "<table cellpadding=0 cellspacing=0 id='poweredByTable'>" + leftCol + middleCol + rightCol + "</table>";
    }
    

}

/* This sets our code to run after the page is rendered */
if ((document.title.indexOf("Guild Application Configuration") == -1) && (document.title.indexOf("Parsed Snapshots and Auctions") == -1))
{
    window.onload = init;   
}


