// ©2003 ChannelVR. All rights reserved

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);

// ----------------------------------------------
// PAGES
// ----------------------------------------------
// a page is an independant section of the brochure
// pages are usually selected by a menu
// when a new page is requested the .js file for that page is reloaded into
// the thumbnails, viewer and description frames
// You can customize this to show different starting content in frames when a new page is chosen
// eg. so the floorplan is shown first instead of thumbnails
function setPage(nPage) {
	activePage = nPage; // active page is defined in the
	pathToPage = pathToJob + pageURL[activePage];
	activePagePath = pathToPage;

	for (var i=0; i<window.frames.length; i++) {
		if(window.frames[i].reloadContent) window.frames[i].pageChanged();

	}
}

function getPage() {
	return activePage;
}


// ----------------------------------------------
// DESCRIPTIONS
// ----------------------------------------------


function showPrimaryDecsription() {
	primaryDescription.location.reload()
}

function setSecondaryDescription(description) {

	if (activeSecondaryDescription != description)
	{
		activeSecondaryDescription = description;

		if (secondaryDescription && secondaryDescription.location)
			secondaryDescription.location.reload();
	}

	//secondaryDescription.document.open();
	//secondaryDescription.document.writeln('<html>');
	//secondaryDescription.document.writeln('<head>');
	//if (ie4) secondaryDescription.document.writeln('	<link rel="stylesheet" href="resources/style.css" type="text/css">');
	//else secondaryDescription.document.writeln('	<link rel="stylesheet" href="'+pathToTemplate+'resources/style.css" type="text/css">');
	//secondaryDescription.document.writeln('</head>');
	//secondaryDescription.document.writeln('<body bgcolor="#FFFFFF" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">');
	//secondaryDescription.document.writeln('&nbsp;<img src="images/image_arrow.gif" width="18" height="26" align="absmiddle"><font color="#000000">'+description);
	//secondaryDescription.document.writeln('</font></body>');
	//secondaryDescription.document.writeln('</html>');
	//secondaryDescription.document.close();
}

function getSecondaryDescription() {
	return activeSecondaryDescription;
}

// ----------------------------------------------
// FULL SCREEN
// ----------------------------------------------
function fullscreen(room) {
	//var fullscreen=openIT('viewer.htm?fullscreen=1',750,540,null,null,'fullscreen');
	var fullscreen=window.open('viewer.htm?fullscreen=1','TheFullscreenWindow','width=750,height=540,left=0,top=0,resizable=1');

	var remote = null;
	currentRoom = room;
	//remote = openIT('viewer.htm?fullscreen=1',750,540,null,null,'fullscreen');
	//remote = window.open('', 'TheFullscreenWindow','width=750,height=540,left=0,top=0,resizable=1');
    	if (remote != null) {
        	if (remote.opener == null) {
        		remote.opener = window.parent;
        	}
	//	remote.location.href = 'viewer.htm?fullscreen=1';
	}
}


// ----------------------------------------------
// FLOORPLANS
// ----------------------------------------------


function showFloorplan(activeFloorplan) {
	floorplan.document.open("floorplan.htm");
	floorplan.document.close();
}

function getFloorplan() {
	return activeFloorplan;
}

// display a Plan
function chPlan(nPlan)
{
	parent.activeFloorplan=nPlan;
	frameToDisplayIn = parent.frameContents['floorplan.htm'].frameName;
	parent.frames[frameToDisplayIn].location="floorplan.htm";
}


// ----------------------------------------------
// PRINTING
// ----------------------------------------------

var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1);

function printPage(frame, arg) {
  if (frame == window) {
    printThis();
  } else {
    link = arg; // a global variable
    printFrame(frame);
  }
  return false;
}

function printThis() {
  if (pr) { // NS4, IE5
    window.print();
  } else if (da && !mac) { // IE4 (Windows)
    vbPrintPage();
  } else { // other browsers
    alert("Sorry, your browser doesn't support this feature.");
  }
}

function printFrame(frame) {
  if (pr && da) { // IE5
    frame.focus();
    window.print();
    link.focus();
  } else if (pr) { // NS4
    frame.print();
  } else if (da && !mac) { // IE4 (Windows)
    frame.focus();
    setTimeout("vbPrintPage(); link.focus();", 100);
  } else { // other browsers
    alert("Sorry, your browser doesn't support this feature.");
  }
}

if (da && !pr && !mac) with (document) {
  writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
  writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
  writeln('Sub window_onunload');
  writeln('  On Error Resume Next');
  writeln('  Set WB = nothing');
  writeln('End Sub');
  writeln('Sub vbPrintPage');
  writeln('  OLECMDID_PRINT = 6');
  writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
  writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
  writeln('  On Error Resume Next');
  writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
  writeln('End Sub');
  writeln('<' + '/SCRIPT>');
}



// ----------------------------------------------
// APPLET ACTIONS
// ----------------------------------------------

// start an action
function jsSetAction(i)
{
	viewer.jsSetAction(i);
}

// get the currently running action
function jsGetAction()
{
	return viewer.jsGetAction();
}

// display a room
function jsLoadRoom(iRoom)
{
	viewer.jsLoadRoom(iRoom);
}

// display a still image
function chImage(nImage)
{
	viewer.chImage(nImage);
}

// display a video
function chVideo(nVideo)
{
	viewer.chVideo(nVideo);
}

// display a 3D Object
function chObject3D(nObject3D)
{
	viewer.chObject3D(nObject3D);
}

// ----------------------------------------------
// COOKIES
// ----------------------------------------------
// Use this function to retrieve a cookie.
function getCookie(name){
var cname = name + "=";
var dc = document.cookie;
    if (dc.length > 0) {
    begin = dc.indexOf(cname);
        if (begin != -1) {
        begin += cname.length;
        end = dc.indexOf(";", begin);
            if (end == -1) end = dc.length;
            return unescape(dc.substring(begin, end));
        }
    }
return null;
}

// Use this function to save a cookie.
function setCookie(name, value, expires) {
document.cookie = name + "=" + escape(value) + "; path=/" +
((expires == null) ? "" : "; expires=" + expires.toGMTString());
}

// Use this function to delete a cookie.
function delCookie(name) {
document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}

function fillframes() {
	for(arrayReference in frameContents) {
		if(frameContents[arrayReference].displayOnEnterPage) {
			window.frames[frameContents[arrayReference].frameName].location.href = pathToTemplate+arrayReference
		}
	}
	viewer = eval(frameContents['viewer.htm'].frameName);
	floorplan = eval(frameContents['floorplan.htm'].frameName);
}

