
// Add a class name to the body as a global flag that the user has javascript.
document.observe('dom:loaded', function(){
	$(document.body).addClassName('js-enabled');
	if ($('socnetlnk_facebook') && $('socnetlnk_twitter'))
	{
		Swedish100SocNetLinks = new SocNetLinks( $('socnetlnk_facebook'), $('socnetlnk_twitter') );
	}
	if ($('maincol') && $('subcol'))
	{
		SubcolHeightAdjuster = new HeightAdjuster( $('maincol'), $('subcol') );
	}
});
// end js-enabled

/*
 * EnterClick listens on a containing element for the enter/return key being pressed.
 * When the enter key is pressed within a child input element that will submit the form, 
 * it will prevent the default form submittal and fire the click event of a designated button.
 * Usage:
 * $('fieldset_forgot').onEnterClick($('btn_Forgot'));
 * currently used on /account/login.aspx
 */
var EnterClick = Class.create({
	relevantTypes: $w('text password checkbox radio'),
	initialize: function(element, button)
	{
		this.element = $(element).addClassName("enterclick");
		this.button = $(button);
		this.element.observe('keypress', this.__keyPress.bindAsEventListener(this));
	},
__keyPress: function(e)
{
	var elSrc = e.element();
	if((e.keyCode == Event.KEY_RETURN) 
		&& (elSrc.nodeName == 'INPUT') 
		&& (this.relevantTypes.include(elSrc.type)))
		{
			// prevent default form submittal
			e.stop(); 
			// fire associated button's click event
			this.button.click();
	}
}
});
// Extend Element with enterclick
Element.addMethods({
	onEnterClick: function(element, button)
	{
		new EnterClick(element, button);
		return element;
	}
});
// end EnterClick

// start PrintPage
var PrintPage = Class.create ({
	initialize: function(link)
	{
		this.link = link;
		this.link.observe('click', this.__Click.bindAsEventListener(this));
	},
	__Click: function(e)
	{
		e.stop();
		window.print();
	}
});
// end PrintPage

// start PopupWindow
var PopupWindow = Class.create ({
	initialize: function(link, width, height, xtras)
	{
		this.popName = 'popup';
		this.link = link;
			this.url = this.link.href;
		this.altW = 640;
		this.altH = 480;
		this.altX = 'location=no,menubar=no,statusbar=no,toolbar=no,scrollbars=no,resizable=yes';
		this.popupW = width || this.altW;
		this.popupH = height || this.altH;
		this.popupX = xtras || this.altX;
		this.availH = screen.availHeight;
		this.availW = screen.availWidth;
		this.topPos = (this.availH - this.popupH) / 2;
		this.leftPos = (this.availW - this.popupW) / 2;
		this.features = 'width=' + this.popupW + ',height=' + this.popupH + ',' + this.popupX + ',top=' + this.topPos + ',left=' + this.leftPos;
		this.link.observe('click', this.__Click.bindAsEventListener(this));
	},
	__Click: function(e)
	{
		e.stop();
		var win = window.open(this.url, this.popName, this.features);
		win.focus();
	}
});
// end PopupWindow

// start ClosePopup
var ClosePopup = Class.create ({
	initialize: function(link)
	{
		this.link = link;
		this.link.observe('click', this.__Click.bindAsEventListener(this));
	},
	__Click: function(e)
	{
		e.stop();
		window.close();
	}
});
// end ClosePopup

// start HeightAdjuster
// set subItem to same height as mainItem
var HeightAdjuster = Class.create ({
	initialize: function(mainItem, subItem)
	{
		this.mainItem = mainItem;
		this.subItem = subItem;
		if (this.subItem.getHeight() > this.mainItem.getHeight()) {return}

		this.subTPad = parseInt(this.subItem.getStyle('padding-top')); // get first elements padding-top in pixels as a number
		this.subBPad = parseInt(this.subItem.getStyle('padding-bottom')); // get first elements padding-bottom in pixels as a number

		this.subItem.style.height = (this.mainItem.getHeight() - (this.subTPad + this.subBPad)) + 'px';
	}
});
// end HeightAdjuster

