﻿//CONSTANTES
var C_PATHMAPICON = "http://www.bmykey.com/images/icons/Key_red.png";
var C_PATHURL = "http://www.bmykey.com/";
var C_PATHMAPICONSHADOW = "http://www.bmykey.com/images/icons/key_shadow.png";
var C_MAP = "GmapControl1";
var C_MAP2 = "ctl00$ContentImmobilier$Property_details_full1$GmapControl1";
var C_MAPCREATE = "ctl00$ContentImmobilier$Property_create1$GmapControl1";
var C_MAPAGENCY = "Agency1$GmapControlAgency";
var C_WIDGET = "widget1$GmapControlAgency";
var C_WIDGET_SEARCH = "widget1$WidgetSearch";
var C_CONTROL = "";
var C_MAPCREATECONTROL = "ctl00_ContentImmobilier_Property_create1_";
var C_MAPCREATECONTROLWiz = "ctl00_ContentImmobilier_Property_create1_Wizard1_";
var C_XML = "http://www.bmykey.com/coordinates/coordinates.aspx";
var arrayProperties = new Array();
var xmlTokenAvailable = true;
var centerRegion = 9;
var centerDepartment = 10;
var centerTown = 12;
var firstMarkerLoad = true;
var prevSelectedMarkerId = 0;

function stop(){
    if(($get(C_MAPCREATECONTROL + "HiddenFieldLatitudeTown").value =="") && ($get(C_MAPCREATECONTROL + "HiddenFieldLongitudeTown").value == "")) {
        alert("Impossible de trouver cette adresse");
        return false;
    }
    else
        return true;
}

function enableModule() {
    ShowHideElement('show','modules');
}

function GetCoordinate(address, zip, city, country)
{  
  var address = $get(C_MAPCREATECONTROLWiz + "TextBoxAddressesAddress").value;
  var zip = $get(C_MAPCREATECONTROLWiz + "TextBoxAddressesZip").value;
  var city = $get(C_MAPCREATECONTROLWiz + "TextBoxAddressesCity").value;
  var pays = $get(C_MAPCREATECONTROLWiz + "DropDownListAddressesCountry").value;
  address = address.replace("'","\'");
  city = city.replace("'","\'");
  pays = pays.replace("'","\'");
  
  if(address != "" & zip != "" & city != "" & pays != "") {
    var townaddress = city + ', ' + zip + ', ' + pays;
    var address = address + ', ' + zip + ', ' + city + ', ' + pays;
    window.setTimeout(stop, 15000);
    GetTownPoint(townaddress, address);
    
    return true;
  }
  else
  {
    return false;
  }
}

function GetTownPoint(townaddress, address) {
    if (geocoderTown) {
        geocoderTown.getLatLng(
        townaddress,
        function(pointTown) {
            if (!pointTown) {
            } 
            else {
                var markerTown = new GMarker(pointTown);
                var coordinateTown = markerTown.getPoint();
                var latituteTown = coordinateTown.lat();
                var longituteTown = coordinateTown.lng();
                $get(C_MAPCREATECONTROL + "HiddenFieldLatitudeTown").value = latituteTown;
                $get(C_MAPCREATECONTROL + "HiddenFieldLongitudeTown").value = longituteTown;
                showAddress(address);
                $get("td_address_verified").innerHTML = "<b>Adresse vérifiée!</b>";
                $("#errorAddress").hide();
                }
            }
        );
    }
}

function DragEndGetCoordinates(marker)
{
    var coordinate = eval(marker).getPoint();
    var latitute = coordinate.lat();
    var longitute = coordinate.lng();
    $get(C_MAPCREATECONTROL + "HiddenFieldLatitude").value = latitute;
    $get(C_MAPCREATECONTROL + "HiddenFieldLongitude").value = longitute;
}

function Pause(millis)
{
    var date = new Date();
    var curDate = null;

    do { curDate = new Date(); }
    while(curDate-date < millis);
} 

//Create Event Creator function
function addEvent(element, evenementType, fct, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(evenementType, fct, useCapture);
        return true;
    }
        else if (element.attachEvent) {
        var r = element.attachEvent('on' + evenementType, fct);
        return r;
    }
        else {
        element['on' + evenementType] = fct;
    }
}

//Create Marker with info window
function createMarker(point, propertyId, type, map) {
    var icon = new GIcon();
    icon.image = C_PATHMAPICON;
    icon.iconSize = new GSize(20, 40);
    icon.shadow = C_PATHMAPICONSHADOW;
    icon.shadowSize = new GSize(37, 34);
    icon.iconAnchor = new GPoint(8, 39);
    icon.infoWindowAnchor = new GPoint(10, 1);
    
    var marker = new GMarker(point,icon);
    
    //Add marker to propertyid array
    Array.add(arrayProperties, propertyId);
    
    var temp;
    
    if(type == "info") {
        var temp = new gmarkersObject(markerIndexcount, propertyId, marker);
        gmarkersProperties[markerIndexcount] = temp;
    }
    if(type == "window") {
        var ew = new EWindow(map, E_STYLE_7);  
        temp = new gmarkersObject(markerIndexcount, propertyId, marker, ew);
        
        map.addOverlay(ew);
        gmarkersProperties[markerIndexcount] = temp;
        
        // ========== Close the EWindow if theres a map click ==========
        GEvent.addListener(map, "click", function(marker,point) {
            if (point) {
                ew.hide();
            }
        });
    }

    GEvent.addListener(marker,"click",function() {
        GetPropertyInfos(temp, type);
    });
    
    markerIndexcount = markerIndexcount + 1;
      
    return marker;
}

function LoadMarkersFromXml(xmlPath, searchFilter, maxZoomLevel, fitZoomToData, mapName, type){
    var map = getCurrentMap();
    if(type == null) {
        type="info";
        }
    if(xmlTokenAvailable) {
        xmlTokenAvailable = false;
        var request = GXmlHttp.create();
        window.setTimeout(ResetToken, 5000);
        
        request.open("GET", xmlPath + "?" + searchFilter, true);
        request.onreadystatechange = function() {
            if (request.readyState == 4) {
                var batch = [];
                var xmlDoc = request.responseXML;
                var markers = xmlDoc.documentElement.getElementsByTagName("marker");
                var j = 0;
                for (var i = 0; i < markers.length; i++) {
                    var lat = parseFloat(markers[i].getAttribute("lat"));
                    var lng = parseFloat(markers[i].getAttribute("lng"));
                    var point = new GLatLng(lat,lng);
                    var myPropertyid = markers[i].getAttribute("property_id");
                    
                    if(!Array.contains(arrayProperties, myPropertyid)){
                        //batch.push(createMarker(point, myPropertyid, type, mapName));
                        map.addOverlay(createMarker(point, myPropertyid, type, map));
                        //Fit Zoom To data
                        if(fitZoomToData == "true") {
                            bounds.extend(point);
                            map.setZoom(mapName.getBoundsZoomLevel(bounds) - 1);
                            map.setCenter(bounds.getCenter());
                        }
                    }
                }
                //manager.addMarkers(batch, maxZoomLevel);
                //manager.addMarkers(batch, 3);
                if(firstMarkerLoad) {
                    //manager.refresh();
                    firstMarkerLoad = false;
                    }
                updateMapCenter();
                xmlTokenAvailable = true;
            }
        }
        request.send(null);
    }
}

function ResetMarkers(isWidget) {
    var map = getCurrentMap();
    var tempMarker = null;
    
    if(!isWidget) {
        for(var i=0 ;  i < gmarkersProperties.length ; i++) {
            if(gmarkersProperties != null) {
                if(gmarkersProperties[i].property_id != prevSelectedMarkerId) {
                    map.removeOverlay(gmarkersProperties[i].marker);
                }
                else {
                    tempMarker = gmarkersProperties[i].marker;
                }
            }
        }
        
        arrayProperties = new Array();
        gmarkersProperties = new Array();
        markerIndexcount = 0;
        
        if(tempMarker != null) {
            Array.add(arrayProperties, prevSelectedMarkerId);
            var temp = new gmarkersObject(0, prevSelectedMarkerId, tempMarker);
            gmarkersProperties[0] = temp;
            markerIndexcount = 1;
        }
    } else {
        map.clearOverlays();
        arrayProperties = new Array();
        gmarkersProperties = new Array();
        markerIndexcount = 0;
    }
}

//Connect to webservices to obtain property informations
function GetPropertyInfos(myMarkerObject, type){
    var size = 2;
    var isneuf = false;
    if($get("hfIsNeuf") != null) {
        isneuf = true;
    }
    if($get("Agency1__HfIsNeuf") != null) {        
        if($get("Agency1__HfIsNeuf").value == "True") {      
            isneuf = true;
        }
    }
    if($get("Property_fulldetails1__HFIsNeuf") != null) {
        if($get("Property_fulldetails1__HFIsNeuf").value == "true") {
            isneuf = true;
        }
    }
    prevSelectedMarkerId = 0;
    //Check if we are on main page
    if($get("HiddenFieldSelectedModule") != null) {
        //Check if we are on a geocoder page
        if($get("HiddenFieldSelectedModule").value == "nearby") {
            size = 1;
        }
        if(type == "info"){
            BmyKey.WebServices.Properties.GetMarkersHtml(myMarkerObject.property_id, myMarkerObject.id, size, isneuf, OnSucceededGetPropertyInfosWithInfo);
            prevSelectedMarkerId = myMarkerObject.property_id;
        }
        if(type == "window"){
            BmyKey.WebServices.Properties.GetMarkersHtml(myMarkerObject.property_id, myMarkerObject.id, size, isneuf, OnSucceededGetPropertyInfosWithWindow);
            prevSelectedMarkerId = myMarkerObject.property_id;
        }
    }
    //We are on single property page
    else {
        if(type == "info"){
            BmyKey.WebServices.Properties.GetMarkersHtmlLight(myMarkerObject.property_id, myMarkerObject.id, 2, isneuf, OnSucceededGetPropertyInfosWithInfo);
        }
        if(type == "window"){
            BmyKey.WebServices.Properties.GetMarkersHtmlWindow(myMarkerObject.property_id, myMarkerObject.id, isneuf, OnSucceededGetPropertyInfosWithWindow);
        }
        prevSelectedMarkerId = myMarkerObject.property_id;
    }
}

function OnSucceededGetPropertyInfosWithInfo(result){
    //gmarkers[result[1]].openInfoWindowHtml(result[0]);
    gmarkersProperties[result[1]].marker.openInfoWindowHtml(result[0]);
}
function OnSucceededGetPropertyInfosWithWindow(result){
    gmarkersProperties[result[1]].ew.openOnMarker( gmarkersProperties[result[1]].marker, result[0]);
    var centerPoint=new GLatLng(gmarkersProperties[result[1]].marker.getPoint().lat(),gmarkersProperties[result[1]].marker.getPoint().lng());
    GetWidgetMap().panTo(centerPoint);
    window.setTimeout(PanAnimation, 1000);
}

function PanAnimation() {
    var northEast = GetWidgetMap().getBounds().getNorthEast();
    GetWidgetMap().panDirection(-1.5,  +1.5);
}

function GetWidgetMap() {
     if($get("widget1$GmapControlProperty") != null) {
        return  widget1$GmapControlProperty;
     }
     if($get("widget1$GmapControlAgency") != null) {
        return  widget1$GmapControlAgency;
     }
     if($get("widget1$WidgetSearch") != null) {
        return  widget1$WidgetSearch;
     }
}

//Center to the selected marker
function CenterToMarker(markerId){
    var centerPoint=new GLatLng(gmarkers[markerId].getPoint().lat(),gmarkers[markerId].getPoint().lng());
    eval(C_MAP).setCenter(centerPoint);
}

//Function use to select a marker when a property is selected inside the list
function SelectProperty(markerPropertyId){
    //Set hidden field
    $get(C_CONTROL+"HiddenFieldPropertyId").value = markerPropertyId;
    //reset prev selected property
    prevSelectedMarkerId = 0;
    var hiddenField = $get("HiddenFieldSelectedModule");
    if (hiddenField) {
        if(hiddenField.value == "mainmap") {
            for (i = 0; i < gmarkersProperties.length; i++) {
                if (gmarkersProperties[i].property_id == markerPropertyId) {
                    GetPropertyInfos(gmarkersProperties[i], "info");
                    //Remember selected marker
                    prevSelectedMarkerId = markerPropertyId;
                }
            }
        }
        if(hiddenField.value == "description") {
            //$get("Property_modules1_Property_fastdetails1__HiddenFieldPropertyIdListener").value = markerPropertyId;
            $get("Property_modules1_Property_fastdetails1__HiddenFieldPropertyId").value = markerPropertyId;
            AddHistory("description");
            __doPostBack("Menu1$LinkButtonProperty",'');
            //__doPostBack("Property_modules1_Property_fastdetails1__HiddenFieldPropertyIdListener",'');
        }
        if(hiddenField.value == "photos") {
            AddHistory("photos");
            switchNavigationUi("photos");
            __doPostBack("Submenu1$LinkButtonPhotos",'');
        }
        if(hiddenField.value == "nearby") {
            AddHistory("nearby");
            switchNavigationUi("nearby");
            GetNearBynfos("Property_nearby1$GmapControl2");
        }
    }
    else {
    }
}

//Object association between marker id and property id*/
function gmarkersObject(id, propertyId, myMarker, ew){
    this.id=id;
    this.property_id=propertyId;
    this.marker=myMarker;
    this.ew=ew;
}

//Move Map to Selected Town
function CenterToTown(town_id){
    BmyKey.WebServices.Properties.GetCoordinates(town_id,'','','',OnSucceededCenterToTown);
}
function OnSucceededCenterToTown(result){
    if(result.length > 0){
        eval(C_MAP).setCenter(new GLatLng(result[0], result[1]), CenterToTown);
    }
}

//Move Map to Selected Region
function CenterToRegion(region_id){
    BmyKey.WebServices.Properties.GetCoordinates('','',region_id,'',OnSucceededCenterToRegion);
}
function OnSucceededCenterToRegion(result){
    if(result.length > 0){
        eval(C_MAP).setCenter(new GLatLng(result[0], result[1]), centerRegion);
    }
}

//Move Map to Selected Departement
function CenterToDepartement(departement_id){
    BmyKey.WebServices.Properties.GetCoordinates('','','',departement_id,OnSucceededCenterToDepartement);
}
function OnSucceededCenterToDepartement(result){
    if(result.length > 0){
        eval(C_MAP).setCenter(new GLatLng(result[0], result[1]), centerDepartment);
    }
}

function ResetToken() {
    xmlTokenAvailable = true;
}

function LoadMarkersFromXmlForCountry(searchValue){
    var request = GXmlHttp.create();
    request.open("GET", C_XML + "?" + searchValue, true);
    request.onreadystatechange = function() {
        if (request.readyState == 4) {
            var xmlDoc = request.responseXML;
            var markers = xmlDoc.documentElement.getElementsByTagName("marker");
            for (var i = 0; i < markers.length; i++) {
                var lat = parseFloat(markers[i].getAttribute("lat"));
                var lng = parseFloat(markers[i].getAttribute("lng"));
                var point = new GLatLng(lat,lng);
                var id = markers[i].getAttribute("region_id");
                var marker = createMarker(point,id,"info");
                eval(C_MAP).addOverlay(marker);
            }
        }
    }
    request.send(null);
}

function getCurrentMap() {
    var map = null;
    if($get(C_MAP) != null)
    {
        map = eval(C_MAP);
    }
    if($get(C_MAP2) != null)
    {
        map = eval(C_MAP2);
    }
    if($get(C_MAPCREATE) != null)
    {
        map = eval(C_MAPCREATE);
    }
    if($get(C_MAPCREATE) != null)
    {
        map = eval(C_MAPCREATE);
    }
    if($get(C_MAPAGENCY) != null)
    {
        map = eval(C_MAPAGENCY);
    }
    if($get(C_WIDGET) != null)
    {
        map = eval(C_WIDGET);
    }
    if($get(C_WIDGET_SEARCH) != null)
    {
        map = eval(C_WIDGET_SEARCH);
    }
    return map;
}

function mapBounds() {
    var map = getCurrentMap();
    if(map != null) {
        var bounds = map.getBounds();
        min_x = bounds.getSouthWest()
        min_x = min_x.lng()
        min_y = bounds.getSouthWest()
        min_y = min_y.lat()
        max_x = bounds.getNorthEast()
        max_x = max_x.lng()
        max_y = bounds.getNorthEast()
        max_y = max_y.lat()
        
        return {minX: min_x, maxX: max_x, minY: min_y, maxY: max_y}
    }
}

function updateMapCenter() {
    var map = getCurrentMap();
    if(map != null) {
	    var bounds = mapBounds();
	    var width = bounds.maxX - bounds.minX;
	    var height = bounds.maxY - bounds.minY;
	    map.queryCenter=map.getCenter();
	    map.maxY = bounds.maxY+height*.4;
	    map.maxX = bounds.maxX+width*.4;
	    map.minY = bounds.minY-height*.4;
	    map.minX = bounds.minX-width*.4;
	}
}

function generateSearchFilterQueryString()  {
    var hd1 = $get(C_CONTROL+"HiddenFieldRoomsMin");
    var hd2 = $get(C_CONTROL+"HiddenFieldRoomsMax");
    var hd3 = $get(C_CONTROL+"HiddenFieldBedRoomsMin");
    var hd4 = $get(C_CONTROL+"HiddenFieldBedRoomsMax");
    var hd5 = $get(C_CONTROL+"HiddenFieldSquareInsideMin");
    var hd6 = $get(C_CONTROL+"HiddenFieldSquareInsideMax");
    var hd8 = $get(C_CONTROL+"HiddenFieldPriceMin");
    var hd9 = $get(C_CONTROL+"HiddenFieldPriceMax");
    var hd10 = $get(C_CONTROL+"HiddenFieldPropertyTypeCode");
    var hd11 = $get(C_CONTROL+"HiddenFieldIsForRent");
    var hd12 = $get(C_CONTROL+"HiddenFieldSortExpression");
    var hd13 = $get(C_CONTROL+"HiddenFieldSquareOutsideMin");
    var hd14 = $get(C_CONTROL+"HiddenFieldSquareOutsideMax");
    
    var isneuf = false;
    if($get("hfIsNeuf") != null) {
        isneuf = true;
    }
    if($get("Agency1__HfIsNeuf") != null) {        
        if($get("Agency1__HfIsNeuf").value == "True") {      
            isneuf = true;
        }
    }
    if($get("Property_fulldetails1__HFIsNeuf") != null) {
        if($get("Property_fulldetails1__HFIsNeuf").value == "true") {
            isneuf = true;
        }
    }
    
    var type;
    var stringVar = new String();
    
    if(hd11.value != "")
    { 
        stringVar += String.format("&isforrent={0}",hd11.value);
    }
    if(hd1.value != "")
    {
        stringVar += String.format("&roomsmin={0}",hd1.value);
    }
    if(hd2.value != "")
    {
        stringVar += String.format("&roomsmax={0}",hd2.value);
    }
    if(hd3.value != "")
    {
        stringVar += String.format("&bedroomsmin={0}",hd3.value);
    }
    if(hd4.value != "")
    {
        stringVar += String.format("&bedroomsmax={0}",hd4.value);
    }
    if(hd8.value != "" && hd9.value != "")
    {
        stringVar += String.format("&price={0}-{1}",hd8.value,hd9.value);
    }
    if(hd5.value != "" && hd6.value != "")
    {
        stringVar += String.format("&square={0}-{1}",hd5.value,hd6.value);
    }
    if (hd13 != null && hd14 != null) {
        if(hd13.value != "" && hd14.value != "")
        {
            stringVar += String.format("&squareoutside={0}-{1}",hd13.value,hd14.value);
        }
    }
    if(hd10.value != "")
    {
        stringVar += String.format("&propertytype={0}",hd10.value);
    }
    if(hd12.value != "")
    {
        stringVar += String.format("&sortexpression={0}",hd12.value);
    }
    
    if(isneuf)
    {
        stringVar += "&isneuf=true";
    }
    else
    {
        stringVar += "&isneuf=false";
    }
    
    return stringVar;
}

function zoomEnd() {
    var map = getCurrentMap();
    var zoom = map.getZoom();
	var bounds = mapBounds();
    var coordinatesCount = 100;
    updateMap(bounds,"move", coordinatesCount, zoom, false);
}

function filterEnd() {
    var map = getCurrentMap();
    var zoom = map.getZoom();
	var bounds = mapBounds();
    updateMap(bounds, "nopostback", 100, zoom, false);
}

function dragEnd() {
    var map = getCurrentMap();
    var zoom = map.getZoom();
	var bounds = mapBounds();
    if(!(bounds.minX>=map.minX && bounds.maxX<=map.maxX && bounds.minY>=map.minY && bounds.maxY<=map.maxY)) {
        updateMap(bounds,"move", 100, zoom, true);
	}
}

function updateMap(bounds, type, count, maxZoomLevel, refresh) {
    if($get(C_CONTROL+"HiddenFieldGenericWidget") == null) {
        ResetMarkers(false);
    } else {
        ResetMarkers(true);
    }
    if(type == "move")
    {
        var searchValue;
        searchValue = "coordinatescount=" + count;
        searchValue += "&coordinates=" + bounds.minX + ";" + bounds.minY + ";" + bounds.maxX + ";"+bounds.maxY;
        searchValue += generateSearchFilterQueryString();
        if(refresh) {
            firstMarkerLoad = true;
            }
        if($get(C_CONTROL+"HiddenFieldGenericWidget") == null) {
            LoadMarkersFromXml(C_XML,searchValue, maxZoomLevel, "false", null);
        }
        else {
            LoadMarkersFromXml(C_XML,searchValue, maxZoomLevel, "false", null, "window");
        }
        updateListCoordinates(bounds.minX, bounds.maxX, bounds.minY, bounds.maxY);
    }
    if(type == "nopostback")
    {
        var searchValue;
        searchValue = "coordinatescount=" + count;
        searchValue += "&coordinates=" + bounds.minX + ";" + bounds.minY + ";" + bounds.maxX + ";"+bounds.maxY;
        searchValue += generateSearchFilterQueryString();
        if(refresh) {
            firstMarkerLoad = true;
        }
        LoadMarkersFromXml(C_XML,searchValue, maxZoomLevel, "false", null, "window");
    }
    if(type == "country")
    {
        searchValue = "searchtype=5&";
        searchValue += "search=" + search;
        LoadMarkersFromXmlForCountry(searchValue);
    }
}

function updateListCoordinates(minX, maxX, minY, maxY) {
    $get("hfminX").value = minX
    $get("hfmaxX").value = maxX
    $get("hfminY").value = minY
    $get("hfmaxY").value = maxY
    
    //Swith to coordinate search mode
    $get("HiddenFieldSearchType").value = 'coordinatesbox';
    //Reset selected page to page 1
    $get("HiddenFieldPageIndex").value = 0;
    
    if($get(C_CONTROL+"HiddenFieldGenericWidget") == null) {
        __doPostBack("hfmaxX",'');
    }
}

function imageSwap(imageToChange, newImageUrl, imageFolder) {
    var url = C_PATHURL + imageFolder + newImageUrl;
    imageToChange.src = url;
}

function imageNext(imageToChange) {
    
    var url = C_PATHURL + imageFolder + newImageUrl;
    imageToChange.src = url;
}
function imagePrev(imageToChange) {
    var url = C_PATHURL + imageFolder + newImageUrl;
    imageToChange.src = url;
}

function propertyNearByUpdateMap(map, longitude, latitude, zoomLevel, propertyId) {
    eval(map).clearOverlays();
    eval(map).checkResize();
    var point = new GLatLng(latitude,longitude);
    var marker = createMarker(point,propertyId,"info", eval(map));
    eval(map).addOverlay(marker);
    eval(map).setCenter(point, zoomLevel);
}

//Connect to webservices to obtain property Nearby
function GetNearBynfos(mapSourceId){
    var propertyId = $get("HiddenFieldPropertyId").value;
    var isNeuf = false;
    if($get("hfIsNeuf") != null) {
        if($get("hfIsNeuf").value == "true") {
            isNeuf = true;
        }
    }
    BmyKey.WebServices.Properties.GetNearByObject(propertyId, mapSourceId, isNeuf, OnSucceededGetNearBynfos);
}

function OnSucceededGetNearBynfos(result){
    var latitude = result.latitude;
    var longitude = result.longitude;
    var propertyId = result.propertyId;
    var zoomLevel = result.zoomLevel;
    propertyNearByUpdateMap(result.mapSourceId, result.longitude, result.latitude, result.zoomLevel, result.propertyId);
}

//Connect to webservices to load suggestion template METHODE TEMPLATE SCOTTGU + WEBSERVICES
//function displaySuggestion(result) {                           
//    $get("wsModules").innerHTML = result;
//}

function AddHistory(type) {
    switchNavigationUi(type);
    
    $get("HiddenFieldSelectedModule").value=type;

    if((type != "description") && (type != "photos") && (type != "nearby") && (type != "same")) {
        ASPCode.net.History.setLocation(type);
        return false;
    }
    else
    {
        if($get("HiddenFieldPropertyId").value != "") {
            //History Action
            $get("HiddenFieldPropertyIdPrev").value=$get("HiddenFieldPropertyId").value;
            ASPCode.net.History.setLocation(type + ";" + $get("HiddenFieldPropertyId").value);
            return false;
        }
        else {
            return false;
        }
    }
}

function StartSlideShow() {
    var resultSlide;
    countArticle = 0;
    BmyKey.WebServices.ImagesSlide.GetPropertyPictures($get('Property_slideshow1_HiddenFieldPropertyId').value, $get('Property_slideshow1_HiddenFieldSelectedImage').value , OnSucceededGetPropertyPictures);
    function OnSucceededGetPropertyPictures(result){
        resultSlide = result;
        var slideshow = new showcaseSlideShow($('mySlideshow'), resultSlide);
    }
}