// standard functions for the SRO website
// David Loewenstern, 2/5/04
// Modified by Paul Tukey 

// alert("This is stdFunctions.js"); //DEBUG

function showprops(el) {
//    if( (p = id.indexOf(".")) > 0 ) {
//         var ID  = id.substring(0,p);
//         var SUB = id.substring(p+1);
//         var el  = (Obj(ID))[SUB];
//         // Generalize to allow:  aaa.bbb.ccc etc
//    }
//    else  
//        el = GetElementById(id);
var id="window";
    var s = "";
    var n;
    var i=0;
    for(n in el) {
        var v = el[n]+""; 
        var nv = n+"="+v;
        if(0 || !v.match(/function|[A-Z][A-Z][A-Z]/)) {
          if(1 || !n.match(/[A-Z][A-Z][A-Z]/)) {
            if(1 || nv.match(/color/i)) {
              if(v != "") {
                if((++i)%2 == 0)
                  s += "\n";
                else
                  s += ", ";
                s += n+"='"+v+"'";
              }
            }
          }
        }
    }
    s = "P R O P E R T I E S  O F  "+id+": \n"+s;
    return s;
}

var isFirefox = navigator.userAgent.match(/Firefox/i)? 1 : 0;
var BaseFontSize = (isFirefox)? "1.3em" : "1.0em"; // needs work!
BaseFontSize = "12pt";
var InitString = "";
var EndString = "";
var SymRealWinOpen = window.open;
function SymWinOpen(url, name, attributes)
{
  return (new Object());
}

InitString += "<span style='font-size:"+BaseFontSize+";'>\n";
InitString += "<style>td, .td { font-size:"+BaseFontSize+";} </style>\n";
EndString   = "</span>\n";

function sroHeader(iyear, size) {
//    var logo="<div style=\"position:relative; height: 56px; width: 124px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='logo_SRO_lightblue_black.png',sizingMethod='scale');\"></div>";
//  Meant to make transpareny work in png images in IE.   Needs work.
    size = "";
    year = iyear+"";
    if(iyear==undefined || iyear==null || iyear=="" || year.match(/[^0-9]/)) {
	year = "2009";
	iyear = 2009;
    }
    nyears = 33 + iyear - 2008;
    nyears = 36; // in 2010
    textString = "";   // Ignore input textString.  We'll hardwire Dita & Jim instead

    var output = '<LINK REL="shortcut icon" href="/favicon.ico" type="image/x-icon" >\n';
    output += InitString;

     if(textString==undefined || textString==null || textString=="") {
	textString  = '<nobr><img src="pics/nil.gif" width=50 height=1>';
 	textString += '<a href="ditajim.html#dita">Dita Delman</a> <span class=white>- Artistic Director</span>';
 	textString += '&nbsp; &nbsp; &nbsp; ';
 	textString += '<a href="ditajim.html#jim">James Sadewhite</a> <span class=white>- Music Director</span></nobr>';
     }
    size = (size==null || size==undefined || size=="")? "" : ("size='"+size+"'");

     output += '<table cellpadding=0 cellspacing=0 border=0 align=center>';
     output += '<tr><td><img src="pics/nil.gif" width=50 height=1></td>\n';
     output += '<td valign=top style="padding:6px 6px 6px 6px"><a href="http://www.njsro.com">';
     output += '<img src="logo_SRO_lightblue_darkgrey.jpg" width=124 height=55 border=0 alt="SRO - State Repertory Opera of New Jersey" title="SRO - State Repertory Opera of New Jersey" >';
     output += '</a></td><td align=center valign=top style="padding:12px 12px 12px 12px" nowrap><p class=normal style="margin-top:8pt;font-size:1.1em;font-weight:bold" title="SRO - State Repertory Opera of New Jersey">-- State Repertory Opera of New Jersey</p>';
     output += '</td></tr><tr><td colspan=2></td><td colspan=2 align=center>';
     output += '<p class=white style="margin-top:0pt;margin-bottom:0pt;" >';
     output += '<span class=normal>&#149;</span> '+nyears+' years of Opera in New Jersey ';
     output += '&nbsp; &nbsp; <span class=normal>&#149;</span> '+year+' Season ';
     output += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>';
     output += '</td></tr></table>';
     output += '<p style="margin-top:4pt;margin-bottom:10pt">';
     output += (size)? '<font '+size+'>'+textString+'</font>' : textString;
     output += '</p>';

//   document.write(output.replace(new RegExp('<','gi'),'&lt;')); //debug only
     document.write(output);
}


//for now, commented out because we are not using images in our menus.
//
//imgArry = new Array;
//
//function precacheSrc(inSrc, inIndex)
//{
//  //
//  // Precaches inSrc -- from SourceForge.
//  //
//  imgArry[inIndex] = new Image; // Make new image
//  imgArry[inIndex].src = inSrc; // Load it into invisible image
//}
//
//function toggleImage(inImg, inIndex)
//{
// //
// // Changes source
// //
//  inImg.src = imgArry[inIndex].src;
//}
//
//<img id="FOO" src="SROlogo-gold-black-124x55.jpg" onMouseOver="javascript:toggleImage(FOO,1);" onMouseOut="javascript:toggleImage(FOO,0);">


function menuItem(URL, show, selected, popup) {
  //old:  var bullet = '<span style="font-family:wingdings">&#109;</span>';
  var bullet    = '&#187;';
  var location = window.location+""
  selected = (location.match(URL+""));
  if(URL.match(/about/)) {
//     alert(" URL="+URL+"\n show="+show+"\n selected="+selected+"\n popup="+popup+"\n location="+location);
//     alert(" window.props = "+showprops(window));
  }


  popup = (popup)? " target=_blank" : "";
  var button1   = '<p align="left"><nobr><a href="';
  var button2   = '" class=bare'+popup+'>'+bullet+'&nbsp;&nbsp;&nbsp;';
  var button3   = '</a></nobr></p>\n';

  var selected1 = '<p align="left"><nobr><span style="font-weight:bold;color:white;';
  var selected2 = '" class=bare>'+bullet+'&nbsp;&nbsp;&nbsp;';
  var selected3 = '</span></nobr></p>\n';

  if(selected)
     return selected1 + ''  + selected2 + show + selected3;
  else
     return button1   + URL + button2   + show + button3;
}

function sroMenuBegin(itemNum,frameclass) {
  var output ='';

//  if(frameclass == undefined) {
     frameclass = 'frameleft';
//  }
  output += '<table width="100%" class=' + frameclass +'>';
  output += '<tr><td valign="top" align="left" width="150px">';

  var directions = 'direction.html';
//  var directions = 'http://www.montclair.edu/welcome/directions.html';
  var Lelisir   = "<i>L'Elisir d'Amore</i><small> (2006)</small>";
  var Pasquale  = "<i>Don Pasquale</i><small> (2007)</small>";
  var LLM       = "<i>Love, Lust, Murder</i><small> (2008)</small>";
  var MIDs      = "<i>Mistaken IDs</i><small> (2009)</small>";
  var MIDphotos = "<i>Mistaken IDs</i> - Photos";
  var BelCanto  = "<i>Bel Canto to B'way</i>";
  var Cast2009  = "Cast <small> (2009)</small>";

   output += menuItem( 'index.html',          'Home',			itemNum == 0  );
// output += menuItem( 'party-2008.html',     'Preview Party',  	itemNum == 14 );
   output += menuItem( 'cast-2009.html',       Cast2009,           	itemNum == 16 );
   output += menuItem( 'about.html',          'About SRO',      	itemNum == 1  );
   output += menuItem( 'reviews.html',        'Reviews',        	itemNum == 4  );
   output += menuItem( 'support.html',        'Support',        	itemNum == 6  );
// output += menuItem( 'events.html',         'Events',         	itemNum == 7  );
   output += menuItem( 'contact.html',        'Contact',        	itemNum == 8  );
// output += menuItem(  directions,           'Directions',     	itemNum == 9  );
   output += menuItem( 'bookings.html',       'Booking Shows',  	itemNum == 10 );
   output += menuItem( 'mail.html',           'Mailing List',   	itemNum == 11 );
   output += menuItem( 'MistakenIDs2009.html', MIDs,			itemNum == 18 );
   output += menuItem( 'LLM-2008.html',        LLM,             	itemNum == 17 );
   output += menuItem( 'home-pasquale.html',   Pasquale,        	itemNum == 5  );
   output += menuItem( 'lelisir.html',         Lelisir,          	itemNum == 2  );
// output += menuItem( 'home-Fall2006.html',   BelCanto,        	itemNum == 3  );
   output += menuItem( 'gallery.html',        'Photo Gallery 1',	itemNum == 12 );
   output += menuItem( 'gallery05-06/index.html', 'Photo Gallery 2',    itemNum == 13 );
   output += menuItem( 'photos-MistakenIDs.html', 'Photo Gallery 3',    itemNum == 15 );

  if(itemNum < -1 || itemNum > 12) { // Note: -1 means show all.
    output += '\n<!-- unknown itemNum: ' + itemNum + '-->\n';
  }

  output += '</td><td width="20px"></td>';
  output += '<td valign=top style="padding-top:6px;">';

//  document.write(output.replace(new RegExp('<','gi'),'&lt;')); //debug only
  document.write(output);

}

function sroMenuEnd(width) {
  var output = '';

  if(width == null) {
    width = '170px'; //width of menu + spacer
  }

  output += '</td><td width="' + width + '"></td></tr></table>';

//  document.write(output.replace(new RegExp('<','gi'),'&lt;')); //debug only
  document.write(output);

}

//From Paul Tukey
function PopUp (URL,width,height) {
    if(width  == null) { width  = "500" }
    if(height == null) { height = .6*width }
    win = window.open (
	    URL, "PopUp",
	    "scrollbars,menubar,resizable," + 
	    "width=" + width + ",height=" + height );
    WinFocus(win);
}

function WinFocus(win) {
    // assume win.focus works, unless broken old msoft browser
    if ( (navigator.appName.search (/^microsoft/i) == -1) ||
         (navigator.appName == "Microsoft Internet Explorer" &&
          navigator.appVersion.indexOf("Windows", 0) != -1   &&
          navigator.appVersion.substring(0,1) >= 4) ) {
		win.focus()
    }
}


if(document['getElementById'] == null) {
  if (navigator.family == 'ie4' && navigator.version < 5) {
    document.getElementById = new Function("id", "return document.all[id];");
    }
    else if (navigator.family == 'nn4') {
      document.getElementById = nav4GetLayerById;
    }
}
var Obj  = document.getElementById;  // defines function Obj()

function sb(s){
var r=/\[([0-9A-F]{2})\]/g;s=s.replace(r,'%$1');
document.write(unescape(s))}
