// JavaScript for Erw Gerrig holiday cottages

// requires 'met-util.js' to be loaded.

//---------------------------------------------------------------------------

(function (libname) { // name of utility library - see end
//---------------------------------------------------------------------------

// update links of certain classes to open in a new window.
function openLinksInNewWindowOfClass(link_class)
{
	var o_links = lib.getElementsByClassName(document, link_class);
	var win_popup = null;
// original features (amended to improve accessibility):
// 'width=800, height=460, status=yes, directories=no, toolbar=no, location=no, menubar=no, scrollbars=yes, resizable=no'
	var o_features = { 
		width: '800', 
		height: '460',
		status: 'yes', 
		directories: 'no', 
		toolbar: 'no', 
		location: 'no', 
		menubar: 'no', 
		scrollbars: 'yes', 
		resizable: 'yes'
		};

	var a_features = [];
	for (var item in o_features)
		a_features[a_features.length] = item + '=' + o_features[item];
	var s_features = a_features.join(',');

	var show_popup = function()
	{
		if (!win_popup || win_popup.closed)
			win_popup = window.open(href,'X', s_features);
		else
			win_popup.focus();

		return false;
	};

	for (var i = 0, o_link; o_link = o_links[i]; ++i)
	{
		if (!o_link || !(typeof o_link.getAttribute == 'function'))
			continue;

		var href = o_link.getAttribute('href');
		o_link.onclick = show_popup;

		var o_text = document.createTextNode(' (opens in new window)');
		o_link.setAttribute('title', o_link.getAttribute('title') + ' - opens in new window');
		o_link.parentNode.insertBefore(o_text, o_link.nextSibling);
	}
}
//---------------------------------------------------------------------------

// Code to execute
	if (!window[libname])
		return alert('Warning: library \'' + libname + ' not loaded.');

	var lib = window[libname];

	if (!lib.isSupported())
		return false;

	lib.addLoadEvent(function () { openLinksInNewWindowOfClass('disability-statement') });
	lib.addLoadEvent(function () { openLinksInNewWindowOfClass('short-breaks') });

//---------------------------------------------------------------------------
})('MET'); // library name - execute immediately
//---------------------------------------------------------------------------

// end of scripts