﻿function mp_onload() {
    if (window.body_onload != null)
        window.body_onload();
}
function signUpMessagePassiv(url, companyName) {
    var con = confirm("Du er medlem af "+companyName+", men ikke som aktiv. \n\n Du kan blive det ved at redigere dine medlemsskaber. Tryk ok for at gøre dette nu");
    if (con) {
        location.href = url;
    }
}


function signUpMessage(logInUrl, companyName) {


    var con = confirm("Du er ikke logget ind. Log ind via boksen til venstre. \n\n Hvis du ikke er medlem af " + companyName + " kan du oprette dig ved at klikke ok");
    if (con) {
        location.href = logInUrl;
     }

 }

function signUpMessageOtherCompany(url, companyName){

    var con = confirm("Du er ikke medlem af dette " + companyName + ". \n\n Du kan blive det ved at redigere dine medlemsskaber. Tryk ok for at gøre dette nu");
    if (con) {
        location.href = url;
     }

}

//LOADING INFO
function showLoadingInfo() {
    setTimeout('showLoadingInfoDelayed()', 3000);
}

function showLoadingInfoDelayed() {
    $('#waitingForResultBox').dialog('open');
 }

function getAdditionalApartmentData(companyID, departmentID, apartmentID, xsltName, divID) {
    var url2 = "/Public/AdditionalApartmentInfo.aspx?companyID=" + companyID + "&departmentID=" + departmentID + "&apartmentID=" + apartmentID + "&departmentXSLT=" + xsltName;
        var result ="no";
        $.ajax({
            type: "GET",
            url: url2,
            dataType: "text",
            success: function(data, msg) {
                $('#' + divID).html(data);
                $('#' + divID).dialog('open');
            },
            error: function() {
                $('#' + divID).html("");
            }
        });
    }


//Marker array to only create needed markers once
var markerArray = [];
var markerBase = "http://www.bosj.dk/files/system/nemlejesystem/images/";

//Provide markers to points on map
function getMarker(key) {

    if (typeof markerArray[key] == 'undefined') {
        var new_icon = new GIcon();
        switch (key) {

            case "1":
                new_icon.image = markerBase + "marker_1.gif";
                break;
            case "12":
                new_icon.image = markerBase + "marker_12.gif";
                break;
            case "15":
                new_icon.image = markerBase + "marker_15.gif";
                break;
            case "16":
                new_icon.image = markerBase + "marker_16.gif";
                break;
            case "20":
                new_icon.image = markerBase + "marker_20.gif";
                break;

            default:
                new_icon.image = markerBase + "marker_default.gif";
                break;
        }

        new_icon.size = new GSize(23, 15);
        new_icon.iconAnchor = new GPoint(8, 9);
        new_icon.infoWindowAnchor = new GPoint(7, 7);

        var opt;
        opt = {};

        opt.icon = new_icon;
        opt.draggable = false;
        opt.clickable = true;
        opt.dragCrossMove = true;
        markerArray[key] = opt;

    }

    return markerArray[key];

}

// Load blueprint file into JQuery dialog
function loadBlueprint(completePath) {
    $('#blueprint').attr("src", completePath);
    $("#dialog").dialog("open");
}

// Load values into dialog form
function respond(Afd, Sel, Lejemaal, Datotilb, Lejer) {
    $('#Afd').val(Afd);
    $('#Sel').val(Sel);
    $('#Lejemaal').val(Lejemaal);
    $('#Datotilb').val(Datotilb);
    $('#Lejer').val(Lejer);

    $("#responddialog").dialog("open");
}
function respondAccept(Afd, Sel, Lejemaal, Datotilb, Lejer) {
    $('#Afd').val(Afd);
    $('#Sel').val(Sel);
    $('#Lejemaal').val(Lejemaal);
    $('#Datotilb').val(Datotilb);
    $('#Lejer').val(Lejer);

    $("#responddialogAccept").dialog("open");
}
function respondDecline(Afd, Sel, Lejemaal, Datotilb, Lejer) {
    $('#Afd').val(Afd);
    $('#Sel').val(Sel);
    $('#Lejemaal').val(Lejemaal);
    $('#Datotilb').val(Datotilb);
    $('#Lejer').val(Lejer);

    $("#responddialogDecline").dialog("open");
}

function confirmOffer(Afd, Sel, Lejemaal, Internetnr, Datotilb, Lejer, ID) {
    if (confirm("Ved denne handling accepterer du tilbuddet! Er du helt sikker?")) {
        location.href = "/Default.aspx?ID=" + ID + "&action=AcceptMemberOffer&Afd=" + Afd + "&Sel=" + Sel + "&Lejemaal=" + Lejemaal + "&Internetnr=" + Internetnr + "&Datotilb=" + Datotilb + "&Lejer=" + Lejer;
    } else {
        return false;
    }
}

function rejectOffer(Afd, Sel, Lejemaal, Internetnr, Datotilb, Lejer, ID) {
    if (confirm("Ved denne handling afviser du tilbuddet! Er du helt sikker?")) {
        location.href = "/Default.aspx?ID=" + ID + "&action=RejectMemberOffer&Afd=" + Afd + "&Sel=" + Sel + "&Lejemaal=" + Lejemaal + "&Internetnr=" + Internetnr + "&Datotilb=" + Datotilb + "&Lejer=" + Lejer;
    } else {
        return false;
    }
}

// Google Maps variables
var map;
var geocoder;
var bounds;
var countPointOnMap = 0;
var svc;

// Initialize Google Maps
function initialize() {
    if (GBrowserIsCompatible()) {
        // New GStreetView functionality:
        svc = new GStreetviewClient(); 
        //var myPano = new GStreetviewPanorama(document.getElementById("GStreetView"));
        //        GEvent.addListener(myPano, "error", handleNoFlash);  

        map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(0, 0), 1);
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        geocoder = new GClientGeocoder();
        bounds = new GLatLngBounds();

        // New GStreetView functionality:
        //svOverlay = new GStreetviewOverlay();
        //map.addOverlay(svOverlay);
//        GEvent.addListener(map, "click", function(overlay, latlng) {
//            myPano.setLocationAndPOV(latlng);
//        });

    }
}

// Create marker on Google Maps
function createMarker(point, html, opt) {
    var marker = new GMarker(point, opt);
    marker.y = 0;
    marker.p = 5;
    marker.z = 0;
    var gStretHTML = "";
    GEvent.addListener(marker, "click", function() {
        svc.getNearestPanorama(point, function(reply) {

            if (reply.code == 200) {
                if (reply.Location) {

//                    gStretHTML = "<div class=\"header\"><b>" + reply.Location.description + "</b> - " + name + "</div>" + "<div class=\"bubble\"><embed src=\"http://maps.google.com/mapfiles/cb/googlepano.040.swf\" quality=\"high\" bgcolor=\"#EFEFEF\" style=\"width: 100%; height: 270px;\" wmode=\"opaque\" swliveconnect=\"false\" id=\"googlepano\" allowscriptaccess=\"always\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" scale=\"noscale\" salign=\"lt\" flashvars=\"panoId=" + reply.Location.panoId + "&amp;directionMap=N:N,W:W,S:S,E:E,NW:NW,NE:NE,SW:SW,SE:SE&amp;yaw=" + marker.y + "&amp;zoom=" + marker.z + "&amp;browser=3&amp;serverURLPrefix=http://cbk0.google.com/cbk&amp;pitch=" + marker.p + "&amp;\" align=\"middle\"></embed></div><br />";

                    var gSIframe = '<IFRAME marginWidth=0 marginHeight=0 src="http://maps.google.dk/maps/sv?panoid=' + reply.Location.panoId + '&amp;gl=&amp;hl=" frameBorder=0 width=425 scrolling=no height=240></IFRAME>';
                    gStretHTML = "<div class=\"header\"><b>" + reply.Location.description + "</b> - " + name + "</div>" + "<div class=\"bubble\">" + gSIframe + "<div id='streetViewDisclaimer'>NB: Det viste er ikke nødvendigvis den præcise adresse</div>";



                  //  prompt("", gStretHTML);
                    var pp = new GLatLng(parseFloat(reply.Location.lat), parseFloat(reply.Location.lng));
                    map.openInfoWindowHtml(pp, gStretHTML + html);
                }
            } else {
                marker.openInfoWindowHtml(html);
            }
        });

    });

    // The new marker "mouseover" listener
    //GEvent.addListener(marker, "mouseover", function() { marker.openInfoWindowHtml(html); });

    return marker;
}

//function createMarker(p, name, html) {
//    var marker = new GMarker(p);
//    marker.y = 0;
//    marker.p = 5;
//    marker.z = 0;
//    GEvent.addListener(marker, "click", function() {
//        if (p) {
//            svc.getNearestPanorama(p, function(reply) {
//                if (reply.code = 200) {
//                    if (reply.Location) {
//                        var html = "<div class=\"header\"><b>" + reply.Location.description + "</b> - " + name + "</div>" + "<div class=\"bubble\"><embed src=\"http://maps.google.com/mapfiles/cb/googlepano.040.swf\" quality=\"high\" bgcolor=\"#EFEFEF\" style=\"width: 100%; height: 270px;\" wmode=\"opaque\" swliveconnect=\"false\" id=\"googlepano\" allowscriptaccess=\"always\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" scale=\"noscale\" salign=\"lt\" flashvars=\"panoId=" + reply.Location.panoId + "&amp;directionMap=N:N,W:W,S:S,E:E,NW:NW,NE:NE,SW:SW,SE:SE&amp;yaw=" + marker.y + "&amp;zoom=" + marker.z + "&amp;browser=3&amp;serverURLPrefix=http://cbk0.google.com/cbk&amp;pitch=" + marker.p + "&amp;\" align=\"middle\"></embed></div>" + "<div class=\"footer\">Copyright: " + reply.Data.copyright + "<br></div>"; var pp = new GLatLng(parseFloat(reply.Location.lat), parseFloat(reply.Location.lng)); map.openInfoWindowHtml(pp, html);
//                    } 
//                } 
//            });
//        }
//    }); gmarkers[i] = marker; side_bar_html += '<a href="javascript:myclick(' + i + ')">' + name + '</a><br>'; i++; return marker;
//}
//function myclick(i) { GEvent.trigger(gmarkers[i], "click"); }
//var map = new GMap2(document.getElementById("map")); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng(41.89243, -87.63112, 14), 14); map.addOverlay(new GStreetviewOverlay()); geocoder = new GClientGeocoder(); function showAddress(address) {
//    if (geocoder) {
//        geocoder.getLatLng(address, function(p) {
//            if (!p) { alert(address + " not found"); } else {
//                map.setCenter(p, 13); svc.getNearestPanorama(p, function(reply) {
//                    if (reply.code = 200) {
//                        if (reply.Location) { var html = "<div class=\"header\"><b>" + reply.Location.description + "</div></b>" + "<div class=\"bubble\"><embed src=\"http://maps.google.com/mapfiles/cb/googlepano.040.swf\" quality=\"high\" bgcolor=\"#EFEFEF\" style=\"width: 100%; height: 270px;\" wmode=\"opaque\" swliveconnect=\"false\" id=\"googlepano\" allowscriptaccess=\"always\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" scale=\"noscale\" salign=\"lt\" flashvars=\"panoId=" + reply.Location.panoId + "&amp;directionMap=N:N,W:W,S:S,E:E,NW:NW,NE:NE,SW:SW,SE:SE&amp;yaw=350.08435065836153&amp;zoom=0&amp;browser=3&amp;serverURLPrefix=http://cbk0.google.com/cbk&amp;pitch=10.983050525042998&amp;viewHeight=0.616426117417295\" align=\"middle\"></embed></div>" + "<div class=\"footer\">Copyright: " + reply.Data.copyright + "<br></div>"; var pp = new GLatLng(parseFloat(reply.Location.lat), parseFloat(reply.Location.lng)); map.openInfoWindowHtml(pp, html); } else { }
//                    } else { GLog.write("Error : " + reply.code); }
//                }); var marker = new GMarker(p); map.addOverlay(marker);
//            }
//        });
//    }
//}


// Calculate the boundaries and center of Google Map
function showMap() {
    // Find boundary points
    //    var bounds = new GLatLngBounds();
    //    for (var i = 0; i < mapMarkers.length; i++) {
    //        map.addOverlay(mapMarkers[i]);
    //        bounds.extend(mapMarkers[i].getPoint());
    //    }

    // Reset center and zoom level
    if (countPointOnMap > 0) {
        map.setCenter(bounds.getCenter());
        map.setZoom(map.getBoundsZoomLevel(bounds));
    } else {    
        document.getElementById("map").style.display = 'none';
        document.getElementById("mapError").style.display = '';
    }
}

// Insert point on map
function insertPointOnMap(gCoordsLat, gCoordsLng, Adresse, DepartmentPicture, DepartmentPictureThumbnailWidth, DepartmentPictureThumbnailHeight, pageId, afd, sel, Beliggenhed, PostBy, AfdelingNavn, SelskabNavn) {
    if (gCoordsLat != '' && gCoordsLng != '') {
        var point = new GLatLng(gCoordsLat, gCoordsLng);
        bounds.extend(point);
        countPointOnMap++;
    } else {
        //    geocoder.getLatLng(Adresse, Beliggenhed, PostBy, 'Denmark',
        //            function(point) {
        //                if (point) {
        //                    bounds.extend(point);
        //                }
        //            }
        //        );
    }
    if (point) {
        //var markerString = "<h2 class=h2>" + Adresse + " " + Beliggenhed + "<br />" + PostBy + "</h2><br />";
        var markerString = "<div id='GoogleMapsDepartmentInfo'>";
        if (DepartmentPicture != "") {
            markerString += "<img src=\'" + DepartmentPicture + "\' width=\'" + DepartmentPictureThumbnailWidth + "\' height=\'" + DepartmentPictureThumbnailHeight + "\' align=\'left\'>";
        }
        if (AfdelingNavn != "") {
            markerString += AfdelingNavn + "/" + SelskabNavn + "<br>";
            }
        markerString += "<a href=\'/Default.aspx?ID=" + pageId + "&amp;departmentId=" + afd + "&amp;companyId=" + sel + "&amp;action=DisplayDepartment\'>Klik her for at se detaljer for hele afdelingen</a><br/>";
        //  markerString += "<a href=\'javascript:void(0);\' onclick=\'javascript:$(\"\#tabs\").tabs(\"select\", 1);\'>Klik her for at se lejligheder fra din søgning</a></div>";
        markerString += "</div>";
        //markerString += "<a href='#apartments' rel=\'apartments\'>Klik her for at se lejligheder</a></div>";
        var marker = createMarker(point, markerString, getMarker(sel));

        map.addOverlay(marker);
    }
}

function insertPointOnMapSimpleInfo(gCoordsLat, gCoordsLng, Adresse, sel, html) {
    if (gCoordsLat != '' && gCoordsLng != '') {
        var point = new GLatLng(gCoordsLat, gCoordsLng);
        bounds.extend(point);
        countPointOnMap++;
    } else {
        //    geocoder.getLatLng(Adresse, Beliggenhed, PostBy, 'Denmark',
        //            function(point) {
        //                if (point) {
        //                    bounds.extend(point);
        //                }
        //            }
        //        );
    }
    if (point) {
        //var markerString = "<h2 class=h2>" + Adresse + " " + Beliggenhed + "<br />" + PostBy + "</h2><br />";
        var markerString = "<div id='GoogleMapsDepartmentInfo'>";
        markerString += html + "</div>";
        
        
        var marker = createMarker(point, markerString, getMarker(sel));

        map.addOverlay(marker);
    }
}



// Validate search form
function validateForm(frm) {
    if (parseInt(document.getElementById('MinimumHusleje').options[document.getElementById('MinimumHusleje').selectedIndex].value) > parseInt(document.getElementById('MaximumHusleje').options[document.getElementById('MaximumHusleje').selectedIndex].value)) {
        alert('Du bedes vælge en maksimum husleje, der er større end minimum');
        return false;
    }

    if (parseInt(document.getElementById('Minimumbareal').options[document.getElementById('Minimumbareal').selectedIndex].value) > parseInt(document.getElementById('Maximumbareal').options[document.getElementById('Maximumbareal').selectedIndex].value)) {
        alert('Du bedes vælge et maksimum areal, der er større end minimum');
        return false;
    }

    if (parseInt(document.getElementById('Minimumrum').options[document.getElementById('Minimumrum').selectedIndex].value) > parseInt(document.getElementById('Maximumrum').options[document.getElementById('Maximumrum').selectedIndex].value)) {
        alert('Du bedes vælge et maksimum areal, der er større end minimum');
        return false;
    }

    return true;
}

$().ready(function() {
    // Initialize the right menu
    $("#accordion").accordion({ autoHeight: false, animated: false });

    $('.accordion .head').click(function() {
        $(this).next().toggle();
        return false;
    }).next().hide();
    // if 'map' div is present - insert loading-text
    //$('<div id="loading">Henter kort...</div>')
    //          .insertBefore('#map')
    //          .ajaxStart(function() {
    //              $(this).show();
    //          }).ajaxStop(function() {
    //              $(this).hide();
    //          });

    // bind click-event to submitToList-button
    $('#submitToList').bind('click', function() {
        $('#frmSearchApartment').submit();
        return false;
    });

    // bind click-event to submitToMap-button
    //$('#submitToMap').bind('click', function() {
    //    $.get('/Public/GoogleMapSearch.aspx?search=true', $('#frmSearchApartment').serialize(), function(data) {
    //        $('#googleMapScript').empty();
    //        $('#googleMapScript').html(data);
    //    });
    //    return false;
    //});

    // Take care of Dynamicweb replacing hyperlinks
    $("a.tabLink").each(function() {
        var tabId = $(this).attr('href').split('#')[1];
        $(this).attr('href', '#' + tabId);
    });

    // Activate tabs
    $('#tabs').tabs();


//<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
//<link href="/Files/System/NemLejeSystem/css/jquery-ui-1.7.1.custom.css" rel="stylesheet" type="text/css" />
//<script type="text/javascript" src="/Files/System/NemLejeSystem/jquery-ui-1.7.1.custom.min.js"></script>
//<script type="text/javascript" src="/Files/System/NemLejeSystem/jquery.validate.js"></script>
//<script type="text/javascript" src="/Files/System/NemLejeSystem/ui.datepicker.js"></script>
//<script type="text/javascript" src="/Files/System/NemLejeSystem/tablesorter/jquery.tablesorter.min.js"></script>
//<script type="text/javascript" src="/Files/System/NemLejeSystem/tablesorter/jquery.tablesorter.pager.js"></script>
//<script type="text/javascript" src="/Files/System/NemLejeSystem/lightbox/jquery.lightbox-0.5.min.js"></script>
//<script type="text/javascript" src="/Files/System/NemLejeSystem/javascript.js"></script>
 
 // LOADING INFO
    $("#waitingForResultBox").dialog({
        autoOpen: false,
        bgiframe: true,
        modal: true,
        width: 300,
        height: 100,
        overlay: { opacity: 0.5, background: "black" },
        buttons: {
//            Ok: function() {
//                $(this).dialog('close');

//            }
        }
    });

    // Activate lightbox
    $('#Pictures a').lightBox({
        txtImage: 'Billede',
        txtOf: 'af',
        imageLoading: '/Files/System/NemLejeSystem/lightbox/lightbox-ico-loading.gif',
        imageBtnClose: '/Files/System/NemLejeSystem/lightbox/closelabel.gif',
        imageBtnPrev: '/Files/System/NemLejeSystem/lightbox/prev.gif',
        imageBtnNext: '/Files/System/NemLejeSystem/lightbox/next.gif',
        fixedNavigation: false
    });

    // Activate dialog 
    $("#dialog").dialog({
        autoOpen: false,
        bgiframe: true,
        modal: true,
        width: 600,
        height: 700,
        overlay: { opacity: 0.5, background: "black" },
        buttons: {
            Ok: function() {
                $(this).dialog('close');
           
            }
        }
    });

	    $("#additionalInfoWindow").dialog({
        autoOpen: false,
        bgiframe: true,
        modal: true,
        width: 900,
       // height: 700,
        overlay: { opacity: 0.5, background: "black" },
 buttons: {

 

 }
    });
	
	
    // Activate wish list changed dialog
    $("#wishlistChangedDialog").dialog({
        autoOpen: false,
        bgiframe: true,
        modal: true,
        width: 300,
        height: 150,
        overlay: { opacity: 0.5, background: "black" },
        buttons: {
            Ok: function() {
                $(this).dialog('close');
            }
        }
    });

    // Activate wish list changed dialog
    $("#YouNeedToUpgradeDialog").dialog({
        autoOpen: false,
        bgiframe: true,
        modal: true,
        width: 400,
        height: 300,
        overlay: { opacity: 0.5, background: "black" },
        buttons: {
            Ok: function() {
                $(this).dialog('close');
            }
        }
    });

    // Activate wish list changed dialog
    $("#AnErrorOccurred").dialog({
        autoOpen: false,
        bgiframe: true,
        modal: true,
        width: 300,
        height: 100,
        overlay: { opacity: 0.5, background: "black" },
        buttons: {
            Ok: function() {
                $(this).dialog('close');
            }
        }
    });


    // Activate wishlist actions
    $('a.addToWishList').bind('click', function() {
        var div = $(this).find('div');
        var link = $(this);
        $.get(this.href, function(data) {
            //alert(data);
            if (data == "1") {
                $("#wishlistChangedDialog").dialog("open");
                div.removeClass('addToWishList');
                link.removeClass('addToWishList');
                div.addClass('removeFromWishList');
                link.addClass('removeFromWishList');
            } else if (data != "Fejl") {
                $("#YouNeedToUpgradeDialog").dialog("open");
            } else {
                $("#AnErrorOccurred").dialog("open");
            }
        }
            );
        return false;
    });

    // Activate wishlist actions
    $('a.removeFromWishList').bind('click', function() {
        var div = $(this).find('div');
        var link = $(this);
        $.get(this.href, function(data) {
            $("#wishlistChangedDialog").dialog("open");
            div.removeClass('removeFromWishList');
            link.removeClass('removeFromWishList');
            div.addClass('addToWishList');
            link.addClass('addToWishList');
        }
            );
        return false;
    });

    // Activate respond dialog
    $("#responddialog").dialog({
        autoOpen: false,
        bgiframe: true,
        modal: true,
        width: 400,
        height: 200,
        overlay: { opacity: 0.5, background: "black" },
        buttons: {
            Accepter: function() {
                if (confirm("Ved denne handling accepterer du tilbuddet! Er du helt sikker?")) {
                    $('#Svar').val("J");
                    $("#responddialogform").submit();
                }
                $(this).dialog('close');
            },
            Afvis: function() {
                    if (confirm("Ved denne handling afviser du tilbuddet! Er du helt sikker?")) {
                        $('#Svar').val("N");
                        $("#responddialogform").submit();
                    }
                    $(this).dialog('close');
                }
            
        }
    });$("#responddialogAccept").dialog({
        autoOpen: false,
        bgiframe: true,
        modal: true,
        width: 400,
        height: 200,
        overlay: { opacity: 0.5, background: "black" },
        buttons: {
            Accepter: function() {
                if (confirm("Ved denne handling accepterer du tilbuddet! Er du helt sikker?")) {
                    $('#Svar').val("J");
                    $("#responddialogform").submit();
                }
                $(this).dialog('close');
            }
            
        }
    });
    $("#responddialogDecline").dialog({
            autoOpen: false,
            bgiframe: true,
            modal: true,
            width: 400,
            height: 200,
            overlay: { opacity: 0.5, background: "black" },
            buttons: {                
                Afvis: function() {
                    if (confirm("Ved denne handling afviser du tilbuddet! Er du helt sikker?")) {
                        $('#Svar').val("N");
                        $("#responddialogform").submit();
                    }
                    $(this).dialog('close');
                }
            }
        });
        
    // Activate response reciept dialog
    $("#recieptdialog").dialog({
        autoOpen: true,
        bgiframe: true,
        modal: true,
        width: 300,
        height: 200,
        overlay: { opacity: 0.5, background: "black" },
        buttons: {
            Ok: function() {
                $(this).dialog('close');
            }
        }
    });

    // Activate Terminate Lease dialog
    $("#TerminateLeaseDialog").dialog({
        autoOpen: false,
        autoResize: true,
        resizable: true,
        bgiframe: true,
        modal: true,
        width: 820,
        height: 800,
        overlay: { opacity: 0.5, background: "black" },
        buttons: {
            Luk: function() {
                $(this).dialog('close');
            }
        }
    });

    // Load terminate lease file into JQuery dialog
    $("a.TerminateLeaseLink").click(
        function(e) {
            e.preventDefault();
            $('#TerminateLeaseIframe').attr("src", "/Public/TerminateLease.aspx?apartmentId=1032");
            $("#TerminateLeaseDialog").dialog("open");
            return false;
        }
    );

    // Activate respond actions

    // Activate table sorter
    $("#apartmentsTable")
          .tablesorter({ widgets: ['zebra'], sortList: [[0, 0]] })
          .tablesorterPager({ container: $("#pager"), size: 20, positionFixed: false });
    // Min side - Tilbud
    $("#Apartments")
          .tablesorter({ widgets: ['zebra'], sortList: [[0, 0]] })
    // Min side - Tilbudshistorik
    $("#Apartments_history")
          .tablesorter({ widgets: ['zebra'], sortList: [[0, 0]] })
          //.tablesorterPager({ container: $("#pager"), size: 20, positionFixed: false });

    //    var onblurFields = $("#Navn, #Email");
    //    onblurFields.blur(function() {
    //        $("#NameEmail").val($("#Navn").val() + "|" + $("#Email").val());
    //    });


    // validate signup form on keyup and submit
    $("#CreateUserForm").validate({
        rules: {
            Navn: {
                required: true,
                minlength: 5
            },
            Adresse: {
                required: true,
                minlength: 5
            },
            Postby: {
                required: true,
                minlength: 5
            },
            Email: {
                required: true,
                email: true
            },
            Cpr6: {
                required: true,
                minlength: 6,
                maxlength: 6
            },
            Tlf: {
                required: true
            },
            Password: {
                required: true,
                minlength: 5
            },
            RepeatPassword: {
                equalTo: "#Password"
            }

        },
        messages: {
            Navn: {
                required: "<br /><span>Indtast venligst dit navn</span>",
                minlength: "<br /><span>Indtast venligst dit navn</span>"
            },
            Adresse: {
                required: "<br />Indtast venligst din adresse",
                minlength: "<br />Indtast venligst din adresse"
            },
            Postby: {
                required: "<br />Indtast venligst dit postnummer og by",
                minlength: "<br />Indtast venligst dit postnummer og by"
            },
            Email: {
                required: "<br />Indtast venligst en gyldig e-mail adresse",
                email: "<br />Indtast venligst en gyldig e-mail adresse"
            },
            Cpr6: {
                required: "<br />Indtast venligst de første seks cifre i dit personnummer",
                minlength: "<br />Indtast venligst de første seks cifre i dit personnummer",
                maxlength: "<br />Indtast venligst de første seks cifre i dit personnummer"
            },
            Tlf: {
                required: "<br />Indtast venligst dit telefonnummer"
            },
            Password: {
                required: "<br />Indtast venligst dit nye password.",
                minlength: "<br />Dit password skal bestå af mindst fem tegn."
            },
            RepeatPassword: {
                equalTo: "<br />Gentag venligst dit nye password."
            }
        }
    });

    // validate login form on keyup and submit
    $("#ExtUserForm").validate({
        rules: {
            Username: {
                required: true
            },
            Password: {
                required: true
            }
        },
        messages: {
            Username: {
                required: "<br />Indtast venligst dit brugernavn"
            },
            Password: {
                required: "<br />Indtast venligst dit kodeord"
            }
        }
    });

    $("#loginButton").bind("click", function(e) {
        if ($("#Username").val() == '' || $("#Password").val() == '') {
            alert('Du bedes venligst indtaste både dit brugernavn og dit password');
            return false;
        }
    });

    // Set default values for search form
    //    apartmentTypes = new Array;
    //    apartmentTypes = $("#Server_Request_apartmenttypes").val().split(",");
    //    $.each(apartmentTypes, function() {
    //        alert(this);
    //    });

    //$.each($("#ApartmentTypes"), function() { alert(this); });
    //alert($("#Server_Request_apartmenttypes").val());
    //$("#frmSearchApartment :input[@ApartmentTypes]").val([$("#Server_Request_apartmenttypes").val()]);

    //$("#ApartmentTypes").each(function() { alert(this); });

    $("#MinimumHusleje").val($("#Server_Request_minimumhusleje").val());
    if ($("#Server_Request_maximumhusleje").val() != '') {
        $("#MaximumHusleje").val($("#Server_Request_maximumhusleje").val());
    }

    $("#Minimumbareal").val($("#Server_Request_minimumbareal").val());

    if ($("#Server_Request_maximumbareal").val() != '') {
        $("#Maximumbareal").val($("#Server_Request_maximumbareal").val());
    }

    $("#Minimumrum").val($("#Server_Request_minimumrum").val());

    if ($("#Server_Request_maximumrum").val() != '') {
        $("#Maximumrum").val($("#Server_Request_maximumrum").val());
    }

    if ($("#Server_Request_petallowed").val() != '') {
        $("#petAllowed").attr("checked", true);
    }

    if ($("#Server_Request_noorlowwaitingtime").val() != '') {
        $("#noOrLowWaitingTime").attr("checked", true);
    }

    if ($("#Server_Request_showonlyfreeapartments").val() != '') {
        $("#showOnlyFreeApartments").attr("checked", true);
    }


    var dt = new Date();
    $(function() {
        $("#Cpr6").datepicker({
            dateFormat: 'ddmmy',
            maxDate: dt.getDate() - (15 * 365),
            showButtonPanel: true,
            yearRange: "-100:+0",
            showOn: "both",
            changeYear: true,
            changeMonth: true
        });
    });
});