﻿// JScript File

$(document).ready(function ()
{
	var menuDelayReset;

	$("#topNavigation > ul > li").mouseenter(function ()
	{
		var menuItem = $(this);

		selectMenuItem(menuItem);
	});

	$("#topNavigation").mouseleave(function ()
	{
		menuDelayReset = window.setTimeout(resetMenu, 1000);
	});

	$("#topNavigation").mouseenter(function ()
	{
		window.clearTimeout(menuDelayReset);
	});

	function resetMenu()
	{
		var menuItem = $("#defaultMenuItem");

		if (menuItem.hasClass("selected"))
		{
			return;
		}

		menuItem.siblings().children("ul").fadeOut(300, function ()
		{
			menuItem.siblings().removeClass("selected");
			menuItem.siblings().children("ul").removeAttr("style");
		});

		menuItem.children("ul").css("display", "none");

		menuItem.addClass("selected");

		menuItem.children("ul").fadeIn(300, function ()
		{
			menuItem.children("ul").removeAttr("style");
		});
	}

	function selectMenuItem(menuItem)
	{
		menuItem.siblings().removeClass("selected");
		menuItem.addClass("selected");
	}

	/*function setDelay(){
	$("#topNavigation ul li ul").fadeOut(200);
	//$("#topNavigation ul li a").css("background", "none").fadeOut(200);
	}*/

	//	$("#topNavigation ul li ul").hover(function ()
	//	{
	//		//$(this).parent().find("ul li a").css("background", "none");
	//		//window.clearTimeout(delayfadeout);
	//	});

	/*function setDelay(){
	$("#topNavigation ul li ul").fadeOut(200);
	//$("#topNavigation ul li a").css("background", "none").fadeOut(200);
	}*/
});

function Bookmark()
{
	var title = document.title;
	var url = location.href;

	if (window.sidebar)
		window.sidebar.addPanel(title, url, "");
	else if (window.opera && window.print)
	{
		var mbm = document.createElement('a');
		mbm.setAttribute('rel', 'sidebar');
		mbm.setAttribute('href', url);
		mbm.setAttribute('title', title);
		mbm.click();
	}
	else if (document.all)
		window.external.AddFavorite(url, title);
}

function CheckMaxDaysInMonth(ddlDay, ddlMonth, ddlYear)
{
	var oMaxDaysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	var oDay = document.getElementById(ddlDay);
	var oMonth = document.getElementById(ddlMonth);
	var oYear = document.getElementById(ddlYear);

	var iDay = oDay.options[oDay.selectedIndex].value;
	var iMonth = oMonth.options[oMonth.selectedIndex].value;
	var iYear = oYear.options[oYear.selectedIndex].value;

	var bLeapYear = false;

	if (iYear % 4 == 0)
	{
		bLeapYear = true;

		if (iYear % 100 == 0)
			bLeapYear = false;

		if (iYear % 400 == 0)
			bLeapYear = true;
	}

	if (bLeapYear)
		oMaxDaysInMonth[1] = 29;

	if (iDay > oMaxDaysInMonth[iMonth - 1])
		oDay.selectedIndex = (oMaxDaysInMonth[iMonth - 1] - 1);
}

function OpenWindow(sUrl, sName, iWidth, iHeight, iLeft, iTop)
{
	window.open(sUrl, sName, "width=" + iWidth + ", height=" + iHeight + ", top=" + iTop + ", left=" + iLeft + ", screenY=" + iTop + ", screenX=" + iLeft);
}

var newwindow = null;

function OpenWindowWithFocus(sURL, sTitle, iWidth, iHeight)
{

	if ((newwindow != null) && (!newwindow.closed))
	{
		newwindow.close();
	}

	newwindow = window.open(sURL, sTitle, "width=" + iWidth + ", height=" + iHeight + ", top=100, left=100, screenY=100, screenX=100, scrollbars=no, status=no");

	newwindow.focus();

}

function OpenCampaignWindowWithFocus(sURL, iWidth, iHeight)
{

	if ((newwindow != null) && (!newwindow.closed))
	{
		newwindow.close();
	}

	newwindow = window.open(sURL, "Kampagnetilbud", "width=" + iWidth + ", height=" + iHeight + ", top=100, left=100, screenY=100, screenX=100, scrollbars=yes, status=no");

	newwindow.focus();

}

function SetFocus(ControlID)
{
	document.getElementById(ControlID).focus();
	document.getElementById(ControlID).value = document.getElementById(ControlID).value;
}

function VideoObject(sPath, iWidth, iHeight, bAutoPlay)
{
	// Because of the controller and statusbar
	iHeight = (iHeight + 45);

	var sHTML = "<object type='video/x-ms-wmv' data='" + sPath + "' width='" + iWidth + "' height='" + iHeight + "'>" +
				"<param name='src' value='" + sPath + "' />";

	if (bAutoPlay)
	{
		sHTML += "<param name='autostart' value='true' />" +
					"<param name='autoplay' value='true' />";
	}
	else
	{
		sHTML += "<param name='autostart' value='false' />" +
					"<param name='autoplay' value='false' />";
	}

	sHTML += "<param name='controller' value='false' />" +
				"<embed src='" + sPath + "' controller='false' displaysize='4' ";

	if (bAutoPlay)
		sHTML += "autostart='true' autoplay='true' ";
	else
		sHTML += "autostart='false' autoplay='false' ";

	sHTML += "playeveryframe='false' pluginspage='plugin.html' height='" + iHeight + "' width='" + iWidth + "'>" +
				"</object>";

	document.write(sHTML);
}

function FlashObject(sPath, iWidth, iHeight)
{
	var sHTML = "<!--[if !IE]> -->" +
				"<object type='application/x-shockwave-flash' data='" + sPath + "' width='" + iWidth + "' height='" + iHeight + "' scale='noscale' salign='lt'>" +
				"<!-- <![endif]-->" +
				"<!--[if IE]>" +
				"<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='" + iWidth + "' height='" + iHeight + "'>" +
				"<param name='movie' value='" + sPath + "' />" +
				"<!--><!---->" +
				"<param name='loop' value='true' />" +
				"<param name='menu' value='false' />" +
				"<param name='scale' value='noscale' />" +
				"<param name='salign' value='lt' />" +
                "<param name='WMODE' value='opaque' />" +
				"</object>" +
				"<!-- <![endif]-->";

	document.write(sHTML);
}

function SetWatermark(txt, sName)
{
	if (txt.value == '')
	{
		txt.setAttribute("class", sName);
		txt.setAttribute("className", sName);
	}
	else
	{
		RemoveWatermark(txt);
	}
}

function RemoveWatermark(txt)
{
	txt.removeAttribute("class");
	txt.removeAttribute("className");
}

function ChangeClass(elementID, newClassName)
{
	var element = document.getElementById(elementID);
	element.setAttribute("class", newClassName);
	element.setAttribute("className", newClassName);
}

function ChangeAttribute(elementID, attribute, value)
{
	document.getElementById(elementID).setAttribute(attribute, value);
}

function CreateHttpRequest()
{
	try { return new XMLHttpRequest(); } catch (e) { }
	try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch (e) { }
	try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch (e) { }
	return null;
}

function GetHttpResponse(sUrl)
{
	var httpReq = CreateHttpRequest();

	if (httpReq)
	{
		httpReq.open('GET', sUrl, false);
		httpReq.send(null);

		return httpReq.responseText;
	}
	else
	{
		return '';
	}
}

function SetCityName(txtCityClientID, txtPostcodeClientID)
{
	document.getElementById(txtCityClientID).value = GetHttpResponse('/x/function/CityNameFromPostalCode.ashx?postalcode=' + document.getElementById(txtPostcodeClientID).value);
}

function Decrypt(input)
{
	var output = "";

	for (var i = input.length - 1; i >= 0; i--)
	{
		output = output + input.substring(i, i + 1);
	}

	document.write("<a href='mailto:" + output + "'>" + output + "</a>");
}

function ToggleHover(str, AddHover)
{
	if (AddHover)
	{
		return str.replace(".jpg", "_o.jpg");
	}
	else
	{
		return str.replace("_o", "");
	}
}

function ReloadWindow()
{
	location.reload();
}

function PrintHtml(id, width, height) {
    w = window.open("#", "mywindow", "menubar=0,resizable=1,width=" + width + ",height=" + height + "");
    w.document.write("<html><body><div style='width:" + width + "px;height:" + height + ";'>" + $(id).html() + "</div></body></html>");
    w.print();
    w.close();
}

$(function ()
{
	$("#topBarLeft a img").hover(function () { this.src = ToggleHover(this.src, true); }, function () { this.src = ToggleHover(this.src, false); })
});

