/**
* @author PeanutC
* @version 0.0.0.2
*/
function installEvent( eventname, callback, owner )
{
if( typeof( owner ) == "undefined" )owner = window;
if( owner.addEventListener )owner.addEventListener( eventname, callback, false );
else if( owner.attachEvent )owner.attachEvent( 'on'+eventname, callback );
}
function onPageLoad( funcref )
{
installEvent( "load", funcref );
}
function reset( tagname )
{
var tags = document.getElementsByTagName( tagname );
for( var x in tags )
{
tags[x].outerHTML = tags[x].outerHTML;
}
}
function resetPlugins()
{
reset( "embed" );
reset( "object" );
}
function scaleImg( img, fac )
{
var w = img.width*fac;
var h = img.height*fac;
img.width = w;
img.height = h;
}
function scale_iotw(event)
{
event = event ? event : window.event;
var target = event.currentTarget ? event.currentTarget : event.srcElement;
var im_week = target;
if( im_week.width > iotw_maxwidth )scaleImg( im_week, iotw_maxwidth /im_week.width );
if( im_week.height > iotw_maxheight )scaleImg( im_week, iotw_maxheight/im_week.height );
}
function insert_iotw()
{
var logo_tag = document.getElementById( "logostrip" );
if( !logo_tag )return;
var wrapper = document.createElement( "div" );
wrapper.className = "iotw";
var im_week = document.createElement( "img" );
im_week.src = iotw_image_source;
im_week.alt = iotw_image_alternate;
im_week.title = iotw_mouseover;
im_week.onload = scale_iotw;
im_week.id = "iotw";
var title = document.createElement("p");
title.innerHTML = iotw_title;
var caption = document.createElement("p");
caption.innerHTML = iotw_caption;
wrapper.appendChild( title );
wrapper.appendChild( im_week );
wrapper.appendChild( caption );
logo_tag.appendChild( wrapper );
}
function doIotw()
{
var nav_strip = document.getElementById( 'navstrip' );
var nav_tree = nav_strip.getElementsByTagName( 'a' );
if( nav_tree.length == 1 )insert_iotw();
}
function addButton(
nextSiblingName,
title,
name,
accesskey,
mouseovermessage,
onclick )
{
var button = document.createElement( "input" );
var spacer = document.createTextNode( " " );
button.setAttribute( "value", title );
button.setAttribute( "type", "button" );
button.setAttribute( "name", name );
button.accessKey = accesskey;
button.onmouseover = function(){ document.REPLIER.helpbox.value = mouseovermessage; }
button.onclick = onclick;
button.className = "codebuttons";
var inputs = document.getElementsByTagName( "input" );
for( var x in inputs )
{
if( inputs[x].className )
{
if( inputs[x].className == "codebuttons" )
{
if( inputs[x].name == nextSiblingName )
{
inputs[x].parentNode.insertBefore( button, inputs[x] );
inputs[x].parentNode.insertBefore( spacer, inputs[x] );
}
}
}
}
}
function addUTubeVid(id)
{
var tag =
'[doHTML][/doHTML]';
doInsert( tag, "", false );
}
function addGoogleVid(src)
{
var tag = '[doHTML][/doHTML]';
doInsert( tag, "", false );
}
function onVideoClick()
{
var address = prompt( "Enter full youtube or google video url:\r\neg: http://www.youtube.com/watch?v=ABCDEFG or\r\nhttp://www.video.google.com/googleplayer.swf?docId=ABCDEF", "" );
if( !address )return;
if( address.match( "youtube.com" ) )
{
addUTubeVid( address.split( '?v=' )[1] );
}
else
if( address.match( "video.google." ) )
{
address = address.replace( "videoplay", "googleplayer.swf" );
addGoogleVid( address );
}
else return alert( "unrecognised url type\r\n(you may be able to embed it manually with the [doHTML] tags)" );
}
function videoButton()
{
addButton( "email",
video_caption,
video_name,
video_access_key,
video_help_msg,
onVideoClick );
}
function getClassElements( tagname, classname )
{
var el = document.getElementsByTagName( tagname );
var r = Array();
for( var x in el )
{
if( el[x].className == classname )
{
r.push( el[x] );
}
}
return r;
}
function doLolCat( sig )
{
while( sig.childNodes.length )
{
sig.removeChild( sig.firstChild );
}
var i = document.createElement( "img" );
i.src = sig_replacement;
i.alt = "i have a deficient sense of sig height. ARF.";
sig.appendChild( i );
}
function lolcatSigs()
{
var sigs = getClassElements( "div", "signature" );
for( var x in sigs )
{
var nl = true;
var h =0;
for( var y=0; y< sigs[x].childNodes.length; y++ )
{
if( sigs[x].offsetHeight )
if( sigs[x].offsetHeight > maxSigHeight )
{
doLolCat( sigs[x] );
h = -1;
}
}
}
}
function setCookie(name,value,time)
{
var second = 1000;
var minute = second*60;
var hour = minute*60;
var day = hour*24;
var exp = '';
if (time && typeof(time) == "number")
{
var d = new Date();
d.setTime(d.getTime()+(time*hour));
exp = "; expires="+d.toGMTString();
}
document.cookie = name+"="+value+exp+"; path=/";
}
function getCookie( name )
{
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function write_quote(text)
{
var anch = document.getElementById( anch_name );
if( !anch )return;
while( anch.childNodes.length )anch.removeChild( anch.firstChild );
anch.appendChild( document.createTextNode( text ) );
}
function buildQuoteCookie( quote_array )
{
var cookie_open = "["+cookieTag+"]";
var cookie_close = "[/"+cookieTag+"]";
var tagssize = cookie_open.length+cookie_close.length;
var cookie = '';
var maxCookie = 4000;
var result = new Array();
while( quote_array.length )
{
var pick = popRandom( quote_array );
if( cookie.length + (pick.length+tagssize) >= maxCookie )break;
result.push( pick );
cookie+=cookie_open+pick+cookie_close;
if( cookie.length >= maxCookie )break;
}
var cookielife = cookie.length ? cookieLifetime : -1;
setCookie( cookieName, cookie, cookielife );
}
function ajhaxQuoteResult( quote_string )
{
if( !quote_string.length )return;
var quote_array = buildQuotes( quote_string, tagname );
if( !quote_array.length )return;
write_quote( popRandom( quote_array ) );
buildQuoteCookie( quote_array );
}
function popRandom( array )
{
var s = array.length;
var i = Math.round(Math.random()*(s-1));
var a = array[i];
array = array.splice( i, 1 );
return a;
}
function buildQuotes( quote_string, tag )
{
var open_tag = '['+tag+']';
var close_tag = '[/'+tag+']';
var results = Array();
var entry='';
var start =0;
var end = 0;
var x=0;
do
{
start = quote_string.indexOf(open_tag)+open_tag.length;
if( start < open_tag.length )return;
end = quote_string.indexOf( close_tag );
results.push( quote_string.slice( start,end ) );
quote_string = quote_string.slice( end+close_tag.length, quote_string.length);
}while(quote_string.indexOf(open_tag)>=0);
return results;
}
function AJhax( src, onfail, onok )
{
http_request = null;
if( window.XMLHttpRequest )
{
http_request = new XMLHttpRequest();
}
else
if (window.ActiveXObject)
{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
if( !http_request )return onfail("ajax it not working sorry");
http_request.onreadystatechange = function()
{
switch( http_request.readyState )
{
case 4:
switch( http_request.status )
{
case 200:
return onok( http_request.responseText );
default:
return onfail("-");
}
break;
}
}
http_request.open( "GET", src, true );
http_request.send( null );
}
function loadQuote()
{
write_quote( "" );
var cached = getCookie( cookieName );
if(cached && cached.length)
{
var quote_array = buildQuotes( cached, cookieTag );
if( quote_array.length )
{
write_quote( popRandom( quote_array ) );
buildQuoteCookie( quote_array );
}
}
else
{
AJhax( thread_src, write_quote, ajhaxQuoteResult );
}
}
function installBobby()
{
var pn = document.getElementById( "userlinks" );
if( !pn )return;
var dv = document.createElement( "div" );
var ic = document.createElement( "img" );
var sp = document.createElement( "span" );
ic.src = bob_img;
ic.alt = "TMNT";
ic.onclick = loadQuote;
dv.className = "bobbyquote";
sp.id = anch_name;
sp.innerHTML = "loading...";
dv.appendChild( ic );
dv.appendChild( sp );
pn.parentNode.insertBefore(dv, pn);
loadQuote();
}
function TMNT()
{
var text = prompt( "OH OK you enter quoted now" );
if( !text )return;
var tag = "[doHTML]"+text+"[/doHTML]";
doInsert( tag, "", false );
}
function addTMNTButton()
{
addButton( "QUOTE",
tmnt_button_title,
tmnt_button_name,
tmnt_button_access_key,
tmnt_button_help_msg,
TMNT
);
}
onPageLoad( resetPlugins );
onPageLoad( doIotw );
//onPageLoad( installBobby );
onPageLoad( videoButton );
onPageLoad( lolcatSigs );
onPageLoad( addTMNTButton );