

// popup window open for Hal Crook Page //////////////////////////////////////////////////////////////////////////////////// 
var halCrookWin;
function openHalCrookWin(link)
{
	if(halCrookWin && !halCrookWin.closed)
	{
		halCrookWin.focus();			
	}
	else
	{
		halCrookWin = window.open(link,'halCrookWin','width=1124,height=650, directories=yes,location=yes, menubar=yes, scrollbars=yes, status=yes, toolbar=yes, resizable=yes');
	}
}
// End popup window open for Catalog Page ////////////////////////////////////////////////////////////////////////////////////
// popup window open for Catalog Page //////////////////////////////////////////////////////////////////////////////////// 
var catalogWin;
function openCatalogWin(link)
{
	if(catalogWin && !catalogWin.closed)
	{
		catalogWin.focus();			
	}
	else
	{
		catalogWin = window.open(link,'catalogWindow','width=1124,height=650, directories=yes,location=yes, menubar=yes, scrollbars=yes, status=yes, toolbar=yes, resizable=yes');
	}
}
// End popup window open for Catalog Page ////////////////////////////////////////////////////////////////////////////////////

// popup window open for Class Reserves Page //////////////////////////////////////////////////////////////////////////////////// 
var classReservesWin;
function openClassReservesWin(link)
{
	if(classReservesWin && !classReservesWin.closed)
	{
		classReservesWin.focus();			
	}
	else
	{
		classReservesWin = window.open(link,'classReservesWindow','width=1124, height=750,  directories=yes,location=yes, menubar=yes, scrollbars=yes, status=yes, toolbar=yes, resizable=yes');
	}
}
// popup window open for Class Reserves Page //////////////////////////////////////////////////////////////////////////////////// 
var homeWin;
function goToHomeWin(link, openerWin)
{
	if(openerWin && !openerWin.closed)
	{
		openerWin.focus();	
		openerWin.location.href = link;		
	}
	else
	{
		homeWin = window.open(link,'homeWindow','width=1124,height=650,  directories=yes,location=yes, menubar=yes, scrollbars=yes, status=yes, toolbar=yes, resizable=yes');
	}
}
// end popup window open for Class Reserves Page //////////////////////////////////////////////////////////////////////////////////// 



// popup window open for Articles Page //////////////////////////////////////////////////////////////////////////////////// 
var articlesWin;
  

function openArticlesWin(link)
{      
  //---------------------------
  //display articles browser warning if neccessary
  if( berkleeBrowserTest() )
  {
    return false;
  }  
  //---------------------------  
  
	if(articlesWin && !articlesWin.closed)
	{
		articlesWin.focus();			
	}
	else
	{
		articlesWin = window.open(link,'articlesWindow','width=1124, height=650, directories=yes,location=yes, menubar=yes, scrollbars=yes, status=yes, toolbar=yes, resizable=yes');
	}
	                     
}
// end popup window open for Articles Page //////////////////////////////////////////////////////////////////////////////////// 


// popup window open for A-Z Page //////////////////////////////////////////////////////////////////////////////////// 
var azWin;
  

function openAZWin(link)
{      
	if(azWin && !azWin.closed)
	{
		azWin.focus();			
	}
	else
	{
		azWin = window.open(link,'azWindow','width=1124, height=650, directories=yes,location=yes, menubar=yes, scrollbars=yes, status=yes, toolbar=yes, resizable=yes');
	}
	                     
}
// end popup window open for Articles Page //////////////////////////////////////////////////////////////////////////////////// 


// popup window open for A-Z Page //////////////////////////////////////////////////////////////////////////////////// 
var subjectWin;
  

function openSubjectWin(link)
{      
	if(subjectWin && !subjectWin.closed)
	{
		subjectWin.focus();			
	}
	else
	{
		subjectWin = window.open(link,'subjectWindow','width=1124, height=650, directories=yes,location=yes, menubar=yes, scrollbars=yes, status=yes, toolbar=yes, resizable=yes');
	}
	                     
}
// end popup window open for Articles Page //////////////////////////////////////////////////////////////////////////////////// 




function berkleeBrowserTest()
{     
 
  //alert("berkleeBrowserTest()");     
   var show_upgrade_info = false;
  
  if ( berkleeBrowserCheck() == false )
  {
     if( displayWarning() )
     {
       show_upgrade_info = true;
     } 
  } 
  else
  {
    //alert('passed');
  }     
   
   return show_upgrade_info;
}

    
                         
//--------------------------------
function displayWarning()
{

  //alert user of issues; give them a choice 
  var show_info_bool = false;
  var msg = 'You are using an older Safari web browser that does not work with the Berklee library\'s Article site.\n\nPlease click "OK" for information on how to upgrade your browser.\n\nClick "Cancel" to ignore this warning';
  if( confirm(msg) )
  {
  	  window.location = "http://library.berklee.edu/articles_upgrade";
  	  show_info_bool = true;
  }
  else
  {
    //do nothing, they ignored warning 
    //alert("confirm ignored");
  }
  return show_info_bool;
}

function berkleeBrowserCheck()
{                             
  
  var browser_check_bool = false;
  
   //  see http://developer.apple.com/internet/safari/uamatrix.html
  var minimun_safari_build_ver = 523; //corresponds to safari version 3.x
  
  var ua_text = navigator.userAgent;
  //alert('ua: ' + ua_text);
  var pattern_safari = new RegExp("safari/\\d*", "i");   //example "Safari/312.26"  
  //this "[0-9\.]*" pattern did not work!!! had to use the folowing pattern                                                                                    
  var pattern_safari_version = new RegExp("\\d{2,3}");   //example "312.26"
  
  var safari_ua = pattern_safari.exec(ua_text);
  
  if( safari_ua != null) //if this is a Safari  browser
  {
    var safari_build_version = pattern_safari_version.exec(safari_ua[0]); //are the brackets "[0]" neccessary???

    if ( safari_build_version != null && safari_build_version >= minimun_safari_build_ver)
    {
      browser_check_bool= true;
    }
  }      
  else
  {
    //this is not a Safari browser
    browser_check_bool = true;
  }                           
  
  return browser_check_bool;
   
}                                        
/*
//http://www.dustindiaz.com/getelementsbyclass/
function getElementsByClassName(classname, node)  
{
    if(!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}            
    */


