﻿/*
----------------------------------------------------------
Initialize Namespace
----------------------------------------------------------
*/
window.Websajt = { Util: {}, Form: {}, Admin: {}, Effects: {} };

Websajt.Class = {
	create: function() {
		return function() {
			this.initialize.apply(this, arguments);
		}
	}
};

/*
----------------------------------------------------------
Milou.Constants
-Websajt.CustomEvents.MouseOverBox(this)
-Websajt.CustomEvents.MouseOutBox(this)
-Websajt.CustomEvents.Search(this)
-Websajt.CustomEvents.Submit(strButtonID)
-Websajt.CustomEvents.PreventSubmit()
-Websajt.CustomEvents.CheckContentHeight()
----------------------------------------------------------
*/

Websajt.CustomEvents = {
	MouseOverBox: function(objElement) {
		$(objElement).addClassName('hover');
	},
	MouseOutBox: function(objElement) {
		$(objElement).removeClassName('hover');
	},
	Search: function(strElement, strUrl) {
		document.location.href = strUrl + '?q=' + $F(strElement);
	},
	Submit: function(e, strButtonID, delay) {
		if (e.keyCode == 13) {
			if (delay != null) {
				setTimeout(function() { $(strButtonID).click() }, delay);
			}
			else
				$(strButtonID).click();
			return false;
		}
	},
	PreventSubmit: function(e, strButtonID) {
		try {
			if (e.keyCode == 13) {
				e.returnValue = false;
				e.cancel = true;
				e.preventDefault();
				e.stopPropagation();
			}
		}
		catch (exp) { }
	},
	CheckContentHeight: function() {

		if (Object.isElement($('ContainerContentLeft')) && Object.isElement($('ContainerContentMain')) && Object.isElement($('ContainerContentRight'))) {
			var intLeft = $('ContainerContentLeft').getHeight();
			var intMiddle = $('ContainerContentMain').getHeight();
			var intRight = $('ContainerContentRight').getHeight();

			if ((intLeft > intMiddle) && intLeft > intRight)
				$('ContainerContentRight').setStyle({ height: intLeft + 'px' })
			else if ((intMiddle > intLeft) && intMiddle > intRight)
				$('ContainerContentRight').setStyle({ height: intMiddle + 'px' })
		}
	}
};

Websajt.Util.deEncAddr = function(ea) {
	var em = '';
	for (i = 0; i < ea.length; ) {
		var le = '';
		le = ea.charAt(i) + ea.charAt(i + 1);
		em += String.fromCharCode(parseInt(le, 16));
		i += 2;
	}
	return em;
}

Websajt.Util.safeMail = function(ea) {
	document.location.href = 'mailto:' + Websajt.Util.deEncAddr(ea);
}

Websajt.Util.DoSubmit = function(btnInput) {
	$(btnInput).click();
}

Websajt.Util.ValidateCompanySearch = function() {

if ($F("txtSearchResultSearchBox") != "Sökord" && $F("txtSearchResultSearchBox") != "Search phrase") {
		Websajt.Util.DoSubmit('btnSearchResultSearchSubmit');
	}
}