
// sets up external links to open in a new window.
function externalLinks()
{
   if (!document.getElementsByTagName) return;
   var anchors = document.getElementsByTagName("a");
   for (var i=0; i<anchors.length; i++)
   {
      var anchor = anchors[i];
      if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
         anchor.target = "_blank";
   }
}
window.onload = externalLinks;


var newwindow = '';

// ------------------------------------------------------------------------

// opens a new window positioned 100px from top and left.
function positionedWindow(url, width, height)
{
   if ( ! newwindow.closed && newwindow.location)
   {
      newwindow.location.href = url;
   }
   else
   {
      newwindow = window.open(url,"positionedWindow",'width=' + width + ',height=' + height + ',resizable=no,scrollbars=yes,menubar=yes,' + 'location=no,status=no,toolbar=yes,left=100,top=100,' + 'xposition=100,yposition=100');
      if ( ! newwindow.opener) newwindow.opener = self;
   }
   if (window.focus)
   {
      newwindow.focus()
   }
   return false;
}

// ------------------------------------------------------------------------

// opens a new window centered on the screen.
function centeredWindow(url, myname, w, h, scroll)
{
   var winl = (screen.width - w) / 2;
   var wint = (screen.height - h) / 2;

   winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=yes,resizable=yes'

   if ( ! newwindow.closed && newwindow.location)
   {
      newwindow.location.href = url;
   }
   else
   {
      newwindow = window.open(url, myname, winprops);
      if ( ! newwindow.opener) newwindow.opener = self;
   }
   if (window.focus)
   {
      newwindow.focus()
   }
   return false;
}


// ------------------------------------------------------------------------

// opens a new window centered on the screen, WITH menu bar, navigation, etc
function centeredFullWindow(url, myname, w, h, scroll)
{
   var winl = (screen.width - w) / 2;
   var wint = (screen.height - h) / 2;

   winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=yes,resizable=yes,toolbar=yes,menubar=yes,location=yes toolbar=yes'

   if ( ! newwindow.closed && newwindow.location)
   {
      newwindow.location.href = url;
   }
   else
   {
      newwindow = window.open(url, myname, winprops);
      if ( ! newwindow.opener) newwindow.opener = self;
   }
   if (window.focus)
   {
      newwindow.focus()
   }
   return false;
}



// ------------------------------------------------------------------------

// opens a new window centered on the screen.
// for the online store, it adds the location and menu bars.
function centeredStoreWindow(url, myname, w, h, scroll)
{
   var winl = (screen.width - w) / 2;
   var wint = (screen.height - h) / 2;

   winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=yes,resizable=yes,location=yes,menubar=yes'

   if ( ! newwindow.closed && newwindow.location)
   {
      newwindow.location.href = url;
   }
   else
   {
      newwindow = window.open(url, myname, winprops);
      if ( ! newwindow.opener) newwindow.opener = self;
   }
   if (window.focus)
   {
      newwindow.focus()
   }
   return false;
}

// ------------------------------------------------------------------------

// 
function to_old_win(url)
{
   opener.location.href = url;
}

// ------------------------------------------------------------------------

/*
* Name: emptyField(fieldID)
* Desc: empty a text field on click
*/
function emptyField(fieldID)
{
   var myField = document.getElementById(fieldID);
   myField.value = "";
}

// ------------------------------------------------------------------------

/*
* Name: refillField(fieldID)
* Desc: refill default text in a text field if not filled in.
*/
function refillField(fieldID, defaulttext)
{
   var myField = document.getElementById(fieldID);
   if (myField.value == "")
   {
      myField.value = defaulttext;
   }
}
