﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />

// ---------
// Globals
// ---------
var initSearch;
var gCounter = 0;
try {
    $(document).ready(function() {
        $('.tabset > li').bind('click', function() {
            $(this).siblings().removeClass('active');
            $(this).addClass('active');
            var id = '#' + $(this).children('span').attr('sel');

            var content = $(id);
            content.css('display', 'block');
            content.siblings('.tab').css('display', 'none');
            return false;
        });

        $('div.share').bind('mouseenter', function() {
            $(this).attr('class', 'share share-hover');
        });
        $('div.share').bind('mouseleave', function() {
            $(this).attr('class', 'share');
        });
    });
} catch (e) { }

// ------------------------------------------------------------
// This function will fire a click event on the specified control when the 
// enter key is pressed in a text field. Attach this function to the 
// onkeypress-event on the text field like this:
// <input type="text" onkeypress="return fireClickOnEnter(event, 'IdOfControlToFireClickOn');">
// ------------------------------------------------------------
function fireClickOnEnter(evt, controlId) {
    var control = document.getElementById(controlId);
    var keyCode = (typeof window.event == 'object') ? window.event.keyCode : evt.keyCode;

    // If enter is pressed -> fire click-event on the control
    if (control && (keyCode == 13)) {
        control.focus();
        control.click();
        return false;
    }
    else {
        return true;
    }
}

// ------------------------------------------------------------
// This function will fire a postbackon the specified control when the 
// enter key is pressed in a text field. Attach this function to the 
// onkeypress-event on the text field like this:
// <input type="text" onkeypress="return postbackOnEnter(event, 'IdOfControlToFirePostbackOn');">
// ------------------------------------------------------------
function postbackOnEnter(evt, controlId) {
    var keyCode = (typeof window.event == 'object') ? window.event.keyCode : evt.keyCode;

    // If enter is pressed -> do a postback
    if (keyCode == 13) {
        __doPostBack(controlId, '');
        return false;
    }
    else {
        return true;
    }
}

// ------------------------------------------------------------
// Returns the x coordinate of the specified object
// ------------------------------------------------------------
function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft;
            obj = obj.offsetParent;
        }
    }
    else if (obj.clientLeft) {
        curleft += obj.clientLeft;
    }
    return curleft;
}

// ------------------------------------------------------------
// Returns the y coordinate of the specified object
// ------------------------------------------------------------
function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curtop += obj.offsetTop;
            obj = obj.offsetParent;
        }
    }
    else if (obj.clientTop) {
        curtop += obj.clientTop;
    }
    return curtop;
}

// ---------------
// Toggles visibility of the specified element.
// ---------------
function toggleVisibility(elemId) {
    var elem = document.getElementById(elemId);

    if (elem) {
        if (elem.style.display == 'none') {
            elem.style.display = 'block';
        }
        else {
            elem.style.display = 'none';
        }
    }
}

// ---------------
// Toggles visibility of details for the specified divs.
// ---------------
function toggleDetails(noDetailDivId, detailDivId) {
    var noDetailDiv = document.getElementById(noDetailDivId);
    var detailDiv = document.getElementById(detailDivId);

    if (noDetailDiv && detailDiv) {
        if (noDetailDiv.style.display == 'none') {
            detailDiv.style.display = 'none';
            noDetailDiv.style.display = 'block';
        }
        else {
            noDetailDiv.style.display = 'none';
            detailDiv.style.display = 'block';
        }
    }
}

// ---------------
// Hides all windowed controls in browsers that
// can't display layers on top of them.
// ---------------
function hideWindowedControls() {
    if ((BrowserDetect.browser == 'Explorer') && (BrowserDetect.version < 7)) {
        // Hides all listboxes
        for (var i = 0; i < document.getElementsByTagName('select').length; i++) {
            document.getElementsByTagName('select')[i].style.visibility = 'hidden';
        }
    }
}

// ---------------
// Shows all windowed controls.
// ---------------
function showWindowedControls() {
    if ((BrowserDetect.browser) == 'Explorer' && (BrowserDetect.version < 7)) {
        // Show all listboxes
        for (var i = 0; i < document.getElementsByTagName('select').length; i++) {
            document.getElementsByTagName('select')[i].style.visibility = 'visible';
        }
    }
}

// ---------------
// Create cookie
// ---------------
function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

// ---------------
// Read cookie
// ---------------
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

// ---------------
// Returns the size of the viewport.
// ---------------
function getViewportSize() {
    size = {};
    if (window.innerHeight) {
        size.width = window.innerWidth;
        size.height = window.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) {
        size.width = document.documentElement.clientWidth;
        size.height = document.documentElement.clientHeight;
    }
    else if (document.body) {
        size.width = document.body.clientWidth;
        size.height = document.body.clientHeight;
    }
    return size;
}

// ---------------
// Returns the scroll offset
// ---------------
function getScrollOffset() {
    scrollOffset = {};
    if (window.pageYOffset)// all except Explorer
    {
        scrollOffset.x = window.pageXOffset;
        scrollOffset.y = window.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict
    {
        scrollOffset.x = document.documentElement.scrollLeft;
        scrollOffset.y = document.documentElement.scrollTop;
    }
    else if (document.body) // all other Explorers
    {
        scrollOffset.x = document.body.scrollLeft;
        scrollOffset.y = document.body.scrollTop;
    }
    return scrollOffset;
}

// ---------------
// Used by the pager on the object search page. Selects what page to display.
// ---------------
function searchResultSelectPage(pageIndex, hiddenControlId) {
    var hiddenControl = document.getElementById(hiddenControlId);
    if (hiddenControlId) {
        hiddenControl.value = pageIndex;
    }
    return true;
}

// ---------------
// Activates the object card with the specified id
// ---------------
function activateObjectCard(outerCard) {
    $(outerCard).attr('class', 'ObjectCardOuter ObjectCardActive Clickable');
    $(outerCard).find('.ObjectCardTools').show();

    return true;
}

// ---------------
// Deactivates the object card with the specified id
// ---------------
function deactivateObjectCard(outerCard) {
    $(outerCard).attr('class', 'ObjectCard ObjectCardOuter');
    $(outerCard).find('.ObjectCardTools').hide();

    return true;
}

// ---------------
// Activates the object list item with the specified id
// ---------------
function activateObjectListItem(index, favLink) {
    var ObjectListItemOuter = document.getElementById('ListItemOuter' + index);
    var previousObjectListItemTopDiv = document.getElementById('ObjectListItemTop' + (index - 1));
    var previousObjectListItemBottomDiv = document.getElementById('ObjectListItemBottom' + (index - 1));
    var objectListFavorite = document.getElementById(favLink);

    if (ObjectListItemOuter) {
        ObjectListItemOuter.style.border = 'solid 2px #ffc309';
    }
    if (previousObjectListItemTopDiv && previousObjectListItemBottomDiv) {
        deactivateObjectListItem(index - 1);
    }
    if (objectListFavorite) {
        objectListFavorite.className = 'ObjectFavorite';
    }


    return true;
}

// ---------------
// Deactivates the object list item with the specified id
// ---------------
function deactivateObjectListItem(index, favLink) {
    var ObjectListItemOuter = document.getElementById('ListItemOuter' + index);
    var objectListFavorite = document.getElementById(favLink);

    if (ObjectListItemOuter) {
        ObjectListItemOuter.style.border = 'solid 2px #ffffff';
    }
    if (objectListFavorite) {
        objectListFavorite.className = 'ObjectFavoriteGray';
    }

    return true;
}



// ---------------
// Used when adding/removing favorites on the search result page.
// ---------------
function handleFavorite(objectId) {
    var hiddenField = document.getElementById('HiddenFavoriteObjectId');
    if (hiddenField) {
        hiddenField.value = objectId;
        __doPostBack('HiddenFavoriteObjectId', '');
    }
}

// ---------------
// Perform object search.
// ---------------
function doObjectSearch(actionUrl) {
    var sourceForm = document.forms[0];
    var destForm = document.forms['ObjectSearchForm'];

    if (actionUrl) {
        destForm.action = actionUrl;
    }

    destForm.action = destForm.action.replace("&alternatives=true", "");
    
    // Copy search params to hidden search form and post it
    //ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_DropDownListAreaMax
    if (sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_TextBoxAreaMin) {
        destForm.la1.value = sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_TextBoxAreaMin.value;
        destForm.la2.value = sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_TextBoxAreaMax.value;
    }

    if (sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_TextBoxRoomMin) {
        destForm.r1.value = sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_TextBoxRoomMin.value;
        destForm.r2.value = sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_TextBoxRoomMax.value;
    }

    if (sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_TextBoxArealMin) {
        destForm.pa1.value = sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_TextBoxArealMin.value;
        destForm.pa2.value = sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_TextBoxArealMax.value;
    }

    if (sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_TextBoxTomtArealMin) {
        destForm.sa1.value = sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_TextBoxTomtArealMin.value.replace(/ /g, '');
        destForm.sa2.value = sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_TextBoxTomtArealMax.value.replace(/ /g, '');
    }
    //This replace(/ /g, ''), will remove all ' ' in the price field, sins we format the price like this 1 000 000
    destForm.pr1.value = sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_TextBoxPriceMin.value.replace(/ /g, '');
    destForm.pr2.value = sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_TextBoxPriceMax.value.replace(/ /g, '');

    if (sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_TextBoxFeeMin) {
        destForm.fee1.value = sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_TextBoxFeeMin.value;
        destForm.fee2.value = sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_TextBoxFeeMax.value;
    }

    if (sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_DropDownListChanged) {
        destForm.upd.value = sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_DropDownListChanged.options[sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_DropDownListChanged.selectedIndex].value;
    }
    if (sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_DropDownListVisning) {
        destForm.vis.value = sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_DropDownListVisning.options[sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_DropDownListVisning.selectedIndex].value;
    }

    destForm.lp.value = (sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxLagePlus &&
						 sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxLagePlus.checked)
							 ? '1' : '0';

    destForm.prm.value = (sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxPremium &&
						 sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxPremium.checked)
							 ? '1' : '0';

    destForm.newb.value = (sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_rbl_ObjectType_1 &&
						   sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_rbl_ObjectType_1.checked)
						     ? '1' : '0';

    destForm.bid.value = ($('div.SearchResult h1.smalH1 span.searchTerms').html().indexOf("budgivning") != -1) ? 1 : 0;
    

    if ($('div.SearchResult h1.smalH1 span.searchTerms').html().indexOf("med planerade visningar") != -1)
        destForm.vis.value = 1;
    else if ($('div.SearchResult h1.smalH1 span.searchTerms').html().indexOf("med visning idag") != -1)
        destForm.vis.value = 2;
    else if ($('div.SearchResult h1.smalH1 span.searchTerms').html().indexOf("med visning kommande vecka") != -1)
        destForm.vis.value = 3;
    else if ($('div.SearchResult h1.smalH1 span.searchTerms').html().indexOf("med visning kommande 14 dagar") != -1)
        destForm.vis.value = 4;
  
    

    destForm.lok.value = (sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxLokal &&
						   sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxLokal.checked)
						     ? '1' : '0';

    destForm.fast.value = (sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxFastighet &&
						   sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxFastighet.checked)
						     ? '1' : '0';

    if (sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_DropDownListKommersiellSubTyp) {
        destForm.st.value = sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_DropDownListKommersiellSubTyp.options[sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_DropDownListKommersiellSubTyp.selectedIndex].value;
    }

    if (sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_DropDownListMosaicType) {
        destForm.mos.value = sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_DropDownListMosaicType.options[sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_DropDownListMosaicType.selectedIndex].value;
    }

    // This (rather ugly) checkbox-to-index-mapping need to 
    // match the one in UISearchHandler.AddParamsFromRequest()
    destForm.sw.value = (
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxAldrestil && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxAldrestil.checked ? '1,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxModernStil && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxModernStil.checked ? '2,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxFunkis && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxFunkis.checked ? '3,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxRenoveringsbehov && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxRenoveringsbehov.checked ? '4,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxToppskick && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxToppskick.checked ? '5,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxFilterLokal && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxFilterLokal.checked ? '6,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxEnplanshus && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxEnplanshus.checked ? '7,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxFriliggandeHus && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxFriliggandeHus.checked ? '8,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxKedjeRadhus && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxKedjeRadhus.checked ? '9,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxCentralt && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxCentralt.checked ? '10,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxLandet && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxLandet.checked ? '11,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxBarnvanligt && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxBarnvanligt.checked ? '12,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxFrittEnskiltAvskilt && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxFrittEnskiltAvskilt.checked ? '13,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxIBebyggelse && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxIBebyggelse.checked ? '14,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxStrandtomt && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxStrandtomt.checked ? '15,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxSjoHavsnara && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxSjoHavsnara.checked ? '16,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxSjoHavsutsikt && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxSjoHavsutsikt.checked ? '17,' : '') +
 		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxSkolaForskola && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxSkolaForskola.checked ? '18,' : '') +
 		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxAllmannaKommunikationer && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxAllmannaKommunikationer.checked ? '19,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxSkogNatur && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxSkogNatur.checked ? '20,' : '') +
 		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxAffarKopcentrum && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxAffarKopcentrum.checked ? '21,' : '') +
 		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxGolfbana && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxGolfbana.checked ? '22,' : '') +
 		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxNyproduktion && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxNyproduktion.checked ? '23,' : '') +
 		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxBalkongAltanUteplats && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxBalkongAltanUteplats.checked ? '24,' : '') +
 		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxBastu && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxBastu.checked ? '25,' : '') +
 		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxGarageParkeringsplats && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxGarageParkeringsplats.checked ? '26,' : '') +
 		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxOppenSpisKakelugn && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxOppenSpisKakelugn.checked ? '27,' : '') +
 		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxPool && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxPool.checked ? '28,' : '') +
 		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxBubbelbad && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxBubbelbad.checked ? '29,' : '') +
 		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxHiss && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxHiss.checked ? '30,' : '') +
 		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxFjarrvarmeVarmepump && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxFjarrvarmeVarmepump.checked ? '31,' : '') +
 		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxHandikappvanlig && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxHandikappvanlig.checked ? '32,' : '')
	);

    destForm.submit();
}

// ---------------
// Disables the price checkboxes if the user only searches rentable object.
// This only applies to Kommersiella fastigheter
// ---------------
function setPriceDisabled(checkBoxLokalId, checkBoxFastighetId, dropdownMinPriceId, dropdownMaxPriceId) {
    var checkBoxLokal = document.getElementById(checkBoxLokalId);
    var checkBoxFastighet = document.getElementById(checkBoxFastighetId);
    var dropdownMinPrice = document.getElementById(dropdownMinPriceId);
    var dropdownMaxPrice = document.getElementById(dropdownMaxPriceId);

    if (checkBoxLokal && checkBoxFastighet && dropdownMinPrice && dropdownMaxPrice) {
        if (!checkBoxFastighet.checked && checkBoxLokal.checked) {
            dropdownMinPrice.selectedIndex = 0;
            dropdownMaxPrice.selectedIndex = 0;
            dropdownMinPrice.disabled = true;
            dropdownMaxPrice.disabled = true;
        }
        else {
            dropdownMinPrice.disabled = false;
            dropdownMaxPrice.disabled = false;
        }
    }
}

// ---------------
// Sets the dialog layout. This one shall be called before openDialog()
// ---------------
function setDialogLayout(index) {
    var hiddenField = document.getElementById(gHiddenFieActiveDialogLayoutID);
    if (hiddenField)
        hiddenField.value = index;
}


// ---------------
// Opens a dialog. The first parameter should be the dialog name.
// ---------------
function openDialog() {
    gCounter = gCounter + 1;
    var dialogName = arguments[0];
    var dialog = document.getElementById('DialogContainer');
    var hiddenField = document.getElementById(gDialogHiddenFieldId);
    if (dialog && hiddenField) {
        dialog.className = 'Dialog ' + dialogName;
        hiddenField.value = '';
        // Make a delimited string with the dialogname and parameters
        for (var i = 0; i < arguments.length; i++) {
            hiddenField.value += arguments[i];
            if (i + 1 < arguments.length) hiddenField.value += '|';
        }

        __doPostBack(gDialogHiddenFieldId, '');

        hideWindowedControls();
        showDialogBackground();
    }
}
function openLoginDialog() {
    $('#dvLogin').show('fast'); showDialogBackground();
}

function openHelp() {
    gCounter = gCounter + 1;
    var dialog = document.getElementById('DialogHelpContainer');
    var hiddenField = document.getElementById(gHelpDialogHiddenFieldId);

    if (dialog && hiddenField) {
        hiddenField.value = '';
        // Make a delimited string with the dialogname and parameters

        hiddenField.value = "clicked";
        __doPostBack(gHelpDialogHiddenFieldId, '');

        hideWindowedControls();
        showDialogBackground();
    }
}
// ---------------
// Closes the dialog-layer.
// ---------------
function closePlanDrawing() {
    gCounter = gCounter - 1;
    var dialog = document.getElementById('dvPlanDrawing');
    if (dialog) {
        dialog.style.display = 'none';

        hideDialogBackground();
        showWindowedControls();
    }
}
function closeDialog() {
    gCounter = gCounter - 1;
    var dialog = document.getElementById('DialogContainer');
    var hiddenField = document.getElementById(gDialogHiddenFieldId);
    if (dialog && hiddenField) {
        dialog.style.display = 'none';
        hiddenField.value = '';
        __doPostBack(gDialogHiddenFieldId, '');

        hideDialogBackground();
        showWindowedControls();
    }
    var helpDialog = document.getElementById('DialogHelpContainer');
    var helphiddenField = document.getElementById(gHelpDialogHiddenFieldId);
    if (helpDialog) {
        helpDialog.style.display = 'none';
        helphiddenField.value = '';
        __doPostBack(gHelpDialogHiddenFieldId, '');
    }

}
function closeHelpDialog() {
    gCounter = gCounter - 1;
    var parentDialog = document.getElementById('DialogContainer');
    var helpDialog = document.getElementById('DialogHelpContainer');
    var helphiddenField = document.getElementById(gHelpDialogHiddenFieldId);
    if (gCounter == 0) {
        hideDialogBackground();
        showWindowedControls();
    }
    if (helpDialog) {
        helpDialog.style.display = 'none';
        helphiddenField.value = '';
        __doPostBack(gHelpDialogHiddenFieldId, '');
    }
}

function closeLightBox() {
    $("body #lightbox_overlay").remove();
}

// ---------------
// Positions the dialog layer in the center of the screen.
// ---------------
function positionDialog() {
    var dialog = document.getElementById('DialogContainer');
    if (dialog) {
        var viewSize = getViewportSize();
        var scrollSize = getScrollOffset();
        dialog.style.display = 'block';

        // Center window on screen
        dialog.style.left = (scrollSize.x + (viewSize.width - dialog.clientWidth) / 2) + 'px';

        var marginTop = dialog.clientHeight > viewSize.height ? ((viewSize.height - dialog.clientHeight) / 2) : 100;
        var top = (scrollSize.y + ((viewSize.height - dialog.clientHeight) / 2) - marginTop);
        if (top > scrollSize.y)
            dialog.style.top = top + 'px';
        else
            dialog.style.top = scrollSize.y + 'px';
    }
}

function positionHelpDialog() {
    var dialog = document.getElementById('DialogHelpContainer');
    if (dialog) {
        var viewSize = getViewportSize();
        var scrollSize = getScrollOffset();
        dialog.style.display = 'block';

        // Center window on screen
        dialog.style.left = (scrollSize.x + (viewSize.width - dialog.clientWidth) / 2) + 'px';

        var marginTop = dialog.clientHeight > viewSize.height ? ((viewSize.height - dialog.clientHeight) / 2) : 100;
        var top = (scrollSize.y + ((viewSize.height - dialog.clientHeight) / 2) - marginTop);
        if (top > scrollSize.y)
            dialog.style.top = top + 'px';
        else
            dialog.style.top = scrollSize.y + 'px';
    }
}


// ---------------
// Creates and closes PlanDrawing lightbox
// ---------------

function ShowPlanDrawing(toShowObject) {
    var width = toShowObject.width();
    showDialogBackground();
    $('form').prepend(toShowObject);
    $("#dvPlanDrawing .popup").css({ "background": "none", "top": "20px", "right": "20px", "z-index": "1000000" }).show();

    var left = (($(window).width()) - (toShowObject.width())) / 2;

    toShowObject.css({ "z-index": "1000000", "left": left + "px" }).show();

    return false;
}

function ClosePlanDrawing(objectToHide) {
    //Moves the dialogs back after the menu so that they work with the normal dropdown functionality if used without overlay
    objectToHide.hide('slow');

    //Close the dialog backgroundlayer
    closePlanDrawing();
    return false;
}

// ---------------
// Creates a semi-transparent div and places it over the entire screen.
// ---------------
function showDialogBackground() {
    var bgDiv = document.getElementById('DialogBG');
    //alert(bgDiv);
    if (bgDiv) {
        bgDiv.style.height = '0px';
        var page = $(document.getElementById('page') ? document.getElementById('page') : document.getElementById('pageHemnet'));
        //var page = document.getElementById('wrapper')
        //alert(page);
        var height = $(document).height();
        // height = (height >= document.documentElement.clientHeight) ? height : document.documentElement.clientHeight;
        bgDiv.style.height = ($(document).height() + 100) + 'px';

        bgDiv.style.width = ($(document).width()) + 'px';
        bgDiv.style.display = 'block';
        //bgDiv.style.zIndex = 0;
        $("#menu_drpdivar div").css("z-index", "0");
        // IE needs a special class
        if ($.browser.msie) {
            $(".var-vill-du-bo, .more-tools span, .fb-like").css("z-index", "0");
            bgDiv.className = 'DialogBGIE6';
        }
    }
}

function pageHeight() {
    return window.innerHeight != null ?
        window.innerHeight : document.documentElement && document.documentElement.clientHeight ?
            document.documentElement.clientHeight : document.body != null ?
                document.body.clientHeight : null;
}

// ---------------
// Hides the semi-transparent div
// ---------------
function hideDialogBackground() {
    var bgDiv = document.getElementById('DialogBG');
    if (bgDiv) {
        bgDiv.style.display = 'none';
    }
}

// ---------------
// Display the specified drawing.
// ---------------
function showDrawing(menuDiv, activeIndex, imageCount) {
    // Activate menu item
    for (j = 0; j < imageCount; j++) {
        document.getElementById("Item" + j).className = "MenuArrowLeft";
    }
    document.getElementById("Item" + activeIndex).className = "MenuArrowLeft_Active";
    deactivateSiblings(menuDiv, 'MenuArrowLeft');
    menuDiv.className = 'MenuArrowLeft_Active';

    // Loop over drawing divs and display the correct one
    for (i = 0; i < imageCount; i++) {
        imageDiv = document.getElementById('DrawingDiv' + i);
        if (imageDiv) {
            imageDiv.style.display = (i == activeIndex) ? 'block' : 'none';
        }
    }
}



// ---------------
// Deactivates all the siblings to the specified menu-div.
// ---------------
function deactivateSiblings(menuDiv, className) {
    var div = menuDiv.previousSibling;
    while (div != null) {
        div.className = className;
        div = div.previousSibling;
    }

    div = menuDiv.nextSibling;
    while (div != null) {
        div.className = className;
        div = div.nextSibling;
    }
}

// ---------------
// Returns a parameter from the query string
// ---------------
function getUrlParam(strParamName) {
    var strReturn = '';
    var strHref = window.location.href;
    if (strHref.indexOf('?') > -1) {
        var strQueryString = strHref.substr(strHref.indexOf('?'));
        var aQueryString = strQueryString.split('&');
        for (var iParam = 0; iParam < aQueryString.length; iParam++) {
            if (aQueryString[iParam].indexOf(strParamName + '=') > -1) {
                var aParam = aQueryString[iParam].split('=');
                strReturn = aParam[1];
                break;
            }
        }
    }
    return strReturn;
}

// ---------------
// Open window for viewing all pictures
// ---------------
function openPictureWindow(url) {
    url += location.href.toLowerCase().indexOf('hemnet', 0) != -1 ? "&referrer=hemnet" : "&referrer=svenskfast";
    w = window.open(url, 'PictureViewWindow', 'location=no,scrollbars=yes,menubar=yes,toolbar=yes,resizable=yes,left=0,top=0');
    w.focus();
}

function openPictureWindow(url,width,height,left,top) {
    if (!height)
        height = screen.height * 0.7;
    if (!width)
        width = 'auto';
    if (!left)
        left = (screen.width - width) / 2;
    if (!top)
        top = ((screen.height - height) / 2) - 30;

    url += location.href.toLowerCase().indexOf('hemnet', 0) != -1 ? "&referrer=hemnet" : "&referrer=svenskfast";
    w = window.open(url, 'PictureViewWindow', 'location=no,scrollbars=yes,menubar=yes,toolbar=yes,resizable=yes,left=' + left + ' ,top=' + top + ' ,width=' + width + ' ,height=' + height);
    w.focus();
}
// ---------------
// Open window for viewing all pictures
// ---------------
function openFotostylingWindow(url) {
    w = window.open(url, 'FotostylingViewWindow', 'location=no,scrollbars=yes,menubar=yes,toolbar=yes,resizable=yes');
    w.focus();
}

// ---------------
// Open lightbox for viewing drawings
// ---------------
function openDrawingLightbox(url) {
    url += location.href.toLowerCase().indexOf('hemnet', 0) != -1 ? "&referrer=hemnet" : "&referrer=svenskfast";
    openObjectMapLightbox(url, null);
    $("body #lightbox_overlay div#lightbox").css({ 'background-color': 'transparent' });
    $("body #lightbox_overlay div#lightbox").height(2060);
    $("body #lightbox_overlay div#lightbox div.popup a.btn-close").css({ 'position': 'relative', 'top': '50px', 'right': '40px' });
}

// ---------------
// Open lightbox for object on map
// ---------------

function openObjectMapLightbox(url, poisearch) {
    // Add poisearch-param if specified
    if (poisearch != null && poisearch != '') {
        url += ('&poisearch=' + poisearch.replace(/\&/, '%26'));
    }
    window.scrollTo(0, 0);
    var docHeight = $(document).height();
    var windowHeight = $(window).height();
    var width = 0;
    var height = 0;
    var div = $("<div id='lightbox'></div>");
    var divOverlay = $("<div id='lightbox_overlay'></div>");
    $("body").append(divOverlay);
    $("#lightbox_overlay").height(docHeight).show();
    $("body #lightbox_overlay").append(div);
    height = (windowHeight * 0.8);
    $("body #lightbox_overlay div#lightbox").height(height);
    $("body #lightbox_overlay div#lightbox").prepend("<div class='popup' style='float: right; padding:5px;'><a onclick='closeLightBox();return false;' href='#' class='btn-close'>STÄNG</a></div>");
    $("body #lightbox_overlay div#lightbox div.popup").css({ "position": "static", "background": "none" }).show();
    $("body #lightbox_overlay div#lightbox").append("<iframe style='height:96%' scrolling='no' frameBorder='0' src='" + url + "'></iframe>");
    $("body #lightbox_overlay div#lightbox").show();
    if ($.browser.msie) {
        if ($.browser.version == "7.0") {
            $("body #lightbox_overlay").css('min-width', '1680px');
        }
    }
}

function openDefaultLightbox(url, height, width, showFlash) {
    window.scrollTo(0, 0);
    var docHeight = $(document).height();
    var windowHeight = $(window).height();
    var div = $("<div id='lightbox'></div>");
    var divOverlay = $("<div id='lightbox_overlay'></div>");
    $("body").append(divOverlay);
    $("#lightbox_overlay").height(docHeight).show();
    $("body #lightbox_overlay").append(div);
    $("body #lightbox_overlay div#lightbox").height(height + 60);
    $("body #lightbox_overlay div#lightbox").css({ "height": (height + 60) + "px", "width": width + "px", "text-align": "center" });

    if (showFlash) {
        $("body #lightbox_overlay div#lightbox").prepend("<div class='popup' style='display:block;height:20px;width:" + width + "px;background-color:#FFFFFF;padding:5px 0 0 0; position:relative;'><a onclick='closeLightBox();return false;' href='#' style='padding-right:5px;' class='btn-close'>STÄNG</a></div>");
    }
    else {
        $("body #lightbox_overlay div#lightbox").prepend("<div class='popup' style='float: left; padding:5px;'><a onclick='closeLightBox();return false;' href='#' class='btn-close'>STÄNG</a></div>");
        $("body #lightbox_overlay div#lightbox div.popup").css({ "position": "relative", "background": "none", "width": width - 10 + "px" }).show();
    }

    $("body #lightbox_overlay div#lightbox").append("<iframe style='height:96%; width:" + width + "px;' scrolling='no' frameBorder='0' src='" + url + "'></iframe>");
    $("body #lightbox_overlay div#lightbox").show();
    if ($.browser.msie) {
        if ($.browser.version == "7.0") {
            $("body #lightbox_overlay").css('min-width', '1680px');
        }
    }
}

// ---------------
// Open lightbox for viewing panorama
// ---------------
function openPanoramaLightbox(url, height, width) {
    url += location.href.toLowerCase().indexOf('hemnet', 0) != -1 ? "&referrer=hemnet" : "&referrer=svenskfast";
    openDefaultLightbox(url, height, width, true);
}

// ---------------
// Open lightbox for viewing furnishing
// ---------------
function openFurnishingLightbox(url, height, width) {
    url += location.href.toLowerCase().indexOf('hemnet', 0) != -1 ? "&referrer=hemnet" : "&referrer=svenskfast";
    openDefaultLightbox(url, height, width, true);
}

// ---------------
// Open lightbox for viewing photo styling
// ---------------
function openPhotoStylingLightbox(url, height, width) {
    url += location.href.toLowerCase().indexOf('hemnet', 0) != -1 ? "&referrer=hemnet" : "&referrer=svenskfast";
    openDefaultLightbox(url, height, width, true);
}

// ---------------
// Open lightbox for viewing image viewing
// ---------------
function openImageViewingLightbox(url, height, width) {
    openDefaultLightbox(url, height, width, true);
    $("body #lightbox_overlay div#lightbox").css({ 'background-color': 'transparent' });
    //$("body #lightbox_overlay div#lightbox div.popup a.btn-close").css({ 'position': 'relative', 'top': '25px', 'right': '5px' });
}

// ---------------
// Open window for viewing drawings
// ---------------
function openDrawingWindow(url) {
    url += location.href.toLowerCase().indexOf('hemnet', 0) != -1 ? "&referrer=hemnet" : "&referrer=svenskfast";
    w = window.open(url, 'DrawingViewWindow', 'location=no,scrollbars=yes,menubar=yes,toolbar=yes,resizable=yes');
    w.focus();
}

// ---------------
// Open window for furnishing
// ---------------
function openFurnishWindow(url) {
    w = window.open(url, 'FurnishWindow', 'width=980,height=650,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes,status=yes');
    w.focus();
}

// ---------------
// Open window for panorama
// ---------------
function openPanoramaWindow(url) {
    // Use different size on pop-up window depending on where the link goes
    if (url.substr(0, 27) == 'http://viewer.previsite.net') {
        var width = 322;
        var height = 322;
    }
    else // http://www.vrfilm.se
    {
        var width = 718;
        var height = 440;
    }

    // Center window on screen
    var left = (screen.width - width) / 2;
    var top = ((screen.height - height) / 2) - 30;

    w = window.open(url, 'PanoramaWindow', 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + 'location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes,status=yes');
    w.focus();
}

// ---------------
// Open window for panorama
// ---------------
function openSE360Window(url) {

    var width = 820;
    var height = 520;

    // Center window on screen
    var left = (screen.width - width) / 2;
    var top = ((screen.height - height) / 2) - 30;

    w = window.open(url, 'SE360', 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + 'location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes,status=yes');
    w.focus();
}

// ---------------
// Open window for panorama
// ---------------
function openSE720Window(url) {

    var width = 820;
    var height = 520;

    // Center window on screen
    var left = (screen.width - width) / 2;
    var top = ((screen.height - height) / 2) - 30;

    w = window.open(url, 'SE720', 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + 'location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes,status=yes');
    w.focus();
}

// ---------------
// Open window for vr
// ---------------
function openVRWindow(url) {
    w = window.open(url, 'VRWindow', 'width=980,height=650,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes,status=yes');
    w.focus();
}
// ---------------
// Open window for Virtuel Visning
// ---------------
function openVirtuellVisningWindow(url) {
    w = window.open(url, 'VirtuellVisningWindow', 'width=980,height=650,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes,status=yes');
    w.focus();
}
// ---------------
// Open window for Zentuvo
// ---------------
function openZentuvoWindow(url) {
    w = window.open(url, 'cHem', 'width=702,height=465,location=no,scrollbars=no,menubar=no,toolbar=no,resizable=no,status=no');
    w.focus();
}
// ---------------
// Open window for SeBostad
// ---------------
function openSeBostadWindow(url) {
    w = window.open(url, 'SeBostad', 'width=702,height=545,location=no,scrollbars=no,menubar=no,toolbar=no,resizable=no,status=no');
    w.focus();
}
// ---------------
// Open window for StreetView
// ---------------
function openStreetViewWindow(url) {
    w = window.open(url, 'StreetView', 'width=1094,height=530,location=no,scrollbars=no,menubar=no,toolbar=no,resizable=yes,status=no');
    w.focus();
}

// ---------------
// Open window for object on map
// ---------------
function openObjectMapWindow(url, poisearch, width, height, left, top) {
    // Center window on screen
    if (!left)
        left = (screen.width - width) / 2;
    if (!top)
        top = ((screen.height - height) / 2) - 30;

    // Size the window slightly smaller than the screen
    if (!width)
        width = (screen.width * 0.85);
    if (!height)
        height = (screen.height * 0.80);

    // Add poisearch-param if specified
    if (poisearch != null && poisearch != '') {
        url += ('&poisearch=' + poisearch.replace(/\&/, '%26'));
    }

    url += location.href.toLowerCase().indexOf('hemnet', 0) != -1 ? "&referrer=hemnet" : "&referrer=svenskfast";
    w = window.open(url, 'ObjectMapWindow', 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes,status=yes');
    w.focus();
}

function openObjectMapWindowCookie(url, poisearch, width, height, left, top) {
    var mapCookie = readCookie("ShowHittaMap");
    var date = new Date();
    
    if (mapCookie == null) {
        createCookie("ShowHittaMap", getUrlParam('objectid'), 7);
    }
    else if (mapCookie.indexOf(getUrlParam('objectid'), 0) > -1) {
        return;
    }
    else {
        createCookie("ShowHittaMap", mapCookie + "," + getUrlParam('objectid'), 7);
    }

    openObjectMapWindow(url, poisearch, width, height, left, top);
}

// ---------------
// First time adding favourite to cookie
// ---------------
function firstTimeCookieFavourite() {
    var mapCookie = readCookie("HasAddedToCookieFavourite");
    
    if (mapCookie == null) {
        alert('Dina favoriter hittar du i h\u00F6gerkolumnen l\u00E4ngst ner. Favoriter sparas som en tillf\u00E4llig fil p\u00E5 din dator. F\u00F6r att vara s\u00E4ker p\u00E5 att beh\u00E5lla dina favoriter kan du skapa ett konto p\u00E5 Min bostad.');
        createCookie("HasAddedToCookieFavourite", true, 365);
    }
}

// ---------------
// Open window for search-result on map
// ---------------
function openSearchResultMapWindow(url) {
    
    // Size the window slightly smaller than the screen
    var width = (screen.width * 0.85);
    var height = (screen.height * 0.80);

    // Center window on screen
    var left = (screen.width - width) / 2;
    var top = ((screen.height - height) / 2) - 30;

    w = window.open(url, 'ObjectMapWindow', 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes,status=yes');
    w.focus();
}

// ---------------
// Open window for Bokalkyl
// ---------------
function openBokalkylWindow(url) {
    w = window.open(url, 'BokalkylWindow', 'width=730,height=445,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes,status=yes');
    w.focus();
}

// ---------------
// Open window for Forsakringskalkyl
// ---------------
function openForsakringskalkylWindow(url) {
    w = window.open(url, 'ForsakringskalkylWindow', 'fullscreen=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes,top=0,left=0', "true");
    w.focus();
}
// ---------------
// Open window for Intresseanmälan
// ---------------
function openInterestRegistrationWindow(url) {
    w = window.open(url, 'InterestRegistrationWindow', 'width=685,height=575,location=no,scrollbars=no,menubar=no,toolbar=no,resizable=no,status=yes');
    w.focus();
}
// ---------------
// Open print window
// ---------------
function openPrintWindow(url) {
    w = window.open(url, 'PrintWindow', 'width=666,height=614,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes,status=yes');
    w.focus();
}

// ---------------
// Open print office window
// ---------------
function openPrintOfficeWindow(url) {
    w = window.open(url, 'PrintOfficeWindow', 'width=666,height=614,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=no,status=yes');
    w.focus();
}

// ---------------
// Opens the SL window
// ---------------
function openSLWindow(fromAddress, toAddress, travelNow) {
    var url = 'http://reseplanerare.sl.se/bin/help.exe/sn?tpl=index&REQ0JourneyStopsS0A=255&REQ0JourneyStopsZ0A=255';
    url += '&Z=' + escape(toAddress);
    url += '&S=' + escape(fromAddress);
    url += (travelNow ? '&start=yes&REQ0JourneyTime=%2b0%3a05' : '');
    w = window.open(url, 'SLWindow', 'location=yes,scrollbars=yes,menubar=yes,toolbar=yes,resizable=yes,status=yes');
    w.focus();
}

// ---------------
// Opens the SL window if enter was pressed.
// This function is attached to an onkeypress-event
// ---------------
function openSLOnEnter(evt, toAddress) {
    var keyCode = (typeof window.event == 'object') ? window.event.keyCode : evt.keyCode;

    // If enter is pressed -> open the SL window
    if (keyCode == 13) {
        openSLWindow(document.forms[0].fromAddress.value, toAddress, true);
        return false;
    }
    else {
        return true;
    }
}

// ---------------
// Display the specified picture. 
// Used to browse pictures on the object page.
// ---------------
function showPicture(index) {
    // Make sure index is valid
    if ((index < gPictureCount) && (index > -1)) {
        // Change cssclass of currentlink
        var currentLink = document.getElementById('PicturePagerLink' + gCurrentPicture);
        if (currentLink) {
            currentLink.className = 'GreyText PicturePagerLink';
        }

        // Change picture on the image tag
        var imageTag = document.getElementById(gImageTagId);
        if (imageTag) {
            imageTag.src = gPictureUrls[index];
            imageTag.alt = gPictureDescriptions[index];
            gCurrentPicture = index;
        }

        // Change cssclass of the clickedlink
        var newCurrentLink = document.getElementById('PicturePagerLink' + gCurrentPicture);
        if (newCurrentLink) {
            newCurrentLink.className = 'GreyText PicturePagerLinkActive';
        }
    }
}

function openBopriset(dropdownlanid, dropdownkommunid) {
    var droplan = document.getElementById(dropdownlanid);
    var dropkommun = document.getElementById(dropdownkommunid);

    openBoprisetWindow(droplan.options[droplan.selectedIndex].value, dropkommun.options[dropkommun.selectedIndex].value);
}
function openBoprisetWindow(lankod, kommunkod) {
    var baseUrl = 'http://www.bopriset.nu/bopris/Kartor1/';
    var winsettings = 'width=788,height=583,menubar=no,toolbar=no,status=no,resizable=no,scrollbars=no';

    if (lankod != '00' && kommunkod != '') {
        window.open(baseUrl + lankod + kommunkod + '/' + lankod + kommunkod + '.htm', 'BoprisetWindow', winsettings);
    } else {
        alert('Välj län och kommun');
    }
}
function openBokalkylWindow(url, params) {
    w = window.open(url + params, 'BokalkylWindow', 'width=1080,height=600,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes,status=yes');
    w.focus();
}

// ---------------
// Open window for Ansok om lanelofte
// ---------------
function openLanelofteWindow(url, targetSelf) {
    var outlinkStr = '/outlink/seb.se';

    if (window.location.href.indexOf('____1870')) {
        outlinkStr = '/outlink/seb.se-tjanster-bolan';
    }
    else if (window.location.href.indexOf('____15')) {
        outlinkStr = '/outlink/seb.se-kopa-bolan';
    }

    snoobi.trackPageView(window.location.href + '/outlink/seb.se');
    if (targetSelf && (targetSelf == 'true' || targetSelf == 'True')) {
        window.location.href = url;
    }
    else {
        w = window.open(url, 'LanelofteWindow', 'width=1060,height=600,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes,status=yes');
        w.focus();
    }
}

function openLanelofteWindowObjectView(url, outlink) {
    snoobi.trackPageView(window.location.href + outlink);
    w = window.open(url, 'LanelofteWindow', 'width=1060,height=600,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes,status=yes');
    w.focus();
}

function SearchTabStrip_OnMouseOver(sourceObject) {
    var sourceID = sourceObject.id;

    var left = document.getElementById(sourceID + '_Left');
    var middle = document.getElementById(sourceID + '_Middle');
    var right = document.getElementById(sourceID + '_Right');


    if (left.parentNode.className != 'SearchResultTabSelected') {
        left.className = left.className + '_Hover';
        middle.className = middle.className + '_Hover';
        right.className = right.className + '_Hover';
    }
}

function SearchTabStrip_OnMouseOut(sourceObject) {
    var sourceID = sourceObject.id;

    var left = document.getElementById(sourceID + '_Left');
    var middle = document.getElementById(sourceID + '_Middle');
    var right = document.getElementById(sourceID + '_Right');

    if (left.parentNode.className != 'SearchResultTabSelected') {
        left.className = left.className.replace('_Hover', '');
        middle.className = middle.className.replace('_Hover', '');
        right.className = right.className.replace('_Hover', '');
    }
}

function toggleFontWeight(objectId) {
    var domObject = document.getElementById(objectId);

    domObject.style.fontWeight = (domObject.style.fontWeight == 'bold') ? '' : 'bold';
}

function fbs_click() {
    u = location.href;
    t = document.title;
    window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '%26cmpe=facebook&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436'); return false;
}

function SetCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");

    return true;
}

function TogglePresentationPremium(showPresentation) {
    var infDiv = document.getElementById('information');
    var presDiv = document.getElementById('presentation');
    var presA = document.getElementById('presLink');
    var infA = document.getElementById('infoLink');
    var functionsRows = document.getElementById('functionsRows');
    //var buttons = document.getElementById('buttons');
    var brokerIntrestRow = document.getElementById('brokerIntrestRow');

    if (showPresentation) {
        infA.parentNode.parentNode.className = '';
        presA.parentNode.parentNode.className = 'selected';
        infDiv.style.display = 'none';
        presDiv.style.display = 'block';
        //functionsRows.style.width = '545px';
        //buttons.style.display = 'none';
        if (brokerIntrestRow)
            brokerIntrestRow.className = 'brokerPres';
    }
    else {
        if (brokerIntrestRow)
            brokerIntrestRow.className = 'brokerInfo';
        infA.parentNode.parentNode.className = 'selected';
        presA.parentNode.parentNode.className = '';
        infDiv.style.display = 'block';
        presDiv.style.display = 'none';
        //functionsRows.style.width = '545px';
        //buttons.style.display = 'block';
    }
}

function TogglePresentation(showPresentation) {
    //var infDiv = document.getElementById('information');
    //var presDiv = document.getElementById('presentation');
    
    //var presA = document.getElementById('presLink');
    //*** FLICKEN PÅ TOPPEN ***********
    //var infA = document.getElementById('infoLink');
    var functionsRows = document.getElementById('functionsRows');
    //var buttons = document.getElementById('buttons');
    var brokerIntrestRow = document.getElementById('brokerIntrestRow');

    if (showPresentation) {
        //infA.parentNode.parentNode.className = '';
        //presA.parentNode.parentNode.className = 'selected';
        //infDiv.style.display = 'none';
        //presDiv.style.display = 'block';
        //buttons.style.display = 'none';
    }
    else {
        //infA.parentNode.parentNode.className = 'selected';
        //presA.parentNode.parentNode.className = '';
        //infDiv.style.display = 'block';
        //presDiv.style.display = 'none';
        //buttons.style.display = 'block';
    }

    //functionsRows.style.width = '706px';
    if (brokerIntrestRow)
        brokerIntrestRow.className = 'brokerPres';
}

function SearchResultBrowserPremium(index) {
    Avantime.Templates.Units.Object.SearchResultBrowserPremium.GetImages(index, SearchResultBrowserPremium_CallBack);
}
function SearchResultBrowserPremium_CallBack(e) {
    SetCookie('SearchResultIndex', e.value.Images[0].SearchResultIndex);
    var searchBrowse = document.getElementById('searchBrowse');
    if (searchBrowse && e.value.Images.length > 0) {
        searchBrowse.innerHTML = '';
        var li = document.createElement('li');
        if (e.value.Images[0].SearchResultIndex > 0) {
            li.className = 'arrow';
            var arrow = document.createElement('img');
            arrow.setAttribute('onclick', 'SearchResultBrowserPremium(' + (e.value.Images[0].SearchResultIndex - 4 > 0 ? e.value.Images[0].SearchResultIndex - 4 : 0) + ');');
            arrow.src = gAppRoot + "images/premium/arrowBrowseSmallObjects_l.gif";
            li.appendChild(arrow);
            searchBrowse.appendChild(li);
        }

        for (var i = 0; i < e.value.Images.length; i++) {
            li = document.createElement('li');
            var a = document.createElement('a');

            a.title = e.value.Images[i].AltText;
            a.href = e.value.Images[i].ObjectUrl;
            a.innerHTML = '<img onclick="SetCookie(' + e.value.Images[i].SearchResultIndex + ')" src="' + e.value.Images[i].ImgUrl + '" title="' + e.value.Images[i].AltText + '" />'

            li.appendChild(a);
            searchBrowse.appendChild(li);
        }
        if (e.value.Images.length == 4 && e.value.Images[e.value.Images.length - 1].SearchResultIndex + 1 < e.value.SearchResultCount) {
            li = document.createElement('li');
            li.className = 'arrow';
            var arrow = document.createElement('img');
            arrow.setAttribute('onclick', 'SearchResultBrowserPremium(' + (e.value.Images[e.value.Images.length - 1].SearchResultIndex + 1) + ');');
            arrow.src = gAppRoot + "images/premium/arrowBrowseSmallObjects_r.gif";
            li.appendChild(arrow);
            searchBrowse.appendChild(li);
        }
    }
}

function SearchResultBrowser(index) {
    Avantime.Templates.Units.Object.SearchResultBrowser.GetImages(index, SearchResultBrowser_CallBack);
}
function SearchResultBrowser_CallBack(e) {
    SetCookie('SearchResultIndex', e.value.Images[0].SearchResultIndex);
    var searchBrowse = document.getElementById('searchBrowse');
    if (searchBrowse && e.value.Images.length > 0) {
        searchBrowse.innerHTML = '';
        var li = document.createElement('li');


        for (var i = 0; i < e.value.Images.length; i++) {
            li = document.createElement('li');
            var a = document.createElement('a');

            a.title = e.value.Images[i].AltText;
            a.href = e.value.Images[i].ObjectUrl;
            a.innerHTML = '<img onclick="SetCookie(' + e.value.Images[i].SearchResultIndex + ')" src="' + e.value.Images[i].ImgUrl + '" title="' + e.value.Images[i].AltText + '" />'

            li.appendChild(a);
            searchBrowse.appendChild(li);
        }

    }
}

/*

<li>
<a href="<%#Eval("ObjectUrl") %>" onclick="SetCookie('SearchResultIndex', '<%Eval("SearchResultIndex") %>');"><img src="<%#Eval("ImgUrl") %>" alt="<%#Eval("AltText") %>" /></a> 
</li>
public string ImgUrl;
public string AltText;
public string ObjectUrl;
public int SearchResultIndex;
*/

function changeSoftSearchTab(tab) {

    if ($('#tabcontent1').length != 0) {
        document.getElementById("tabcontent1").className = 'softSearchTabContentHidden';
        document.getElementById("tabLi1").className = 'searchWordsTabHidden';
        document.getElementById("tabA1").className = 'searchWordsLinkHidden';
    }
    else {
        $('#tabLi1').hide();
    }

    if ($('#tabcontent2').length != 0) {
        document.getElementById("tabcontent2").className = 'softSearchTabContentHidden';
        document.getElementById("tabLi2").className = 'searchWordsTabHidden';
        document.getElementById("tabA2").className = 'searchWordsLinkHidden';
    }
    else {
        $('#tabLi2').hide();
    }

    if ($('#tabcontent3').length != 0) {
        document.getElementById("tabcontent3").className = 'softSearchTabContentHidden';
        document.getElementById("tabLi3").className = 'searchWordsTabHidden';
        document.getElementById("tabA3").className = 'searchWordsLinkHidden';
    }
    else {
        $('#tabLi3').hide();
    }

    if ($('#tabcontent4').length != 0) {
        document.getElementById("tabcontent4").className = 'softSearchTabContentHidden';
        document.getElementById("tabLi4").className = 'searchWordsTabHidden';
        document.getElementById("tabA4").className = 'searchWordsLinkHidden';
    }
    else {
        $('#tabLi4').hide();
    }

    if ($('#tabcontent5').length != 0) {
        document.getElementById("tabcontent5").className = 'softSearchTabContentHidden';
        document.getElementById("tabLi5").className = 'searchWordsTabHidden';
        document.getElementById("tabA5").className = 'searchWordsLinkHidden';
    }
    else {
        $('#tabLi5').hide();
    }

    if ($('#tabcontent6').length != 0) {
        document.getElementById("tabcontent6").className = 'softSearchTabContentHidden';
        document.getElementById("tabLi6").className = 'searchWordsTabHidden';
        document.getElementById("tabA6").className = 'searchWordsLinkHidden';
    }
    else {
        $('#tabLi6').hide();
    }

    if ($('#tabcontent' + tab).length != 0) {
        document.getElementById("tabcontent" + tab).className = 'softSearchTabContentVisible';
        document.getElementById("tabLi" + tab).className = 'searchWordsTabVisible';
        document.getElementById("tabA" + tab).className = 'searchWordsLinkVisible';
    }
    //change padding
    var linkPadding;

    switch (tab) {
        case '1':
            linkPadding = '30px';
            break;
        case '2':
            linkPadding = '10px';
            break;
        case '3':
            linkPadding = '30px';
            break;
        case '4':
            linkPadding = '65px';
            break;
        case '5':
            linkPadding = '65px';
            break;
        default:
            linkPadding = '10px';
            break;
    }

    if ($('#situatedLink').length != 0) {
        document.getElementById('situatedLink').style.paddingTop = linkPadding;
    }

}

function HideSearchDiv() {

    $('#SearchOptionsDiv').hide();
}

function ToggleSearchDiv() {
        if ($('#SearchOptionsDiv').is(":visible")) {
            $('#SearchOptionsDiv').hide();
            return true;
        }
        $('#SearchOptionsDiv').show();
        InitScripts();
}

function FormatSlider(num, max) {
    if (isNaN(num))
        num = "0";
    else
        num = Math.ceil(num);

    var isMax = false;
    if (num >= max) {
        isMax = true;
        num = max;
    }

    num = num.toString().replace(/\$|\,/g, '');

    for (var i = 0; i < Math.ceil((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + ' ' + num.substring(num.length - (4 * i + 3));

    return isMax ? num + ' >' : num;
}
var idPath = 'ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_';
var grafAreaArea = document.getElementById('grafAreaArea');
var grafAreaRoom = document.getElementById('grafAreaRoom');
var grafAreaPrice = document.getElementById('grafAreaPrice');
var grafAreaFee = document.getElementById('grafAreaFee');
var grafAreaTomtAreal = document.getElementById('grafAreaTomtAreal');
var grafAreaAreal = document.getElementById('grafAreaAreal');
var sliderArea, sliderRoom, sliderPrice, sliderFee, sliderAreal, sliderTomtAreal;
var initScriptHasFired = false;

function InitScripts() {   

    changeSoftSearchTab('1');

    if (initScriptHasFired)
        return true;

    SetTime("Welcome", "Loaded and ready to serve");
    if (grafAreaArea) {
        sliderArea = YAHOO.widget.Slider.getHorizDualSlider("tArea", "tAreaMin", "tAreaMax", 290, 6, [(parseInt(document.getElementById(idPath + 'TextBoxAreaMin').value) / 0.862), (parseInt(document.getElementById(idPath + 'TextBoxAreaMax').value) / 0.862 + 1)]);
        sliderArea.setValues((parseInt(document.getElementById(idPath + 'TextBoxAreaMin').value) / 0.862), (parseInt(document.getElementById(idPath + 'TextBoxAreaMax').value) / 0.862 + 1));
        
        sliderArea.subscribe('change', function() {
            document.getElementById(idPath + 'TextBoxAreaMin').value = FormatSlider(sliderArea.minVal * 0.862, 250);
            document.getElementById(idPath + 'TextBoxAreaMax').value = FormatSlider(sliderArea.maxVal * 0.862 + 1, 250);
            setSliderBG('sliderBGArea', sliderArea);
            //Comment / remove Search(), if the search not shall be performed one slide
            //This is shall be done on all sliders
            //Search();
            //------^
        });
        sliderArea.subscribe('slideEnd', Search);
    }
    if (grafAreaRoom) {
        sliderRoom = YAHOO.widget.Slider.getHorizDualSlider("tRoom", "tRoomMin", "tRoomMax", 290, 28, [document.getElementById(idPath + 'TextBoxRoomMin').value / 0.0345, document.getElementById(idPath + 'TextBoxRoomMax').value / 0.0345]);
        sliderRoom.setValues(document.getElementById(idPath + 'TextBoxRoomMin').value / 0.0345, document.getElementById(idPath + 'TextBoxRoomMax').value / 0.0345);
        
        sliderRoom.subscribe('change', function() {
            document.getElementById(idPath + 'TextBoxRoomMin').value = FormatSlider(sliderRoom.minVal * 0.0345, 10);
            document.getElementById(idPath + 'TextBoxRoomMax').value = FormatSlider(sliderRoom.maxVal * 0.0345, 10);
            setSliderBG('sliderBGRoom', sliderRoom);
            //Search();
        });
        sliderRoom.subscribe('slideEnd', Search);
    }
    if (grafAreaPrice) {
        sliderPrice = YAHOO.widget.Slider.getHorizDualSlider("tPrice", "tPriceMin", "tPriceMax", 290, 5, [document.getElementById(idPath + 'TextBoxPriceMin').value / 20690, document.getElementById(idPath + 'TextBoxPriceMax').value / 20690]);
        sliderPrice.setValues(document.getElementById(idPath + 'TextBoxPriceMin').value / 20690, document.getElementById(idPath + 'TextBoxPriceMax').value / 20690);
        
        sliderPrice.subscribe('change', function() {
            document.getElementById(idPath + 'TextBoxPriceMin').value = FormatSlider(sliderPrice.minVal * 20690, 6000000);
            document.getElementById(idPath + 'TextBoxPriceMax').value = FormatSlider(sliderPrice.maxVal * 20690 + 1, 6000000);
            setSliderBG('sliderBGPrice', sliderPrice);
            //Search();
        });
        sliderPrice.subscribe('slideEnd', Search);
    }
    if (grafAreaFee) {
        sliderFee = YAHOO.widget.Slider.getHorizDualSlider("tFee", "tFeeMin", "tFeeMax", 290, 6, [document.getElementById(idPath + 'TextBoxFeeMin').value / 35, document.getElementById(idPath + 'TextBoxFeeMax').value / 35]);
        sliderFee.setValues(document.getElementById(idPath + 'TextBoxFeeMin').value / 35, document.getElementById(idPath + 'TextBoxFeeMax').value / 35);
        
        sliderFee.subscribe('change', function() {
            document.getElementById(idPath + 'TextBoxFeeMin').value = FormatSlider(sliderFee.minVal * 35, 10000);
            document.getElementById(idPath + 'TextBoxFeeMax').value = FormatSlider(sliderFee.maxVal * 35, 10000);
            setSliderBG('sliderBGFee', sliderFee);
            //Search();
        });
        sliderFee.subscribe('slideEnd', Search);
    }
    if (grafAreaTomtAreal) {
        sliderTomtAreal = YAHOO.widget.Slider.getHorizDualSlider("tTomtAreal", "tTomtArealMin", "tTomtArealMax", 290, 6, [document.getElementById(idPath + 'TextBoxTomtArealMin').value / 3.5, document.getElementById(idPath + 'TextBoxTomtArealMax').value / 3.5]);
        sliderTomtAreal.setValues(document.getElementById(idPath + 'TextBoxTomtArealMin').value / 3.5, document.getElementById(idPath + 'TextBoxTomtArealMax').value / 3.5);
        
        sliderTomtAreal.subscribe('change', function() {
            document.getElementById(idPath + 'TextBoxTomtArealMin').value = FormatSlider(sliderTomtAreal.minVal * 3.5, 1000);
            document.getElementById(idPath + 'TextBoxTomtArealMax').value = FormatSlider(sliderTomtAreal.maxVal * 3.5, 1000);
            setSliderBG('sliderBGTomtAreal', sliderTomtAreal);
            //Search();
        });
        sliderTomtAreal.subscribe('slideEnd', Search);
    }
    if (grafAreaAreal) {
        sliderAreal = YAHOO.widget.Slider.getHorizDualSlider("tAreal", "tArealMin", "tArealMax", 290, 6, [document.getElementById(idPath + 'TextBoxArealMin').value / 3.472, document.getElementById(idPath + 'TextBoxArealMax').value / 3.472]);
        sliderAreal.setValues(document.getElementById(idPath + 'TextBoxArealMin').value / 3.472, document.getElementById(idPath + 'TextBoxArealMax').value / 3.472);

        sliderAreal.subscribe('change', function() {
            document.getElementById(idPath + 'TextBoxArealMin').value = FormatSlider(sliderAreal.minVal * 3.472, 1000);
            document.getElementById(idPath + 'TextBoxArealMax').value = FormatSlider(sliderAreal.maxVal * 3.472, 1000);
            setSliderBG('sliderBGAreal', sliderAreal);
            //Search();
        });
        sliderAreal.subscribe('slideEnd', Search);
    }
    initScriptHasFired = true;
    
    return true;
}
function Search() {
    if (initScriptHasFired) {
        var start = new Date();
        var handleSuccess = function(o) {
            if (o.responseText !== undefined) {
                var pareseStart = new Date();
                var r = YAHOO.lang.JSON.parse(o.responseText);
                document.getElementById('hittCount').innerHTML = r.count;
                var pareseEnd = new Date();

                if (grafAreaArea) grafAreaArea.innerHTML = '';
                if (grafAreaRoom) grafAreaRoom.innerHTML = '';
                if (grafAreaPrice) grafAreaPrice.innerHTML = '';
                if (grafAreaFee) grafAreaFee.innerHTML = '';
                if (grafAreaTomtAreal) grafAreaTomtAreal.innerHTML = '';
                if (grafAreaAreal) grafAreaAreal.innerHTML = '';

                for (var i = 0; i < 49; i++) {
                    //Area
                    if (grafAreaArea) {
                        var gElement = document.createElement('div');
                        gElement.className = 'grafElement';
                        if (r.items[GetIndex(i, 0)] == r.items[GetMaxCountIndex(0)] && r.items[GetMaxCountIndex(0)] > 0)
                            gElement.style.height = '15px';
                        else {
                            gElement.style.height = CalcHeight(r.items[GetIndex(i, 0)], r.items[GetMaxCountIndex(0)]) + 'px';
                        }
                        gElement.style.left = (i * 6) + 'px';
                        gElement.title = "IndegElementx: " + GetIndex(i, 0);
                        grafAreaArea.appendChild(gElement);
                    }
                    //Room
                    if (grafAreaRoom) {
                        if (i < 10) {
                            gElement = document.createElement('div');
                            gElement.className = 'grafElement';
                            if (r.items[GetIndex(i, 1)] == r.items[GetMaxCountIndex(1)] && r.items[GetMaxCountIndex(1)] > 0)
                                gElement.style.height = '15px';
                            else
                                gElement.style.height = CalcHeight(r.items[GetIndex(i, 1)], r.items[GetMaxCountIndex(1)]) + 'px';
                            gElement.style.left = (i * 26) + 'px';
                            gElement.style.width = '25px';
                            gElement.title = "Index: " + GetIndex(i, 1);
                            grafAreaRoom.appendChild(gElement);
                        }
                    }
                    //Price
                    if (grafAreaPrice) {
                        gElement = document.createElement('div');
                        gElement.className = 'grafElement';
                        if (r.items[GetIndex(i, 2)] == r.items[GetMaxCountIndex(2)] && r.items[GetMaxCountIndex(2)] > 0) {
                            gElement.style.height = '15px';
                            gElement.style.bgColor = '#C2201E';
                        }
                        else
                            gElement.style.height = CalcHeight(r.items[GetIndex(i, 2)], r.items[GetMaxCountIndex(2)]) + 'px';
                        gElement.style.left = (i * 6) + 'px';
                        gElement.title = "Index: " + GetIndex(i, 2);
                        grafAreaPrice.appendChild(gElement);
                    }
                    //Fee
                    if (grafAreaFee) {
                        gElement = document.createElement('div');
                        gElement.className = 'grafElement';
                        if (r.items[GetIndex(i, 3)] == r.items[GetMaxCountIndex(3)] && r.items[GetMaxCountIndex(3)] > 0)
                            gElement.style.height = '15px';
                        else
                            gElement.style.height = CalcHeight(r.items[GetIndex(i, 3)], r.items[GetMaxCountIndex(3)]) + 'px';
                        gElement.style.left = (i * 6) + 'px';
                        gElement.title = "Index: " + GetIndex(i, 3);
                        grafAreaFee.appendChild(gElement);
                    }
                    //TomtAreal
                    if (grafAreaTomtAreal) {
                        gElement = document.createElement('div');
                        gElement.className = 'grafElement';
                        if (r.items[GetIndex(i, 4)] == r.items[GetMaxCountIndex(4)] && r.items[GetMaxCountIndex(4)] > 0)
                            gElement.style.height = '15px';
                        else
                            gElement.style.height = CalcHeight(r.items[GetIndex(i, 4)], r.items[GetMaxCountIndex(4)]) + 'px';
                        gElement.style.left = (i * 6) + 'px';
                        gElement.title = "Index: " + GetIndex(i, 4);
                        grafAreaTomtAreal.appendChild(gElement);
                    }
                    //Areal
                    if (grafAreaAreal) {
                        gElement = document.createElement('div');
                        gElement.className = 'grafElement';
                        if (r.items[GetIndex(i, 5)] == r.items[GetMaxCountIndex(5)] && r.items[GetMaxCountIndex(5)] > 0)
                            gElement.style.height = '15px';
                        else
                            gElement.style.height = CalcHeight(r.items[GetIndex(i, 5)], r.items[GetMaxCountIndex(5)]) + 'px';
                        gElement.style.left = (i * 6) + 'px';
                        grafAreaAreal.appendChild(gElement);
                    }

                }
            }

            var parse = new Date(pareseEnd - pareseStart);
            var end = new Date(new Date() - start);

            SetTime(((1000 * end.getSeconds()) + end.getMilliseconds()), ((1000 * parse.getSeconds()) + parse.getMilliseconds()));
        }


        var handleFailure = function(o) {
            if (o.responseText !== undefined) {
                SetTime("Transaction id", o.tId);
                SetTime("HTTP status", o.status);
                SetTime("Status code message", o.statusText);
            }
        }

        var callback =
            {
                success: handleSuccess,
                failure: handleFailure,
                argument: {}
            };

        try {
            var transaction = YAHOO.util.Connect.asyncRequest('GET', gAppRoot + 'pages/SearchOptions.aspx' +
                 '?feeMin=' + GetValue('TextBoxFeeMin') +
                 '&feeMax=' + GetValue('TextBoxFeeMax') +
                 '&areaMin=' + GetValue('TextBoxAreaMin') +
                 '&areaMax=' + GetValue('TextBoxAreaMax') +
                 '&priceMin=' + GetValue('TextBoxPriceMin') +
                 '&priceMax=' + GetValue('TextBoxPriceMax') +
                 '&roomMin=' + GetValue('TextBoxRoomMin') +
                 '&roomMax=' + GetValue('TextBoxRoomMax') +
                 '&ArealMin=' + GetValue('TextBoxArealMin') +
                 '&ArealMax=' + GetValue('TextBoxArealMax') +
                 '&TomtArealMin=' + GetValue('TextBoxTomtArealMin') +
                 '&Viewing=' + GetValue('DropDownListVisning') +
                 '&Added=' + GetValue('DropDownListChanged') +
                 '&TomtArealMax=' + GetValue('TextBoxTomtArealMax') +
                 '&premises=' + GetSelected('CheckBoxFilterLokal') +
                 '&onefloorhouse=' + GetSelected('CheckBoxEnplanshus') +
                 '&detachedhouse=' + GetSelected('CheckBoxFriliggandeHus') +
                 '&townhouse=' + GetSelected('CheckBoxKedjeRadhus') +
                 '&central=' + GetSelected('CheckBoxCentralt') +
                 '&countryside=' + GetSelected('CheckBoxLandet') +
                 '&childfriendly=' + GetSelected('CheckBoxBarnvanligt') +
                 '&private=' + GetSelected('CheckBoxFrittEnskiltAvskilt') +
                 '&urban=' + GetSelected('CheckBoxIBebyggelse') +
                 '&beachproperty=' + GetSelected('CheckBoxStrandtomt') +
                 '&oceannear=' + GetSelected('CheckBoxSjoHavsnara') +
                 '&oceanview=' + GetSelected('CheckBoxSjoHavsutsikt') +
                 '&school=' + GetSelected('CheckBoxSkolaForskola') +
                 '&communications=' + GetSelected('CheckBoxAllmannaKommunikationer') +
                 '&nature=' + GetSelected('CheckBoxSkogNatur') +
                 '&supermarket=' + GetSelected('CheckBoxAffarKopcentrum') +
                 '&golfcourse=' + GetSelected('CheckBoxGolfbana') +
                 '&nyProd=' + GetSelected('CheckBoxNyproduktion') +
                 '&topp=' + GetSelected('CheckBoxToppskick') +
                 '&renovering=' + GetSelected('CheckBoxRenoveringsbehov') +
                 '&old=' + GetSelected('CheckBoxAldrestil') +
                 '&funkis=' + GetSelected('CheckBoxFunkis') +
                 '&modern=' + GetSelected('CheckBoxModernStil') +
                 '&balconyTerrace=' + GetSelected('CheckBoxBalkongAltanUteplats') +
                 '&sauna=' + GetSelected('CheckBoxBastu') +
                 '&garage=' + GetSelected('CheckBoxGarageParkeringsplats') +
                 '&fireplace=' + GetSelected('CheckBoxOppenSpisKakelugn') +
                 '&jacuzzi=' + GetSelected('CheckBoxBubbelbad') +
                 '&pool=' + GetSelected('CheckBoxPool') +
                 '&elevator=' + GetSelected('CheckBoxHiss') +
                 '&districtHeating=' + GetSelected('CheckBoxFjarrvarmeVarmepump') +
                 '&handicapfriendly=' + GetSelected('CheckBoxHandikappvanlig') +
                 '&lagePlus=' + GetSelected('CheckBoxLagePlus') +
                 '&premium=' + GetSelected('CheckBoxPremium')
                 , callback, null);
        }
        catch (err) {
            SetTime("err", err.message);
        }
    }
}
function ResetSearch() {
    SetValue('TextBoxFeeMin', 0);
    if (GetValue('TextBoxFeeMax').indexOf('>') == -1)
        SetValue('TextBoxFeeMax', 10005);
    SetValue('TextBoxAreaMin', 0);
    if (GetValue('TextBoxAreaMax').indexOf('>') == -1)
        SetValue('TextBoxAreaMax', 250);
    SetValue('TextBoxPriceMin', 0);
    if (GetValue('TextBoxPriceMax').indexOf('>') == -1)
        SetValue('TextBoxPriceMax', 6000005);
    SetValue('TextBoxRoomMin', 0);
    if (GetValue('TextBoxRoomMax').indexOf('>') == -1)
        SetValue('TextBoxRoomMax', 15);
    SetValue('TextBoxArealMin', 0);
    SetValue('TextBoxTomtArealMin', 0);
    SetValue('DropDownListVisning', 0);
    SetValue('DropDownListChanged', 0);
    if (GetValue('TextBoxArealMax').indexOf('>') == -1)
        SetValue('TextBoxArealMax', 1000);
    if (GetValue('TextBoxTomtArealMax').indexOf('>') == -1)
        SetValue('TextBoxTomtArealMax', 1000);


    $('input[type="checkbox"]').each(function () {
        $(this).attr('checked', false);
    });


    SetValue('rbl_ObjectType_0', 1);








    var transaction = YAHOO.util.Connect.asyncRequest('GET', gAppRoot + 'pages/SearchOptions.aspx?ResetSearch=true', null, null);

    if (sliderArea)
        sliderArea.setValues((parseInt(document.getElementById(idPath + 'TextBoxAreaMin').value) / 0.862), (parseInt(document.getElementById(idPath + 'TextBoxAreaMax').value) / 0.862 + 1));
    if (sliderRoom)
        sliderRoom.setValues(document.getElementById(idPath + 'TextBoxRoomMin').value / 0.0345, document.getElementById(idPath + 'TextBoxRoomMax').value / 0.0345);
    if (sliderPrice)
        sliderPrice.setValues(document.getElementById(idPath + 'TextBoxPriceMin').value / 20690, document.getElementById(idPath + 'TextBoxPriceMax').value / 20690);
    if (sliderFee)
        sliderFee.setValues(document.getElementById(idPath + 'TextBoxFeeMin').value / 35, document.getElementById(idPath + 'TextBoxFeeMax').value / 35);
    if (sliderTomtAreal)
        sliderTomtAreal.setValues(document.getElementById(idPath + 'TextBoxTomtArealMin').value / 3.5, document.getElementById(idPath + 'TextBoxTomtArealMax').value / 3.5);
    if (sliderAreal)
        sliderAreal.setValues(document.getElementById(idPath + 'TextBoxArealMin').value / 3.472, document.getElementById(idPath + 'TextBoxArealMax').value / 3.472);

    return false;
}
function SetValue(id, value) {
    var el = document.getElementById(idPath + id);
    if (el) {
        if (el.tagName == 'select')
            el.selectedIndex = value;
        else if (el.type == 'checkbox' || el.type == 'radio')
            el.checked = value > 0;
        else
            el.value = value;
    }
}
function GetValue(id) {
    var el = document.getElementById(idPath + id);
    if (el) {
        if (el.tagName == 'select')
            el.options[el.selectedIndex].value
        else

            return el.value;
    }
    else
        return "0";
}
function GetSelected(id) {
    var el = document.getElementById(idPath + id);
    if (el)
        return el.checked;
    else
        return "false";
}
function setSliderBG(divID, slider) {
    var div = document.getElementById(divID);
    div.style.left = (slider.minVal + 3) + 'px';
    div.style.width = (slider.maxVal - slider.minVal - 3) + 'px';
}

function GetIndex(index, order) {
    return index + (50 * order);
}
function GetMaxCountIndex(i) {
    return 49 + (i * 50);
}

function CalcHeight(first, second) {

    if (first == 0 && second == 0) {
        return 0;
    } else {
        return Math.ceil((first / second) * 14);
    }
}

function SetTime(total, json) {
    var table = document.getElementById('result');
    if (table)
        table.innerHTML = total + ' - ' + json + '<br />' + table.innerHTML;
}

function SF() {
    document.getElementById('searchButton').focus();
}

function FeatchOffice_CallBack(e) {
    var offices = eval('(' + e + ')');

    var hiddenCode = document.getElementById(offices.HiddenOfficeCode);
    var officesDispDiv = document.getElementById('officesDispDiv');
    var radiButtonList = document.getElementById('radiButtonList');

    radiButtonList.innerHTML = '';
    hiddenCode.value = '';

    if (offices.Offices.length > 1) {
        for (var i = 0; i < offices.Offices.length; i++) {
            officesDispDiv.style.display = 'block';
            var label = document.createElement('label');
            var span = document.createElement('span');
            span.innerHTML = offices.Offices[i].Office.Name;

            var radio = document.createElement('input');
            radio.setAttribute('type', 'radio');
            radio.setAttribute('onchange', 'SetOfficeCode(this,"' + offices.HiddenOfficeCode + '");');
            radio.setAttribute('name', 'officecode');
            radio.setAttribute('value', offices.Offices[i].Office.Code);
            radio.checked = (i == 0);


            label.appendChild(radio);
            label.appendChild(span);
            radiButtonList.appendChild(label);
        }
    }
    else if (offices.Offices.length == 1) {
        officesDispDiv.style.display = 'none';
        hiddenCode.value = offices.Offices[0].Code;
    }
    else {
        officesDispDiv.style.display = 'none';
        hiddenCode.value = '';
    }
}
function SetOfficeCode(sender, hiddenOfficeCode) {
    var hiddenCode = document.getElementById(hiddenOfficeCode);

    if (sender.checked && hiddenCode) {
        hiddenCode.value = sender.value;
    }
}

try {
    $(document).ready(function() {
        if (initSearch)
            GetObjects_CallBack(initSearch);
        $('#titlebar > li').bind('click', function() {

            $(this).siblings().removeClass('active');
            $(this).addClass('active');

            $('#titlebar').attr('class', this.id);


            GetObjects(this.id);

        })
    });
} catch (e) { }


var gCurrMargin = 0;
var gWidthOffObj = 126;
function GetObjects_CallBack(data) {
    var data = eval(data);
    $('#soResult').empty();
    var list = $('<div id="objHolder"></div>').appendTo('#soResult');
    list.css('width', (data.length * gWidthOffObj));
    for (var i = 0; i < data.length; i++) {
        if (data[i]) {
            var item = $('<ul class="result"></ul>');
            $('<li><img src="http://image.svenskfast.se/imagemod2/ObjectData/' + data[i].ObjectID + '/' + data[i].ObjectID + '_____resize_cs_98_76.jpg" /></li>').appendTo(item);
            $('<li><strong>' + data[i].City + '</strong></li>').appendTo(item);
            $('<li>' + data[i].StreetAddress + '</li>').appendTo(item);


            var rk = '';
            if (data[i].Rok != '0')
                rk += data[i].Rok + ' ROK';

            if (data[i].Kvm != '0') {
                if (rk)
                    rk += ', ';

                rk += data[i].Kvm + ' KVM';
            }

            if (rk)
                $('<li>' + rk + '</li>').appendTo(item);

            if (data[i].Price != '0')
                $('<li class="price"><span>Pris: </span>' + data[i].Price + '</li>').appendTo(item);

            item.bind('click', data[i], function(e) {
                window.location = e.data.Link;
            });

            item.appendTo(list);
        }
    }
    gCurrMargin = 0;
    $('.leftButton').addClass('leftButtonInactive');
    $('.rightButton').removeClass('rightButtonInactive');
}

function MoveObjects(dir) {
    var objHolder = $('#objHolder');

    var newMargin = gCurrMargin + (dir * gWidthOffObj * 4);
    if (newMargin <= 0 && newMargin - (gWidthOffObj * 4) > -1 * objHolder.width()) {
        if (newMargin - (gWidthOffObj * 4) - gWidthOffObj == -1 * objHolder.width())
            $('.rightButton').addClass('rightButtonInactive');
        else
            $('.rightButton').removeClass('rightButtonInactive');


        if (newMargin == 0)
            $('.leftButton').addClass('leftButtonInactive');
        else
            $('.leftButton').removeClass('leftButtonInactive');


        gCurrMargin = newMargin;
        objHolder.animate({ marginLeft: gCurrMargin + 'px' }, 750);

    }
}


var curObjPickIndex = 0;
var curObjPickWidth = 596;
var runObjects = true;


function MovePickObjects(newIndex) {
    var objHolder = $('#objPickHolder');



    if (newIndex < 0)
        curObjPickIndex = objPickItems - 1;
    else if (newIndex == objPickItems)
        curObjPickIndex = 0;
    else
        curObjPickIndex = newIndex;

    if (curObjPickIndex == objPickItems - 1)
        $('.nav-bar > .right').addClass('inactive-right');
    else
        $('.nav-bar > .right').removeClass('inactive-right');


    if (curObjPickIndex == 0)
        $('.nav-bar > .left').addClass('inactive-left');
    else
        $('.nav-bar > .left').removeClass('inactive-left');





    $('.nav-bar > img').removeClass('selected').get(curObjPickIndex).className = 'selected';

    if (newIndex >= 0 && newIndex < objPickItems)
        objHolder.animate({ marginLeft: -(curObjPickIndex * curObjPickWidth) + 'px' }, 750);
    else
        objHolder.css('margin-left', -(curObjPickIndex * curObjPickWidth) + 'px');

}

function RunPickObjects() {
    runObjects = true;
    window.setInterval('if(runObjects){MovePickObjects(curObjPickIndex+1);}', 5000);
}

function LoadFlash(flashUrl, pageLinkID, flashWidth, flashHeight, clickTag) {
    var so = new SWFObject(flashUrl, "moduleflash_" + pageLinkID, flashWidth, flashHeight, "6", "#ffffff");
    so.addParam("quality", "high");
    so.addParam("wmode", "transparent");
    if (clickTag) {
        so.addVariable("clickTag", clickTag);
    }
    //    <%=PageData["FlashModuleExtraParams"]%>
    so.write("flashcontent_" + pageLinkID);
}

function ChangeLanguageAndClose(newLang) {


    var browser = $.browser;
    closeDialog();
    new google.translate.TranslateElement(
            {
                pageLanguage: 'sv',
                includedLanguages: newLang
            }
            , 'google_translate_element');

}

//Cookiehandler (used by the iPhone popup)
function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
        ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
}

function setCookieWithPath(c_name, value, path, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
        ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString()) +
        ((path) ? ";path=" + path : "");
}


function deleteCookie(name) {
    document.cookie = name +
    '=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
} 

//Köp och säljsidorna
function onEmailFocus(self) {
    self = $(self);
    if (self.val() === "Din e-postadress") {
        self.val("");
        self.css("color", "#000");
    }
}

function onEmailBlur(self) {
    self = $(self);
    if (self.val() === "") {
        self.val("Din e-postadress");
        self.css("color", "#888");
    }
}

// ExtenderMapView "Sveriges största visningshelg" START

function setAutoComplete(txtInput)
{
    $('#' + txtInput).autocomplete({
        source: function (request, response) {
            searchResults = [];
            $.getJSON(gAppRoot + 'pages/searchlocations.aspx', { search: request.term }, function (data, textStatus, jqXHR) {
                searchResults = data[1];
                if (searchResults.length > 0)
                    response(searchResults);
                else
                    response(['Inga tr\u00E4ffar ...']);
            });
        },
        select: function (event, ui) {
            updateLocation(ui.item.value);
        },
        delay: 300,
        minChars: 2
    });
}

function updateSelectedType(value) {
    selectedType = value
    callExtendedMap();
}

function updateLocation(value) {
    if (value.indexOf('Inga träffar') < 0) {
        selectedLocation = value;
        //selectedLocation = value.toLowerCase().replace('å', '&aring;').replace('ä', '&auml;').replace('ö', '&ouml;');
        $('#txtMapSearch').val(value);
        callExtendedMap();
    }
}

// This is used to cause an async postback using ICallbackEventHandler
function callExtendedMap() {
    UpdateSession(encodeURI(selectedLocation) + ';' + selectedType);
}

function UpdateIframe(rValue) {
    document.getElementById("hittaIframe").src = rValue;
}

function selectLocation() {
    var selectedItem = $('#ui-active-menuitem');
    
    if (selectedItem.length > 0) {
        // Select the selected one    
        updateLocation(selectedItem.html());
    }
    else if ($('.ui-autocomplete').children().length > 0) {
        // Select the first one
        updateLocation($('.ui-autocomplete').children().first().find('a').html());
    }
}

function showPopup(sender, url, locationName, popupStyle, count) {
    // Variable to keep the popup
    var objPopup = $('.ExtendedMapModuleContainer #ExtendedMapPopup');
    
    // Make sure no other MapPoint is selected
    $('.ExtendedMapModuleContainer .MapPoint').removeClass('Selected');
    $(sender).addClass('Selected');

    // Remove other classes
    $(objPopup).attr('class', '');
    $(objPopup).addClass(popupStyle);
    $('.ExtendedMapModuleContainer #ExtendedMapPopup #Location').html(locationName);
    $('.ExtendedMapModuleContainer #ExtendedMapPopup #Count').html(count);

    $('.ExtendedMapModuleContainer #ExtendedMapPopup .RightArrow').attr('href', url);
    $('.ExtendedMapModuleContainer #ExtendedMapPopup #LocationAnchor').attr('href', url);


    // Display the popup over the pin
    var pos = $(sender).position();
    var xAdjust = 0;
    var yAdjust = 0;

    // We need to adjust the position depending on the style
    if (popupStyle == 'LeftPopup') {
        xAdjust = -160
        yAdjust = - 30
    }
    else if (popupStyle == 'AbovePopup') {
        xAdjust = -110
        yAdjust = -120
    }
    else if (popupStyle == 'BelowPopup') {
        xAdjust = - 120
        yAdjust = + 20
    }
    $(objPopup).css({ 'left': (pos.left + xAdjust) + 'px', 'top': (pos.top + yAdjust) + 'px' });
    $(objPopup).fadeIn('fast');
}

function setIframeSize(event) {

    // Get the width of the browser
    var documentWidth = $(window).width();
    if (documentWidth < 1100) {
        // The resolution is too low. We hide the elements to avoid a complete mess
        $('#IframeContainer #LeftBorder').hide();
        $('#IframeContainer #RightBorder').hide();
        $('#IframeContainer #LeftHorizontal').hide();
        $('#IframeContainer #RightHorizontal').hide();
        $('#IframeContainer #MiddleBorder').hide();
        $('#hittaIframe').width(915 + 'px');
        $('#hittaIframe').css('left', 'auto');
        $('#ExpanderDiv').height($('#hittaIframe').height());
        return;
    }
    else {
        // Resolution is ok. Show the elements
        $('#IframeContainer #LeftBorder').show();
        $('#IframeContainer #RightBorder').show();
        $('#IframeContainer #LeftHorizontal').show();
        $('#IframeContainer #RightHorizontal').show();
        $('#IframeContainer #MiddleBorder').show();
    }
    
    if(documentWidth > 2000){
        documentWidth = 2000;
    }

    var leftConstant = documentWidth/10;
    var baseDiff = $('#page').offset().left;

    $('#hittaIframe').width(documentWidth - leftConstant);
    var widthDiff = ($('#hittaIframe').width() - $('#page').width())/2;
    $('#hittaIframe').css('left', '-' + widthDiff - 10 + 'px');

    var left = $('#hittaIframe').position().left - 20;
    var right = left + $('#hittaIframe').width() + 30;
    $('#IframeContainer #LeftBorder').css('left', left + 'px');
    $('#IframeContainer #RightBorder').css('left', right + 'px');

    $('#IframeContainer #LeftHorizontal').css('left', left + 8 + 'px');
    $('#IframeContainer #LeftHorizontal').css('width',  -1* (left + 29) + 'px');

    $('#IframeContainer #RightHorizontal').css('left', $('#page').width() + 3 + 'px');
    $('#IframeContainer #RightHorizontal').css('width', $('#IframeContainer #LeftHorizontal').css('width'));

    $('#IframeContainer #MiddleBorder').css('left', '-28px');
        
    // We use this to make sure that elements below the iframe is positioned at the correct height
    $('#ExpanderDiv').height($('#hittaIframe').height());
}

function ShowBigExhibitionPopup() {

    // Se if the popup has been shown already
    var shown = getCookie('BigExhibitionPopup');
    if (shown != 'IsShown') {
        var popup = $('.BigExhibitionInfo');
        (popup).show();
        $(popup).css("top", $(window).height() / 2 - $('.BigExhibitionInfo').height() / 2 + "px");
        $(popup).css("left", (($('#page').width() - $(popup).outerWidth()) / 2) + $('#page').scrollLeft() + "px");
        $(popup).click(function (event) {
            $('.BigExhibitionInfo').fadeOut('fast');
            setCookie('BigExhibitionPopup', 'IsShown', 365);
        });
    }


}

// ExtenderMapView "Sveriges största visningshelg" END

function getBaseUrl() {
    return location.href.substring(0, location.href.lastIndexOf('/'));
}


// SEBInterestModules - Shows/hides div with example text 
function ShowSEBInterestExampleDiv() {
    $('.SEBModuleExample').mouseover(function () {       
        $('.SEBInterestExample').css({
            width: $(this).parent().outerWidth() - $(this).css('paddingLeft').replace('px', '') - $(this).css('paddingRight').replace('px', '') - 40 
        });
        $('.SEBInterestExample').show();
    });

    $('.SEBInterestExample').mouseleave(function () {
        $(this).hide();
    });
}

