/* 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 && window.location.href.indexOf("/upload") == -1)
    {
        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("sddm").innerHTML = document.getElementById("sddm").innerHTML+" 	<li><a href=\"/console\" onmouseover=\"mopen(\'ma\')\" onmouseout=\"mclosetime()\">Admin</a><div id=\"ma\" onmouseover=\"mcancelclosetime()\" onmouseout=\"mclosetime()\"><a href=\"/console\">Console</a><a href=\"/page/show/36084\">Export Calendar</a></div></li>";
    
    }
    
    if (document.getElementById("guildApplicationsNib") != null)
    {
        //document.getElementById("guildApplicationsNib").innerHTML = document.getElementById("guildApplicationsNib").innerHTML.replace("Apply Now","Apply Here");
    }



    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://s.guildomatic.com/885/host/3c/3c2c089587419676406f4982a54ec775.gif'></td><td id='col2head'>&nbsp;</td><td id='col3head'><img src='http://s.guildomatic.com/885/host/b1/b1a74338fe1107bbe139939f0a5309f6.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://s.guildomatic.com/885/host/3c/3c2c089587419676406f4982a54ec775.gif'></td><td id='col2head'>&nbsp;</td><td id='col3head'><img src='http://s.guildomatic.com/885/host/b1/b1a74338fe1107bbe139939f0a5309f6.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://s.guildomatic.com/885/host/8f/8f6d985e465b665bfb969599c05503a0.gif)'><img src='http://s.guildomatic.com/885/host/91/91dc4dbd7246fca27dcd855f279676e5.gif'></td>";
        middleCol = "<td id='bottomMiddle' style='background-image:url(http://s.guildomatic.com/885/host/8f/8f6d985e465b665bfb969599c05503a0.gif)'><div id='copyLine'>" + newCopyLine + bottomLine.innerHTML + "</div></td>";
        rightCol = "<td id='bottomRight' style='background-image:url(http://s.guildomatic.com/885/host/8f/8f6d985e465b665bfb969599c05503a0.gif)' ><img src='http://s.guildomatic.com/885/host/b8/b8be1c2534d4948c110dfa354a377918.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;
		
}



