﻿
// written by Dean Edwards, 2005
// with input from Tino Zijdel
// http://dean.edwards.name/weblog/2005/10/add-event/

function addEvent(element, type, handler) {
	// assign each event handler a unique ID
	if (!handler.$$guid) handler.$$guid = addEvent.guid++;
	// create a hash table of event types for the element
	if (!element.events) element.events = {};
	// create a hash table of event handlers for each element/event pair
	var handlers = element.events[type];
	if (!handlers) {
		handlers = element.events[type] = {};
		// store the existing event handler (if there is one)
		if (element["on" + type]) {
			handlers[0] = element["on" + type];
		}
	}
	// store the event handler in the hash table
	handlers[handler.$$guid] = handler;
	// assign a global event handler to do all the work
	element["on" + type] = handleEvent;
};
// a counter used to create unique IDs
addEvent.guid = 1;

function removeEvent(element, type, handler) {
	// delete the event handler from the hash table
	if (element.events && element.events[type]) {
		delete element.events[type][handler.$$guid];
	}
};

function handleEvent(event) {
	var returnValue = true;
	// grab the event object (IE uses a global event object)
	event = event || fixEvent(window.event);
	// get a reference to the hash table of event handlers
	var handlers = this.events[event.type];
	// execute each event handler
	for (var i in handlers) {
		this.$$handleEvent = handlers[i];
		if (this.$$handleEvent(event) === false) {
			returnValue = false;
		}
	}
	return returnValue;
};

function fixEvent(event) {
	// add W3C standard event methods
	event.preventDefault = fixEvent.preventDefault;
	event.stopPropagation = fixEvent.stopPropagation;
	return event;
};
fixEvent.preventDefault = function() {
	this.returnValue = false;
};
fixEvent.stopPropagation = function() {
	this.cancelBubble = true;
};

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	allows instant window.onload function execution
	(c) Dean Edwards/Matthias Miller/John Resig/Rob Chenny
	http://www.cherny.com/demos/onload/domloaded.js
	
	Calling:

	DomLoaded.load(FUNCTION_NAME);

	or

	DomLoaded.load( function() {
		...
	});
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

var DomLoaded = {
	onload: [],
	loaded: function() {
		if (arguments.callee.done) return;
		arguments.callee.done = true;
		for (var i=0; i<DomLoaded.onload.length; i++) DomLoaded.onload[i]();
	},
	load: function(fireThis) {
		this.onload.push(fireThis);
		if (document.addEventListener) 
			document.addEventListener("DOMContentLoaded", DomLoaded.loaded, null);
		if (/KHTML|WebKit/i.test(navigator.userAgent)) { 
			var _timer = setInterval(function() {
				if (/loaded|complete/.test(document.readyState)) {
					clearInterval(_timer);
					delete _timer;
					DomLoaded.loaded();
				}
			}, 10);
		}
		/*@cc_on @*/
		/*@if (@_win32)
		var proto = "src='javascript:void(0)'";
		if (location.protocol == "https:") proto = "src=//0";
		document.write("<scr"+"ipt id=__ie_onload defer " + proto + "><\/scr"+"ipt>");
		var script = document.getElementById("__ie_onload");
		script.onreadystatechange = function() {
		    if (this.readyState == "complete") {
		        DomLoaded.loaded();
		    }
		};
		/*@end @*/
	   window.onload = DomLoaded.loaded;
	}
};

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	client.js - client specific things
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	(c) Copyright 2003, Finsoft Ltd
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	calls Flash function to write-out in-running header	
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
function InR_WriteHeader() {
	//	needed to overcome mixed-content warning on SSL pages
	if (SG_bIsSSL) {
		sProtocol = "https://";
		sSiteAddress = SG_sSSLserver;
	} else {
		sProtocol = "http://";
		sSiteAddress = SG_sHTTPserver;
	}

	var oReplace = null;
	oReplace = document.getElementById("inrunH2");
	if (oReplace) {
		oReplace.innerHTML = '<div class="flashcenterer">' + SWF_WriteFlashContent("/interface/css/images/headers/header_inrunning.swf", 398, 40, ".gif", "", false, sProtocol, sSiteAddress, "6,0,0,0") + '</div>';
	}
}

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	calls Flash function to write-out simple widgets (checkmark, exclaim, x)	
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
function SG_WriteWidget(sFile, nW, nH) {
	//	needed to overcome mixed-content warning on SSL pages
	if (SG_bIsSSL) {
		sProtocol = "https://";
		sSiteAddress = SG_sSSLserver;
	} else {
		sProtocol = "http://";
		sSiteAddress = SG_sHTTPserver;
	}

	var sBaseWidgetPath = "/interface/images/widgets/";
	sFile = sBaseWidgetPath + sFile;
	
	sFile += ".swf";

	if (typeof(nW) == "undefined")
		nW = 50;
	if (typeof(nH) == "undefined")
		nH = 50;

	document.write( '<div class="flashcenterer">' + SWF_WriteFlashContent(sFile, nW, nH, ".gif", "", false, sProtocol, sSiteAddress, "6,0,0,0") + '</div>' );
}

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	freephone betline functionality
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
var FPB_aDiv = new Array();
var FPB_aLI = new Array();
var FPB_x = null;
if (document.getElementsByTagName) {
	var FPB_x = document.getElementsByTagName("head")[0];
	if (FPB_x) FPB_x = FPB_x.parentNode;
	if (FPB_x) document.write('\n<style type="text/css" media="screen, tv, projection"> .freephone div{display:none;} </style>\n');
}

function FPB_Setup() {
	if (!FPB_x) return;
	
	var nCnt = 0;
	xGetElementsByClassName("freephone", null, "div", function(oDiv) {
		var aA = oDiv.getElementsByTagName("a");
		var aDiv = oDiv.getElementsByTagName("div");
		for (var i=0;i<aDiv.length;i++) {
			aA[i].oDiv = aDiv[i];
			aA[i].nCnt = nCnt;
			aA[i].onclick = function() {
				var nCnt = this.nCnt;
				if (FPB_aLI[nCnt])
					FPB_aLI[nCnt].className = FPB_aLI[nCnt].className.replace(/fpbcur/, "");
				if (FPB_aDiv[nCnt])
					FPB_aDiv[nCnt].style.display = "none";
				this.parentNode.className += " fpbcur";
				this.oDiv.style.display = "block";
				FPB_aLI[nCnt] = this.parentNode;
				FPB_aDiv[nCnt] = this.oDiv;
				return false;
			};
		}

		FPB_aLI[nCnt] = aA[0].parentNode;
		FPB_aLI[nCnt].className += " fpbcur";

		FPB_aDiv[nCnt] = aDiv[0];
		FPB_aDiv[nCnt].style.display = "block";
		
		nCnt++;
	});
}

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	workaround for damn IE and it's a:hover span problem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
function FormHelp_Setup() {
	if (!document.all || window.opera) return;

	var aTmp, aFld = document.getElementsByTagName("fieldset");
	for (var i=0;i<aFld.length;i++) {
		xGetElementsByClassName("formhelp", aFld[i], "a", function(oA) {
			oA.onmouseenter = function() {
				if (!(x = this.getElementsByTagName('span')[0])) return;
				x.style.visibility = 'visible';
			};
			oA.onmouseleave = function() {
				if (!(x = this.getElementsByTagName('span')[0])) return;
				x.style.visibility = 'hidden';
			};
		});
	}
}

//	this will execute various client stuff on page load
function ClientSetup() {
	FPB_Setup();
	FormHelp_Setup();
}

DomLoaded.load(ClientSetup);




