// System iNetwork Color Changer
// version 0.1 BETA!   2009-03-09 
// --------------------------------------------------------------------
// Copyright (c) 2009, Scott C. Klement
// All rights reserved.
// 
// Redistribution and use in source and binary forms, with or without 
// modification, are permitted provided that the following conditions 
// are met:
// 
//     * Redistributions of source code must retain the above copyright 
//         notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright 
//         notice, this list of conditions and the following disclaimer 
//         in the documentation and/or other materials provided with the 
//         distribution.
//     * Neither the name of the Scott C. Klement nor the names of its 
//         contributors may be used to endorse or promote products derived
//         from this software without specific prior written permission.
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
// TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://greasespot.net/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "System iNetwork Colors", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name          System iNetwork Colors
// @namespace     http://www.scottklement.com/scripts/
// @description   Change the color scheme in System iNetwork Forums
// @include       http://forums.systeminetwork.com/*
// ==/UserScript==

// GM_addStyle('.sck:link { color: #22229C ! important; }');
GM_addStyle('.sck:visited { color: #88801E ! important; }');
GM_addStyle('.sckbutton { position:absolute; z-index:9999; top:2px; left:2px; overflow:hidden; }');

var allLinks, thisLink, modColors, buttonText;

modColors=GM_getValue("modify","on");
buttonText = "Modify Page";

if (modColors == "on") {
   buttonText = "Original Page";
   allLinks = document.evaluate(
       '//a[@href]',
       document,
       null,
       XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
       null);

   for (var i = 0; i < allLinks.snapshotLength; i++) {
       thisLink = allLinks.snapshotItem(i);
       if (thisLink.href.indexOf('forumdisplay.php?f=') != -1) {
            thisLink.className="sck";
       }
       else if (thisLink.href.indexOf('showthread.php?') != -1) {
            thisLink.className="sck";
       }
   }
   document.body.style.backgroundImage = "none";
   document.body.style.backgroundColor = "black";
   document.getElementById("topAd").innerHTML =
     '<p><form method="GET" action="http://www.google.com/search">' +
     '<input id="sck2" type="button" value="New Posts">' +
     '<input id="sck3" type="button" value="Posted Today">' +
     '<input id="sck4" type="button" value="Top Posters">' +
     '<input id="sck5" type="button" value="Link to PostCode">' +
     '&nbsp;&nbsp;' +
     '<input type="text" name="q">' +
     '<input type="hidden" name="sitesearch" value="forums.systeminetwork.com">' +
     '<input type="submit" value="Forum Google!">' +
     '</form></p>';
}


var sckButtDiv = document.createElement('div');
sckButtDiv.innerHTML = 
     '<form class="sckbutton" method="GET" action="#">' +
     '<input id="sck1" type="button" value="' + buttonText + '">' +
     '</form>';
document.body.insertBefore(sckButtDiv, document.body.firstChild);
sckButtDiv.style.fontSize = 'small';
sckButtDiv.style.textAlign = 'left';

var butt = document.getElementById("sck1");
butt.addEventListener('click', function(event) {
   var buttonText, modColors;
   modColors = GM_getValue("modify", "on");
   if (modColors=="on") {
      modColors="off";
   } else {
      modColors="on";
   }
   GM_setValue("modify", modColors);
   location.reload();
}, true);

butt = document.getElementById("sck2");
butt.addEventListener('click', function(event) {
   location.href="http://forums.systeminetwork.com/isnetforums/search.php?do=getnew";
}, true);

butt = document.getElementById("sck3");
butt.addEventListener('click', function(event) {
   location.href="http://forums.systeminetwork.com/isnetforums/search.php?do=getdaily";
}, true);

butt = document.getElementById("sck4");
butt.addEventListener('click', function(event) {
   location.href="http://forums.systeminetwork.com/isnetforums/memberlist.php?order=DESC&sort=posts&pp=100";
}, true);

butt = document.getElementById("sck5");
butt.addEventListener('click', function(event) {
   var message = document.getElementById("vB_Editor_001_textarea");
   if (message != null) {
      message.value = message.value + "http://forums.systeminetwork.com/isnetforums/showthread.php?t=45452";
      message.focus();
   }
}, true);



// GM_xmlhttpRequest({
//   method:"GET",
//   url:"http://www.scottklement.com/batchfile",
//   headers:{
//     "User-Agent":"Mozilla/5.0",            // Recommend using navigator.userAgent when possible
//     "Accept":"text/xml"
//   },
//   onload:function(response) {
//     alert(response.responseText);
    // if you need a responseXML
    // var responseXML = new DOMParser().parseFromString(response.responseText, "text/xml");
//   }
// });
