var homewindowreference = null;

//alert('naming window');

window.name='crushthetestarticles';

var baseref = location.href.substring(0,location.href.lastIndexOf("/") + 1); 
//can't use relative urls if this function is called by a file not in the main directory

//alert ('in articleswindowcontrol');

if (window.opener)
{

//   alert('trying to get homewindowreference');
   
   if (window.opener.parent.name == "crushthetesthome") //new window opened by parent of mainframe
   {
   
//      alert ('getting homewindowreference');
      window.opener.parent.articleswindowreference = self;
      homewindowreference = window.opener.parent; //the opener window might be a subframe if target is used just = self if alread the top 
   }
}   

//check to see if there is a valid reference to the home window. if there is check to see if it is crushthetest. 
//if the questions window was opened by someone other than crushthetest, reset the homewindowreference.
//the idea is not to choke if there is no homewindowreference and then to make sure the home link in the articles window
//opens crushthetest home and not some other window that may have linked to the questions window from some other site. 

//alert ('loading openorfocusfunction');

function openorfocus_homewindow()

{  
//   alert('in openorfocus');
   if (homewindowreference)
   {
     // alert("setting focus to home window, ref = " + homewindowreference);
      //alert('name of home window is ' + homewindowreference.name); // knows home but can't go home.
      //self.blur(); doesn't switch tabs
      homewindowreference.focus(); //firefox gets here and has the correct reference but doesn't focus
      return false;
   }
   else
   {
      if (top.getcookiedata("homewindow") == "open")    //if use target don't get reference BUT can get ref if window sends its ref
      {
         //alert("targeting home window");
         self.blur();
         return true;
      } 
      else
      {
         var windowsettings='location=yes,toolbar=yes,menubar=yes,status=yes,resizable=yes,scrollbars=yes,left=10,top=10,height=600,width=800';
         var windowname='crushthetesthome';
         var filetoload= baseref + 'index.html';
         //alert("opening new home window");  
         window.open(filetoload, windowname, windowsettings);
         return false;
      }
   }
}
