// **************************************************
// This is the Temple of Dins common javascript file.
// **************************************************

// **************************************************
// Global variables
// **************************************************

var g_domain = 'templeofdin';
var g_doman_suffix = 'co.uk';
var g_timerID = 0;
var g_timerCount = 0;

// **************************************************
// Breaks out of enclosing frames
// **************************************************

function breakFrames() {
	if (window != top) top.location.href = location.href;
};


// **************************************************
// Breaks out of enclosing frames
// **************************************************

function newBreakFrames() {
	var idx = "0";

	if (top.location.href == "http://www.templeofdin.demon.co.uk/todindex.htm") {
		// Do nothing
		idx = "1";

	} else if (top.location.href == "http://www.templeofdin.demon.co.uk/jollyboys.htm") {
		// Do nothing
		idx = "1";

	} else {
		idx = "0";
	} ;

	// If we've been elcosed in someone elses frame break out.
	if (idx == "0") {
		window.status = "Not from Temple of Din";
		// alert(top.location.href);
		// if (window != top) top.location.href = location.href;
	} else {
		window.status = "From Temple of Din";
	} ;

};

// **************************************************
// Welcome message
// **************************************************

function showWelcomeMessage() {
	var ss1 = new Array(20)
	ss1[0] = "Welcome to the Temple of Din"
	ss1[1] = "Welcome to the Thimble of Dill"
	ss1[2] = "Welcome to the Tadpole of Dung"
	ss1[3] = "Welcome to the Tumbler of Dahl"
	ss1[4] = "Guaranteed free of worthwhile or educational content"
	ss1[5] = "Please stop picking your nose, this is a religious site."
	ss1[6] = "Who ate the last of the chocolade biscuidos ???"
	ss1[7] = "12 electrons were lost whilst loading this page"
	ss1[8] = "Check out the Movie Meister"
	ss1[9] = "Don't blame me.... the Devil made me do it"
	ss1[10] = "Love is the Law, Love under Will"
	ss1[11] = 'Hail Eris !  All hail Discordia ! Praise "Bob" !'
	ss1[12] = "Todays favourite animal is the Cat"
	ss1[13] = "Todays favourite insect is the Walrus"
	ss1[14] = "Help... I'm being held prisoner in your browser's status bar..."
	ss1[15] = "Todays lucky number is 2,145.023"
	ss1[16] = "Todays lucky colour is nine gazelles"
	ss1[17] = "Todays favourite animal is the antelope"
	ss1[18] = "This page is made from hand picked electrons."
	ss1[19] = "This page has been constructed for idiots, by idiots"

	var now = new Date();
	var sec = now.getSeconds();
	var msg = ss1[sec % 19];

	//Show a random message

	window.status=msg;

};

// **************************************************
// Display a random message on a Phantom Creeps page load.
// **************************************************

function showCreepsMessage() {
	var ar = new Array(20)
	ar[0] = "Welcome to Thee Phantom Creeps home page"
	ar[1] = "Armed & Fat records 1998"
	ar[2] = "Have you checked out the Real Audio clips yet ?"
	ar[3] = "We apologise for the shodiness of the photos !"
	ar[4] = "Boo hiss, gerrof...."

	var now = new Date()
	var sec = now.getSeconds()
	var msg = ar[sec % 5]

	window.status=msg
}

// **************************************************
// Display a random message on a WATK page load.
// **************************************************

function showWATKMessage() {
	var ss1 = new Array(20)
	ss1[0] = "We are the nutters, we come from the sea..."
	ss1[1] = "Walter and the Knobheads, Punk Never Ends"
	ss1[2] = "Walter and the Knobheads, Poulton-Le-Fyldes Premier Punk Band"
	ss1[3] = "Walter and the Knobheads use Dolphin Friendly Tuners"
	ss1[4] = "This page is guaranteed to be free of worthwhile or educational content"
	ss1[5] = "Please stop picking your nose, this is a religious site."
	ss1[6] = "Walter and the Knobheads, Poulton-Le-Fyldes Premier Punk Band"
	ss1[7] = "12 electrons were lost whilst loading this page"
	ss1[8] = "Walter and the Knobheads, Poulton-Le-Fyldes Premier Punk Band"
	ss1[9] = "Don't blame the Knobheads.... the Devil made us do it"
	ss1[10] = "Love is the Law, Love under Will"
	ss1[11] = 'Hail Eris !  All hail Discordia ! Praise "Bob" !'
	ss1[12] = "Todays favourite animal is the Cat"
	ss1[13] = "Todays favourite insect is the Walrus"
	ss1[14] = "Help... I'm being held prisoner in your browser's status bar..."
	ss1[15] = "Todays lucky number is 2,145.023"
	ss1[16] = "Todays lucky colour is nine gazelles"
	ss1[17] = "Todays favourite animal is the Carleton antelope"
	ss1[18] = "This page is made from hand picked electrons."
	ss1[19] = "This page has been constructed for idiots, by idiots"

	var now = new Date()
	var sec = now.getSeconds()
	var msg = ss1[sec % 20]

	//Show a random message

	window.status=msg

};

// **************************************************
// Display a random message on Jolly Boys page load.
// **************************************************

function showJBMessage() {
	var ss1 = new Array(11)
	ss1[0] = 'Hip Hip Hooray, for the Knights of the Jolly "J"'
	ss1[1] = "Love is the Law, Love under Will"
	ss1[2] = 'Hail Eris !  All hail Discordia ! Praise "Bob" !'
	ss1[3] = "Could this be the year the Jolly Boys move off last place ?"
	ss1[4] = "When oh when will victory be ours ?"
	ss1[5] = "Help... I'm being held prisoner in your browser's status bar..."
	ss1[6] = "Todays lucky number is 2,145.023"
	ss1[7] = "Todays favourite animal is the frowl (part frog, part owl... all nuts)"
	ss1[8] = "This page is made from hand picked electrons."
	ss1[9] = "This page has been constructed for idiots, by idiots"
	ss1[10] = "Every Jolly Boy is tested and certified as being gallon ready"

	var now = new Date()
	var sec = now.getSeconds()
	var msg = ss1[sec % 10]

	//Show a random message

	window.status=msg

};


// **************************************************
// Email function
// **************************************************

function mailMe(object,recipient) {
    var em_add = 'mailto:' + recipient + '@' + g_domain + "." + g_domain_suffix;

    object.encoding = 'text/plain';
    object.action = em_add
    object.method = 'POST';

};


// **************************************************
// This script checks whether my home server is up 
// by trying to load an image from it.  If it is then 
// redirect to the audio dungeon page.  If not then
// simply show a small "sorry" message.
// **************************************************
function testServerIsUp2() {
//	alert("Setting timeout");
	window.status="Testing for Temple of Din webserver, please wait...";
	g_timerID = setTimeout("testServerCallback()",1000);
}

function testServerCallback() {
	var ImageObject = new Image();
	var Link = "http://templeofdin.dyndns.org/todaudiodungeon.php"

	ImageObject.src= "http://templeofdin.dyndns.org/images/dragon01.gif";

	if (ImageObject.height > 0){
		//alert("Moving page");
		clearTimeout(g_timerID);
		window.location = Link;

	} else if (g_timerCount < 1) {
		// Rety in 5 seconds
		window.status="Temple of Din webserver didn't respond, retrying again in 5 seconds";
		//alert("Temple of Din webserver didn't respond, retrying again in 5 seconds");
		g_timerCount += 1 ;
		window.status="Server down, retrying in 10 seconds";
  	g_timerID = setTimeout("testServerCallback()",5000);

	} else {
		// Counter too large, give up...
		alert("Sorry but the Temple of Din webserver didn't respond, this means it's probably offline");
		clearTimeout(g_timerID);
	};
}

function testServerIsUp1() {
	var ImageObject = new Image();
	var Link = "http://templeofdin.dyndns.org"

	ImageObject.src= "http://templeofdin.dyndns.org/images/dragon01.gif";

	if (ImageObject.height > 0){
		window.location = Link;
	};
}


// **************************************************
// This function chooses one of the liks pages
// **************************************************

function viewRandomLinksPage() {

	var now = new Date()
	var sec = now.getSeconds()
	var idx = [sec % 3]

	if (idx == "0")
		{window.location.href = "todlinkshead.htm";target="main frame";}	

	else if (idx == "1")
		{window.location.href = "todlinkseyeandear.htm";target="main frame";}	

	else if (idx == "2")
		{window.location.href = "todlinksutilities.htm";target="main frame";}	

	else if (idx == "666")
		{window.location.href = "mmzombiedream.htm";target="main frame";}	

};

// **************************************************
// Random link function
// **************************************************

function viewRandomLink() {
   var sslinks = new Array(18);
   
   sslinks[0] = "http://www.subgenius.com"
   sslinks[1] = "http://www.rawilson.com"
   sslinks[2] = "http://www.junkpile.demon.co.uk/prin1.htm"
   sslinks[3] = "http://www.deoxy.org/learyraw.htm"
   sslinks[4] = "http://www.anxietyculture.com/"
   sslinks[5] = "http://www.catnoise.co.uk"
   sslinks[6] = "http://www.private-eye.co.uk"
   sslinks[7] = "http://www.mozilla.org"
   sslinks[9] = "http://www.slackware.com"
   sslinks[10] = "http://www.gunsanddope.com/"
   sslinks[11] = "http://www.slashdot.org/"
   sslinks[12] = "http://www.knplogic.co.uk/are_u_mad.html"
   sslinks[13] = "http://www.frozentech.com/content/livecd.php"
   sslinks[14] = "http://chordfind.com/"
   sslinks[15] = "http://www.no35.dial.pipex.com/KillingJoke/Promos.shtml"
   sslinks[16] = "http://www.framleyexaminer.com/"
   sslinks[17] = "http://freespace.virgin.net/paul.renold/shongers_2/launch.htm"
   sslinks[18] = "http://www.subgenius.com"

   var now = new Date();
   var sec = now.getSeconds();
   var link = sslinks[sec % 17];

//   window.location.href = link;
//   top.location=link;
   window.open(link);

};

// **************************************************
// Test function
// **************************************************

function testAlert() {
   alert("At least the javascript got called...");
};