/* 
*	Some general applicable scripts	
*
*	$Revision: 1.5 $
*	$Date: 2008/12/04 15:54:04 $
*	$Author: jobv $
*/

/**
 *  General settings
 */
var debug = true; // show debug message; setting this to false saves some mem
var ShowAlerts = false; // show alert box when 'console' is not available.
var FixPNG = true; // fix transparent png's in ie < 7
var ErrorMessages = []; // new Array()
var alerts = ''; // alerts output
var ExpandTextareas = false; // make textareas expand when typing
var resourcesFolder = '/5/resources/'; // set folder for css and images
var placeLanguageList = true;
var doCheckPopupBlocker = false;
var env; // holds browser evn info
var showScreenInfo = true; // dump screen size and scroll info

// Set site minimals
var minW = "1176";
var minH = "1500";

if(!OldBrowserMsg) {
	var OldBrowserMsg = "WARNING: The browser that you are using (__browser__ __version__) is not supported by StepStone.<br />Some elements of our site may not be displayed correctly. We recommend: <a href=\"http://www.google.com/search?q=download+web+browser\">Firefox, Internet Explorer 7 or Safari</a>.";
}

var OldBrowserMsg = null;

/**
 * Test if prototype library function $ exists
 */
function PrototypeTest(){
	var prototypeAvailable;
	if (typeof(Prototype) == "undefined") {
		return false;
	}
	prototypeAvailable = true;		
	log('Prototype loaded');
}

/**
 * Dreamweaver findObj
 * @param {Object} theObj
 * @param {Object} theDoc
 */
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

/**
 * LoadListener
 * @param {Object} fn
 */
function addLoadListener(fn) {
  if (typeof window.addEventListener != 'undefined')   {
    window.addEventListener('load', fn, false);
  } else if (typeof document.addEventListener != 'undefined') {
    document.addEventListener('load', fn, false);
  } else if (typeof window.attachEvent != 'undefined') {
    window.attachEvent('onload', fn);
  } else {
    var oldfn = window.onload;
    if (typeof window.onload != 'function') {
      window.onload = fn;
    } else {
      window.onload = function() {
        oldfn();
        fn();
      };
    }
  }
}

/**
 * Simple load handler
 * @param {Object} func
 */
function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			}
		}
}

/**
*	aliases for addLoadEvent
*/
addloadevent = addLoadEvent;
RegisterOnLoad = addLoadEvent;

/**
 *	ULTRA-SIMPLE EVENT ADDING 
 *	Quirksmode.org
 */
function addEventSimple(obj,evt,fn) {
 if (obj.addEventListener)
 obj.addEventListener(evt,fn,false);
 else if (obj.attachEvent)
 obj.attachEvent('on'+evt,fn);
}

function removeEventSimple(obj,evt,fn) {
 if (obj.removeEventListener)
 obj.removeEventListener(evt,fn,false);
 else if (obj.detachEvent)
 obj.detachEvent('on'+evt,fn);
}

// add Array.push if needed (ie5)
if (!Array.prototype.push) {
	Array.prototype.push = function(item) {
		this[this.length] = item; return this.length;
	}
}

// The shift() and unshift() methods. (ie5)
if(!Array.prototype.shift) { // if this method does not exist..
	Array.prototype.shift = function(){
		firstElement = this[0];
		this.reverse();
		this.length = Math.max(this.length-1,0);
		this.reverse();
		return firstElement;
	}	
}

if(!Array.prototype.unshift) { // if this method does not exist..	
	Array.prototype.unshift = function(){
		this.reverse();		
			for(var i=arguments.length-1;i>=0;i--){
				this[this.length]=arguments[i]
			}			
		this.reverse();
		return this.length
	}
}

/**
 * Trim spaces from a string
 * http://www.nicknettleton.com/zine/javascript/trim-a-string-in-javascript 
*/ 
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }


/**
 *	Holds browser and display information
 **/
env = {
	
	// returned variables
	
	sw : 0, // screen.width
	sH : 0, // screen.height
	aW : 0, // screen.availWidth
	aH : 0, // screen.availHeight
	cD : 0, // screen.colorDepth
	pW : 0, // pageWidth
	pH : 0, // pageHeight
	wW : 0, // windowWidth
	wH : 0, // windowHeight
	sX : 0, // xScroll
	sY : 0, // yScroll
	sU : 0,	// screen usage percentage
	uW : 0, // screen usage width
	uH : 0, // screen usage height
	
	init: function() {		
		env.sW = screen.width;
		env.sH = screen.height;
		env.aW = screen.availWidth;
		env.aH = screen.availHeight;
		env.cD = screen.colorDepth;		
		log("Screen size: " + env.sW + "px x " + env.sH + "px");
		log("Screen available size: " + env.aW + "px x " + env.aH + "px");
		log("Screen colordepth: " + env.cD + "bit");		
		// returns array: pageWidth,pageHeight,windowWidth,windowHeight
		arrPageSizes = env.getPageSize();		
		env.pW = arrPageSizes[0];
		env.pH = arrPageSizes[1];
		env.wW = arrPageSizes[2];
		env.wH = arrPageSizes[3];		
		log("Page size: " + env.pW + "px x " + env.pH + "px");
		log("Window size: " + env.wW + "px x " + env.wH + "px");		
		// returns array: xScroll,yScroll
		var arrPageScroll = env.getPageScroll();		
		env.sX = arrPageScroll[0];
		env.sY = arrPageScroll[1];		
		log("Scrolling: " + env.sX + " x " + env.sY);		
		// screensize,windowsize,PercentageTotal,PercentageWidth,PercentageHeight
		arrScreenUsage = env.getScreenUsage();
		env.sU = arrScreenUsage[2];
		env.uW = arrScreenUsage[3]; 
		env.uH = arrScreenUsage[4];		
		log("Total Screen Usage: " + env.sU + "% / Width: " + env.uW + "% / Height: " + env.uH + "%");
		
	},
	// on resize function
	calculatePageSize: function (output) {		
		var arrPageSizes = env.getPageSize();		
		env.pW = arrPageSizes[0];
		env.pH = arrPageSizes[1];
		env.wW = arrPageSizes[2];
		env.wH = arrPageSizes[3];		
		dump( "Page size: " + env.pW + "px x " + env.pH + "px" );
		dump( "Window size: " + env.wW + "px x " + env.wH + "px" );
		
	},
	// on resize function
	calculatePageScroll: function (output) {		
		var arrPageScroll = env.getPageScroll();		
		env.sX = arrPageScroll[0];
		env.sY = arrPageScroll[1];		
		dump( "Scrolling: " + env.sX + " x " + env.sY );		
	},
	
	calculateScreenUsage: function () {		
		// screensize,windowsize,PercentageTotal,PercentageWidth,PercentageHeight
		arrScreenUsage = env.getScreenUsage();
		env.sU = arrScreenUsage[2];
		env.uW = arrScreenUsage[3]; 
		env.uH = arrScreenUsage[4];		
		dump( "Total Screen Usage: " + env.sU + "% / Width: " + env.uW + "% / Height: " + env.uH + "%" );
	},
	
	// Quirksmode.org
	getPageSize: function() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
	},
	
	// Quirksmode.org
	getPageScroll: function() {
		var xScroll, yScroll;
		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
			xScroll = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
			xScroll = document.documentElement.scrollLeft;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
			xScroll = document.body.scrollLeft;	
		}
		arrayPageScroll = new Array(xScroll,yScroll);
		return arrayPageScroll;
	},
	
	getScreenUsage: function() {		
		var screensize, windowsize, PercentageTotal, PercentageWidth, PercentageHeight;
		screensize = env.sW * env.sH;
		windowsize = env.wW * env.wH;		
		PercentageTotal = Math.ceil((windowsize / screensize) * 100);		
		PercentageWidth = Math.ceil((env.wW / env.sW) * 100);
		PercentageHeight = (Math.ceil(env.wH / env.sH) * 100);		
		arrayScreenUsage = new Array(screensize,windowsize,PercentageTotal,PercentageWidth,PercentageHeight);		
		return arrayScreenUsage;		
	}
}

/**
 * Calculate the height of an iframe's content
 * Auto-resize an ifame depending on it's content
 * Add this to the onload handler of the iframe tag
 * Only works when iframe source is on the same domain!
 * @param {Object} el The iframe to check
 */
function calcHeight(el){
	 var theIFrame = document.getElementById(el);
	 //log('Checking : ' + theIFrame.id);
	 if(typeof theIFrame != 'undefined'){
		 var getFFVersion = navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
		 var FFextraHeight = parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers
		 if (theIFrame.contentDocument && theIFrame.contentDocument.body.offsetHeight) //ns6 syntax
		 theIFrame.height = theIFrame.contentDocument.body.offsetHeight + FFextraHeight;
		 else if (theIFrame.Document && theIFrame.Document.body.scrollHeight) //ie5+ syntax
		 theIFrame.height = theIFrame.Document.body.scrollHeight;
		 //log('The height will be ' + theIFrame.height);
	 }
}

// synonimes
calcheight = calcHeight;
CalcHeight = calcHeight;

/**
 *	Check popupblocker
 *	Sets a cookie with the result of the check
 *	Status: experimental
 */
function checkPopupBlocker() {	
	if(typeof Cookies.popUpsBlocked == 'string') {
		cookie = Cookies.popUpsBlocked;
		var popUpsBlocked = cookie;
		return true;
	}	
	if(typeof Cookies.popUpsBlocked == 'undefined') {		
		var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');		
		if(mine) {
			var popUpsBlocked = false + ' blocked';
		} else {
			var popUpsBlocked = true + ' blocked';
		}		
		if(mine && typeof mine.close == 'function') {
			mine.close();
		}		
		if(typeof Cookies.cookiecheck == 'string'){
			Cookies.create('popUpsBlocked',popUpsBlocked);
		}		
	}	
	if(typeof Cookies.cookiecheck == 'undefined') {
		Cookies.create('cookiecheck',true);	
	}	
	//dump('typeof Cookies.popUpsBlocked: ' + typeof Cookies.popUpsBlocked);	
	log('popUpsBlocked = ' + popUpsBlocked);	
}

/**
 *	COOKIES
 *	http://www.quirksmode.org/quirksmode.js
 */
var Cookies = {
	init: function () {
		var allCookies = document.cookie.split('; ');
		for (var i=0;i<allCookies.length;i++) {
			var cookiePair = allCookies[i].split('=');
			this[cookiePair[0]] = cookiePair[1];
		}
	},
	create: function (name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
		this[name] = value;
	},
	erase: function (name) {
		this.create(name,'',-1);
		this[name] = undefined;
	}
};


/**
 * Create a browser popup window
 *
 * @param {String} url
 * @param {String} name
 * @param {String} w
 * @param {String} h
 * @param {String} scroll
 */
function PopUp(url,name,w,h,scroll) {
  var Window   = null;
  LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
  TopPosition  = (screen.height) ? (screen.height-h)/2 : 0;
  settings     = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+''
  Window       = window.open(url,name,settings)
}


/**
 * Outputs an email address where .'s are obscured with 'dot' and @'s with 'at'
 * @param {String} e
 */
function address(e) {
	e = e.replace(/ dot /g,".");
	e = e.replace(/ at /g,"@");
	document.write(e);
}

/**
 * Very simple nospam measure
 * @param {String} u user
 * @param {String} d domain
 * @param {String} t tld
 */
function noSpam(u,d,t) {
	l = "mailto:" + u + "@" + d + "." + t;
	window.location = l;
}

/**
 * Addition to nospam measures
 * @param {String} a address
 * @param {String} s subject
 * @param {boolean} t track
 */
function send(a,s,t) {
	var url;
	url = "mailto:" + a;
	//url = "mailto:test@stepstone.be";
	if(s){
		url += '?subject=' + s;	
	}
	if(t){
		date = new Date;
		dump(url + ' is clicked on ' + date.toString());
		// place ajax call here
	}
	//dump('l:' + url.toString());
	window.location = url.toString();
}

// aliases for send function
sendmail = send;
mail = send;

/**
 * open an url 
 * @param {String} u url
 * @param {String} t target
 */
function url(u, t){
	var u;
	// log this
	if (t == '_blank') {
		window.open = u;
	}else{
		window.location = u;
	}
}

goto = url;

/**
 * Set display none of obj
 * @param {Object} obj
 */
function hide(obj){
	el = findObj(obj);
	log('found: ' + el.id);
	el.style.display = 'none';
}

/**
 * Debug log wrapper
 * Uses console.log if available, otherwise alerts the log messages
 * Use when building functions
 * @param {String} msg
 */
function log(msg) {	
	if(ErrorMessages && typeof ErrorMessages == 'object'){		
		ErrorMessages.push(msg);		
	}
}

/**
 * Show gathered messages in one alert
 * Use this to output intermediate log messages in the code on execution
 * @param {String} msg
 */
function dump(msg){	
	if(msg != null && msg.length > 0){		
		//old_alerts = alerts;
		alerts = msg;			
	}else{
		for (var i=0;i<ErrorMessages.length;i++) {
			alerts += ErrorMessages[i] + '\r\n';
		}
	}	
	if(debug){
		// use console if available? Works in FireFox firebug, Safari 3
		if(window.console && console.log){		
			console.log(alerts);
		}else{
			// opera alternative
			if(window.opera && opera.postError) {
				opera.postError(alerts);
			}else{		
				// only alert if requested
				if(window.alert && ShowAlerts){
					alert(alerts);
				}
			}
		}
	}
}

/**
 * 
 */
var FormHelpers = {
	init: function () {
		if(ExpandTextareas){
			addLoadListener(this.ExpandTextareas);
		}
	},
	// looks for textareas and tries to make them grow on text input
	ExpandTextareas: function () {
		var ts;
		ts = document.getElementsByTagName('textarea');
		//log("Found " + textareas.length + " textareas");		
		for (var i=0;i<ts.length;i++) {
			//log(textareas[i].id + " is a " + typeof textareas[i]);			
				t = ts[i];
				log('Expanding:' + ts[i].id);
				ts[i].className += ' expand';			
				ts[i].originalHeight = ts[i].offsetHeight;
				
				ts[i].onkeyup = function () {					
					if(this.scrollHeight - Math.round(this.originalHeight / 30) > this.originalHeight) {
						this.style.height = this.scrollHeight + 'px';
					}
				}
		}		
	},
	validateEmail: function(strEmail) {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,16})+$/.test(strEmail)){ 
			return true;
		}else{
			return false;
		}
	},
	Trim: function(s) {
		while (s.substring(0,1) == ' ') {
			s = s.substring(1,s.length);
		}
		return s;
	},
	/**
	 *	On change select menu handler
	 */
	GoSelect: function (obj) {
		//dump('obj: ' + obj);
		if(typeof obj != 'undefined' && window) {
			//dump('selected: ' + obj.options[obj.selectedIndex].value);
			window.location = obj.options[obj.selectedIndex].value;
		}
	}
};


/**
 *	Fixes transparent BACKGROUND png images in IE Sux
 *	http://msdn.microsoft.com/en-us/library/ms532920(VS.85).aspx	
 */
var bgsleight = function() {	
	function fnLoadPngs() {
		//log('Are there png images?');
		var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
		var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
		for (var i = document.all.length - 1, obj = null; (obj = document.all[i]); i--) {
			if (itsAllGood && obj.currentStyle.backgroundImage.match(/\.png/i) != null) {				
				fnFixPng(obj);
				obj.attachEvent("onpropertychange", fnPropertyChanged);
			}
		}
	}
	function fnPropertyChanged() {
		if (window.event.propertyName == "style.backgroundImage") {
			var el = window.event.srcElement;
			if (!el.currentStyle.backgroundImage.match(/x\.gif/i)) {
				var bg	= el.currentStyle.backgroundImage;
				var src = bg.substring(5,bg.length-2);
				el.filters.item(0).src = src;
				el.style.backgroundImage = "url(x.gif)";
			}
		}
	}
	/**
	*	@param {Object} obj
	**/
	function fnFixPng(obj) {
		var bg	= obj.currentStyle.backgroundImage;
		var src = bg.substring(5,bg.length-2);
		// sizingMethods can be "image", "scale" or "crop"		
		obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='crop')";
		obj.style.backgroundImage = "url(x.gif)";
		log('PNG ' + src + ' found and fixed');
	}	
	return {		
		init: function() {			
			if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
				addLoadEvent(fnLoadPngs);
			}			
		}
	}
	
}();


/**
 *	Fix png images
 *	Searches for img's in the code with src's ending on png
 */
var pngfix = function (){	
	function fnFixPng() {	
		var arVersion = navigator.appVersion.split("MSIE")
		var version = parseFloat(arVersion[1])	
		if ((version >= 5.5) && (document.body.filters)) 
		{
		   for(var i=0; i<document.images.length; i++)
		   {
			  var img = document.images[i]
			  var imgName = img.src.toUpperCase()
			  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			  {
				 var imgID = (img.id) ? "id='" + img.id + "' " : ""
				 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				 var imgStyle = "display:inline-block;" + img.style.cssText 
				 if (img.align == "left") imgStyle = "float:left;" + imgStyle
				 if (img.align == "right") imgStyle = "float:right;" + imgStyle
				 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				 var strNewHTML = "<span " + imgID + imgClass + imgTitle
				 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				 img.outerHTML = strNewHTML
				 i = i-1
				 log('Fixed png image : ' + imgName);
			  }
		   }
		}	
	}	
	return {		
		init: function () {			
			if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
				addLoadEvent(fnFixPng);
			}		
		}	
	}	
}();


/**
 * Browser Detection
 * http://www.quirksmode.org/js/detect.html
 * 
 * Checks also for the required version to make the site work
 * Uses a structure with current browsers
 * Outputs the OldBrowserMsg if necessary
 *
 */ 
var BrowserDetect = {
	init: function (theMsg) {
		this.msg = theMsg;
		this.browser = this.searchString(this.dataBrowser) || "unknown";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "unknown";
		this.userAgent = this.browser + ' ' + this.version;	
		this.OS = this.searchString(this.dataOS) || "unknown";
		this.check = this.checkBrowser(this.dataBrowser);
		this.checkVersion();
	},
	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;
		}
	},
	checkBrowser: function (data) {
		for (var i=0;i<data.length;i++) {
			required = data[i].required;
			// stop if we found our browser in data
			if(this.browser == data[i].identity){
				// check if we have a required version for this browser
				if(this.browser == data[i].identity && required){
					//log("Check: " + this.browser + ' ' + this.version + " >= " + data[i].identity + ' ' + required);
					// check if the current version is higher or equal to the required version
					if(this.version >= data[i].required) {				
						return true;
					}else{
						return false;	
					}
				}else{
					// we didn't set a minimum version, so return ok
					return true;	
				}
			}
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	checkVersion: function (targetBrowser,minVersion) {
		if(this.msg == null) return false;
		// note: this will not check sub versions
		//log('Good browser? ' + this.check);
		//var Msg = "WARNING: The browser that you are using ("+this.browser+" "+this.version+") is not supported by StepStone.<br />Some elements of our site may not be displayed correctly. We recommend: <a href=\"http://www.google.com/search?q=download+browser\">Safari 3, Firefox 2 or Internet Explorer 7</a>.";
		var Msg = this.msg.replace("__browser__", this.browser).replace("__version__", this.version);
		// note that we only target known browsers with issues here...
		if(!this.check){
			this.resetCSS();
			document.write('<div id="goldbar">'+Msg+' <a href="#" onclick="javascript:hide(\'goldbar\');">X</a></div>');
		}
	},
	resetCSS: function () {
		document.write('<link rel="stylesheet" type="text/css" href="'+resourcesFolder+'css/reset.css" />');
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			required: "3" // Set required version for the site to work correctly
		},
		{
			prop: window.opera,
			identity: "Opera",
			required: "8"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox",
			required: "2" // Set required version for the site to work correctly
		},
		{
			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",
			required: "7.0" // Set required version for the site to work correctly
		},
		{
			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"
		}
	]

};

/**
 * Returns the height of an element
 * @param {Object} id
 */
function checkHeight(id){
	//log('checking height of ' + id);	
	var el = findObj(id);
	if(!el){
		return false;	
	}
	//log('found :' + el.id + ' is ' + el.offsetHeight + 'px high' );
	return el.offsetHeight;
}

/**
 * Move the element the dif number of px to the top
 * @param {Object} el
 * @param {Integer} dif
 */
function moveToTop(el,dif){
	dif += 5;
	el.style.top = '-' + dif / 1.75 + 'px';
	//el.style.zIndex = '99';
}

/**
 * Remove element from the dom
 * @param {Object} el
 */
function removeElement(el) {
  d = findObj(el); 
  d.parentNode.removeChild(document.getElementById(el));
}


// Stepstone V5 specific

/**
 * Pushes the language list some pixels to top if Photo is positioned on top of the links rendering them useless.
 */
function placeLanguageLinksOnTop(){
	
	var boxheight;
	var photoheight;
	var check = false;
	
	el = findObj('languagelist');
	
	if(!document.getElementsByTagName) {
		return false;	
	}
	
	// don't do the check on the frontpage
	if(document.getElementsByTagName('body')[0].className.indexOf('front') == '-1'){
		check = true;
	}
	
	if(check && typeof el != 'undefined'){
		// check height of dashboard
		boxheight = checkHeight('DynamicBox');
		// check height of photo
		photoheight = checkHeight('Photo');
		
		if(!boxheight || !photoheight){
			return false;
		}
			
		dif = photoheight - boxheight;
		log('dif: ' + dif);
		// reposition languagelist if necessary
		if(dif > 0){
			//setTimeout("moveLanguageList(el,dif)",500);
			moveToTop(el,dif);
		}
		
	}
}


/**
 * Create Photo element when necessary
 */
function createPhoto(){
	photo = document.createElement('div');
	photo.setAttribute("id","Photo");
	thebox = findObj('DynamicBox');
	log('thebox:' + thebox.id);
	if(typeof thebox != 'undefined'){
		thebox.appendChild(photo);
	}
}

/*****************
 * START SCRIPTS *
 *****************/

/* Prototype test */
addLoadListener(PrototypeTest);

/* detect current browser and output warning message if necessary */
BrowserDetect.init(OldBrowserMsg);
log('Current browser: ' + BrowserDetect.userAgent);

/* start form helper methods */
FormHelpers.init();

// cookies
Cookies.init();

// check popup blocker
if(doCheckPopupBlocker) {
	addLoadListener(checkPopupBlocker);
}

/* Routines for explorer 6 */
if((BrowserDetect.browser.toLowerCase() == "explorer") && (BrowserDetect.version < 7)){
	
	var isIE6 = true;
	var isIE6 = BrowserDetect.isIE6
	
	log('Starting routines for IE 6...');
	
	if(placeLanguageList) {
		log('Moving the language list div if necessary.');
		addLoadListener(placeLanguageLinksOnTop);
	}

	log('Checking for png images...');
	if(FixPNG){
		// background png's 
		bgsleight.init();
		// img png's
		pngfix.init();
	}
	
}

/* Check environment */
addLoadListener(env.init);

if(showScreenInfo){
	addEventSimple(window,"resize",env.calculatePageSize);
	addEventSimple(window,"resize",env.calculateScreenUsage);
	addEventSimple(window,"scroll",env.calculatePageScroll);
}

/* Cookies */
Cookies.init();

/* Error logging and feedback */
addLoadListener(dump);