// ******************************
//
//  Script for Page History
//  Date: 2008
//  Author/Owner: Linde AG
//
// ******************************

function doPageHistory(title,ref,flag) {
	myHistory = getCookie("pagehistory")
	list = new Array();
	if ((myHistory == null) || (myHistory == "")) {
		setCookie("pagehistory",title+"@"+ref,365)
		document.writeln("-")
		return true
	} else {
		list = myHistory.split("@")
		// Check if the list should be diplayed or not
		if (flag) {
			counter=1
			for (i=0;i<list.length;i+=2) {
				document.writeln("<p><a class=\"\" href=\""+list[i+1]+"\">"+counter+". "+list[i]+"&nbsp;<img src=\"\/images\/global\/ico_link_arrow.gif\" border=\"0\"></p></a>")
				counter++
			}
		}
		for (i=0;i<list.length;i+=2) {
			if (list[i+1] == ref) {
				list.splice(i,2);
				break;
			}
		}
		list.unshift(title,ref) // Adds current to the top of the list
		if (list.length > 10) { list = list.slice(0,10); }
		// Add current page to list
		setCookie("pagehistory",list.join("@"),365)
	}
}
// Cookie functions
function setCookie(cookieName, cookieVal, days) {
	if (!days) days = 1;
	var expDate = new Date();
	expDate.setTime(expDate.getTime() + days*24*60*60*1000);
	var expDateString = expDate.toGMTString();
	document.cookie = cookieName + "="+escape(cookieVal) + ";path=/;expires="+expDateString;
}
function getCookie(cookieName) {
	cookieName = cookieName+"=";
	var allCookies = document.cookie;
	if (allCookies.length > 0) {
		var start = allCookies.indexOf(cookieName);
		if (start != -1) {
			start = start + cookieName.length;
			var end = allCookies.indexOf(";",start);
			if (end == -1) end = allCookies.length;
			return unescape(allCookies.substring(start,end));
		}
	}
	return null;		
}
function delCookie(cookieName) {
	document.cookie = cookieName + "=" + ";path=/;expires=Thu, 01-Jan-70 00:00:01 GMT";
}
// Generates a 30 digit random number used for tracking individual users in statistics
id = getCookie('session')
if (id == null) {
	id = ""
	for (i=0;i<30;i++) {
		tempid = Math.random()*10
		tempid = Math.floor(tempid)
		id = id + tempid
	}
	setCookie('session',id,365)
}
