////////////////////////////////////////////////////////
// ExternalOpen                                       //
//                                                    //
// -Opens external hyperlinks in new window           //
////////////////////////////////////////////////////////

function ExternalOpen() {
    if (!(null == document.links) && document.links.length > 0) {
        for (var i = 0; i < document.links.length; i++) {
            if (document.links[i].hostname > '' && 'http:' == document.links[i].protocol && (document.links[i].pathname.toLowerCase().indexOf('media(') > -1 || document.links[i].pathname.toLowerCase().indexOf('.pdf') > -1 || (document.links[i].hostname.toLowerCase().indexOf(document.location.hostname) == -1))) {
                document.links[i].target = 'siteExtern';
            }
        }
    }
}

////////////////////////////////////////////////////////
// Onload event attach - attaches ExternalOpen()      //
////////////////////////////////////////////////////////

if (typeof window.addEventListener != "undefined") {
    window.addEventListener("load", ExternalOpen, false);
}
else {
    if (typeof window.attachEvent != "undefined") {
        window.attachEvent("onload", ExternalOpen);
    }
    else {
        ExternalOpen_addLoadFunction()
    }
}

function ExternalOpen_addLoadFunction() {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = ExternalOpen;
    }
    else {
        window.onload = function() {
            oldonload();
            ExternalOpen();
        }
    }
}




/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
/*												*/
/* Search form									*/
/*												*/
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */








/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
/*												*/
/* Search form									*/
/*												*/
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
function SubmitSearchForm(formObject) {

    function parseDate(dateString) {
        var dateArray = dateString.split('/'); // DD/MM/YYYY
        var day = dateArray[0];
        var month = dateArray[1] - 1;
        var year = dateArray[2];
        if (year < 100) {
            year = parseInt('20' + year);
            dateArray[2] = year;
        }
        var res = new Date(year, month, day);
        if (year != res.getFullYear() || month != res.getMonth() || day != res.getDate()) {
            return null;
        }
        return res;
    }

    //var StartDay = formObject.StartDateDay.value;
    //if (StartDay == "...")
    //    StartDay = "01";
    //var StartMonthYear = formObject.StartDateMonthYear.value;
    //var StartMonthYearArray = StartMonthYear.split(',');
    //StartMonth = StartMonthYearArray[0];
    //StartYear = StartMonthYearArray[1];
    var Quantity = 0;
    var Facilities = '';
    for (var i = 0; i < formObject.elements.length; i++) {
        if (formObject.elements[i].name.indexOf('Facility') != -1) {
            if (formObject.elements[i].checked == true) {
                var Id = formObject.elements[i].value;
                Facilities += Id + ',1;';
            }
        }
    }
    var date = document.getElementById('StartDateDayMonthYear').value;
    date = parseDate(date);
    if (!date) {
        alert(wrongDateFormat);
        return;
    }
    $('#StartDateDayMonthYearValue').datepicker('setDate', date);
    formObject.StartDate.value = document.getElementById('StartDateDayMonthYearValue').value; //StartYear + '-' + StartMonth + '-' + StartDay;
    formObject.Facilities.value = Facilities;
    formObject.submit();
}


function SetOrderBy(element) {
    var FormObject = document.forms['Search'];
    FormObject.OrderBy.value = element.options[element.selectedIndex].value;
    var urchinPath = '/tracking/search/sortere-';
    switch (element.options[element.selectedIndex].value) {
        case 'ARRIVALDATEASC':
            urchinPath += 'dato';
            //urchinTracker(urchinPath);
            break;
        case 'TOTALPRICEASC':
            urchinPath += 'pric';
            //urchinTracker(urchinPath);
            break;
        case 'AREA':
            urchinPath += 'område';
            //urchinTracker(urchinPath);
            break;
    }
    pageTracker._trackPageview(urchinPath);
    SubmitSearchForm(FormObject);
}

function CreateSelectBox(name, startPosition, endPosition, valueIndex, selectedValue, data, className) {
    document.write('<select name="' + name + '" id="' + name + '" class="' + className + '">');
    document.write('<option value=""></option>');
    var ii;
    for (var i = startPosition; i <= endPosition; i++) {
        if (i < 10) { ii = '0' + (i + valueIndex) } else { ii = i }
        document.write('<option value="' + ii + '"');
        if ((i + valueIndex) == selectedValue) { document.write(' selected="selected" ') };
        document.write('>');
        if (data != null) { document.write(data[i]) } else { document.write(i) };
        document.write('</option>');
    }
    document.write('</select>');
}

var IsSimple = true;
function ToggleSearchType() {
    var ExtendedObject = document.getElementById('ExtendedSearchForm');
    var ExtendedItemObject = document.getElementById('ExtendedSearchFormItem');
    var ExtendedButtonObject = document.getElementById('ExtendedSearchFormButton');
    var SimpleButtonObject = document.getElementById('SimpleSearchFormButton');
    var FormObject = document.forms['Search'];
    if (IsSimple) {
        //urchinTracker('/tracking/forside/udvidetsearch');
        pageTracker._trackPageview('/tracking/forside/udvidetsearch');
        ExtendedObject.style.display = 'block';
        ExtendedItemObject.style.display = 'block';
        ExtendedButtonObject.style.display = 'none';
        SimpleButtonObject.style.display = 'block';
        FormObject.IsExtendedSearch.value = 'true';
        IsSimple = false;
    } else {
        ExtendedObject.style.display = 'none';
        ExtendedItemObject.style.display = 'none';
        ExtendedButtonObject.style.display = 'block';
        SimpleButtonObject.style.display = 'none';
        FormObject.IsExtendedSearch.value = 'false';
        IsSimple = true;
    }
}

function SelectLocation(siteId, districtId, regionId, areaId) {
    if (districtId != '') { SelectDistrict(districtId) }
    if (regionId != '') { SelectRegion(siteId, regionId) }
    //if (areaId != '') { SelectArea(siteId, areaId) }
    SelectArea(siteId, areaId);
}


function SelectDistrict(districtId) {
    var FormObject = document.forms['Search'];

    if (districtId == '') {
        districtId = FormObject.DistrictId.options[FormObject.DistrictId.selectedIndex].value;
        var urchinPath = '/tracking/forside/landsdel-' + FormObject.DistrictId.options[FormObject.DistrictId.selectedIndex].text;
        //urchinTracker(urchinPath);
        pageTracker._trackPageview(urchinPath);
    }
    else if (FormObject.DistrictId != null) {
        for (var i = 0; i < FormObject.DistrictId.options.length; i++) {
            if (FormObject.DistrictId.options[i].value == districtId) {
                FormObject.DistrictId.options[i].selected = 'true';
            }
        }
    }
    var FileName = '';

    try {
        for (var i = 0; i < DistrictMapList.length; i++) {
            District = DistrictMapList[i].split(',');
            if (District[0] == districtId) {
                FileName = District[1];
                i = DistrictMapList.length;
            }
        }
    }
    catch (ex) {
        return;
    }

    if (FileName == '') {
        FileName = '1030_2.gif';
        ResetRegions();
        FormObject.RegionId.options.length = 1;
        FormObject.RegionId.options[0] = new Option(RegionListHeader, '');
    } else {
        FileName = FileName;

    }
    var f1 = FileName.lastIndexOf("_");
    var f2 = FileName.substr(f1 + 1).replace(".gif", "");
    var MapObject = document.getElementById('Map');
    if (MapObject != null) {
        MapObject.src = '/media/' + FileName;
        document.getElementById('selectedRegion').innerHTML = f2;
    }

    LoadRegions(districtId);
}



function SelectDistrictOnMouseOver(districtId) {
    //alert ("districtId = " + districtId);
    var FileName = '';
    for (var i = 0; i < DistrictMapList.length; i++) {
        District = DistrictMapList[i].split(',');
        if (District[0] == districtId) {
            FileName = District[1];
        }
    }
    if (FileName == '') {
        FileName = '1030_2.gif';
        ResetRegions();
    }

    var MapObject = document.getElementById('Map');

    var f1 = FileName.lastIndexOf("_");
    var f2 = FileName.substr(f1 + 1).replace(".gif", "");
    //alert ("Test = " + document.getElementById('selectedRegion').innerHTML)
    if (document.getElementById('selectedRegion').innerHTML > 3 && f2 != "2") {
        MapObject.src = '/media/mapOver/1030_' + document.getElementById('selectedRegion').innerHTML + "_" + f2 + ".gif";
    } else {
        MapObject.src = '/media/' + FileName;
    }
}
function regionMouseOut() {
    var MapObject = document.getElementById('Map');
    if (document.getElementById('selectedRegion').innerHTML == "") {
        document.getElementById('selectedRegion').innerHTML = "2";
    }
    MapObject.src = '/media/1030_' + document.getElementById('selectedRegion').innerHTML + ".gif";
}

function ResetRegions() {
    try {
        var FormObject = document.forms['Search'];
        for (var i = 0; i < RegionList.length; i++) {
            Region = RegionList[i].split(',');
            var MapDot = document.getElementById('MapDot' + Region[1]);
            if (MapDot != null)
                MapDot.style.display = 'none';
            var MapDotText = document.getElementById('MapDotTextContainer' + Region[1]);
            if (MapDotText != null)
                MapDotText.style.display = 'none';
        }
    }
    catch (ex) { }
}

function ResetRegionDots() {
    var FormObject = document.forms['Search'];
    for (var i = 0; i < RegionList.length; i++) {
        Region = RegionList[i].split(',');
        var MapDot = document.getElementById('MapDot' + Region[1]);
        MapDot.style.display = 'none';
        var MapDotText = document.getElementById('MapDotTextContainer' + Region[1]);
        MapDotText.style.display = 'none';
    }
}

function LoadRegions(districtId) {
    RegionSelectBox = document.forms['Search'].RegionId;
    var ii = 1;
    RegionSelectBox.options.length = 0;
    RegionSelectBox.options[0] = new Option(RegionListHeader, '');
    ResetRegions();
    for (var i = 0; i < RegionList.length; i++) {
        Region = RegionList[i].split(',');
        if (Region[0] == districtId) {
            RegionSelectBox.options[ii] = new Option(Region[2], Region[1]);
            var MapDot = document.getElementById('MapDot' + Region[1]);
            if (MapDot != null)
                MapDot.style.display = 'block';
            ii++;
        }
    }
    //RegionSelectBox.options[ii] = new Option(Region[0], districtId);
}

function SelectRegion(siteId, regionId) {
    var FormObject = document.forms['Search'];
    if (FormObject.RegionId != null) {
        for (var i = 1; i < FormObject.RegionId.options.length; i++) {
            var MapDotText = document.getElementById('MapDotTextContainer' + FormObject.RegionId.options[i].value);
            var MapDot = document.getElementById('MapDot' + FormObject.RegionId.options[i].value)
            MapDotText.style.display = 'none';
            MapDot.style.zIndex = 10;
        }
    }
    if (regionId == '') {
        var urchinPath = '/tracking/forside/region-' + FormObject.RegionId.options[FormObject.RegionId.selectedIndex].text;
        //urchinTracker(urchinPath);
        pageTracker._trackPageview(urchinPath);
        regionId = FormObject.RegionId.options[FormObject.RegionId.selectedIndex].value;
        if (siteId == 102) {
            if (regionId == '') {
                AreaSelectBox = document.forms['Search'].AreaId;
                AreaSelectBox.options.length = 0;
                AreaSelectBox.options[0] = new Option(AreaListHeader, '');
                ResetAreas();
                for (var i = 0; i < DistrictMapList.length; i++) {
                    District = DistrictMapList[i].split(',');
                    FileName = District[1];
                }
                var MapObject = document.getElementById('Map');
                MapObject.src = '/media/' + FileName;
                return;
            }
        }
    } else if (FormObject.RegionId != null) {
        for (var i = 0; i < FormObject.RegionId.options.length; i++) {
            if (FormObject.RegionId.options[i].value == regionId) {
                FormObject.RegionId.options[i].selected = 'true';
            }
        }
    }
    var MapDotText = document.getElementById('MapDotTextContainer' + regionId);
    var MapDot = document.getElementById('MapDot' + regionId);
    if (MapDot != null) {
        MapDot.style.zIndex = 100;
        MapDotText.style.display = 'block';
    }
    if (siteId == 102) {
        var FileName = '';
        for (var i = 0; i < RegionMapList.length; i++) {
            Region = RegionMapList[i].split(',');
            if (Region[0] == regionId) {
                FileName = Region[1];
                i = RegionMapList.length;
            }
        }
        if (FileName == '') {
            FileName = '1030_2.gif';
            ResetRegions();
            FormObject.RegionId.options.length = 1;
            FormObject.RegionId.options[0] = new Option(RegionListHeader, '');
        } else {
            FileName = FileName;
        }
        var MapObject = document.getElementById('Map');
        MapObject.src = '/media/' + FileName;
        ResetRegionDots();
        LoadAreas(regionId);
    }
}

function ResetAreas() {
    var FormObject = document.forms['Search'];
    for (var i = 0; i < AreaList.length; i++) {
        Area = AreaList[i].split(';');
        var MapDot = document.getElementById('MapDotArea' + Area[0]);
        MapDot.style.display = 'none';
        var MapDotText = document.getElementById('MapDotAreaTextContainer' + Area[0]);
        MapDotText.style.display = 'none';
    }
}

function LoadAreas(regionId) {
    AreaSelectBox = document.forms['Search'].AreaId;
    var ii = 1;
    AreaSelectBox.options.length = 0;
    AreaSelectBox.options[0] = new Option(AreaListHeader, '');
    ResetAreas();
    for (var i = 0; i < AreaList.length; i++) {
        Area = AreaList[i].split(';');
        if (Area[1] == regionId) {
            AreaSelectBox.options[ii] = new Option(Area[3], Area[2]);
            var MapDot = document.getElementById('MapDotArea' + Area[0]);
            MapDot.style.display = 'inline';
            ii++;
        }
    }
}

function SelectArea(siteId, areaId) {
    var FormObject = document.forms['Search'];
    var urchinPath = '/tracking/forside/area-';
    if (siteId == 102) {
        for (var i = 0; i < AreaList.length; i++) {
            Area = AreaList[i].split(';');
            var MapDotText = document.getElementById('MapDotAreaTextContainer' + Area[0]);
            var MapDot = document.getElementById('MapDotArea' + Area[0])
            MapDotText.style.display = 'none';
            MapDot.style.zIndex = 10;
        }
        if (areaId == '') {
            urchinPath += FormObject.AreaId.options[FormObject.AreaId.selectedIndex].value;
            //urchinTracker(urchinPath);
            pageTracker._trackPageview(urchinPath);
            areaId = FormObject.AreaId.selectedIndex;
        } else {
            if ( isNaN(parseInt(areaId)) ) {
                for (var i = 0; i < AreaList.length; i++) {
                    if (areaId == AreaList[i].split(';')[2]) {
                        areaId = AreaList[i].split(';')[0];
                        break;
                    }
                }
            }
            for (var i = 0; i < FormObject.AreaId.options.length; i++) {
                var Value = FormObject.AreaId.options[i].value;
                Area = AreaList[areaId].split(';');
                if (Value == Area[2]) {
                    FormObject.AreaId.options[i].selected = true;
                }
            }
        }
    } else if (FormObject.AreaId != null) {
        for (var i = 1; i < FormObject.AreaId.options.length; i++) {
            var MapDotText = document.getElementById('MapDotAreaTextContainer' + FormObject.AreaId.options[i].value);
            var MapDot = document.getElementById('MapDotArea' + FormObject.AreaId.options[i].value)
            MapDotText.style.display = 'none';
            MapDot.style.zIndex = 10;
        }
        if (areaId == '') {
            areaId = FormObject.AreaId.options[FormObject.AreaId.selectedIndex].value;
            urchinPath += areaId;
            //urchinTracker(urchinPath);
            pageTracker._trackPageview(urchinPath);
        } else {
            for (var i = 0; i < FormObject.AreaId.options.length; i++) {
                if (FormObject.AreaId.options[i].value == areaId) {
                    FormObject.AreaId.options[i].selected = 'true';
                }
            }
        }
    }
    var MapDotText = document.getElementById('MapDotAreaTextContainer' + areaId);
    var MapDot = document.getElementById('MapDotArea' + areaId);
    
    if(MapDot != null)
        MapDot.style.zIndex = 100;

    if (MapDotText != null)
        MapDotText.style.display = 'inline';
}

function LookUpPrice() {
    var FormObject = document.forms['Book'];

    var NumberOfAdults = FormObject.NumberOfAdults.options[FormObject.NumberOfAdults.selectedIndex].value
    var NumberOfChildren = FormObject.NumberOfChildren.options[FormObject.NumberOfChildren.selectedIndex].value
    FormObject.NumberOfPersons.value = Math.abs(NumberOfAdults) + Math.abs(NumberOfChildren);

    var actionstr = '/composite-441.htm';
    actionstr += '?NumberOfPersons=' + FormObject.NumberOfPersons.value + '&AgencyId=' + FormObject.AgencyId.value;
    actionstr += '&HouseId=' + FormObject.HouseId.value + '&StartDate=' + FormObject.StartDate.value;
    actionstr += '&PeriodLength=' + FormObject.PeriodLength.value + '&LanguageId=' + FormObject.LanguageId.value + '&CurrencyCode=' + FormObject.CurrencyCode.value;

    var iframeObject = document.getElementById('PriceLookUp');
    iframeObject.src = actionstr;

    //FormObject.method = 'get';
    //FormObject.action = '/composite-441.htm';
    //FormObject.target = 'PriceLookUp';
    //FormObject.submit();

    //FormObject.method = 'post';
    //FormObject.action = '';
    //FormObject.target = '_top';
}

function LoadPeriodLength(element) {
    var PeriodObject = document.forms['Search'].PeriodLength;
    PeriodObject.options.length = 0;
    var PersonsObject = document.forms['Search'].NumberOfPersons;
    PersonsObject.options.length = 0;
    var SelectedValue = 4;
    for (var i = 0; i < document.forms['Search'].elements.length; i++) {
        if (document.forms['Search'].elements[i].type == 'radio') {
            if (document.forms['Search'].elements[i].checked == true) {
                SelectedValue = document.forms['Search'].elements[i].value;
            }
        }
    }
    switch (SelectedValue) {
        case '2':
            PeriodObject.options[0] = new Option('3 ' + Days, 3);
            PeriodObject.options[1] = new Option('4 ' + Days, 4);
            PeriodObject.options[2] = new Option('5 ' + Days, 5);
            switch (SelectedPeriodLength) {
                case '3':
                    PeriodObject.options[0].selected = true;
                    break;
                case '4':
                    PeriodObject.options[1].selected = true;
                    break;
                case '5':
                    PeriodObject.options[2].selected = true;
                    break;
            }
            break;

        case '5':
            PeriodObject.options[0] = new Option('2 ' + Weeks, 14);
            PeriodObject.options[1] = new Option('3 ' + Weeks, 21);
            PeriodObject.options[2] = new Option('4 ' + Weeks, 28);
            PeriodObject.options[3] = new Option('5 ' + Weeks, 35);
            switch (SelectedPeriodLength) {
                case '14':
                    PeriodObject.options[0].selected = true;
                    break;
                case '21':
                    PeriodObject.options[1].selected = true;
                    break;
                case '28':
                    PeriodObjectoptions[2].selected = true;
                    break;
                case '35':
                    PeriodObject.options[3].selected = true;
                    break;
            }
            break;

        default:
            PeriodObject.options[0] = new Option('1 ' + Week, 7);
            PeriodObject.options[1] = new Option('2 ' + Weeks, 14);
            PeriodObject.options[2] = new Option('3 ' + Weeks, 21);
            PeriodObject.options[3] = new Option('4 ' + Weeks, 28);
            PeriodObject.options[4] = new Option('5 ' + Weeks, 35);
            switch (SelectedPeriodLength) {
                case '7':
                    PeriodObject.options[0].selected = true;
                    break;
                case '14':
                    PeriodObject.options[1].selected = true;
                    break;
                case '21':
                    PeriodObject.options[2].selected = true;
                    break;
                case '28':
                    PeriodObject.options[3].selected = true;
                    break;
                case '35':
                    PeriodObject.options[4].selected = true;
                    break;
            }
            break;
    }
    if (SelectedValue == 4)//Discount for two persons only
    {
        PersonsObject.options[0] = new Option('1', 1);
        PersonsObject.options[1] = new Option('2', 2);
        if (SelectedNumberOfPersons == '' || SelectedNumberOfPersons == 1) {
            PersonsObject.options[0].selected = true;
        } else {
            //PersonsObject.options[Math.abs(SelectedNumberOfPersons)-1].selected = true; 
            PersonsObject.options[1].selected = true;
        }
    }
    else {
        PersonsObject.options[0] = new Option('1', 1);
        PersonsObject.options[1] = new Option('2', 2);
        PersonsObject.options[2] = new Option('3', 3);
        PersonsObject.options[3] = new Option('4', 4);
        PersonsObject.options[4] = new Option('5', 5);
        PersonsObject.options[5] = new Option('6', 6);
        PersonsObject.options[6] = new Option('7', 7);
        PersonsObject.options[7] = new Option('8', 8);
        PersonsObject.options[8] = new Option('9', 9);
        PersonsObject.options[9] = new Option('10', 10);
        PersonsObject.options[10] = new Option('11', 11);
        PersonsObject.options[11] = new Option('12', 12);
        PersonsObject.options[12] = new Option('13', 13);
        PersonsObject.options[13] = new Option('14', 14);
        PersonsObject.options[14] = new Option('15', 15);
        PersonsObject.options[15] = new Option('16', 16);
        PersonsObject.options[16] = new Option('17', 17);
        PersonsObject.options[17] = new Option('18', 18);
        PersonsObject.options[18] = new Option('19', 19);
        PersonsObject.options[19] = new Option('20', 20);
        PersonsObject.options[20] = new Option('21', 21);
        PersonsObject.options[21] = new Option('22', 22);
        PersonsObject.options[22] = new Option('23', 23);
        PersonsObject.options[23] = new Option('24', 24);
        PersonsObject.options[24] = new Option('25', 25);
        if (SelectedNumberOfPersons == '') {
            PersonsObject.options[2].selected = true;
        } else {
            PersonsObject.options[Math.abs(SelectedNumberOfPersons) - 1].selected = true;
        }
    }
    switch (SelectedPeriodLength) {
        case '3':
            //PersonsObject.options[Math.abs(SelectedPeriodLength) - 1].selected = true;
            break;
        case '4':
            break;
        case '5':
            break;
        case '7':
            break;
        case '14':
            break;
        case '21':
            break;
        case '28':
            break;
        case '35':
            break;
    }
}

/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
/*												*/
/* Send to friend								*/
/*												*/
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
var IsSendToFriendFormVisible = false;
function ToggleSendToFriendForm() {
    var SendToFriendFormObject = document.getElementById('SendToFriendForm');
    if (IsSendToFriendFormVisible) {
        SendToFriendFormObject.style.display = 'none';
        IsSendToFriendFormVisible = false;
    } else {
        SendToFriendFormObject.style.display = 'block';
        IsSendToFriendFormVisible = true;
    }
}

function SubmitSendToFriend() {
    var FormObject = document.forms['Book'];
    var Email = FormObject.RecipientEmail.value;
    var IsValidEmail = true;
    if (Email != '') {
        var At = Email.indexOf('@')
        var Dot = Email.indexOf('.', At)
        if (At < 1 || At == (Email.length - 3) || Dot < 1 || Dot == (Email.length - 1)) {
            IsValidEmail = false;
        }
    } else {
        IsValidEmail = false;
    }

    if (FormObject.SenderName.value == '' || !IsValidEmail) {
        alert(MissingSendToFriendInput);
    } else {
        FormObject.action = '';
        FormObject.State.value = 'SendToFriend';
        FormObject.submit();
    }
}


/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
/*												*/
/* Print										*/
/*												*/
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
function PrintPage(url) {
    var PrintWindow = window.open(url + '?TemplateId=16', 'PrintWindow');
    Print.Window.focus();
}

function PrintBookingSearchResults() {
    var FormObject = document.forms['Search'];
    FormObject.target = '_blank';
    FormObject.TemplateId.value = 16;
    FormObject.Print.value = 'True';
    SubmitSearchForm(document.Search);
    FormObject.target = '_top';
    FormObject.TemplateId.value = 11;
    FormObject.Print.value = 'False';
}

function PrintBookingConfirmation() {
    var DetailObject = document.getElementById('Detail');
    var PrintWindow = window.open('/composite-380.htm', 'Print');
    var PrintableContainerObject = PrintWindow.document.getElementById('PrintableContainer');
    PrintableContainerObject.innerHTML = 'HELLO';
    alert(DetailObject.innerHTML);
}

function PrintBookingBrowser() {
    var Url = document.location.href + '?TemplateID=16&Print=True';
    var PrintWindow = window.open(Url);
    PrintWindow.focus();
}

function PrintBookingMemo() {
    var Url = document.location.href + '?TemplateID=16&Print=True';
    var PrintWindow = window.open(Url);
    PrintWindow.focus();
}

function PrintBookingDetail() {
    var Url = document.location.href + '?TemplateID=16&Print=True';
    var PrintWindow = window.open(Url);
    PrintWindow.focus();
}

function PrintBookingPhotos() {
    var Url = document.location.href + '?TemplateID=16&Print=True&Photos=True';
    var PrintWindow = window.open(Url);
    PrintWindow.focus();
}

function HideNonePrintableElements() {
    var SearchFormObject = document.getElementById('SearchForm');
    if (SearchFormObject) {
        SearchFormObject.style.display = 'none';
    }

    var ResultsObject = document.getElementById('Results');
    if (ResultsObject) {
        ResultsObject.style.marginLeft = '0px';
    }

    var ResultsNavigationTopObject = document.getElementById('ResultsNavigationTop');
    if (ResultsNavigationTopObject) {
        ResultsNavigationTopObject.style.display = 'none';
    }
    var ResultsNavigationBottomObject = document.getElementById('ResultsNavigationBottom');
    if (ResultsNavigationBottomObject) {
        ResultsNavigationBottomObject.style.display = 'none';
    }
}

/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
/*												*/
/* Search for house id							*/
/*												*/
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */


function GoToHouse(path, modePath) {
    //urchinTracker('/tracking/forside/husnrseach');
    try {
        pageTracker._trackPageview('/tracking/forside/husnrseach');
    }
    catch (err) { }
    var FormObject = document.forms['SearchForHouse'];
    var HouseId = document.getElementById('HouseId').value;

    if (document.getElementById('AgencyId').options) {
        var AgencyId = document.getElementById('AgencyId').value;
    } else {
        var AgencyId = document.getElementById('AgencyId').value;
    }
    if (AgencyId == 102) { AgencyId = 24 }
    if (AgencyId == 101) { AgencyId = 24 }
    if (HouseId != '' && AgencyId != '') {
        document.location.href = '/' + path + '/' + modePath + '-' + HouseId + '-' + AgencyId + '.htm';
    } else {
        alert(MissingHouseSearchInput);
    }
}


/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
/*												*/
/* Date											*/
/*												*/
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
var daysInMonthArray = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

function isLeapYear(inputYear) {
    if (inputYear % 400 == 0 || (inputYear % 4 == 0 && inputYear % 100 != 0)) return true;
    return false;
}

function addOption(obj, value, text, selected) {
    var oOption = document.createElement("OPTION");
    obj.options.add(oOption);
    oOption.value = value;
    oOption.innerHTML = text;
    if (selected)
        oOption.selected = true;
}

function PreSetEndDate(element) {
    var FormObject = document.forms['Search'];
    var StartDate = '';
    var StartDay = FormObject.StartDateDay.options[FormObject.StartDateDay.selectedIndex].value;
    var StartMonthYear = FormObject.StartDateMonthYear.options[FormObject.StartDateMonthYear.selectedIndex].value;
    var StartMonthYearArray = StartMonthYear.split(',');
    var StartMonth = Math.abs(StartMonthYearArray[0]) - 1;
    var StartYear = StartMonthYearArray[1];
    var StartDayObject = FormObject.StartDateDay;

    if (isLeapYear(StartYear))
        daysInMonthArray[1] = 29;

    var previasDaysCount = 0;
    if (StartDayObject.options[0].value == '') {
        previasDaysCount = StartDayObject.options.length + 1;
    }
    else {
        previasDaysCount = StartDayObject.options.length;
    }

    if (previasDaysCount != daysInMonthArray[StartMonth]) {
        while (StartDayObject.options.length > 0)
            StartDayObject.remove(StartDayObject.options.length - 1);

        for (var day = 1; day <= daysInMonthArray[StartMonth]; day++) {
            if (day < 10)
                addOption(StartDayObject, '0' + day, day, day == StartDay);
            else
                addOption(StartDayObject, day, day, day == StartDay);
        }
    }

    /*var EndDate = new Date(StartYear, StartMonth, StartDay);
    EndDate = AddDays(EndDate, 7)
	
	for(var i=0;i<FormObject.EndDateDay.options.length;i++){
    if(FormObject.EndDateDay.options[i].value == EndDate.getDate()){
    FormObject.EndDateDay.options[i].selected = 'selected';
    }
    }
    for(var i=0;i<FormObject.EndDateMonthYear.options.length;i++){
    var ThisMonth = EndDate.getMonth()+1;
    var ThisYear = EndDate.getFullYear();
    var EndDateMonthYear = FormObject.EndDateMonthYear.options[i].value;
    var EndDateMonthYearArray = EndDateMonthYear.split(',');
    var EndDateMonth = EndDateMonthYearArray[0];
    var EndDateYear = EndDateMonthYearArray[1];
    if(ThisMonth == EndDateMonth && ThisYear == EndDateYear){
    FormObject.EndDateMonthYear.options[i].selected = 'selected';
    }
    }*/
}


function GetNextSaturday() {
    var TempToday = new Date()
    var Weekday = TempToday.getDay();
    var Difference = 6 - Weekday;
    var Saturday = new Date(TempToday.getTime() + ((Difference * 24 * 60 * 60 * 1000)))
    var Day = Saturday.getDate()
    if (Day < 10) { Day = '0' + Day }
    var Month = Saturday.getMonth() + 1
    if (Month < 10) { Month = '0' + Month }
    var Year = Saturday.getFullYear()
    return Saturday;
}

function GetDateDifference(startDate, endDate) {
    var DayMilliSeconds = 1000 * 60 * 60 * 24
    var StartDateMilliSeconds = startDate.getTime()
    var EndDateMilliSeconds = endDate.getTime()
    var Difference = Math.abs(EndDateMilliSeconds - StartDateMilliSeconds)
    return Math.round(Difference / DayMilliSeconds)
}

function GetWeekday(date) {
    var ThisDay = date.getDay() - 1;
    if (date.getDay() == 0) { ThisDay = 6 }
    return WeekdayShortName[ThisDay];
}

function FormatDate(value) {
    var Day = value.substr(8, 2);
    var Month = value.substr(5, 2);
    var Year = value.substr(0, 4);
    var formattedDate = new Date(Year, Month - 1, Day);
    return formattedDate;
}

function GetMonthLength(month, year) {
    return 32 - new Date(year, month, 32).getDate();
}

function GetMonthStartDay(month, year) {
    return new Date(year, month, 1).getDay();
}

function AddDays(date, numberOfDays) {
    var TemporaryDate = date
    var NewDate = new Date(TemporaryDate.getTime() + (numberOfDays * 24 * 60 * 60 * 1000));
    return NewDate;
}



/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
/*												*/
/* Photos										*/
/*												*/
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
function ShowPreview(src, id) {
    Photo = document.getElementById('Preview');
    src = src.replace(id, 'id');
    src = src.replace('/M', '/B');
    src = src.replace('id', id);
    Photo.src = src;
}


/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
/*												*/
/* Cart											*/
/*												*/
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
function AddToShoppingCart(element, id, checkInsurance) {
    var OptionObject = document.getElementById('Option' + id);
    if (checkInsurance != false) { FindInsuranceItems(id) }
    switch (element.type) {
        case 'checkbox':
            if (!element.checked) {
                OptionObject.style.display = 'none';
                ResetPrice(element, id);
            } else {
                OptionObject.style.display = 'block';
                SetPrice(element, id);
            }
            break;

        case 'select-one':
            if (element.selectedIndex == 0) {
                OptionObject.style.display = 'none';
                ResetPrice(element, id);
            } else {
                OptionObject.style.display = 'block';
                SetPrice(element, id);
            }
            break;
    }
}


function FindInsuranceItems(id) {
    var FormObject = document.forms['Book'];
    for (var i = 0; i < FormObject.elements.length; i++) {
        if (FormObject.elements[i].name.indexOf('ProductItem') != -1) {
            var OptionInfo = FormObject.elements[i].value;
            OptionInfo = OptionInfo.split(',');
            Id = OptionInfo[0];
            if (OptionInfo[3] == 'INSURANCE') {
                if (Id != id) {
                    FormObject.elements[i].checked = false;
                    AddToShoppingCart(FormObject.elements[i], Id, false)
                }
            }
        }
    }
    var InsuranceObject = document.getElementById('InsuranceNotIncluded');
    if (!FindSelectedInsuranceItems(id)) {
        InsuranceObject.style.display = 'block';
    } else {
        InsuranceObject.style.display = 'none';
    }
}

function FindSelectedInsuranceItems(id) {
    var FormObject = document.forms['Book'];
    for (var i = 0; i < FormObject.elements.length; i++) {
        if (FormObject.elements[i].name.indexOf('ProductItem') != -1) {
            var OptionInfo = FormObject.elements[i].value;
            OptionInfo = OptionInfo.split(',');
            Id = OptionInfo[0];

            if (OptionInfo[3] == 'INSURANCE') {
                if (FormObject.elements[i].checked) {
                    return true;
                }
            }

        }
    }
    return false;
}

function SetPrice(element, id) {
    switch (element.type) {
        case 'checkbox':
            var OptionInfo = element.value;
            break;

        case 'select-one':
            var OptionInfo = element.options[element.selectedIndex].value;
            break;
    }
    OptionInfo = OptionInfo.split(',');
    var Id = OptionInfo[0];
    var Quantity = OptionInfo[1];
    var Price = OptionInfo[2];

    switch ($(element).attr('unitname')) {
        case 'Per Week':
            Price = Price * Math.ceil($("input[name='PeriodLength']").val() / 7);
            break;
        case 'Per Day':
            Price = Price * $("input[name='PeriodLength']").val();
            break;
        case 'Per Person':
            Price = Price * $("input[name='NumberOfAdults']").val();
            break;
        case 'Per Person Per Day':
            Price = Price * $("input[name='NumberOfAdults']").val() * $("input[name='PeriodLength']").val();
            break;
        case 'Per Person Per Week':
            Price = Price * $("input[name='NumberOfAdults']").val() * Math.ceil($("input[name='PeriodLength']").val() / 7);
            break;
    }
    
    var TotalPriceForOption = Price * Quantity;

    // Write price in html and input
    PriceInProductList = document.getElementById('PriceInProductList' + id);
    PriceInSelectedProductList = document.getElementById('PriceInSelectedProductList' + id);
    PriceInProductList.innerHTML = FormatPrice(TotalPriceForOption);
    PriceInSelectedProductList.innerHTML = FormatPrice(TotalPriceForOption);
    //PriceInputInSelectedProductList = document.getElementById('PriceInputInSelectedProductList' + id);
    //PriceInputInSelectedProductList.value = TotalPriceForOption;

    // Set total price
    SetTotalPrice()
}

function ResetPrice(element, id) {
    switch (element.type) {
        case 'checkbox':
            var OptionInfo = element.value;
            break;

        case 'select-one':
            var OptionInfo = element.options[element.selectedIndex].value;
            break;
    }
    OptionInfo = OptionInfo.split(',');
    var Id = OptionInfo[0];
    var Price = OptionInfo[2];
    var Quantity = OptionInfo[1];
    var TotalPriceForOption = 0;

    // Write price in html and input
    PriceInProductList = document.getElementById('PriceInProductList' + id);
    PriceInSelectedProductList = document.getElementById('PriceInSelectedProductList' + id);
    PriceInProductList.innerHTML = FormatPrice(TotalPriceForOption);
    PriceInSelectedProductList.innerHTML = FormatPrice(TotalPriceForOption);

    // Set total price
    SetTotalPrice()
}

function SetTotalPrice() {
    var FormObject = document.forms['Book'];
    var TotalProductPrice = 0;
    for (var i = 0; i < FormObject.elements.length; i++) {
        if (FormObject.elements[i].name.indexOf('ProductItem') != -1 && FormObject.elements[i].value.indexOf('DEPOSIT') == -1) {
            var OptionInfo = '';
            switch (FormObject.elements[i].type) {
                case 'checkbox':
                    if (FormObject.elements[i].checked) {
                        OptionInfo = FormObject.elements[i].value;
                    }
                    break;

                case 'select-one':
                    OptionInfo = FormObject.elements[i].options[FormObject.elements[i].selectedIndex].value;
                    break;

                default:
                    OptionInfo = FormObject.elements[i].value; ;
                    break;
            }
            if (OptionInfo != '') {
                OptionInfo = OptionInfo.split(',');
                var Price = OptionInfo[2];
                var Quantity = OptionInfo[1];
                TotalProductPrice += Math.abs(Price * Quantity);
            }
        }
    }
    var TotalPrice = document.getElementById('TotalPrice');
    realPrice = Math.abs(FormObject.HousePrice.value) + TotalProductPrice;

    if ($.isFunction(totalPriceChanged))    //bornholm functionality
        totalPriceChanged();
    else                                    //all other's functionalities        
        TotalPrice.innerHTML = FormatPrice(realPrice);
}


function CheckNumberOfPersons(numberAllowed, element) {
    if (numberAllowed == '') { numberAllowed = 0 }
    var FormObject = document.forms['Book'];
    var NumberOfChildren = Math.abs(FormObject.NumberOfChildren.options[FormObject.NumberOfChildren.selectedIndex].value);
    var NumberOfAdults = Math.abs(FormObject.NumberOfAdults.options[FormObject.NumberOfAdults.selectedIndex].value);
    if (NumberOfChildren + NumberOfAdults > numberAllowed) {
        alert(PersonsAllowed + numberAllowed);
        if (element.name == 'NumberOfChildren') {
            FormObject.NumberOfChildren.options[0].selected = true;
        } else {
            FormObject.NumberOfAdults.options[1].selected = true;
        }
    }
}

/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
/*												*/
/* Price										*/
/*												*/
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
function FormatPrice(price) {
    var FormattedPrice;
    price = Math.round(price * 100) / 100
    if (price == 0) {
        FormattedPrice = '0,00'
    } else {
        price = new String(price);
        if (price.indexOf('.') != -1) {
            FormattedPrice = price.replace('.', ',');
        } else {
            FormattedPrice = price.replace(/(\d*)/, "$1,00 ");
        }
    }
    return AddDots(FormattedPrice);
}

function AddDots(nStr) {
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + '.' + '$2');
    }
    return x1 + x2;
}

/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
/*												*/
/* Booking										*/
/*												*/
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
function MoveToNextStep(action, direction) {
    var FormObject = document.forms['Book'];
    FormObject.action = action;
    FormObject.Direction.value = direction;
}

//For bornholm ferry booking
function MoveToNextStep1(action, linkName, houseId, agencyId, currentNumberOfPersons, direction, ownerAgencyId) {
    if (ownerAgencyId == 10 && direction == "Forward" && false) {
        if (isValidNames())
            prepareBooking(action, linkName, houseId, agencyId, currentNumberOfPersons, direction);
    }
    else
        MoveToNextStepForm1(action, linkName, houseId, agencyId, currentNumberOfPersons, direction);
}


function MoveToNextStepForm1(action, linkName, houseId, agencyId, currentNumberOfPersons, direction) {

    var FormObject = document.forms['Book'];
    var LocationHref = document.location.href;

    //Set number of persons
    var NumberOfAdults = Math.abs(FormObject.NumberOfAdults.options[FormObject.NumberOfAdults.selectedIndex].value);
    var NumberOfChildren = Math.abs(FormObject.NumberOfChildren.options[FormObject.NumberOfChildren.selectedIndex].value);
    var NumberOfInfants = Math.abs(FormObject.NumberOfInfants.options[FormObject.NumberOfInfants.selectedIndex].value);
    var NumberOfPersons = NumberOfAdults + NumberOfChildren + NumberOfInfants;


    //Update number of persons query string
    if (NumberOfPersons != currentNumberOfPersons) {
        LocationHref = LocationHref.replace('pers-' + currentNumberOfPersons, 'pers-' + NumberOfPersons);
    }

    //Update page name in query string
    var CurrentPageName = linkName + '-1-' + houseId + '-' + agencyId + '.htm';
    LocationHref = LocationHref.replace(CurrentPageName, action);

    FormObject.action = LocationHref;
    FormObject.Direction.value = direction;
    FormObject.submit();
}

function CheckNumberOfCharacters(element) {
    if (element.value.length > 499) { element.value = element.value.substring(0, 499); }
}


/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
/*												*/
/* Calendar										*/
/*												*/
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
function OpenCalendar(url) {
    var CalendarWindow = window.open(url, 'CalendarWindow', 'width=490,height=400,status=1');
    CalendarWindow.focus();
}

function OpenCalendarForm(url) {
    //urchinTracker('/tracking/forside/kalenderOpen');
    pageTracker._trackPageview('/tracking/forside/kalenderOpen');
    var CalendarWindow = window.open(url, 'CalendarWindow', 'width=300,height=350,status=1');
    CalendarWindow.focus();
}


/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
/*												*/
/* Memo											*/
/*												*/
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
function GetMemoLength() {
    var MemoCookie = GetCookie('Memo');
    if (MemoCookie) {
        var CurrentList = MemoCookie.split(';');
        document.write(CurrentList.length);
    } else {
        document.write(0);
    }
}


function SetMemoLength() {
    var MemoLength = document.getElementById('MemoLengthContainer');
    var MemoCookie = GetCookie('Memo');
    var Length = 0;
    if (MemoCookie) {
        var CurrentList = MemoCookie.split(';');
        Length = CurrentList.length;
    }
    if (MemoLength) {
        if (Length == '') { Length = 0 }
        MemoLength.innerHTML = Length;
    }
}

function SetMemoButton(imageId, lcid, type, buttonType) {
    Button = document.getElementById(imageId);
    if (buttonType == 'TEXT') {
        if (type == 'ADD') {
            Button.innerHTML = AddToMemo;
        } else {
            Button.innerHTML = RemoveFromMemo;
        }
    } else {
        if (type == 'ADD') {
            Button.innerHTML = '<img src="/media/' + lcid + '_58.gif" class="Button" alt="" />';
        } else {
            Button.innerHTML = '<img src="/media/' + lcid + '_116.gif" class="Button" alt="" />';
        }
    }
}

function AddMemoItem(agencyId, houseId, startDate, numberOfDays, imageId, lcid, buttonType) {
    if (!VerifyMemoItem(agencyId, houseId)) {
        var MemoCookie = GetCookie('Memo');
        var HousePath = '' + agencyId + ',' + houseId + ',' + startDate + ',' + numberOfDays + '';
        if (!MemoCookie) {
            SetCookie('Memo', HousePath, SetDate(), false);
        } else {
            var CurrentPath = GetCookie('Memo');
            SetCookie('Memo', CurrentPath + ';' + HousePath, SetDate(), false)
        }
        SetMemoButton(imageId, lcid, 'DELETE', buttonType);
        SetMemoLength();
    } else {
        DeleteMemoItem(agencyId, houseId, startDate, numberOfDays, imageId, lcid, buttonType);
    }
}

function DeleteMemoItem(agencyId, houseId, startDate, numberOfDays, imageId, lcid, buttonType) {
    var MemoCookie = GetCookie('Memo');
    var HousePath = '' + agencyId + ',' + houseId + ',' + startDate + ',' + numberOfDays + '';
    var NewList = '';
    if (MemoCookie) {
        var CurrentList = MemoCookie.split(';');
        for (i = 0; i < CurrentList.length; i++) {
            var CurrentPath = CurrentList[i].split(',');
            var CurrentAgencyId = CurrentPath[0];
            var CurrentHouseId = CurrentPath[1];
            if (CurrentHouseId != houseId) {
                (NewList != '') ? NewList += ';' : NewList += '';
                NewList += CurrentList[i];
            }
        }
    }
    SetCookie('Memo', NewList, SetDate(), false);
    SetMemoButton(imageId, lcid, 'ADD', buttonType);
    SetMemoLength();
}

function VerifyMemoItem(agencyId, houseId) {
    var MemoCookie = GetCookie('Memo');
    if (MemoCookie) {
        var CurrentList = MemoCookie.split(';');
        for (i = 0; i < CurrentList.length; i++) {
            var CurrentPath = CurrentList[i].split(',');
            var CurrentAgencyId = CurrentPath[0];
            var CurrentHouseId = CurrentPath[1];
            if (CurrentHouseId == houseId) {
                return true;
            }
        }
    }
    return false;
}


/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
/*												*/
/* Catalogue									*/
/*												*/
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
var CatalogueLength = 0;
var Action = '';
function SelectCatalogue(element, count) {
    var ElementVerification = new String(element);
    var FormObject = document.forms['Catalogue'];
    var IsObject = false;
    (ElementVerification.indexOf('[object', 0) >= 0) ? IsObject = true : IsObject = false;
    var Id;
    var TempElement = element;
    if (!IsObject) {
        for (i = 0; i < document.forms['Catalogue'].elements.length; i++) {
            ElementId = FormObject.elements[i].id;
            Id = ElementId.substring(6, ElementId.length);
            if (FormObject.elements[i].value == Id) {
                element = eval('FormObject.elements[' + i + ']');
                if (!element.checked) {
                    element.checked = false;
                } else {
                    element.checked = true;
                }
            }
        }
        element = document.getElementById('Agency' + TempElement);
        if (!element.checked) {
            element.checked = true;
        } else {
            element.checked = false;
        }
    }
    if (typeof (count) == 'undefined')
        count = 3;
    if (element.checked) {
        if (CatalogueLength < count) {
            CatalogueLength += 1;
        } else {
            element.checked = false;
            alert(OnlyCataloguesAllowed[count]);
        }
    } else {
        CatalogueLength -= 1;
    }
    var AgencyList = '';
    for (i = 0; i < FormObject.elements.length; i++) {
        if (FormObject.elements[i].type == 'checkbox') {
            if (FormObject.elements[i].checked == true) {
                if (AgencyList != '') { AgencyList += ';' }
                AgencyList += FormObject.elements[i].value;
            }
            if (FormObject.elements[i].value == '5A65237E-015A-4083-9C60-F6768E87C4DB') {
                FormObject.elements[i].checked = false;
            }
        }
    }
    FormObject.elements['AgencyList'].value = AgencyList;
}

function ResetCatalogueSelection() {
    var FormObject = document.forms['Catalogue'];
    for (i = 0; i < FormObject.elements.length; i++) {
        if (FormObject.elements[i].type == 'checkbox' && FormObject.elements[i].value != '5A65237E-015A-4083-9C60-F6768E87C4DB') {
            FormObject.elements[i].checked = false;
        }
    }
    FormObject.elements['AgencyList'].value = '5A65237E-015A-4083-9C60-F6768E87C4DB';
    CatalogueLength = 0;
}

function ValidateCatalogueOrderForm(formObject) {
    var IsValid = false;
    for (var i = 0; i < formObject.elements.length; i++) {
        if (formObject.elements[i].type == 'checkbox') {
            if (formObject.elements[i].checked == true) {
                IsValid = true;
                i = formObject.elements.length;
            }
        }
    }
    if (IsValid == false) {
        return false;
    } else {

        //urchinTracker('/Katalog/step2');
        return true;
    }
}


function SetCatalogueFormMode(mode) {
    var FormObject = document.forms['Catalogue'];
    FormObject.Mode.value = mode;
    if (mode == 'Map') {
        FormObject.Direction.value = 'Backward';
        //urchinTracker('/Katalog/step1');
    } else {
        FormObject.Direction.value = 'Forward';

        //urchinTracker('/Katalog/final3');
    }
}




/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
/*												*/
/* Map											*/
/*												*/
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
function OpenMap(id, lcid) {
    var LanguagePath = '';
    switch (lcid) {
        case 1030:
            LanguagePath = '';
            break;
        case 1031:
            LanguagePath = '&lang=de';
            break;
        case 1033:
            LanguagePath = '&lang=en';
            break;
        case 1043:
            LanguagePath = '&lang=en';
            break;
        case 1044:
            LanguagePath = '&lang=en';
            break;
        case 1053:
            LanguagePath = '&lang=en';
            break;
    }
    var Win = window.open('http://feriepartner.krak.dk/kortRutelink.aspx?type=kort&ID=' + id + LanguagePath, 'Map', 'width=680, height=550');
    Win.focus();
}

function OpenDrivingDirections(id, lcid) {
    var LanguagePath;
    switch (lcid) {
        case 1030:
            LanguagePath = '';
            break;
        case 1031:
            LanguagePath = '&lang=de';
            break;
        case 1033:
            LanguagePath = '&lang=en';
            break;
        case 1043:
            LanguagePath = '&lang=en';
            break;
        case 1044:
            LanguagePath = '&lang=en';
            break;
        case 1053:
            LanguagePath = '&lang=en';
            break;
    }
    var Win = window.open('http://feriepartner.krak.dk/kortRutelink.aspx?type=rute&ID=' + id + LanguagePath, 'Directions', 'width=680, height=600, scrollbars=yes');
    Win.focus();
}

function OpenAddressFinder(url) {
    var Phone = document.forms['Book'].Phone.value;
    if (Phone != '') {
        var FinderWindow = window.open('/composite-458.htm?Phone=' + Phone, 'AddressFinderr', 'width=150, height=50');
        FinderWindow.focus();
    } else {
        alert('Udfyld venligst telefonnr!');
    }
}


/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
/*												*/
/* Cookie										*/
/*												*/
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
function SetCookie(name, value, expires, isSecure) {
    var CurrentCookie = name + '=' + escape(value) + '; path=/' +
	((expires) ? '; expires=' + expires.toUTCString() : '') +
	((isSecure) ? '; secure' : '');
    document.cookie = CurrentCookie;
}

function GetCookie(name) {
    var Cookie = document.cookie;
    var Prefix = name + '=';
    var Begin = Cookie.indexOf('; ' + Prefix);
    if (Begin == -1) {
        Begin = Cookie.indexOf(Prefix);
        if (Begin != 0) return null;
    } else {
        Begin += 2;
    }
    var End = document.cookie.indexOf(';', Begin);
    if (End == -1)
        End = Cookie.length;
    return unescape(Cookie.substring(Begin + Prefix.length, End));
}

function DeleteCookie(name) {
    if (GetCookie(name)) {
        document.cookie = name + '=' +
		'; expires=Thu, 01-Jan-70 00:00:01 UTC';
    }
}

function SetDate() {
    var CurrentDate = new Date();
    RepairDate(CurrentDate);
    return new Date((CurrentDate.getTime() + 365 * 1000 * 60 * 60 * 24));
}

function RepairDate(date) {
    var Base = new Date(0);
    var Skew = Base.getTime();
    if (Skew > 0)
        date.setTime(date.getTime() - Skew);
}

function GetTomorrow() {
    CurrentDate = new Date()
    if (10 > CurrentDate.getDate()) { Day = '0' + CurrentDate.getDay() } else { Day = CurrentDate.getDate() }
    if (10 > Math.round((CurrentDate.getMonth() + 1))) { Month = '0' + CurrentDate.getMonth() } else { Month = Math.round(CurrentDate.getMonth() + 1) }
    Year = CurrentDate.getYear();
    return AddDays(FormatDate(Year + '-' + Month + '-' + Day), 1)
}



/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
/*												*/
/* Form validation								*/
/*												*/
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
function getArgs() {
    var args = new Object();
    var query = location.search.substring(1);
    var pairs = query.split("&");
    for (i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('=');
        if (pos == -1) continue;
        var argname = pairs[i].substring(0, pos);
        var value = pairs[i].substring(pos + 1);
        args[argname] = unescape(value);
    }
    return args;
}

/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
/*												*/
/* Contact form 								*/
/*												*/
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
function LoadOpeningHoursStart(start, end) {
    var FormObject = document.forms['Contact'];
    var HoursFrom = FormObject.HoursFrom;
    HoursFrom.options.length = 1;
    var ii = 1;
    for (var i = Math.abs(start); Math.abs(end) > i; i++) {
        HoursFrom.options[ii] = new Option(i, i);
        ii++;
    }
}

function LoadOpeningHoursEnd(start, end) {
    var FormObject = document.forms['Contact'];
    var HoursTo = FormObject.HoursTo;
    HoursTo.options.length = 1;
    var ii = 1;
    for (var i = (Math.abs(start) + 1); Math.abs(end) >= i; i++) {
        HoursTo.options[ii] = new Option(i, i);
        ii++;
    }
}


/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
/*												*/
/* Form			 								*/
/*												*/
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
var args = getArgs();

function fncValidateForm(aryArgs, lngLCID, formObject) {
    if (formObject.Direction.value != 'Backward') {
        // v3.0 browsers
        // This function validates forms
        // The input is an array of arguments with 3 arguments per form field
        // The array must have this syntax: 'Form field name', 'Text to alert in case of error', 'Type of validation'
        // Example: 'companyName', 'Company name', 'R', 'email', 'Email', 'RisEmail'
        // Requires the function fncFindObj()
        // Version 1.0, dec 2000, by Søren Larsen
        var objField; // The form field object matching the given field name
        var strFieldAlertText; // The given text that represent the form field in the alert box
        var strTypeOfValidation; // The given validation string
        // Possible values: 
        // - R - input is required
        // - RisEmail - input is required, must be an email address (one or more characters + @ + 3 or more characters and at least one dot after the first lette after the @)
        // - NisEmail - input is NOT required, but if input is given it must be an email address
        // - RisChecked2:3 - input is required, between 2 and 3 of the checkboxes must checked
        // - NisChecked0:3 - input is not required, no more that 3 of the checkboxes can be checked
        // - RisNum - input is required, must be a number
        // - NisNum - input is NOT required, but if input is given it must be a number
        // - RinRange10:400 - input is required, must be a number in this case in the range 10 to 400
        // - NinRange1:5 - input is NOT required, but if input is given it must be a number in this case in the range 1 to 5
        var i; // Counter for iterations
        var pAt; // Pointer for email '@'
        var pDot; // Pointer for email '.'
        var lngCheckedFields; // Count number of checked checkboxes
        var n; // Counter for array of checkboxes / radio buttons
        var pColon; // Pointer for ':' in numeric ranges
        var lngMin; // Minimum value for numeric ranges
        var lngMax; // Maximum value for numeric ranges
        var strErrors = ''; // Used to build string for alert box

        if (lngLCID == 1030) {
            var strMsgGeneral1 = 'Du mangler at udfylde nogle felter.';
            var strMsgGeneral2 = 'Udfyld venligst:';
            var strMsgGeneral3 = 'og send formularen igen.';
            var strMsgIsEmail = 'skal indeholde en gyldig email-adresse';
            var strMsgIsChecked1 = ' (du må ikke markere flere end ';
            var strMsgIsChecked2 = ' (du skal markere mindst ';
            var strMsgIsChecked3 = ' (du skal markere ';
            var strMsgIsChecked4 = ' (du skal markere mellem ';
            var strMsgIsChecked5 = ' af checkboksene';
            var strMsgIsNum = 'skal være et tal';
            var strMsgInRange1 = ' (skal være et tal mellem ';
            var strMsgAnd = ' og ';
        }
        else if (lngLCID == 1031) {
            var strMsgGeneral1 = 'Geben Sie bitte fehlende Informationen an.';
            var strMsgGeneral2 = 'Bitte ausfüllen:';
            var strMsgGeneral3 = 'und drücken Sie nochmals.';
            var strMsgIsEmail = 'must contain a valid e-mail address';
            var strMsgIsChecked1 = ' (you must check no more than ';
            var strMsgIsChecked2 = ' (you must check at least ';
            var strMsgIsChecked3 = ' (you must check ';
            var strMsgIsChecked4 = ' (you must check between ';
            var strMsgIsChecked5 = ' of the checkboxes';
            var strMsgIsNum = 'must contain a number';
            var strMsgInRange1 = ' (must contain a number between ';
            var strMsgAnd = ' and ';
        }
        else if (lngLCID == 2057) {
            var strMsgGeneral1 = 'You need to specify additional information.';
            var strMsgGeneral2 = 'Please fill in:';
            var strMsgGeneral3 = 'and submit again.';
            var strMsgIsEmail = 'must contain a valid e-mail address';
            var strMsgIsChecked1 = ' (you must check no more than ';
            var strMsgIsChecked2 = ' (you must check at least ';
            var strMsgIsChecked3 = ' (you must check ';
            var strMsgIsChecked4 = ' (you must check between ';
            var strMsgIsChecked5 = ' of the checkboxes';
            var strMsgIsNum = 'must contain a number';
            var strMsgInRange1 = ' (must contain a number between ';
            var strMsgAnd = ' and ';
        }
        else if (lngLCID == 1043) {
            var strMsgGeneral1 = 'U hebt een aantal velden niet ingevuld.';
            var strMsgGeneral2 = 'Vul de volgende velden a.u.b. in:';
            var strMsgGeneral3 = 'en verstuur het formulier opnieuw.';
            var strMsgIsEmail = 'moet een geldig e-mailadres bevatten';
            var strMsgIsChecked1 = ' (u mag niet meer dan ';
            var strMsgIsChecked2 = ' (u moet minimaal  ';
            var strMsgIsChecked3 = ' (u moet ';
            var strMsgIsChecked4 = ' (u moet tussen ';
            var strMsgIsChecked5 = ' hokje(s) aanvinken';
            var strMsgIsNum = 'moet een getal zijn';
            var strMsgInRange1 = ' (moet een getal zijn tussen ';
            var strMsgAnd = ' en ';
        }
        else if (lngLCID == 1044) {
            var strMsgGeneral1 = 'Du mangler å utfylle noen felter.';
            var strMsgGeneral2 = 'Utfyll vennligst:';
            var strMsgGeneral3 = 'og send formularen igjen.';
            var strMsgIsEmail = 'skal inneholde en gyldig e-postadresse';
            var strMsgIsChecked1 = ' (du får ikke markere flere enn ';
            var strMsgIsChecked2 = ' (du skal markere minst ';
            var strMsgIsChecked3 = ' (du skal markere ';
            var strMsgIsChecked4 = ' (du skal markere mellom ';
            var strMsgIsChecked5 = ' av sjekkboksene';
            var strMsgIsNum = 'skal være et tall';
            var strMsgInRange1 = ' (skal være et tall mellom ';
            var strMsgAnd = ' og ';
        }
        else if (lngLCID == 1053) {
            var strMsgGeneral1 = 'Du har inte fyllt i alla fält i formuläret.';
            var strMsgGeneral2 = 'Vänligen fyll i:';
            var strMsgGeneral3 = 'och skicka igen.';
            var strMsgIsEmail = 'måste vara en giltig e-mail adress';
            var strMsgIsChecked1 = ' (du får inte markera fler än ';
            var strMsgIsChecked2 = ' (du måste markera minst ';
            var strMsgIsChecked3 = ' (du måste markera ';
            var strMsgIsChecked4 = ' (du måste markera mellan ';
            var strMsgIsChecked5 = ' av checkboxarna';
            var strMsgIsNum = 'skall innehålla ett tal';
            var strMsgInRange1 = ' (skall innehålla ett tal mellan ';
            var strMsgAnd = ' och ';
        }
        else {
            var strMsgGeneral1 = 'You need to specify additional information.';
            var strMsgGeneral2 = 'Please fill in:';
            var strMsgGeneral3 = 'and submit again.';
            var strMsgIsEmail = 'must contain a valid e-mail address';
            var strMsgIsChecked1 = ' (you must check no more than ';
            var strMsgIsChecked2 = ' (you must check at least ';
            var strMsgIsChecked3 = ' (you must check ';
            var strMsgIsChecked4 = ' (you must check between ';
            var strMsgIsChecked5 = ' of the checkboxes';
            var strMsgIsNum = 'must contain a number';
            var strMsgInRange1 = ' (must contain a number between ';
            var strMsgAnd = ' and ';
        }

        for (i = 0; i < (aryArgs.length - 2); i += 3) {
            objField = fncFindObj(aryArgs[i]);
            if (objField) {

                valField = objField.value;
                strFieldAlertText = aryArgs[i + 1];
                strTypeOfValidation = aryArgs[i + 2];

                // save status of array of checkboxes or radio buttons in variable.
                lngCheckedFields = 0
                if (objField.type == "checkbox" || objField.type == "radio" || (isArray(objField) && (objField[1].type == "checkbox" || objField[1].type == "radio")))
                    if (objField.checked) // Mark if only one checkbox exists i.e. there is no array (possible in dynamic arrays)
                    lngCheckedFields = 1;
                else
                    for (n = 0; n < objField.length; n++)
                    if (objField[n].checked)
                    lngCheckedFields++;

                if ((valField == '') || (valField == null && lngCheckedFields == 0) || ((objField.type == "checkbox" || objField.type == "radio") && objField.checked == false)) { // If no input was given
                    if (strTypeOfValidation.charAt(0) == 'R') { // and input is required
                        strErrors += '- ' + strFieldAlertText + '\n'; //build error string
                    }
                }
                else { // Input was given
                    if (strTypeOfValidation.indexOf('isEmail') != -1) {
                        pAt = valField.indexOf('@')
                        pDot = valField.indexOf('.', pAt)
                        if (pAt < 1 || pAt == (valField.length - 3) || pDot < 1 || pDot == (valField.length - 1))
                            strErrors += '- ' + strFieldAlertText + ' (' + strMsgIsEmail + ')\n';
                    }
                    else if (strTypeOfValidation.indexOf('isChecked') != -1) {
                        pColon = strTypeOfValidation.indexOf(':');
                        lngMin = strTypeOfValidation.substring(10, pColon);
                        lngMax = strTypeOfValidation.substring(pColon + 1);
                        if (lngCheckedFields < lngMin || lngMax < lngCheckedFields) {
                            if (lngMin == 0)
                                strErrors += '- ' + strFieldAlertText + strMsgIsChecked1 + lngMax + strMsgIsChecked5 + ')\n';
                            else if ((lngMax == 9999) && (lngCheckedFields > 9998)) //9999 means unlimited
                                strErrors += '- ' + strFieldAlertText + strMsgIsChecked2 + lngMin + strMsgIsChecked5 + ')\n';
                            else if (lngMin == lngMax)
                                strErrors += '- ' + strFieldAlertText + strMsgIsChecked3 + lngMin + strMsgIsChecked5 + ')\n';
                            else
                                strErrors += '- ' + strFieldAlertText + strMsgIsChecked4 + lngMin + strMsgAnd + lngMax + strMsgIsChecked5 + ')\n';
                        }
                    }
                    else if (strTypeOfValidation != 'R') { // The rest of the validation types are numeric
                        if (valField != '' + parseFloat(valField))
                            strErrors += '- ' + strFieldAlertText + ' (' + strMsgIsNum + ')\n';
                        else { // Value is a number
                            if (strTypeOfValidation.indexOf('inRange') != -1) {
                                pColon = strTypeOfValidation.indexOf(':');
                                lngMin = strTypeOfValidation.substring(8, pColon);
                                lngMax = strTypeOfValidation.substring(pColon + 1);
                                if (lngMin * 1 > valField * 1 || valField * 1 > lngMax * 1)
                                    strErrors += '- ' + strFieldAlertText + strMsgInRange1 + lngMin + strMsgAnd + lngMax + ')\n';
                            }
                        }
                    }
                }
            } // Field not found
        } // End of loop
        if (strErrors) {
            alert(strMsgGeneral1 + '\n\n' + strMsgGeneral2 + '\n' + strErrors + '\n' + strMsgGeneral3 + '\n\n');
        }
        document.blnReturnValue = (strErrors == '');
        return (strErrors == '');
    } else {
        //document.blnReturnValue = (strErrors == '');
        //return (strErrors == '');
        return true;
    }
}

function fncFindObj(strFormFieldName, d) { //v3.0
    var p, i, x;

    if (!d)
        d = document;
    if ((p = strFormFieldName.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[strFormFieldName.substring(p + 1)].document;
        strFormFieldName = strFormFieldName.substring(0, p);
    }
    if (!(x = d[strFormFieldName]) && d.all)
        x = d.all[strFormFieldName];
    for (i = 0; !x && i < d.forms.length; i++)
        x = d.forms[i][strFormFieldName];
    for (i = 0; !x && d.layers && i < d.layers.length; i++)
        x = fncFindObj(strFormFieldName, d.layers[i].document);
    return x;
}

function isArray(obj) {
    return (typeof (obj.length) == "undefined") ? false : true;
}

function fncGetRadioValue(aryName) {
    var aryFields;
    var objValue = '';
    aryFields = fncFindObj(aryName);
    if (aryFields) {
        if (aryFields.checked) // Mark if only one radiobutton exists i.e. there is no array (possible in dynamic arrays)
            objValue = aryFields.value;
        else
            for (n = 0; n < aryFields.length; n++)
            if (aryFields[n].checked)
            objValue = aryFields[n].value;
        return objValue;
    }
}

/** function for event  **/


function sendSerchform(obj) {

    if (obj) { event = obj; }

    if (event.keyCode == 13) {
        SubmitSearchForm(document.Search);
    }



}