﻿
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function dmxAdvLayerPopup(sWinId, onCloseFunc, sTitle,sURL,sPopupName,sContent,sClass,nPositionLeft,nPositionRight,nWidth,nHeight,nAutoCloseTime,bDragable,bResizable,bOverlay,nOverlayOpacity,sIncomingEffect,sIncomingEffectEasing,nIncomingEffectDuration,bFadeIn,sOutgoingEffect,sOutgoingEffectEasing,nOutgoingEffectDuration,bFadeOut,sSlideEffect,nEffectTime,nSlideTime,bClosable,bWireframe,bgContentColor) { // v1.05
  var aURL, aSlides = sURL.split('|');
  if (aSlides && aSlides.length > 1) {
    aURL = [];
    for (var si=0;si<aSlides.length;si++) {
      var cf=aSlides[si],nW='',nH='',nS='';
      if (cf.substr(cf.length-1,1)==']') {
        var bd=cf.lastIndexOf('[');
        if(bd>0){
          var di=cf.substring(bd+1,cf.length-1);
          var da=di.split('x');
          nW=da[0];nH=da[1];
          if (da.length==3) nS=da[2];
          cf=cf.substring(0,bd)
        }   
      }      
      aURL[si] = new Object();
      aURL[si].src = cf;
      aURL[si].nWidth = (nW!=''?nW:nWidth);
      aURL[si].nHeight = (nH!=''?nH:nHeight);
      aURL[si].nDelay = (nS!=''?nS:nSlideTime);
    }  
  } else aURL = sURL;
  if (!cDMXPopupWindow) {
  	alert('The Advanced Layer Popup script is missing on your website!\nPlease upload the file ScriptLibrary/advLayerPopup.js to your live server.');
  } else {
    if (sClass == 'OS_Look') sClass = (navigator.userAgent.toLowerCase().indexOf('mac')!=-1?'dmxOSX':'dmxXP');  
    cDMXPopupWindow.buildWindow({sWinId: sWinId, onCloseFunc: onCloseFunc, sTitle: sTitle, sURL: aURL, sPopupName: sPopupName, sContent: sContent, sClass: sClass, aPosition: [nPositionLeft,nPositionRight], aSize: [nWidth,nHeight], nCloseDelay: nAutoCloseTime, bDragable: bDragable, bResizable: bResizable, bOverlay: bOverlay, nOverlayOpacity: nOverlayOpacity, sStartPosition: sIncomingEffect, sStartShowEffect: sIncomingEffectEasing, nIncomingEffectDuration: nIncomingEffectDuration, bFadeIn: bFadeIn, sEndPosition: sOutgoingEffect, sEndShowEffect: sOutgoingEffectEasing, nOutgoingEffectDuration: nOutgoingEffectDuration, bFadeOut: bFadeOut, sSlideEffect: sSlideEffect, nEffectTime: nEffectTime, nSlideTime: nSlideTime, bClosable: bClosable, bWireframe: bWireframe, sContentBgColor: bgContentColor });
  }  
  document.MM_returnValue = false;
  return 'dmxPopup'+cDMX.util.toCamelCase(sTitle);
}

function ValidatorValidate(val, validationGroup, event) {
    try{
        val.isvalid = true;
        if(typeof(val.enabled) == 'string') {
            val.enabled = (val.enabled.toUpperCase() == 'true');
        }
        if ((typeof(val.enabled) == "undefined" || val.enabled != false) && IsValidationGroupMatch(val, validationGroup)) {
            
                if (typeof(val.evaluationfunction) == "string") {
                    eval("val.evaluationfunction = " + val.evaluationfunction + ";");
                }    
                if (typeof(val.evaluationfunction) == "function") {
                    val.isvalid = val.evaluationfunction(val);
                    if (!val.isvalid && Page_InvalidControlToBeFocused == null && typeof(val.focusOnError) == "string" && val.focusOnError == "t") {
                        ValidatorSetFocus(val, event);
                    }
                }
        }
        ValidatorUpdateDisplay(val);
    } catch(e) { alert(e);}
}

Type.registerNamespace("ScriptLibrary");

ScriptLibrary.RentalPortal = function() 
{
    this._lnkRefreshId = '';
}
ScriptLibrary.RentalPortal.prototype.validatePasswordFormat = function(src, args)
{   
    args.IsValid = true;
    if(args && typeof(args.Value) == 'string')
    {
        if(args.Value.length < 6) 
        {
            args.IsValid = false;
        }
    }
}

ScriptLibrary.RentalPortal.prototype.validateState = function(src, args)
{   
    args.IsValid = true;
    if(args && typeof(args.Value) == 'string')
    {
        if(args.Value.length < 6) 
        {
            args.IsValid = false;
        }
    }
}

ScriptLibrary.RentalPortal.prototype.testtest = function(validationGroup)
{
    var i;
    for (i = 0; i < Page_Validators.length; i++) {
        alert(i + ':\n' + Page_Validators[i].evaluationfunction);
    }
    return false;
}

ScriptLibrary.RentalPortal.prototype.preventKeyEnter = function (e)
{
    var evt= (e) ? e:(window.event) ? window.event : null; 
    if(evt)
    { 
        var key=(evt.charCode)? evt.charCode: ((evt.keyCode)? evt.keyCode:((evt.which)?evt.which:0)); 
        if(key == '13') 
        {
            return false;
        }
    }
    return true;
}
ScriptLibrary.RentalPortal.prototype.preventKeySpace = function (e)
{
    var evt= (e) ? e:(window.event) ? window.event : null; 
    if(evt)
    { 
        var key=(evt.charCode)? evt.charCode: ((evt.keyCode)? evt.keyCode:((evt.which)?evt.which:0)); 
        if(key == '32') 
        {
            return false;
        }
    }
    return true;
}
ScriptLibrary.RentalPortal.scrollUp = function(div)
{
    var top = document.getElementById(div).scrollTop;
    top -= 550;
    top = top < 0 ? 0 : top;
    document.getElementById(div).scrollTop = top;
    
}
ScriptLibrary.RentalPortal.scrollDown = function(div)
{
    var top = document.getElementById(div).scrollTop;
    top += 550;
    document.getElementById(div).scrollTop = top;
}

ScriptLibrary.RentalPortal.prototype.openPopupWindow = function(id, url, title, w, h, onclose)
{
    LswModal.Open(url, w, h, onclose, undefined, undefined, undefined, title);
}

ScriptLibrary.RentalPortal.prototype.openPopupWindow2 = function(id, url, title, w, h, onclose)
{
    LswModal.Open(url, w, h, onclose, undefined, undefined, undefined, title);
}

ScriptLibrary.RentalPortal.closePopupWindow = function(id)
{
    window.parent.LswModal.Close();
}

// EditContactInfo Dialog
ScriptLibrary.RentalPortal.prototype.openEditContactInfo = function()
{
    this._popupContact_returnValue = '';
    this.openPopupWindow2('EditContactInfo', '/portal/DialogContactInfo.aspx', 'My Account - Contact Information', 600, 325, this.onPopupContactClose);
}
ScriptLibrary.RentalPortal.prototype.onPopupContactClose = function()
{
    if(typeof(RentalPortal._popupContact_returnValue) == 'string')
    {
        if(RentalPortal._popupContact_returnValue == 'ok')
        {
            if(typeof(RentalPortal._lnkRefreshId) == 'string')
            {
                window.setTimeout('__doPostBack(\'' + RentalPortal._lnkRefreshId + '\', \'EditContactInfo\');', 10);
            }
        }
    }
}
ScriptLibrary.RentalPortal.closePopupContact = function(returnValue)
{
    window.parent.RentalPortal._popupContact_returnValue = returnValue;
    window.parent.LswModal.Close();
    //window.parent.cDMXPopupWindow.closeWindow('EditContactInfo');
    
}

// UserLogin Dialog
ScriptLibrary.RentalPortal.prototype.openUserLogin = function(returnUrl)
{
    this._userlogin_returnValue = '';
    this.openPopupWindow2('DialogLogin', '/portal/DialogLogin.aspx?ReturnUrl=' + returnUrl, 'Big Bridge Travel Login', 600, 400, this.onUserLoginClose);
}
ScriptLibrary.RentalPortal.prototype.onUserLoginClose = function()
{
    if(typeof(RentalPortal._userlogin_returnValue) == 'string')
    {
        if(RentalPortal._userlogin_returnValue != '')
        {
            if(RentalPortal._userlogin_returnValue == 'refresh') {
                window.location.href = window.location.href;
            }
            else {
                window.location.href = RentalPortal._userlogin_returnValue;
            }
        }
    }
}
ScriptLibrary.RentalPortal.closeUserLogin = function(returnValue)
{
    window.parent.RentalPortal._userlogin_returnValue = returnValue;
    window.setTimeout('window.parent.LswModal.Close();', 0);
}

// ProvideGuestBook Dialog
ScriptLibrary.RentalPortal.prototype.openProvideGuestBook = function(url, title, refreshId)
{
    this._popupProvideGuestBook_refreshId = refreshId;
    this.openPopupWindow2('ResDlgPage', url, title, 500, 480, this.onProvideGuestBookClose);
}

ScriptLibrary.RentalPortal.prototype.onProvideGuestBookClose = function(returnValue)
{
    if(typeof(returnValue) == 'string')
    {
        if(returnValue == 'ok')
        {
            if(typeof(RentalPortal._popupProvideGuestBook_refreshId) == 'string')
            {
                window.setTimeout('__doPostBack(\'' + RentalPortal._popupProvideGuestBook_refreshId + '\', \'ProvideGuestBook\');', 10);
            }
        }
    }
}

ScriptLibrary.RentalPortal.closeProvideGuestBook = function(returnValue)
{
    window.parent.LswModal.Close(returnValue);
}

// ResDlgPage
ScriptLibrary.RentalPortal.closeResDlgPage = function(returnValue)
{
    window.parent.LswModal.Close(returnValue);
}

ScriptLibrary.RentalPortal.registerClass('ScriptLibrary.RentalPortal', null);
RentalPortal = new ScriptLibrary.RentalPortal();

ScriptLibrary.PropertyMap = function(id, name, point, br) 
{
    this._id = id;
    this._name = name;
    this._point = point;
    this._br = br;
}
ScriptLibrary.PropertyMap.registerClass('ScriptLibrary.PropertyMap', null);

ScriptLibrary.RegionMap = function(id, name, point, fullpath, unitcount, level, rstartzoom, rendzoom) {
    this._id = id;
    this._name = name;
    this._point = point;
    this._fullpath = fullpath;
    this._unitcount = unitcount;
    this._level = level;
    this._rstartzoom = rstartzoom;
    this._rendzoom = rendzoom;
}
ScriptLibrary.RegionMap.registerClass('ScriptLibrary.RegionMap', null);

ScriptLibrary.GroundOverlayMap = function(id, url, sw, ne) 
{
    this._id = id;
    this._url = url;
    this._sw = sw;
    this._ne = ne;
}
ScriptLibrary.GroundOverlayMap.registerClass('ScriptLibrary.GroundOverlayMap', null);

ScriptLibrary.Address = function(country, state, city, street) 
{
    this._country = country;
    this._state = state;;
    this._city = city;;
    this._street = street;
}
ScriptLibrary.Address.registerClass('ScriptLibrary.Address', null);

function clearGoogleMaps()
{
    if(typeof(PropertiesMap) != 'undefined')
    {
        if(PropertiesMap._mgr){
            PropertiesMap._mgr.clearMarkers();
        }
        if(PropertiesMap._map) {
            PropertiesMap._map.clearOverlays();
        }
    }
}

function clearGoogleMapRegions() {
    if (typeof (RegionsMap) != 'undefined') {
        if (RegionsMap._mgr) {
            RegionsMap._mgr.clearMarkers();
        }
        if (RegionsMap._map) {
            RegionsMap._map.clearOverlays();
        }
    }
}

ScriptLibrary.GoogleMaps = function() {
    this._map = null;
    this._mgr = null;
    this._propertyWindows = new Hashtable();
    this._rmarkers = new Array();
    this._markers = new Hashtable();
    this._propertyMaps = new Array();
    this._regionMaps = new Array();
    this._overlayMaps = new Array();
    this._isRunningFindAddress = false;
    this._point = null;
    this._showTooltip = null;
    this._zoomLevel = 14;
   
    this._address = null;
    this._findAddressCount = 0;
    this._clickedMarker = null;
}

ScriptLibrary.GoogleMaps.prototype.GMap_initialize = function(map_canvas, c, zoomLevel, address) {
    if (GBrowserIsCompatible()) {

        this._map = new GMap2(document.getElementById(map_canvas));
        this._map.addControl(new GLargeMapControl());
        this._map.addControl(new GMapTypeControl());
        this.setupGroundOverlayMap();
        this._zoomLevel = zoomLevel;
        this.setAddress(address);

        GEvent.addListener(this._map, "moveend", this.moveEnd);

        if (typeof (c) == 'undefined' || c == null) {
            this.findNextAddress();
        }
        else {
            this.moveTo(c);
        }
    }
}

ScriptLibrary.GoogleMaps.prototype.GMapRegion_initialize = function(map_canvas, c, zoomLevel, address, showTooltip) {
    if (GBrowserIsCompatible()) {
        this._map = new GMap2(document.getElementById(map_canvas));
        this._map.addControl(new GLargeMapControl3D());
        this._zoomLevel = zoomLevel;
        this._showTooltip = showTooltip;

        this.moveRegionTo(c);
    }
}

ScriptLibrary.GoogleMaps.prototype.moveTo = function(c)
{
    if(typeof(c) != 'undefined' && c != null) {
        this._point = c;
        this._map.setCenter(this._point, this._zoomLevel);    
        this.setupPropertyMarkers();
    }
}

ScriptLibrary.GoogleMaps.prototype.moveRegionTo = function(c) {
    if (typeof (c) != 'undefined' && c != null) {
        this._point = c;
        this._map.setCenter(this._point, this._zoomLevel);
        this.setupRegionMarkers();
    }
}

ScriptLibrary.GoogleMaps.prototype.moveEnd = function()
{
    if(PropertiesMap._clickedMarker != null)
    {
        try{
            window.setTimeout('PropertiesMap.showMarkerWindowInfo(\'' + PropertiesMap._clickedMarker.id + '\');', 100);
            //PropertiesMap.showMarkerWindowInfo(PropertiesMap._clickedMarker.id);
        } catch(e) {}
    }
    PropertiesMap._clickedMarker = null;
}

ScriptLibrary.GoogleMaps.prototype.setupGroundOverlayMap = function ()
{
    this._map.clearOverlays()
    for(var i=0; i<this._overlayMaps.length; i++) 
    {   try{
        var m = this._overlayMaps[i];
        var boundaries = new GLatLngBounds(m._sw, m._ne);
        if(m != null && boundaries!=null){
//        setTimeout(250);
        var map = new GGroundOverlay(m._url, boundaries);  
          
            this._map.addOverlay(map);  
            }  
        } catch(e) {}
    }
}

ScriptLibrary.GoogleMaps.prototype.addPropertyMap = function (map)
{
    this._propertyMaps.push(map);
}

ScriptLibrary.GoogleMaps.prototype.addRegionMap = function(map) {
    this._regionMaps.push(map);
}

ScriptLibrary.GoogleMaps.prototype.addOverlayMap = function (map)
{
    this._overlayMaps.push(map);
}

ScriptLibrary.GoogleMaps.prototype.setupPropertyMarkers = function() {
    var mgrOptions = { maxZoom: 10 };
    this._mgr = new MarkerManager(this._map, mgrOptions);
    for (var i = 0; i < this._propertyMaps.length; i++) {
        var p = this._propertyMaps[i];
        var icon = new GIcon();

        var image = '/portal/images/markerMultiUnit.gif';
        if (p._br == 1)
            image = '/portal/images/Marker1BR.gif';
        else if (p._br == 2)
            image = '/portal/images/Marker2BR.gif';
        else if (p._br == 3)
            image = '/portal/images/Marker3BR.gif';
        else if (p._br > 3)
            image = '/portal/images/Marker4BR.gif';

        icon.image = image;
        icon.shadow = "";
        icon.iconSize = new GSize(10, 12);
        icon.shadowSize = new GSize(10, 12);
        icon.iconAnchor = new GPoint(10, 12);
        icon.infoWindowAnchor = new GPoint(6, 1);
        icon.infoShadowAnchor = new GPoint(12, 12);

        var opts = new Object();
        opts.title = p._name;
        opts.icon = icon;
        var marker = this.createMarker(p._id, p._point, opts);
        marker.disableDragging();
        this._mgr.addMarker(marker, 1);
    }
    this._mgr.refresh();
}

ScriptLibrary.GoogleMaps.prototype.createMarker = function (id, point, opts) 
{
    var marker = new GMarker(point, opts);
    marker.id = id;
    var html = document.getElementById(id);
    this._propertyWindows.put(marker.id, html);
    
    GEvent.addListener(marker, "click", function() {
        //var html = document.getElementById(id);
        var html = PropertiesMap._propertyWindows.get(marker.id);
        marker.openInfoWindowHtml(html);
    });
    
    this._markers.put(id, marker);
    
    return marker;
}

ScriptLibrary.GoogleMaps.prototype.markerClick = function(id)
{
    marker = this._markers.get(id);
    if(marker != null && typeof(marker) != 'undefined')
    {    
        this._clickedMarker = marker;
        this._map.setCenter(marker.getLatLng(), this._zoomLevel);    
    }
}

ScriptLibrary.GoogleMaps.prototype.showMarkerWindowInfo = function(id)
{
    marker = this._markers.get(id);
    var html = this._propertyWindows.get(id);
    try{
        marker.openInfoWindowHtml(html);
    } catch(e) {}
}

ScriptLibrary.GoogleMaps.prototype.setAddress = function(addr)
{
    this._address = addr;
}

ScriptLibrary.GoogleMaps.prototype.findNextAddress = function()
{
    var s = '';
    var street = this._address._street;
    var city = this._address._city;
    var state = this._address._state;
    var country = this._address._country;
    switch(this._findAddressCount)
    {
        case 0:
            s = (this.sne(street) ? street + ', ' : '') + (this.sne(city) ? city + ', ' : '') + (this.sne(state) ? state + ', ' : '') + (this.sne(country) ? country : 'CA');                        
            break;
        case 1:
            s = (this.sne(city) ? city + ', ' : '') + (this.sne(state) ? state + ', ' : '') + (this.sne(country) ? country : 'CA');
            break;
        case 2:
            s = (this.sne(country) ? country : 'US'); 
            break;
        default:
            break;
    }
    if(this._findAddressCount <= 2)
    {
        this._findAddressCount ++;
        this.getPointByAddress(s);
    }
}

ScriptLibrary.GoogleMaps.prototype.getPointByAddress = function(address)
{
    var geocoder = new GClientGeocoder();
    if(geocoder)
    {
        geocoder.getLatLng(address,
            function(point) {
                if (!point) {  
                    PropertiesMap.findNextAddress();                
                } else {
                    PropertiesMap.moveTo(point);
                }
            });    
    }
}

ScriptLibrary.GoogleMaps.prototype.sne = function(s) 
{
    if(typeof(s) == 'undefined' || s == null)
    {
        return false;
    }
    if((s + '') == '')
    {
        return false;
    }
    return true;
}

ScriptLibrary.GoogleMaps.registerClass('ScriptLibrary.GoogleMaps', null);

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

ScriptLibrary.GoogleMaps.prototype.setupRegionMarkers = function() {
    this._mgr = new MarkerManager(this._map);
    this._map.enableScrollWheelZoom();

    for (var i = 0; i < this._regionMaps.length; i++) {
        var r = this._regionMaps[i];
        var icon = new GIcon();

        var image = ''; 
        if (r._level == 1)
            image = '/portal/images/gmarker.png';
        else if(r._level == 2)
            image = '/portal/images/smarker.png';
        else
            image = '/portal/images/omarker.png';

        icon.image = image;
        icon.shadow = "";
        icon.iconSize = new GSize(12, 20);
        icon.shadowSize = new GSize(22, 20);
        icon.iconAnchor = new GPoint(6, 20);
        icon.infoWindowAnchor = new GPoint(5, 1);
        icon.infoShadowAnchor = new GPoint(10, 18);

        var opts = new Object();
        opts.title = r._name;
        opts.icon = icon;
        var marker = this.createRegionMarker(r._id, r._point, opts, r._fullpath);
        var t = new Tooltip(marker, r._name, r._unitcount, 4, this._showTooltip);
        marker.tooltip = t;

        this._map.addOverlay(t);

        marker.disableDragging();

        if (r._rendzoom > 0)
            this._mgr.addMarker(marker, r._rstartzoom, r._rendzoom);
        else
            this._mgr.addMarker(marker, r._rstartzoom);
    }
    this._mgr.refresh();
}

ScriptLibrary.GoogleMaps.prototype.createRegionMarker = function(id, point, opts, fullpath) {
    var marker = new GMarker(point, opts);
    marker.id = id;

    GEvent.addListener(marker, 'mouseover', function() {
        this.tooltip.show();
    });

    GEvent.addListener(marker, 'mouseout', function() {
        this.tooltip.hide();
    });

    GEvent.addListener(marker, "click", function() {
        window.location.href = "/Portal/rentals/" + fullpath;
    });

    this._markers.put(id, marker);

    return marker;
}