// JavaScript Document

/*
Disable right click script II (on images)- By Dynamicdrive.com
For full source, Terms of service, and 100s DTHML scripts
Visit http://www.dynamicdrive.com
*/
var Core = {};
// W3C DOM 2 Events model
if (document.addEventListener)
{
Core.addEventListener = function(target, type, listener)
{
target.addEventListener(type, listener, false);
};
Core.removeEventListener = function(target, type, listener)
{
target.removeEventListener(type, listener, false);
};
Core.preventDefault = function(event)
{
event.preventDefault();
};
Core.stopPropagation = function(event)
{
event.stopPropagation();
};
}
// Internet Explorer Events model
else if (document.attachEvent)
{
Core.addEventListener = function(target, type, listener)
{
// prevent adding the same listener twice, since DOM 2
// Events ignores duplicates like this
if (Core._findListener(target, type, listener) != -1)
return;
// listener2 calls listener as a method of target in one of
// two ways, depending on what this version of IE supports,
// and passes it the global event object as an argument
var listener2 = function()
{
var event = window.event;
if (Function.prototype.call)
{
listener.call(target, event);
}
else
{
target._currentListener = listener;
target._currentListener(event)
target._currentListener = null;
}
};
// add listener2 using IE's attachEvent method
target.attachEvent("on" + type, listener2);
// create an object describing this listener so we can
// clean it up later
var listenerRecord =
{
target: target,type: type,
listener: listener,
listener2: listener2
};
// get a reference to the window object containing target
var targetDocument = target.document || target;
var targetWindow = targetDocument.parentWindow;
// create a unique ID for this listener
var listenerId = "l" + Core._listenerCounter++;
// store a record of this listener in the window object
if (!targetWindow._allListeners)
targetWindow._allListeners = {};
targetWindow._allListeners[listenerId] = listenerRecord;
// store this listener's ID in target
if (!target._listeners) target._listeners = [];
target._listeners[target._listeners.length] = listenerId;
// set up Core._removeAllListeners to clean up all
// listeners on unload
if (!targetWindow._unloadListenerAdded)
{
targetWindow._unloadListenerAdded = true;
targetWindow.attachEvent(
"onunload", Core._removeAllListeners);
}
};
Core.removeEventListener = function(target, type, listener)
{
// find out if the listener was actually added to target
var listenerIndex = Core._findListener(
target, type, listener);
if (listenerIndex == -1) return;
// get a reference to the window object containing target
var targetDocument = target.document || target;
var targetWindow = targetDocument.parentWindow;
// obtain the record of the listener from the window object
var listenerId = target._listeners[listenerIndex];var listenerRecord =
targetWindow._allListeners[listenerId];
// remove the listener, and remove its ID from target
target.detachEvent("on" + type, listenerRecord.listener2);
target._listeners.splice(listenerIndex, 1);
// remove the record of the listener from the window object
delete targetWindow._allListeners[listenerId];
};
Core.preventDefault = function(event)
{
event.returnValue = false;
};
Core.stopPropagation = function(event)
{
event.cancelBubble = true;
};
Core._findListener = function(target, type, listener)
{
// get the array of listener IDs added to target
var listeners = target._listeners;
if (!listeners) return -1;
// get a reference to the window object containing target
var targetDocument = target.document || target;
var targetWindow = targetDocument.parentWindow;
// searching backward (to speed up onunload processing),
// find the listener
for (var i = listeners.length - 1; i >= 0; i--)
{
// get the listener's ID from target
var listenerId = listeners[i];
// get the record of the listener from the window object
var listenerRecord =
targetWindow._allListeners[listenerId];
// compare type and listener with the retrieved record
if (listenerRecord.type == type &&listenerRecord.listener == listener)
{
return i;
}
}
return -1;
};
Core._removeAllListeners = function()
{
var targetWindow = this;
for (id in targetWindow._allListeners)
{
var listenerRecord = targetWindow._allListeners[id];
listenerRecord.target.detachEvent(
"on" + listenerRecord.type, listenerRecord.listener2);
delete targetWindow._allListeners[id];
}
};
Core._listenerCounter = 0;
}
Core.addClass = function(target, theClass)
{
if (!Core.hasClass(target, theClass))
{
if (target.className == "")
{
target.className = theClass;
}
else
{
target.className += " " + theClass;
}
}
};
Core.getElementsByClass = function(theClass)
{
var elementArray = [];
if (document.all){
elementArray = document.all;
}
else
{
elementArray = document.getElementsByTagName("*");
}
var matchedArray = [];
var pattern = new RegExp("(^| )" + theClass + "( |$)");
for (var i = 0; i < elementArray.length; i++)
{
if (pattern.test(elementArray[i].className))
{
matchedArray[matchedArray.length] = elementArray[i];
}
}
return matchedArray;
};
Core.hasClass = function(target, theClass)
{
var pattern = new RegExp("(^| )" + theClass + "( |$)");
if (pattern.test(target.className))
{
return true;
}
return false;
};
Core.removeClass = function(target, theClass)
{
var pattern = new RegExp("(^| )" + theClass + "( |$)");
target.className = target.className.replace(pattern, "$1");
target.className = target.className.replace(/ $/, "");
};
Core.getComputedStyle = function(element, styleProperty)
{var computedStyle = null;
if (typeof element.currentStyle != "undefined")
{
computedStyle = element.currentStyle;
}
else
{
computedStyle =
document.defaultView.getComputedStyle(element, null);
}
return computedStyle[styleProperty];
};
Core.start = function(runnable)
{
Core.addEventListener(window, "load", runnable.init);
};



var sendToFriend =
{
	init: function()
	{
		var title = document.title;
		var strpos = title.indexOf("|");
		//alert(strpos);
		title = escape(title.substring(0, strpos-1));
		var target = document.getElementById("nav_org");
		if(target != null) {
		var list = target.getElementsByTagName("ul")[0];
		
		var liitems = list.getElementsByTagName("li");
		
		var li = document.createElement('li');		
		li.appendChild(document.createTextNode('Send to a friend')); 
		list.appendChild(li); 		
		var lastitem = liitems[liitems.length-1];
		var text = lastitem.innerHTML;		
		var ahref = "http://www.sahistory.org.za/pages/saho%20stuff/recommend.php?loc=";
		ahref += window.location.href;
		ahref += "&title=";
		ahref += title;
		lastitem.innerHTML = "<a title='Send to a Friend' href="+ahref+">"+text+"</a>";
		var linkli = lastitem.getElementsByTagName("a")[0];
				
		//alert(linkli.nodeName);
		linkli.setAttribute("class", "sendlink");	
		
		linkli.onclick = sendToFriend.clickHandler;
		}
	},
	clickHandler: function()
	{
		open(this.href);
		return false;
	}
	
};

Core.start(sendToFriend);

var saTitle =
{
	init: function()
	{
		var saho = Core.getElementsByClass("threedots")[0];
		var ad = saho.getElementsByTagName("a")[0];
		ad.setAttribute("title", "Go to home page - SAHistory.org.za");
		//	var koko = ad.getAttribute("title");
		//alert(koko);
		//Core.addClass(hd, "hd");	
	}
};
Core.start(saTitle);

//****************************************************//

var clickmessage="Please contact the archive/person cited for copyright details."

function disableclick(e) {
if (document.all) {
if (event.button==2||event.button==3) {
if (event.srcElement.tagName=="IMG"){
alert(clickmessage);
return false;
}
}
}
else if (document.layers) {
if (e.which == 3) {
alert(clickmessage);
return false;
}
}
else if (document.getElementById){
if (e.which==3&&e.target.tagName=="IMG"){
alert(clickmessage)
return false
}
}
}

function associateimages(){
for(i=0;i<document.images.length;i++)
document.images[i].onmousedown=disableclick;
}

if (document.all)
document.onmousedown=disableclick
else if (document.getElementById)
document.onmouseup=disableclick
else if (document.layers)
associateimages()

function clearForm() {
	document.lib_search.q.value = "";
}

function openPage()
{
	var selObj = document.getElementById('livesofcourage');		
	var selIndex = selObj.selectedIndex;
	var url = selObj.options[selIndex].value;
	if (url){ window.location = url;}
}

function writelocation() {
	var title = document.title;
	var strpos = title.indexOf("|");
		//alert(strpos);
	title = unescape(title.substring(0, strpos-1));
	document.write(title);
}
/* ================================================================ 
This copyright notice must be kept untouched in the stylesheet at 
all times.

The original version of this script and the associated (x)html
is available at http://www.stunicholls.com/menu/skeleton.html
Copyright (c) 2005-2007 Stu Nicholls. All rights reserved.
This script and the associated (x)html may be modified in any 
way to fit your requirements.
=================================================================== */

stuHover = function() {
	var cssRule;
	var newSelector;
	for (var i = 0; i < document.styleSheets.length; i++)
		for (var x = 0; x < document.styleSheets[i].rules.length ; x++)
			{
			cssRule = document.styleSheets[i].rules[x];
			if (cssRule.selectorText.indexOf("LI:hover") != -1)
			{
				 newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
				document.styleSheets[i].addRule(newSelector , cssRule.style.cssText);
			}
		}
	var getElm = document.getElementById("no_nav").getElementsByTagName("LI");
	for (var i=0; i<getElm.length; i++) {
		getElm[i].onmouseover=function() {
			this.className+=" iehover";
		}
		getElm[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", stuHover);