﻿function showObjectDetails(objGUID) {
    document.aspnetForm.ctl00$cp1$objectGUID.value = objGUID;
    document.aspnetForm.ctl00$cp1$showDetails.value = 1;
    document.aspnetForm.submit();
}

function showEstateAgentObjects(estateAgentGUID) {

    document.aspnetForm.ctl00$cp1$estateAgentGUID.value = estateAgentGUID;
    document.aspnetForm.ctl00$cp1$showEstateAgentDetails.value = 1;
    document.aspnetForm.submit();
}

function sortSearchResult(sortColumn, sortOrder) {
    if (document.aspnetForm.ctl00$cp1$sortColumn) {
        document.aspnetForm.ctl00$cp1$sortColumn.value = sortColumn;
        document.aspnetForm.ctl00$cp1$sortOrder.value = sortOrder;
        document.aspnetForm.ctl00$cp1$sortObjects.value = 1;
    }
    else {
        document.aspnetForm.ctl00$ctl00$ContentPlaceHolder1$cp1$sortColumn.value = sortColumn;
        document.aspnetForm.ctl00$ctl00$ContentPlaceHolder1$cp1$sortOrder.value = sortOrder;
        document.aspnetForm.ctl00$ctl00$ContentPlaceHolder1$cp1$sortObjects.value = 1;
    }

    document.aspnetForm.submit();
}

function showEstateAgentContactWindow(estateAgentGUID, estateAgentName, estateAgentEmail) {
    var urlString = "/showEstateAgentContactForm.aspx?estateAgentGUID=" + estateAgentGUID + "&estateAgentName=" + estateAgentName + "&estateAgentEmail=" + estateAgentEmail;
    var newWin = window.open(urlString, "EstateAgentContactForm", "menubar=no, toolbar=no, status=no, width=780, height=470, left=0, top=0");
}

function showObjectPrintWindow(objectGUID, fotoSlider, googleMap) {
    var urlString = "/printObjectDetails.aspx?id=" + objectGUID + (fotoSlider ? "&fotoSlider=1" : "") + (googleMap ? "&googleMap=1" : "");
    var newWin = window.open(urlString, "PrintWindow", "menubar=no, toolbar=no, status=no,width=642, height=700, left=0, top=0, scrollbars=yes");
}

function showEmailObjectForm(objectGUID, objectAddress) {
    var urlString = "/showEmailFriendForm.aspx?id=" + objectGUID + "&addr=" + objectAddress;
    var newWin = window.open(urlString, "EmailObjectWindow", "menubar=no, toolbar=no, status=no,width=525, height=260, left=0, top=0");
}
function showAdvertPrintWindow(advertId, fotoSlider, googleMap, noMap) {
    var urlString = "/printAdvertDetails.aspx?AdvertId=" + advertId + (fotoSlider ? "&fotoSlider=1" : "") + (googleMap ? "&googleMap=1" : "") + noMap;
    var newWin = window.open(urlString, "PrintWindow", "menubar=no, toolbar=no, status=no,width=642, height=700, left=0, top=0, scrollbars=yes");
}

function showEmailAdvertForm(advertId, objectAddress, noMap) {
    var map = "";
    if (noMap != undefined)
        map = noMap;
    var urlString = "/showEmailFriendForm.aspx?AdvertId=" + advertId + "&addr=" + objectAddress + map;
    var newWin = window.open(urlString, "EmailObjectWindow", "menubar=no, toolbar=no, status=no,width=525, height=260, left=0, top=0");
}

function showPluginObjectPrintWindow(objectGUID, fotoSlider, googleMap) {
    var urlString = "/printObjectDetails.aspx?id=" + objectGUID + (fotoSlider ? "&fotoSlider=1" : "") + (googleMap ? "&googleMap=1" : "");
    var newWin = window.open(urlString, "PrintWindow", "menubar=no, toolbar=no, status=no,width=642, height=700, left=0, top=0, scrollbars=yes");
}

function showEstateAgentPluginContactWindow(estateAgentGUID, estateAgentName, estateAgentEmail) {
    var urlString = "../showEstateAgentContactForm.aspx?showAddParams=1&estateAgentGUID=" + estateAgentGUID + "&estateAgentName=" + estateAgentName + "&estateAgentEmail=" + estateAgentEmail;
    var newWin = window.open(urlString, "EstateAgentContactForm", "menubar=no, toolbar=no, status=no, width=780, height=375, left=0, top=0");
}

function showSearchEstateAgentWindow(controlName) {
    var urlString = "../admin/searchEstateAgent.aspx?cname=" + controlName;
    var newWin = window.open(urlString, "SearchEstateAgent", "menubar=no, toolbar=no, status=no,width=725, height=600, left=0, top=0, scrollbars=yes");
}

function showObjectOwnerForm(objectGUID, objectAddress1, objectAddress2, ownerId) {
    var urlString = "/showObjectOwnerForm.aspx?id=" + objectGUID + "&addr1=" + objectAddress1 + "&addr2=" + objectAddress2 + "&o=" + ownerId;
    var newWin = window.open(urlString, "ObjectOwnerWindow", "menubar=no, toolbar=no, status=no,width=575, height=475, left=0, top=0");
}

function onMyFormSubmit(a, b) {
    var cur = EdenWay.GeoMaps.GetCurrentSelection();

    //alert('country = (' + cur.country + ') locality = (' + cur.locality + ')');

    var countryField = document.getElementById(a);
    var localityField = document.getElementById(b);

    if (cur.country) {
        countryField.value = cur.country;
        localityField.value = cur.locality;
        //open("searchResults.aspx?objectType=F&searchTypeForeign=3&noMap=1&localitySearch=1&ewCountry="+ countryField.value +"&ewLocality="+ localityField.value ,"_parent");

        return true;
    } else {
        countryField.value = '';
        localityField.value = '';

        alert('Please select a country first.');

        return false;
    }
}

function addAutoCompleteCity(textfieldid, wijkenid) {
    $("#" + textfieldid).autocomplete({
        source: function (request, response) {
            $.ajax({
                url: "/hl.asmx/GetCityOrPostalCode",
                data: "{'s': '" + $('#' + textfieldid).val().replace("'", '#') + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                type: "POST",
                success: function (data) {
                    response($.map(data.d, function (item) {
                        return {
                            label: item.CityOrZip,
                            value: item.CityOrZip
                        }
                    }))
                }
            });
        },
        delay: 100,
        minLength: 2,
        select: function (event, ui) {
            if (wijkenid) {
                loadWijken(wijkenid, textfieldid);
            }

        }
    });
}

function loadWijken(wijkenid, textfieldid) {
    $.ajax({
        url: "/hl.asmx/GetWijk",
        data: "{'s': '" + $('#' + textfieldid).val().replace("'", '#') + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        type: "POST",
        success: function (data) {
            $('#' + wijkenid).html(""); //clear old options
            $('#' + wijkenid).get(0).add(new Option("Geen voorkeur", ""), document.all ? 0 : null);
            data = eval(data); //get json array
            for (i = 0; i < data.d.length; i++)//iterate over all options
            {
                $('#' + wijkenid).get(0).add(new Option(data.d[i].CityOrZip, data.d[i].CityOrZip), document.all ? i : null);

            }
        }
    });

}


function loadImageSlider() {

    $("#image_placeholder_nav_left").hide();
    $("#image_placeholder_nav_right").hide();

    LoadStripe(GetIdFromFirstItemInList(bigThumbListId), bigThumbListId);

    $("#imagee").hover(
                                                                            function () {
                                                                                ShowNavigationOverlayButtons(bigThumbListId);
                                                                            },
                                                                            function () {
                                                                                HideNavigationOverlayButtons(bigThumbListId);
                                                                            }
                                                                        );

    $("#image_placeholder_nav_left").click(function () {
        $("#imgPrev").click();
        ShowNavigationOverlayButtons(bigThumbListId);

    });

    $("#image_placeholder_nav_right").click(function () {
        $("#imgNext").click();
        ShowNavigationOverlayButtons(bigThumbListId);

    });

    $(".stripe_thumb").live('click', function () {
        var id = $(this).attr("id");
        SetSelectedStripeItem($(this));
        SelectImage(id, bigThumbListId, bigThumbWidthListId, bigThumbHeightListId);
    });

    $("#imgPrev").live('click', function () {
        var item = GetSelectedStripeItem();
        var itemId = $(item).attr("id");
        var first = IsFirstStripeItem(item);
        if (first) {
            if (itemId == GetIdFromFirstItemInList(bigThumbListId)) {
                //no moving left because it is first item in the list
            }
            else {
                var prevId = GetIdFromPreviousItemInList(itemId, bigThumbListId)
                LoadStripe(prevId, bigThumbListId);
                var firstItem = GetFirstItemInStripe();
                SetSelectedStripeItem(firstItem);
                SelectImage($(firstItem).attr("id"), bigThumbListId, bigThumbWidthListId, bigThumbHeightListId);
            }
        } else {
            var prevItem = GetPreviousItemInStripe(item);
            SetSelectedStripeItem(prevItem);
            SelectImage($(prevItem).attr("id"), bigThumbListId, bigThumbWidthListId, bigThumbHeightListId);
        }

    });

    $("#imgNext").live('click', function () {
        var item = GetSelectedStripeItem();
        var itemId = $(item).attr("id");
        var last = IsLastStripeItem(item);
        if (last) {
            if (itemId == GetIdFromLastItemInList(bigThumbListId)) {
                //no moving forward because it is last item in list
            }
            else {
                var firstItem = GetFirstItemInStripe();
                var firstItemId = $(firstItem).attr("id");
                var nextItemId = GetIdFromNextItemInList(firstItemId, bigThumbListId);
                LoadStripe(nextItemId, bigThumbListId);
                var lastItem = GetLastItemInStripe();
                SetSelectedStripeItem(lastItem);
                SelectImage($(lastItem).attr("id"), bigThumbListId, bigThumbWidthListId, bigThumbHeightListId);
            }
        } else {
            var nextItem = GetNextItemInStripe(item);
            SetSelectedStripeItem(nextItem);
            SelectImage($(nextItem).attr("id"), bigThumbListId, bigThumbWidthListId, bigThumbHeightListId);
        }


    });

    var fItem = GetFirstItemInStripe();
    SetSelectedStripeItem(fItem);
    SelectImage($(fItem).attr("id"), bigThumbListId, bigThumbWidthListId, bigThumbHeightListId);

}


function getOpenxIframe(zoneid, url) {
    var numRand = Math.floor(Math.random()*999999);
    return "<iframe id='a65e9ad2' name='a65e9ad2' src='http://ads.huislijn.nl/bannersystem/www/delivery/afr.php?zoneid=" + zoneid + "&amp;cb=" + numRand + url + "' frameborder='0' scrolling='no' width='728' height='90'><a href='http://ads.huislijn.nl/bannersystem/www/delivery/ck.php?n=a47b8940&amp;cb=" + numRand + "' target='_blank'><img src='http://ads.huislijn.nl/bannersystem/www/delivery/avw.php?zoneid=" + zoneid + "&amp;cb=" + numRand + "&amp;n=a47b8940' border='0' alt='' /></a></iframe>";
}

function getOpenxIframeblock(zoneid, url) {
    var numRand = Math.floor(Math.random() * 999999);
    return "<iframe id='a65e9ad2' name='a65e9ad2' src='http://ads.huislijn.nl/bannersystem/www/delivery/afr.php?zoneid=" + zoneid + "&amp;cb=" + numRand + url + "' frameborder='0' scrolling='no' width='336' height='280'><a href='http://ads.huislijn.nl/bannersystem/www/delivery/ck.php?n=a47b8940&amp;cb=" + numRand + "' target='_blank'><img src='http://ads.huislijn.nl/bannersystem/www/delivery/avw.php?zoneid=" + zoneid + "&amp;cb=" + numRand + "&amp;n=a47b8940' border='0' alt='' /></a></iframe>";
}
function getOpenxIframetext(zoneid, url) {
    var numRand = Math.floor(Math.random() * 999999);
    return "<iframe id='a65e9ad2' name='a65e9ad2' src='http://ads.huislijn.nl/bannersystem/www/delivery/afr.php?zoneid=" + zoneid + "&amp;cb=" + numRand + url + "' frameborder='0' scrolling='no' width='500' height='20'><a href='http://ads.huislijn.nl/bannersystem/www/delivery/ck.php?n=a47b8940&amp;cb=" + numRand + "' target='_blank'><img src='http://ads.huislijn.nl/bannersystem/www/delivery/avw.php?zoneid=" + zoneid + "&amp;cb=" + numRand + "&amp;n=a47b8940' border='0' alt='' /></a></iframe>";
}


function getVideo(guid) {
    return '<iframe id="FotoSliderMovie" name="FotoSliderMovie" src="http://www.fotoslider.nl/partner.php?pid=25-' + guid + '" width="320" height="300" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>';
}


function getBuurt(zipcode) {
    return '<iframe name="buurtinfo" src="http://www.estate-ware.com/services/buurt.asp?pc=' + zipcode + '&stylesheet=" width="780" height="500" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes"></iframe>';
}

function getMapAround(guid, lat, pos, objecttype) {
    return '<iframe width="540" height="320" frameborder="0" scrolling="no" src="/gMaps.aspx?o=1&type=2&guid=' + guid + '&lng=' + lat + '&pos=' + pos + '&min=&max=&objt=' + objecttype + '"></iframe>';
}

function getStreetview(lat, pos) {
    return '<iframe width="950" height="600" frameborder="0" scrolling="no" src="/StreetView.aspx?lng=' + lat + '&pos=' + pos + '"></iframe>';
}


function addAutoCompleteCityCountry(textfieldid, countryid) {
    $("#" + textfieldid).autocomplete({
        source: function (request, response) {
            $.ajax({
                url: "/hl.asmx/GetCityCountry",
                data: "{'s': '" + $('#' + textfieldid).val().replace("'", '#') + "', 'c':'" + $('#' + countryid).val() + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                type: "POST",
                success: function (data) {
                    response($.map(data.d, function (item) {
                        return {
                            label: item.CityOrZip,
                            value: item.CityOrZip
                        }
                    }))
                }
            });
        },
        delay: 100,
        minLength: 1,
        select: function (event, ui) {            

        }
    });
}

function showContactInfoAdvert(advertid){
    $(".adres p:first-child").empty();

    $.ajax({
        url: "/hl.asmx/GetContactByAdvertId",
        data: "{'vsAdvertID': '" + advertid + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        type: "POST",
        success: function (data) {
            $(".adres p:first-child").html(data.d.Address + '<br/>' + data.d.City + '<br/>' + data.d.LandPhone + '<br/>');
            $("#advertcomment").html('<p>' + data.d.Comment + '</p>');
        }
    });

}





