
//Allow you to add multiple events to the onload event handler - props to simon willison
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

/*Makes secondary popup nav work in IE*/
function sfHover() {
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
	if(itsAllGood){
		var sfEls = document.getElementById("nav1").getElementsByTagName("li");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
addLoadEvent(sfHover);

//Makes link elements with class 'popup' open in a new browser window of fixed spec
function doPopups() {
  if (!document.getElementsByTagName) return false;
  var links = document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) {
	if (links[i].className.match("popup")) {
	  links[i].onclick = function() {
		window.open(this.getAttribute("href"), '_blank', 'resizable=1,location=0,statusbar=0,menubar=0,toolbar=0,directories=0,status=0,scrollbars=1,width=770,height=468');
		return false;
	  }
	  
	}
  }
}
addLoadEvent(doPopups);

/*Makes PN Opacity work in IE*/
var bgsleight	= function() {
	
	function fnLoadPngs() {
		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)";
			}
		}
	}

	function fnFixPng(obj) {
		var bg	= obj.currentStyle.backgroundImage;
		var src = bg.substring(5,bg.length-2);
		obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
		obj.style.backgroundImage = "url(x.gif)";
	}

	return {
		
		init: function() {
			
			if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
				addLoadEvent(fnLoadPngs);
			}
			
		}
	}
	
}();

bgsleight.init();


/* Client-side access to querystring name=value pairs
	Version 1.2.3
	22 Jun 2005
	Adam Vandenberg
	
	API Reference

	new Querystring([qs])
		Creates a new Querystring object, optionally passing a string qs to parse. If qs is omitted, the querystring from the current page is used. If qs is passed, it should not begin with a "?".
	
		// Parse the current page's querystring
		var qs = new Querystring()
	
		// Parse a given querystring
		var qs2 = new Querystring("name1=value1&name2=value2")
	
	Querstrying.get(name[, default_value])
		Returns the value of querystring parameter name if it exists, or default_value if it doesn't. If default_value is omitted and parameter name doesn't exist, returns null.
	
		var v1 = qs2.get("name1")
		var v3 = qs2.get("name3", "default value")
	
	Note: If a name appears more than once in a querystring only the last value is kept. 
	
	*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}
//end of client side query string access code


function getInnerText(target)
{
	var text = target.firstChild;

	while (text.nodeValue.match(/^\s*$/)) {
		text = text.nextSibling;
	}

	textString = text.nodeValue.replace(/^\W*(.*\w)\W*$/, "$1");

	return textString;
}

//----------------------------------------

//initiate form type QP buttons based on toggle value given in query string
function initialButtCheck(){
	if (!document.getElementById) return false;
	if (!document.fmEnq) return false;
	if (!document.fmEnq.enqtype) return false;
	
	var qs = new Querystring();
	var gen = qs.get('gen','F');
	if (gen == "T") {
		document.fmEnq.enqtype.value = "Generator Enquiry";
	}
}
addLoadEvent(initialButtCheck);

