//------------------------------------------------------------------------------------
//NETJOHNHENRY HERE, WHY?-------------------------------------------------------------
//------------------------------------------------------------------------------------
/*
	
	On the 30/03/2009 Giuseppe says:
	I've added inside central/include/cssandscripts.asp the
	<script type="text/javascript" src="/central/script/netjohnhenry.js"></script> declaration
	for both English and German site. That requires to bake all sites before the javascript class 
	would be available to all sites which I haven't done due to time constraints.
	I've therefore included this class here so it's quickly available and I can carry on with debugging tracking problem.
	Note: As the content team bake the rocco sites this hardcoded include will become obsolete and no longer needed.
	
	Please check the date of this message and, at your own discretion, if you believe enough time has passed since NETJOHNHENRY.js file 
	was included in the cssandscripts.asp file and you believe content team has baked already ALL sites, 
	then please delete the NETJOHNHENRY class from this file.
	
	Note: As you clean up, there is a copy of this is inside the German and English central/script/main.js.
	
*/
//------------------------------------------------------------------------------------
//START NETJOHNHENRY------------------------------------------------------------------
//------------------------------------------------------------------------------------
/*
netjohnhenry.js
2 November 2007
Global namespace initialisation.
Objects which live within the NETJOHNHENRY namespace should always check for existence first,
and if the namespace object does not exists, create it. Code for doing so:
NETJOHNHENRY = window.NETJOHNHENRY || {};
*/
NETJOHNHENRY = (function() {
	var name = 'NETJOHNHENRY';
	var description = 'Library namespace static object';
	var libraryPath = '';
	var loadedModules = {};
	var queryString = {};

	function require(path, node) {
		/* Used to include external javascript */
		if (!loadedModules[path]) {
			var destinationNode = (node) ? node : document.getElementsByTagName('head')[0];
			var tag = document.createElement('script');
			tag.setAttribute('src', path);
			tag.setAttribute('type', 'text/javascript');
			var coreLibrary = document.getElementById('jhLibrary');

			// insertBefore is effectively the same as appendChild when coreLibrary is null
			destinationNode.insertBefore(tag, coreLibrary);

			loadedModules[path] = true;
		}
	}

	function requireStyles(s, node) {
		/* Used to include external css */
		var destinationNode = (node) ? node : document.getElementsByTagName('head')[0];
		var tag = document.createElement('style');
		tag.setAttribute('type', 'text/css');
		tag.appendChild(document.createTextNode(s));
		destinationNode.appendChild(tag);
	}

	function delegate(context, func, parameters) {
		/*
		Delegate can be used with setTimeout to allow "this" to be set to the correct context
		in the delegated function. Assumes parameters is an object literal.
		*/
		context.delegatedFunction = func;
		context.delegatedFunction(parameters);
	}


	function cloneObject(o) {
		var i, clone = {};

		if (typeof o != 'object' || o === null) {
			return o;
		}

		for (prop in o) {
			if (o.hasOwnProperty(prop)) {
				clone[prop] = NETJOHNHENRY.cloneObject(o[prop]);
			}
		}

		return clone;
	}

	function getQueryString(name) {
		if (name && !queryString[name]) {
			var q = document.location.search.split('?').join('');

			if (q !== '') {
				q = q.split('&');
				for (var i = 0; i < q.length; i++) {
					var vp = q[i].split('=');
					queryString[vp[0]] = vp[1];
				}
			}
		}
		if (name) {
			return queryString[name];
		}
		else {
			return queryString;
		}
	}

	return {
		name: name,
		description: description,
		libraryPath: libraryPath,
		loadedModules: loadedModules,
		require: require,
		requireStyles: requireStyles,
		delegate: delegate,
		cloneObject: cloneObject,
		getQueryString: getQueryString
	};

})();
//------------------------------------------------------------------------------------
//END NETJOHNHENRY--------------------------------------------------------------------
//------------------------------------------------------------------------------------






var theRules = getRules();

// prevent display of navigation until page has loaded, to avoid odd placement
registerEventNode('load', window, showLeftNav);
function showLeftNav()
{
	if (document.getElementById('left'))
	{ document.getElementById('left').style.visibility = 'visible'; }
}

function setHeight(leftId, centreId, rightId, contentId)
{
	if (!leftId) { leftId = 'left'; }
	if (!centreId) { centreId = 'bodycontent'; }
	if (!rightId) { rightId = 'right'; }
	if (!contentId) { contentId = 'content'; }
	
	clearHeight(leftId, centreId, rightId, contentId);
	var leftPadding = 0;
	var maincontentPadding = 0;
	var bodycontentPadding = 0;
	var rightPadding = 0;
	
	var leftHeight = 0, mainHeight = 0, rightHeight = 0, contentHeight = 0;
	
	if (document.getElementById(leftId))
	{ leftHeight = document.getElementById(leftId).offsetHeight; }
	if (document.getElementById(centreId))
	{ mainHeight = document.getElementById(centreId).offsetHeight; } 
	if (document.getElementById(rightId))
	{ rightHeight = document.getElementById(rightId).offsetHeight; } 
	if (document.getElementById(contentId))
	{ contentHeight = document.getElementById(contentId).offsetHeight; } 
	
	// right-hand side must be extended to not overlap the language bar, and the logo on the group site
	rightHeight += 50;
	if (document.getElementById('rightlogo'))
	{ rightHeight += 90; }

	
	if (document.styleSheets[0].rules)
	{ mainHeight += 10; }

	var offHeight = leftHeight;
	offHeight = ( mainHeight > offHeight ) ? mainHeight : offHeight;
	offHeight = ( rightHeight > offHeight ) ? rightHeight : offHeight;
	
	// include a minimum height
	offHeight = (500 > offHeight) ? 500 : offHeight;
	
	if (document.styleSheets[0].rules)
	{ contentHeight -= 10; }

	if (contentHeight < 0)
	{ contentHeight = 0; }

	// firefox
	if (document.styleSheets[0].cssRules)
	{
		for (i=0; i<theRules.length; i++)
		{
			if (theRules[i].selectorText == '#'+centreId || theRules[i].selectorText == '*[ID"'+centreId+'"]')
			{ theRules[i].style.setProperty('height', (offHeight-bodycontentPadding)+'px', null); }
			
			if (theRules[i].selectorText == '#'+leftId || theRules[i].selectorText == '*[ID"'+leftId+'"]')
			{ theRules[i].style.setProperty('height', (offHeight-leftPadding)+'px', null); }
			
			if (theRules[i].selectorText == '#'+rightId || theRules[i].selectorText == '*[ID"'+rightId+'"]')
			{ theRules[i].style.setProperty('height', (offHeight-rightPadding)+'px', null); }
			
			if (theRules[i].selectorText == "#maincontent" || theRules[i].selectorText == '*[ID"maincontent"]')
			{ theRules[i].style.setProperty('height', (offHeight+maincontentPadding)+'px', null); }
			
			if (theRules[i].selectorText == '#'+contentId || theRules[i].selectorText == '*[ID"'+contentId+'"]')
			{ theRules[i].style.setProperty('height', (contentHeight)+'px', null); }
		}
	}
	// IE
	else if (document.styleSheets[0].rules)
	{
		for (i=0; i<theRules.length; i++)
		{
			if(theRules[i].selectorText == '#'+centreId)
			{ theRules[i].style.height = (offHeight-bodycontentPadding-10); }
			
			if(theRules[i].selectorText == '#'+leftId)
			{ theRules[i].style.height = (offHeight-leftPadding); }
			
			if(theRules[i].selectorText == '#'+rightId)
			{ theRules[i].style.height = (offHeight-rightPadding-10); }
			
			if(theRules[i].selectorText == "#maincontent")
			{ theRules[i].style.height = (offHeight+maincontentPadding-10); }			
			
			if(theRules[i].selectorText == '#'+contentId)
			{ theRules[i].style.height = contentHeight; }
		}
	}
}

function clearHeight(leftId, centreId, rightId, contentId){
	// firefox
	if (document.styleSheets[0].cssRules){
		for (i=0; i<theRules.length; i++)
		{
			if (theRules[i].selectorText == '#'+centreId || theRules[i].selectorText == '*[ID"'+centreId+'"]')
			{ theRules[i].style.setProperty('height', 'auto', null); }
			
			if (theRules[i].selectorText == '#'+leftId || theRules[i].selectorText == '*[ID"'+leftId+'"]')
			{ theRules[i].style.setProperty('height', 'auto', null); }
			
			if (theRules[i].selectorText == '#'+rightId || theRules[i].selectorText == '*[ID"'+rightId+'"]')
			{ theRules[i].style.setProperty('height', 'auto', null); }
			
			if (theRules[i].selectorText == "#maincontent" || theRules[i].selectorText == '*[ID"maincontent"]')
			{ theRules[i].style.setProperty('height', 'auto', null); }
			
			if (theRules[i].selectorText == '#'+contentId || theRules[i].selectorText == '*[ID"'+contentId+'"]')
			{ theRules[i].style.setProperty('height', 'auto', null); }
		}
	}
	// IE
	else if (document.styleSheets[0].rules){
		for (i=0; i<theRules.length; i++)
		{
			if(theRules[i].selectorText == '#'+centreId)
			{ theRules[i].style.height = 'auto'; }
			
			if(theRules[i].selectorText == '#'+leftId)
			{ theRules[i].style.height = 'auto'; }
			
			if(theRules[i].selectorText == '#'+rightId)
			{ theRules[i].style.height = 'auto'; }
			
			if(theRules[i].selectorText == "#maincontent")
			{ theRules[i].style.height = 'auto'; }
			
			if(theRules[i].selectorText == '#'+contentId)
			{ theRules[i].style.height = 'auto'; }
		}
	}
}

function getRules()
{
	if (document.styleSheets[0].cssRules)
	{ return document.styleSheets[0].cssRules; }
	// IE
	else if (document.styleSheets[0].rules)
	{ return document.styleSheets[0].rules; }
}

function changeClass(id, classname) {
	var el=id.parentNode;
	var attributeNode = el.getAttributeNode("class");
	if(attributeNode){
		if(classname!="") attributeNode.value = classname;
		else el.removeAttribute("class");
	}
	else
		el.setAttribute("class", classname);
} 

var blnSubpageLinks=false;
var curPos, curNum;
curNum=0;
function turnPageLinks(curLi, num){
	if(curPos!=undefined) {
		curPos.className="";
	}
	curLi.className="on";
	//alert(num+"  "+curNum+"   "+(num+1));
	if (curLi.toString().indexOf('#'+(num+1))>0) {
		if(curNum!=num) document.getElementById("pagelinks").style.display="none";
		document.getElementById("pagelinks").style.display="block";
		blnSubpageLinks=true;
	}
	else{
		document.getElementById("pagelinks").style.display="none";
	}
	curPos=curLi;
	curNum=num;
}

function removeClassname(){
	var allClass=document.getElementById("pagelinks").li;
	//for(int i=0; i<allClass.length; i++){
	//}
}

// cookie functions
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
};

function readCookie(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;
};

// currency convertor window
function popCurrencyConvert()
{
	window.open('/central/currency.asp', 'convertor', 'width=350,height=200,resizable=yes,scrollbars=yes');
}


// quirksmode.org browser detection
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
