﻿// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 7;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Revision of Flash required
var requiredRevision = 0;
// the version of javascript supported
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
var jsVersion = 1.1;

// -----------------------------------------------------------------------------
function openWin(url, w, h) {
    var winprop = "width=" + w + ",height=" + h;
    openwin = window.open(url, '', winprop);
}
function createFlashControl(DivID, movie, width, height) {
    var d = document.getElementById(DivID);
    var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
    if (hasRightVersion)
        d.innerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + width + '" height="' + height + '" id="Shell" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + movie + '" /><param name="quality" value="high"/><param name="wmode" value="transparent"><embed src="' + movie + '" quality="high" width="' + width + '" height="' + height + '" name="Shell" align="middle" wmode="transparent" ScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"/></object>';
    else
        d.innerHTML = 'This content requires the Macromedia Flash Player.<a href="http://www.macromedia.com/go/getflash/">Get Flash</a>';
}
function createFlashControl2(DivID, movie, width, height, base) {
    var d = document.getElementById(DivID);
    var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
    if (hasRightVersion)
        d.innerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ' + 'width="' + width + '" height="' + height + '" id="Shell" align="middle"><PARAM NAME="BASE" VALUE="' + base + '" /><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + movie + '" /><param name="quality" value="high"/><param name="wmode" value="transparent"><embed src="' + movie + '" quality="high" width="' + width + '" height="' + height + '" name="Shell" align="middle" wmode="transparent" base="' + base + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"/></object>';
    else
        d.innerHTML = 'This content requires the Macromedia Flash Player.<a href="http://www.macromedia.com/go/getflash/">Get Flash</a>';
}
function createQuicktimeControl(DivID, movie, width, height) {
    var d = document.getElementById(DivID);
    d.innerHTML = '<object CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width=' + width + ' height=' + height + 'CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab"><param name="src" value="' + movie + '><param name="autoplay" value="true"><param name="loop" value="false"><param name="controller" value="true"><embed src="' + movie + ' width="' + width + '" height="' + height + ' autoplay="true" loop="false" controller="true" pluginspage="http://www.apple.com/quicktime/"></embed></object>';
}
function createMediaPlayer(DivID, movie, width, height) {
    var d = document.getElementById(DivID);
    d.InnerHTML = '<object width=' + width + ' height=' + height + ' classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" id="mediaplayer1" viewastext><param name="Filename" value=' + movie + '><param name="AutoStart" value="True"><param name="ShowControls" value="True"><param name="ShowStatusBar" value="True"><param name="ShowDisplay" value="False"><param name="AutoRewind" value="True"><embed type="application/x-mplayer2" width=' + width + ' height=' + height + ' pluginspage="http://www.microsoft.com/windows/windowsmedia/download/default.asp" src=' + movie + ' autostart="True" filename=' + movie + ' showcontrols="True" showstatusbar="True" showdisplay="False" autorewind="True"></embed></object>';
}
function playSound(soundobj, file) {
    var span = document.getElementById(soundobj);
    span.innerHTML = '<embed src="' + file + '" autostart="true" width="100" height="20" name="player" />';
}
function openWindow(url, height, width) {
    var theURL = url;
    var window_top = (screen.height - height) / 2;
    var window_left = (screen.width - width) / 2;
    var newfeatures = 'scrollbars=yes,resizable=yes,toolbar=no,location=no,status=no,menubar=no, width=' + width + ',height=' + height + ',top=' + window_top + ',left=' + window_left;
    var newWindow = window.open(theURL, 'Popup', newfeatures);
    newWindow.focus();
}
function openNewWindow(url, height, width) {
    var theURL = url;
    var window_top = (screen.height - height) / 2;
    var window_left = (screen.width - width) / 2;
    var newfeatures = 'scrollbars=yes,resizable=yes,toolbar=no,location=no,status=no,menubar=no, width=' + width + ',height=' + height + ',top=' + window_top + ',left=' + window_left;
    var newWindow = window.open(theURL, '_blank', newfeatures);
    newWindow.focus();
}
function openDialog(url, height, width) {
    var theURL = url;
    var window_top = (screen.height - height) / 2;
    var window_left = (screen.width - width) / 2;
    var newfeatures = 'dialogWidth:' + width + ',dialogHeight:' + height + ',dialogTop"' + window_top + ',dialogLeft:' + window_left;
    window.showModalDialog(theURL, '', newfeatures);
}
function saveClick() {
    __doPostBack('Save', '');
}
function launchwin(winurl) {
    var window_width = 1024;
    var window_height = 768;
    var window_top = (screen.height - window_height) / 2;
    var window_left = (screen.width - window_width) / 2;
    var newfeatures = 'scrollbars=yes,resizable=no,toolbar=no,location=no,status=no,menubar=no width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left;
    var newWindow = window.open(winurl, 'Popup', newfeatures);
    newWindow.focus();
}
function captureEnter() {
    if (window.event.keyCode == 13) {
        window.event.cancelBubble = true;
        window.event.returnValue = false;
    }
}
function resizeImage(img, maxSize) {
    if (img.width > maxSize)
        img.width = maxSize;
}
function clickIE4() {
    if (event.button == 2) {
        alert("Sorry - not allowed!"); return false;
    }
}
function clickNS4(e) {
    if (document.layers || document.getElementById && !document.all) {
        if (e.which == 2 || e.which == 3) {
            alert("Sorry - not allowed!"); return false;
        }
    }
}
function blockContextMenu() {

    if (document.layers) {
        document.captureEvents(Event.MOUSEDOWN); document.onmousedown = clickNS4;
    }
    else if (document.all && !document.getElementById) {
        document.onmousedown = clickIE4;
    }
    document.oncontextmenu = new Function("alert('Sorry - not allowed!');return false");
}
function getElementbyClass(rootobj, classname) {
    var temparray = new Array()
    var inc = 0
    var rootlength = rootobj.length
    for (i = 0; i < rootlength; i++) {
        if (rootobj[i].className == classname)
            temparray[inc++] = rootobj[i]
    }
    return temparray
}

function sweeptoggle(ec) {
    var thestate = (ec == "expand") ? "block" : "none"
    var inc = 0
    while (ccollect[inc]) {
        ccollect[inc].style.display = thestate
        inc++
    }
    revivestatus()
}


function contractcontent(omit) {
    var inc = 0
    while (ccollect[inc]) {
        if (ccollect[inc].id != omit)
            ccollect[inc].style.display = "none"
        inc++
    }
}

function expandcontent(curobj, cid) {
    var spantags = curobj.getElementsByTagName("SPAN")
    var showstateobj = getElementbyClass(spantags, "showstate")
    if (ccollect.length > 0) {
        if (collapseprevious == "yes")
            contractcontent(cid)
        document.getElementById(cid).style.display = (document.getElementById(cid).style.display != "block") ? "block" : "none"
        if (showstateobj.length > 0) { //if "showstate" span exists in header
            if (collapseprevious == "no")
                showstateobj[0].innerHTML = (document.getElementById(cid).style.display == "block") ? contractsymbol : expandsymbol
            else
                revivestatus()
        }
    }
}

function revivecontent() {
    contractcontent("omitnothing")
    selectedItem = getselectedItem()
    selectedComponents = selectedItem.split("|")
    for (i = 0; i < selectedComponents.length - 1; i++)
        document.getElementById(selectedComponents[i]).style.display = "block"
}

function revivestatus() {
    var inc = 0
    while (statecollect[inc]) {
        if (ccollect[inc].style.display == "block")
            statecollect[inc].innerHTML = contractsymbol
        else
            statecollect[inc].innerHTML = expandsymbol
        inc++
    }
}

function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        if (offset != -1) {
            offset += search.length
            end = document.cookie.indexOf(";", offset);
            if (end == -1) end = document.cookie.length;
            returnvalue = unescape(document.cookie.substring(offset, end))
        }
    }
    return returnvalue;
}

function getselectedItem() {
    if (get_cookie(window.location.pathname) != "") {
        selectedItem = get_cookie(window.location.pathname)
        return selectedItem
    }
    else
        return ""
}

function saveswitchstate() {
    var inc = 0, selectedItem = ""
    while (ccollect[inc]) {
        if (ccollect[inc].style.display == "block")
            selectedItem += ccollect[inc].id + "|"
        inc++
    }
    document.cookie = window.location.pathname + "=" + selectedItem
}

function do_onload() {
    uniqueidn = window.location.pathname + "firsttimeload"
    var alltags = document.all ? document.all : document.getElementsByTagName("*")
    ccollect = getElementbyClass(alltags, "switchcontent")
    statecollect = getElementbyClass(alltags, "showstate")
    if (enablepersist == "on" && ccollect.length > 0) {
        document.cookie = (get_cookie(uniqueidn) == "") ? uniqueidn + "=1" : uniqueidn + "=0"
        firsttimeload = (get_cookie(uniqueidn) == 1) ? 1 : 0 //check if this is 1st page load
        if (!firsttimeload)
            revivecontent()
    }
    if (ccollect.length > 0 && statecollect.length > 0)
        revivestatus()
}

function OpenRoomTypePage() {
    var r = document.getElementById("ctl00_MainContent_RoomTypeList");
    if (r.options[r.selectedIndex].value == "-1")
        window.location.href = "vrdupload.aspx";
    else
        window.location.href = "vrd.aspx?type=" + r.options[r.selectedIndex].value;
}
function checkForCookies() {
    // CHECK IF COOKIES ARE ENABLED 

    var exp = new Date();
    exp.setTime(exp.getTime() + 1800000);

    // first write a test cookie 

    setCookie("cookies", "cookies", exp, false, false, false);
    if (document.cookie.indexOf('cookies') == -1) {
        alert('Your browser does not have cookies enabled.  Certain features on this site require cookies.  Please enable cookies in your browser preferences before continuing.');
    }

    // now delete the test cookie 

    exp = new Date();
    exp.setTime(exp.getTime() - 1800000);
    setCookie("cookies", "cookies", exp, false, false, false);
}
function setCookie(name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
    document.cookie = curCookie;
}
function JSGetSwfVer(i) {
    // NS/Opera version >= 3 check for Flash plugin in plugin array
    if (navigator.plugins != null && navigator.plugins.length > 0) {
        if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
            var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
            var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
            descArray = flashDescription.split(" ");
            tempArrayMajor = descArray[2].split(".");
            versionMajor = tempArrayMajor[0];
            versionMinor = tempArrayMajor[1];
            if (descArray[3] != "") {
                tempArrayMinor = descArray[3].split("r");
            }
            else {
                tempArrayMinor = descArray[4].split("r");
            }
            versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
        }
        else {
            flashVer = -1;
        }
    }
    // MSN/WebTV 2.6 supports Flash 4
    else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
    // WebTV 2.5 supports Flash 3
    else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
    // older WebTV supports Flash 2
    else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
    // Can't detect in all other cases
    else {

        flashVer = -1;
    }
    return flashVer;
}
// If called with no parameters this function returns a floating point value 
// which should be the version of the Flash Player or 0.0 
// ex: Flash Player 7r14 returns 7.14
// If called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) {
    reqVer = parseFloat(reqMajorVer + "." + reqRevision);
    // loop backwards through the versions until we find the newest version	
    for (i = 25; i > 0; i--) {
        if (isIE && isWin && !isOpera) {
            versionStr = VBGetSwfVer(i);
        } else {
            versionStr = JSGetSwfVer(i);
        }
        if (versionStr == -1) {
            return false;
        } else if (versionStr != 0) {
            if (isIE && isWin && !isOpera) {
                tempArray = versionStr.split(" ");
                tempString = tempArray[1];
                versionArray = tempString.split(",");
            } else {
                versionArray = versionStr.split(".");
            }
            versionMajor = versionArray[0];
            versionMinor = versionArray[1];
            versionRevision = versionArray[2];

            versionString = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
            versionNum = parseFloat(versionString);
            // is the major.revision >= requested major.revision AND the minor version >= requested minor
            if ((versionMajor > reqMajorVer) && (versionNum >= reqVer)) {
                return true;
            } else {
                return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false);
            }
        }
    }
    return (reqVer ? false : 0.0);
}
var dropdowncontent = {
    delaybeforehide: 200, //set delay in milliseconds before content box disappears onMouseout (1000=1 sec)
    disableanchorlink: true, //when user clicks on anchor link, should it be disabled?

    getposOffset: function(what, offsettype) {
        return (what.offsetParent) ? what[offsettype] + this.getposOffset(what.offsetParent, offsettype) : what[offsettype]
    },

    isContained: function(m, e) {
        var e = window.event || e
        var c = e.relatedTarget || ((e.type == "mouseover") ? e.fromElement : e.toElement)
        while (c && c != m) try { c = c.parentNode } catch (e) { c = m }
        if (c == m)
            return true
        else
            return false
    },

    show: function(anchorobj, subobj, e) {
        if (!this.isContained(anchorobj, e)) {
            var horizontaloffset = (subobj.dropposition[0] == "left") ? -(subobj.offsetWidth - anchorobj.offsetWidth) : 0 //calculate user added horizontal offset
            var verticaloffset = (subobj.dropposition[1] == "top") ? -subobj.offsetHeight : anchorobj.offsetHeight //calculate user added vertical offset
            subobj.style.left = this.getposOffset(anchorobj, "offsetLeft") + horizontaloffset + "px"
            subobj.style.top = this.getposOffset(anchorobj, "offsetTop") + verticaloffset + "px"
            subobj.style.clip = (subobj.dropposition[1] == "top") ? "rect(auto auto auto 0)" : "rect(0 auto 0 0)" //hide drop down box initially via clipping
            subobj.style.visibility = "visible"
            subobj.startTime = new Date().getTime()
            subobj.contentheight = parseInt(subobj.offsetHeight)
            if (typeof window["hidetimer_" + subobj.id] != "undefined") //clear timer that hides drop down box?
                clearTimeout(window["hidetimer_" + subobj.id])
            this.slideengine(subobj, (subobj.dropposition[1] == "top") ? "up" : "down")
        }
    },

    curveincrement: function(percent) {
        return (1 - Math.cos(percent * Math.PI)) / 2 //return cos curve based value from a percentage input
    },

    slideengine: function(obj, direction) {
        var elapsed = new Date().getTime() - obj.startTime //get time animation has run
        if (elapsed < obj.glidetime) { //if time run is less than specified length
            var distancepercent = (direction == "down") ? this.curveincrement(elapsed / obj.glidetime) : 1 - this.curveincrement(elapsed / obj.glidetime)
            var currentclip = (distancepercent * obj.contentheight) + "px"
            obj.style.clip = (direction == "down") ? "rect(0 auto " + currentclip + " 0)" : "rect(" + currentclip + " auto auto 0)"
            window["glidetimer_" + obj.id] = setTimeout(function() { dropdowncontent.slideengine(obj, direction) }, 10)
        }
        else { //if animation finished
            obj.style.clip = "rect(0 auto auto 0)"
        }
    },

    hide: function(activeobj, subobj, e) {
        if (!dropdowncontent.isContained(activeobj, e)) {
            window["hidetimer_" + subobj.id] = setTimeout(function() {
                subobj.style.visibility = "hidden"
                subobj.style.left = subobj.style.top = 0
                clearTimeout(window["glidetimer_" + subobj.id])
            }, dropdowncontent.delaybeforehide)
        }
    },

    init: function(anchorid, pos, glidetime) {
        var anchorobj = document.getElementById(anchorid)
        var subobj = document.getElementById(anchorobj.getAttribute("rel"))
        subobj.dropposition = pos.split("-")
        subobj.glidetime = glidetime || 1000
        subobj.style.left = subobj.style.top = 0
        anchorobj.onmouseover = function(e) { dropdowncontent.show(this, subobj, e) }
        anchorobj.onmouseout = function(e) { dropdowncontent.hide(subobj, subobj, e) }
        if (this.disableanchorlink) anchorobj.onclick = function() { return false }
        subobj.onmouseout = function(e) { dropdowncontent.hide(this, subobj, e) }
    }
}
function createMarker(lat, lng, letter, toolTip) {
    var baseIcon = new GIcon();
    baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
    baseIcon.iconSize = new GSize(20, 34);
    baseIcon.shadowSize = new GSize(37, 34);
    baseIcon.iconAnchor = new GPoint(9, 34);
    baseIcon.infoWindowAnchor = new GPoint(9, 2);
    baseIcon.infoShadowAnchor = new GPoint(18, 25);
    var icon = new GIcon(baseIcon)
    icon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
    var point = new GLatLng(lat, lng);
    var marker = new PdMarker(point, icon);
    var loc = '#' + letter;
    if (toolTip != '')
        GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(toolTip); });
    GEvent.addListener(marker, "click", function() { document.location.href = loc; });
    return marker;
}
