// **  002       openNewWindow()     args (depending on your needs-2, 6, or 7)      **
//
// ****** 002 openNewWindow  **** BEGIN *******************************************
// ---------- Instructions --------------------------------------------------------
// To use this in an HTML document, you would put something like the following in
// your document:
//
// <a href="http://www.google.com" onClick="openNewWindow(this.href, 'aWindowName');return false;">Click Me</a>
//
// Parameter list for openNewWindow
// A minimum of TWO parameters is required
//
// Two parameter option -- openNewWindow ('this.url', 'yourWindowName')--opens a new
// window with the default size as defined in the function, and the default options
// as defined in the function.
//
// Six parameter option -- openNewWindow ('this.url', 'yourWindowName', winWidth, winHeight, winLeft, winTop);
// Lets you set up a window with your own dimensions and location.  If you set the four
// size and location parameters all to -1, 
// opens a new window with default window options, but attempts to make it roughly
// half the width of the screen and centered
//
// Seven parameter option -- openNewWindow ('this.url', 'yourWindowName', winWidth, winHeight, winLeft, winTop, 'windowOption1,windowOption2,...,windowOptionN');
// For example: openNewWindow ('this.url', 'yourWindowName', 300, 300, 0, 0, 'resizable,status,location');
// Lets you set up a window with your own dimensions, location, and options.  If you
// set the four size and location parameters all to -1, it opens a new window trying
// to roughly open it in the center of the screen and about half the screen width.
//
// ----------- End Instructions ----------------------------------------------------
// Get the information about the screen
var screenWidth = screen.availWidth;   // Get the screen width
var screenHeight = screen.availHeight; // Get the screen height

function setPopUpDims() {
  if (is_nav) {
    popWidth = Math.round((screenWidth - (screenWidth * .15)));
    popHeight = Math.round((screenHeight - (screenHeight * .45)));
    popLeft = Math.round(((screenWidth - popWidth - 20) * .5));
    popTop = Math.round(((screenHeight - popHeight - 50) * .5));
  }
  else if (is_opera) {
    popWidth = Math.round((screenWidth - (screenWidth * .15)));
    popHeight = Math.round((screenHeight - (screenHeight * .45)));
    popLeft = Math.round(((screenWidth - popWidth - 20) * .5));
    popTop = Math.round(((screenHeight - popHeight - 20) * .5));
  }
  else {
    popWidth = Math.round((screenWidth - (screenWidth * .15)));
    popHeight = Math.round((screenHeight - (screenHeight * .25)));
    popLeft = Math.round(((screenWidth - popWidth - 20) * .5));
    popTop = Math.round(((screenHeight - popHeight - 50) * .5));
  }
  return popWidth, popHeight, popLeft, popTop;
}

function openNewWindow(myPage, myWindowName, myWidth, myHeight, myLeft, myTop, myOptions)
{
  // Set up the default window dimensions
  setPopUpDims();
  // set up a window handle array
  var popUpWin = new Array(); // define the windowHandle as an array
  // Set default variables
  var numArgs = arguments.length;
  this.myPage = myPage;
  this.myWindowName = myWindowName;
  this.DEFAULTWIDTH = popWidth;
  this.DEFAULTHEIGHT = popHeight;
  this.DEFAULTLEFT = popLeft;
  this.DEFAULTTOP = popTop;
  this.DEFAULTWINPROPS = 'height=' + popHeight + ',width=' + popWidth +  // both IE and Netscape
                         ',left=' + popLeft +       // IE
                         ',screenX=' + popLeft +    // Netscape
                         ',top=' + popTop +         // IE
                         ',screenY=' + popTop;      // Netscape
  // You can change the default window options by modifying the this.myOptions below
  // or you can use the function as is and redefine them when you call the function
  this.myOptions = 'fullscreen=no,' +  //IE only
                   'status=yes,' +
                   'scrollbars=yes,' +
                   'toolbar=yes,' +
                   'menubar=yes,' +
                   'resizable=yes,' +
                   'directories=yes,' +
                   'location=yes,' +
                   'dependent=no';   // Netscape only

  if (numArgs < 2)
  {
    alert ("Error -- you need a minimum of 3 arguments in the openNewWindow function!");
    return;
  }
  else if (numArgs == 2)
  {
    winprops = this.DEFAULTWINPROPS + ',' + this.myOptions;
  }
  else if (numArgs == 6)
  {
    if (arguments[2] == -1 || arguments[3] == -1 || arguments[4] == -1 || arguments[5] == -1)
    {
      winprops = this.DEFAULTWINPROPS + ',' + this.myOptions;
    }
    else
    {
      popWidth = arguments[2];
      popHeight = arguments[3];
      popLeft = arguments[4];
      popTop = arguments[5];
     }
     winprops = 'height=' + popHeight + ',width=' + popWidth +  // both IE and Netscape
     ',left=' + popLeft +       // IE
     ',screenX=' + popLeft +    // Netscape
     ',top=' + popTop +         // IE
     ',screenY=' + popTop +     // Netscape
     ',' + myOptions;           // the default options in the default variable section
  }
  else if (numArgs == 7)
  {
    if (arguments[2] == -1 || arguments[3] == -1 || arguments[4] == -1 || arguments[5] == -1)
    {
        winprops = this.DEFAULTWINPROPS + ',' + arguments[6];
    }
    else
    {
      popWidth = arguments[2];
      popHeight = arguments[3];
      popLeft = arguments[4];
      popTop = arguments[5];
     }
     winprops = 'height=' + popHeight + ',width=' + popWidth + // both IE and Netscape
     ',left=' + popLeft +      // IE
     ',screenX=' + popLeft +   // Netscape
     ',top=' + popTop +        // IE
     ',screenY=' + popTop +     // Netscape
     ',' + arguments[6];
  }
  else
  {
    alert ("You entered too many arguments. The maximum is 7, you entered: " + numArgs);
    return;
  }
  // FINALLY --- open the window using the information set in the steps above
    if(popUpWin[myWindowName] && popUpWin[myWindowName].open && popUpWin[myWindowName].closed && !is_opera)  // window was open, but now it's closed -- do NOT do this if in Opera
    {
      popUpWin[myWindowName] = window.open(myPage, myWindowName, winprops);
      popUpWin[myWindowName].focus();
    }
    else if (popUpWin[myWindowName] && popUpWin[myWindowName].open && !popUpWin[myWindowName].closed && !is_opera)  // window is currently open -- do NOT do this if in Opera
    {
      popUpWin[myWindowName].location.href=myPage;
      popUpWin[myWindowName].focus();
    }
    else   // the window has never been opened
    {
      popUpWin[myWindowName] = window.open(myPage, myWindowName, winprops);
      popUpWin[myWindowName].focus();
    }
}
// ****** END openNewWindow *****************************************************
// Hide my email
function emailMe (myClass)
{
  var theClass = myClass;
  var emailText = "Michael Britigan";
  var emailId = "mikeb";
  var emailHost = "recipesitereview.com";
  document.write("<a class=\"" + theClass + "\" " + "href=" + "mailto:" + emailId + "@" + emailHost+ ">" + emailText + "</a>");
}