// $Id: //placeware/dev/i18n/build/placeware.ccc/lib/ccc/view-wmm.1/body.js#5 $
// Copyright(c) 2002 PlaceWare, Inc.

//==========================================================================
// Background color
//==========================================================================
var defFontBGColor  = '#CCCCCC'; // gray

// Variables that should be overridden in vals.js and playback.html
//var WMFileName   = "placeware.wmv";
//var bufferTime   = 13;              // in seconds
//var wmmViewerLib = ".";             // in current dir
//var bitrate      = 100 * 1024;      // # of bits per second in the clip
//var wmmOwnerBrand= "enabled";       // display owner branding
//var wmmPWBrand   = "powered";       // display placeware branding:powered,hosted,disabled
//var wmmHelpURL   = "";		    // Help URL

// Standard font and color definitions

var black	= '#000000';
var white	= '#FFFFFF';
var gray        = '#CCCCCC';
var navy	= '#000066';
var blue        = '#3266CD';
var ltGray      = '#F3F3F3';
var ltBlue      = '#9DBDDC';
var orange	= '#FF9900';
var dkGreen  	= '#669999';
var ltGreen  	= '#99CC99';
var defFontFace     = "arial,helvetica,geneva,swiss,sunsans-regular,sans-serif";
var defFontSize     = 2;
var defFontSizePts  = 9;
var defFontColor    = black;


function imgDir() {
    return wmmViewerLib + '/';
}

function showPWBrand() {
    return wmmPWBrand == "powered" || wmmPWBrand == "hosted";
}

function showOwnerBrand() {
    return wmmOwnerBrand == "enabled";
}

function Help() {
    var href = wmmHelpURL? wmmHelpURL: imgDir() + "wmmHelp-en.html";
    var name = 'wmm_help';
    var attr = 'width=700,height=450,resizable,scrollbars,status';
    window.open(href, name, attr);
}

function Logo() {
    var href = 'http://www.placeware.com';
    var name = 'placeware';
    var attr = 'width=700,height=450,resizable,scrollbars,status';
    window.open(href, name, attr);
}

// Given a URL, show the web site in a pop up window
var web = null;
function showWebSite(url)
{
    // close window
    if (web != null) {
    	web.close();
    	web = null;
    }

    // start/stop displaying this URL in a web frame;
    if (url != "") {
	var name = '_blank';
	var attr = 'alwaysRaised,height=529,width=702,resizable=1,screenX=208,screenY=0,'
		 + 'toolbar=no,scrollbars=yes,status=no';
    	web = window.open(url, name, attr);
    }
}

//#####################################################################
// Universal theme definitions
//#####################################################################
var themes = new Object();
var theme  = new Theme();
theme = themes['defaultTheme'];
theme.activate();

// Initialize Dynamic Elements
theme.newElement(window, 'BrandDiv', 'center');
theme.newElement(window, 'TitleDiv', 'title');

theme.newElement(window, 'TabDiv');
theme.newElement(window, 'DataDiv',  'data');
theme.newElement(window, 'BufferDiv','title');
theme.newElement(window, 'HelpDiv');
if (!smScreen) {
   theme.newElement(window, 'RecDiv',   'default');
   theme.newElement(window, 'SlideDiv', isNetscape4? 'menuNS':'menuIE');
   theme.newElement(window, 'LogoDiv');
   theme.newElement(window, 'QADiv',  'qaform');
} else {
   theme.newElement(window, 'RecDiv',   'small');   
   theme.newElement(window, 'SlideDiv', 'menu');
}
// Initialize Buttons
theme.newImgButton('slide', theme.newImage('slide', 98, 18, 'slides',     'TabDiv'));
theme.newImgButton('help',  theme.newImage('help',  87, 19, 'std-help',   'HelpDiv'));
theme.newImgButton('logo',  theme.newImage('logo', 100, 27, 'basic-brand','LogoDiv'));

// Initialize Images
if (smScreen)
   var branding  = theme.newImage('branding',  67, 15, 'small-brand', 'BrandDiv')
else
   var branding  = theme.newImage('branding', 188, 30, 'owner-brand', 'BrandDiv', null, null, './');
var presenterImage  = theme.newImage('presenterImage', 40, 51, 'blank', 'RecDiv');
var spacer          = theme.newImage( null, 1, 1, 'spacer');

//#####################################################################
// ===== handler functions, can be overridden as needed =====
//#####################################################################
function onLoad() {
    handleOnLoad(); // call stub function

    // if we could not launch media player, don't do anything here.
    if (!playerReady) return;

    if (isNetscape4)
	registerEventObservers();

    // set the recording filename
    player.setFileName();

}

function onResize() {
    handleOnResize(); // call stub function
}

function handleOnLoad() {
    addSlideBackground();
    for (var i in activeButtons) {
	activeButtons[i].onLoadHandler();
    }
}

function handleOnResize() {
    addSlideBackground();
    for (var i in activeButtons)
	activeButtons[i].onResizeHandler();
}

function onDragDrop() { }
function onDefaultAction() { }


//=======================================================================
// The following functions are copied from placeware.ccc/lib/ccc/shared.js
//=======================================================================
function dw(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
  // alas, can't use "arguments" in IE3
  if (a1) document.write(a1);
  if (a2) document.write(a2);
  if (a3) document.write(a3);
  if (a4) document.write(a4);
  if (a5) document.write(a5);
  if (a6) document.write(a6);
  if (a7) document.write(a7);
  if (a8) document.write(a8);
  if (a9) document.write(a9);
}

function opt(val, def) { return val ? val : def; }

function makeAttr(attr, val) { // double quotes within val MUST BE QUOTED
    return ' ' + attr + '="' + val + '"'; // PB 2
}
function makeOptAttr(attr, val) { return val ? makeAttr(attr, val) : ''; }

function wAttr(attr, val) { dw(makeAttr(attr, val)); }

function dwTableTag(attrs, cellspacing, cellpadding, border) {
  return '<table ' +  attrs
         + makeAttr('cellspacing', opt(cellspacing, 0))
         + makeAttr('cellpadding', opt(cellpadding, 0))
         + makeAttr('border',      opt(border, 0))
         + '>\n';
}

function repl(text, s1, s2) {
  for (var i = 0; i < text.length;) {
    i = text.indexOf(s1, i);
    if (i < 0) break;
    text = text.substring(0, i) + s2 + text.substring(i + s1.length);
    i += s2.length;
  }
  return text;
}

function html(val) {
  var text = '' + val;
  text = repl(text, '&',  '&amp;'); // do this first!
  text = repl(text, '<< ', '&lt;&lt; '); // "<< Previous"
  text = repl(text, '< ', '&lt; ');
  text = repl(text, '<=', '&lt;=');
  text = repl(text, '<',  '&lt; '); // BB 181
  text = repl(text, '>',  '&gt;');
  return text;
}

function attr(val) {
  var text = '' + val;
  text = repl(text, '&', '&amp;'); // do this first!
  text = repl(text, '"', '&#34;');
  text = repl(text, "'", '&#39;');
  return text;
}

function addSpace(num) {
    var space = "";
    for (var i=0; i<num; i++)
    	space += "&nbsp;";
    return space;
}

function dwFillTD(w, h, attrs, img) {
    var theImg = opt(img, spacer);
    return theImg.writeTD(attrs, null, null, w, h);
}

function dw(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
  // alas, can't use "arguments" in IE3
  if (a1) document.write(a1);
  if (a2) document.write(a2);
  if (a3) document.write(a3);
  if (a4) document.write(a4);
  if (a5) document.write(a5);
  if (a6) document.write(a6);
  if (a7) document.write(a7);
  if (a8) document.write(a8);
  if (a9) document.write(a9);
}

//=======================================================================

function addPlayer() {
    if (isExplorer && hasWMP7 && !smScreen) {
	player = new Player("Player7", 592, 704, WMFileName);
    } else if (isNetscape4) {
        player = new Player("Player6ns", 574, 704, WMFileName);
    } else if (hasWMP64) {
        player = new Player("Player6", 574, 704, WMFileName);
    } else
    	return;
    player.show();
}

function dwPlayer() {
var width = (smScreen)? 92:220;
    dw('<TABLE><TR VALIGN="top">');
    dw(dwFillTD(width, 1, 'width="' + width + '"'));
    dw('<TD>');
    addPlayer();
    dw('</TD></TR></TABLE>');

}

function dwBranding(){
    elements.BrandDiv.write(branding.write());
}

function RecInfoTable(RecTitle,PresenterName) {
    var html='';
    
    if (smScreen) {
     var showT = (RecTitle!='&nbsp;')? true:false;
     var showP = (PresenterName!='&nbsp;')? true:false;
     if (showT) html += '<p>' + RecText + '<br><b>' + RecTitle + '</b></p>';
     if (showP) html += '<p>' + PresenterText + '<br><b>' + PresenterName + '</b></p>';
     html += presenterImage.write();    	
    } else {
     var html=dwTableTag('width="215"', 2, 1, 0)
         + '<TR><TD bgcolor="navy">'
         + dwTableTag('bgcolor="#f3f3f3"', 0, 3, 0)
         + '<TR VALIGN="top">'
         + '<TD class="default" width="55" ALIGN="right">' + RecText + '</TD>'
         + '<TD class="default" width="115"  VALIGN="top">' + RecTitle + '</TD>'
         + '<TD class="default" width="40" VALIGN="middle" rowspan="2">'
         + presenterImage.write()
         + '</TD>'
         + '</TR><TR>'
         + '<TD class="default" VALIGN="top" ALIGN="right">'+ PresenterText + '</TD>'
         + '<TD class="default" VALIGN="top">' + PresenterName + '</TD>'
         + '</TR></TABLE>'
         + '</TD></TR></TABLE>';
    }
    
    return html;
}

function dwRecordingInfo(){
    elements.TitleDiv.write(RecInfoText);
    elements.RecDiv.write(RecInfoTable('&nbsp;','&nbsp;'));
}

function dwFakeOption() {
    var space= (smScreen)? 18:52;
    return '\n<OPTION>' + addSpace(space) + '</OPTION>';
}

// Go to marker # n (0-based) when the user clicks in the slide list.
function gotoMarker(n) {
    player.setMarker(n);
    if (player.state() == PLAYING) showProgress(true);

}

function dwSlideList() {
    var size  = (!smScreen)? ' SIZE="18"' : '';
    var style = (isExplorer && !smScreen)? ' CLASS="slideIE"' : '';
   
    var html = '<FORM NAME="TOCform">'
               + '<SELECT NAME="SlideList"'
               + size + style
               + ' onChange="gotoMarker(this.selectedIndex)">'
               + dwFakeOption() 
               + dwFakeOption() 
               + dwFakeOption() 
               + '</SELECT>'
             + '</FORM>';
    elements.TabDiv.write(btns.slide.write());
    elements.SlideDiv.write(html);
    
}

function dwBuffer() {
    elements.DataDiv.write('');
    elements.BufferDiv.write('');
}

function dwLogo() {
    if (!smScreen)
       elements.LogoDiv.write(btns.logo.write("javascript:Logo()"));
    elements.HelpDiv.write(btns.help.write("javascript:Help()"));

}

function dwQA() {
    var html = '<FORM>'
             + '<TEXTAREA NAME="msgs" ID="msgs" CLASS="qaIE" ROWS="3" COLS="67" READONLY>'
             + '</TEXTAREA>'
             + '</FORM>';
    elements.QADiv.write(html);
}

// Load windows media plugin in an applet
function addPlugin() {
    dw('<APPLET MAYSCRIPT Code="NPDS.npDSEvtObsProxy.class"'
     + ' width="1" height="1" name="appObs" id="appObs">'
     + '</APPLET>');
}

function addSlideBackground() { // NS 4
  if (isNetscape4 && !smScreen) {
    var overlay = new Layer(210);
    overlay.bgColor = blue;
    overlay.below = "SlideDiv";
    overlay.moveTo(6,235);
    overlay.resizeTo(210,330);
    overlay.visibility = "show";
  }
}

function writeDocument() {
    dw('<BODY onLoad="onLoad()" onResize="onResize()" BGCOLOR="'
     + defFontBGColor 
     + '" marginwidth="0" marginheight="0" leftmargin="0" topmargin="0">');
    
    dwPlayer();
    dwBranding();
    dwRecordingInfo();
    dwSlideList();
    dwBuffer();
    dwLogo();
    if (!smScreen) dwQA();
    if (isNetscape4 && hasPlugin) addPlugin();
    
    dw('</BODY>');
}




