// JavaScript Document

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

			
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

			
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function EnsureNumeric(){
  var key = window.event.keyCode; 
  if (key <48 || key >57) 
    window.event.returnValue = false; 
}

function showImage(imagePath){
    var wndImage = window.open("ShowImage.aspx?image=" + imagePath, "Image", "height=56,width=136,location=no,menubar=no,titlebar=no,toolbar=no,resizable=no,scrollbars=no,status=no");
    wndImage.focus();
}

function showImage(imagePath, title){
    var wndImage = window.open("ShowImage.aspx?image=" + imagePath + "&title=" + title, "Image", "height=56,width=136,location=no,menubar=no,titlebar=no,toolbar=no,resizable=no,scrollbars=no,status=no");
    wndImage.focus();
}

function resize(width,height){
    if (parseInt(navigator.appVersion)>3) top.resizeTo(width,height);
}

	function changeDayofWeek(day, ddlMonth, edDay) {
		var dt = new Date();
		var arDayofWeek = Array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
		dt.setMonth(ddlMonth.selectedIndex);
		dt.setDate(day);
		edDay.value = arDayofWeek[dt.getDay()];
	};
	
function bookThisRoom(pageItemID){
	popup_window=window.open("RoomsPopUp.aspx?ID=" + pageItemID,"popup_window","width=315,height=272");popup_window.focus()
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function CheckOutGraterThanCheckIn(source, args)
{
    args.IsValid=false;
    var dateFormat = 'dd/MM/yyyy';
    var ctlStart = document.getElementById('ModuleHome_UcSearchAvailability1_txtStartDate');
    var ctlEnd = document.getElementById('ModuleHome_UcSearchAvailability1_txtEndDate');
    if (ctlStart!=null && ctlEnd!=null)
        if (isDate(ctlStart.value,dateFormat) && isDate(ctlEnd.value,dateFormat))
        if (compareDates(ctlEnd.value, dateFormat, ctlStart.value, dateFormat)>0) args.IsValid = true
}


javascriptVersion1_1 = true;

// initialize global variables
var detectableWithVB = false;
var pluginFound = false;


function goURL(daURL) {
    // if the browser can do it, use replace to preserve back button
    if(javascriptVersion1_1) {
        window.location.replace(daURL);
    } else {
        window.location = daURL;
    }
    return;
}

function redirectCheck(pluginFound, redirectURL, redirectIfFound) {
    // check for redirection
    if( redirectURL && ((pluginFound && redirectIfFound) ||
        (!pluginFound && !redirectIfFound)) ) {
        // go away
        goURL(redirectURL);
        return pluginFound;
    } else {
        // stay here and return result of plugin detection
        return pluginFound;
    }
}

function canDetectPlugins() {
    if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
        return true;
    } else {
        return false;
    }
}

function detectFlash(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Shockwave','Flash');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
        pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectDirector(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Shockwave','Director');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
        pluginFound = detectActiveXControl('SWCtl.SWCtl.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectQuickTime(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('QuickTime');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
        pluginFound = detectQuickTimeActiveXControl();
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectReal(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('RealPlayer');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
        pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') ||
                       detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
                       detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectWindowsMedia(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Windows Media Player');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
        pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
        var pluginsArrayLength = navigator.plugins.length;
        // for each plugin...
        for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
            // loop through all desired names and check each against the current plugin name
            var numFound = 0;
            for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
                // if desired plugin name is found in either plugin name or description
                if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) ||
                    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
                    // this name was found
                    numFound++;
                }
            }
            // now that we have checked all the required names against this one plugin,
            // if the number we found matches the total number provided then we were successful
            if(numFound == daPlugins.length) {
                pluginFound = true;
                // if we've found the plugin, we can stop looking through at the rest of the plugins
                break;
            }
        }
    }
    return pluginFound;
} // detectPlugin


// Here we write out the VBScript block for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');

    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');

    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('\'and the following function handles QuickTime');
    document.writeln('Function detectQuickTimeActiveXControl()');
    document.writeln('  on error resume next');
    document.writeln('  detectQuickTimeActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('    detectQuickTimeActiveXControl = False');
    document.writeln('    hasQuickTimeChecker = false');
    document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
    document.writeln('    If IsObject(hasQuickTimeChecker) Then');
    document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
    document.writeln('        detectQuickTimeActiveXControl = True');
    document.writeln('      End If');
    document.writeln('    End If');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('</scr' + 'ipt>');
}

var gArgCountErr =        'The "%%" function requires an even number of arguments.'
                                +        '\nArguments should be in the form "atttributeName", "attributeValue", ...';

/******************** END LOCALIZABLE **********************/

var gTagAttrs                                = null;
var gQTGeneratorVersion                = 0.8;

function AC_QuickTimeVersion()        { return gQTGeneratorVersion; }

function _QTComplain(callingFcnName, errMsg)
{
    errMsg = errMsg.replace("%%", callingFcnName);
        alert(errMsg);
}

function _QTAddAttribute(prefix, slotName, tagName)
{
        var                value;

        value = gTagAttrs[prefix + slotName];
        if ( null == value )
                value = gTagAttrs[slotName];

        if ( null != value )
        {
                if ( 0 == slotName.indexOf(prefix) && (null == tagName) )
                        tagName = slotName.substring(prefix.length);
                if ( null == tagName )
                        tagName = slotName;
                return tagName + '="' + value + '" ';
        }
        else
                return "";
}

function _QTAddObjectAttr(slotName, tagName)
{
        // don't bother if it is only for the embed tag
        if ( 0 == slotName.indexOf("emb#") )
                return "";

        if ( 0 == slotName.indexOf("obj#") && (null == tagName) )
                tagName = slotName.substring(4);

        return _QTAddAttribute("obj#", slotName, tagName);
}

function _QTAddEmbedAttr(slotName, tagName)
{
        // don't bother if it is only for the object tag
        if ( 0 == slotName.indexOf("obj#") )
                return "";

        if ( 0 == slotName.indexOf("emb#") && (null == tagName) )
                tagName = slotName.substring(4);

        return _QTAddAttribute("emb#", slotName, tagName);
}


function _QTAddObjectParam(slotName, generateXHTML)
{
        var                paramValue;
        var                paramStr = "";
        var                endTagChar = (generateXHTML) ? ' />' : '>';

        if ( -1 == slotName.indexOf("emb#") )
        {
                // look for the OBJECT-only param first. if there is none, look for a generic one
                paramValue = gTagAttrs["obj#" + slotName];
                if ( null == paramValue )
                        paramValue = gTagAttrs[slotName];

                if ( 0 == slotName.indexOf("obj#") )
                        slotName = slotName.substring(4);

                if ( null != paramValue )
                        paramStr = '  <param name="' + slotName + '" value="' + paramValue + '"' + endTagChar + '\n';
        }

        return paramStr;
}

function _QTDeleteTagAttrs()
{
        for ( var ndx = 0; ndx < arguments.length; ndx++ )
        {
                var attrName = arguments[ndx];
                delete gTagAttrs[attrName];
                delete gTagAttrs["emb#" + attrName];
                delete gTagAttrs["obj#" + attrName];
        }
}



// generate an embed and object tag, return as a string
function _QTGenerate(callingFcnName, generateXHTML, args)
{
        // is the number of optional arguments even?
        if ( args.length < 4 || (0 != (args.length % 2)) )
        {
                _QTComplain(callingFcnName, gArgCountErr);
                return "";
        }

        // allocate an array, fill in the required attributes with fixed place params and defaults
        gTagAttrs = new Array();
        gTagAttrs["src"] = args[0];
        gTagAttrs["width"] = args[1];
        gTagAttrs["height"] = args[2];
        gTagAttrs["classid"] = "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B";
        gTagAttrs["pluginspage"] = "http://www.apple.com/quicktime/download/";

        // set up codebase attribute with specified or default version before parsing args so
        //  anything passed in will override
        var activexVers = args[3]
        if ( (null == activexVers) || ("" == activexVers) )
                activexVers = "6,0,2,0";
        gTagAttrs["codebase"] = "http://www.apple.com/qtactivex/qtplugin.cab#version=" + activexVers;

        var        attrName,
                attrValue;

        // add all of the optional attributes to the array
        for ( var ndx = 4; ndx < args.length; ndx += 2)
        {
                attrName = args[ndx].toLowerCase();
                attrValue = args[ndx + 1];

                // "name" and "id" should have the same value, the former goes in the embed and the later goes in
                //  the object. use one array slot
                if ( "name" == attrName || "id" == attrName )
                        gTagAttrs["name"] = attrValue;

                else
                        gTagAttrs[attrName] = attrValue;
        }

        // init both tags with the required and "special" attributes
        var objTag =  '<object '
                                        + _QTAddObjectAttr("classid")
                                        + _QTAddObjectAttr("width")
                                        + _QTAddObjectAttr("height")
                                        + _QTAddObjectAttr("codebase")
                                        + _QTAddObjectAttr("name", "id")
                                        + _QTAddObjectAttr("tabindex")
                                        + _QTAddObjectAttr("align")
                                        + _QTAddObjectAttr("class")
                                        + _QTAddObjectAttr("title")
                                        + _QTAddObjectAttr("accesskey")
                                        + _QTAddObjectAttr("noexternaldata")
                                        + '>\n'
                                        + _QTAddObjectParam("src", generateXHTML);
        var embedTag = '  <embed '
                                        + _QTAddEmbedAttr("src")
                                        + _QTAddEmbedAttr("width")
                                        + _QTAddEmbedAttr("height")
                                        + _QTAddEmbedAttr("pluginspage")
                                        + _QTAddEmbedAttr("name")
                                        + _QTAddEmbedAttr("align")
                                        + _QTAddEmbedAttr("tabindex");

        // delete the attributes/params we have already added
        _QTDeleteTagAttrs("src","width","height","pluginspage","classid","codebase","name","tabindex",
                                        "align","noexternaldata","class","title","accesskey");

        // and finally, add all of the remaining attributes to the embed and object
        for ( var attrName in gTagAttrs )
        {
                attrValue = gTagAttrs[attrName];
                if ( null != attrValue )
                {
                        embedTag += _QTAddEmbedAttr(attrName);
                        objTag += _QTAddObjectParam(attrName, generateXHTML);
                }
        }

        // end both tags, we're done

        objTag = objTag + embedTag + '> </em' + 'bed>\n<param name="scale" value="tofit"></ob' + 'ject' + '>';
//alert(objTag);
        return objTag;
}

// return the object/embed as a string
function QT_GenerateOBJECTText()
{
        return _QTGenerate("QT_GenerateOBJECTText", false, arguments);
}

function QT_GenerateOBJECTText_XHTML()
{
        return _QTGenerate("QT_GenerateOBJECTText_XHTML", true, arguments);
}

function QT_WriteOBJECT()
{
        document.writeln(_QTGenerate("QT_WriteOBJECT", false, arguments));
}

function QT_WriteOBJECT_XHTML()
{
        document.writeln(_QTGenerate("QT_WriteOBJECT_XHTML", true, arguments));
}

function showFlash(swfFile, pWidth, pHeight)
{
        document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+pWidth+'" height="'+pHeight+'" id="flag" align="top">');
        document.writeln('<param name="allowScriptAccess" value="sameDomain">');
        document.writeln('<param name="movie" value="'+swfFile+'">');
        document.writeln('<param name="quality" value="high">');
        document.writeln('<param name="scale" value="noscale">');
        document.writeln('<param name="salign" value="rt">');
        document.writeln('<param name="wmode" value="transparent">');
        document.writeln('</object>');
}

function  loadTour(qtFile, swfFile, pWidth, pHeight)
{
		
        var quickTimeIsInstalled = detectQuickTime();
        var flashIsInstalled = detectFlash();

        if(quickTimeIsInstalled)
        {
                QT_WriteOBJECT_XHTML(qtFile, pWidth, pHeight, '','autoplay', 'false','emb#bgcolor', 'white','align', 'middle');
        }
        else if(flashIsInstalled)
        {
                alert(swfFile)
                showFlash(swfFile, pWidth, pHeight);
        }
        else
        {
                alert("You have no QuickTime and Macromedia Flash plug-ins installed in your browser!");
        }
}


function showFullscreen(Page)
{
        window.open(Page,"Picture","width="+screen.availWidth+",height="+screen.availHeight+",status=no,toolbar=no,menubar=no,location=no,scrollbars=auto,top=0,left=0")
}

