
// window.onload functions --------------------------------------------------------------------------------------------------------
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') { window.onload = func; }
	else { window.onload = function() { oldonload(); func(); } }
}

// initialise XMLHTTPRequest object --------------------------------------------------------------------------------------------------------
function GetXmlHttpObject() {
	var xmlHttp;
	try { xmlHttp=new XMLHttpRequest(); } // Firefox, Opera 8.0+, Safari 
	 catch (e) { try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } // Internet Explorer
      catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
	   catch (e) { alert("Your browser does not support AJAX!"); return false; }}}
	return xmlHttp;
}

// cookies --------------------------------------------------------------------------------------------------------------------------------
var cookieEnabled=(navigator.cookieEnabled)? true : false // This next script checks whether cookies are enabled (and workable via javascript).
if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ //if not IE4+ nor NS6+
	document.cookie="testcookie"
	cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false
}
function createCookie(name,value,days) { // days - 0 = cookie expires when browser is closed, > 0 = cookie expires in X days time
	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=/";
}
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;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}

// wrap all children of a given parent tag with a new nested tag -----------------------------------------------------------------
function wrapChildrenWith(thisTag, thisParent) {
	while (thisParent.hasChildNodes) { 
		try { thisTag.appendChild(thisParent.firstChild); }
		catch(e) { break; }
	};
	thisParent.appendChild(thisTag);
}
