﻿// JScript File

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' />" +
				"</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) {
    document.getElementById(elementID).setAttribute("class", 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);
}
