// JavaScript Document

var browser = navigator.userAgent.toLowerCase();
var browserIE = ( browser.indexOf("msie") != -1 );
var today = new Date();
var thisYear = today.getFullYear();

/*
 * --------------------------------------------------------------------------------
 */
 
/*
 * --------------------------------------------------------------------------------
 * addLoadEvent will execute a JavaScript command/function when a page is
 * brought up in a browser.  Ordinarily only one such command/function can be
 * performed at that time, but addLoadEvent overrides that limitation.
 * --------------------------------------------------------------------------------
 */

function addLoadEvent(func) {
// Multiple onload function created by: Simon Willison
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

/*
 * --------------------------------------------------------------------------------
 */

function f_element( p_index, p_deliminator, p_string ) {
  /* 
   * JavaScript version of OpenVMS DCL F$ELEMENT lexical
   */
  var currIndex = p_string.indexOf(p_deliminator);
  var i = 0;
  var outChar = '';
  var outPoint = 0;
  var outString = p_string;
  var trackIndex = 0;

  if ( currIndex >= 0 ) {
      while ( ( trackIndex != p_index ) && ( currIndex != -1 ) ) {
        outPoint = ++currIndex;
        currIndex = p_string.indexOf(p_deliminator,outPoint);
        trackIndex++;
      } // end while ( ( trackIndex != p_index ) && ( currIndex != -1 ) )
      if ( trackIndex != p_index ) {
        outString = p_deliminator;
      } else {
        outString = '';
        for ( i=outPoint; i<p_string.length; i++ ) { 
          outChar = p_string.charAt(i);
          if ( outChar == p_deliminator ) {
            break;
          } else {
            outString = ( outString + outChar );
          } // end if ( outChar == p_deliminator )
        } // for ( i=outPoint; i<p_string.length; i++ )
      } // end if ( trackIndex != p_index )
    } else if ( p_index >= 1 )
      outString = p_deliminator;
    // end if ( currIndex >= 0 )
  
  return outString;
  } // end f_element function
  
/*
 * --------------------------------------------------------------------------------
 */

function replace(p_string,p_text,p_by) {
// Replaces p_text with p_by in p_string
// From:  http://tech.irt.org/articles/js037/
    var strLength = p_string.length, txtLength = p_text.length;
    if ((strLength == 0) || (txtLength == 0)) return p_string;

    var i = p_string.indexOf(p_text);
    if ((!i) && (p_text != p_string.substring(0,txtLength))) return p_string;
    if (i == -1) return p_string;

    var newstr = p_string.substring(0,i) + p_by;

    if (i+txtLength < strLength)
        newstr += replace(p_string.substring(i+txtLength,strLength),p_text,p_by);

    return newstr;
}  // end replace function

/*
 * --------------------------------------------------------------------------------
 */

function getPassedValue(p_id) {
  /* 
   * +++
   *
   * Function Name: getPassedValue
   *        Author: Alvin Orzechowski MyFirstWebPage.net
   * Creation Date: 15-Aug-2004
   *      Abstract: To return the passed value or the specified portion of it
   *   Description: 
   *    Parameters: p_id - Value found to the left of an equal sign.  If this is
   *                    found, this function will return the value found to the
   *                    right of the equal sign.  If this parameter is not 
   *                    provided, this function will return the whole value 
   *                    passed.
   *       History: 
   * 
   * ---
   */

  // [ getPassedValue Constants ]
  var passedValue = unescape(location.search.substring(1));

  // [ getPassedValue Variables ]
  var allSubValues = location.search.substring(1,location.search.length).split('&');
  var i;
  var idValue = passedValue;
  var subValue;

  // [ getPassedValue Main Line ]
  if ( p_id != '' )
    idValue = '';
  for (i=0; i<allSubValues.length; i++) {
    subValue = allSubValues[i].split('=');
    if ( subValue[0] == p_id ) {
      idValue = unescape(subValue[1]);
      i = allSubValues.length;
    } // end if ( subValue[0] == p_id )  
  } // end for (i=0; i<allSubValues.length; i++)

  // [ getPassedValue End of Job ]
  return idValue;

} // end getPassedValue function

/*
 * --------------------------------------------------------------------------------
 */

function preloadAllImages() {
  a = document.images.length;
  document.write( a + '<br>' );
  /*
  for (x=0; x<a; x+) {
     document.write( document.images[x].src + '<br>' );
  }
  */
  return;
} // end preloadAllImages function


/*
 * --------------------------------------------------------------------------------
 * The following functions control the menu display
 * --------------------------------------------------------------------------------
 */

function displayOption( pFilename, pOption, pPulldown ) {
  if ( pFilename == '#' )
    pageFile = '#'
  else
  
    pageFile = ( pFilename + '.html' );
  /* pageFile = '#'; */
  if ( pOption == 'Home' )
    if ( devEnviron() == 'Production' )
	  pageFile = 'http://www.yogateachersgroup.com/';
  if ( filename == pFilename )
    aValue = 'class="UrHere" title="You are here"'
  else
    aValue = ( 'href="' + pageFile + '" title="' + pOption + ' page"' );
  document.write('<li><a ' + aValue + '>' + pOption + '</a>');
  if ( !pPulldown )
    document.write('</li>');
  return; // from displayOption function
}

function displayMenu() {
  if ( filename != 'index' )
    document.write('<table border="0" align="center"><tr><td style="background-color: #ffffff;">');
  document.write('<ul id="nav">');
  if ( filename != 'index' )
    displayOption( 'index', 'Home', false );
  displayOption( 'aboutus', 'About Us', false );
  /* displayOption( 'benefits', 'Benefits', false ); */
  displayOption( 'faq', 'FAQ', false );
  displayOption( 'classes', 'Classes', false );
  displayOption( 'teachers', 'Teachers', false );
  displayOption( 'locations', 'Locations', false );
  displayOption( 'calendars', 'Calendars', false );
  displayOption( 'registration', 'Registration', false );
  displayOption( 'contactus', 'Contact Us', false );
  if ( filename != 'index' )
    displayOption( 'resources', 'Resources', false );
  document.write ('</ul>');
  if ( filename != 'index' )
    document.write('</td></tr></table>');
  return;  // from displayMenu
}

/*
 * --------------------------------------------------------------------------------
 * The following function displays the header section information
 * --------------------------------------------------------------------------------
 */

function displayHeader(pPageName) {
  /* 
   * +++
   * 
   * Function Name: displayHeader
   *        Author: Alvin Orzechowski, MyFirstWebPage.net
   * Creation Date: 24-Aug-2005
   *      Abstract: To display the header information
   *   Description: The header information is constant excpect for the page name.
   *    Parameters: pPageName - the string value that will be displayed on the 
   *                            second line of the header. (optional)
   *       History: 
   *
   * ---
   */

  // [ displayHeader Constants ]
    var isIndexPage = ( filename == 'index' );

  // [ displayHeader Variables ]
    homePage = 'index.html';

  // [ displayHeader Main Line ]

  if ( devEnviron() == 'Production' )
    homePage = 'http://www.yogateachersgroup.com/';
  document.write('<table width="100%">');
  document.write('<tr>');
  document.write('<td><a href="' + homePage + '" title="Home page"><img src="images/YTGlogo180w.jpg" id="ytgLogo" alt="YTG Logo"></a></td>');
  document.write('<td valign="middle">');
  if ( pPageName )
    if ( pPageName != '' )
        document.write('<h1 class="pageName UrHere">' + pPageName + '</h1>');
  document.write('<h1 class="YTGname">The Yoga Teachers' + "'" + ' Group</h1>');
  document.write('</td>');
  document.write('</tr>');
  document.write('</table>');

  // [ displayHeader End of Job ]
  return;

} // end displayHeader function

/*
 * --------------------------------------------------------------------------------
 * The following function displays the footer section information
 * --------------------------------------------------------------------------------
 */

function displayFooter() {
  /* 
   * +++
   * 
   * Function Name: displayFooter
   *        Author: Alvin Orzechowski, MyFirstWebPage.net
   * Creation Date: 7-Oct-2004
   *      Abstract: To display the footer information
   *   Description: The footer information and layout is determined by which 
   *                page is being displayed and which browser is being used.
   *    Parameters: 
   *       History: 
   *
   * ---
   */

  // [ displayFooter Constants ]
    var isIndexPage = ( filename == 'index' );
    var isContactUsPage = ( filename == 'contactus' );

  // [ displayFooter Variables ]

  // [ displayFooter Main Line ]
    // document.write('<p>');
    if ( isIndexPage ) {
      document.write('<a class="YTGlink" href="JavaScript:addToFavorites()">Click here to bookmark this page</a>');
      document.write('<br>');
    } else {
	  document.write('<table align="center"><tr><td>');	
	}// end if ( filename == 'index' )
    document.write('<br>Copyright &#169; 2005&ndash;' + thisYear + ' by');
      document.write('<a HREF="javascript:msgForm(' + "'0','Request for Yoga Teachers Group Information','The Yoga Teachers Group')" + '" class="logoColor" title="E-mail us and we will reply ASAP.">' + '<span style="font-style: italic; font-family: ' + "'Times New Roman', Garamond, Times, serif;" + '">The Yoga Teachers' + "' Group</span>, Inc.<\/a><br \/>");
    document.write('Web page services provided by ');
    document.write('<a href="http://myfirstwebpage.net" class="MFWPNlogo" target="_blank">');
    document.write(get_mfwpnLogo('tm'));
    document.write('<\/a><br \/>');
    // if ( isIndexPage )
    //   document.write("The Yoga Teachers' Group")
    // else
    // document.write('<\/p>');
    if ( isContactUsPage )
      document.write('<a HREF="javascript:msgForm(' + "'1','Contacting the YogaTeachersGroup.com Webmaster', 'YogaTeachersGroup.com Webmaster')" + '" title="E-mail the Webmaster" style="text-decoration: none; color: #666666;">E-mail the Webmaster<\/a>');

	if ( !isIndexPage ) 
	  document.write('</td></tr></table>');

  // [ displayFooter End of Job ]
  return;

} // end displayFooter function

/*
 * --------------------------------------------------------------------------------
 * The following function calls the mail form
 * --------------------------------------------------------------------------------
 */

function msgForm(p_to,p_subject,p_toName) {
  /* 
   * +++
   *
   * Function Name: msgForm
   *        Author: Alvin Orzechowski, MyFirstWebPage.net
   * Creation Date: 16-Aug-2004
   *      Abstract: To bring up the msgform.html file in its own window
   *   Description: 
   *    Parameters: p_to - Value of username getting the e-mail address
   *                p_subject - Value of Subject to be put in the form
   *       History: 
   * 
   * ---
   */

  // [ msgForm Constants ]

  var day = new Date();

  // [ msgForm Variables ]

  var id = day.getTime();
  var params = '';
  var URL = 'msgform.html';

  // [ msgForm Main Line ]

  if ( p_to != '' )
    params = ( '?to=' + p_to );
  if ( p_subject != '' ) {
    if ( params == '' )
      params = '?'
    else
      params = ( params + '&' );
    params = ( params + 'subject=' + p_subject );
  }
  if ( p_toName )
    if ( p_toName != '' )
	  params = ( params + '&toName=' + p_toName );
  URL = ( URL + params );
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,status=0,menubar=0,resizable=0,width=685,height=490');");

  // [ msgForm End of Job ]
  return;

} // end msgForm function

/*
 * --------------------------------------------------------------------------------
 * These next functions and variables were used on TheFreeDictionary.com
 * to display inline notes (8-Jun-2004)
 * --------------------------------------------------------------------------------
 */

function layer(id){
  if(document.getElementById) return document.getElementById(id)
  if(document.all) return document.all[id]
  return null
}
var nsx;
var nsy;
if (!document.all) {
	document.captureEvents(Event.MOUSEMOVE);	
	document.onmousemove=get_mouse;
}
function get_mouse(e) {
	nsx=e.pageX;
	nsy=e.pageY+5;
}
function t_i(id) {
	var hlp=layer('Tp'+id).style
	if (hlp) {
	if (document.all) {
	 nsy=event.y+document.body.scrollTop
	 nsx=event.x+document.body.scrollLeft
	}
	hlp.top=nsy+20
	// hlp.left=(nsx>610?nsx-470:140)
    hlp.left=(nsx>610?nsx-470:300)		
	hlp.visibility='visible'
}}
function t_o(id) {
	var hlp=layer('Tp'+id).style
	if(hlp) hlp.visibility='hidden'
}

/*
 * --------------------------------------------------------------------------------
 * MyFirstWebPage.net specific functions
 * Leave this section at the end
 * --------------------------------------------------------------------------------
 */

function get_mfwpnLogo(pTM) {
  var mfwpnLogo = '<span class="MFWPNlogo">' +
  '<span style="color: #000000;">My</span>' +
  '<span style="color: #ff0000;">First</span>' +
  '<span style="color: #00ff00;">Web</span>' +
  '<span style="color: #0000ff;">Page</span>' +
  '<span style="color: #000000;">.net';

  if ( pTM == 'tm' )
    mfwpnLogo = ( mfwpnLogo + '&#153;' );
  mfwpnLogo = ( mfwpnLogo + '</span></span>' );

return mfwpnLogo;
} // end get_mfwpnLogo function