/// <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';
        }
    }
}

// ---------------
// 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;
    }
    // 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.newb.value = (sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_rbl_ObjectType_1 &&
						   sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_rbl_ObjectType_1.checked)
						     ? '1' : '0';

    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_CheckBoxRadhus && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxRadhus.checked ? '0,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_rbl_ObjectType_2 && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_rbl_ObjectType_2.checked ? '1,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_rbl_ObjectType_3 && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_rbl_ObjectType_3.checked ? '2,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_rbl_ObjectType_4 && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_rbl_ObjectType_4.checked ? '3,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_rbl_ObjectType_5 && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_rbl_ObjectType_5.checked ? '4,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_rbl_ObjectType_6 && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_rbl_ObjectType_6.checked ? '5,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxSjonara && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxSjonara.checked ? '6,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxCentralt && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxCentralt.checked ? '7,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxLandet && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxLandet.checked ? '8,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxBastu && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxBastu.checked ? '9,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxBubbelbad && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxBubbelbad.checked ? '10,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxPool && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxPool.checked ? '11,' : '') +
 		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxSpis && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxSpis.checked ? '12,' : '') +
 		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxHiss && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxHiss.checked ? '13,' : '') +
		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxGarage && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxGarage.checked ? '14,' : '') +
 		(sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxBalkong && sourceForm.ctl00_ContentPlaceHolderMain_ContentPlaceHolderRightArea_SearchResultTop_SearchOptions_CheckBoxBalkong.checked ? '15,' : '')

	);

    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);

    try {
        if (dialogName == "TipFriend") {
            s.prop9 = "Tipsa van";
        }
        if (dialogName == "ObjectIntrestRegistration") {
            s.prop9 = "Anmal intresse";
        }
    } catch (err) { }
    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 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 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, '');
    }
}

// ---------------
// 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 a semi-transparent div and places it over the entire screen.
// ---------------
function showDialogBackground() {
    var bgDiv = document.getElementById('DialogBG');
    if (bgDiv) {
        bgDiv.style.height = '0px';
        var page = $(document.getElementById('page') ? document.getElementById('page') : document.getElementById('pageHemnet'));
        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';

        // IE needs a special class
        if ((BrowserDetect.browser == 'Explorer') ) {
            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;
}

// ---------------
// Sends logging events to stats service
// ---------------
function logClick(actionName) {
    var statsSitePrefix = (window.location.href.indexOf('ObjectHemnet.aspx') == -1) ? 'Svenskfast' : 'Hemnet';
    var objectId = getUrlParam('objectid');
    var stringToLog = statsSitePrefix + '|' + actionName + '|' + objectId;
}

// ---------------
// Open window for viewing all pictures
// ---------------
function openPictureWindow(url) {
    logClick('objektlank_visa_bilder');
    w = window.open(url, 'PictureViewWindow', 'location=no,scrollbars=yes,menubar=yes,toolbar=yes,resizable=yes');
    w.focus();
}
// ---------------
// Open window for viewing all pictures
// ---------------
function openFotostylingWindow(url) {
    logClick('objektlank_fotostyling');
    w = window.open(url, 'FotostylingViewWindow', 'location=no,scrollbars=yes,menubar=yes,toolbar=yes,resizable=yes');
    w.focus();
}

// ---------------
// Open window for viewing drawings
// ---------------
function openDrawingWindow(url) {
    logClick('objektlank_planritning');
    w = window.open(url, 'DrawingViewWindow', 'location=no,scrollbars=yes,menubar=yes,toolbar=yes,resizable=yes');
    w.focus();
}

// ---------------
// Open window for furnishing
// ---------------
function openFurnishWindow(url) {
    logClick('objektlank_provbo');
    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) {
    logClick('objektlank_panorama');

    // 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) {
    logClick('objektlank_se360');
   
    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 vr
// ---------------
function openVRWindow(url) {
    logClick('objektlank_vr');
    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) {
    logClick('objektlank_VirtuellVisning');
    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) {
    logClick('objektlank_Zentuvo');
    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 StreetView
// ---------------
function openStreetViewWindow(url) {
    logClick('objektlank_StreetView');
    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) {
    if (poisearch == null) {
        logClick('objektlank_visa_karta');
    }
    else {
        logClick('objektlank_visa_karta_poi_' + poisearch);
    }

    // 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;

    // Add poisearch-param if specified
    if (poisearch != null && poisearch != '') {
        url += ('&poisearch=' + poisearch.replace(/\&/, '%26'));
    }

    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 search-result on map
// ---------------
function openSearchResultMapWindow(url) {
    if (url != null) {
        logClick('soklank_visa_resultat_pa_karta');
    }

    // 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) {
    logClick('objektlank_bokalkyl');
    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 Ansok om lanelofte
// ---------------
function openLanelofteWindow(url) {
    logClick('objektlank_lanelofte');
    w = window.open(url, 'LanelofteWindow', 'width=760,height=600,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes,status=yes');
    w.focus();
}

// ---------------
// Open window for Forsakringskalkyl
// ---------------
function openForsakringskalkylWindow(url) {
    s.prop9 = "Forsakringskalkyl";
    logClick('objektlank_forsakringskalkyl');
    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) {
    logClick('objektlank_anmal_intresse');
    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) {
    s.prop9 = "Skriv ut";
    logClick('objektlank_skrivut');
    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) {
    s.prop9 = "Prisstatistik";
    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) {
    s.prop9 = "Bolanekalkyl";
    logClick('objektlank_bokalkyl');
    w = window.open(url + params, 'BokalkylWindow', 'width=1080,height=600,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes,status=yes');
    w.focus();
}

function openLanelofteWindow(url) {
    s.prop9 = "Lanelofte";
    logClick('objektlank_lanelofte');
    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() {
    SetSiteCatalystData('hiddeneVar2', 'facebook');
    
    u = location.href;
    t = document.title;
    window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436'); return false;
}
// --- SITECATALYST END ----
function SetSiteCatalystData(sitecatalysthiddenid, value) {
    ClearSiteCataLystProperties();
    
    document.getElementById(sitecatalysthiddenid).value = value;
    SendCatalystData();
    var SCDebugger = document.getElementById('SiteCatalystDebugger');
    if (SCDebugger) {
        SCDebugger.innerHTML = GetSiteCatalystDebuggerHTML();
    }
}
function OpenDebugger() {
    document.getElementById('SCOpener').style.display = 'none';
    document.getElementById('SiteCatalystDebuggerContainer').style.display = 'block';

}
function CloseDebugger() {
    document.getElementById('SCOpener').style.display = 'block';
    document.getElementById('SiteCatalystDebuggerContainer').style.display = 'none';

}
function getVal() {
    if (document.getElementById('hiddenCampaignCode').value != "")
        return document.getElementById('hiddenCampaignCode').value;
    else if (s.getValOnce(s.getQueryParam("WT.mc_id")) != "")
        return s.getValOnce(s.getQueryParam("WT.mc_id"));
    else if (s.getValOnce(s.getQueryParam("cmpe")) != "")
        return s.getValOnce(s.getQueryParam("cmpe"))
    else
        return "";
}
function querySt(qString) {
    SearchSub = window.location.search.substring(1);
    QueryStrings = SearchSub.split("&");
    for (i = 0; i < QueryStrings.length; i++) {
        var Query = QueryStrings[i].split("=");
        if (Query[0] == qString) {
            return Query[1];
        }
    }
    return "";
}
function GetSiteCatalystDebuggerHTML() {
    var HTMLCode = "<table>";
    if (querySt("aspxerrorpath") != "") {
        HTMLCode += "<tr>" +
						"<td>PageName:</td>" +
						"<td>" + document.getElementById('hidden404Path').value + "</td>" +
					"</tr>" +
					"<tr>" +
						"<td>PageType:</td>" +
						"<td>errorPage</td>" +
					"</tr>";
    } else {
        HTMLCode += "<tr>" +
						"<td>PageName:</td>" +
						"<td>" + document.getElementById('hiddenPageName').value + "</td>" +
					"</tr>" +
					"<tr>" +
						"<td>Server:</td>" +
						"<td>" + document.getElementById('hiddenServer').value + "</td>" +
					"</tr>";
    }
    if (document.getElementById('hiddenEvent').value != '') {
        HTMLCode += "<tr>" +
						"<td>Events:</td>" +
						"<td>" + document.getElementById('hiddenEvent').value + "</td>" +
					"</tr>";
    }
    if (document.getElementById('hiddeneVar1').value != '') {
        HTMLCode += "<tr>" +
		                "<td>eVar1:</td>" +
		                "<td>" + document.getElementById('hiddeneVar1').value + "</td>" +
	                "</tr>";
    }
    if (document.getElementById('hiddeneVar2').value != '') {
        HTMLCode += "<tr>" +
		                "<td>eVar2:</td>" +
		                "<td>" + document.getElementById('hiddeneVar2').value + "</td>" +
	                "</tr>";
    }
    if (document.getElementById('hiddeneVar3').value != '') {
        HTMLCode += "<tr>" +
		                "<td>eVar3:</td>" +
		                "<td>" + document.getElementById('hiddeneVar3').value + "</td>" +
	                "</tr>";
    }
    if (document.getElementById('hiddeneVar4').value != '') {
        HTMLCode += "<tr>" +
		                "<td>eVar4:</td>" +
		                "<td>" + document.getElementById('hiddeneVar4').value + "</td>" +
	                "</tr>";
    }
    if (document.getElementById('hiddeneVar5').value != '') {
        HTMLCode += "<tr>" +
                        "<td>eVar5:</td>" +
                        "<td>" + document.getElementById('hiddeneVar5').value + "</td>" +
                    "</tr>";
    }
    if (document.getElementById('hiddenChannel').value != '') {
        HTMLCode += "<tr>" +
						"<td>Channel:</td>" +
						"<td>" + document.getElementById('hiddenChannel').value + "</td>" +
					"</tr>";
    }
    if (document.getElementById('hiddenHier2').value != '') {
        HTMLCode += "<tr>" +
				        "<td>Hier2:</td>" +
				        "<td>" + document.getElementById('hiddenHier2').value + "</td>" +
			        "</tr>";
    }
    if (document.getElementById('hiddenCampaignCode').value != '') {
        HTMLCode += "<tr>" +
					    "<td>Campaign:</td>" +
					    "<td>" + document.getElementById('hiddenCampaignCode').value + "</td>" +
				    "</tr>";
    }
    if (document.getElementById('hiddenProp1').value != '') {
        HTMLCode += "<tr>" +
					    "<td>Prop1:</td>" +
					    "<td>" + document.getElementById('hiddenProp1').value + "</td>" +
				    "</tr>";
    }
    if (document.getElementById('hiddenProp2').value != '') {
        HTMLCode += "<tr>" +
						"<td>Prop2:</td>" +
						"<td>" + document.getElementById('hiddenProp2').value + "</td>" +
					"</tr>";
    }
    if (document.getElementById('hiddenProp3').value != '') {
        HTMLCode += "<tr>" +
					    "<td>Prop3:</td>" +
					    "<td>" + document.getElementById('hiddenProp3').value + "</td>" +
				    "</tr>";
    }
    if (document.getElementById('hiddenProp4').value != '') {
        HTMLCode += "<tr>" +
					    "<td>Prop4:</td>" +
					    "<td>" + document.getElementById('hiddenProp4').value + "</td>" +
				    "</tr>";
    }
    if (document.getElementById('hiddenProp5').value != '') {
        HTMLCode += "<tr>" +
						"<td>Prop5:</td>" +
						"<td>" + document.getElementById('hiddenProp5').value + "</td>" +
					"</tr>";
    }
    if (document.getElementById('hiddenProp6').value != '') {
        HTMLCode += "<tr>" +
						"<td>Prop6:</td>" +
						"<td>" + document.getElementById('hiddenProp6').value + "</td>" +
					"</tr>";
    }
    if (document.getElementById('hiddenProp7').value != '') {
        HTMLCode += "<tr>" +
					    "<td>Prop7:</td>" +
					    "<td>" + document.getElementById('hiddenProp7').value + "</td>" +
				    "</tr>";
    }
    if (document.getElementById('hiddenProp8').value != '') {
        HTMLCode += "<tr>" +
					    "<td>Prop8:</td>" +
					    "<td>" + document.getElementById('hiddenProp8').value + "</td>" +
				    "</tr>";
    }
    if (document.getElementById('hiddenProp9').value != '') {
        HTMLCode += "<tr>" +
				        "<td>Prop9:</td>" +
				        "<td>" + document.getElementById('hiddenProp9').value + "</td>" +
			        "</tr>";
    }
    if (document.getElementById('hiddenProp10').value != '') {
        HTMLCode += "<tr>" +
						"<td>Prop10:</td>" +
						"<td>" + document.getElementById('hiddenProp10').value + "</td>" +
					"</tr>";
    }
    if (document.getElementById('hiddenProp11').value != '') {
        HTMLCode += "<tr>" +
					    "<td>Prop11:</td>" +
					    "<td>" + document.getElementById('hiddenProp11').value + "</td>" +
				    "</tr>";
    }
    if (document.getElementById('hiddenProp12').value != '') {
        HTMLCode += "<tr>" +
						"<td>Prop12:</td>" +
						"<td>" + document.getElementById('hiddenProp12').value + "</td>" +
					"</tr>";
    }
    if (document.getElementById('hiddenProp13').value != '') {
        HTMLCode += "<tr>" +
						"<td>Prop13:</td>" +
						"<td>" + document.getElementById('hiddenProp13').value + "</td>" +
					"</tr>";
    }
    if (document.getElementById('hiddenProp14').value != '') {
        HTMLCode += "<tr>" +
						"<td>Prop14:</td>" +
						"<td>" + document.getElementById('hiddenProp14').value + "</td>" +
					"</tr>";
    }
    HTMLCode += "</table>";
    return HTMLCode;

}
function ClearSiteCataLystProperties() {
        document.getElementById('hiddenPageName').value = '';
        document.getElementById('hiddenServer').value = '';
        document.getElementById('hiddenChannel').value = '';
        document.getElementById('hiddenHier2').value = '';
        document.getElementById('hiddenProp1').value = '';
        document.getElementById('hiddenProp2').value = '';
        document.getElementById('hiddenProp3').value = '';
        document.getElementById('hiddenProp4').value = '';
        document.getElementById('hiddenProp5').value = '';
        document.getElementById('hiddenProp6').value = '';
        document.getElementById('hiddenProp7').value = '';
        document.getElementById('hiddenProp8').value = '';
        document.getElementById('hiddenProp9').value = '';
        document.getElementById('hiddenProp10').value = '';
        document.getElementById('hiddenProp11').value = '';
        document.getElementById('hiddenProp12').value = '';
        document.getElementById('hiddenProp13').value = '';
        document.getElementById('hiddenProp14').value = '';
        document.getElementById('hiddenCampaignCode').value = '';
        document.getElementById('hiddenEvent').value = '';
        document.getElementById('hiddeneVar1').value = '';
        document.getElementById('hiddeneVar2').value = '';
        document.getElementById('hiddeneVar3').value = '';
        document.getElementById('hiddeneVar4').value = '';
        document.getElementById('hiddeneVar5').value = '';
}
// --- SITECATALYST END ----
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 LinkTrackEvents(obj, e, pageName) {
    var s = s_gi('rsid');
    s.linkTrackEvents = e;
    s.tl(obj, 'o', pageName);
    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 = '706px';
        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 = '540px';
        buttons.style.display = 'block';
    }
}

function TogglePresentation(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 = '706px';
        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 = '620px';
        buttons.style.display = 'block';
    }
}

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 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() {
    document.getElementById('SearchOptionsDiv').style.visibility = 'visible';
    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.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);
        sliderArea.setValues((parseInt(document.getElementById(idPath + 'TextBoxAreaMin').value) / 0.862), (parseInt(document.getElementById(idPath + 'TextBoxAreaMax').value) / 0.862 + 1));
    }
    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.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);
        sliderRoom.setValues(document.getElementById(idPath + 'TextBoxRoomMin').value / 0.0345, document.getElementById(idPath + 'TextBoxRoomMax').value / 0.0345);
    }
    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.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);
        sliderPrice.setValues(document.getElementById(idPath + 'TextBoxPriceMin').value / 20690, document.getElementById(idPath + 'TextBoxPriceMax').value / 20690);
    }
    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.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);
        sliderFee.setValues(document.getElementById(idPath + 'TextBoxFeeMin').value / 35, document.getElementById(idPath + 'TextBoxFeeMax').value / 35);
    }
    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.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);
        sliderTomtAreal.setValues(document.getElementById(idPath + 'TextBoxTomtArealMin').value / 3.5, document.getElementById(idPath + 'TextBoxTomtArealMax').value / 3.5);
    }
    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.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);
        sliderAreal.setValues(document.getElementById(idPath + 'TextBoxArealMin').value / 3.472, document.getElementById(idPath + 'TextBoxArealMax').value / 3.472);
    }
    initScriptHasFired = true;
    Search();
    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') +
                 '&Sjonara=' + GetSelected('CheckBoxSjonara') +
                 '&Centralt=' + GetSelected('CheckBoxCentralt') +
                 '&Landet=' + GetSelected('CheckBoxLandet') +
                 '&Bastu=' + GetSelected('CheckBoxBastu') +
                 '&Bubbelbad=' + GetSelected('CheckBoxBubbelbad') +
                 '&Pool=' + GetSelected('CheckBoxPool') +
                 '&Spis=' + GetSelected('CheckBoxSpis') +
                 '&Hiss=' + GetSelected('CheckBoxHiss') +
                 '&Garage=' + GetSelected('CheckBoxGarage') +
                 '&Balkong=' + GetSelected('CheckBoxBalkong') +
                 '&IsLagePlus=' + GetSelected('CheckBoxLagePlus') +
                 '&nyProd=' + GetSelected('rbl_ObjectType_1') +
                 '&old=' + GetSelected('rbl_ObjectType_2') +
                 '&modern=' + GetSelected('rbl_ObjectType_3') +
                 '&funkis=' + GetSelected('rbl_ObjectType_4') +
                 '&renovering=' + GetSelected('rbl_ObjectType_5') +
                 '&topp=' + GetSelected('rbl_ObjectType_6')
                 , 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);
    SetValue('CheckBoxSjonara', 0);
    SetValue('CheckBoxCentralt', 0);
    SetValue('CheckBoxLandet', 0);
    SetValue('CheckBoxBastu', 0);
    SetValue('CheckBoxBubbelbad', 0);
    SetValue('CheckBoxPool', 0);
    SetValue('CheckBoxSpis', 0);
    SetValue('CheckBoxHiss', 0);
    SetValue('CheckBoxGarage', 0);
    SetValue('CheckBoxBalkong', 0);
    SetValue('CheckBoxLagePlus', 0);
    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);
}
