// JavaScript Document

var browser = navigator.userAgent.toLowerCase();
var browserIE = ( browser.indexOf("msie") != -1 );
var browserFirefox = ( browser.indexOf("firefox") != -1 );
if ( browserFirefox )
{
    document.write('<style type="text/css" media="print">'); 
    document.write('div#footer a { margin-left: -0.5em; padding-left: 0; }'); 
    document.write('b { margin-left: -0.5em; padding-left: 0; }</style>'); 
    document.write('</style>'); 
}

var HTMLcode = "";
var homePageTitle = 'JewelryByGinny.com';

var topFrames = top.document.getElementsByTagName("frame");
var calledByFrame = ( topFrames ===  undefined )
                      ? ( 1 == 1 )
                      : ( top.location.href != window.location.href );

/*
 * --------------------------------------------------------------------------------
 */

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 homePageAnchor( p_aText ) {

if ( calledByFrame )
   var homePageLink = ('<a href="'+homePage+'" target="_parent" title="' + homePageTitle + '">') 
   else 
     var homePageLink = ('<a href="'+homePage+'"  title="' + homePageTitle + '">');

  return homePageLink;
} // end function homePageAnchor

/*
 * --------------------------------------------------------------------------------
 * The following functions control the left column menu display
 * --------------------------------------------------------------------------------
 */

function displayOption( pPageId, pOption, pColumn ) {
  var optionText = pOption;
  var offSite = ( pPageId.indexOf('http') == 0 );
  var tdClass = ""
  var pageName = f_element( 0, '.', pPageId );
  var pageType = '.'+f_element( 1, '.', pPageId );
  var targetWindow = ( offSite )
                       ? ' target="_blank"'
                       : ( calledByFrame )
                           ? '  target="_parent"'
                           : "";
  if ( offSite )
    pageFile = pPageId
    else {
      if ( pageType == '..' )
        pageType = '.html';
      if ( pPageId == 'index' )
        pageFile = homePage 
        else 
          pageFile = ( pageName + pageType );
      }
  /* pageFile = '#' */
  if ( PgID == pageName ) {
    aValue = 'class="URHere" title="You are here"'
    tdClass = ' class="URHere"'
	}
  else {
    aValue = ( offSite )
               ? ( 'href="' + pageFile + '" title="View the ' + pOption + ' site"' + targetWindow )
               : ( 'href="' + pageFile + '" title="View the ' + pOption + ' page"' + targetWindow );
    // optionText += '<span class="optionArrow">&nbsp;&nbsp;&#9658;</span>';
    // optionText += '<span class="optionArrow">&nbsp;&nbsp;&nbsp;</span>';
    }
  if ( pColumn != null )
     tdClass = ( tdClass + f_element((tdClass==""),"-","- ") + 'width="50%"' );
  if ( pColumn == null )
    HTMLcode += ('<tr><td' + tdClass + '><a ' + aValue + '>' + optionText + '</a></td></tr>\n')
  else if ( pColumn == 1 )
    if ( pPageId == 'empty' )
      HTMLcode += ('<tr><td></td>')
	else
      HTMLcode += ('<tr><td' + tdClass + '><a ' + aValue + '>' + optionText + '</a></td>')
  else
    if ( pPageId == 'empty' )
      HTMLcode += ('<td></td></tr>\n')
	else
      HTMLcode += ('<td' + tdClass + '><a ' + aValue + '>' + optionText + '</a></td></tr>\n');
  return;
} // end function displayOption

 /*
function displayOption( pPageId, pOption, pColumn ) {
  function getType() {
    var typePassed = ( '.' + f_element( 1, '.', pPageId ) );
    return typePassed;
    }
  var tdClass = ""
  var pageName = f_element( 0, '.', pPageId );
  var pageType = getType();
  var displayPastShows = ( getPassedValue('shows') == 'past' );
  var targetAttribute = "";
  var offSite = ( pPageId.indexOf('http') == 0 );
  
  if ( offSite )
    pageFile = pPageId
    else {
      if ( pageType == '..' )
        pageType = '.html';
      if ( pPageId == 'index' )
        pageFile = homePage 
        else 
          pageFile = ( pageName + pageType );
      }
  if ( pageType == '..' )
     pageType = '.html';
  if ( ( pPageId == 'index' ) && ( getType() == '..' ) )
    pageFile = homePage 
  else 
    pageFile = ( pageName + pageType );
  /* pageFile = '#' */ /*
  if ( PgID == 'index' )
    if ( getType() == '..' ) {
      if ( displayPastShows )
        pageName = 'notPgID';
      } else if ( !displayPastShows )
        pageName = 'notPgID';
  if ( PgID == pageName ) {
    aValue = 'class="URHere" title="You are here"'
	tdClass = ' class="URHere"'
	}
  else {
	targetAttribute = ( calledByFrame )
	                    ? ' target="_parent"'
	                    : '';
    aValue = ( 'href="' + pageFile + '" title="Link to the ' + pOption + ' page"' + targetAttribute );
    }
  if ( pColumn != null )
     tdClass = ( tdClass + f_element((tdClass==""),"-","- ") + 'width="50%"' );
  if ( pColumn == null )
    HTMLcode += ('<tr><td' + tdClass + '><a ' + aValue + '>' + pOption + '</a></td></tr>\n')
  else if ( pColumn == 1 )
    if ( pPageId == 'empty' )
      HTMLcode += ('<tr><td></td>')
	else
      HTMLcode += ('<tr><td' + tdClass + '><a ' + aValue + '>' + pOption + '</a></td>')
  else
    if ( pPageId == 'empty' )
      HTMLcode += ('<td></td></tr>\n')
	else
      HTMLcode += ('<td' + tdClass + '><a ' + aValue + '>' + pOption + '</a></td></tr>\n');
  return;
}
*/

function displayMenu() {
  var menuArea = document.getElementById('menuArea');
  HTMLcode = ('<table id="menu" cellpadding="0" cellspacing="0" align="center" width="100%" border="0">\n');
  HTMLcode += ('<tbody>\n');
  for ( var i in allMenuOptions )
    displayOption( allMenuOptions[i].pageId, allMenuOptions[i].menuOption );
  HTMLcode += ('</tbody>\n');
  HTMLcode +=  ('</table>\n');
  menuArea.innerHTML = HTMLcode;
  return;
}

/*
 * --------------------------------------------------------------------------------
 */

function getPassedValue(p_id, p_source) {
  /* 
   * +++
   *
   * 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.
   *                p_source - Look for passed value in parent window.  
   *                               Only checked when calledByFrame variable is
   *                               true.  One of two values is expected:
   *                                  "parent" - Look for passed value in parent 
   *                                             window
   *                                  "current" - Look for passed value in 
   *                                              current window (default)
   *                               This is useful for a frame where a parameter 
   *                               might be passed from the parent window.
   *                               
   *
   *       History: 20-Jan-2010 - p_source added
   * 
   * ---
   */

  // [ getPassedValue Constants ]
  var fromParent = ( p_source === undefined )
                     ? ( 1 == 2 )
                     : ( calledByFrame )
                       ? ( p_source == "parent" )
                       : ( 1 == 2 );
  var passedValue = ( fromParent )
                    ? unescape(f_element( 1, "?", window.parent.location.href ))
                    : unescape(location.search.substring(1));

  // [ getPassedValue Variables ]
  var allSubValues = ( fromParent )
                     ? f_element( 1, "?", window.parent.location.href ).split('&')
                     : location.search.substring(1,location.search.length).split('&');
  var idValue = ( passedValue == '?' )
                ? ""
                : passedValue;
  var subValue = "";

  // [ getPassedValue Main Line ]
  if ( p_id != null ) {
    idValue = "";
    for (var 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++)
  } // if ( p_id != null )

  // [ getPassedValue End of Job ]
  return idValue;

} // end getPassedValue function

/*
 * --------------------------------------------------------------------------------
 */

function subjectDisplay() {
	subjectFound = getPassedValue('subject', 'parent');
	inputValue = ( subjectFound != "" )
	               ? ( ' value="' + subjectFound + '" ' )
		       : "";
	document.write('<INPUT type="text" name="subject" size="70"' + inputValue + '>');
} // end function subjectDisplay

/*
 * --------------------------------------------------------------------------------
 */

function ckboxDisplay ( p_ckbox, p_topic ) {
	checked = ( getPassedValue('ckbox', 'parent') == p_ckbox )
	          ? ' checked="yes"'
	          : "";
	document.write('<INPUT type="checkbox" name="' + p_ckbox + '" value="Yes"' + checked + '>' + p_topic);
} // end function ckboxDisplay
 
/*
 * --------------------------------------------------------------------------------
 */

function include_rpc(script_filename, p1) {
  /* 
   * +++
   *
   * Function Name: include_rpc
   *        Author: Stoyan Stefanov, phpied.com (original)
   *                Alvin Orzechowski, MyFirstWebPage.net (modifications)
   * Creation Date: 20-Mar-2007
   *      Abstract: To call and execute a server script
   *   Description: 
   *    Parameters: script_filename - the name of the script to be called 
   *                                  (required)
   *                p1 - value to be passed (optional)
   *       History: 
   * 
   * ---
   */

  // [ include_rpc Constants ]
  var html_doc = document.getElementsByTagName('head').item(0);
  var js = document.createElement('script');
  
  // [ include_rpc Main Line ]
  if ( p1 != null )
      script_filename += ( '?' + p1 );
  js.setAttribute('language', 'javascript');
  js.setAttribute('type', 'text/javascript');
  js.setAttribute('src', script_filename);
  html_doc.appendChild(js);
  return;
} // end include_rpc function

/*
 * --------------------------------------------------------------------------------
 * The following functions are used to remove a class when a page loads
 * --------------------------------------------------------------------------------
 */

function getElementsByClass(searchClass,tag) {
  // Source: http://www.dustindiaz.com/getelementsbyclass/
	var classElements = new Array();
	if ( tag == null )
		tag = '*';
	var els = document.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
  }

/*
 * --------------------------------------------------------------------------------
 */

function takeYear(theDate) {
  // Source: http://www.quirksmode.org/js/introdate.html
	x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
  }

/*
 * --------------------------------------------------------------------------------
 */

function todayYearMonth() {
  /* 
   * ++
   * Name: todayYearMonth
   * Author: Alvin Orzechowski, MyFirstWebPage.net
   * Creation Date: 6-May-2008
   * Abstract: To return today's month and day in yyyymm format
   * Description: 
   * Parameters: None
   * History:
   *           - 
   * --
   */
  // [ todayYearMonth Constants ]
  var today = new Date();

  // [ todayYearMonth Variables ]
  currentMonth = ( today.getMonth() + 1 );
  currentYYYY = ( takeYear(today) + '' );
  currentYYYYMM = '';

  // [ todayYearMonth Main Line ]
  currentMM = ( ( currentMonth <= 9 ) ? ( "0" + currentMonth ) : ( currentMonth + '' ) );
  currentYYYYMM = ( currentYYYY + currentMM );
  

  return currentYYYYMM;
  } // end todayYearMonth function


/*
 * --------------------------------------------------------------------------------
 */

function todayYearMonthDate() {
  /* 
   * ++
   * Name: todayYearMonthDay
   * Author: Alvin Orzechowski, MyFirstWebPage.net
   * Creation Date: 25-May-2008
   * Abstract: To return today's month and day in yyyymm format
   * Description: 
   * Parameters: None
   * History:
   *           - 
   * --
   */
  // [ todayYearMonth Constants ]
  var currentYYYYMM = todayYearMonth();
  var today = new Date();

  // [ todayYearMonth Variables ]
  var currentDate = today.getDate();
  var currentDD = '';
  currentYYYYMMDD = '';

  // [ todayYearMonth Main Line ]
  currentDD = ( ( currentDate <= 9 ) ? ( "0" + currentDate ) : ( currentDate + '' ) );
  currentYYYYMMDD = ( currentYYYYMM + currentDD );
  

  return currentYYYYMMDD;
  } // end todayYearMonth function


/*
 * --------------------------------------------------------------------------------
 */

function removeDisplayEventsClass() {
  /* 
   * ++
   * Name: removeDisplayEventsClass
   * Author: Alvin Orzechowski, MyFirstWebPage.net
   * Creation Date: 6-May-2008
   * Abstract: To remove the displayEvents class from any HTML dl tag whose id
   *           attribute is less than today's yyyymm value.
   * Description: 
   * Parameters: None
   * History:
   *           - 
   * --
   */
  // [ removeDisplayEventsClass Constants ]
  var allMonths = getElementsByClass('displayEvents', 'dl');
  var currentMonth = todayYearMonth();
  var emptySchedule = document.getElementById('emptySchedule');
  var displayPastShows = ( getPassedValue('shows') == 'past' );
  // [ removeDisplayEventsClass Variables ]
  var classesRemoved = 0;

  // [ removeDisplayEventsClass Main Line ]
  for (i=0; i<allMonths.length; i++) {
    if ( ( allMonths[i].id < currentMonth ) && ( !displayPastShows ) ) {
      allMonths[i].className = '';
      classesRemoved++;
      } else if ( ( allMonths[i].id >= currentMonth ) && ( displayPastShows ) ) {
        allMonths[i].className = '';
        classesRemoved++;
        }
    } // end for (i=0; i<allMonths.length; i++)
  if ( classesRemoved == allMonths.length ) {
    emptySchedule.style.display = 'inline';
    }
  if ( displayPastShows )
    document.getElementById('tentativeNote').style.display = 'none';

  return;
  } // end removeDisplayEventsClass function


/*
 * --------------------------------------------------------------------------------
 */

function hideH2() {
  /* 
   * ++
   * Name: hideH2
   * Author: Alvin Orzechowski, MyFirstWebPage.net
   * Creation Date: 24-May-2008
   * Abstract: To add the "display: none;" style to any HTML h2 tag who's id 
   * attribute value is less than today's yyyymmdd.
   * Description: 
   * Parameters: None
   * History:
   *           - 
   * --
   */
  // [ hideH2 Constants ]
	var allH2tags = document.getElementsByTagName('h2');
  var displayPastShows = ( getPassedValue('shows') == 'past' );

  // [ hideH2 Variables ]
  var allH2tagsLen = allH2tags.length;
  var currentFullDate = ( displayPastShows )
                        ? '00000000'
                        : todayYearMonthDate();

  // [ hideH2 Main Line ]
  for (i=0; i<allH2tagsLen; i++) {
    if ( allH2tags[i].id != '' )
      if ( allH2tags[i].id < currentFullDate )
         allH2tags[i].style.display = 'none';
  }

  return;
  } // end hideH2 function

/*
 * --------------------------------------------------------------------------------
 * 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();
        }
    }
}



/*
 * --------------------------------------------------------------------------------
 * 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
